cortex-m icon indicating copy to clipboard operation
cortex-m copied to clipboard

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

Open tmplt opened this issue 3 years ago • 1 comments

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

tmplt avatar Jan 10 '22 17:01 tmplt

openocd warns the user if a trace port frequency cannot be obtained from a clock input:

(gdb) monitor tpiu config external uart on 120000000 115200
Can not obtain 115200 trace port frequency from 120000000 TRACECLKIN frequency, using 115163 instead

and writes 1041 to SWOSCALER.

tmplt avatar Jan 11 '22 13:01 tmplt