probe-run icon indicating copy to clipboard operation
probe-run copied to clipboard

Detect when the `rt` feature was not enabled

Open jonas-schievink opened this issue 4 years ago • 10 comments

I'm not sure if this can be detected, but if it can, we should totally try to do it, since everyone forgets to enable the "rt" feature from time to time and the symptoms are just "stuff's broken yo", which isn't very easy to debug.

jonas-schievink avatar Sep 22 '20 21:09 jonas-schievink

isn't this already caught at link time by an assertion in cortex-m-rt linker script?

japaric avatar Nov 16 '20 13:11 japaric

I forgot to enable the feature yesterday and the symptoms were just that interrupts handlers were not being called and the CPU getting stuck. I would love to help with a PR with a fix but I don’t have enough background to figure out the detection.

matoushybl avatar Jan 23 '21 08:01 matoushybl

Detect when the rt feature was not enabled

would the goal be printing a warning when it's not enabled? the 'rt' is not required unless you use interrupts, right? earlier this week, I ran into the issue of not enabling the rt feature in the stm32l4xx-hal and using hardware tasks in rtic: I didn't get any sort of linker error but none of the interrupts would fire (I think all of rtic's interrupt handlers got GC-ed by the linker). unsure if that's something that should be reported by rtic or cortex-m-rt ...

japaric avatar Feb 04 '21 14:02 japaric

What rt feature of which crate are you referring to? 😇

Urhengulas avatar May 28 '21 15:05 Urhengulas

PACs generally have a feature called "rt", for example here: https://github.com/nrf-rs/nrf52840-pac/blob/master/Cargo.toml

jonas-schievink avatar May 28 '21 15:05 jonas-schievink

PACs generally have a feature called "rt", for example here: https://github.com/nrf-rs/nrf52840-pac/blob/master/Cargo.toml

So the idea is to detect the feature for any pac crate? That sounds more complicated than I though it is 🤔

Urhengulas avatar May 29 '21 22:05 Urhengulas

if you depend on a PAC but do not enable its rt feature

  • there's no #[cortex_m_rt::interrupt] attribute so you cannot register an interrupt handler that will be discarded by the linker -> Good
  • if you enable cortex-m-rt's device feature (the rt feature of PACs enables this feature), you still cannot use the #[cortex_m_rt::interrupt] attribute; you cannot use #[$PAC::interrupt] either

I think that (cortex-m-rt API) works as intended.

I think the issue is that RTIC does not internally use the #[cortex_m_rt::interrupt] interface (I don't remember the reason for that), instead it directly defines symbols using #[no_mangle]. If the PAC's rt feature is not enabled then all the interrupt handlers generated by RTIC will be discarded by the linker leading to interrupts misbehaving.

So I think that the issue should be fixed in RTIC.

I don't think we can detect the issue in probe-run because we have the ELF after linking.

For starters, not enabling the PAC's rt feature is not a problem per se. If you are not using interrupt handlers then things will work. probe-run should not reject these binaries.

The issue is declaring interrupt handlers like RTIC does (not using the #[cortex_m_rt::interrupt] macro). Those handlers will be discarded by the linker if the "rt" crate is not enabled. When the linked ELF is passed to probe-run we can tell it has no interrupt handlers but cannot tell if the user defined them to begin with (because they are discarded by the linker).

and the symptoms are just "stuff's broken yo", which isn't very easy to debug.

is stuff broken only with RTIC or are there other things that break when you forget to enable the "rt" feature? @jonas-schievink

japaric avatar Jul 01 '21 13:07 japaric

RTIC 0.6 (unreleased) does report the issue:

error[E0433]: failed to resolve: could not find `interrupt` in `you_must_enable_the_rt_feature_for_the_pac_in_your_cargo_toml`
  --> src/bin/hello.rs:16:1
   |
16 | #[rtic::app(device = nrf52840_pac)]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ could not find `interrupt` in `you_must_enable_the_rt_feature_for_the_pac_in_your_cargo_toml`
   |
   = note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)

I don't know what the timeline for that is but maybe that Cargo feature detection feature can be backported to 0.5.x

japaric avatar Jul 01 '21 13:07 japaric

is stuff broken only with RTIC or are there other things that break when you forget to enable the "rt" feature? @jonas-schievink

That is a good question, I don't remember how I ran into this when I filed this issue

jonas-schievink avatar Jul 01 '21 14:07 jonas-schievink

I don't know what the timeline for that is but maybe that Cargo feature detection feature can be backported to 0.5.x

this "you forgot to enable the 'rt' feature in the PAC" feature has been backported and released on version 0.5.7.

@jonas-schievink given the above maybe we can close this issue until we ran into something non-rtic related?

japaric avatar Jul 06 '21 10:07 japaric

Closing as it seems fixed in RTIC and no other case where this is an issue was reported. If you hit this issue please open a new issue and mention this one here.

Urhengulas avatar Feb 11 '23 15:02 Urhengulas