diff --git a/builder/main.py b/builder/main.py index a416659..b60ee4b 100644 --- a/builder/main.py +++ b/builder/main.py @@ -82,7 +82,8 @@ # Target: Build executable and linkable firmware # -if "zephyr" in env.get("PIOFRAMEWORK", []): +frameworks = env.get("PIOFRAMEWORK", []) +if "zephyr" in frameworks: env.SConscript( join(platform.get_package_dir( "framework-zephyr"), "scripts", "platformio", "platformio-build-pre.py"), @@ -96,6 +97,9 @@ else: target_elf = env.BuildProgram() target_firm = env.ElfToBin(join("$BUILD_DIR", "${PROGNAME}"), target_elf) + if "zephyr" in frameworks and "mcuboot-image" in COMMAND_LINE_TARGETS: + target_firm = env.MCUbootImage( + join("$BUILD_DIR", "${PROGNAME}.mcuboot.bin"), target_firm) env.Depends(target_firm, "checkprogsize") AlwaysBuild(env.Alias("nobuild", target_firm)) diff --git a/examples/zephyr-blink/src/main.c b/examples/zephyr-blink/src/main.c index e2fbfd3..9c9ab43 100644 --- a/examples/zephyr-blink/src/main.c +++ b/examples/zephyr-blink/src/main.c @@ -4,48 +4,43 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include -#include -#include -#include +#include +#include /* 1000 msec = 1 sec */ -#define SLEEP_TIME_MS 1000 +#define SLEEP_TIME_MS 300 /* The devicetree node identifier for the "led0" alias. */ #define LED0_NODE DT_ALIAS(led0) -#if DT_NODE_HAS_STATUS(LED0_NODE, okay) -#define LED0 DT_GPIO_LABEL(LED0_NODE, gpios) -#define PIN DT_GPIO_PIN(LED0_NODE, gpios) -#define FLAGS DT_GPIO_FLAGS(LED0_NODE, gpios) -#else -/* A build error here means your board isn't set up to blink an LED. */ -#error "Unsupported board: led0 devicetree alias is not defined" -#define LED0 "" -#define PIN 0 -#define FLAGS 0 -#endif +/* + * 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); void main(void) { - const struct device *dev; - bool led_is_on = true; int ret; - dev = device_get_binding(LED0); - if (dev == NULL) { + if (!gpio_is_ready_dt(&led)) + { return; } - ret = gpio_pin_configure(dev, PIN, GPIO_OUTPUT_ACTIVE | FLAGS); - if (ret < 0) { + ret = gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE); + if (ret < 0) + { return; } - while (1) { - gpio_pin_set(dev, PIN, (int)led_is_on); - led_is_on = !led_is_on; + while (1) + { + ret = gpio_pin_toggle_dt(&led); + if (ret < 0) + { + return; + } k_msleep(SLEEP_TIME_MS); } } diff --git a/examples/zephyr-blink/zephyr/prj.conf b/examples/zephyr-blink/zephyr/prj.conf index 7bbd5af..91c3c15 100644 --- a/examples/zephyr-blink/zephyr/prj.conf +++ b/examples/zephyr-blink/zephyr/prj.conf @@ -1,2 +1 @@ CONFIG_GPIO=y -CONFIG_SERIAL=n diff --git a/examples/zephyr-synchronization/src/main.c b/examples/zephyr-synchronization/src/main.c index fb60a2e..027abd1 100644 --- a/examples/zephyr-synchronization/src/main.c +++ b/examples/zephyr-synchronization/src/main.c @@ -6,8 +6,8 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include -#include +#include +#include /* * The hello world demo has two threads that utilize semaphores and sleeping @@ -16,6 +16,7 @@ * world application would likely use the static approach for both threads. */ +#define PIN_THREADS (IS_ENABLED(CONFIG_SMP) && IS_ENABLED(CONFIG_SCHED_CPU_MASK)) /* size of stack area used by each thread */ #define STACKSIZE 1024 @@ -84,6 +85,9 @@ void threadB(void *dummy1, void *dummy2, void *dummy3) helloLoop(__func__, &threadB_sem, &threadA_sem); } +K_THREAD_STACK_DEFINE(threadA_stack_area, STACKSIZE); +static struct k_thread threadA_data; + K_THREAD_STACK_DEFINE(threadB_stack_area, STACKSIZE); static struct k_thread threadB_data; @@ -95,21 +99,35 @@ void threadA(void *dummy1, void *dummy2, void *dummy3) ARG_UNUSED(dummy2); ARG_UNUSED(dummy3); - /* spawn threadB */ - k_tid_t tid = k_thread_create(&threadB_data, threadB_stack_area, - STACKSIZE, threadB, NULL, NULL, NULL, + /* invoke routine to ping-pong hello messages with threadB */ + helloLoop(__func__, &threadA_sem, &threadB_sem); +} + +int main(void) +{ + k_thread_create(&threadA_data, threadA_stack_area, + K_THREAD_STACK_SIZEOF(threadA_stack_area), + threadA, NULL, NULL, NULL, PRIORITY, 0, K_FOREVER); + k_thread_name_set(&threadA_data, "thread_a"); +#if PIN_THREADS + if (arch_num_cpus() > 1) { + k_thread_cpu_pin(&threadA_data, 0); + } +#endif - k_thread_name_set(tid, "thread_b"); -#if CONFIG_SCHED_CPU_MASK - k_thread_cpu_mask_disable(&threadB_data, 1); - k_thread_cpu_mask_enable(&threadB_data, 0); + k_thread_create(&threadB_data, threadB_stack_area, + K_THREAD_STACK_SIZEOF(threadB_stack_area), + threadB, NULL, NULL, NULL, + PRIORITY, 0, K_FOREVER); + k_thread_name_set(&threadB_data, "thread_b"); +#if PIN_THREADS + if (arch_num_cpus() > 1) { + k_thread_cpu_pin(&threadB_data, 1); + } #endif - k_thread_start(&threadB_data); - /* invoke routine to ping-pong hello messages with threadB */ - helloLoop(__func__, &threadA_sem, &threadB_sem); + k_thread_start(&threadA_data); + k_thread_start(&threadB_data); + return 0; } - -K_THREAD_DEFINE(thread_a, STACKSIZE, threadA, NULL, NULL, NULL, - PRIORITY, 0, 0); diff --git a/examples/zephyr-synchronization/zephyr/prj.conf b/examples/zephyr-synchronization/zephyr/prj.conf index f31f3e0..f1a8e12 100644 --- a/examples/zephyr-synchronization/zephyr/prj.conf +++ b/examples/zephyr-synchronization/zephyr/prj.conf @@ -1,3 +1,4 @@ CONFIG_STDOUT_CONSOLE=y # enable to use thread names CONFIG_THREAD_NAME=y +CONFIG_SCHED_CPU_MASK=y diff --git a/platform.json b/platform.json index 04c183e..21137bf 100644 --- a/platform.json +++ b/platform.json @@ -33,7 +33,7 @@ "toolchain-gccarmnoneeabi": { "type": "toolchain", "owner": "platformio", - "version": ">=1.60301.0,<1.80000.0", + "version": "~1.100301.0", "optionalVersions": [ "~1.90201.0" ] @@ -48,7 +48,7 @@ "type": "framework", "optional": true, "owner": "platformio", - "version": "~2.20701.0" + "version": "~2.30400.0" }, "tool-openocd": { "type": "debugger",