diff --git a/include/flash.h b/include/flash.h index 9b225e4..39f9e3d 100644 --- a/include/flash.h +++ b/include/flash.h @@ -29,6 +29,7 @@ THE SOFTWARE. #include #include +void flash_load(); bool flash_set_user_id(uint8_t channel, uint32_t user_id); uint32_t flash_get_user_id(uint8_t channel); void flash_flush(); diff --git a/ldscripts/mem.ld b/ldscripts/mem.ld index 945a948..6711f9c 100644 --- a/ldscripts/mem.ld +++ b/ldscripts/mem.ld @@ -14,6 +14,7 @@ MEMORY { FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 64K + DATA (rwx) : ORIGIN = 0x0801F800, LENGTH = 2K RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 16K /* diff --git a/ldscripts/sections.ld b/ldscripts/sections.ld index 9ef139f..24f81c5 100644 --- a/ldscripts/sections.ld +++ b/ldscripts/sections.ld @@ -53,6 +53,12 @@ ENTRY(_start) SECTIONS { + /* user data flash */ + .user_data : ALIGN(4) + { + *(.user_data) + } > DATA + /* * For Cortex-M devices, the beginning of the startup code is stored in * the .isr_vector section, which goes to FLASH. diff --git a/src/flash.c b/src/flash.c index 965e5fa..7935a70 100644 --- a/src/flash.c +++ b/src/flash.c @@ -24,18 +24,35 @@ THE SOFTWARE. */ + #include "flash.h" +#include +#include "stm32f0xx_hal_flash.h" #define NUM_CHANNEL 1 -static struct { +typedef struct { uint32_t user_id[NUM_CHANNEL]; -} flash_data; +} flash_data_t; + +static flash_data_t flash_data_ram; +__attribute__((__section__(".user_data"))) const flash_data_t flash_data_rom; + + +void flash_load() +{ + memcpy(&flash_data_ram, &flash_data_rom, sizeof(flash_data_t)); +} bool flash_set_user_id(uint8_t channel, uint32_t user_id) { if (channel