Skip to content

Commit 41c6257

Browse files
schuamkartben
authored andcommitted
include: dt-bindings: stm32g0_clock: add mco macros
Adds macros to be able to use the microcontroller clock output (MCO) on the STM32G0 microcontroller. Signed-off-by: Andreas Schuster <[email protected]>
1 parent 8e765b7 commit 41c6257

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed

dts/arm/st/g0/stm32g0b1.dtsi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77

88
#include <st/g0/stm32g071.dtsi>
9+
#include <zephyr/dt-bindings/clock/stm32g0_b1x_c1x_clock.h>
910

1011
/ {
1112

dts/arm/st/g0/stm32g0c1.dtsi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <st/g0/stm32g0b1.dtsi>
88
#include <st/g0/stm32g0_crypt.dtsi>
9+
#include <zephyr/dt-bindings/clock/stm32g0_b1x_c1x_clock.h>
910

1011
/ {
1112
soc {
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright (c) 2025 Andreas Schuster <[email protected]>
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef ZEPHYR_INCLUDE_DT_BINDINGS_CLOCK_STM32G0_B1X_C1X_CLOCK_H_
8+
#define ZEPHYR_INCLUDE_DT_BINDINGS_CLOCK_STM32G0_B1X_C1X_CLOCK_H_
9+
10+
/* MCO prescaler : division factor */
11+
#define MCO_PRE_DIV_256 8
12+
#define MCO_PRE_DIV_512 9
13+
#define MCO_PRE_DIV_1024 10
14+
15+
/* MCO clock output */
16+
#define MCO_SEL_HSI48 2
17+
#define MCO_SEL_PLLPCLK 8
18+
#define MCO_SEL_PLLQCLK 9
19+
#define MCO_SEL_RTCCLK 10
20+
#define MCO_SEL_RTCWAKEUP 11
21+
22+
#endif /* ZEPHYR_INCLUDE_DT_BINDINGS_CLOCK_STM32G0_B1X_C1X_CLOCK_H_ */

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
#define STM32_SRC_PLL_Q (STM32_SRC_PLL_P + 1)
3636
#define STM32_SRC_PLL_R (STM32_SRC_PLL_Q + 1)
3737

38+
/** @brief RCC_CFGR register offset */
39+
#define CFGR_REG 0x08
40+
3841
/** @brief RCC_CCIPR register offset */
3942
#define CCIPR_REG 0x54
4043
#define CCIPR2_REG 0x58
@@ -43,6 +46,11 @@
4346
#define BDCR_REG 0x5C
4447

4548
/** @brief Device domain clocks selection helpers */
49+
/** CFGR devices */
50+
#define MCO1_SEL(val) STM32_DT_CLOCK_SELECT((val), 15, 24, CFGR_REG)
51+
#define MCO1_PRE(val) STM32_DT_CLOCK_SELECT((val), 15, 28, CFGR_REG)
52+
#define MCO2_SEL(val) STM32_DT_CLOCK_SELECT((val), 15, 16, CFGR_REG)
53+
#define MCO2_PRE(val) STM32_DT_CLOCK_SELECT((val), 15, 20, CFGR_REG)
4654
/** CCIPR devices */
4755
#define USART1_SEL(val) STM32_DT_CLOCK_SELECT((val), 3, 0, CCIPR_REG)
4856
#define USART2_SEL(val) STM32_DT_CLOCK_SELECT((val), 3, 2, CCIPR_REG)
@@ -66,4 +74,22 @@
6674
/** BDCR devices */
6775
#define RTC_SEL(val) STM32_DT_CLOCK_SELECT((val), 3, 8, BDCR_REG)
6876

77+
/* MCO prescaler : division factor */
78+
#define MCO_PRE_DIV_1 0
79+
#define MCO_PRE_DIV_2 1
80+
#define MCO_PRE_DIV_4 2
81+
#define MCO_PRE_DIV_8 3
82+
#define MCO_PRE_DIV_16 4
83+
#define MCO_PRE_DIV_32 5
84+
#define MCO_PRE_DIV_64 6
85+
#define MCO_PRE_DIV_128 7
86+
87+
/* MCO clock output */
88+
#define MCO_SEL_SYSCLK 1
89+
#define MCO_SEL_HSI16 3
90+
#define MCO_SEL_HSE 4
91+
#define MCO_SEL_PLLRCLK 5
92+
#define MCO_SEL_LSI 6
93+
#define MCO_SEL_LSE 7
94+
6995
#endif /* ZEPHYR_INCLUDE_DT_BINDINGS_CLOCK_STM32G0_CLOCK_H_ */

0 commit comments

Comments
 (0)