stm32/flashbdev: Support generic flash storage config via link symbols.
A board can now define the following linker symbols to configure its flash storage layout: _micropy_hw_internal_flash_storage_start _micropy_hw_internal_flash_storage_end _micropy_hw_internal_flash_storage_ram_cache_start _micropy_hw_internal_flash_storage_ram_cache_end And optionally have a second flash segment by configuring MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE_SEGMENT2 to 1 and defining: _micropy_hw_internal_flash_storage2_start _micropy_hw_internal_flash_storage2_end Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
parent
97a7cc243b
commit
84969194a1
@ -133,11 +133,35 @@ extern uint8_t _ram_fs_cache_end[];
|
|||||||
#define FLASH_MEM_SEG1_NUM_BLOCKS ((&_flash_fs_end - &_flash_fs_start) / 512)
|
#define FLASH_MEM_SEG1_NUM_BLOCKS ((&_flash_fs_end - &_flash_fs_start) / 512)
|
||||||
|
|
||||||
#else
|
#else
|
||||||
#error "no internal flash storage support for this MCU"
|
|
||||||
|
// Generic configuration where the linker script specifies flash storage and RAM cache locations.
|
||||||
|
|
||||||
|
extern uint8_t _micropy_hw_internal_flash_storage_start;
|
||||||
|
extern uint8_t _micropy_hw_internal_flash_storage_end;
|
||||||
|
extern uint8_t _micropy_hw_internal_flash_storage2_start;
|
||||||
|
extern uint8_t _micropy_hw_internal_flash_storage2_end;
|
||||||
|
extern uint8_t _micropy_hw_internal_flash_storage_ram_cache_start[];
|
||||||
|
extern uint8_t _micropy_hw_internal_flash_storage_ram_cache_end[];
|
||||||
|
|
||||||
|
#define CACHE_MEM_START_ADDR \
|
||||||
|
((uintptr_t)&_micropy_hw_internal_flash_storage_ram_cache_start[0])
|
||||||
|
#define FLASH_SECTOR_SIZE_MAX \
|
||||||
|
(&_micropy_hw_internal_flash_storage_ram_cache_end[0] - &_micropy_hw_internal_flash_storage_ram_cache_start[0])
|
||||||
|
#define FLASH_MEM_SEG1_START_ADDR \
|
||||||
|
((long)&_micropy_hw_internal_flash_storage_start)
|
||||||
|
#define FLASH_MEM_SEG1_NUM_BLOCKS \
|
||||||
|
((&_micropy_hw_internal_flash_storage_end - &_micropy_hw_internal_flash_storage_start) / 512)
|
||||||
|
|
||||||
|
#if MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE_SEGMENT2
|
||||||
|
#define FLASH_MEM_SEG2_START_ADDR \
|
||||||
|
((long)&_micropy_hw_internal_flash_storage2_start)
|
||||||
|
#define FLASH_MEM_SEG2_NUM_BLOCKS \
|
||||||
|
((&_micropy_hw_internal_flash_storage2_end - &_micropy_hw_internal_flash_storage2_start) / 512)
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(FLASH_MEM_SEG2_START_ADDR)
|
#if !defined(FLASH_MEM_SEG2_START_ADDR)
|
||||||
#define FLASH_MEM_SEG2_START_ADDR (0) // no second segment
|
|
||||||
#define FLASH_MEM_SEG2_NUM_BLOCKS (0) // no second segment
|
#define FLASH_MEM_SEG2_NUM_BLOCKS (0) // no second segment
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -220,9 +244,11 @@ static uint32_t convert_block_to_flash_addr(uint32_t block) {
|
|||||||
if (block < FLASH_MEM_SEG1_NUM_BLOCKS) {
|
if (block < FLASH_MEM_SEG1_NUM_BLOCKS) {
|
||||||
return FLASH_MEM_SEG1_START_ADDR + block * FLASH_BLOCK_SIZE;
|
return FLASH_MEM_SEG1_START_ADDR + block * FLASH_BLOCK_SIZE;
|
||||||
}
|
}
|
||||||
|
#ifdef FLASH_MEM_SEG2_START_ADDR
|
||||||
if (block < FLASH_MEM_SEG1_NUM_BLOCKS + FLASH_MEM_SEG2_NUM_BLOCKS) {
|
if (block < FLASH_MEM_SEG1_NUM_BLOCKS + FLASH_MEM_SEG2_NUM_BLOCKS) {
|
||||||
return FLASH_MEM_SEG2_START_ADDR + (block - FLASH_MEM_SEG1_NUM_BLOCKS) * FLASH_BLOCK_SIZE;
|
return FLASH_MEM_SEG2_START_ADDR + (block - FLASH_MEM_SEG1_NUM_BLOCKS) * FLASH_BLOCK_SIZE;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
// can add more flash segments here if needed, following above pattern
|
// can add more flash segments here if needed, following above pattern
|
||||||
|
|
||||||
// bad block
|
// bad block
|
||||||
|
@ -57,6 +57,11 @@
|
|||||||
#define MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE (1)
|
#define MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE (1)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// If internal flash storage is enabled, whether to use a second segment of flash.
|
||||||
|
#ifndef MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE
|
||||||
|
#define MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE_SEGMENT2 (0)
|
||||||
|
#endif
|
||||||
|
|
||||||
// Whether to enable the RTC, exposed as pyb.RTC
|
// Whether to enable the RTC, exposed as pyb.RTC
|
||||||
#ifndef MICROPY_HW_ENABLE_RTC
|
#ifndef MICROPY_HW_ENABLE_RTC
|
||||||
#define MICROPY_HW_ENABLE_RTC (0)
|
#define MICROPY_HW_ENABLE_RTC (0)
|
||||||
|
Loading…
Reference in New Issue
Block a user