From: Nathael Pajani Date: Sat, 15 Oct 2022 00:34:58 +0000 (+0200) Subject: Bug fix, data corruption when SD card not present or not responding X-Git-Url: http://git.techno-innov.fr/?a=commitdiff_plain;h=0e270dce29285d2de0fdfa57f2d060f4f8ff9dda;p=soft%2Flpc122x%2Fscialys Bug fix, data corruption when SD card not present or not responding --- diff --git a/v10/uSD.c b/v10/uSD.c index 78f2bd2..fe90705 100644 --- 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++;