Closed mawoka-myblock closed 3 days ago
Did you increase the default stack size of your main task? You can do that by changing the according value in your sdkconfig file. Otherwise you spawn a thread that has a appropriated stack_size set on spawning with the std::thread api. Keep in mind that the default stack size is only ~3kb
Sorry for annoying, but how do I do that, how's the parameter called?
Oh, nevermind, it's set to CONFIG_ESP_MAIN_TASK_STACK_SIZE=8000
. I've also increased it to CONFIG_ESP_MAIN_TASK_STACK_SIZE=20000
but it didn't make any difference.
Apparently you either did not increase it, or you have to increase it even more.
But the error can't be any clearer than that:
Guru Meditation Error: Core 0 panic'ed (Stack protection fault)
Two more suggestions:
async-io-mini
(there is such a feature in edge-nal-std
) uses less stackasync-io
. The main thread has a too low priority so the main thread will constantly starve. Spawn a separate thread (and set a bigger stack size programmatically)Oh, one more thing: if you stick with the stock async-io
, you need to increase the pthreads' stack sizes too, as async-io
spins a hidden pthread thread too. Look at the esp-idf-template
generated project for the pthread stack size conf.
Okay, I now got this code:
let handle = thread::Builder::new()
.stack_size(100 * 1024)
.spawn(move ||{smol_block_on(edge_captive::io::run(
&stack,
edge_captive::io::DEFAULT_SOCKET,
&mut tx,
&mut rx,
Ipv4Addr::new(192, 168, 0, 1),
Duration::from_secs(60),
)).unwrap()}).unwrap();
To my understanding, this spawns a new thread with 100KB memory, right? If I go above the 100KB, It throws an OutOfMemory. Like this, it's still a core panic. How high does the stack size has to be? This seems to me like it's way too much memory used for the captive portal part.
Oh, one more thing: if you stick with the stock
async-io
, you need to increase the pthreads' stack sizes too, asasync-io
spins a hidden pthread thread too. Look at theesp-idf-template
generated project for the pthread stack size conf.
Did you also read this?
I did, though I misread it. Turns out, setting CONFIG_PTHREAD_TASK_STACK_SIZE_DEFAULT=10000
made the code above work with adding vfs::initialize_eventfd(5).unwrap();
. This is fixed, though a note about increasing the PTHREAD stack size would be awesome! Still many thanks for the lightning fast replies here!
This is fixed, though a note about increasing the PTHREAD stack size would be awesome!
I'm a bit unsure how far deep the esp-rs
rabbit hole we have to go in the edge-*
crates. The thing is, they are supposed to work on any MCU, not just Espressif's, and not just with ESP-IDF.
But maybe I can add something generic in the readme w.r.t. stack-sizes, and then refer to the ESP-IDF docu or something
Still many thanks for the lightning fast replies here!
Always welcome!
ESP's logs:
main.rs
```rust #![feature(iter_intersperse)] use std::borrow::Cow; use std::net::Ipv4Addr; use std::str::FromStr; use core::time::Duration; use embedded_hal::delay::DelayNs; use esp_idf_svc::hal::sys::nvs_flash_init; use esp_idf_svc::hal::task::block_on; use esp_idf_svc::http::server::EspHttpServer; use esp_idf_svc::http::Method; use esp_idf_svc::io::Write; use esp_idf_svc::ipv4::{ ClientConfiguration as IpClientConfiguration, ClientSettings as IpClientSettings, Configuration as IpConfiguration, Mask, RouterConfiguration, Subnet, }; use esp_idf_svc::netif::{EspNetif, NetifConfiguration, NetifStack}; use esp_idf_svc::nvs::EspDefaultNvsPartition; use esp_idf_svc::timer::EspTaskTimerService; use esp_idf_svc::wifi::{ AccessPointConfiguration, AsyncWifi, BlockingWifi, Configuration, EspWifi, WifiDeviceId, WifiDriver, }; use esp_idf_svc::{ eventloop::EspSystemEventLoop, hal::{ delay::FreeRtos, i2c::{I2cConfig, I2cDriver}, peripherals::Peripherals, prelude::*, reset, }, }; use log::{info, warn}; use smol::block_on as smol_block_on; use smol::io; use smol_macros::main; // use wifi::get; mod dns; mod led; mod wifi; main! { async fn main() -> io::Result<()> { // It is necessary to call this function once. Otherwise some patches to the runtime // implemented by esp-idf-sys might not link properly. See https://github.com/esp-rs/esp-idf-template/issues/71 esp_idf_svc::sys::link_patches(); // Bind the log crate to the ESP Logging facilities esp_idf_svc::log::EspLogger::initialize_default(); let peripherals = Peripherals::take().unwrap(); let sysloop = EspSystemEventLoop::take().unwrap(); // let app_config = CONFIG; let nvs = EspDefaultNvsPartition::take().unwrap(); let timer_service = EspTaskTimerService::new().unwrap(); let driver = EspWifi::new(peripherals.modem, sysloop.clone(), Some(nvs)).unwrap(); let mut wifi = AsyncWifi::wrap(driver, sysloop, timer_service).unwrap(); let stack = edge_nal_std::Stack::new(); let mut tx = [0; 1500]; let mut rx = [0; 1500]; // let http_server = block_on(start_http()).unwrap(); smol_block_on(edge_captive::io::run( &stack, edge_captive::io::DEFAULT_SOCKET, &mut tx, &mut rx, Ipv4Addr::new(192, 168, 0, 1), Duration::from_secs(60), )).unwrap(); // block_on(start_ap(&mut wifi)).unwrap(); loop { FreeRtos.delay_ms(500); } } ```Cargo.toml
```toml [package] name = "td-free-rs" version = "0.1.0" authors = ["MawokaIt doesn't matter whether I use
smol::block_on
oresp_idf_svc::hal::task::block_on