[STM32] DTCM buffer incorrect sized for processor type
In flashbdev.clocation and below the used DTCM is 64kByte, however the STM32F76xxx and STM32F77xxx feature a DTCM of 128kByte, whereas the STM32F75xx and STM32F74xx have a 64kByte DTCM.
Making the /flash drive more flexible
@dpgeorge - I could make a PR for it, but I like to stop by your office first... :-)
I have been working with several STM32's and all of them use the internal Flash to store the code and the filesystem. With the memory of the STM32's the amount of FLASH_TEXT and FLASH_FS can be varied in many ways. Up to now I hardcoded it in storage.c (before) and in flashbdev.c (nowadays). It is not very flexible, so I added all the flash segments in the linker file and use these to generate the correct memory addresses, etc. To make it even more flexible I moved the *.ld file into the board directory as I like to keep the board specifics together. So far I did this to suit my own purpose for the H743, F767, F437, L476 and F405.
There are cases where you have enough using FLASH_MEM_SEG1 and FLASH_MEM_SEG2, however just leave out the FLASH_FSx you don't need and everything works fine.
Part of the code in flashbdev.c:
#elif defined(STM32F437xx)
#define CACHE_MEM_START_ADDR (0x10000000) // CCM data RAM, 64k
#define FLASH_SECTOR_SIZE_MAX (0x10000) // 64k max, size of CCM
extern uint8_t _flash_fs_start;
extern uint8_t _flash_fs_end;
#define FLASH_MEM_SEG1_START_ADDR ((long)&_flash_fs_start)
#define FLASH_MEM_SEG1_NUM_BLOCKS ((&_flash_fs_end - &_flash_fs_start) / 512)
#if MICROPY_HW_FLASH_EXTRA
extern uint8_t _flash_fs2_start;
extern uint8_t _flash_fs2_end;
extern uint8_t _flash_fs3_start;
extern uint8_t _flash_fs3_end;
extern uint8_t _flash_fs4_start;
extern uint8_t _flash_fs4_end;
extern uint8_t _flash_fs5_start;
extern uint8_t _flash_fs5_end;
extern uint8_t _flash_fs6_start;
extern uint8_t _flash_fs6_end;
extern uint8_t _flash_fs7_start;
extern uint8_t _flash_fs7_end;
extern uint8_t _flash_fs8_start;
extern uint8_t _flash_fs8_end;
#define FLASH_MEM_SEG2_START_ADDR ((long)&_flash_fs2_start)
#define FLASH_MEM_SEG2_NUM_BLOCKS ((&_flash_fs2_end - &_flash_fs2_start) / 512)
#define FLASH_MEM_SEG3_START_ADDR ((long)&_flash_fs3_start)
#define FLASH_MEM_SEG3_NUM_BLOCKS ((&_flash_fs3_end - &_flash_fs3_start) / 512)
#define FLASH_MEM_SEG4_START_ADDR ((long)&_flash_fs4_start)
#define FLASH_MEM_SEG4_NUM_BLOCKS ((&_flash_fs4_end - &_flash_fs4_start) / 512)
#define FLASH_MEM_SEG5_START_ADDR ((long)&_flash_fs5_start)
#define FLASH_MEM_SEG5_NUM_BLOCKS ((&_flash_fs5_end - &_flash_fs5_start) / 512)
#define FLASH_MEM_SEG6_START_ADDR ((long)&_flash_fs6_start)
#define FLASH_MEM_SEG6_NUM_BLOCKS ((&_flash_fs6_end - &_flash_fs6_start) / 512)
#define FLASH_MEM_SEG7_START_ADDR ((long)&_flash_fs7_start)
#define FLASH_MEM_SEG7_NUM_BLOCKS ((&_flash_fs7_end - &_flash_fs7_start) / 512)
#define FLASH_MEM_SEG8_START_ADDR ((long)&_flash_fs8_start)
#define FLASH_MEM_SEG8_NUM_BLOCKS ((&_flash_fs8_end - &_flash_fs8_start) / 512)
#endif
#endif
Part of the stm32f437.ld:
MEMORY
{
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 192K
CCMRAM (xrw) : ORIGIN = 0x10000000, LENGTH = 64K
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 2048K
FLASH_ISR (rx) : ORIGIN = 0x08000000, LENGTH = 16K /* sector 0 */
FLASH_TEXT (rx) : ORIGIN = 0x08020000, LENGTH = 896K /* sectors 5,6,7,8,9,10,11 */
/*
For the filesystem the sector size above CCMRAM size is wasted. Keep in mind the number of blocks
Also there are gaps in between due this
*/
FLASH_FS (rx) : ORIGIN = 0x08100000, LENGTH = 256K /* sectors 12-17 is 16K+16K+16K+16K+64K+64K(128K) = 384 blocks */
FLASH_FS2 (rx) : ORIGIN = 0x08140000, LENGTH = 128K /* sector 18 is 128K, but only 64K be used = 128 blocks */
FLASH_FS3 (rx) : ORIGIN = 0x08160000, LENGTH = 128K /* sector 19 */
FLASH_FS4 (rx) : ORIGIN = 0x08180000, LENGTH = 128K /* sector 20 */
FLASH_FS5 (rx) : ORIGIN = 0x081A0000, LENGTH = 128K /* sector 21 */
FLASH_FS6 (rx) : ORIGIN = 0x081C0000, LENGTH = 128K /* sector 22 */
FLASH_FS7 (rx) : ORIGIN = 0x081E0000, LENGTH = 128K /* sector 23 */
FLASH_FS8 (rx) : ORIGIN = 0x08004000, LENGTH = 112K /* sector 1-4 is 16+16+16+64=112K/512 = 224 blocks */
}
/* generate all the labels for the flash drive blocks
only the first 64K can be used from a 128K block due to the CCMRAM size that why the 64K
is subtracted :-)
*/
_flash_fs_start = ORIGIN(FLASH_FS);
_flash_fs_end = ORIGIN(FLASH_FS) + LENGTH(FLASH_FS) - 0x10000;
_flash_fs2_start = ORIGIN(FLASH_FS2);
_flash_fs2_end = ORIGIN(FLASH_FS2) + LENGTH(FLASH_FS2) - 0x10000;
_flash_fs3_start = ORIGIN(FLASH_FS3);
_flash_fs3_end = ORIGIN(FLASH_FS3) + LENGTH(FLASH_FS3) - 0x10000;
_flash_fs4_start = ORIGIN(FLASH_FS4);
_flash_fs4_end = ORIGIN(FLASH_FS4) + LENGTH(FLASH_FS4) - 0x10000;
_flash_fs5_start = ORIGIN(FLASH_FS5);
_flash_fs5_end = ORIGIN(FLASH_FS5) + LENGTH(FLASH_FS5) - 0x10000;
_flash_fs6_start = ORIGIN(FLASH_FS6);
_flash_fs6_end = ORIGIN(FLASH_FS6) + LENGTH(FLASH_FS6) - 0x10000;
_flash_fs7_start = ORIGIN(FLASH_FS7);
_flash_fs7_end = ORIGIN(FLASH_FS7) + LENGTH(FLASH_FS7) - 0x10000;
_flash_fs8_start = ORIGIN(FLASH_FS8);
_flash_fs8_end = ORIGIN(FLASH_FS8) + LENGTH(FLASH_FS8);
For completeness mpconfigboard.mk:
MCU_SERIES = f4
CMSIS_MCU = STM32F437xx
AF_FILE = boards/TARGETBOARD/stm32f437_af.csv
LD_FILES = boards/TARGETBOARD/stm32f437.ld boards/common_ifs.ld
TEXT0_ADDR = 0x08000000
TEXT1_ADDR = 0x08020000