From 0e270dce29285d2de0fdfa57f2d060f4f8ff9dda Mon Sep 17 00:00:00 2001 From: Nathael Pajani Date: Sat, 15 Oct 2022 02:34:58 +0200 Subject: [PATCH] Bug fix, data corruption when SD card not present or not responding --- v10/uSD.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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++; -- 2.43.0