mciantyre / teensy4-rs

Rust support for the Teensy 4
Apache License 2.0
271 stars 31 forks source link

Interaction with RTIC SYSTICK handling #134

Closed wyager closed 1 year ago

wyager commented 1 year ago

Consider the following code, from an RTIC v2 app:

let systick_token = rtic_monotonics::create_systick_token!();
//Systick::start(cx.core.SYST, teensy4_bsp::EXT_SYSTICK_HZ, systick_token);
let poller = bsp::logging::log::usbd(usb, bsp::logging::Interrupts::Enabled).unwrap();

If I uncomment the second line, to activate the systick timer, it seems to break USB. No device even shows up under /dev/cu...., and my computer doesn't register any attached USB devices.

I saw in an earlier version of the teensy4-rs docs, it said that you couldn't have USB logging and systick timing at the same time, but that seems to have been removed.

Any idea what the situation might be here?

wyager commented 1 year ago

This might actually have nothing to do with USB, as it looks like even a simple PIT led blinky is broken by uncommenting that line. Closing issue, at least for the moment

wyager commented 1 year ago

For the record, the issue seems to be the use of EXT_SYSTICK_HZ. It's supposed to be set to the core clock freq (like 500MHz or whatever), it seems.

mciantyre commented 1 year ago

SYSTCK can have two different clock sources. If the clock source is set to "external clock," then EXT_SYSTICK_HZ is the correct frequency to use for your SYSTICK.

If I'm looking at the right code, it seems that RTIC always uses the processor or "core" clock. EXT_SYSTICK_HZ won't work in this case. If you're using the teensy4-bsp board setup to configure the clocks, then you can use ARM_FREQUENCY as the clock frequency for your SYSTICK.


I saw in an earlier version of the teensy4-rs docs, it said that you couldn't have USB logging and systick timing at the same time, but that seems to have been removed.

This was a design limitation of previous BSPs. Nowadays, USB logging and SYSTICK should work together. Reach out if you notice they're not jiving.