From 93d9c1b0f101d786856af1ccc595bd702620dfba Mon Sep 17 00:00:00 2001 From: Bastien Jauny Date: Fri, 27 Mar 2026 18:07:13 +0100 Subject: [PATCH 1/3] Homework for lesson 2 The board used is the esp32s3_rlcd_4_2. It needs a special openocd from espressif to be able debug though. But with the correct host setup it's all good. The command used to build: west build -p always -b esp32s3_rlcd_4_2/esp32s3/procpu ./app -- -DCONFIG_DEBUG_THREAD_INFO=y -DOPENOCD=/home/bajau/openocd-esp32/bin/openocd -DOPENOCD_DEFAULT_PATH=/home/bajau/openocd-esp32/share/openocd/scripts The first lines of output: I (esp_psram): SPI SRAM memory test OK *** Booting Zephyr OS build v4.4.0-rc1 *** [00:00:03.012,000] main: LED state: OFF [00:00:04.012,000] main: LED state: ON [00:00:05.012,000] main: LED state: OFF [00:00:06.013,000] main: LED state: ON [00:00:07.013,000] main: LED state: OFF --- app/src/main.cpp | 11 +---------- west.yml | 6 ++---- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/app/src/main.cpp b/app/src/main.cpp index 5dfdde9c..9fcb18d2 100644 --- a/app/src/main.cpp +++ b/app/src/main.cpp @@ -1,12 +1,8 @@ -#include #include #include #define SLEEP_TIME_MS 1000 -/* The devicetree node identifier for the "led0" alias. */ -#define LED_NODE DT_ALIAS(led0) - static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED_NODE, gpios); LOG_MODULE_REGISTER(main, LOG_LEVEL_INF); @@ -15,13 +11,8 @@ int main(void) { bool led_state = true; - if (!gpio_is_ready_dt(&led)) return 0; - - if (gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE) < 0) return 0; - while (1) { - if (gpio_pin_toggle_dt(&led) < 0) return 0; - + /* No LED on a esp32s3_rlcd_4_2, just toggle the boolean :) */ led_state = !led_state; LOG_INF("LED state: %s", led_state ? "ON" : "OFF"); k_msleep(SLEEP_TIME_MS); diff --git a/west.yml b/west.yml index 8b525769..db8df41e 100644 --- a/west.yml +++ b/west.yml @@ -4,11 +4,9 @@ manifest: projects: - name: zephyr url: https://github.com/zephyrproject-rtos/zephyr - revision: v4.2.0 + revision: v4.4.0-rc1 import: name-allowlist: - cmsis_6 - - hal_nxp - - hal_stm32 - - hal_nordic + - hal_espressif path-prefix: deps From 128eb9bd3a0c85778998b6bb38d51d5193aa5d0f Mon Sep 17 00:00:00 2001 From: Bastien Jauny Date: Fri, 3 Apr 2026 15:26:33 +0200 Subject: [PATCH 2/3] Lesson 3: added a custom menu in Kconfig --- app/Kconfig | 76 ++++++++++++++++++++++++++++++++++++++++++++++++ app/src/main.cpp | 7 +---- 2 files changed, 77 insertions(+), 6 deletions(-) create mode 100644 app/Kconfig diff --git a/app/Kconfig b/app/Kconfig new file mode 100644 index 00000000..fb9eccc1 --- /dev/null +++ b/app/Kconfig @@ -0,0 +1,76 @@ +menu "Zephyr" +source "Kconfig.zephyr" +endmenu + +menuconfig LED_SUBSYSTEM + bool "LED Subsystem" + default y + +if LED_SUBSYSTEM + +choice + prompt "LED blinking sleep time" + default BLINKING_SPEED_MEDIUM + +config BLINKING_SPEED_SLOW + bool "2s (slow)" + +config BLINKING_SPEED_MEDIUM + bool "1s (medium)" + +config BLINKING_SPEED_FAST + bool "500ms (fast)" + +config BLINKING_LUDICROUS_SPEED + bool "250ms (ludicrous)" + +endchoice + +config LED_BLINK_PERIOD_MS + int + default 2000 if BLINKING_SPEED_SLOW + default 1000 if BLINKING_SPEED_MEDIUM + default 500 if BLINKING_SPEED_FAST + default 250 if BLINKING_LUDICROUS_SPEED + default 0 + +menuconfig ADVANCED_LED_SETTINGS + bool "Advanced LED settings" + default n + +if ADVANCED_LED_SETTINGS + +config LED_BRIGHTNESS + int "LED brightness (0-100)" + default 100 + range 0 100 + help + Brightness power in percentage (0 is off, 100 is full power). + +config LED_FADE_DURATION + int "LED fade duration (ms)" + default 500 + range 0 5000 + help + Duration of the fade effect in milliseconds. + +menu "Expert settings" + visible if GPIO + +config LED_DEBUGGING + bool "Enable LED debugging" + default n + help + Enable LED debugging. + +config CUSTOM_BLINK_PATTERN + bool "Custom blink pattern" + default n + help + Use a custom blink pattern. + +endmenu + +endif # ADVANCED_LED_SETTINGS + +endif # LED_SUBSYSTEM diff --git a/app/src/main.cpp b/app/src/main.cpp index 9fcb18d2..c23831d6 100644 --- a/app/src/main.cpp +++ b/app/src/main.cpp @@ -1,10 +1,6 @@ #include #include -#define SLEEP_TIME_MS 1000 - -static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED_NODE, gpios); - LOG_MODULE_REGISTER(main, LOG_LEVEL_INF); int main(void) @@ -12,10 +8,9 @@ int main(void) bool led_state = true; while (1) { - /* No LED on a esp32s3_rlcd_4_2, just toggle the boolean :) */ led_state = !led_state; LOG_INF("LED state: %s", led_state ? "ON" : "OFF"); - k_msleep(SLEEP_TIME_MS); + k_msleep(CONFIG_LED_BLINK_PERIOD_MS); } return 0; } From 356d9d8c2d4875c3642ba01163813e71181c6b72 Mon Sep 17 00:00:00 2001 From: Bastien Jauny Date: Fri, 10 Apr 2026 15:44:23 +0200 Subject: [PATCH 3/3] Lesson4: added a custom external LED --- app/Kconfig | 5 +++++ app/app.overlay | 14 ++++++++++++++ app/prj.conf | 1 + app/src/main.cpp | 20 +++++++++++++++++++- 4 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 app/app.overlay diff --git a/app/Kconfig b/app/Kconfig index fb9eccc1..2dcab7b9 100644 --- a/app/Kconfig +++ b/app/Kconfig @@ -8,6 +8,11 @@ menuconfig LED_SUBSYSTEM if LED_SUBSYSTEM +config APP_HEARTBEAT_PERIOD_MS + int "Period (in milliseconds) of the heartbeat LED" + default 500 + range 100 2000 + choice prompt "LED blinking sleep time" default BLINKING_SPEED_MEDIUM diff --git a/app/app.overlay b/app/app.overlay new file mode 100644 index 00000000..f69df84d --- /dev/null +++ b/app/app.overlay @@ -0,0 +1,14 @@ +/ { + aliases { + app-led = &led0; + }; + + leds { + compatible = "gpio-leds"; + + led0: ext_led { + gpios = <&gpio0 17 GPIO_ACTIVE_LOW>; + label = "External LED"; + }; + }; +}; diff --git a/app/prj.conf b/app/prj.conf index 244cc784..d54ba502 100644 --- a/app/prj.conf +++ b/app/prj.conf @@ -1,2 +1,3 @@ +CONFIG_CPP=y CONFIG_GPIO=y CONFIG_LOG=y diff --git a/app/src/main.cpp b/app/src/main.cpp index c23831d6..5d918ae9 100644 --- a/app/src/main.cpp +++ b/app/src/main.cpp @@ -1,16 +1,34 @@ #include +#include #include LOG_MODULE_REGISTER(main, LOG_LEVEL_INF); +#define LED_NODE DT_ALIAS(app_led) +static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED_NODE, gpios); + int main(void) { bool led_state = true; + if (!gpio_is_ready_dt(&led)) { + LOG_ERR("LED not ready!"); + return -1; + } + + if (gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE) < 0) { + LOG_ERR("Unable to configure LED!"); + return -1; + } + while (1) { led_state = !led_state; + if (gpio_pin_toggle_dt(&led) < 0) { + LOG_ERR("Unable to toggle the LED!"); + return -1; + } LOG_INF("LED state: %s", led_state ? "ON" : "OFF"); - k_msleep(CONFIG_LED_BLINK_PERIOD_MS); + k_msleep(CONFIG_APP_HEARTBEAT_PERIOD_MS); } return 0; }