I am trying to use the NRFx Softdevice controller, with Rust and the nRF5340. I have successfully initialized the library, but when I try to start to start advertising the controller hangs. I also never receive sdc_cb, or the SWI0 interrupt I have configured. Is there some missing HCI command that I have to run before I can set advertising enabled
#[cortex_m_rt::entry]
fn main() -> ! {
rtt_init_print!();
// IPCNotifier::<1, 0>::init();
rprintln!("net start");
let mut server: Server<Handler, IPCNotifier<2, 1>> = m10_ipc::server::Server::shared(Handler);
let ipc = unsafe { &*nrf5340_net_pac::IPC_NS::PTR };
unsafe {
use nrfx_softdevice_sys::*;
let clock = mpsl_clock_lfclk_cfg_t {
source: MPSL_CLOCK_LF_SRC_MPSL_CLOCK_LF_SRC_XTAL as u8,
rc_ctiv: 0,
rc_temp_ctiv: 0,
accuracy_ppm: 50,
skip_wait_lfclk_started: true, // NOTE: not sure if this is correct
};
let res = nrfx_softdevice_sys::mpsl_init(
&clock,
nrf5340_net_pac::Interrupt::SWI0.number() as i32,
Some(mpsl_fail),
);
let res = nrfx_softdevice_sys::sdc_init(Some(sdc_fail));
let res = nrfx_softdevice_sys::sdc_support_adv();
let res = nrfx_softdevice_sys::sdc_support_ext_adv();
let res = nrfx_softdevice_sys::sdc_support_le_periodic_adv();
let res = nrfx_softdevice_sys::sdc_support_slave();
let adv_params = nrfx_softdevice_sys::sdc_hci_cmd_le_set_adv_params_t {
adv_interval_min: 0x020,
adv_interval_max: 0x090,
adv_type: 0x0,
own_address_type: 0x0,
peer_address_type: 0x0,
peer_address: [0; 6],
adv_channel_map: 0x07,
adv_filter_policy: 0x00,
};
sdc_cfg_set(
SDC_DEFAULT_RESOURCE_CFG_TAG as u8,
sdc_cfg_type_SDC_CFG_TYPE_MASTER_COUNT as u8,
&sdc_cfg_t {
master_count: sdc_cfg_role_count_t {
count: SDC_DEFAULT_MASTER_COUNT as u8,
},
},
);
sdc_cfg_set(
SDC_DEFAULT_RESOURCE_CFG_TAG as u8,
sdc_cfg_type_SDC_CFG_TYPE_SLAVE_COUNT as u8,
&sdc_cfg_t {
slave_count: sdc_cfg_role_count_t {
count: SDC_DEFAULT_SLAVE_COUNT as u8,
},
},
);
let out = sdc_cfg_set(
SDC_DEFAULT_RESOURCE_CFG_TAG as u8,
sdc_cfg_type_SDC_CFG_TYPE_BUFFER_CFG as u8,
&sdc_cfg_t {
buffer_cfg: sdc_cfg_buffer_cfg_t {
tx_packet_size: SDC_DEFAULT_TX_PACKET_SIZE as u8,
rx_packet_size: SDC_DEFAULT_RX_PACKET_SIZE as u8,
tx_packet_count: SDC_DEFAULT_TX_PACKET_COUNT as u8,
rx_packet_count: SDC_DEFAULT_RX_PACKET_COUNT as u8,
},
},
);
rprintln!("set cfg res: {:?}", out);
let res = nrfx_softdevice_sys::sdc_rand_source_register(&SDC_RAND_SOURCE);
let res = nrfx_softdevice_sys::sdc_enable(Some(sdc_cb), MEMPOOL.as_mut_ptr());
rprintln!("res {:?}", res);
let c = nrfx_softdevice_sys::sdc_hci_cmd_vs_zephyr_write_bd_addr(
&sdc_hci_cmd_vs_zephyr_write_bd_addr_t {
bd_addr: [0x2, 0x1, 0x3, 0x0, 0x2, 0x2],
},
);
mpsl_low_priority_process();
IPCNotifier::<2, 1>::init();
let irq = unsafe { embassy_nrf::interrupt::IPC::steal() };
irq.unpend();
irq.set_priority(embassy_nrf::interrupt::Priority::P0);
irq.enable();
let irq = unsafe { embassy_nrf::interrupt::TIMER0::steal() };
irq.unpend();
irq.set_priority(embassy_nrf::interrupt::Priority::P0);
irq.enable();
mpsl_low_priority_process();
let params = sdc_hci_cmd_le_set_random_address_t {
random_addess: [0x2, 0, 1, 2, 3, 0x2],
};
let res = sdc_hci_cmd_le_set_random_address(¶ms);
mpsl_low_priority_process();
let res = nrfx_softdevice_sys::sdc_hci_cmd_le_set_adv_params(&adv_params);
rprintln!("adv params: {:?}", res);
mpsl_low_priority_process();
let enable_params =
nrfx_softdevice_sys::sdc_hci_cmd_le_set_adv_enable_t { adv_enable: 0x1 };
rprintln!("enable");
let res = nrfx_softdevice_sys::sdc_hci_cmd_le_set_adv_enable(&enable_params);
mpsl_low_priority_process();
rprintln!("enable adv res: {}", res);
rprintln!("test");
}
loop {
unsafe { mpsl_low_priority_process() };
}
}