Repository navigation
STM32L5 Crash while reading SD card or calling .end() #83
Description
Activity
- added a commit that references this issue
on Mar 27, 2025 OK this did fix the issue with
.end()causing a crash, but it didn't fix the issue with crashes happeningloop(). Here's my sketch:#include <Arduino.h> #include <STM32SD.h> #include "stm32l5xx_hal.h" #include "stm32l5xx_hal_flash.h" #include "stm32l5xx_hal_rcc.h" #define FIRMWARE_FILENAME "stm32l5_series_test.ino.bin" File root; uint32_t loopCount = 0; void setup() { Serial.begin(115200); while(!Serial); pinMode(LED_GREEN, OUTPUT); pinMode(LED_RED, OUTPUT); delay(1000); Serial.print("Initializing SD card..."); if (SD.begin(SD_DETECT_PIN)) { Serial.println("SD card initialized"); } else { Serial.println("SD card failed to initialize"); } } void loop() { digitalWrite(LED_GREEN, HIGH); digitalWrite(LED_RED, LOW); Serial.println("Hello World"); delay(1000); digitalWrite(LED_GREEN, LOW); digitalWrite(LED_RED, HIGH); File test = SD.open(FIRMWARE_FILENAME, FILE_READ); if (test) { Serial.println("Firmware file exists"); test.close(); } else { Serial.println("No firmware file found"); } loopCount++; Serial.print("Loop count: "); Serial.println(loopCount); Serial.flush(); Serial.println("Looping in 2 seconds..."); delay(2000); }And here's the logs I get. Note that it resets itself (the watchdog does this, I think) but without the watchdog, it will just hang.
Hello World Firmware file exists Loop count: 2 Looping in 2 seconds... Hello World Firmware file exists Loop count: 3 Looping in 2 seconds... Hello World Firmware file exists Loop count: 4 Looping in 2 seconds... Hello World Device /dev/ttyACM1 disconnected. Waiting for reconnect... Device /dev/ttyACM1 not found. Retrying in 1 second... Device /dev/ttyACM1 detected. Opening connection... Initializing SD card...SD card initialized Hello World Firmware file exists Loop count: 1 Looping in 2 seconds...I'm running the latest pull request and board defs for the STM32L5 DK. I can share if you want but it's right from here:
stm32duino/Arduino_Core_STM32#2696Using your sketch, I have no crash.
You said you used the watchdog but can't see any code for this nor the reload. So if really enable and no reload then it will automatically restart each time it expires.Running ~10min.
last part of the log
19:09:42.404 -> Loop count: 137
19:09:42.404 -> Looping in 2 seconds...
19:09:44.414 -> Hello World
19:09:45.418 -> Firmware file exists
19:09:45.418 -> Loop count: 138
19:09:45.418 -> Looping in 2 seconds...
19:09:47.420 -> Hello World
19:09:48.389 -> Firmware file exists
19:09:48.422 -> Loop count: 139
19:09:48.422 -> Looping in 2 seconds...
19:09:50.417 -> Hello World
19:09:51.419 -> Firmware file exists
19:09:51.419 -> Loop count: 140
19:09:51.419 -> Looping in 2 seconds...
19:09:53.421 -> Hello World
19:09:54.420 -> Firmware file exists
19:09:54.420 -> Loop count: 141
19:09:54.420 -> Looping in 2 seconds...
19:09:56.416 -> Hello World
19:09:57.418 -> Firmware file exists
19:09:57.418 -> Loop count: 142
19:09:57.418 -> Looping in 2 seconds...
19:09:59.411 -> Hello World
19:10:00.407 -> Firmware file exists
19:10:00.407 -> Loop count: 143
19:10:00.407 -> Looping in 2 seconds...
19:10:02.408 -> Hello World
19:10:03.408 -> Firmware file exists
19:10:03.408 -> Loop count: 144
19:10:03.408 -> Looping in 2 seconds...
19:10:05.416 -> Hello World
19:10:06.415 -> Firmware file exists
19:10:06.415 -> Loop count: 145
19:10:06.415 -> Looping in 2 seconds...
19:10:08.421 -> Hello World
19:10:09.421 -> Firmware file exists
19:10:09.421 -> Loop count: 146
19:10:09.421 -> Looping in 2 seconds...
19:10:11.420 -> Hello World
19:10:12.416 -> Firmware file exists
19:10:12.416 -> Loop count: 147
19:10:12.416 -> Looping in 2 seconds...Welp, the issue must be on my end then, I'll push some buttons until it works. Thanks for your help
- added a commit that references this issue
on Jul 19, 2025
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
I'm experiencing an issue with the SD card reader and the STM32L5. This is using the STM32 DK board referenced here:
stm32duino/Arduino_Core_STM32#2694
The issue is that reading from the SD card causes the microcontroller to either freeze, or crash and restart if the watchdog is enabled (i have watchdog enabled).
To Reproduce a Crash
And here's what the serial log looks like as this runs.
So it appears to be crashing every few SD card reads - it's really unpredictable. Sometimes it goes for a while and sometimes it will only do 2-3 loops before there's a crash.
Here's how I build an upload
And to reproduce a crash even simpler:
I've tried a few things, including changing the heap size and tweaking some timing but I can't seem to figure out why it's doing this. If I have it dump crash information, it looks like this. not sure if helpful.
I've tried different SD cards, of different sizes and can't seem to find a pattern. It does this with all of them. It is especially reproducible by calling the .end() method.