cargo: update to esp-hal 1.0, and use esp-radio for less crashes

This commit is contained in:
2025-12-07 14:58:07 +01:00
parent b64678cff3
commit 83ecdb61b2
6 changed files with 404 additions and 332 deletions

584
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -15,7 +15,7 @@ real-output = []
simulation = ["dep:rmp"]
radio = [
"dep:bleps",
"dep:esp-wifi",
"dep:esp-radio",
"dep:reqwless"
]
motion = ["mpu", "gps"]
@@ -31,36 +31,37 @@ demo = []
# The basic requirements for all features
figments = { path = "../figments/figments/", features = ["alloc", "embedded-graphics"] }
figments-render = { path = "../figments/figments-render/", features = ["smart-leds", "micromath"], default-features = false }
esp-bootloader-esp-idf = { version = "0.2.0", features = ["esp32s3"] }
esp-hal = { version = "=1.0.0-rc.0", features = [
esp-bootloader-esp-idf = { version = "0.4.0", features = ["esp32s3"] }
esp-hal = { version = "1.0.0", features = [
"esp32s3",
"log-04",
"unstable",
] }
esp-alloc = "0.8.0"
esp-backtrace = { version = "0.17.0", features = [
esp-alloc = "0.9.0"
esp-backtrace = { version = "0.18", features = [
"esp32s3",
"exception-handler",
"panic-handler",
"println",
] }
esp-println = { version = "0.15.0", features = ["esp32s3", "log-04"] }
esp-println = { version = "0.16", features = ["esp32s3", "log-04"] }
# for more networking protocol support see https://crates.io/crates/edge-net
critical-section = "1.2.0"
embassy-executor = { version = "0.7.0", features = [
embassy-executor = { version = "0.9.0", features = [
"log",
"task-arena-size-98304",
# "task-arena-size-98304",
] }
embassy-time = { version = "0.5.0", features = ["log"] }
esp-hal-embassy = { version = "0.9.0", features = [
esp-rtos = { version = "0.2.0", features = [
"esp-radio",
"embassy",
"esp-alloc",
"esp32s3",
"log-04"
] }
log = "0.4.27"
log = "0.4"
static_cell = "2.1.1"
rgb = "0.8.52"
# esp-hal-smartled = { version = "0.15.0", features = ["esp32c3"] }
esp-hal-smartled = { git = "https://github.com/esp-rs/esp-hal-community.git", features = ["esp32s3"] }
esp-hal-smartled = { version = "0.17.0", features = ["esp32s3"] }
smart-leds = "0.4.0"
embassy-sync = "0.7.2"
embassy-embedded-hal = "0.5.0"
@@ -73,13 +74,14 @@ enumset = "1.1.10"
enum-map = "2.7.3"
# Telemetry outputs
esp-wifi = { version = "0.15.0", optional = true, features = [
"builtin-scheduler",
esp-radio = { version = "*", optional = true, features = [
"esp-alloc",
"esp32s3",
"log-04",
"wifi",
"ble"
"ble",
"coex",
"unstable"
] }
bleps = { git = "https://github.com/bjoernQ/bleps", optional = true, package = "bleps", rev = "a5148d8ae679e021b78f53fd33afb8bb35d0b62e", features = [ "macros", "async"] }
embedded-graphics = { version = "0.8.1", features = ["nalgebra_support"] }

View File

@@ -18,12 +18,13 @@ use esp_hal::{
clock::CpuClock, system::{AppCoreGuard, CpuControl, Stack}, timer::{systimer::SystemTimer, timg::{TimerGroup, Wdt}}
};
use esp_hal_embassy::{Executor, InterruptExecutor};
use log::*;
use renderbug_embassy::{logging::RenderbugLogger, tasks::{oled::{OledUI, OledUiSurfacePool, oled_ui}, safetyui::{SafetyUi, safety_ui_main}, ui::UiSurfacePool}};
use renderbug_embassy::events::BusGarage;
use static_cell::StaticCell;
use esp_backtrace as _;
use esp_rtos::embassy::{Executor, InterruptExecutor};
use esp_hal::interrupt::software::SoftwareInterruptControl;
use renderbug_embassy::tasks::{
motion::motion_task,
@@ -37,14 +38,15 @@ extern crate alloc;
// For more information see: <https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/system/app_image_format.html#application-description>
esp_bootloader_esp_idf::esp_app_desc!();
static STATIC_HI_EXEC: StaticCell<InterruptExecutor<0>> = StaticCell::new();
static STATIC_HI_EXEC: StaticCell<InterruptExecutor<2>> = StaticCell::new();
static CORE2_EXEC: StaticCell<Executor> = StaticCell::new();
static BUS_GARAGE: StaticCell<BusGarage> = StaticCell::new();
static mut CORE2_STACK: Stack<16384> = Stack::new();
static CORE_HANDLE: StaticCell<AppCoreGuard> = StaticCell::new();
#[cfg(feature="radio")]
static WIFI_INIT: StaticCell<esp_radio::Controller<'static>> = StaticCell::new();
#[esp_hal_embassy::main]
#[esp_rtos::main]
async fn main(spawner: Spawner) {
critical_section::with(|_| {
RenderbugLogger::init_logger();
@@ -56,7 +58,7 @@ async fn main(spawner: Spawner) {
esp_alloc::heap_allocator!(size: 128 * 1024);
let sys_timer = SystemTimer::new(peripherals.SYSTIMER);
esp_hal_embassy::init([sys_timer.alarm0, sys_timer.alarm1, sys_timer.alarm2]);
esp_rtos::start(sys_timer.alarm0);
info!("Embassy initialized!");
let timer0 = TimerGroup::new(peripherals.TIMG0);
@@ -82,10 +84,10 @@ async fn main(spawner: Spawner) {
let mut wdt = timer0.wdt;
wdt.set_timeout(esp_hal::timer::timg::MwdtStage::Stage0, esp_hal::time::Duration::from_secs(5));
let swi = SoftwareInterruptControl::new(peripherals.SW_INTERRUPT);
let hi_exec = STATIC_HI_EXEC.init(InterruptExecutor::new(swi.software_interrupt0));
let hi_exec = STATIC_HI_EXEC.init(InterruptExecutor::new(swi.software_interrupt2));
let hi_spawn = hi_exec.start(esp_hal::interrupt::Priority::max());
wdt.enable();
//wdt.enable();
hi_spawn.must_spawn(renderbug_embassy::tasks::render::render(peripherals.RMT, peripherals.GPIO5.degrade(), surfaces, safety_surfaces, garage.display.clone(), wdt));
#[cfg(feature="motion")]
@@ -97,8 +99,8 @@ async fn main(spawner: Spawner) {
static I2C_BUS: StaticCell<Mutex<CriticalSectionRawMutex, I2c<'static, Async>>> = StaticCell::new();
info!("Launching i2c sensor tasks");
let sda = peripherals.GPIO3;
let scl = peripherals.GPIO4;
let sda = peripherals.GPIO4;
let scl = peripherals.GPIO3;
let i2c = I2c::new(peripherals.I2C1, Config::default()).unwrap().with_scl(scl).with_sda(sda).into_async();
let i2c_bus = I2C_BUS.init(Mutex::new(i2c));
#[cfg(feature="mpu")]
@@ -148,48 +150,44 @@ async fn main(spawner: Spawner) {
#[cfg(feature="radio")]
let wifi_init = {
info!("Configuring wifi");
static WIFI_INIT: StaticCell<esp_wifi::EspWifiController<'static>> = StaticCell::new();
let rng = esp_hal::rng::Rng::new(peripherals.RNG);
WIFI_INIT.init_with(|| {esp_wifi::init(timer0.timer0, rng).expect("Failed to initialize radio controller")})
//let rng = esp_hal::rng::Rng::new(peripherals.RNG);
WIFI_INIT.init_with(|| {esp_radio::init().expect("Failed to initialize radio controller")})
};
info!("Starting core 2");
let mut cpu_control = CpuControl::new(peripherals.CPU_CTRL);
CORE_HANDLE.init_with(|| {
cpu_control.start_app_core(unsafe { &mut *addr_of_mut!(CORE2_STACK) }, || {
let exec = CORE2_EXEC.init_with(|| { Executor::new() });
exec.run(|spawner| {
info!("Launching Safety UI");
spawner.must_spawn(safety_ui_main(garage.notify.dyn_subscriber().unwrap(), safety_ui));
info!("Launching UI");
spawner.must_spawn(ui_main(garage.notify.dyn_subscriber().unwrap(), garage.telemetry.dyn_publisher().unwrap(), ui));
info!("Launching OLED UI");
spawner.must_spawn(oled_ui(garage.telemetry.dyn_subscriber().unwrap(), oledui));
//let mut cpu_control = CpuControl::new(peripherals.CPU_CTRL);
esp_rtos::start_second_core(peripherals.CPU_CTRL, swi.software_interrupt0, swi.software_interrupt1, unsafe { &mut *addr_of_mut!(CORE2_STACK) }, || {
let exec = CORE2_EXEC.init_with(|| { Executor::new() });
exec.run(|spawner| {
info!("Launching Safety UI");
spawner.must_spawn(safety_ui_main(garage.notify.dyn_subscriber().unwrap(), safety_ui));
info!("Launching UI");
spawner.must_spawn(ui_main(garage.notify.dyn_subscriber().unwrap(), garage.telemetry.dyn_publisher().unwrap(), ui));
info!("Launching OLED UI");
spawner.must_spawn(oled_ui(garage.telemetry.dyn_subscriber().unwrap(), oledui));
#[cfg(feature="radio")]
{
info!("Launching networking stack");
spawner.must_spawn(renderbug_embassy::tasks::wifi::wireless_task(garage.telemetry.dyn_subscriber().unwrap(), wifi_init, peripherals.WIFI));
}
#[cfg(feature="radio")]
{
info!("Launching networking stack");
spawner.must_spawn(renderbug_embassy::tasks::wifi::wireless_task(garage.telemetry.dyn_subscriber().unwrap(), wifi_init, peripherals.WIFI));
}
#[cfg(feature="demo")]
{
warn!("Launching with demo sequencer");
spawner.must_spawn(renderbug_embassy::tasks::demo::demo_task(garage.notify.dyn_publisher().unwrap()));
}
#[cfg(not(feature="demo"))]
{
info!("Launching prediction engine");
spawner.must_spawn(renderbug_embassy::tasks::predict::prediction_task(garage.predict.dyn_receiver(), garage.notify.dyn_publisher().unwrap(), garage.telemetry.dyn_publisher().unwrap()));
}
#[cfg(feature="demo")]
{
warn!("Launching with demo sequencer");
spawner.must_spawn(renderbug_embassy::tasks::demo::demo_task(garage.notify.dyn_publisher().unwrap()));
}
#[cfg(not(feature="demo"))]
{
info!("Launching prediction engine");
spawner.must_spawn(renderbug_embassy::tasks::predict::prediction_task(garage.predict.dyn_receiver(), garage.notify.dyn_publisher().unwrap(), garage.telemetry.dyn_publisher().unwrap()));
}
info!("Launching core 2 watchdog");
spawner.must_spawn(wdt_task(ui_wdt));
info!("Launching core 2 watchdog");
spawner.must_spawn(wdt_task(ui_wdt));
info!("System is ready in {}ms", Instant::now().as_millis());
});
}).unwrap()
info!("System is ready in {}ms", Instant::now().as_millis());
});
});
}

View File

@@ -29,7 +29,7 @@ fn gyro_raw_to_rads(raw: i16) -> f32 {
(raw as f32 / 16.4) * (DEG2RAD)
}
#[esp_hal::ram(rtc_fast, persistent)]
#[esp_hal::ram(unstable(rtc_fast, persistent))]
static mut MPU_WAS_CALIBRATED: u8 = 0;
#[embassy_executor::task]

View File

@@ -16,10 +16,9 @@ pub async fn render(rmt: esp_hal::peripherals::RMT<'static>, gpio: AnyPin<'stati
.expect("Failed to initialize RMT").into_async();
let rmt_channel = rmt.channel0;
let rmt_buffer = [0u32; buffer_size_async(NUM_PIXELS)];
let mut rmt_buffer = esp_hal_smartled::smart_led_buffer!(NUM_PIXELS);
//let target = SmartLedsAdapterAsync::new(rmt_channel, gpio, rmt_buffer);
let target = SmartLedsAdapterAsync::new(rmt_channel, gpio, rmt_buffer);
let target = SmartLedsAdapterAsync::new_with_color(rmt_channel, gpio, &mut rmt_buffer);
// Change this to adjust the power available; the USB spec says 500ma is the standard limit, but sometimes you can draw more from a power brick
const POWER_MA : u32 = 500;

View File

@@ -1,7 +1,8 @@
use alloc::string::ToString;
use embassy_executor::Spawner;
use embassy_sync::pubsub::DynSubscriber;
use esp_wifi::{EspWifiController, wifi::{ClientConfiguration, WifiDevice}};
use esp_radio::Controller;
use esp_radio::wifi::{ClientConfig, WifiDevice};
use log::*;
use alloc::format;
@@ -24,19 +25,17 @@ static RESOURCES: StaticCell<StackResources<5>> = StaticCell::new();
// TODO: Wifi task needs to know when there is data to upload, so it only connects when needed.
#[embassy_executor::task]
pub async fn wireless_task(mut telemetry: DynSubscriber<'static, Telemetry>, wifi_init: &'static mut EspWifiController<'static>, wifi_device: esp_hal::peripherals::WIFI<'static>) {
let (mut wifi, interfaces) = esp_wifi::wifi::new(wifi_init, wifi_device)
pub async fn wireless_task(mut telemetry: DynSubscriber<'static, Telemetry>, wifi_init: &'static mut Controller<'static>, wifi_device: esp_hal::peripherals::WIFI<'static>) {
let (mut wifi, interfaces) = esp_radio::wifi::new(wifi_init, wifi_device, esp_radio::wifi::Config::default())
.expect("Failed to initialize WIFI!");
wifi.set_configuration(&esp_wifi::wifi::Configuration::Client(
ClientConfiguration {
ssid: "The Frequency".to_string(),
auth_method: esp_wifi::wifi::AuthMethod::WPA2Personal,
password: "thepasswordkenneth".to_string(),
..Default::default()
}
wifi.set_config(&esp_radio::wifi::ModeConfig::Client(
ClientConfig::default()
.with_ssid("The Frequencey".to_string())
.with_auth_method(esp_radio::wifi::AuthMethod::Wpa2Personal)
.with_password("thepasswordkenneth".to_string())
)).unwrap();
wifi.set_mode(esp_wifi::wifi::WifiMode::Sta).unwrap();
wifi.set_power_saving(esp_wifi::config::PowerSaveMode::Maximum).unwrap();
wifi.set_mode(esp_radio::wifi::WifiMode::Sta).unwrap();
wifi.set_power_saving(esp_radio::wifi::PowerSaveMode::Maximum).unwrap();
wifi.start_async().await.unwrap();
let device = interfaces.sta;
@@ -46,7 +45,7 @@ pub async fn wireless_task(mut telemetry: DynSubscriber<'static, Telemetry>, wif
let config = Config::dhcpv4(Default::default());
let (stack, runner) = embassy_net::new(device, config, RESOURCES.init_with(|| { StackResources::new() }), seed as u64);
info!("Launching network task");
Spawner::for_current_executor().await.must_spawn(net_task(runner));
unsafe { Spawner::for_current_executor().await }.must_spawn(net_task(runner));
loop {
Backoff::from_secs(3).forever().attempt(async || {