Skip to content

Commit 03d3075

Browse files
youssefz24danieldegrasse
authored andcommitted
drivers: clock_control: add uart clock handling
Add clock bindings for UART/USART (1-9) peripherals in the `stm32mp2_clock.h`. Add UART/USART clocks rate reading to the STM32MP2 clock driver. Signed-off-by: Youssef Zini <youssef.zini@savoirfairelinux.com>
1 parent 98b4f4e commit 03d3075

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

drivers/clock_control/clock_stm32_ll_mp2.c

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,37 @@ static int stm32_clock_control_off(const struct device *dev, clock_control_subsy
4646
static int stm32_clock_control_get_subsys_rate(const struct device *dev,
4747
clock_control_subsys_t sub_system, uint32_t *rate)
4848
{
49+
struct stm32_pclken *pclken = (struct stm32_pclken *)(sub_system);
50+
4951
ARG_UNUSED(dev);
50-
ARG_UNUSED(sub_system);
51-
ARG_UNUSED(rate);
52-
return -ENOTSUP;
52+
53+
switch (pclken->bus) {
54+
case STM32_CLOCK_PERIPH_USART1:
55+
*rate = LL_RCC_GetUARTClockFreq(LL_RCC_USART1_CLKSOURCE);
56+
break;
57+
case STM32_CLOCK_PERIPH_USART2:
58+
case STM32_CLOCK_PERIPH_UART4:
59+
*rate = LL_RCC_GetUARTClockFreq(LL_RCC_UART24_CLKSOURCE);
60+
break;
61+
case STM32_CLOCK_PERIPH_USART3:
62+
case STM32_CLOCK_PERIPH_UART5:
63+
*rate = LL_RCC_GetUARTClockFreq(LL_RCC_USART35_CLKSOURCE);
64+
break;
65+
case STM32_CLOCK_PERIPH_USART6:
66+
*rate = LL_RCC_GetUARTClockFreq(LL_RCC_USART6_CLKSOURCE);
67+
break;
68+
case STM32_CLOCK_PERIPH_UART7:
69+
case STM32_CLOCK_PERIPH_UART8:
70+
*rate = LL_RCC_GetUARTClockFreq(LL_RCC_UART78_CLKSOURCE);
71+
break;
72+
case STM32_CLOCK_PERIPH_UART9:
73+
*rate = LL_RCC_GetUARTClockFreq(LL_RCC_UART9_CLKSOURCE);
74+
break;
75+
default:
76+
return -ENOTSUP;
77+
}
78+
79+
return 0;
5380
}
5481

5582
static DEVICE_API(clock_control, stm32_clock_control_api) = {

include/zephyr/dt-bindings/clock/stm32mp2_clock.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,18 @@
3939
#define STM32_CLOCK_PERIPH_GPIOK 0x554
4040
#define STM32_CLOCK_PERIPH_GPIOZ 0x558
4141

42+
/* USART/UART Peripheral */
43+
#define STM32_CLOCK_PERIPH_USART1 0x77C
44+
#define STM32_CLOCK_PERIPH_USART2 0x780
45+
#define STM32_CLOCK_PERIPH_USART3 0x784
46+
#define STM32_CLOCK_PERIPH_UART4 0x788
47+
#define STM32_CLOCK_PERIPH_UART5 0x78C
48+
#define STM32_CLOCK_PERIPH_USART6 0x790
49+
#define STM32_CLOCK_PERIPH_UART7 0x794
50+
#define STM32_CLOCK_PERIPH_UART8 0x798
51+
#define STM32_CLOCK_PERIPH_UART9 0x79C
52+
4253
#define STM32_CLOCK_PERIPH_MIN STM32_CLOCK_PERIPH_GPIOA
43-
#define STM32_CLOCK_PERIPH_MAX STM32_CLOCK_PERIPH_GPIOZ
54+
#define STM32_CLOCK_PERIPH_MAX STM32_CLOCK_PERIPH_UART9
4455

4556
#endif /* ZEPHYR_INCLUDE_DT_BINDINGS_CLOCK_STM32MP2_CLOCK_H_ */

0 commit comments

Comments
 (0)