File tree Expand file tree Collapse file tree 7 files changed +86
-24
lines changed Expand file tree Collapse file tree 7 files changed +86
-24
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,13 @@ Requirements
16
16
The SoC should support MCO functionality and use a pin that has the MCO alternate function.
17
17
To support another board, add a dts overlay file in boards folder.
18
18
Make sure that the output clock is enabled in dts overlay file.
19
+ Depending on the stm32 serie, several clock source and prescaler are possible for each MCOx.
20
+ The clock source is set by the DTS among the possible values for each stm32 serie.
21
+ The prescaler is set by the DTS, through the property ``prescaler = <MCOx_PRE(MCO_PRE_DIV_n)>; ``
22
+
23
+ See :zephyr_file: `dts/bindings/clock/st,stm32-clock-mco.yaml `
24
+
25
+ It is required to check the Reference Manual to configure the DTS correctly.
19
26
20
27
21
28
Building and Running
Original file line number Diff line number Diff line change
1
+ /* Enable the PLLI2s and set it as clock source for the MCO2 (with prescaler 5) */
2
+
3
+ &plli2s {
4
+ div-m = <8>;
5
+ mul-n = <100>;
6
+ div-r = <2>;
7
+ clocks = <&clk_hse>;
8
+ status = "okay";
9
+ };
10
+
11
+ /* see RefMan RM0383 */
12
+ &mco1 {
13
+ /* Select One of the line below for clock source */
14
+ clocks = <&rcc STM32_SRC_HSI MCO1_SEL(0)>;
15
+ /* clocks = <&rcc STM32_SRC_LSE MCO1_SEL(1)>; */
16
+ /* clocks = <&rcc STM32_SRC_HSE MCO1_SEL(2)>; */
17
+ /* clocks = <&rcc STM32_SRC_PLL_P MCO1_SEL(3)>; */
18
+ prescaler = <MCO1_PRE(MCO_PRE_DIV_2)>;
19
+ pinctrl-0 = <&rcc_mco_1_pa8>;
20
+ pinctrl-names = "default";
21
+ status = "okay";
22
+ };
23
+
24
+ &mco2 {
25
+ clocks = <&rcc STM32_SRC_PLLI2S_R MCO2_SEL(1)>;
26
+ prescaler = <MCO2_PRE(MCO_PRE_DIV_5)>;
27
+ pinctrl-0 = <&rcc_mco_2_pc9>;
28
+ pinctrl-names = "default";
29
+ status = "okay";
30
+ };
Original file line number Diff line number Diff line change
1
+ /* Enable the PLLI2s and set it as clock source for the MCO2 (with prescaler 2) : 25MHz */
2
+
3
+ &plli2s {
4
+ div-m = <8>;
5
+ mul-n = <100>;
6
+ div-r = <2>;
7
+ clocks = <&clk_hse>;
8
+ status = "okay";
9
+ };
10
+
11
+ /* see RefMan RM0390 */
12
+ &mco1 {
13
+ /* Select One of the line below for clock source */
14
+ /* clocks = <&rcc STM32_SRC_HSI MCO1_SEL(0)>; */
15
+ /* clocks = <&rcc STM32_SRC_LSE MCO1_SEL(1)>; */
16
+ clocks = <&rcc STM32_SRC_HSE MCO1_SEL(2)>;
17
+ /* clocks = <&rcc STM32_SRC_PLL_P MCO1_SEL(3)>;*/
18
+ prescaler = <MCO1_PRE(MCO_PRE_DIV_1)>;
19
+ pinctrl-0 = <&rcc_mco_1_pa8>;
20
+ pinctrl-names = "default";
21
+ status = "okay";
22
+ };
23
+
24
+ &mco2 {
25
+ clocks = <&rcc STM32_SRC_PLLI2S_R MCO2_SEL(1)>;
26
+ prescaler = <MCO2_PRE(MCO_PRE_DIV_2)>;
27
+ pinctrl-0 = <&rcc_mco_2_pc9>;
28
+ pinctrl-names = "default";
29
+ status = "okay";
30
+ };
Original file line number Diff line number Diff line change 8
8
*/
9
9
#define MCO1_SEL_LSE 7
10
10
11
- /* See reference manual (RM0456):
12
- * 0b001: MCO divided by 2
13
- */
14
- #define MCO1_PRE_DIV_2 1
15
-
16
11
&mco1 {
17
12
status = "okay";
18
13
clocks = <&rcc STM32_SRC_LSE MCO1_SEL(MCO1_SEL_LSE)>;
19
- prescaler = <MCO1_PRE(MCO1_PRE_DIV_2 )>;
14
+ prescaler = <MCO1_PRE(MCO_PRE_DIV_2 )>;
20
15
pinctrl-0 = <&rcc_mco_pa8>;
21
16
pinctrl-names = "default";
22
17
};
Original file line number Diff line number Diff line change 12
12
*/
13
13
#define MCO1_SEL_LSE 1
14
14
15
- /* See reference manual (RM0385):
16
- * 0b100: division by 2
17
- */
18
- #define MCO1_PRE_DIV_2 4
19
-
20
15
&mco1 {
21
16
status = "okay";
22
17
clocks = <&rcc STM32_SRC_LSE MCO1_SEL(MCO1_SEL_LSE)>;
23
- prescaler = <MCO1_PRE(MCO1_PRE_DIV_2 )>;
18
+ prescaler = <MCO1_PRE(MCO_PRE_DIV_2 )>;
24
19
pinctrl-0 = <&rcc_mco_1_pa8>; /* D10 (CN7) */
25
20
pinctrl-names = "default";
26
21
};
30
25
*/
31
26
#define MCO2_SEL_HSE 2
32
27
33
- /* See reference manual (RM0385):
34
- * 0b111: division by 5
35
- */
36
- #define MCO2_PRE_DIV_5 7
37
-
38
28
&mco2 {
39
29
status = "okay";
40
30
clocks = <&rcc STM32_SRC_HSE MCO2_SEL(MCO2_SEL_HSE)>;
41
- prescaler = <MCO2_PRE(MCO2_PRE_DIV_5 )>;
31
+ prescaler = <MCO2_PRE(MCO_PRE_DIV_5 )>;
42
32
pinctrl-0 = <&rcc_mco_2_pc9>; /* uSD_D1 (CN3 pin 8) */
43
33
pinctrl-names = "default";
44
34
};
Original file line number Diff line number Diff line change 3
3
tests :
4
4
sample.board.stm32.mco :
5
5
platform_allow :
6
+ - nucleo_f411re
7
+ - nucleo_f446ze
8
+ - stm32f746g_disco
6
9
- nucleo_u5a5zj_q
10
+ integration_platforms :
7
11
- stm32f746g_disco
8
12
tags : board
Original file line number Diff line number Diff line change 9
9
10
10
int main (void )
11
11
{
12
- const struct device * dev ;
13
12
14
13
/* This sample demonstrates MCO usage via Device Tree.
15
14
* MCO configuration is performed in the Device Tree overlay files.
16
15
* Each MCO will be enabled automatically by the driver during device
17
16
* initialization. This sample checks that all MCOs are ready - if so,
18
17
* the selected clock should be visible on the chosen GPIO pin.
19
18
*/
20
- dev = DEVICE_DT_GET (DT_NODELABEL (mco1 ));
21
- if (device_is_ready (dev )) {
19
+
20
+ #if DT_NODE_HAS_STATUS_OKAY (DT_NODELABEL (mco1 ))
21
+ const struct device * dev1 ;
22
+
23
+ dev1 = DEVICE_DT_GET (DT_NODELABEL (mco1 ));
24
+ if (device_is_ready (dev1 )) {
22
25
printk ("MCO1 device successfully configured\n" );
23
26
} else {
24
27
printk ("MCO1 device not ready\n" );
25
28
return -1 ;
26
29
}
30
+ #endif /* mco1 */
27
31
28
32
#if DT_NODE_HAS_STATUS_OKAY (DT_NODELABEL (mco2 ))
29
- dev = DEVICE_DT_GET (DT_NODELABEL (mco2 ));
30
- if (device_is_ready (dev )) {
33
+ const struct device * dev2 ;
34
+
35
+ dev2 = DEVICE_DT_GET (DT_NODELABEL (mco2 ));
36
+ if (device_is_ready (dev2 )) {
31
37
printk ("MCO2 device successfully configured\n" );
32
38
} else {
33
39
printk ("MCO2 device not ready\n" );
34
40
return -1 ;
35
41
}
36
- #endif
42
+ #endif /* mco2 */
37
43
38
44
printk ("\nDisplayed the status of all MCO devices - end of example.\n" );
39
45
return 0 ;
You can’t perform that action at this time.
0 commit comments