File tree Expand file tree Collapse file tree 4 files changed +34
-17
lines changed Expand file tree Collapse file tree 4 files changed +34
-17
lines changed Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ Requirements
1414************
1515
1616The 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.
1818Make sure that the output clock is enabled in dts overlay file.
1919
2020
Original file line number Diff line number Diff line change 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};
Original file line number Diff line number Diff line change 1- # Set MCO1 source to desired clock.
2- CONFIG_CLOCK_STM32_MCO1_SRC_LSE=y
3- CONFIG_CLOCK_STM32_MCO1_DIV=1
1+ # Empty
Original file line number Diff line number Diff line change 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-
1310int 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}
You can’t perform that action at this time.
0 commit comments