Skip to content

Commit 764dbbf

Browse files
FRASTMcarlescufi
authored andcommitted
drivers: flash: stm32 ospi driver configures peripheral clock
The clock of the octospi peripheral is directly defined by the DTS and configured by the clock_control_on function. No specific stm32cube function is required then. The clock control is taking this clock source to calculate the clock rate. Signed-off-by: Francois Ramu <[email protected]>
1 parent c1a9866 commit 764dbbf

File tree

1 file changed

+28
-15
lines changed

1 file changed

+28
-15
lines changed

drivers/flash/flash_stm32_ospi.c

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ typedef void (*irq_config_func_t)(const struct device *dev);
4545

4646
struct flash_stm32_ospi_config {
4747
OCTOSPI_TypeDef *regs;
48-
struct stm32_pclken pclken;
48+
const struct stm32_pclken *pclken; /* clock subsystem */
49+
size_t pclk_len; /* number of clock subsystems */
4950
irq_config_func_t irq_config;
5051
size_t flash_size;
5152
uint32_t max_frequency;
@@ -1568,21 +1569,33 @@ static int flash_stm32_ospi_init(const struct device *dev)
15681569
return ret;
15691570
}
15701571

1571-
/* Initializes the independent peripherals clock */
1572-
__HAL_RCC_OSPI_CONFIG(RCC_OSPICLKSOURCE_SYSCLK); /* */
1573-
15741572
/* Clock configuration */
15751573
if (clock_control_on(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE),
1576-
(clock_control_subsys_t) &dev_cfg->pclken) != 0) {
1574+
(clock_control_subsys_t) &dev_cfg->pclken[0]) != 0) {
15771575
LOG_ERR("Could not enable OSPI clock");
15781576
return -EIO;
15791577
}
1580-
1581-
if (clock_control_get_rate(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE),
1582-
(clock_control_subsys_t) &dev_cfg->pclken,
1583-
&ahb_clock_freq) < 0) {
1584-
LOG_ERR("Failed to get AHB clock frequency");
1585-
return -EIO;
1578+
/* Alternate clock config for peripheral if any */
1579+
if (dev_cfg->pclk_len > 1) {
1580+
if (clock_control_configure(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE),
1581+
(clock_control_subsys_t) &dev_cfg->pclken[1],
1582+
NULL) != 0) {
1583+
LOG_ERR("Could not select OSPI source clock pclk[1]");
1584+
return -EIO;
1585+
}
1586+
if (clock_control_get_rate(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE),
1587+
(clock_control_subsys_t) &dev_cfg->pclken[1],
1588+
&ahb_clock_freq) < 0) {
1589+
LOG_ERR("Failed call clock_control_get_rate(pclk[1])");
1590+
return -EIO;
1591+
}
1592+
} else {
1593+
if (clock_control_get_rate(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE),
1594+
(clock_control_subsys_t) &dev_cfg->pclken[0],
1595+
&ahb_clock_freq) < 0) {
1596+
LOG_ERR("Failed call clock_control_get_rate(pclk[0])");
1597+
return -EIO;
1598+
}
15861599
}
15871600

15881601
for (; prescaler <= STM32_OSPI_CLOCK_PRESCALER_MAX; prescaler++) {
@@ -1773,12 +1786,12 @@ static void flash_stm32_ospi_irq_config_func(const struct device *dev);
17731786

17741787
PINCTRL_DT_DEFINE(STM32_OSPI_NODE);
17751788

1789+
static const struct stm32_pclken pclken_id[] = STM32_DT_CLOCKS(STM32_OSPI_NODE);
1790+
17761791
static const struct flash_stm32_ospi_config flash_stm32_ospi_cfg = {
17771792
.regs = (OCTOSPI_TypeDef *)DT_REG_ADDR(STM32_OSPI_NODE),
1778-
.pclken = {
1779-
.enr = DT_CLOCKS_CELL(STM32_OSPI_NODE, bits),
1780-
.bus = DT_CLOCKS_CELL(STM32_OSPI_NODE, bus)
1781-
},
1793+
.pclken = pclken_id,
1794+
.pclk_len = DT_NUM_CLOCKS(STM32_OSPI_NODE),
17821795
.irq_config = flash_stm32_ospi_irq_config_func,
17831796
.flash_size = DT_INST_PROP(0, size) / 8U,
17841797
.max_frequency = DT_INST_PROP(0, ospi_max_frequency),

0 commit comments

Comments
 (0)