Commit 6be0bbb8 authored by Damien George's avatar Damien George
Browse files

stmhal: Add support for flash filesystem on F401 MCUs.

It uses a 16k cache buffer and so the filesystem size is limited.
parent 5a11086d
......@@ -37,10 +37,12 @@
#define ADDR_FLASH_SECTOR_5 ((uint32_t)0x08020000) /* Base @ of Sector 5, 128 Kbytes */
#define ADDR_FLASH_SECTOR_6 ((uint32_t)0x08040000) /* Base @ of Sector 6, 128 Kbytes */
#define ADDR_FLASH_SECTOR_7 ((uint32_t)0x08060000) /* Base @ of Sector 7, 128 Kbytes */
#if defined(FLASH_SECTOR_8)
#define ADDR_FLASH_SECTOR_8 ((uint32_t)0x08080000) /* Base @ of Sector 8, 128 Kbytes */
#define ADDR_FLASH_SECTOR_9 ((uint32_t)0x080A0000) /* Base @ of Sector 9, 128 Kbytes */
#define ADDR_FLASH_SECTOR_10 ((uint32_t)0x080C0000) /* Base @ of Sector 10, 128 Kbytes */
#define ADDR_FLASH_SECTOR_11 ((uint32_t)0x080E0000) /* Base @ of Sector 11, 128 Kbytes */
#endif
static const uint32_t flash_info_table[26] = {
ADDR_FLASH_SECTOR_0, FLASH_SECTOR_0,
......@@ -51,11 +53,15 @@ static const uint32_t flash_info_table[26] = {
ADDR_FLASH_SECTOR_5, FLASH_SECTOR_5,
ADDR_FLASH_SECTOR_6, FLASH_SECTOR_6,
ADDR_FLASH_SECTOR_7, FLASH_SECTOR_7,
#if defined(FLASH_SECTOR_8)
ADDR_FLASH_SECTOR_8, FLASH_SECTOR_8,
ADDR_FLASH_SECTOR_9, FLASH_SECTOR_9,
ADDR_FLASH_SECTOR_10, FLASH_SECTOR_10,
ADDR_FLASH_SECTOR_11, FLASH_SECTOR_11,
ADDR_FLASH_SECTOR_11 + 0x20000, 0,
#else
ADDR_FLASH_SECTOR_7 + 0x20000, 0,
#endif
};
uint32_t flash_get_sector_info(uint32_t addr, uint32_t *start_addr, uint32_t *size) {
......
......@@ -34,10 +34,26 @@
#include "flash.h"
#include "storage.h"
#if defined(STM32F405xx)
#define CACHE_MEM_START_ADDR (0x10000000) // CCM data RAM, 64k
#define FLASH_PART1_START_BLOCK (0x100)
#define FLASH_PART1_NUM_BLOCKS (224) // 16k+16k+16k+64k=112k
#define FLASH_MEM_START_ADDR (0x08004000) // sector 1, 16k
#define FLASH_SECTOR_SIZE_MAX (0x10000) // 64k max, size of CCM
#elif defined(STM32F401xE)
STATIC byte flash_cache_mem[0x4000] __attribute__((aligned(4))); // 16k
#define CACHE_MEM_START_ADDR (&flash_cache_mem[0])
#define FLASH_PART1_START_BLOCK (0x100)
#define FLASH_PART1_NUM_BLOCKS (128) // 16k+16k+16k+16k(of64k)=64k
#define FLASH_MEM_START_ADDR (0x08004000) // sector 1, 16k
#define FLASH_SECTOR_SIZE_MAX (0x4000) // 16k max due to size of cache buffer
#else
#error "no storage support for this MCU"
#endif
#define FLASH_FLAG_DIRTY (1)
#define FLASH_FLAG_FORCE_WRITE (2)
......@@ -62,6 +78,9 @@ static uint8_t *flash_cache_get_addr_for_write(uint32_t flash_addr) {
uint32_t flash_sector_start;
uint32_t flash_sector_size;
uint32_t flash_sector_id = flash_get_sector_info(flash_addr, &flash_sector_start, &flash_sector_size);
if (flash_sector_size > FLASH_SECTOR_SIZE_MAX) {
flash_sector_size = FLASH_SECTOR_SIZE_MAX;
}
if (flash_cache_sector_id != flash_sector_id) {
flash_cache_flush();
memcpy((void*)CACHE_MEM_START_ADDR, (const void*)flash_sector_start, flash_sector_size);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment