2929/* STM32L4: maximum erase time of 24.47ms for a 2K sector */
3030#elif defined(CONFIG_SOC_SERIES_STM32L4X )
3131#define STM32_FLASH_TIMEOUT (K_MSEC(25))
32+ /* TBC: STM32WB: maximum erase time of 24.47ms for a 2K sector */
33+ #elif defined(CONFIG_SOC_SERIES_STM32WBX )
34+ #define STM32_FLASH_TIMEOUT (K_MSEC(25))
3235#endif
3336
3437/*
@@ -46,6 +49,7 @@ static inline void flash_stm32_sem_give(struct device *dev)
4649 k_sem_give (& FLASH_STM32_PRIV (dev )-> sem );
4750}
4851
52+ #if !defined(CONFIG_SOC_SERIES_STM32WBX )
4953static int flash_stm32_check_status (struct device * dev )
5054{
5155 u32_t const error =
@@ -75,6 +79,7 @@ static int flash_stm32_check_status(struct device *dev)
7579
7680 return 0 ;
7781}
82+ #endif /* CONFIG_SOC_SERIES_STM32L5X */
7883
7984int flash_stm32_wait_flash_idle (struct device * dev )
8085{
@@ -86,7 +91,7 @@ int flash_stm32_wait_flash_idle(struct device *dev)
8691 return - EIO ;
8792 }
8893
89- while (( FLASH_STM32_REGS ( dev ) -> sr & FLASH_SR_BSY )) {
94+ while (__HAL_FLASH_GET_FLAG ( FLASH_FLAG_BSY )) {
9095 if (k_uptime_get () > timeout_time ) {
9196 return - EIO ;
9297 }
@@ -95,20 +100,25 @@ int flash_stm32_wait_flash_idle(struct device *dev)
95100 return 0 ;
96101}
97102
103+
98104static void flash_stm32_flush_caches (struct device * dev ,
99105 off_t offset , size_t len )
100106{
101107#if defined(CONFIG_SOC_SERIES_STM32F0X ) || defined(CONFIG_SOC_SERIES_STM32F3X )
102108 ARG_UNUSED (dev );
103109 ARG_UNUSED (offset );
104110 ARG_UNUSED (len );
105- #elif defined(CONFIG_SOC_SERIES_STM32F4X ) || defined(CONFIG_SOC_SERIES_STM32L4X )
111+ #elif defined(CONFIG_SOC_SERIES_STM32F4X ) || \
112+ defined(CONFIG_SOC_SERIES_STM32L4X ) || \
113+ defined(CONFIG_SOC_SERIES_STM32WBX )
106114 ARG_UNUSED (offset );
107115 ARG_UNUSED (len );
108116#if defined(CONFIG_SOC_SERIES_STM32F4X )
109117 struct stm32f4x_flash * regs = FLASH_STM32_REGS (dev );
110118#elif defined(CONFIG_SOC_SERIES_STM32L4X )
111119 struct stm32l4x_flash * regs = FLASH_STM32_REGS (dev );
120+ #elif defined(CONFIG_SOC_SERIES_STM32WBX )
121+ struct stm32wbx_flash * regs = FLASH_STM32_REGS (dev );
112122#endif
113123 if (regs -> acr .val & FLASH_ACR_DCEN ) {
114124 regs -> acr .val &= ~FLASH_ACR_DCEN ;
@@ -185,17 +195,6 @@ static int flash_stm32_write(struct device *dev, off_t offset,
185195
186196static int flash_stm32_write_protection (struct device * dev , bool enable )
187197{
188- #if defined(CONFIG_SOC_SERIES_STM32F4X )
189- struct stm32f4x_flash * regs = FLASH_STM32_REGS (dev );
190- #elif defined(CONFIG_SOC_SERIES_STM32F7X )
191- struct stm32f7x_flash * regs = FLASH_STM32_REGS (dev );
192- #elif defined(CONFIG_SOC_SERIES_STM32F0X )
193- struct stm32f0x_flash * regs = FLASH_STM32_REGS (dev );
194- #elif defined(CONFIG_SOC_SERIES_STM32F3X )
195- struct stm32f3x_flash * regs = FLASH_STM32_REGS (dev );
196- #elif defined(CONFIG_SOC_SERIES_STM32L4X )
197- struct stm32l4x_flash * regs = FLASH_STM32_REGS (dev );
198- #endif
199198 int rc = 0 ;
200199
201200 flash_stm32_sem_take (dev );
@@ -206,17 +205,9 @@ static int flash_stm32_write_protection(struct device *dev, bool enable)
206205 flash_stm32_sem_give (dev );
207206 return rc ;
208207 }
209- regs -> cr |= FLASH_CR_LOCK ;
208+ HAL_FLASH_Lock () ;
210209 } else {
211- if (regs -> cr & FLASH_CR_LOCK ) {
212- regs -> keyr = FLASH_KEY1 ;
213- #ifdef CONFIG_SOC_SERIES_STM32F3X
214- /* On STM32F3 series some time is requested */
215- /* before writing again on key register */
216- flash_stm32_wait_flash_idle (dev );
217- #endif /* CONFIG_SOC_SERIES_STM32F3X */
218- regs -> keyr = FLASH_KEY2 ;
219- }
210+ HAL_FLASH_Unlock ();
220211 }
221212
222213 flash_stm32_sem_give (dev );
@@ -241,6 +232,8 @@ static struct flash_stm32_priv flash_data = {
241232 .regs = (struct stm32l4x_flash * ) DT_FLASH_DEV_BASE_ADDRESS ,
242233 .pclken = { .bus = STM32_CLOCK_BUS_AHB1 ,
243234 .enr = LL_AHB1_GRP1_PERIPH_FLASH },
235+ #elif defined(CONFIG_SOC_SERIES_STM32WBX )
236+ .regs = (struct stm32wbx_flash * ) DT_FLASH_DEV_BASE_ADDRESS ,
244237#endif
245238};
246239
0 commit comments