From ffdbc1f42c7db64807dabdb5ddb31324d56eb35a Mon Sep 17 00:00:00 2001 From: Alexander Amelkin Date: Tue, 26 Jun 2018 21:41:23 +0300 Subject: [PATCH] STM32F1: Fix SD card persistent store API (#11090) --- .../HAL_STM32F1/persistent_store_flash.cpp | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/Marlin/src/HAL/HAL_STM32F1/persistent_store_flash.cpp b/Marlin/src/HAL/HAL_STM32F1/persistent_store_flash.cpp index dff5122964..a0b940f371 100644 --- a/Marlin/src/HAL/HAL_STM32F1/persistent_store_flash.cpp +++ b/Marlin/src/HAL/HAL_STM32F1/persistent_store_flash.cpp @@ -42,10 +42,12 @@ namespace HAL { namespace PersistentStore { -// Store settings in the last two pages -// Flash pages must be erased before writing, so keep track. -bool firstWrite = false; -uint32_t pageBase = EEPROM_START_ADDRESS; +namespace { + // Store settings in the last two pages + // Flash pages must be erased before writing, so keep track. + bool firstWrite = false; + uint32_t pageBase = EEPROM_START_ADDRESS; +} bool access_start() { firstWrite = true; @@ -64,9 +66,9 @@ bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) { if (firstWrite) { FLASH_Unlock(); status = FLASH_ErasePage(EEPROM_PAGE0_BASE); - if (status != FLASH_COMPLETE) return false; + if (status != FLASH_COMPLETE) return true; status = FLASH_ErasePage(EEPROM_PAGE1_BASE); - if (status != FLASH_COMPLETE) return false; + if (status != FLASH_COMPLETE) return true; firstWrite = false; } @@ -76,7 +78,7 @@ bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) { uint16_t* wordBuffer = (uint16_t *)value; while (wordsToWrite) { status = FLASH_ProgramHalfWord(pageBase + pos + (i * 2), wordBuffer[i]); - if (status != FLASH_COMPLETE) return false; + if (status != FLASH_COMPLETE) return true; wordsToWrite--; i++; } @@ -85,15 +87,15 @@ bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) { if (size & 1) { uint16_t temp = value[size - 1]; status = FLASH_ProgramHalfWord(pageBase + pos + i, temp); - if (status != FLASH_COMPLETE) return false; + if (status != FLASH_COMPLETE) return true; } crc16(crc, value, size); pos += ((size + 1) & ~1); - return true; + return false; } -void read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const bool writing/*=true*/) { +bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const bool writing/*=true*/) { for (uint16_t i = 0; i < size; i++) { byte* accessPoint = (byte*)(pageBase + pos + i); uint8_t c = *accessPoint; @@ -101,6 +103,7 @@ void read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const boo crc16(crc, &c, 1); } pos += ((size + 1) & ~1); + return false; } } // PersistentStore