@@ -136,20 +136,23 @@ static const flash_layout_t flash_layout[] = {
136136
137137#elif defined(STM32L4S5xx )
138138
139- // as defined stm32lib/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_flash.h
140- // - operating in single-bank mode (DBANK=0), total 2M; 8k pages
141- // Use the homogeneous form: the get_bank() / get_page() code path below
142- // (for L4 with SYSCFG_MEMRMP_FB_MODE) references FLASH_LAYOUT_START_ADDR
143- // and FLASH_LAYOUT_SECTOR_SIZE, so the layout must be expressed as macros.
144- // Alternative (non-homogeneous array) approach kept here for reference:
145- // #define FLASH_LAYOUT_IS_HOMOGENEOUS (0)
146- // static const flash_layout_t flash_layout[] = {
147- // { (uint32_t)FLASH_BASE, 0x2000, (2<<20)/0x2000 },
148- // };
139+ // STM32L4S5xx: 2 MB total, dual-bank (DBANK=1) with 4 KB pages.
140+ // Verified at runtime via FLASH->OPTR bit 22 (DBANK) = 1 on Q1/Mk4.
141+ // In dual-bank mode the HAL macros agree:
142+ // FLASH_BANK_SIZE = FLASH_SIZE >> 1 = 1 MB
143+ // FLASH_PAGE_SIZE = 0x1000 (per stm32l4xx_hal_flash.h)
144+ // The flash_get_sector_info() / get_bank() / get_page() math (selected by
145+ // the STM32L4 + SYSCFG_MEMRMP_FB_MODE branch below) then produces correct
146+ // physical addresses for both banks.
147+ //
148+ // NOTE: an earlier revision of this case used 0x2000 sectors (single-bank
149+ // DBANK=0 assumption). That made get_page() return half the page index it
150+ // should, so the flash_bdev cache committed to the wrong physical sector
151+ // and settings did not survive reboot.
149152#define FLASH_LAYOUT_IS_HOMOGENEOUS (1)
150153#define FLASH_LAYOUT_START_ADDR (FLASH_BASE)
151- #define FLASH_LAYOUT_SECTOR_SIZE (0x2000 )
152- #define FLASH_LAYOUT_NUM_SECTORS ((2 << 20) / 0x2000 )
154+ #define FLASH_LAYOUT_SECTOR_SIZE (0x1000 )
155+ #define FLASH_LAYOUT_NUM_SECTORS ((2 << 20) / 0x1000 )
153156
154157#elif defined(STM32G0 ) || defined(STM32G4 ) || defined(STM32L0 ) || defined(STM32L4 ) || defined(STM32WB ) || defined(STM32WL )
155158
0 commit comments