Skip to content

Commit 376c857

Browse files
committed
drivers/flash: stm32wb: Add HSEM
Add HSEM for Flash access since shared between 2 cores. Signed-off-by: Erwan Gouriou <[email protected]>
1 parent 672e834 commit 376c857

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

drivers/flash/flash_stm32.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,33 @@
3434
#define STM32_FLASH_TIMEOUT (K_MSEC(25))
3535
#endif
3636

37+
#define CFG_HW_FLASH_SEMID 2
38+
3739
/*
3840
* This is named flash_stm32_sem_take instead of flash_stm32_lock (and
3941
* similarly for flash_stm32_sem_give) to avoid confusion with locking
4042
* actual flash pages.
4143
*/
4244
static inline void flash_stm32_sem_take(struct device *dev)
4345
{
46+
47+
#ifdef CONFIG_SOC_SERIES_STM32WBX
48+
while (LL_HSEM_1StepLock(HSEM, CFG_HW_FLASH_SEMID))
49+
;
50+
#endif /* CONFIG_SOC_SERIES_STM32WBX */
51+
4452
k_sem_take(&FLASH_STM32_PRIV(dev)->sem, K_FOREVER);
4553
}
4654

4755
static inline void flash_stm32_sem_give(struct device *dev)
4856
{
57+
4958
k_sem_give(&FLASH_STM32_PRIV(dev)->sem);
59+
60+
#ifdef CONFIG_SOC_SERIES_STM32WBX
61+
LL_HSEM_ReleaseLock(HSEM, CFG_HW_FLASH_SEMID, 0);
62+
#endif /* CONFIG_SOC_SERIES_STM32WBX */
63+
5064
}
5165

5266
#if !defined(CONFIG_SOC_SERIES_STM32WBX)
@@ -294,6 +308,10 @@ static int stm32_flash_init(struct device *dev)
294308
}
295309
#endif
296310

311+
#ifdef CONFIG_SOC_SERIES_STM32WBX
312+
LL_AHB3_GRP1_EnableClock(LL_AHB3_GRP1_PERIPH_HSEM);
313+
#endif /* CONFIG_SOC_SERIES_STM32WBX */
314+
297315
k_sem_init(&p->sem, 1, 1);
298316

299317
return flash_stm32_write_protection(dev, false);

soc/arm/st_stm32/stm32wb/soc.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@
4343
#include <stm32wbxx_ll_system.h>
4444
#endif /* CONFIG_CLOCK_CONTROL_STM32_CUBE */
4545

46+
#ifdef CONFIG_FLASH
47+
#include <stm32wbxx_ll_hsem.h>
48+
#endif /* CONFIG_FLASH */
49+
4650
#endif /* !_ASMLANGUAGE */
4751

4852
#endif /* _STM32WBX_SOC_H_ */

0 commit comments

Comments
 (0)