Skip to content

Commit 438ed89

Browse files
joerchancarlescufi
authored andcommitted
samples: stm32: mco: Update sample to use dts instead of Kconfig
Update MCO board sample to use devicetree information instead of Kconfig configurations. Signed-off-by: Joakim Andersson <[email protected]>
1 parent a624fe0 commit 438ed89

File tree

4 files changed

+34
-17
lines changed

4 files changed

+34
-17
lines changed

samples/boards/st/mco/README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Requirements
1414
************
1515

1616
The SoC should support MCO functionality and use a pin that has the MCO alternate function.
17-
To support another board, add an overlay in boards folder.
17+
To support another board, add a dts overlay file in boards folder.
1818
Make sure that the output clock is enabled in dts overlay file.
1919

2020

samples/boards/st/mco/boards/nucleo_u5a5zj_q.overlay

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,20 @@
33
status = "okay";
44
};
55

6-
/ {
7-
zephyr,user {
8-
/* Select MCO pin to use. */
9-
pinctrl-0 = <&rcc_mco_pa8>;
10-
pinctrl-names = "default";
11-
};
6+
/* See reference manual (RM0456):
7+
* 0b0111: LSE clock selected
8+
*/
9+
#define MCO1_SEL_LSE 7
10+
11+
/* See reference manual (RM0456):
12+
* 0b001: MCO divided by 2
13+
*/
14+
#define MCO1_PRE_DIV_2 1
15+
16+
&mco1 {
17+
status = "okay";
18+
clocks = <&rcc STM32_SRC_LSE MCO1_SEL(MCO1_SEL_LSE)>;
19+
prescaler = <MCO1_PRE(MCO1_PRE_DIV_2)>;
20+
pinctrl-0 = <&rcc_mco_pa8>;
21+
pinctrl-names = "default";
1222
};

samples/boards/st/mco/prj.conf

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
# Set MCO1 source to desired clock.
2-
CONFIG_CLOCK_STM32_MCO1_SRC_LSE=y
3-
CONFIG_CLOCK_STM32_MCO1_DIV=1
1+
# Empty

samples/boards/st/mco/src/main.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,24 @@
77
#include <zephyr/kernel.h>
88
#include <zephyr/drivers/pinctrl.h>
99

10-
/* Define the pinctrl information for the MCO pin. */
11-
PINCTRL_DT_DEFINE(DT_PATH(zephyr_user));
12-
1310
int main(void)
1411
{
15-
/* Configure the MCO pin using pinctrl in order to set the alternate function of the pin. */
16-
const struct pinctrl_dev_config *pcfg = PINCTRL_DT_DEV_CONFIG_GET(DT_PATH(zephyr_user));
17-
(void)pinctrl_apply_state(pcfg, PINCTRL_STATE_DEFAULT);
12+
const struct device *dev;
13+
14+
/* This sample demonstrates MCO usage via Device Tree.
15+
* MCO configuration is performed in the Device Tree overlay files.
16+
* Each MCO will be enabled automatically by the driver during device
17+
* initialization. This sample checks that all MCOs are ready - if so,
18+
* the selected clock should be visible on the chosen GPIO pin.
19+
*/
20+
dev = DEVICE_DT_GET(DT_NODELABEL(mco1));
21+
if (device_is_ready(dev)) {
22+
printk("MCO1 device successfully configured\n");
23+
} else {
24+
printk("MCO1 device not ready\n");
25+
return -1;
26+
}
1827

19-
printk("\nMCO pin configured, end of example.\n");
28+
printk("\nDisplayed the status of all MCO devices - end of example.\n");
2029
return 0;
2130
}

0 commit comments

Comments
 (0)