STMicroelectronics / STM32CubeL1

Full Firmware Package for the STM32L1 series: HAL+LL drivers, CMSIS, BSP, MW, plus a set of Projects (examples and demos) running on all boards provided by ST (Nucleo, Evaluation and Discovery Kits).
Other
37 stars 24 forks source link

FLASH_SIZE incorrectly reports flash size for cat.3 devices with DEV_ID 0x436 #16

Closed caoddx closed 1 year ago

caoddx commented 1 year ago

Describe the set-up

Describe the bug

FLASH_SIZE incorrectly reports flash size for cat.3 devices with DEV_ID 0x436.

STM32L1 Reference Manual RM0038:

31.1.1 Flash size register F_SIZE: Flash memory size For DEV_ID = 0x416 or 0x427 or 0x429 or 0x437, this field value indicates the Flash memory size of the device in Kbytes. Example: 0x0080 = 128 Kbytes. For DEV_ID = 0x436, the field value can be ‘0’ or ‘1’, with ‘0’ for 384 Kbytes and ‘1’ for 256 Kbytes.

Additional context

My solution:

// stm32l1xx_hal_flash.h:
#if defined (FLASH_CUT1) || defined (FLASH_CUT2)
#define FLASH_SIZE_RAW    (uint32_t)(*((uint32_t *)FLASHSIZE_BASE)&0xFFU)
#else /*FLASH_CUT3 || FLASH_CUT4 || FLASH_CUT5 || FLASH_CUT6*/
#define FLASH_SIZE_RAW    (uint32_t)(*((uint32_t *)FLASHSIZE_BASE)&0xFFFFU)
#endif
#define FLASH_SIZE        (((FLASH_SIZE_RAW) == 0 ? 384 : ((FLASH_SIZE_RAW) == 1 ? 256 : (FLASH_SIZE_RAW))) * 1024)
HBOSTM commented 1 year ago

ST Internal Reference: 134631