2020-08-17 10:07 AM
Is there a preprocessor define of the flash size available at compile time ?
I know that the flash size can be read at run-time from the FLASH_SIZE_DATA_REGISTER but I need the value for a constexpr.
I found only the following definitions - but this is not sufficient to calculate the flash size (examples for a STM32F103 device):
FLASH_BASE: 0x08000000UL
FLASH_BANK1_END: 0x0801FFFFUL
FLASH_PAGE_SIZE: 0x400
e.g. the number of pages would be nice :smiling_face_with_smiling_eyes:
Thanks!
2020-08-17 10:22 AM
>>Is there a preprocessor define of the flash size available at compile time ?
No but the compiler is often told which part via the command line. Check project settings.
2020-08-17 11:54 AM
number of pages = (end-base)/pagesize
Also if you are using GCC, you can read memory section info in linker script:
2020-08-17 12:22 PM
Been a long time since I used F1 parts, but as I recall the flash code could determine what hardware and flash capacity was at runtime, via DEVID and FLASH_KB (0x1FFFF7E0)
Could figure page size (1K, 2KB) and page count
2020-08-17 03:15 PM
On the F4 family, and others, FLASH_END is available in the CMSIS board include file, but something similar doesn't appear to exist on the F1 series.
2020-08-17 03:23 PM
The F1 has smaller and uniform flash sectors/pages, but only has 8-bit as I recall, so 1MB part had 2-banks, with 256 * 2KB pages
STM32Cube_FW_F1_V1.8.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_flash_ex.h
/** @defgroup FLASHEx_Page_Size Page Size
* @{
*/
#if (defined(STM32F101x6) || defined(STM32F102x6) || defined(STM32F103x6) || defined(STM32F100xB) || defined(STM32F101xB) || defined(STM32F102xB) || defined(STM32F103xB))
#define FLASH_PAGE_SIZE 0x400U
#endif /* STM32F101x6 || STM32F102x6 || STM32F103x6 */
/* STM32F100xB || STM32F101xB || STM32F102xB || STM32F103xB */
#if (defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F103xE) || defined(STM32F101xG) || defined(STM32F103xG) || defined(STM32F105xC) || defined(STM32F107xC))
#define FLASH_PAGE_SIZE 0x800U
#endif /* STM32F100xB || STM32F101xB || STM32F102xB || STM32F103xB */
/* STM32F101xG || STM32F103xG */
/* STM32F105xC || STM32F107xC */
2020-08-18 01:52 AM
Hi Guys,
thanks for your feedback.
It seams that for F1 devices there is no "easy way" to get the flash size of the selected device.
To keep the effort low I'll create a define it in the Eclipse project settings (although I don't like "redundant" settings :( ) ...