Skip to content

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

Open
@banyanshade-software

Description

@banyanshade-software

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions