cargo: update to esp-hal 1.0, and use esp-radio for less crashes
This commit is contained in:
@@ -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());
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user