From 2b8b776b9ec554ad781cf6ed9bfebc42864fa999 Mon Sep 17 00:00:00 2001 From: Hector van der Aa Date: Sat, 21 Mar 2026 18:03:08 +0100 Subject: [PATCH] Blue LED flash on CM4 --- Zephyr/prj.conf | 3 +++ Zephyr/src/main.c | 46 +++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/Zephyr/prj.conf b/Zephyr/prj.conf index e69de29..11ef425 100644 --- a/Zephyr/prj.conf +++ b/Zephyr/prj.conf @@ -0,0 +1,3 @@ +CONFIG_GPIO=y +CONFIG_STM32H7_DUAL_CORE=y +CONFIG_STM32H7_BOOT_M4_AT_INIT=y diff --git a/Zephyr/src/main.c b/Zephyr/src/main.c index 5496741..d6d67ec 100644 --- a/Zephyr/src/main.c +++ b/Zephyr/src/main.c @@ -1,11 +1,47 @@ -// Copyright (C) 2026 Hector van der Aa -// Copyright (C) 2026 Association Exergie -// SPDX-License-Identifier: GPL-3.0-or-later +/* + * Copyright (c) 2016 Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ +#include +#include #include -#include + +/* 1000 msec = 1 sec */ +#define SLEEP_TIME_MS 1000 + +/* The devicetree node identifier for the "led0" alias. */ +#define LED0_NODE DT_ALIAS(led0) + +/* + * A build error on this line means your board is unsupported. + * See the sample documentation for information on how to fix this. + */ +static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED0_NODE, gpios); int main(void) { - printk("Hello from my freestanding Zephyr app!\n"); + int ret; + bool led_state = true; + + if (!gpio_is_ready_dt(&led)) { + return 0; + } + + ret = gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE); + if (ret < 0) { + return 0; + } + + while (1) { + ret = gpio_pin_toggle_dt(&led); + if (ret < 0) { + return 0; + } + + led_state = !led_state; + printf("LED state: %s\n", led_state ? "ON" : "OFF"); + k_msleep(SLEEP_TIME_MS); + } return 0; }