Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NVRAM refactor, phase 1. #18969

Merged
merged 5 commits into from
Nov 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions builddefs/common_features.mk
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,10 @@ else
else ifeq ($(PLATFORM),CHIBIOS)
ifneq ($(filter %_STM32F072xB %_STM32F042x6, $(MCU_SERIES)_$(MCU_LDSCRIPT)),)
# STM32 Emulated EEPROM, backed by MCU flash (soon to be deprecated)
OPT_DEFS += -DEEPROM_DRIVER -DEEPROM_STM32_FLASH_EMULATED
OPT_DEFS += -DEEPROM_DRIVER -DEEPROM_LEGACY_EMULATED_FLASH
COMMON_VPATH += $(PLATFORM_PATH)/$(PLATFORM_KEY)/$(DRIVER_DIR)/flash
COMMON_VPATH += $(DRIVER_PATH)/flash
SRC += eeprom_driver.c eeprom_stm32.c flash_stm32.c
SRC += eeprom_driver.c eeprom_legacy_emulated_flash.c legacy_flash_ops.c
else ifneq ($(filter $(MCU_SERIES),STM32F1xx STM32F3xx STM32F4xx STM32L4xx STM32G4xx WB32F3G71xx WB32FQ95xx GD32VF103),)
# Wear-leveling EEPROM implementation, backed by MCU flash
OPT_DEFS += -DEEPROM_DRIVER -DEEPROM_WEAR_LEVELING
Expand All @@ -242,8 +242,8 @@ else
WEAR_LEVELING_DRIVER = rp2040_flash
else ifneq ($(filter $(MCU_SERIES),KL2x K20x),)
# Teensy EEPROM implementations
OPT_DEFS += -DEEPROM_TEENSY
SRC += eeprom_teensy.c
OPT_DEFS += -DEEPROM_KINETIS_FLEXRAM
SRC += eeprom_kinetis_flexram.c
else
# Fall back to transient, i.e. non-persistent
OPT_DEFS += -DEEPROM_DRIVER -DEEPROM_TRANSIENT
Expand Down Expand Up @@ -287,7 +287,7 @@ ifneq ($(strip $(WEAR_LEVELING_DRIVER)),none)
POST_CONFIG_H += $(PLATFORM_PATH)/$(PLATFORM_KEY)/$(DRIVER_PATH)/wear_leveling/wear_leveling_rp2040_flash_config.h
else ifeq ($(strip $(WEAR_LEVELING_DRIVER)), legacy)
COMMON_VPATH += $(PLATFORM_PATH)/$(PLATFORM_KEY)/$(DRIVER_DIR)/flash
SRC += flash_stm32.c wear_leveling_legacy.c
SRC += legacy_flash_ops.c wear_leveling_legacy.c
POST_CONFIG_H += $(PLATFORM_PATH)/$(PLATFORM_KEY)/$(DRIVER_DIR)/wear_leveling/wear_leveling_legacy_config.h
endif
endif
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <ch.h>
#include <hal.h>

#include "eeprom_teensy.h"
#include "eeprom_kinetis_flexram.h"
#include "eeconfig.h"

/*************************************/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
#include <stdbool.h>
#include "util.h"
#include "debug.h"
#include "eeprom_stm32.h"
#include "flash_stm32.h"
#include "eeprom_legacy_emulated_flash.h"
#include "legacy_flash_ops.h"

/*
* We emulate eeprom by writing a snapshot compacted view of eeprom contents,
Expand Down Expand Up @@ -132,7 +132,7 @@
*
*/

#include "eeprom_stm32_defs.h"
#include "eeprom_legacy_emulated_flash_defs.h"
/* These bits are used for optimizing encoding of bytes, 0 and 1 */
#define FEE_WORD_ENCODING 0x8000
#define FEE_VALUE_NEXT 0x6000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/

#include <hal.h>
#include "flash_stm32.h"
#include "legacy_flash_ops.h"

#if defined(STM32F1XX)
# define FLASH_SR_WRPERR FLASH_SR_WRPRTERR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ extern "C" {

#include <stdint.h>

#ifdef FLASH_STM32_MOCKED
#ifdef LEGACY_FLASH_OPS_MOCKED
extern uint8_t FlashBuf[MOCK_FLASH_SIZE];
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "timer.h"
#include "wear_leveling.h"
#include "wear_leveling_internal.h"
#include "flash_stm32.h"
#include "legacy_flash_ops.h"

