Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iprintln!(), itm::write_all(), etc not compatible with STM32CubeIDE Serial Wire Viewer (should send on char per u32) #571

Open
banyanshade-software opened this issue Jan 3, 2025 · 0 comments

Comments

@banyanshade-software
Copy link

Good evening !
I'm starting to use rust+cortex-m on STM32, and I'm planning to mix existing C code (using STM32CubeIDE, CMSIS and freeRTOS) and Rust code (as a static library).
In my early experiments, I have trouble with ITM support, which seems incompatible with Cube IDE (or at least the SWV ITM Data console)

itm::write_all(), which is used by write_str() and iprintln!, will send 32bits words on ITM (thus 4 chars per word).
This is not compatible with ST CubeIDE ITM display, and CMSIS Core Peripheral Access Layer

E.g in core_cm4.h: (Drivers/CMSIS/, (provided by ARM I think))

__STATIC_INLINE uint32_t ITM_SendChar (uint32_t ch)
{
  if (((ITM->TCR & ITM_TCR_ITMENA_Msk) != 0UL) &&      /* ITM enabled */
      ((ITM->TER & 1UL               ) != 0UL)   )     /* ITM Port #0 enabled */
  {
    while (ITM->PORT[0U].u32 == 0UL)
    {
      __NOP();
    }
    ITM->PORT[0U].u8 = (uint8_t)ch;
  }
  return (ch);
}

thus a single byte is sent at a time (wasting 75% bandwidth with ascii)

With Rust/Cortex-m:

	itm::write_all(itm(), "DEF".as_bytes());
	itm::write_all(itm(), "DEF".as_bytes());
	itm::write_all(itm(), "DEF".as_bytes());
	itm::write_all(itm(), "\n".as_bytes());

And this will display "D䙅D䙅D䙅" in cube IDE

Trace log shows
Capture d’écran 2025-01-03 à 22 46 18
hence the D (68), while EF becomes 0x4645 and is displayed as U+4645 character (as if it was utf-32)

IMHO, a mode that complies/mimic with CMSIS lib should be provided (and probably should be default)

banyanshade-software added a commit to banyanshade-software/cortex-m that referenced this issue Jan 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant