1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-14 20:10:18 +03:00

Allow the use of EEPROM_IN_RAM on MCUs.

If the MCU also supports PERSISTENT ram (not erased on a warm boot) it
allows testing of config changes without wearing out your flash.

e.g.

linker script
-------------
comment out __config_start/__config_end

target.c
--------
PERSISTENT uint8_t eepromData[EEPROM_SIZE]; // persistent, so it
survives warm boots.

target.h
--------
extern uint8_t eepromData[EEPROM_SIZE];

SITL actually keeps the EEPROM in a FILE, loaded into RAM using
alternate FLASH_* implementation.
This commit is contained in:
Dominic Clifton 2018-11-24 16:37:36 +01:00
parent 13389970c4
commit e83ba0db0e
8 changed files with 61 additions and 32 deletions

View file

@ -26,11 +26,6 @@
#include "config/config_streamer.h"
#ifndef EEPROM_IN_RAM
extern uint8_t __config_start; // configured via linker script when building binaries.
extern uint8_t __config_end;
#endif
// @todo this is not strictly correct for F4/F7, where sector sizes are variable
#if !defined(FLASH_PAGE_SIZE)
// F1
@ -83,7 +78,9 @@ void config_streamer_start(config_streamer_t *c, uintptr_t base, int size)
c->address = base;
c->size = size;
if (!c->unlocked) {
#if defined(STM32F7) || defined(STM32H7)
#if defined(EEPROM_IN_RAM)
// NOP
#elif defined(STM32F7) || defined(STM32H7)
HAL_FLASH_Unlock();
#else
FLASH_Unlock();
@ -91,7 +88,9 @@ void config_streamer_start(config_streamer_t *c, uintptr_t base, int size)
c->unlocked = true;
}
#if defined(STM32F10X)
#if defined(EEPROM_IN_RAM) || defined(EEPROM_IN_FILE)
// NOP
#elif defined(STM32F10X)
FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_PGERR | FLASH_FLAG_WRPRTERR);
#elif defined(STM32F303)
FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_PGERR | FLASH_FLAG_WRPERR);
@ -109,7 +108,9 @@ void config_streamer_start(config_streamer_t *c, uintptr_t base, int size)
c->err = 0;
}
#if defined(STM32F745xx) || defined(STM32F746xx) || defined(STM32F765xx)
#if defined(EEPROM_IN_RAM)
// No flash sector method required.
#elif defined(STM32F745xx) || defined(STM32F746xx) || defined(STM32F765xx)
/*
Sector 0 0x08000000 - 0x08007FFF 32 Kbytes
Sector 1 0x08008000 - 0x0800FFFF 32 Kbytes
@ -339,7 +340,20 @@ static int write_word(config_streamer_t *c, config_streamer_buffer_align_type_t
if (c->err != 0) {
return c->err;
}
#if defined(STM32H7)
#if defined(EEPROM_IN_RAM)
if (c->address == (uintptr_t)&eepromData[0]) {
memset(eepromData, 0, sizeof(eepromData));
}
uint64_t *dest_addr = (uint64_t *)c->address;
uint64_t *src_addr = (uint64_t*)buffer;
uint8_t row_index = 4;
/* Program the 256 bits flash word */
do
{
*dest_addr++ = *src_addr++;
} while (--row_index != 0);
#elif defined(STM32H7)
if (c->address % FLASH_PAGE_SIZE == 0) {
FLASH_EraseInitTypeDef EraseInitStruct = {
.TypeErase = FLASH_TYPEERASE_SECTORS,
@ -385,7 +399,7 @@ static int write_word(config_streamer_t *c, config_streamer_buffer_align_type_t
if (c->address % FLASH_PAGE_SIZE == 0) {
#if defined(STM32F4)
const FLASH_Status status = FLASH_EraseSector(getFLASHSectorForEEPROM(), VoltageRange_3); //0x08080000 to 0x080A0000
#else // STM32F3 or STM32F1
#else // STM32F3, STM32F1 or EEPROM_IN_FILE
const FLASH_Status status = FLASH_ErasePage(c->address);
#endif
if (status != FLASH_COMPLETE) {
@ -432,7 +446,9 @@ int config_streamer_flush(config_streamer_t *c)
int config_streamer_finish(config_streamer_t *c)
{
if (c->unlocked) {
#if defined(STM32F7) || defined(STM32H7)
#if defined(EEPROM_IN_RAM)
// NOP
#elif defined(STM32F7) || defined(STM32H7)
HAL_FLASH_Lock();
#else
FLASH_Lock();