bool backing_store_init(void) {
bs_dprintf("Init\n");
Expand Down
12 changes: 6 additions & 6 deletions platforms/eeprom.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ void eeprom_update_block(const void *__src, void *__dst, size_t __n);
#elif defined(EEPROM_STM32_L0_L1)
# include "eeprom_stm32_L0_L1.h"
# define TOTAL_EEPROM_BYTE_COUNT (STM32_ONBOARD_EEPROM_SIZE)
#elif defined(EEPROM_TEENSY)
# include "eeprom_teensy.h"
#elif defined(EEPROM_KINETIS_FLEXRAM)
# include "eeprom_kinetis_flexram.h"
# define TOTAL_EEPROM_BYTE_COUNT (EEPROM_SIZE)
#elif defined(EEPROM_STM32_FLASH_EMULATED)
# include "eeprom_stm32_defs.h"
#elif defined(EEPROM_LEGACY_EMULATED_FLASH)
# include "eeprom_legacy_emulated_flash_defs.h"
# define TOTAL_EEPROM_BYTE_COUNT (FEE_DENSITY_BYTES)
#elif defined(EEPROM_SAMD)
# include "eeprom_samd.h"
Expand All @@ -59,12 +59,12 @@ void eeprom_update_block(const void *__src, void *__dst, size_t __n);
#elif defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__)
# define TOTAL_EEPROM_BYTE_COUNT 4096
#elif defined(EEPROM_TEST_HARNESS)
# ifndef FLASH_STM32_MOCKED
# ifndef LEGACY_FLASH_OPS_MOCKED
// Normal tests
# define TOTAL_EEPROM_BYTE_COUNT 32
# else
// Flash wear-leveling testing
# include "eeprom_stm32_tests.h"
# include "eeprom_legacy_emulated_flash_tests.h"
# define TOTAL_EEPROM_BYTE_COUNT (EEPROM_SIZE)
# endif
#else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once

#include "flash_stm32.h"
#include "eeprom_stm32.h"
#include "legacy_flash_ops.h"
#include "eeprom_legacy_emulated_flash.h"

#define EEPROM_SIZE (FEE_PAGE_SIZE * FEE_PAGE_COUNT / 2)
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#include <string.h>
#include <stdbool.h>
#include "flash_stm32.h"
#include "legacy_flash_ops.h"

uint8_t FlashBuf[MOCK_FLASH_SIZE] = {0};

Expand Down
24 changes: 12 additions & 12 deletions platforms/test/rules.mk
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
eeprom_stm32_DEFS := -DEEPROM_TEST_HARNESS -DFLASH_STM32_MOCKED -DNO_PRINT -DFEE_FLASH_BASE=FlashBuf
eeprom_stm32_tiny_DEFS := $(eeprom_stm32_DEFS) \
eeprom_legacy_emulated_flash_DEFS := -DEEPROM_TEST_HARNESS -DLEGACY_FLASH_OPS_MOCKED -DNO_PRINT -DFEE_FLASH_BASE=FlashBuf
eeprom_legacy_emulated_flash_tiny_DEFS := $(eeprom_legacy_emulated_flash_DEFS) \
-DFEE_MCU_FLASH_SIZE=1 \
-DMOCK_FLASH_SIZE=1024 \
-DFEE_PAGE_SIZE=512 \
-DFEE_PAGE_COUNT=1
eeprom_stm32_large_DEFS := $(eeprom_stm32_DEFS) \
eeprom_legacy_emulated_flash_large_DEFS := $(eeprom_legacy_emulated_flash_DEFS) \
-DFEE_MCU_FLASH_SIZE=64 \
-DMOCK_FLASH_SIZE=65536 \
-DFEE_PAGE_SIZE=2048 \
-DFEE_PAGE_COUNT=16

eeprom_stm32_INC := \
eeprom_legacy_emulated_flash_INC := \
$(PLATFORM_PATH)/chibios/drivers/eeprom/ \
$(PLATFORM_PATH)/chibios/drivers/flash/
eeprom_stm32_tiny_INC := $(eeprom_stm32_INC)
eeprom_stm32_large_INC := $(eeprom_stm32_INC)
eeprom_legacy_emulated_flash_tiny_INC := $(eeprom_legacy_emulated_flash_INC)
eeprom_legacy_emulated_flash_large_INC := $(eeprom_legacy_emulated_flash_INC)

eeprom_stm32_SRC := \
eeprom_legacy_emulated_flash_SRC := \
$(TOP_DIR)/drivers/eeprom/eeprom_driver.c \
$(PLATFORM_PATH)/$(PLATFORM_KEY)/eeprom_stm32_tests.cpp \
$(PLATFORM_PATH)/$(PLATFORM_KEY)/flash_stm32_mock.c \
$(PLATFORM_PATH)/chibios/drivers/eeprom/eeprom_stm32.c
eeprom_stm32_tiny_SRC := $(eeprom_stm32_SRC)
eeprom_stm32_large_SRC := $(eeprom_stm32_SRC)
$(PLATFORM_PATH)/$(PLATFORM_KEY)/eeprom_legacy_emulated_flash_tests.cpp \
$(PLATFORM_PATH)/$(PLATFORM_KEY)/legacy_flash_ops_mock.c \
$(PLATFORM_PATH)/chibios/drivers/eeprom/eeprom_legacy_emulated_flash.c
eeprom_legacy_emulated_flash_tiny_SRC := $(eeprom_legacy_emulated_flash_SRC)
eeprom_legacy_emulated_flash_large_SRC := $(eeprom_legacy_emulated_flash_SRC)
2 changes: 1 addition & 1 deletion platforms/test/testlist.mk
Original file line number Diff line number Diff line change
@@ -1 +1 @@
TEST_LIST += eeprom_stm32_tiny eeprom_stm32_large
TEST_LIST += eeprom_legacy_emulated_flash_tiny eeprom_legacy_emulated_flash_large