STM32CubeL1 icon indicating copy to clipboard operation
STM32CubeL1 copied to clipboard

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

Open caoddx opened this issue 2 years ago • 1 comments

Describe the set-up

  • Custom board with STM32L152RCT6A
  • FW_L1 V1.10.3

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)

caoddx avatar Aug 17 '22 03:08 caoddx

ST Internal Reference: 134631

HBOSTM avatar Sep 14 '22 13:09 HBOSTM