Comments (8)
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
from nrf-softdevice.
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
from nrf-softdevice.
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
from nrf-softdevice.
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
from nrf-softdevice.
Oh great, now i start missing info in the readme... 😂
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
from nrf-softdevice.
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.
from nrf-softdevice.
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?
from nrf-softdevice.
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
from nrf-softdevice.
Related Issues (20)
- `FixedGattValue` (and other ble traits) should be provided by a separate library
- Recommendation to enable squash merges?
- Use PHY Coded as Primary PHY for advertisement HOT 1
- Connecting to an incorrect Mac address causes a "hang" due to underlying NRF_ERROR_NOT_FOUND HOT 1
- Connecting with 2M PHY HOT 4
- L2CAP Channel API Design Flaws HOT 1
- Switch examples to use default `gatts_attr_tab_size` ? HOT 1
- Add descriptor to a characteristic HOT 2
- NRF52832/S132 Freezes Upon Connection HOT 3
- There is currently no way to disable the SoftDevice HOT 2
- Softdevice peripheral clash with RNG peripheral HOT 3
- Implement `NorFlash` for `Flash` HOT 2
- Debugging HOT 1
- Store and load bond info using `nrf_softdevice::Flash` HOT 13
- Softdevice.run_with_callback never calls the callback HOT 1
- Improve defmt trace HOT 1
- Could not execute process probe-run --chip nRF52840_xxAA HOT 3
- Security connection HOT 1
- Allow to open/close a BLE pairing&bonding window HOT 4
- Flash Capacity Definition Discrepancy for nRF52832 and nRF52833 Chips HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nrf-softdevice.