Skip to content

Commit 9bcc89d

Browse files
kbidanikartben
authored andcommitted
drivers : can: replace LL_RCC_GetFDCANClockFreq
replace LL_RCC_GetFDCANClockFreq, remove stm32_ll_rcc.h include and use_stm32_ll_rcc from kconfig. Signed-off-by: Khaoula Bidani <khaoula.bidani-ext@st.com>
1 parent a3474b7 commit 9bcc89d

File tree

3 files changed

+43
-13
lines changed

3 files changed

+43
-13
lines changed

drivers/can/Kconfig.stm32

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ config CAN_STM32_FDCAN
5454
depends on DT_HAS_ST_STM32_FDCAN_ENABLED
5555
select CAN_MCAN
5656
select PINCTRL
57-
select USE_STM32_LL_RCC
5857

5958
if CAN_STM32_FDCAN
6059

@@ -82,4 +81,3 @@ config CAN_STM32H7_FDCAN
8281
depends on DT_HAS_ST_STM32H7_FDCAN_ENABLED
8382
select CAN_MCAN
8483
select PINCTRL
85-
select USE_STM32_LL_RCC

drivers/can/can_stm32_fdcan.c

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include <zephyr/kernel.h>
1414
#include <zephyr/sys/__assert.h>
1515
#include <soc.h>
16-
#include <stm32_ll_rcc.h>
1716
#include <zephyr/logging/log.h>
1817
#include <zephyr/irq.h>
1918

@@ -403,13 +402,30 @@ static int can_stm32fd_clear_mram(const struct device *dev, uint16_t offset, siz
403402

404403
static int can_stm32fd_get_core_clock(const struct device *dev, uint32_t *rate)
405404
{
406-
const uint32_t rate_tmp = LL_RCC_GetFDCANClockFreq(LL_RCC_FDCAN_CLKSOURCE);
405+
uint32_t rate_tmp;
406+
const struct can_mcan_config *mcan_cfg = dev->config;
407+
const struct can_stm32fd_config *stm32fd_cfg = mcan_cfg->custom;
408+
const struct device *const clk = DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE);
407409

408410
ARG_UNUSED(dev);
411+
if (!device_is_ready(clk)) {
412+
return -ENODEV;
413+
}
409414

410-
if (rate_tmp == LL_RCC_PERIPH_FREQUENCY_NO) {
411-
LOG_ERR("Can't read core clock");
412-
return -EIO;
415+
if (IS_ENABLED(STM32_CANFD_DOMAIN_CLOCK_SUPPORT) && (stm32fd_cfg->pclk_len > 1)) {
416+
if (clock_control_get_rate(clk,
417+
(clock_control_subsys_t) &stm32fd_cfg->pclken[1],
418+
&rate_tmp) < 0) {
419+
LOG_ERR("Failed call clock_control_get_rate(pclk[1])");
420+
return -EIO;
421+
}
422+
} else {
423+
if (clock_control_get_rate(clk,
424+
(clock_control_subsys_t) &stm32fd_cfg->pclken[0],
425+
&rate_tmp) < 0) {
426+
LOG_ERR("Failed call clock_control_get_rate(pclk[0])");
427+
return -EIO;
428+
}
413429
}
414430

415431
if (FDCAN_CONFIG->CKDIV == 0) {

drivers/can/can_stm32h7_fdcan.c

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include <zephyr/drivers/clock_control.h>
1212
#include <zephyr/drivers/pinctrl.h>
1313
#include <zephyr/kernel.h>
14-
#include <stm32_ll_rcc.h>
1514
#include <zephyr/logging/log.h>
1615
#include <zephyr/irq.h>
1716
#include <zephyr/sys/util.h>
@@ -84,16 +83,33 @@ static int can_stm32h7_clear_mram(const struct device *dev, uint16_t offset, siz
8483

8584
static int can_stm32h7_get_core_clock(const struct device *dev, uint32_t *rate)
8685
{
87-
const uint32_t rate_tmp = LL_RCC_GetFDCANClockFreq(LL_RCC_FDCAN_CLKSOURCE);
86+
uint32_t rate_tmp;
87+
const struct can_mcan_config *mcan_cfg = dev->config;
88+
const struct can_stm32h7_config *stm32h7_cfg = mcan_cfg->custom;
89+
const struct device *const clk = DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE);
8890
uint32_t cdiv;
8991

9092
ARG_UNUSED(dev);
91-
92-
if (rate_tmp == LL_RCC_PERIPH_FREQUENCY_NO) {
93-
LOG_ERR("Can't read core clock");
94-
return -EIO;
93+
if (!device_is_ready(clk)) {
94+
LOG_ERR("clock control device not ready");
95+
return -ENODEV;
9596
}
9697

98+
if (IS_ENABLED(STM32H7_FDCAN_DOMAIN_CLOCK_SUPPORT) && (stm32h7_cfg->pclk_len > 1)) {
99+
if (clock_control_get_rate(clk,
100+
(clock_control_subsys_t) &stm32h7_cfg->pclken[1],
101+
&rate_tmp) < 0) {
102+
LOG_ERR("Failed call clock_control_get_rate(pclk[1])");
103+
return -EIO;
104+
}
105+
} else {
106+
if (clock_control_get_rate(clk,
107+
(clock_control_subsys_t) &stm32h7_cfg->pclken[0],
108+
&rate_tmp) < 0) {
109+
LOG_ERR("Failed call clock_control_get_rate(pclk[0])");
110+
return -EIO;
111+
}
112+
}
97113
cdiv = FIELD_GET(FDCANCCU_CCFG_CDIV, FDCAN_CCU->CCFG);
98114
if (cdiv == 0U) {
99115
*rate = rate_tmp;

0 commit comments

Comments
 (0)