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 <joerchan@gmail.com>
This commit is contained in:
parent
a624fe0f3d
commit
438ed89238
4 changed files with 34 additions and 17 deletions
|
|
@ -14,7 +14,7 @@ Requirements
|
|||
************
|
||||
|
||||
The SoC should support MCO functionality and use a pin that has the MCO alternate function.
|
||||
To support another board, add an overlay in boards folder.
|
||||
To support another board, add a dts overlay file in boards folder.
|
||||
Make sure that the output clock is enabled in dts overlay file.
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,10 +3,20 @@
|
|||
status = "okay";
|
||||
};
|
||||
|
||||
/ {
|
||||
zephyr,user {
|
||||
/* Select MCO pin to use. */
|
||||
pinctrl-0 = <&rcc_mco_pa8>;
|
||||
pinctrl-names = "default";
|
||||
};
|
||||
/* See reference manual (RM0456):
|
||||
* 0b0111: LSE clock selected
|
||||
*/
|
||||
#define MCO1_SEL_LSE 7
|
||||
|
||||
/* See reference manual (RM0456):
|
||||
* 0b001: MCO divided by 2
|
||||
*/
|
||||
#define MCO1_PRE_DIV_2 1
|
||||
|
||||
&mco1 {
|
||||
status = "okay";
|
||||
clocks = <&rcc STM32_SRC_LSE MCO1_SEL(MCO1_SEL_LSE)>;
|
||||
prescaler = <MCO1_PRE(MCO1_PRE_DIV_2)>;
|
||||
pinctrl-0 = <&rcc_mco_pa8>;
|
||||
pinctrl-names = "default";
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,3 +1 @@
|
|||
# Set MCO1 source to desired clock.
|
||||
CONFIG_CLOCK_STM32_MCO1_SRC_LSE=y
|
||||
CONFIG_CLOCK_STM32_MCO1_DIV=1
|
||||
# Empty
|
||||
|
|
|
|||
|
|
@ -7,15 +7,24 @@
|
|||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/drivers/pinctrl.h>
|
||||
|
||||
/* Define the pinctrl information for the MCO pin. */
|
||||
PINCTRL_DT_DEFINE(DT_PATH(zephyr_user));
|
||||
|
||||
int main(void)
|
||||
{
|
||||
/* Configure the MCO pin using pinctrl in order to set the alternate function of the pin. */
|
||||
const struct pinctrl_dev_config *pcfg = PINCTRL_DT_DEV_CONFIG_GET(DT_PATH(zephyr_user));
|
||||
(void)pinctrl_apply_state(pcfg, PINCTRL_STATE_DEFAULT);
|
||||
const struct device *dev;
|
||||
|
||||
printk("\nMCO pin configured, end of example.\n");
|
||||
/* This sample demonstrates MCO usage via Device Tree.
|
||||
* MCO configuration is performed in the Device Tree overlay files.
|
||||
* Each MCO will be enabled automatically by the driver during device
|
||||
* initialization. This sample checks that all MCOs are ready - if so,
|
||||
* the selected clock should be visible on the chosen GPIO pin.
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
printk("\nDisplayed the status of all MCO devices - end of example.\n");
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue