From a1903f2867037ada39ab814658e1034eb96d1827 Mon Sep 17 00:00:00 2001 From: Tarek BOCHKATI Date: Thu, 2 Sep 2021 12:03:59 +0100 Subject: [PATCH] flash/stm32l4x: fix dual bank support for STM32L552xC devices For STM32L552xC devices with 256K flash: dual bank mode is activated if DB256 is set page size is 2KB if DBANK is set For parts with 512K (aka STM32L5x2xE): DBANK controls both of dual/single bank mode and page size as well. Change-Id: I8be668d5552fefe81acffaf2e3e35ef5e938162e Signed-off-by: Tarek BOCHKATI Reported-by: Patrik Bachan Fixes: https://sourceforge.net/p/openocd/tickets/317/ Reviewed-on: https://review.openocd.org/c/openocd/+/6538 Tested-by: jenkins Reviewed-by: Oleksij Rempel --- src/flash/nor/stm32l4x.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/flash/nor/stm32l4x.c b/src/flash/nor/stm32l4x.c index 0182aae660..8c292e76d5 100644 --- a/src/flash/nor/stm32l4x.c +++ b/src/flash/nor/stm32l4x.c @@ -1923,15 +1923,17 @@ static int stm32l4_probe(struct flash_bank *bank) /* STM32L55/L56xx can be single/dual bank: * if size = 512K check DBANK bit * if size = 256K check DB256K bit + * + * default page size is 4kb, if DBANK = 1, the page size is 2kb. */ - page_size_kb = 4; + + page_size_kb = (stm32l4_info->optr & FLASH_L5_DBANK) ? 2 : 4; num_pages = flash_size_kb / page_size_kb; stm32l4_info->bank1_sectors = num_pages; + if ((is_max_flash_size && (stm32l4_info->optr & FLASH_L5_DBANK)) || (!is_max_flash_size && (stm32l4_info->optr & FLASH_L5_DB256))) { stm32l4_info->dual_bank_mode = true; - page_size_kb = 2; - num_pages = flash_size_kb / page_size_kb; stm32l4_info->bank1_sectors = num_pages / 2; } break; -- 2.30.2