Skip to content

Commit

Permalink
samples: boards: stm32 mco output control
Browse files Browse the repository at this point in the history
This samples enables and configure the MCO1/2 output
for stm32 target boards.

Signed-off-by: Francois Ramu <[email protected]>
  • Loading branch information
FRASTM committed Nov 15, 2024
1 parent 9c90a1a commit 3603ce3
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 3 deletions.
5 changes: 5 additions & 0 deletions samples/boards/st/mco/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ Requirements
The SoC should support MCO functionality and use a pin that has the MCO alternate function.
To support another board, add a dts overlay file in boards folder.
Make sure that the output clock is enabled in dts overlay file.
Depending on the stm32 serie, several clock source are possible for each MCOx and prescaler.
The clock source is set by the DTS and converted in LL_RCC_MCO2SOURCE_xxx which is the parameter
for the LL_RCC_ConfigMCO function.
If prescaler is set by the DTS, the property prescaler = <5>; will be converted in LL_RCC_MCO2_DIV_5
which is the parameter for the LL_RCC_ConfigMCO function.


Building and Running
Expand Down
18 changes: 18 additions & 0 deletions samples/boards/st/mco/boards/nucleo_f411re.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* Enable the PLLI2s and set it as clock source for the MCO2 (with prescaler 5) */

&plli2s {
div-m = <8>;
mul-n = <100>;
div-r = <2>;
clocks = <&clk_hse>;
status = "okay";
};

/* see RefMan RM0383 */
&mco2 {
clocks = <&rcc STM32_SRC_PLLI2S_R MCO2_SEL(1)>;
prescaler = <5>; /* set 0b111 in the MCO2PRE of the RCC CFGR */
pinctrl-0 = <&rcc_mco_2_pc9>;
pinctrl-names = "default";
status = "okay";
};
2 changes: 1 addition & 1 deletion samples/boards/st/mco/boards/nucleo_u5a5zj_q.overlay
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
&mco1 {
status = "okay";
clocks = <&rcc STM32_SRC_LSE MCO1_SEL(MCO1_SEL_LSE)>;
prescaler = <MCO1_PRE(MCO1_PRE_DIV_2)>;
prescaler = <MCO1_PRE_DIV_2>;
pinctrl-0 = <&rcc_mco_pa8>;
pinctrl-names = "default";
};
2 changes: 1 addition & 1 deletion samples/boards/st/mco/boards/stm32f746g_disco.overlay
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
&mco2 {
status = "okay";
clocks = <&rcc STM32_SRC_HSE MCO2_SEL(MCO2_SEL_HSE)>;
prescaler = <MCO2_PRE(MCO2_PRE_DIV_5)>;
prescaler = <MCO2_PRE_DIV_5>;
pinctrl-0 = <&rcc_mco_2_pc9>; /* uSD_D1 (CN3 pin 8) */
pinctrl-names = "default";
};
4 changes: 3 additions & 1 deletion samples/boards/st/mco/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ int main(void)
* initialization. This sample checks that all MCOs are ready - if so,
* the selected clock should be visible on the chosen GPIO pin.
*/
#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(mco1))
dev = DEVICE_DT_GET(DT_NODELABEL(mco1));
if (device_is_ready(dev)) {
printk("MCO1 device successfully configured\n");
} else {
printk("MCO1 device not ready\n");
return -1;
}
#endif /* mco1 */

#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(mco2))
dev = DEVICE_DT_GET(DT_NODELABEL(mco2));
Expand All @@ -33,7 +35,7 @@ int main(void)
printk("MCO2 device not ready\n");
return -1;
}
#endif
#endif /* mco2 */

printk("\nDisplayed the status of all MCO devices - end of example.\n");
return 0;
Expand Down

0 comments on commit 3603ce3

Please sign in to comment.