How to disable WiFi from GPIO ISR for Brownout?
Posted: Wed Mar 01, 2023 10:11 pm
Hi Everyone,
I'm trying to write a brownout handler routine for my commercial project (using ESP32-WROVER IE) and I'm wondering if anyone can help me figure out how to do this. I am using internal SPIFAT, NVS, and SD FAT. I also have a second MCU on the board that is relying on the same supply being up for a similar routine.
I've written an intermediate layer on all my file IOs so that I can prevent all my code from accessing the files after the brownout is triggered. When brownout is triggered by the external comparator they should only finish the current operation.
The idea is that the circuit has enough bulk energy storage to finish any pending operations and exit cleanly. When everything goes as expected my GPIO brownout task drops clock speeds, closes files etc and I get >800ms of time (I need ~400ms). The problem is that flash operations on the internal SPI chip are slow and block all non IRAM code, including the brownout task. I've been through the menuconfig and setup the options to lower the latency/duration on the internal flash ops as much as possible already (yield during erase, and force sector erase etc.). The delay in processing the brownout uses too much power.
I want to do the following:
GPIO ISR handler in IRAM on Brownout input:
Immediately drop CPU speed and disable wifi. Don't care about clean deinit, just power consumption.
Very high priority brownout task:
Close open files etc and then go to sleep until hardware supervisor resets circuit.
I'm stuck on not understanding the low level details of how to reduce the power consumption of the wifi from that ISR in IRAM.
esp_wifi_stop() takes a long time to complete I think and also not sure if it is ISR or IRAM safe.
Should I be looking at lower layers of code? Should I be writing to registers to force things to disable and can I kill the WiFi task?
Any ideas or lessons from someone else doing the same thing would be appreciated.
Thanks.
I'm trying to write a brownout handler routine for my commercial project (using ESP32-WROVER IE) and I'm wondering if anyone can help me figure out how to do this. I am using internal SPIFAT, NVS, and SD FAT. I also have a second MCU on the board that is relying on the same supply being up for a similar routine.
I've written an intermediate layer on all my file IOs so that I can prevent all my code from accessing the files after the brownout is triggered. When brownout is triggered by the external comparator they should only finish the current operation.
The idea is that the circuit has enough bulk energy storage to finish any pending operations and exit cleanly. When everything goes as expected my GPIO brownout task drops clock speeds, closes files etc and I get >800ms of time (I need ~400ms). The problem is that flash operations on the internal SPI chip are slow and block all non IRAM code, including the brownout task. I've been through the menuconfig and setup the options to lower the latency/duration on the internal flash ops as much as possible already (yield during erase, and force sector erase etc.). The delay in processing the brownout uses too much power.
I want to do the following:
GPIO ISR handler in IRAM on Brownout input:
Immediately drop CPU speed and disable wifi. Don't care about clean deinit, just power consumption.
Very high priority brownout task:
Close open files etc and then go to sleep until hardware supervisor resets circuit.
I'm stuck on not understanding the low level details of how to reduce the power consumption of the wifi from that ISR in IRAM.
esp_wifi_stop() takes a long time to complete I think and also not sure if it is ISR or IRAM safe.
Should I be looking at lower layers of code? Should I be writing to registers to force things to disable and can I kill the WiFi task?
Any ideas or lessons from someone else doing the same thing would be appreciated.
Thanks.