Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Activate softdevice #183

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions firmware/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@ rust-version.workspace = true


[features]
default = [
"mcu-esp32c3",
"imu-stubbed",
"log-rtt",
"net-wifi",
"fusion-stubbed",
]
# default = [
# "mcu-nrf52840",
# "mcu-esp32c3",
# "imu-stubbed",
# "log-rtt",
# "net-stubbed",
# "net-wifi",
# "fusion-stubbed",
# "nrf-boot-s140",
# ]
default = [
"mcu-nrf52840",
"imu-stubbed",
"log-rtt",
"net-ble",
"fusion-stubbed",
"nrf-boot-s140",
]
# default = ["mcu-esp32", "imu-stubbed", "log-uart", "net-wifi", "fusion-stubbed"]

# Supported microcontrollers
Expand Down Expand Up @@ -67,9 +67,9 @@ mcu-nrf52832 = [
]

# Wi-fi dependencies
net-wifi = ["esp-wifi/wifi", "dep:smoltcp"] # use wifi
net-ble = ["esp-wifi/ble", "dep:bleps", "dep:bleps-macros"]
net-stubbed = [] # Stubs out network
net-wifi = ["esp-wifi/wifi", "dep:smoltcp"] # use wifi
net-ble = ["esp-wifi?/ble", "dep:bleps", "dep:bleps-macros"]
net-stubbed = [] # Stubs out network

# Supported IMUs
imu-bmi160 = []
Expand Down
2 changes: 1 addition & 1 deletion firmware/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl MemoryLayout {
const S140: MemoryLayout = MemoryLayout {
mbr_size: 0x1000,
sd_flash_size: 0x26000,
sd_ram_size: 0x8,
sd_ram_size: 50_000,
};
/// Softdevice 132.
const S132: MemoryLayout = MemoryLayout {
Expand Down
6 changes: 2 additions & 4 deletions firmware/crates/panic_defmt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ fn panic(info: &core::panic::PanicInfo) -> ! {
if let Some(location) = info.location() {
let (file, line, column) =
(location.file(), location.line(), location.column());
error!(
"A panic occured in '{}', at line {}, column {}",
file, line, column
);
error!("Panic in '{}'", file);
error!("Panic was at line {}, column {}", line, column);
} else {
error!("A panic occured at an unknown location");
}
Expand Down
5 changes: 5 additions & 0 deletions firmware/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,13 @@ fn main() -> ! {
.unwrap();
s.spawn(crate::networking::network_task(packets)).unwrap();
s.spawn(crate::imu::imu_task(quat, p.i2c, p.delay)).unwrap();

#[cfg(bbq)]
s.spawn(logger_task(bbq, bbq_peripheral)).unwrap();

#[cfg(any(feature = "nrf-boot-s140", feature = "nrf-boot-s132"))]
s.spawn(crate::networking::ble::ඞ::softdevice_task())
.unwrap()
});
}

Expand Down
6 changes: 5 additions & 1 deletion firmware/src/networking/ble/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#[cfg(feature = "net-ble")]
#[cfg(mcu_f_esp32)]
#[path = "esp.rs"]
pub mod ඞ;

#[cfg(mcu_f_nrf52)]
#[path = "nrf.rs"]
pub mod ඞ;
36 changes: 36 additions & 0 deletions firmware/src/networking/ble/nrf.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use defmt::{debug, error};
use embassy_futures::yield_now;
use embassy_time::Duration;
use nrf_softdevice::Softdevice;

use crate::networking::protocol::Packets;

pub async fn network_task(_packets: &Packets) -> ! {
debug!("Starting BLE loop");
loop {
yield_now().await;
}
}

#[embassy_executor::task]
pub async fn softdevice_task() -> ! {
error!("softdevice task");
embassy_time::Timer::after(Duration::from_millis(1000)).await;

#[cfg(any(feature = "nrf-boot-s140", feature = "nrf-boot-s132"))]
let sd = crate::networking::ble::ඞ::init_softdevice().await;
error!("after init");

embassy_time::Timer::after(Duration::from_millis(1000)).await;
sd.run().await
}

pub async fn init_softdevice() -> &'static mut Softdevice {
let config = nrf_softdevice::Config::default();
error!("after config");

embassy_time::Timer::after(Duration::from_millis(1000)).await;
let sd = Softdevice::enable(&config);
error!("enabled softdevice");
sd
}
15 changes: 14 additions & 1 deletion firmware/src/peripherals/nrf52.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use crate::aliases::ඞ::UsbDriverConcrete;

use defmt::debug;
use embassy_nrf::interrupt;
use embassy_nrf::interrupt::InterruptExt;
use embassy_nrf::interrupt::Priority;
use embassy_nrf::twim::{self, Twim};
use embassy_nrf::uarte::{self, Uarte};
use paste::paste;
Expand All @@ -24,7 +26,14 @@ pub fn get_peripherals() -> Peripherals<
UartConcrete<'static>,
UsbDriverConcrete<'static>,
> {
let p = embassy_nrf::init(Default::default());
// With softdevice, certain interrupt priorities are used by softdevice.
// https://github.com/embassy-rs/nrf-softdevice#interrupt-priority
//
// We therefore have to set interrupt priorities manually.
let mut cfg = embassy_nrf::config::Config::default();
// cfg.gpiote_interrupt_priority = Priority::P2;
cfg.time_interrupt_priority = Priority::P2;
let p = embassy_nrf::init(cfg);

// Fix issue on rev 3 boards where AP is protected, preventing debugging/rtt.
#[cfg(feature = "mcu-nrf52840")] // TODO: Add nrf52832 support
Expand Down Expand Up @@ -111,6 +120,7 @@ pub fn get_peripherals() -> Peripherals<
let twim = {
let config = twim::Config::default();
let irq = interrupt::take!(SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0);
irq.set_priority(Priority::P3);
Twim::new(
p.TWISPI0,
irq,
Expand All @@ -126,6 +136,7 @@ pub fn get_peripherals() -> Peripherals<

let uarte = {
let irq = interrupt::take!(UARTE0_UART0);
irq.set_priority(Priority::P3);
let mut config = uarte::Config::default();
config.parity = uarte::Parity::EXCLUDED;
config.baudrate = uarte::Baudrate::BAUD115200;
Expand All @@ -142,7 +153,9 @@ pub fn get_peripherals() -> Peripherals<
let usb_driver = {
use embassy_nrf::usb::{self, Driver};
let irq = interrupt::take!(USBD);
irq.set_priority(Priority::P3);
let power_irq = interrupt::take!(POWER_CLOCK);
power_irq.set_priority(Priority::P3);
let d = Driver::new(p.USBD, irq, usb::PowerUsb::new(power_irq));
debug!("Initialized usb_driver");
d
Expand Down