Skip to content

Commit ee280d1

Browse files
committed
drivers/flash: STM32: Getting clock settings from DT.
This commit uses DT APIs to get the flash clock settings. Signed-off-by: Krishna Mohan Dani <[email protected]>
1 parent 782f41d commit ee280d1

File tree

2 files changed

+10
-27
lines changed

2 files changed

+10
-27
lines changed

drivers/flash/flash_stm32.c

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -348,14 +348,11 @@ flash_stm32_get_parameters(const struct device *dev)
348348

349349
static struct flash_stm32_priv flash_data = {
350350
.regs = (FLASH_TypeDef *) DT_INST_REG_ADDR(0),
351-
#if defined(CONFIG_SOC_SERIES_STM32L4X) || \
352-
defined(CONFIG_SOC_SERIES_STM32F0X) || \
353-
defined(CONFIG_SOC_SERIES_STM32F1X) || \
354-
defined(CONFIG_SOC_SERIES_STM32F3X) || \
355-
defined(CONFIG_SOC_SERIES_STM32G0X) || \
356-
defined(CONFIG_SOC_SERIES_STM32G4X)
357-
.pclken = { .bus = STM32_CLOCK_BUS_AHB1,
358-
.enr = LL_AHB1_GRP1_PERIPH_FLASH },
351+
#if DT_INST_NODE_HAS_PROP(0, clocks)
352+
.pclken = {
353+
.enr = DT_INST_CLOCKS_CELL(0, bits),
354+
.bus = DT_INST_CLOCKS_CELL(0, bus),
355+
}
359356
#endif
360357
};
361358

@@ -372,17 +369,15 @@ static const struct flash_driver_api flash_stm32_api = {
372369
static int stm32_flash_init(const struct device *dev)
373370
{
374371
int rc;
375-
#if defined(CONFIG_SOC_SERIES_STM32L4X) || \
376-
defined(CONFIG_SOC_SERIES_STM32F0X) || \
377-
defined(CONFIG_SOC_SERIES_STM32F1X) || \
378-
defined(CONFIG_SOC_SERIES_STM32F3X) || \
379-
defined(CONFIG_SOC_SERIES_STM32G0X)
372+
/* Below is applicable to L4, F0, F1, F3, G0*/
373+
#if DT_INST_NODE_HAS_PROP(0, clocks)
380374
struct flash_stm32_priv *p = FLASH_STM32_PRIV(dev);
381375
const struct device *clk = DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE);
382376

383377
/*
384378
* On STM32F0, Flash interface clock source is always HSI,
385379
* so statically enable HSI here.
380+
* Below is applicable to F0, F1 and F3 as HSI is the source
386381
*/
387382
#if defined(CONFIG_SOC_SERIES_STM32F0X) || \
388383
defined(CONFIG_SOC_SERIES_STM32F1X) || \

drivers/flash/flash_stm32.h

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,14 @@
88
#ifndef ZEPHYR_DRIVERS_FLASH_FLASH_STM32_H_
99
#define ZEPHYR_DRIVERS_FLASH_FLASH_STM32_H_
1010

11-
#if defined(CONFIG_SOC_SERIES_STM32L4X) || \
12-
defined(CONFIG_SOC_SERIES_STM32F0X) || \
13-
defined(CONFIG_SOC_SERIES_STM32F1X) || \
14-
defined(CONFIG_SOC_SERIES_STM32F3X) || \
15-
defined(CONFIG_SOC_SERIES_STM32G0X) || \
16-
defined(CONFIG_SOC_SERIES_STM32G4X) || \
17-
defined(CONFIG_SOC_SERIES_STM32H7X)
11+
#if DT_NODE_HAS_PROP(DT_INST(0, st_stm32_flash_controller), clocks)
1812
#include <drivers/clock_control.h>
1913
#include <drivers/clock_control/stm32_clock_control.h>
2014
#endif
2115

2216
struct flash_stm32_priv {
2317
FLASH_TypeDef *regs;
24-
#if defined(CONFIG_SOC_SERIES_STM32L4X) || \
25-
defined(CONFIG_SOC_SERIES_STM32F0X) || \
26-
defined(CONFIG_SOC_SERIES_STM32F1X) || \
27-
defined(CONFIG_SOC_SERIES_STM32F3X) || \
28-
defined(CONFIG_SOC_SERIES_STM32G0X) || \
29-
defined(CONFIG_SOC_SERIES_STM32G4X) || \
30-
defined(CONFIG_SOC_SERIES_STM32H7X)
18+
#if DT_NODE_HAS_PROP(DT_INST(0, st_stm32_flash_controller), clocks)
3119
/* clock subsystem driving this peripheral */
3220
struct stm32_pclken pclken;
3321
#endif

0 commit comments

Comments
 (0)