Fix hardware-verified bugs: EPD stack overflow and busy-wait spin
Two crashes found flashing to real hardware: - epd_display_stream's 4KB SPI chunk buffer was a stack local, but the default main task stack (3584 bytes) is smaller than that alone -- Guru Meditation stack protection fault. Made it static instead, and bumped CONFIG_ESP_MAIN_TASK_STACK_SIZE to 8192 for headroom in the rest of the boot call chain (provisioning -> QR render -> eventually the HTTP fetch cycle all run in this one task). - epd_wait_busy() polled with a 1ms vTaskDelay, which rounds down to 0 FreeRTOS ticks at the default 100Hz tick rate -- so it never actually blocked, tight-spinning the CPU for the panel's real refresh time (15-30+s for a full-color pass) and starving the idle task long enough to trip the 5s task watchdog. Bumped to 20ms, safely >=1 tick regardless of tick rate. Also updates the EPD pin defaults to the board's actual wiring (CLK=20 MOSI=19 CS=18 DC=9 RST=10 BUSY=11), confirmed working on hardware.
This commit is contained in:
@@ -34,8 +34,14 @@ static void epd_delay_ms(uint32_t ms)
|
||||
/* BUSY: LOW = busy, HIGH = idle. */
|
||||
static void epd_wait_busy(void)
|
||||
{
|
||||
/* A full refresh on this panel can hold BUSY low for 15-30+ seconds.
|
||||
* A 1ms poll delay rounds down to 0 FreeRTOS ticks at the default
|
||||
* 100Hz tick rate, so vTaskDelay() never actually blocks -- confirmed
|
||||
* on hardware as a tight busy-spin that starves the idle task long
|
||||
* enough to trip the 5s task watchdog. 20ms is safely >= 1 tick
|
||||
* regardless of tick rate and still imperceptibly responsive here. */
|
||||
while (gpio_get_level((gpio_num_t)CONFIG_EPD_PIN_BUSY) == 0) {
|
||||
epd_delay_ms(1);
|
||||
epd_delay_ms(20);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -207,7 +213,12 @@ esp_err_t epd_display_stream(epd_read_fn_t read_fn, void *ctx)
|
||||
gpio_set_level((gpio_num_t)CONFIG_EPD_PIN_DC, 1);
|
||||
gpio_set_level((gpio_num_t)CONFIG_EPD_PIN_CS, 0);
|
||||
|
||||
uint8_t chunk[EPD_SPI_CHUNK_SIZE];
|
||||
/* Static rather than a stack local: the default main task stack
|
||||
* (CONFIG_ESP_MAIN_TASK_STACK_SIZE, 3584 bytes) is smaller than this
|
||||
* 4KB chunk buffer alone, let alone with the rest of the call chain --
|
||||
* confirmed on hardware as a stack protection fault/crash. Not
|
||||
* reentrant, but this driver only ever runs from one task at a time. */
|
||||
static uint8_t chunk[EPD_SPI_CHUNK_SIZE];
|
||||
size_t total = 0;
|
||||
size_t n;
|
||||
esp_err_t err = ESP_OK;
|
||||
|
||||
Reference in New Issue
Block a user