Bug fix, data corruption when SD card not present or not responding
authorNathael Pajani <nathael.pajani@ed3l.fr>
Sat, 15 Oct 2022 00:34:58 +0000 (02:34 +0200)
committerNathael Pajani <nathael.pajani@ed3l.fr>
Tue, 8 Nov 2022 11:07:29 +0000 (12:07 +0100)
v10/uSD.c

index 78f2bd2..fe90705 100644 (file)
--- a/v10/uSD.c
+++ b/v10/uSD.c
@@ -153,11 +153,14 @@ int scialys_uSD_append_data(struct sd_data_blob* data)
        memcpy(mmc_data + index, data, sizeof(struct sd_data_blob));
        index += sizeof(struct sd_data_blob);
 
-       /* Flush buffer to uSD ? */
+       /* Flush buffer to uSD ?
+        * Do it when there's not enough room in buffer for another chunk of data. */
        if ((index + sizeof(struct sd_data_blob)) >= MMC_BUF_SIZE) {
                int ret = scialys_uSD_write(last_block.block_num + 1);
                if (ret != 0) {
                        uprintf(UART0, "Write to uSD returned %d\n", ret);
+                       /* Drop old data ... we do not have that much RAM available !!! */
+                       index = 0;
                        return ret;
                }
                last_block.block_num++;