rust-embedded / rust-embedded/cortex-m

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

Open
#571 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
1k
Forks
202
Avg merge
6d 2h
Merged PRs (30d)
2

Description

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)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the implementations of itm::write_all(), write_str(), and iprintln!(), then compare their ITM writes with the CMSIS ITM_SendChar behavior shown in the issue. Reproduce the output in STM32CubeIDE's SWV ITM Data console. Done means a documented compatibility mode or equivalent behavior sends characters in the form expected by that console.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
embedded-iot
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.