Closed dzervas closed 1 year ago
Oh and the error:
INFO Starting SoftDevice BLE shit
└─ src/main.rs:179
ERROR panicked at 'sd_softdevice_enable err SdmIncorrectInterruptConfiguration'
└─ /home/dzervas/.cargo/git/checkouts/nrf-softdevice-03ef4aef10e777e4/3b08bda/nrf-softdevice/src/fmt.rs:101
ERROR panicked at /home/dzervas/.cargo/registry/src/index.crates.io-6f17d22bba15001f/defmt-0.3.5/src/lib.rs:368:5:
explicit panic
└─ /home/dzervas/.cargo/registry/src/index.crates.io-6f17d22bba15001f/panic-probe-0.3.1/src/lib.rs:104
DEBUG probe_rs::debug::unit_info: Found DIE, now checking for inlined functions: name=None
DEBUG probe_rs::debug::unit_info: Found DIE, now checking for inlined functions: name=None
DEBUG probe_rs::debug::unit_info: Found DIE, now checking for inlined functions: name=None
DEBUG probe_rs::debug::unit_info: Found DIE, now checking for inlined functions: name=None
DEBUG probe_rs::debug::unit_info: Found DIE, now checking for inlined functions: name=None
DEBUG probe_rs::debug::unit_info: Found DIE, now checking for inlined functions: name=None
Frame 0: div_half_u128 @ 0x00000a60
Frame 1: __udf @ 0x0004f61a inline
./asm/lib.rs:48:1
Frame 2: __udf @ 0x000000000004f61a
./asm/lib.rs:51:17
Frame 3: udf @ 0x0004f4a8
/home/dzervas/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cortex-m-0.7.7/src/asm.rs:43:5
Frame 4: hard_fault @ 0x0004f52e
/home/dzervas/.cargo/registry/src/index.crates.io-6f17d22bba15001f/panic-probe-0.3.1/src/lib.rs:86:5
Frame 5: panic @ 0x0004f500
/home/dzervas/.cargo/registry/src/index.crates.io-6f17d22bba15001f/panic-probe-0.3.1/src/lib.rs:54:9
Frame 6: panic_fmt @ 0x00050ed8
/rustc/2e5a9dd6c9eaa42f0684b4b760bd68fc27cbe51b/library/core/src/panicking.rs:72:14
Frame 7: panic_display<&str> @ 0x00050f72 inline
/rustc/2e5a9dd6c9eaa42f0684b4b760bd68fc27cbe51b/library/core/src/panicking.rs:178:5
Frame 8: panic_explicit @ 0x0000000000050f42
/rustc/2e5a9dd6c9eaa42f0684b4b760bd68fc27cbe51b/library/core/src/panicking.rs:160:5
Frame 9: panic_cold_explicit @ 0x00050bf2
/rustc/2e5a9dd6c9eaa42f0684b4b760bd68fc27cbe51b/library/core/src/panic.rs:87:13
Frame 10: default_panic @ 0x00050b4a
/home/dzervas/.cargo/registry/src/index.crates.io-6f17d22bba15001f/defmt-0.3.5/src/lib.rs:368:5
Frame 11: panic @ 0x000449e2 inline
/home/dzervas/.cargo/registry/src/index.crates.io-6f17d22bba15001f/defmt-0.3.5/src/export/mod.rs:133:14
Frame 12: <unknown function @ 0x000449e2> @ 0x00000000000449de
/home/dzervas/.cargo/git/checkouts/nrf-softdevice-03ef4aef10e777e4/3b08bda/nrf-softdevice/src/softdevice.rs:108:25
Frame 13: {async_fn#0} @ 0x0002faaa
/home/dzervas/Lab/clackrust/src/main.rs:216:11
Frame 14: <unknown function @ 0x000279fa> @ 0x000279fa
/home/dzervas/.cargo/registry/src/index.crates.io-6f17d22bba15001f/embassy-executor-0.3.0/src/raw/mod.rs:161:15
Frame 15: {closure#0} @ 0x0004a59c
/home/dzervas/.cargo/registry/src/index.crates.io-6f17d22bba15001f/embassy-executor-0.3.0/src/raw/mod.rs:411:17
Frame 16: <unknown function @ 0x00049fae> @ 0x00049fae
/home/dzervas/.cargo/registry/src/index.crates.io-6f17d22bba15001f/embassy-executor-0.3.0/src/raw/run_queue.rs:85:13
Frame 17: <unknown function @ 0x0004a506> @ 0x0004a506
/home/dzervas/.cargo/registry/src/index.crates.io-6f17d22bba15001f/embassy-executor-0.3.0/src/raw/mod.rs:391:13
Frame 18: <unknown function @ 0x0004a5f6> @ 0x0004a5f6
/home/dzervas/.cargo/registry/src/index.crates.io-6f17d22bba15001f/embassy-executor-0.3.0/src/raw/mod.rs:533:6
Frame 19: <unknown function @ 0x0002dcbc> @ 0x0002dcbc
/home/dzervas/.cargo/registry/src/index.crates.io-6f17d22bba15001f/embassy-executor-0.3.0/src/arch/cortex_m.rs:108:21
Frame 20: __cortex_m_rt_main @ 0x000341e8
/home/dzervas/Lab/clackrust/src/main.rs:84:1
Frame 21: __cortex_m_rt_main_trampoline @ 0x000341cc
/home/dzervas/Lab/clackrust/src/main.rs:84:1
Frame 22: <unknown function @ 0x00027126> @ 0x00027126
Frame 23: <unknown function @ 0x00027126> @ 0x00027126
this is because you've enabled some interrupt at a softdevice-reserved priority. make sure to follow https://github.com/embassy-rs/nrf-softdevice#interrupts
Oh great, now i start missing info in the readme... :joy:
Ok so I also use the usb driver so I did the following before even enabling the hardware peripherals and did the timer and GPIOTE priority fix that you describe in the readme
Interrupt::USBD.set_priority(Priority::
Interrupt::POWER_CLOCK.set_priority(Priority::P2);
Here are all my enabled interrupts:
Interrupt 0: Enabled = true, Priority = P2
└─ src/main.rs:197
Interrupt 6: Enabled = true, Priority = P2
└─ src/main.rs:197
Interrupt 17: Enabled = true, Priority = P2
└─ src/main.rs:197
Interrupt 39: Enabled = true, Priority = P2
└─ src/main.rs:197
But I still get the exact same panic
POWER_CLOCK is reserved to the softdevice. If you want to use VBUS detect must do it through the softdevice's SoC events, not directly with POWER.
oh so the softdevice exports events instead of interrupts to be able to use such functionality can you give me an example on how to setup the nrf driver to use events?
there's no example (PRs welcome!). You'd do it with this, calling the methods there when the events fire: https://docs.embassy.dev/embassy-nrf/git/nrf52840/usb/vbus_detect/struct.SoftwareVbusDetect.html
At this point I'm too bored to do a PR but I'll come back
For now to make it work you need:
lazy_static! {
pub static ref VBUS_DETECT: SoftwareVbusDetect = SoftwareVbusDetect::new(false, false);
}
#[task]
async fn softdevice_task(sd: &'static Softdevice) {
info!("SoftDevice task started");
sd.run_with_callback(|event: SocEvent| {
info!("SoftDevice event: {:?}", event);
match event {
SocEvent::PowerUsbRemoved => VBUS_DETECT.detected(false),
SocEvent::PowerUsbDetected => VBUS_DETECT.detected(true),
SocEvent::PowerUsbPowerReady => VBUS_DETECT.ready(),
_ => {}
};
}).await;
info!("SoftDevice task finished");
}
#[embassy_executor::main]
async fn main(spawner: Spawner) {
...
let driver = Driver::new(p.USBD, Irqs, &*VBUS_DETECT);
...
let sd = Softdevice::enable(Default::default());
spawner.spawn(softdevice_task(sd)).unwrap();
}
I'm omitting any code covered by the readme
Thanks for sharing your solution @dzervas. For anyone in the future implementing SoftwareVbusDetect, it looks like you may need to enable these events in the soft device (can't find anything in the soft device documentation that says what their default state is).
Here's an example where those events are explicitly enabled: https://github.com/matoushybl/air-force-one/blob/9dab9a5785fb3a71890e25806152a8e5846b1d1b/bridge-fw/src/main.rs#L294-L297 And the relevant documentation (at least for my version of the soft device): https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.s140.api.v7.3.0%2Fgroup___n_r_f___s_o_c___f_u_n_c_t_i_o_n_s.html&cp=5_7_4_1_2_7_2_27&anchor=gadf77ee1a740e17981163be1903a96f10
I'm trying to at least get softdevice enabled but I stumble upon this panic error
I know that it's relevant to #16 and #18 but I'm not sure how to solve it. I don't use RTIC.
My target is an nrf52840 and the code about the SoftDevice is:
I'm almost sure that something's wrong with my features. Here are my deps and features:
Shouldn't the interrupts be enabled by default?