Skip to content

Commit 3e166bc

Browse files
FRASTMkartben
authored andcommitted
drivers: flash: stm32 driver move sem functions for multithread
Place the flash_stm32_sem_take and flash_stm32_sem_give function to header file for common to use in any flash driver Signed-off-by: Francois Ramu <francois.ramu@st.com>
1 parent 2424bfd commit 3e166bc

File tree

3 files changed

+38
-57
lines changed

3 files changed

+38
-57
lines changed

drivers/flash/flash_stm32.c

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include <zephyr/logging/log.h>
2323

2424
#include "flash_stm32.h"
25-
#include "stm32_hsem.h"
2625

2726
LOG_MODULE_REGISTER(flash_stm32, CONFIG_FLASH_LOG_LEVEL);
2827

@@ -59,32 +58,6 @@ int __weak flash_stm32_check_configuration(void)
5958
return 0;
6059
}
6160

62-
#if defined(CONFIG_MULTITHREADING)
63-
/*
64-
* This is named flash_stm32_sem_take instead of flash_stm32_lock (and
65-
* similarly for flash_stm32_sem_give) to avoid confusion with locking
66-
* actual flash pages.
67-
*/
68-
static inline void _flash_stm32_sem_take(const struct device *dev)
69-
{
70-
k_sem_take(&FLASH_STM32_PRIV(dev)->sem, K_FOREVER);
71-
z_stm32_hsem_lock(CFG_HW_FLASH_SEMID, HSEM_LOCK_WAIT_FOREVER);
72-
}
73-
74-
static inline void _flash_stm32_sem_give(const struct device *dev)
75-
{
76-
z_stm32_hsem_unlock(CFG_HW_FLASH_SEMID);
77-
k_sem_give(&FLASH_STM32_PRIV(dev)->sem);
78-
}
79-
80-
#define flash_stm32_sem_init(dev) k_sem_init(&FLASH_STM32_PRIV(dev)->sem, 1, 1)
81-
#define flash_stm32_sem_take(dev) _flash_stm32_sem_take(dev)
82-
#define flash_stm32_sem_give(dev) _flash_stm32_sem_give(dev)
83-
#else
84-
#define flash_stm32_sem_init(dev)
85-
#define flash_stm32_sem_take(dev)
86-
#define flash_stm32_sem_give(dev)
87-
#endif
8861

