rust-embedded / rust-embedded/cortex-m
TPIU: `set_swo_baud_rate` silently integer divisions, does not verify prescaler
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 1k
- Forks
- 202
- Avg merge
- 6d 2h
- Merged PRs (30d)
- 2
Description
Experimentally, tpiu.set_swo_baud_rate(16_000_000, 115_200) works for me on an stm32, but instead of writing the expected (but invalid) 137.88, 137 is written. I theorize I just happen to be within a margin of error to kinda work, which would explain the invalid packets I get in https://github.com/rtic-scope/cargo-rtic-scope/issues/18.
On another device, an atsame51n, tpiu.set_swo_baud_rate(120_000_000, 115_200) writes 1040 instead of 1040.66, and no trace output is seen on the SWO. Whether an invalid prescaler is the cause of this or just incorrect device setup remains to be seen.
In any case, the input arguments should yield an integer after division or otherwise fail. Preferably the function should also check what the largest implented prescaler value is.
Relevant section from ARMv7-M documentation attached below.

Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with src/peripheral/tpiu.rs lines 105-113 and compare set_swo_baud_rate with the linked ARMv7-M documentation. Verify how the requested clock and baud rate produce the prescaler, then ensure invalid division or unsupported prescaler values are rejected; confirm behavior with relevant tests or device checks.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- embedded-iot
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100