Skip to content

Commit 4c862c1

Browse files
str4t0mcfriedt
authored andcommitted
drivers: flash: stm32: wait for CFGBSY & BSY2 in wait_flash_idle
Some series (namely g0, u5, wb, wl, ?) use CFGBSY to indicate that FLASH_CR is not ready to be modfied. This commit adds this flag additionally to other the flash busy flags, in flash_stm32_wait_flash_idle such that the driver waits before trying to modify PG, PNB[6:0], PER, and MER bits in FLASH_CR. Additionally, dual bank variants of STM32G0 have a seperarate BSY2 flag for flash bank two. Until now this was not yet checked in flash_stm32_wait_flash_idle. Signed-off-by: Thomas Stranger <[email protected]>
1 parent f15f9df commit 4c862c1

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

drivers/flash/flash_stm32.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ int flash_stm32_wait_flash_idle(const struct device *dev)
103103

104104
busy_flags = FLASH_STM32_SR_BUSY;
105105

106+
/* Some Series can't modify FLASH_CR reg while CFGBSY is set. Wait as well */
107+
#if defined(FLASH_STM32_SR_CFGBSY)
108+
busy_flags |= FLASH_STM32_SR_CFGBSY;
109+
#endif
110+
106111
while ((FLASH_STM32_REGS(dev)->FLASH_STM32_SR & busy_flags)) {
107112
if (k_uptime_get() > timeout_time) {
108113
LOG_ERR("Timeout! val: %d", STM32_FLASH_TIMEOUT);

drivers/flash/flash_stm32.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,21 @@ struct flash_stm32_priv {
5454

5555
/* Redefintions of flags and masks to harmonize stm32 series: */
5656
#if defined(CONFIG_SOC_SERIES_STM32G0X)
57+
#if defined(FLASH_FLAG_BSY2)
58+
#define FLASH_STM32_SR_BUSY (FLASH_FLAG_BSY1 | FLASH_FLAG_BSY2);
59+
#else
5760
#define FLASH_STM32_SR_BUSY (FLASH_SR_BSY1)
61+
#endif /* defined(FLASH_FLAG_BSY2) */
5862
#else
5963
#define FLASH_STM32_SR_BUSY (FLASH_FLAG_BSY)
6064
#endif
6165

66+
#if defined(CONFIG_SOC_SERIES_STM32G0X)
67+
#define FLASH_STM32_SR_CFGBSY (FLASH_SR_CFGBSY)
68+
#elif defined(FLASH_FLAG_CFGBSY)
69+
#define FLASH_STM32_SR_CFGBSY (FLASH_FLAG_CFGBSY)
70+
#endif
71+
6272
#if defined(CONFIG_SOC_SERIES_STM32G0X)
6373
/* STM32G0 HAL FLASH_FLAG_x don't represent bit-masks, need FLASH_SR_x instead */
6474
#define FLASH_STM32_SR_OPERR FLASH_SR_OPERR

0 commit comments

Comments
 (0)