8962
#if !defined(CONFIG_SOC_SERIES_STM32WBX)
9063
static int flash_stm32_check_status(const struct device *dev)
@@ -319,7 +292,7 @@ int flash_stm32_option_bytes_lock(const struct device *dev, bool enable)
319292
{
320293
FLASH_TypeDef *regs = FLASH_STM32_REGS(dev);
321294

322-
#if defined(FLASH_OPTCR_OPTLOCK) /* F2, F4, F7 and H7 */
295+
#if defined(FLASH_OPTCR_OPTLOCK) /* F2, F4, F7 */
323296
if (enable) {
324297
regs->OPTCR |= FLASH_OPTCR_OPTLOCK;
325298
} else if (regs->OPTCR & FLASH_OPTCR_OPTLOCK) {
@@ -395,7 +368,7 @@ static int flash_stm32_control_register_disable(const struct device *dev)
395368
{
396369
FLASH_TypeDef *regs = FLASH_STM32_REGS(dev);
397370

398-
#if defined(FLASH_CR_LOCK) /* F0, F1, F2, F3, F4, F7, L4, G0, G4, H7, WB, WL \
371+
#if defined(FLASH_CR_LOCK) /* F0, F1, F2, F3, F4, F7, L4, G0, G4, WB, WL \
399372
*/
400373
/*
401374
* Access to control register can be disabled by writing wrong key to
@@ -425,7 +398,7 @@ static int flash_stm32_option_bytes_disable(const struct device *dev)
425398
{
426399
FLASH_TypeDef *regs = FLASH_STM32_REGS(dev);
427400

428-
#if defined(FLASH_OPTCR_OPTLOCK) /* F2, F4, F7 and H7 */
401+
#if defined(FLASH_OPTCR_OPTLOCK) /* F2, F4, F7 */
429402
/*
430403
* Access to option register can be disabled by writing wrong key to
431404
* the key register. Option register will remain disabled until reset.

drivers/flash/flash_stm32.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#define ZEPHYR_DRIVERS_FLASH_FLASH_STM32_H_
1111

1212
#include <zephyr/drivers/flash.h>
13+
#include "stm32_hsem.h"
1314

1415
#if DT_NODE_HAS_PROP(DT_INST(0, st_stm32_flash_controller), clocks) || \
1516
DT_NODE_HAS_PROP(DT_INST(0, st_stm32h7_flash_controller), clocks)
@@ -271,6 +272,40 @@ static inline bool flash_stm32_range_exists(const struct device *dev,
271272
}
272273
#endif /* CONFIG_FLASH_PAGE_LAYOUT */
273274

275+
276+
#if defined(CONFIG_MULTITHREADING) || defined(CONFIG_STM32H7_DUAL_CORE)
277+
/*
278+
* This is named flash_stm32_sem_take instead of flash_stm32_lock (and
279+
* similarly for flash_stm32_sem_give) to avoid confusion with locking
280+
* actual flash pages.
281+
*/
282+
283+
static inline void _flash_stm32_sem_take(const struct device *dev)
284+
{
285+
k_sem_take(&FLASH_STM32_PRIV(dev)->sem, K_FOREVER);
286+
z_stm32_hsem_lock(CFG_HW_FLASH_SEMID, HSEM_LOCK_WAIT_FOREVER);
287+
}
288+
289+
static inline void _flash_stm32_sem_give(const struct device *dev)
290+
{
291+
z_stm32_hsem_unlock(CFG_HW_FLASH_SEMID);
292+
k_sem_give(&FLASH_STM32_PRIV(dev)->sem);
293+
}
294+
295+
#define flash_stm32_sem_init(dev) k_sem_init(&FLASH_STM32_PRIV(dev)->sem, 1, 1)
296+
#define flash_stm32_sem_take(dev) _flash_stm32_sem_take(dev)
297+
#define flash_stm32_sem_give(dev) _flash_stm32_sem_give(dev)
298+
#else
299+
#define flash_stm32_sem_init(dev)
300+
#define flash_stm32_sem_take(dev)
301+
#define flash_stm32_sem_give(dev)
302+
#endif /* CONFIG_MULTITHREADING */
303+
304+
#ifdef CONFIG_FLASH_EX_OP_ENABLED
305+
int flash_stm32_ex_op(const struct device *dev, uint16_t code,
306+
const uintptr_t in, void *out);
307+
#endif /* CONFIG_FLASH_EX_OP_ENABLED */
308+
274309
static inline bool flash_stm32_valid_write(off_t offset, uint32_t len)
275310
{
276311
return ((offset % FLASH_STM32_WRITE_BLOCK_SIZE == 0) &&

drivers/flash/flash_stm32h7x.c

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -62,33 +62,6 @@ struct flash_stm32_sector_t {
6262
volatile uint32_t *sr;
6363
};
6464

65-
#if defined(CONFIG_MULTITHREADING) || defined(CONFIG_STM32H7_DUAL_CORE)
66-
/*
67-
* This is named flash_stm32_sem_take instead of flash_stm32_lock (and
68-
* similarly for flash_stm32_sem_give) to avoid confusion with locking
69-
* actual flash sectors.
70-
*/
71-
static inline void _flash_stm32_sem_take(const struct device *dev)
72-
{
73-
k_sem_take(&FLASH_STM32_PRIV(dev)->sem, K_FOREVER);
74-
z_stm32_hsem_lock(CFG_HW_FLASH_SEMID, HSEM_LOCK_WAIT_FOREVER);
75-
}
76-
77-
static inline void _flash_stm32_sem_give(const struct device *dev)
78-
{
79-
z_stm32_hsem_unlock(CFG_HW_FLASH_SEMID);
80-
k_sem_give(&FLASH_STM32_PRIV(dev)->sem);
81-
}
82-
83-
#define flash_stm32_sem_init(dev) k_sem_init(&FLASH_STM32_PRIV(dev)->sem, 1, 1)
84-
#define flash_stm32_sem_take(dev) _flash_stm32_sem_take(dev)
85-
#define flash_stm32_sem_give(dev) _flash_stm32_sem_give(dev)
86-
#else
87-
#define flash_stm32_sem_init(dev)
88-
#define flash_stm32_sem_take(dev)
89-
#define flash_stm32_sem_give(dev)
90-
#endif
91-
9265
bool flash_stm32_valid_range(const struct device *dev, off_t offset, uint32_t len, bool write)
9366
{
9467
#if defined(DUAL_BANK)

0 commit comments

Comments
 (0)