Skip to content

Commit a8da574

Browse files
FRASTMkartben
authored andcommitted
drivers: flash: stm32 flash ex op functions are common
Move the stm32 flash driver ex_op functions to common flash_stm32_ex_op.c file. Signed-off-by: Francois Ramu <francois.ramu@st.com>
1 parent 3e166bc commit a8da574

File tree

3 files changed

+38
-45
lines changed

3 files changed

+38
-45
lines changed

drivers/flash/flash_stm32.c

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ int flash_stm32_option_bytes_lock(const struct device *dev, bool enable)
364364
}
365365

366366
#if defined(CONFIG_FLASH_EX_OP_ENABLED) && defined(CONFIG_FLASH_STM32_BLOCK_REGISTERS)
367-
static int flash_stm32_control_register_disable(const struct device *dev)
367+
int flash_stm32_control_register_disable(const struct device *dev)
368368
{
369369
FLASH_TypeDef *regs = FLASH_STM32_REGS(dev);
370370

@@ -394,7 +394,7 @@ static int flash_stm32_control_register_disable(const struct device *dev)
394394
#endif
395395
}
396396

397-
static int flash_stm32_option_bytes_disable(const struct device *dev)
397+
int flash_stm32_option_bytes_disable(const struct device *dev)
398398
{
399399
FLASH_TypeDef *regs = FLASH_STM32_REGS(dev);
400400

@@ -432,41 +432,6 @@ flash_stm32_get_parameters(const struct device *dev)
432432
return &flash_stm32_parameters;
433433
}
434434

435-
#ifdef CONFIG_FLASH_EX_OP_ENABLED
436-
static int flash_stm32_ex_op(const struct device *dev, uint16_t code,
437-
const uintptr_t in, void *out)
438-
{
439-
int rv = -ENOTSUP;
440-
441-
flash_stm32_sem_take(dev);
442-
443-
switch (code) {
444-
#if defined(CONFIG_FLASH_STM32_WRITE_PROTECT)
445-
case FLASH_STM32_EX_OP_SECTOR_WP:
446-
rv = flash_stm32_ex_op_sector_wp(dev, in, out);
447-
break;
448-
#endif /* CONFIG_FLASH_STM32_WRITE_PROTECT */
449-
#if defined(CONFIG_FLASH_STM32_READOUT_PROTECTION)
450-
case FLASH_STM32_EX_OP_RDP:
451-
rv = flash_stm32_ex_op_rdp(dev, in, out);
452-
break;
453-
#endif /* CONFIG_FLASH_STM32_READOUT_PROTECTION */
454-
#if defined(CONFIG_FLASH_STM32_BLOCK_REGISTERS)
455-
case FLASH_STM32_EX_OP_BLOCK_OPTION_REG:
456-
rv = flash_stm32_option_bytes_disable(dev);
457-
break;
458-
case FLASH_STM32_EX_OP_BLOCK_CONTROL_REG:
459-
rv = flash_stm32_control_register_disable(dev);
460-
break;
461-
#endif /* CONFIG_FLASH_STM32_BLOCK_REGISTERS */
462-
}
463-
464-
flash_stm32_sem_give(dev);
465-
466-
return rv;
467-
}
468-
#endif
469-
470435
static struct flash_stm32_priv flash_data = {
471436
.regs = (FLASH_TypeDef *) DT_INST_REG_ADDR(0),
472437
/* Getting clocks information from device tree description depending

drivers/flash/flash_stm32.h

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -351,14 +351,9 @@ uint8_t flash_stm32_get_rdp_level(const struct device *dev);
351351
void flash_stm32_set_rdp_level(const struct device *dev, uint8_t level);
352352
#endif
353353

354-
/* Flash extended operations */
355-
#if defined(CONFIG_FLASH_STM32_WRITE_PROTECT)
356-
int flash_stm32_ex_op_sector_wp(const struct device *dev, const uintptr_t in,
357-
void *out);
358-
#endif
359-
#if defined(CONFIG_FLASH_STM32_READOUT_PROTECTION)
360-
int flash_stm32_ex_op_rdp(const struct device *dev, const uintptr_t in,
361-
void *out);
354+
#if defined(CONFIG_FLASH_STM32_BLOCK_REGISTERS)
355+
int flash_stm32_control_register_disable(const struct device *dev);
356+
int flash_stm32_option_bytes_disable(const struct device *dev);
362357
#endif
363358

364359
#endif /* ZEPHYR_DRIVERS_FLASH_FLASH_STM32_H_ */

drivers/flash/flash_stm32_ex_op.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,3 +225,36 @@ int flash_stm32_ex_op_rdp(const struct device *dev, const uintptr_t in,
225225
return rc;
226226
}
227227
#endif /* CONFIG_FLASH_STM32_READOUT_PROTECTION */
228+
229+
int flash_stm32_ex_op(const struct device *dev, uint16_t code,
230+
const uintptr_t in, void *out)
231+
{
232+
int rv = -ENOTSUP;
233+
234+
flash_stm32_sem_take(dev);
235+
236+
switch (code) {
237+
#if defined(CONFIG_FLASH_STM32_WRITE_PROTECT)
238+
case FLASH_STM32_EX_OP_SECTOR_WP:
239+
rv = flash_stm32_ex_op_sector_wp(dev, in, out);
240+
break;
241+
#endif /* CONFIG_FLASH_STM32_WRITE_PROTECT */
242+
#if defined(CONFIG_FLASH_STM32_READOUT_PROTECTION)
243+
case FLASH_STM32_EX_OP_RDP:
244+
rv = flash_stm32_ex_op_rdp(dev, in, out);
245+
break;
246+
#endif /* CONFIG_FLASH_STM32_READOUT_PROTECTION */
247+
#if defined(CONFIG_FLASH_STM32_BLOCK_REGISTERS)
248+
case FLASH_STM32_EX_OP_BLOCK_OPTION_REG:
249+
rv = flash_stm32_option_bytes_disable(dev);
250+
break;
251+
case FLASH_STM32_EX_OP_BLOCK_CONTROL_REG:
252+
rv = flash_stm32_control_register_disable(dev);
253+
break;
254+
#endif /* CONFIG_FLASH_STM32_BLOCK_REGISTERS */
255+
}
256+
257+
flash_stm32_sem_give(dev);
258+
259+
return rv;
260+
}

0 commit comments

Comments
 (0)