Git Product home page Git Product logo

Comments (8)

aloebs29 avatar aloebs29 commented on June 28, 2024 2

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.

dzervas avatar dzervas commented on June 28, 2024 1

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.

dzervas avatar dzervas commented on June 28, 2024

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.

Dirbaio avatar Dirbaio commented on June 28, 2024

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.

dzervas avatar dzervas commented on June 28, 2024

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.

Dirbaio avatar Dirbaio commented on June 28, 2024

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.

dzervas avatar dzervas commented on June 28, 2024

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.

Dirbaio avatar Dirbaio commented on June 28, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.