Skip to content

Commit 05da8d7

Browse files
FRASTMstephanosio
authored andcommitted
drivers: flash: stm32 page layout size differs in stm32u5 or stm32l5
Adjust the size of the stm32_flash_layout[] table depending on the bank configuration of the stm32u5 or stm32l5 devices. That will avoid div by zero error in flash_get_page_info() if the layout_size is not correct. Assign the *layout_size only once with the correct value : 3 or 1. Signed-off-by: Francois Ramu <[email protected]>
1 parent 4d7e150 commit 05da8d7

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

drivers/flash/flash_stm32l5x.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,10 +360,9 @@ void flash_stm32_page_layout(const struct device *dev,
360360
static struct flash_pages_layout stm32_flash_layout[3];
361361

362362
*layout = stm32_flash_layout;
363-
*layout_size = ARRAY_SIZE(stm32_flash_layout);
364363

365364
if (stm32_flash_layout[0].pages_count != 0) {
366-
/* Short circuit calculation logic if already performed */
365+
/* Short circuit calculation logic if already performed (size is known) */
367366
return;
368367
}
369368

@@ -386,6 +385,8 @@ void flash_stm32_page_layout(const struct device *dev,
386385
/* Bank2 */
387386
stm32_flash_layout[2].pages_count = PAGES_PER_BANK;
388387
stm32_flash_layout[2].pages_size = FLASH_PAGE_SIZE;
388+
389+
*layout_size = ARRAY_SIZE(stm32_flash_layout);
389390
} else {
390391
/*
391392
* For stm32l562xx & stm32l552xx with 512 flash or stm32u58x
@@ -404,6 +405,11 @@ void flash_stm32_page_layout(const struct device *dev,
404405
stm32_flash_layout[0].pages_size = FLASH_PAGE_SIZE_128_BITS;
405406
#endif /* CONFIG_SOC_SERIES_STM32L5X */
406407
}
407-
}
408408

409+
/*
410+
* In this case the stm32_flash_layout table has one single element
411+
* when read by the flash_get_page_info()
412+
*/
413+
*layout_size = 1;
414+
}
409415
}

0 commit comments

Comments
 (0)