rust-embedded / rust-embedded/cortex-m

TPIU: `set_swo_baud_rate` silently integer divisions, does not verify prescaler

Open
#388 1 comment 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

https://github.com/rust-embedded/cortex-m/blob/92552c73d3b56dc86007450633950d16ebe0e495/src/peripheral/tpiu.rs#L105-L113

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.

2022-01-10T18:10:04+01:00

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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.