1
0
mirror of https://github.com/MarlinFirmware/Marlin.git synced 2024-11-23 12:04:19 +00:00

Finish STM32F4 SD-based settings storage (#14844)

This commit is contained in:
Tanguy Pruvot 2019-08-07 05:53:11 +02:00 committed by Scott Lahteine
parent a0d782e46e
commit eecfcd124d

View File

@ -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