ESP32 CAN Web Interface can't recover from failed update
Posted: Thu Jul 25, 2024 3:52 pm
The STM32 bootloader enables the independent watchdog and the firmware is expected to feed that at least once a second or so. If it fails to do so, the STM32 is reset.
This is used to recover from a failed update. If a firmware is just partially flashed it is usually not runnable and won't feed the dog. The STM32 ends up in a reset loop where the boot loader asks for an update like every 2s. The works fine with the update over uart (both python script and ESP), it also works with the CAN python script but it doesn't work with the ESP32 CAN.
Now I simulated the situation by pulling down the STMs reset pin, starting an update and then releasing the pin. Everything looks good:
The boot loader sends it 0x33 hello message with serial number, the ESP32 reflects the serial number, the STM asks for size (S), the ESP replies with 0x8C or 140 pages, the STM asks for the first page (P) and then the ESP32 successfully transmits 1024 bytes.
It becomes dodgy afterwards: The last 8 bytes are requested (P) and transmitted, the CRC is requested (C) and transmitted but then instead of requesting the next page with "P" the boot loader reports update finished "D". Consequently the ESP also goes into done state.
This is the code snippet in question: Decrement remaining number of pages and if we reached 0 go to done state. So it seems like numPages is set to 1 instead of 140.
Here is the file: https://github.com/jsphuebner/stm32-CAN ... loader.cpp
I suspect some timing issue as I don't see what else should be different between sending via PC or ESP.
This is used to recover from a failed update. If a firmware is just partially flashed it is usually not runnable and won't feed the dog. The STM32 ends up in a reset loop where the boot loader asks for an update like every 2s. The works fine with the update over uart (both python script and ESP), it also works with the CAN python script but it doesn't work with the ESP32 CAN.
Now I simulated the situation by pulling down the STMs reset pin, starting an update and then releasing the pin. Everything looks good:
The boot loader sends it 0x33 hello message with serial number, the ESP32 reflects the serial number, the STM asks for size (S), the ESP replies with 0x8C or 140 pages, the STM asks for the first page (P) and then the ESP32 successfully transmits 1024 bytes.
It becomes dodgy afterwards: The last 8 bytes are requested (P) and transmitted, the CRC is requested (C) and transmitted but then instead of requesting the next page with "P" the boot loader reports update finished "D". Consequently the ESP also goes into done state.
This is the code snippet in question: Decrement remaining number of pages and if we reached 0 go to done state. So it seems like numPages is set to 1 instead of 140.
Here is the file: https://github.com/jsphuebner/stm32-CAN ... loader.cpp
I suspect some timing issue as I don't see what else should be different between sending via PC or ESP.