Make sure storage is initialized before logging error.
* Early __fatal_error calls may try to log an error to file,
before any storage is initialized which may cause a hardfault.
@@ -213,6 +213,9 @@ void flash_error(int n) {
}
void NORETURN __fatal_error(const char *msg) {
+ // Check if any storage has been initialized
+ // before attempting to create the error log.
+ if (pyb_usb_storage_medium) {
FIL fp;
if (f_open(&vfs_fat->fatfs, &fp, "ERROR.LOG",
FA_WRITE|FA_CREATE_ALWAYS) == FR_OK) {
@@ -226,7 +229,7 @@ void NORETURN __fatal_error(const char *msg) {
// the host to mount the filesystem and access the error log.
pyb_usb_dev_init(pyb_usb_dev_detect(), USBD_VID, USBD_PID_CDC_MSC, USBD_MODE_CDC_MSC, 0, NULL, NULL);
}
-
+ }
for (uint i = 0;;) {
led_toggle(((i++) & 3));
for (volatile uint delay = 0; delay < 500000; delay++) {
