Skip to content

Commit 71547b1

Browse files
committed
drivers: spi: stm32: Refactor for reinitialization feature
Refactor to prevent code duplication in the driver reinitialization functionality following this commit. Move HAL include statement from driver source to header to make header self-contained. Signed-off-by: Kenneth J. Miller <[email protected]>
1 parent 3931c01 commit 71547b1

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

drivers/spi/spi_ll_stm32.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ LOG_MODULE_REGISTER(spi_ll_stm32);
1313
#include <zephyr/sys/util.h>
1414
#include <zephyr/kernel.h>
1515
#include <soc.h>
16-
#include <stm32_ll_spi.h>
1716
#include <errno.h>
1817
#include <zephyr/drivers/spi.h>
1918
#include <zephyr/drivers/pinctrl.h>
@@ -983,10 +982,8 @@ static inline bool spi_stm32_is_subghzspi(const struct device *dev)
983982
#endif
984983
}
985984

986-
static int spi_stm32_init(const struct device *dev)
985+
static int spi_stm32_clock_configure(const struct spi_stm32_config *cfg)
987986
{
988-
struct spi_stm32_data *data __attribute__((unused)) = dev->data;
989-
const struct spi_stm32_config *cfg = dev->config;
990987
int err;
991988

992989
if (!device_is_ready(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE))) {
@@ -1011,6 +1008,20 @@ static int spi_stm32_init(const struct device *dev)
10111008
}
10121009
}
10131010

1011+
return 0;
1012+
}
1013+
1014+
static int spi_stm32_init(const struct device *dev)
1015+
{
1016+
struct spi_stm32_data *data __attribute__((unused)) = dev->data;
1017+
const struct spi_stm32_config *cfg = dev->config;
1018+
int err;
1019+
1020+
err = spi_stm32_clock_configure(cfg);
1021+
if (err < 0) {
1022+
return err;
1023+
}
1024+
10141025
if (!spi_stm32_is_subghzspi(dev)) {
10151026
/* Configure dt provided device signals when available */
10161027
err = pinctrl_apply_state(cfg->pcfg, PINCTRL_STATE_DEFAULT);
@@ -1119,8 +1130,6 @@ static void spi_stm32_irq_config_func_##id(const struct device *dev) \
11191130
#define STM32_SPI_USE_SUBGHZSPI_NSS_CONFIG(id)
11201131
#endif
11211132

1122-
1123-
11241133
#define STM32_SPI_INIT(id) \
11251134
STM32_SPI_IRQ_HANDLER_DECL(id); \
11261135
\

drivers/spi/spi_ll_stm32.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#ifndef ZEPHYR_DRIVERS_SPI_SPI_LL_STM32_H_
88
#define ZEPHYR_DRIVERS_SPI_SPI_LL_STM32_H_
99

10+
#include <stm32_ll_spi.h>
11+
1012
#include "spi_context.h"
1113

1214
typedef void (*irq_config_func_t)(const struct device *port);

0 commit comments

Comments
 (0)