You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The code below crashes on an ESP32 (ESP-WROOM-32) with the exception below.
The issue seems to be the f32/float operation in the "read_sensor_data()" function, while being connected to a wifi.
If I remove the wifi part or set invalid wifi connection data, it performs the floating point operations normally.
Exception occurred 'Cp0Disabled (Access to the floating point coprocessor is not allowed. You may want to enable the `float-save-restore` feature of the `xtensa-lx-rt` crate.)'
Context
PC=0x400f00b7 PS=0x00060930
0x400f00b7 - core::f32::<impl f32>::abs_private
at /home/foobar/.rustup/toolchains/esp/lib/rustlib/src/rust/library/core/src/num/f32.rs:533
0x00060930 - PS_WOE
at ??:??
A0=0x800ee5d5 A1=0x3ffdab00 A2=0x3ffdb638 A3=0x3ffdab30 A4=0x00000000
0x800ee5d5 - _rtc_slow_bss_start
at ??:??
0x3ffdab00 - __stack_chk_guard
at ??:??
0x3ffdb638 - __stack_chk_guard
at ??:??
0x3ffdab30 - __stack_chk_guard
at ??:??
0x00000000 - <esp32::RMT as core::fmt::Debug>::fmt
at /home/foobar/.cargo/registry/src/index.crates.io-6f17d22bba15001f/esp32-0.33.0/src/lib.rs:1533
A5=0x0006ffff A6=0x00000000 A7=0x00000001 A8=0x00000001 A9=0x4442accd
0x0006ffff - PS_WOE
at ??:??
0x00000000 - <esp32::RMT as core::fmt::Debug>::fmt
at /home/foobar/.cargo/registry/src/index.crates.io-6f17d22bba15001f/esp32-0.33.0/src/lib.rs:1533
0x00000001 - <esp32::RMT as core::fmt::Debug>::fmt
at /home/foobar/.cargo/registry/src/index.crates.io-6f17d22bba15001f/esp32-0.33.0/src/lib.rs:1533
0x00000001 - <esp32::RMT as core::fmt::Debug>::fmt
at /home/foobar/.cargo/registry/src/index.crates.io-6f17d22bba15001f/esp32-0.33.0/src/lib.rs:1533
0x4442accd - wDev_GetNoiseFloor
at ??:??
A10=0x7fffffff A11=0x00000000 A12=0x00000000 A13=0x3ffdbd50 A14=0x00000010
0x7fffffff - _rtc_slow_bss_start
at ??:??
0x00000000 - <esp32::RMT as core::fmt::Debug>::fmt
at /home/foobar/.cargo/registry/src/index.crates.io-6f17d22bba15001f/esp32-0.33.0/src/lib.rs:1533
0x00000000 - <esp32::RMT as core::fmt::Debug>::fmt
at /home/foobar/.cargo/registry/src/index.crates.io-6f17d22bba15001f/esp32-0.33.0/src/lib.rs:1533
0x3ffdbd50 - __stack_chk_guard
at ??:??
0x00000010 - <esp32::RMT as core::fmt::Debug>::fmt
at /home/foobar/.cargo/registry/src/index.crates.io-6f17d22bba15001f/esp32-0.33.0/src/lib.rs:1534
A15=0x00000001
0x00000001 - <esp32::RMT as core::fmt::Debug>::fmt
at /home/foobar/.cargo/registry/src/index.crates.io-6f17d22bba15001f/esp32-0.33.0/src/lib.rs:1533
SAR=00000004
EXCCAUSE=0x00000020 EXCVADDR=0x00000000
0x00000020 - <esp32::RMT as core::fmt::Debug>::fmt
at /home/foobar/.cargo/registry/src/index.crates.io-6f17d22bba15001f/esp32-0.33.0/src/lib.rs:1535
0x00000000 - <esp32::RMT as core::fmt::Debug>::fmt
at /home/foobar/.cargo/registry/src/index.crates.io-6f17d22bba15001f/esp32-0.33.0/src/lib.rs:1533
LBEG=0x4000c28c LEND=0x4000c296 LCOUNT=0x00000000
0x4000c28c - memcmp
at ??:??
0x4000c296 - memcmp
at ??:??
0x00000000 - <esp32::RMT as core::fmt::Debug>::fmt
at /home/foobar/.cargo/registry/src/index.crates.io-6f17d22bba15001f/esp32-0.33.0/src/lib.rs:1533
THREADPTR=0x00000000
0x00000000 - <esp32::RMT as core::fmt::Debug>::fmt
at /home/foobar/.cargo/registry/src/index.crates.io-6f17d22bba15001f/esp32-0.33.0/src/lib.rs:1533
SCOMPARE1=0x00000003
0x00000003 - <esp32::RMT as core::fmt::Debug>::fmt
at /home/foobar/.cargo/registry/src/index.crates.io-6f17d22bba15001f/esp32-0.33.0/src/lib.rs:1533
BR=0x00000000
0x00000000 - <esp32::RMT as core::fmt::Debug>::fmt
at /home/foobar/.cargo/registry/src/index.crates.io-6f17d22bba15001f/esp32-0.33.0/src/lib.rs:1533
ACCLO=0x00000000 ACCHI=0x00000000
0x00000000 - <esp32::RMT as core::fmt::Debug>::fmt
at /home/foobar/.cargo/registry/src/index.crates.io-6f17d22bba15001f/esp32-0.33.0/src/lib.rs:1533
0x00000000 - <esp32::RMT as core::fmt::Debug>::fmt
at /home/foobar/.cargo/registry/src/index.crates.io-6f17d22bba15001f/esp32-0.33.0/src/lib.rs:1533
M0=0x00000000 M1=0x00000000 M2=0x00000000 M3=0x00000000
0x00000000 - <esp32::RMT as core::fmt::Debug>::fmt
at /home/foobar/.cargo/registry/src/index.crates.io-6f17d22bba15001f/esp32-0.33.0/src/lib.rs:1533
0x00000000 - <esp32::RMT as core::fmt::Debug>::fmt
at /home/foobar/.cargo/registry/src/index.crates.io-6f17d22bba15001f/esp32-0.33.0/src/lib.rs:1533
0x00000000 - <esp32::RMT as core::fmt::Debug>::fmt
at /home/foobar/.cargo/registry/src/index.crates.io-6f17d22bba15001f/esp32-0.33.0/src/lib.rs:1533
0x00000000 - <esp32::RMT as core::fmt::Debug>::fmt
at /home/foobar/.cargo/registry/src/index.crates.io-6f17d22bba15001f/esp32-0.33.0/src/lib.rs:1533
F64R_LO=0x3ffdab10 F64R_HI=0x632a07e3 F64S=0x00000002
0x3ffdab10 - __stack_chk_guard
at ??:??
0x632a07e3 - _rtc_slow_bss_start
at ??:??
0x00000002 - <esp32::RMT as core::fmt::Debug>::fmt
at /home/foobar/.cargo/registry/src/index.crates.io-6f17d22bba15001f/esp32-0.33.0/src/lib.rs:1533
FCR=0x3f409e3e FSR=0x00000005
0x3f409e3e - anon.98cb325b9f2c8a025c2833ff4d43dbdd.7.llvm.9682373318355679123
at ??:??
0x00000005 - <esp32::RMT as core::fmt::Debug>::fmt
at /home/foobar/.cargo/registry/src/index.crates.io-6f17d22bba15001f/esp32-0.33.0/src/lib.rs:1533
F0=0x3f4014c1 F1=0x00000004 F2=0x3f409e54 F3=0x00000005 F4=0x3ffdaab8
0x3f4014c1 - anon.9515259f68c3fedf326c00a7d8f5849f.4.llvm.2516482696797543646
at ??:??
0x00000004 - <esp32::RMT as core::fmt::Debug>::fmt
at /home/foobar/.cargo/registry/src/index.crates.io-6f17d22bba15001f/esp32-0.33.0/src/lib.rs:1533
0x3f409e54 - anon.98cb325b9f2c8a025c2833ff4d43dbdd.7.llvm.9682373318355679123
at ??:??
0x00000005 - <esp32::RMT as core::fmt::Debug>::fmt
at /home/foobar/.cargo/registry/src/index.crates.io-6f17d22bba15001f/esp32-0.33.0/src/lib.rs:1533
0x3ffdaab8 - __stack_chk_guard
at ??:??
F5=0x00000004 F6=0x00000000 F7=0x00000000 F8=0x3ffdaa90 F9=0x400ef64c
0x00000004 - <esp32::RMT as core::fmt::Debug>::fmt
at /home/foobar/.cargo/registry/src/index.crates.io-6f17d22bba15001f/esp32-0.33.0/src/lib.rs:1533
0x00000000 - <esp32::RMT as core::fmt::Debug>::fmt
at /home/foobar/.cargo/registry/src/index.crates.io-6f17d22bba15001f/esp32-0.33.0/src/lib.rs:1533
0x00000000 - <esp32::RMT as core::fmt::Debug>::fmt
at /home/foobar/.cargo/registry/src/index.crates.io-6f17d22bba15001f/esp32-0.33.0/src/lib.rs:1533
0x3ffdaa90 - __stack_chk_guard
at ??:??
0x400ef64c - <&T as core::fmt::Display>::fmt
at /home/foobar/.rustup/toolchains/esp/lib/rustlib/src/rust/library/core/src/fmt/mod.rs:2368
F10=0x3ffdaadc F11=0x400e35a0 F12=0x3ffdaae0 F13=0x400e332c F14=0x3ffdaa98
0x3ffdaadc - __stack_chk_guard
at ??:??
0x400e35a0 - log::Level::as_str
at /home/foobar/.cargo/registry/src/index.crates.io-6f17d22bba15001f/log-0.4.22/src/lib.rs:566
0x3ffdaae0 - __stack_chk_guard
at ??:??
0x400e332c - <&T as core::fmt::Display>::fmt
at /home/foobar/.rustup/toolchains/esp/lib/rustlib/src/rust/library/core/src/fmt/mod.rs:2368
0x3ffdaa98 - __stack_chk_guard
at ??:??
F15=0x400ef64c
0x400ef64c - <&T as core::fmt::Display>::fmt
at /home/foobar/.rustup/toolchains/esp/lib/rustlib/src/rust/library/core/src/fmt/mod.rs:2368
0x400e3404
0x400e3404 - <&mut W as core::fmt::Write::write_fmt::SpecWriteFmt>::spec_write_fmt
at /home/foobar/.rustup/toolchains/esp/lib/rustlib/src/rust/library/core/src/fmt/mod.rs:230
0x400d4b64
0x400d4b64 - test::read_sensor_data::{{closure}}
at ??:??
0x400ede2b
0x400ede2b - embassy_executor::raw::util::SyncUnsafeCell<T>::get
at /home/foobar/.cargo/registry/src/index.crates.io-6f17d22bba15001f/embassy-executor-0.6.0/src/raw/util.rs:55
0x400d3d42
0x400d3d42 - esp_hal_embassy::executor::thread::Executor::run
at /home/foobar/.cargo/registry/src/index.crates.io-6f17d22bba15001f/esp-hal-embassy-0.3.0/src/executor/thread.rs:126
0x400d44e2
0x400d44e2 - main
at ??:??
0x400e1e6d
0x400e1e6d - Reset
at ??:??
0x400e1582
0x400e1582 - ESP32Reset
at ??:??
To Reproduce
set SSID and SSID_PW environment variables for your wifi
Use an ESP32 uC and flash the following source
monitor the serial connection and wait for the exception above
#![no_std]#![no_main]#![feature(type_alias_impl_trait)]#![feature(impl_trait_in_assoc_type)]use embassy_executor::Spawner;use embassy_net::{Config,Stack,StackResources};use embassy_time::{Duration,Timer};use esp_backtrace as _;use esp_hal::{
clock::ClockControl, peripherals::Peripherals, rng::Rng, system::SystemControl,
timer::timg::TimerGroup,};use esp_println::println;use esp_wifi::{
initialize,
wifi::{
new_with_mode,ClientConfiguration,Configuration,WifiController,WifiDevice,WifiEvent,WifiStaDevice,WifiState,},EspWifiInitFor,};use log::info;constSSID:&str = env!("SSID");constPASSWORD:&str = env!("SSID_PW");macro_rules! mk_static {($t:ty,$val:expr) => {{staticSTATIC_CELL: static_cell::StaticCell<$t> = static_cell::StaticCell::new();
#[deny(unused_attributes)]let x = STATIC_CELL.uninit().write(($val));
x
}};}#[esp_hal_embassy::main]asyncfnmain(spawner:Spawner){
esp_println::logger::init_logger_from_env();
esp_println::println!("Init!");let peripherals = Peripherals::take();let system = SystemControl::new(peripherals.SYSTEM);let clocks = ClockControl::boot_defaults(system.clock_control).freeze();let timg0 = TimerGroup::new(peripherals.TIMG0,&clocks);
esp_hal_embassy::init(&clocks, timg0.timer1);let init = initialize(EspWifiInitFor::Wifi,
timg0.timer0,Rng::new(peripherals.RNG),
peripherals.RADIO_CLK,&clocks,).unwrap();let wifi = peripherals.WIFI;let(wifi_interface, controller) = new_with_mode(&init, wifi,WifiStaDevice).unwrap();let dhcpconfig = Config::dhcpv4(Default::default());let seed = 1234;// very random, very secure seedlet stack:&'static Stack<WifiDevice<'_,WifiStaDevice>> = mk_static!(Stack<WifiDevice<'_, WifiStaDevice>>,
Stack::new(
wifi_interface,
dhcpconfig,
mk_static!(StackResources<3>, StackResources::<3>::new()),
seed
));
spawner.spawn(connection(controller)).unwrap();
spawner.spawn(net_task(stack)).unwrap();read_sensor_data().await;}asyncfnread_sensor_data(){//This part crashes when there is a wifi connection.info!("Perform some floating point operation");loop{Timer::after(Duration::from_secs(5)).await;let f = 12.0;let g = 83u16 << 3;let rel_humidity = ((4asu16) << 8 | (3asu16))asf32 / 10.0f32;println!("{:?}", f + (g asf32) + (rel_humidity asf32));}}#[embassy_executor::task]pubasyncfnconnection(mutcontroller:WifiController<'static>){println!("start connection task");println!("Device capabilities: {:?}", controller.get_capabilities());loop{match esp_wifi::wifi::get_wifi_state(){WifiState::StaConnected => {// wait until we're no longer connected
controller.wait_for_event(WifiEvent::StaDisconnected).await;Timer::after(Duration::from_millis(5000)).await}
_ => {}}if !matches!(controller.is_started(), Ok(true)){let client_config = Configuration::Client(ClientConfiguration{ssid:SSID.try_into().unwrap(),password:PASSWORD.try_into().unwrap(),
..Default::default()});
controller.set_configuration(&client_config).unwrap();println!("Starting wifi");
controller.start().await.unwrap();println!("Wifi started!");}println!("About to connect...");match controller.connect().await{Ok(_) => println!("Wifi connected!"),Err(e) => {println!("Failed to connect to wifi: {e:?}");Timer::after(Duration::from_millis(5000)).await}}}}#[embassy_executor::task]pubasyncfnnet_task(stack:&'static embassy_net::Stack<WifiDevice<'static,WifiStaDevice>>){
stack.run().await}
Expected behavior
The floating-point operation succeeds without an exception.
ByteMaDo
changed the title
Floating point operation crashes with "Exception occurred 'Cp0Disabled'" while connected to a Wifi
Floating point operation crashes with "Exception occurred 'Cp0Disabled'" while connected to wifi
Sep 24, 2024
Woa, I've wasted three hours on this and double-checked the Cargo.toml three times - but missed this completely...
Now it's working like a charm :-D
Thank you!
Bug description
The code below crashes on an ESP32 (ESP-WROOM-32) with the exception below.
The issue seems to be the f32/float operation in the "read_sensor_data()" function, while being connected to a wifi.
If I remove the wifi part or set invalid wifi connection data, it performs the floating point operations normally.
To Reproduce
Expected behavior
The floating-point operation succeeds without an exception.
Environment
The text was updated successfully, but these errors were encountered: