Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TPIU: set_swo_baud_rate silently integer divisions, does not verify prescaler #388

Open
tmplt opened this issue Jan 10, 2022 · 1 comment · May be fixed by #389
Open

TPIU: set_swo_baud_rate silently integer divisions, does not verify prescaler #388

tmplt opened this issue Jan 10, 2022 · 1 comment · May be fixed by #389

Comments

@tmplt
Copy link
Contributor

tmplt commented Jan 10, 2022

/// Sets the prescaler value for a wanted baud rate of the Serial
/// Wire Output (SWO) in relation to a given asynchronous refernce
/// clock rate.
#[inline]
pub fn set_swo_baud_rate(&mut self, ref_clk_rate: u32, baud_rate: u32) {
unsafe {
self.acpr.write((ref_clk_rate / baud_rate) - 1);
}
}

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 rtic-scope/cargo-rtic-scope#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 added a commit to rtic-scope/cortex-m that referenced this issue Jan 10, 2022
tmplt added a commit to rtic-scope/cortex-m that referenced this issue Jan 10, 2022
@tmplt
Copy link
Contributor Author

tmplt commented Jan 11, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant