From 3603ce3d0cd049c296e6c9d44e0f1bd3d81bf195 Mon Sep 17 00:00:00 2001 From: Francois Ramu Date: Fri, 15 Nov 2024 15:48:39 +0100 Subject: [PATCH] samples: boards: stm32 mco output control This samples enables and configure the MCO1/2 output for stm32 target boards. Signed-off-by: Francois Ramu --- samples/boards/st/mco/README.rst | 5 +++++ .../boards/st/mco/boards/nucleo_f411re.overlay | 18 ++++++++++++++++++ .../st/mco/boards/nucleo_u5a5zj_q.overlay | 2 +- .../st/mco/boards/stm32f746g_disco.overlay | 2 +- samples/boards/st/mco/src/main.c | 4 +++- 5 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 samples/boards/st/mco/boards/nucleo_f411re.overlay diff --git a/samples/boards/st/mco/README.rst b/samples/boards/st/mco/README.rst index cb3c1d9e927194..6de29c058e7480 100644 --- a/samples/boards/st/mco/README.rst +++ b/samples/boards/st/mco/README.rst @@ -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 diff --git a/samples/boards/st/mco/boards/nucleo_f411re.overlay b/samples/boards/st/mco/boards/nucleo_f411re.overlay new file mode 100644 index 00000000000000..4988be13fe2a11 --- /dev/null +++ b/samples/boards/st/mco/boards/nucleo_f411re.overlay @@ -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"; +}; diff --git a/samples/boards/st/mco/boards/nucleo_u5a5zj_q.overlay b/samples/boards/st/mco/boards/nucleo_u5a5zj_q.overlay index acff74efdc3b9d..5bbfa92b3b730b 100644 --- a/samples/boards/st/mco/boards/nucleo_u5a5zj_q.overlay +++ b/samples/boards/st/mco/boards/nucleo_u5a5zj_q.overlay @@ -16,7 +16,7 @@ &mco1 { status = "okay"; clocks = <&rcc STM32_SRC_LSE MCO1_SEL(MCO1_SEL_LSE)>; - prescaler = ; + prescaler = ; pinctrl-0 = <&rcc_mco_pa8>; pinctrl-names = "default"; }; diff --git a/samples/boards/st/mco/boards/stm32f746g_disco.overlay b/samples/boards/st/mco/boards/stm32f746g_disco.overlay index a69e0d147b5e48..e15dca090aff66 100644 --- a/samples/boards/st/mco/boards/stm32f746g_disco.overlay +++ b/samples/boards/st/mco/boards/stm32f746g_disco.overlay @@ -38,7 +38,7 @@ &mco2 { status = "okay"; clocks = <&rcc STM32_SRC_HSE MCO2_SEL(MCO2_SEL_HSE)>; - prescaler = ; + prescaler = ; pinctrl-0 = <&rcc_mco_2_pc9>; /* uSD_D1 (CN3 pin 8) */ pinctrl-names = "default"; }; diff --git a/samples/boards/st/mco/src/main.c b/samples/boards/st/mco/src/main.c index 7e79d1e8cd8dcc..e51130d8a23192 100644 --- a/samples/boards/st/mco/src/main.c +++ b/samples/boards/st/mco/src/main.c @@ -17,6 +17,7 @@ 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"); @@ -24,6 +25,7 @@ int main(void) 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)); @@ -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;