From c8fe95e63b01047678b36b009d91c69b8de12a2b Mon Sep 17 00:00:00 2001 From: hangpersonal Date: Thu, 8 Oct 2026 00:09:26 -0700 Subject: [PATCH] Add my_led --- apps/my_led/CMakeLists.txt | 10 +++++++ apps/my_led/boards/black_f407ve.overlay | 21 ++++++++++++++ apps/my_led/dts/bindings/custom-led.yaml | 14 ++++++++++ apps/my_led/prj.conf | 6 ++++ apps/my_led/src/main.c | 35 ++++++++++++++++++++++++ 5 files changed, 86 insertions(+) create mode 100644 apps/my_led/CMakeLists.txt create mode 100644 apps/my_led/boards/black_f407ve.overlay create mode 100644 apps/my_led/dts/bindings/custom-led.yaml create mode 100644 apps/my_led/prj.conf create mode 100644 apps/my_led/src/main.c diff --git a/apps/my_led/CMakeLists.txt b/apps/my_led/CMakeLists.txt new file mode 100644 index 0000000..f3846da --- /dev/null +++ b/apps/my_led/CMakeLists.txt @@ -0,0 +1,10 @@ +cmake_minimum_required(VERSION 3.20.0) + +# Locate the Zephyr build system as a CMake package +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) + +# Project name +project(my_led) + +# Add source files belong to this application +target_sources(app PRIVATE src/main.c) \ No newline at end of file diff --git a/apps/my_led/boards/black_f407ve.overlay b/apps/my_led/boards/black_f407ve.overlay new file mode 100644 index 0000000..2140ea5 --- /dev/null +++ b/apps/my_led/boards/black_f407ve.overlay @@ -0,0 +1,21 @@ +/ { + custom_led0: custom_led0 { + compatible = "custom-led"; + custom-gpios = <&gpioe 13 GPIO_ACTIVE_HIGH>; + my-delay-ms = <1000>; /* Optional, equals 500 by default */ + }; + aliases { + myled = &custom_led0; + }; +}; + +&clk_hse { + clock-frequency = ; +}; + +&pll { + div-m = <25>; + mul-n = <336>; + div-p = <2>; + div-q = <7>; +}; diff --git a/apps/my_led/dts/bindings/custom-led.yaml b/apps/my_led/dts/bindings/custom-led.yaml new file mode 100644 index 0000000..0322b94 --- /dev/null +++ b/apps/my_led/dts/bindings/custom-led.yaml @@ -0,0 +1,14 @@ +compatible: custom-led + +description: Example custom node describing a single LED GPIO and a blink delay. + +properties: + custom-gpios: + type: phandle-array + required: true + description: My LED GPIO. + my-delay-ms: + type: int + required: false + default: 500 + description: Blink delay in milliseconds. diff --git a/apps/my_led/prj.conf b/apps/my_led/prj.conf new file mode 100644 index 0000000..cb21cb7 --- /dev/null +++ b/apps/my_led/prj.conf @@ -0,0 +1,6 @@ +CONFIG_GPIO=y +CONFIG_SERIAL=y +CONFIG_ADC=y +CONFIG_UART_INTERRUPT_DRIVEN=y +CONFIG_CONSOLE=y +CONFIG_PRINTK=y \ No newline at end of file diff --git a/apps/my_led/src/main.c b/apps/my_led/src/main.c new file mode 100644 index 0000000..9801852 --- /dev/null +++ b/apps/my_led/src/main.c @@ -0,0 +1,35 @@ +#include +#include + +#define LED_NODE DT_ALIAS(myled) + +#define BLINK_DELAY_MS DT_PROP(LED_NODE, my_delay_ms) + +const struct gpio_dt_spec led = + GPIO_DT_SPEC_GET(LED_NODE, custom_gpios); + +int main(void) { + + int ret; + + if (!device_is_ready(led.port)) { + printk("LED GPIO device not ready\n"); + return 0; + } + + ret = gpio_pin_configure_dt(&led, GPIO_OUTPUT_INACTIVE); + if (ret != 0) { + printk("Failed to configure LED: %d\n", ret); + return 0; + } + + printk("Blinking with delay %d ms\n", BLINK_DELAY_MS); + + while (1) { + gpio_pin_toggle_dt(&led); + k_sleep(K_MSEC(BLINK_DELAY_MS)); + } + + return 0; + +} \ No newline at end of file