From eecfcd124d9dda91f886f89663bfb3521a759869 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Wed, 7 Aug 2019 05:53:11 +0200 Subject: [PATCH] Finish STM32F4 SD-based settings storage (#14844) --- .../HAL/HAL_STM32/persistent_store_sdcard.cpp | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/Marlin/src/HAL/HAL_STM32/persistent_store_sdcard.cpp b/Marlin/src/HAL/HAL_STM32/persistent_store_sdcard.cpp index de9ed17a3d..33bff7a7a8 100644 --- a/Marlin/src/HAL/HAL_STM32/persistent_store_sdcard.cpp +++ b/Marlin/src/HAL/HAL_STM32/persistent_store_sdcard.cpp @@ -21,24 +21,23 @@ */ /** - * HAL for stm32duino.com based on Libmaple and compatible (STM32F1) * Implementation of EEPROM settings in SD Card */ -#ifdef TARGET_STM32F4 +#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC) #include "../../inc/MarlinConfig.h" -#if ENABLED(EEPROM_SETTINGS) && NONE(FLASH_EEPROM_EMULATION, SPI_EEPROM, I2C_EEPROM) +#if ENABLED(EEPROM_SETTINGS) && NONE(FLASH_EEPROM_EMULATION, SRAM_EEPROM_EMULATION, SPI_EEPROM, I2C_EEPROM) #include "../shared/persistent_store_api.h" #ifndef E2END #define E2END 0xFFF // 4KB #endif -#define HAL_EEPROM_SIZE (E2END + 1) // 16KB +#define HAL_EEPROM_SIZE int(E2END + 1) -#define _ALIGN(x) __attribute__ ((aligned(x))) // SDIO uint32_t* compat. +#define _ALIGN(x) __attribute__ ((aligned(x))) static char _ALIGN(4) HAL_eeprom_data[HAL_EEPROM_SIZE]; #if ENABLED(SDSUPPORT) @@ -52,11 +51,11 @@ static char _ALIGN(4) HAL_eeprom_data[HAL_EEPROM_SIZE]; SdFile file, root = card.getroot(); if (!file.open(&root, EEPROM_FILENAME, O_RDONLY)) - return false; + return true; - int16_t bytes_read = file.read(HAL_eeprom_data, HAL_STM32F4_EEPROM_SIZE); + int bytes_read = file.read(HAL_eeprom_data, HAL_EEPROM_SIZE); if (bytes_read < 0) return false; - for (; bytes_read < HAL_STM32F4_EEPROM_SIZE; bytes_read++) + for (; bytes_read < HAL_EEPROM_SIZE; bytes_read++) HAL_eeprom_data[bytes_read] = 0xFF; file.close(); return true; @@ -66,17 +65,17 @@ static char _ALIGN(4) HAL_eeprom_data[HAL_EEPROM_SIZE]; if (!card.isDetected()) return false; SdFile file, root = card.getroot(); - int16_t bytes_written = 0; + int bytes_written = 0; if (file.open(&root, EEPROM_FILENAME, O_CREAT | O_WRITE | O_TRUNC)) { - bytes_written = file.write(HAL_eeprom_data, HAL_STM32F4_EEPROM_SIZE); + bytes_written = file.write(HAL_eeprom_data, HAL_EEPROM_SIZE); file.close(); } - return (bytes_written == HAL_STM32F4_EEPROM_SIZE); + return (bytes_written == HAL_EEPROM_SIZE); } #else // !SDSUPPORT - #error "Please define SPI_EEPROM (in Configuration.h) or disable EEPROM_SETTINGS." + #error "Please define an EEPROM, a SDCARD or disable EEPROM_SETTINGS." #endif // !SDSUPPORT @@ -98,7 +97,7 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, const size_t size, uin return false; } -size_t PersistentStore::capacity() { return HAL_STM32F4_EEPROM_SIZE; } +size_t PersistentStore::capacity() { return HAL_EEPROM_SIZE; } #endif // EEPROM_SETTINGS -#endif // __STM32F4__ +#endif // STM32