Skip to content

Commit fd064fb

Browse files
committed
driver: can: stm32fd: add stm32u5 clock selection
The STM32u% series of processors has a unique set of clock sources for the FDCAN peripheral. This brings the selection in line with the existing can_stm32fd clock selection Kconfigs. This change was tested on a proprietary board using the STM32U5 series which exposes the CAN pins of the SOC using a transciever on a live CAN bus as well as on the nucleo_g474re board from ST in loopback mode. HSE and PLL1Q tests run and all passed. PLL2P is not currently supported by the clock drivers for STM32U5, and as such is currently untested. When this support is added, the driver should be able to use this clock without issue. When changes from zephyrproject-rtos#42097 are merged this fix should be deprecated in favor of using the methods outlined there. Signed-off-by: Peter Maxwell Warasila <[email protected]>
1 parent d490358 commit fd064fb

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

drivers/can/Kconfig.stm32fd

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,28 @@ config CAN_STM32FD_CLOCK_SOURCE_HSE
4242

4343
config CAN_STM32FD_CLOCK_SOURCE_PLL
4444
bool "PLL"
45+
depends on !SOC_SERIES_STM32U5X
4546
help
4647
PLL "Q" clock used ad FDCAN clock source.
4748

4849
config CAN_STM32FD_CLOCK_SOURCE_PCLK1
4950
bool "PCLK1"
51+
depends on !SOC_SERIES_STM32U5X
5052
help
5153
PCLK1 clock used ad FDCAN clock source.
5254

55+
config CAN_STM32FD_CLOCK_SOURCE_PLL1Q
56+
bool "PLL1Q"
57+
depends on SOC_SERIES_STM32U5X
58+
help
59+
PLL1 "Q" clock used as FDCAN clock source.
60+
61+
config CAN_STM32FD_CLOCK_SOURCE_PLL2P
62+
bool "PLL2P"
63+
depends on SOC_SERIES_STM32U5X
64+
help
65+
PLL2 "P" clock used as FDCAN clock source.
66+
5367
endchoice
5468

5569
config CAN_STM32FD_CLOCK_DIVISOR

drivers/can/can_stm32fd.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <kernel.h>
1111
#include <soc.h>
1212
#include <stm32_ll_rcc.h>
13+
#include <stm32_ll_bus.h>
1314
#include <logging/log.h>
1415

1516
#include "can_stm32fd.h"
@@ -22,6 +23,10 @@ LOG_MODULE_REGISTER(can_stm32fd, CONFIG_CAN_LOG_LEVEL);
2223
#define CAN_STM32FD_CLOCK_SOURCE LL_RCC_FDCAN_CLKSOURCE_PLL
2324
#elif defined(CONFIG_CAN_STM32FD_CLOCK_SOURCE_PCLK1)
2425
#define CAN_STM32FD_CLOCK_SOURCE LL_RCC_FDCAN_CLKSOURCE_PCLK1
26+
#elif defined(CONFIG_CAN_STM32FD_CLOCK_SOURCE_PLL1Q)
27+
#define CAN_STM32FD_CLOCK_SOURCE LL_RCC_FDCAN_CLKSOURCE_PLL1
28+
#elif defined(CONFIG_CAN_STM32FD_CLOCK_SOURCE_PLL2P)
29+
#define CAN_STM32FD_CLOCK_SOURCE LL_RCC_FDCAN_CLKSOURCE_PLL2
2530
#else
2631
#error "Unsupported FDCAN clock source"
2732
#endif
@@ -56,7 +61,19 @@ static int can_stm32fd_get_core_clock(const struct device *dev, uint32_t *rate)
5661
static void can_stm32fd_clock_enable(void)
5762
{
5863
LL_RCC_SetFDCANClockSource(CAN_STM32FD_CLOCK_SOURCE);
64+
65+
/* LL_RCC API names do not align with PLL output name but are correct */
66+
#ifdef CONFIG_CAN_STM32FD_CLOCK_SOURCE_PLL1Q
67+
LL_RCC_PLL1_EnableDomain_48M();
68+
#elif CONFIG_CAN_STM32FD_CLOCK_SOURCE_PLL2P
69+
LL_RCC_PLL2_EnableDomain_SAI();
70+
#endif
71+
72+
#ifdef CONFIG_SOC_SERIES_STM32U5X
73+
LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_FDCAN1);
74+
#else
5975
__HAL_RCC_FDCAN_CLK_ENABLE();
76+
#endif
6077

6178
FDCAN_CONFIG->CKDIV = CAN_STM32FD_CLOCK_DIVISOR >> 1;
6279
}

0 commit comments

Comments
 (0)