From cc5636701fd18213ce74cff6b044e2a3492be216 Mon Sep 17 00:00:00 2001 From: Christopher Seidl Date: Tue, 9 Dec 2025 15:06:22 +0100 Subject: [PATCH 1/5] Update for next extension version --- .cmsis/zephyr+B-U585I-IOT02A.dbgconf | 16 +-- ... zephyr+B-U585I-IOT02A.dbgconf.base@1.0.0} | 16 +-- .gitignore | 1 - .vscode/extensions.json | 6 + .vscode/settings.json | 12 ++ README.md | 105 ++++++++-------- blinky/CMakeLists.txt | 7 ++ blinky/README.rst | 97 +++++++++++++++ blinky/prj.conf | 1 + blinky/sample.yaml | 12 ++ blinky/src/main.c | 48 ++++++++ threads/CMakeLists.txt | 7 ++ threads/README.rst | 54 ++++++++ threads/prj.conf | 4 + threads/sample.yaml | 21 ++++ threads/src/main.c | 116 ++++++++++++++++++ zephyr.cbuild-pack.yml | 20 +++ zephyr.csolution.yml | 10 +- 18 files changed, 476 insertions(+), 77 deletions(-) rename .cmsis/{zephyr+B-U585I-IOT02A.dbgconf.base@1.0.1 => zephyr+B-U585I-IOT02A.dbgconf.base@1.0.0} (96%) create mode 100644 .vscode/extensions.json create mode 100644 .vscode/settings.json create mode 100644 blinky/CMakeLists.txt create mode 100644 blinky/README.rst create mode 100644 blinky/prj.conf create mode 100644 blinky/sample.yaml create mode 100644 blinky/src/main.c create mode 100644 threads/CMakeLists.txt create mode 100644 threads/README.rst create mode 100644 threads/prj.conf create mode 100644 threads/sample.yaml create mode 100644 threads/src/main.c create mode 100644 zephyr.cbuild-pack.yml diff --git a/.cmsis/zephyr+B-U585I-IOT02A.dbgconf b/.cmsis/zephyr+B-U585I-IOT02A.dbgconf index 3b73033..87f56f4 100644 --- a/.cmsis/zephyr+B-U585I-IOT02A.dbgconf +++ b/.cmsis/zephyr+B-U585I-IOT02A.dbgconf @@ -1,5 +1,5 @@ // File: STM32U535_545_575_585_59x_5Ax.dbgconf -// Version: 1.0.1 +// Version: 1.0.0 // Note: refer to STM32U5 reference manual (RM0456) // refer to STM32U535xx datasheet (DS14217) // STM32U545xx datasheet (DS14216) @@ -29,7 +29,7 @@ DbgMCU_CR = 0x00000006; // DBG_TIM3_STOP TIM3 is frozen while CPU is in debug mode // DBG_TIM2_STOP TIM2 is frozen while CPU is in debug mode // -DbgMCU_APB1L_Fz = 0x0060183F; +DbgMCU_APB1L_Fz = 0x00000000; // Debug MCU APB1H freeze register (DBGMCU_APB1HFZR) // Reserved bits must be kept at reset value @@ -40,7 +40,7 @@ DbgMCU_APB1L_Fz = 0x0060183F; // DBG_LPTIM2_STOP LPTIM2 is frozen while CPU is in debug mode // DBG_I2C4_STOP I2C4 is frozen while CPU is in debug mode // -DbgMCU_APB1H_Fz = 0x000000E2; +DbgMCU_APB1H_Fz = 0x00000000; // Debug MCU APB2 freeze register (DBGMCU_APB2FZR) // Reserved bits must be kept at reset value @@ -50,7 +50,7 @@ DbgMCU_APB1H_Fz = 0x000000E2; // DBG_TIM8_STOP TIM8 is frozen while CPU is in debug mode // DBG_TIM1_STOP TIM1 is frozen while CPU is in debug mode // -DbgMCU_APB2_Fz = 0x00072800; +DbgMCU_APB2_Fz = 0x00000000; // Debug MCU APB3 freeze register (DBGMCU_APB3FZR) // Reserved bits must be kept at reset value @@ -60,7 +60,7 @@ DbgMCU_APB2_Fz = 0x00072800; // DBG_LPTIM1_STOP LPTIM1 is frozen while CPU is in debug mode // DBG_I2C3_STOP I2C3 is frozen while CPU is in debug mode // -DbgMCU_APB3_Fz = 0x000E0400; +DbgMCU_APB3_Fz = 0x00000000; // Debug MCU AHB1 freeze register (DBGMCU_AHB1FZR) // Reserved bits must be kept at reset value @@ -81,7 +81,7 @@ DbgMCU_APB3_Fz = 0x000E0400; // DBG_GPDMA1_STOP GPDMA channel 1 is frozen while CPU is in debug mode // DBG_GPDMA0_STOP GPDMA channel 0 is frozen while CPU is in debug mode // -DbgMCU_AHB1_Fz = 0x0000FFFF; +DbgMCU_AHB1_Fz = 0x00000000; // Debug MCU AHB3 freeze register (DBGMCU_AHB3FZR) // Reserved bits must be kept at reset value @@ -90,12 +90,12 @@ DbgMCU_AHB1_Fz = 0x0000FFFF; // DBG_LPDMA1_STOP LPDMA channel 1 is frozen while CPU is in debug mode // DBG_LPDMA0_STOP LPDMA channel 0 is frozen while CPU is in debug mode // -DbgMCU_AHB3_Fz = 0x0000000F; +DbgMCU_AHB3_Fz = 0x00000000; // TPIU Pin Routing // TRACECLK // ETM Trace Clock -// <0x00040002=> Pin PE2 +// <0x0002000A=> Pin PE2 // <0x00000008=> Pin PA8 // TRACECLK: Pin PE2 // TRACED0 diff --git a/.cmsis/zephyr+B-U585I-IOT02A.dbgconf.base@1.0.1 b/.cmsis/zephyr+B-U585I-IOT02A.dbgconf.base@1.0.0 similarity index 96% rename from .cmsis/zephyr+B-U585I-IOT02A.dbgconf.base@1.0.1 rename to .cmsis/zephyr+B-U585I-IOT02A.dbgconf.base@1.0.0 index 3b73033..87f56f4 100644 --- a/.cmsis/zephyr+B-U585I-IOT02A.dbgconf.base@1.0.1 +++ b/.cmsis/zephyr+B-U585I-IOT02A.dbgconf.base@1.0.0 @@ -1,5 +1,5 @@ // File: STM32U535_545_575_585_59x_5Ax.dbgconf -// Version: 1.0.1 +// Version: 1.0.0 // Note: refer to STM32U5 reference manual (RM0456) // refer to STM32U535xx datasheet (DS14217) // STM32U545xx datasheet (DS14216) @@ -29,7 +29,7 @@ DbgMCU_CR = 0x00000006; // DBG_TIM3_STOP TIM3 is frozen while CPU is in debug mode // DBG_TIM2_STOP TIM2 is frozen while CPU is in debug mode // -DbgMCU_APB1L_Fz = 0x0060183F; +DbgMCU_APB1L_Fz = 0x00000000; // Debug MCU APB1H freeze register (DBGMCU_APB1HFZR) // Reserved bits must be kept at reset value @@ -40,7 +40,7 @@ DbgMCU_APB1L_Fz = 0x0060183F; // DBG_LPTIM2_STOP LPTIM2 is frozen while CPU is in debug mode // DBG_I2C4_STOP I2C4 is frozen while CPU is in debug mode // -DbgMCU_APB1H_Fz = 0x000000E2; +DbgMCU_APB1H_Fz = 0x00000000; // Debug MCU APB2 freeze register (DBGMCU_APB2FZR) // Reserved bits must be kept at reset value @@ -50,7 +50,7 @@ DbgMCU_APB1H_Fz = 0x000000E2; // DBG_TIM8_STOP TIM8 is frozen while CPU is in debug mode // DBG_TIM1_STOP TIM1 is frozen while CPU is in debug mode // -DbgMCU_APB2_Fz = 0x00072800; +DbgMCU_APB2_Fz = 0x00000000; // Debug MCU APB3 freeze register (DBGMCU_APB3FZR) // Reserved bits must be kept at reset value @@ -60,7 +60,7 @@ DbgMCU_APB2_Fz = 0x00072800; // DBG_LPTIM1_STOP LPTIM1 is frozen while CPU is in debug mode // DBG_I2C3_STOP I2C3 is frozen while CPU is in debug mode // -DbgMCU_APB3_Fz = 0x000E0400; +DbgMCU_APB3_Fz = 0x00000000; // Debug MCU AHB1 freeze register (DBGMCU_AHB1FZR) // Reserved bits must be kept at reset value @@ -81,7 +81,7 @@ DbgMCU_APB3_Fz = 0x000E0400; // DBG_GPDMA1_STOP GPDMA channel 1 is frozen while CPU is in debug mode // DBG_GPDMA0_STOP GPDMA channel 0 is frozen while CPU is in debug mode // -DbgMCU_AHB1_Fz = 0x0000FFFF; +DbgMCU_AHB1_Fz = 0x00000000; // Debug MCU AHB3 freeze register (DBGMCU_AHB3FZR) // Reserved bits must be kept at reset value @@ -90,12 +90,12 @@ DbgMCU_AHB1_Fz = 0x0000FFFF; // DBG_LPDMA1_STOP LPDMA channel 1 is frozen while CPU is in debug mode // DBG_LPDMA0_STOP LPDMA channel 0 is frozen while CPU is in debug mode // -DbgMCU_AHB3_Fz = 0x0000000F; +DbgMCU_AHB3_Fz = 0x00000000; // TPIU Pin Routing // TRACECLK // ETM Trace Clock -// <0x00040002=> Pin PE2 +// <0x0002000A=> Pin PE2 // <0x00000008=> Pin PA8 // TRACECLK: Pin PE2 // TRACED0 diff --git a/.gitignore b/.gitignore index d3a7579..37cfdee 100644 --- a/.gitignore +++ b/.gitignore @@ -76,7 +76,6 @@ uv2csolution.log .vscode/cmsis.json .vscode/launch.json .vscode/tasks.json -.vscode/settings.json .cmd.jlink # legacy intermediate project file diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..4a4ad81 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,6 @@ +{ + "recommendations": [ + "arm.keil-studio-pack", + "mcu-debug.rtos-views" + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..cf0901d --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,12 @@ +{ + "cmsis-csolution.env": { + "ZEPHYR_BASE": "$HOME/zephyrproject/zephyr", + "PATH": "$HOME/zephyrproject/.venv/bin", + "VIRTUAL_ENV": "$HOME/zephyrproject/.venv", + }, + "clangd.arguments": [ + "--compile-commands-dir=/Users/chrsei01/02_Git/Arm-Examples/CMSIS-Zephyr/out/blinky/FRDM-MCXN947/Debug" + ], + "debug.hideSlowPreLaunchWarning": true, + "debug.showInStatusBar": "never" +} \ No newline at end of file diff --git a/README.md b/README.md index da8159a..5deb6c5 100644 --- a/README.md +++ b/README.md @@ -11,14 +11,30 @@ and run the image on the target hardware. 1. Make sure that your host OS is up-to-date. 2. Install the following dependencies using your favorite package manager: - Cmake (min. version 3.20.5) - - Python (min. version 3.10) + - Python (min. version 3.10, see warning below) 3. Clone this repository onto your machine. -4. In a terminal, change the current directory to `./CMSIS-Zephyr`. -5. Install Zephyr locally (refer to [Linux and macOS](#linux-and-macos)/[Windows](#windows)). -6. [Work with the example](#work-with-the-example) +4. Install Zephyr on your machine (refer to [Linux and macOS](#linux-and-macos)/[Windows](#windows)). +5. [Work with the example](#work-with-the-example) + +> [!WARNING] +> On Windows, do not install Python 3.14 or above as the Python package `windows-curses` is not yet available! + +## Zephyr installation + +This chapter contains installation instructions for [Linux and macOS](#linux-and-macos) and [Windows](#windows)). + +If you have a Zephyr environment already set up on your computer, you can skip this step. Make sure to check the +[environment settings](#environment-settings). ### Linux and macOS +- In your home directory, create a `zephyrproject` directory and change into it: + + ```sh + mkdir zephyrproject + cd zephyrproject + ``` + - Create a new virtual environment: ```sh @@ -31,10 +47,8 @@ and run the image on the target hardware. source .venv/bin/activate ``` - Once activated your shell will be prefixed with (.venv). The virtual environment can be deactivated at any time by running deactivate. - -> [!Note] -> Remember to activate the virtual environment every time you start working. + Once activated, your shell will be prefixed with (.venv). The virtual environment can be deactivated at any time by + running `deactivate`. - Install west: @@ -45,7 +59,7 @@ and run the image on the target hardware. - Get the Zephyr source code: ```sh - west init + west init west update ``` @@ -55,14 +69,22 @@ and run the image on the target hardware. west packages pip --install ``` +Continue with [environment settings](#environment-settings). + ### Windows - Open a `cmd.exe` terminal window as a regular user. +- Create a `zephyrproject` directory and change into it: + + ```sh + mkdir zephyrproject + cd zephyrproject + ``` + - Create a new virtual environment: ```sh - cd %HOMEPATH% python -m venv .venv ``` @@ -72,10 +94,8 @@ and run the image on the target hardware. .venv\Scripts\activate.bat ``` - Once activated your shell will be prefixed with (.venv). The virtual environment can be deactivated at any time by running deactivate. - -> [!Note] -> Remember to activate the virtual environment every time you start working. + Once activated your shell will be prefixed with (.venv). The virtual environment can be deactivated at any time by + running deactivate. - Install west: @@ -96,24 +116,29 @@ and run the image on the target hardware. west packages pip --install ``` -### Work with the example +Continue with [environment settings](#environment-settings). -> [!NOTE] -> - Make sure that the virtual environment is still sourced. -> - Starting VS Code from here ensures that the virtual environment is present in your VS Code instance. +### Environment settings -- From the same terminal, start VS Code: +This repository contains a `.vscode/settings.json` file with the required settings for the Python virtual environment. +If you have followed the instructions without changing folder names, it should work out-of-the-box. If you have created +the Zephyr environment is a different location, adapt the paths to your needs. - ```sh - code . - ``` +> [!NOTE] +> On Windows, you might want to replace the `~` with `%USERPROFILE%` to make it work. + +## Work with the example -- In the CMSIS view, click on **...**, use **Select Active Solution from workspace**, and choose "zephyr". +- Open the folder in VS Code. It should install required extensions automatically. +- In the CMSIS view, click on **...**, use **Open Solution in Workspace**, and choose "zephyr". - Press the **Manage Solution Settings** button. In the dialog, select the target board and application. - Press the **Build solution** button to build the example. -- Start the CMSIS Debugger. +- Press the **Load & Debug application** button to start a debug session. -## Switch to a different board +> [!NOTE] +> Check that the **Arm CMSIS Solution** is at least v1.64.0. + +### Switch to a different board If you want to run the examples on a different board, simply edit the `Examples/Blinky/blinky.csolution.yml` or `Examples/Threads/threads.csolution.yml` files: @@ -147,33 +172,3 @@ Zephyr board name like this: > [!NOTE] > Make sure to delete the previous `/out` and `/tmp` directories before saving the updated `*.csolution.yml` file, > otherwise the solution might not load correctly. - -## Using an existing Zephyr environment - -If you have previously set up your Zephyr environment, set the `ZEPHYR_BASE` environment variable to the -`/zephyrproject/zephyr` folder: - -**Linux** - -```sh -(echo; echo 'export ZEPHYR_BASE="/home/.../zephyrproject/zephyr"') >> ~/.bashrc -source ~/.bashrc -``` - -**macOS** - -```sh -(echo; echo 'export ZEPHYR_BASE="/usr/.../zephyrproject/zephyr"') >> ~/.zshrc -source ~/.zshrc -``` - -**Windows** - -Set `ZEPHYR_BASE` to `C:\...\Zephyr-Workspace\zephyr` in -[Environment Variables](https://learn.microsoft.com/en-us/answers/questions/4330946/change-system-variables-on-windows-11). - -Now, open a terminal window and continue with the fourth item in the [Quick start](#quick-start) section. - -> [!NOTE] -> You need to adapt the paths to the examples in the `zephyr.csolution.yml` file to the location of your Zephyr -> installation (change `app-path:`). diff --git a/blinky/CMakeLists.txt b/blinky/CMakeLists.txt new file mode 100644 index 0000000..4de34fb --- /dev/null +++ b/blinky/CMakeLists.txt @@ -0,0 +1,7 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(blinky) + +target_sources(app PRIVATE src/main.c) diff --git a/blinky/README.rst b/blinky/README.rst new file mode 100644 index 0000000..ec23fe5 --- /dev/null +++ b/blinky/README.rst @@ -0,0 +1,97 @@ +.. zephyr:code-sample:: blinky + :name: Blinky + :relevant-api: gpio_interface + + Blink an LED forever using the GPIO API. + +Overview +******** + +The Blinky sample blinks an LED forever using the :ref:`GPIO API `. + +The source code shows how to: + +#. Get a pin specification from the :ref:`devicetree ` as a + :c:struct:`gpio_dt_spec` +#. Configure the GPIO pin as an output +#. Toggle the pin forever + +See :zephyr:code-sample:`pwm-blinky` for a similar sample that uses the PWM API instead. + +.. _blinky-sample-requirements: + +Requirements +************ + +Your board must: + +#. Have an LED connected via a GPIO pin (these are called "User LEDs" on many of + Zephyr's :ref:`boards`). +#. Have the LED configured using the ``led0`` devicetree alias. + +Building and Running +******************** + +Build and flash Blinky as follows, changing ``reel_board`` for your board: + +.. zephyr-app-commands:: + :zephyr-app: samples/basic/blinky + :board: reel_board + :goals: build flash + :compact: + +After flashing, the LED starts to blink and messages with the current LED state +are printed on the console. If a runtime error occurs, the sample exits without +printing to the console. + +Build errors +************ + +You will see a build error at the source code line defining the ``struct +gpio_dt_spec led`` variable if you try to build Blinky for an unsupported +board. + +On GCC-based toolchains, the error looks like this: + +.. code-block:: none + + error: '__device_dts_ord_DT_N_ALIAS_led_P_gpios_IDX_0_PH_ORD' undeclared here (not in a function) + +Adding board support +******************** + +To add support for your board, add something like this to your devicetree: + +.. code-block:: DTS + + / { + aliases { + led0 = &myled0; + }; + + leds { + compatible = "gpio-leds"; + myled0: led_0 { + gpios = <&gpio0 13 GPIO_ACTIVE_LOW>; + }; + }; + }; + +The above sets your board's ``led0`` alias to use pin 13 on GPIO controller +``gpio0``. The pin flags :c:macro:`GPIO_ACTIVE_HIGH` mean the LED is on when +the pin is set to its high state, and off when the pin is in its low state. + +Tips: + +- See :dtcompatible:`gpio-leds` for more information on defining GPIO-based LEDs + in devicetree. + +- If you're not sure what to do, check the devicetrees for supported boards which + use the same SoC as your target. See :ref:`get-devicetree-outputs` for details. + +- See :zephyr_file:`include/zephyr/dt-bindings/gpio/gpio.h` for the flags you can use + in devicetree. + +- If the LED is built in to your board hardware, the alias should be defined in + your :ref:`BOARD.dts file `. Otherwise, you can + define one in a :ref:`devicetree overlay `. diff --git a/blinky/prj.conf b/blinky/prj.conf new file mode 100644 index 0000000..91c3c15 --- /dev/null +++ b/blinky/prj.conf @@ -0,0 +1 @@ +CONFIG_GPIO=y diff --git a/blinky/sample.yaml b/blinky/sample.yaml new file mode 100644 index 0000000..de71191 --- /dev/null +++ b/blinky/sample.yaml @@ -0,0 +1,12 @@ +sample: + name: Blinky Sample +tests: + sample.basic.blinky: + tags: + - LED + - gpio + filter: dt_enabled_alias_with_parent_compat("led0", "gpio-leds") + depends_on: gpio + harness: led + integration_platforms: + - frdm_k64f diff --git a/blinky/src/main.c b/blinky/src/main.c new file mode 100644 index 0000000..4cab496 --- /dev/null +++ b/blinky/src/main.c @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2016 Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#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) +{ + 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; +} diff --git a/threads/CMakeLists.txt b/threads/CMakeLists.txt new file mode 100644 index 0000000..3f730cb --- /dev/null +++ b/threads/CMakeLists.txt @@ -0,0 +1,7 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(threads) + +target_sources(app PRIVATE src/main.c) diff --git a/threads/README.rst b/threads/README.rst new file mode 100644 index 0000000..f58c886 --- /dev/null +++ b/threads/README.rst @@ -0,0 +1,54 @@ +.. zephyr:code-sample:: multi-thread-blinky + :name: Basic thread manipulation + :relevant-api: gpio_interface thread_apis + + Spawn multiple threads that blink LEDs and print information to the console. + +Overview +******** + +This example demonstrates spawning multiple threads using +:c:func:`K_THREAD_DEFINE`. It spawns three threads. Each thread is then defined +at compile time using K_THREAD_DEFINE. + +The first two each control an LED. These LEDs, ``led0`` and ``led1``, have +loop control and timing logic controlled by separate functions. + +- ``blink0()`` controls ``led0`` and has a 100ms sleep cycle +- ``blink1()`` controls ``led1`` and has a 1000ms sleep cycle + +When either of these threads toggles its LED, it also pushes information into a +:ref:`FIFO ` identifying the thread/LED and how many times it has +been toggled. + +The third thread uses :c:func:`printk` to print the information added to the +FIFO to the device console. + +Requirements +************ + +The board must have two LEDs connected via GPIO pins. These are called "User +LEDs" on many of Zephyr's :ref:`boards`. The LEDs must be configured using the +``led0`` and ``led1`` :ref:`devicetree ` aliases, usually in the +:ref:`BOARD.dts file `. + +You will see one of these errors if you try to build this sample for an +unsupported board: + +.. code-block:: none + + Unsupported board: led0 devicetree alias is not defined + Unsupported board: led1 devicetree alias is not defined + +Building +******** + +For example, to build this sample for :ref:`96b_carbon_board`: + +.. zephyr-app-commands:: + :zephyr-app: samples/basic/threads + :board: 96b_carbon/stm32f401xe + :goals: build flash + :compact: + +Change ``96b_carbon/stm32f401xe`` appropriately for other supported boards. diff --git a/threads/prj.conf b/threads/prj.conf new file mode 100644 index 0000000..1848bb8 --- /dev/null +++ b/threads/prj.conf @@ -0,0 +1,4 @@ +CONFIG_PRINTK=y +CONFIG_HEAP_MEM_POOL_SIZE=256 +CONFIG_ASSERT=y +CONFIG_GPIO=y diff --git a/threads/sample.yaml b/threads/sample.yaml new file mode 100644 index 0000000..0d3acce --- /dev/null +++ b/threads/sample.yaml @@ -0,0 +1,21 @@ +sample: + description: A basic demo to showcase multi-threading using K_THREAD_DEFINE + name: Basic Thread Demo +tests: + sample.basic.threads: + tags: + - kernel + - threads + - gpio + filter: dt_enabled_alias_with_parent_compat("led0", "gpio-leds") and + dt_enabled_alias_with_parent_compat("led1", "gpio-leds") + integration_platforms: + - nrf52833dk/nrf52820 + depends_on: gpio + harness: console + harness_config: + type: multi_line + ordered: false + regex: + - "Toggled led0; counter=(.*)" + - "Toggled led1; counter=(.*)" diff --git a/threads/src/main.c b/threads/src/main.c new file mode 100644 index 0000000..529df15 --- /dev/null +++ b/threads/src/main.c @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2017 Linaro Limited + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include +#include + +/* size of stack area used by each thread */ +#define STACKSIZE 1024 + +/* scheduling priority used by each thread */ +#define PRIORITY 7 + +#define LED0_NODE DT_ALIAS(led0) +#define LED1_NODE DT_ALIAS(led1) + +#if !DT_NODE_HAS_STATUS_OKAY(LED0_NODE) +#error "Unsupported board: led0 devicetree alias is not defined" +#endif + +#if !DT_NODE_HAS_STATUS_OKAY(LED1_NODE) +#error "Unsupported board: led1 devicetree alias is not defined" +#endif + +struct printk_data_t { + void *fifo_reserved; /* 1st word reserved for use by fifo */ + uint32_t led; + uint32_t cnt; +}; + +K_FIFO_DEFINE(printk_fifo); + +struct led { + struct gpio_dt_spec spec; + uint8_t num; +}; + +static const struct led led0 = { + .spec = GPIO_DT_SPEC_GET_OR(LED0_NODE, gpios, {0}), + .num = 0, +}; + +static const struct led led1 = { + .spec = GPIO_DT_SPEC_GET_OR(LED1_NODE, gpios, {0}), + .num = 1, +}; + +void blink(const struct led *led, uint32_t sleep_ms, uint32_t id) +{ + const struct gpio_dt_spec *spec = &led->spec; + int cnt = 0; + int ret; + + if (!device_is_ready(spec->port)) { + printk("Error: %s device is not ready\n", spec->port->name); + return; + } + + ret = gpio_pin_configure_dt(spec, GPIO_OUTPUT); + if (ret != 0) { + printk("Error %d: failed to configure pin %d (LED '%d')\n", + ret, spec->pin, led->num); + return; + } + + while (1) { + gpio_pin_set(spec->port, spec->pin, cnt % 2); + + struct printk_data_t tx_data = { .led = id, .cnt = cnt }; + + size_t size = sizeof(struct printk_data_t); + char *mem_ptr = k_malloc(size); + __ASSERT_NO_MSG(mem_ptr != 0); + + memcpy(mem_ptr, &tx_data, size); + + k_fifo_put(&printk_fifo, mem_ptr); + + k_msleep(sleep_ms); + cnt++; + } +} + +void blink0(void) +{ + blink(&led0, 100, 0); +} + +void blink1(void) +{ + blink(&led1, 1000, 1); +} + +void uart_out(void) +{ + while (1) { + struct printk_data_t *rx_data = k_fifo_get(&printk_fifo, + K_FOREVER); + printk("Toggled led%d; counter=%d\n", + rx_data->led, rx_data->cnt); + k_free(rx_data); + } +} + +K_THREAD_DEFINE(blink0_id, STACKSIZE, blink0, NULL, NULL, NULL, + PRIORITY, 0, 0); +K_THREAD_DEFINE(blink1_id, STACKSIZE, blink1, NULL, NULL, NULL, + PRIORITY, 0, 0); +K_THREAD_DEFINE(uart_out_id, STACKSIZE, uart_out, NULL, NULL, NULL, + PRIORITY, 0, 0); diff --git a/zephyr.cbuild-pack.yml b/zephyr.cbuild-pack.yml new file mode 100644 index 0000000..6656351 --- /dev/null +++ b/zephyr.cbuild-pack.yml @@ -0,0 +1,20 @@ +cbuild-pack: + resolved-packs: + - resolved-pack: Keil::B-L475E-IOT01A_BSP@2.1.0 + selected-by-pack: + - Keil::B-L475E-IOT01A_BSP + - resolved-pack: Keil::B-U585I-IOT02A_BSP@2.0.0 + selected-by-pack: + - Keil::B-U585I-IOT02A_BSP + - resolved-pack: Keil::STM32L4xx_DFP@3.1.0 + selected-by-pack: + - Keil::STM32L4xx_DFP + - resolved-pack: Keil::STM32U5xx_DFP@3.0.0 + selected-by-pack: + - Keil::STM32U5xx_DFP + - resolved-pack: NXP::FRDM-MCXN947_BSP@19.0.0 + selected-by-pack: + - NXP::FRDM-MCXN947_BSP@19.0.0 + - resolved-pack: NXP::MCXN947_DFP@19.0.0 + selected-by-pack: + - NXP::MCXN947_DFP@19.0.0 diff --git a/zephyr.csolution.yml b/zephyr.csolution.yml index c56ff83..8914a4f 100644 --- a/zephyr.csolution.yml +++ b/zephyr.csolution.yml @@ -31,13 +31,13 @@ solution: device: STMicroelectronics::STM32U585AIIx target-set: - set: - images: - - project-context: blinky.Debug debugger: name: ST-Link@pyOCD port: 3333 protocol: swd clock: 4000000 + images: + - project-context: blinky.Debug - type: FRDM-MCXN947 board: NXP::FRDM-MCXN947 @@ -47,7 +47,7 @@ solution: target-set: - set: images: - - project-context: threads.Debug + - project-context: blinky.Debug debugger: name: CMSIS-DAP@pyOCD port: 3333 @@ -69,8 +69,8 @@ solution: # List related projects. projects: - west: - app-path: ./zephyr/samples/basic/blinky + app-path: ./blinky - west: - app-path: ./zephyr/samples/basic/threads + app-path: ./threads compiler: GCC created-for: CMSIS-Toolbox@2.12.0 From 52801175ed5c22021d939aea75e6327dac5ac3bc Mon Sep 17 00:00:00 2001 From: Christopher Seidl Date: Tue, 9 Dec 2025 15:10:36 +0100 Subject: [PATCH 2/5] Update --- README.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/README.md b/README.md index 5deb6c5..d22a2e9 100644 --- a/README.md +++ b/README.md @@ -124,9 +124,6 @@ This repository contains a `.vscode/settings.json` file with the required settin If you have followed the instructions without changing folder names, it should work out-of-the-box. If you have created the Zephyr environment is a different location, adapt the paths to your needs. -> [!NOTE] -> On Windows, you might want to replace the `~` with `%USERPROFILE%` to make it work. - ## Work with the example - Open the folder in VS Code. It should install required extensions automatically. From e62932563473b780add69d782edaaae4a10ecede Mon Sep 17 00:00:00 2001 From: Christopher Seidl Date: Tue, 9 Dec 2025 15:15:04 +0100 Subject: [PATCH 3/5] Removed user-specific setting. --- .vscode/settings.json | 3 --- 1 file changed, 3 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index cf0901d..d2edebc 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -4,9 +4,6 @@ "PATH": "$HOME/zephyrproject/.venv/bin", "VIRTUAL_ENV": "$HOME/zephyrproject/.venv", }, - "clangd.arguments": [ - "--compile-commands-dir=/Users/chrsei01/02_Git/Arm-Examples/CMSIS-Zephyr/out/blinky/FRDM-MCXN947/Debug" - ], "debug.hideSlowPreLaunchWarning": true, "debug.showInStatusBar": "never" } \ No newline at end of file From 1f8e45c3169c700d7c8873e140b8172a02d83b68 Mon Sep 17 00:00:00 2001 From: Christopher Seidl Date: Wed, 17 Dec 2025 10:56:24 +0100 Subject: [PATCH 4/5] Polishing --- README.md | 127 +++---------------------------------------- blinky/prj.conf | 6 ++ threads/prj.conf | 6 ++ zephyr.csolution.yml | 14 +---- 4 files changed, 21 insertions(+), 132 deletions(-) diff --git a/README.md b/README.md index d22a2e9..3c2c252 100644 --- a/README.md +++ b/README.md @@ -6,134 +6,21 @@ system to create the executable file for an application and the [Arm CMSIS Debugger](https://marketplace.visualstudio.com/items?itemName=Arm.vscode-cmsis-debugger) to flash download and run the image on the target hardware. -## Quick start - -1. Make sure that your host OS is up-to-date. -2. Install the following dependencies using your favorite package manager: - - Cmake (min. version 3.20.5) - - Python (min. version 3.10, see warning below) -3. Clone this repository onto your machine. -4. Install Zephyr on your machine (refer to [Linux and macOS](#linux-and-macos)/[Windows](#windows)). -5. [Work with the example](#work-with-the-example) - -> [!WARNING] -> On Windows, do not install Python 3.14 or above as the Python package `windows-curses` is not yet available! - -## Zephyr installation - -This chapter contains installation instructions for [Linux and macOS](#linux-and-macos) and [Windows](#windows)). - -If you have a Zephyr environment already set up on your computer, you can skip this step. Make sure to check the -[environment settings](#environment-settings). - -### Linux and macOS - -- In your home directory, create a `zephyrproject` directory and change into it: - - ```sh - mkdir zephyrproject - cd zephyrproject - ``` - -- Create a new virtual environment: - - ```sh - python3 -m venv .venv - ``` - -- Activate the virtual environment: - - ```sh - source .venv/bin/activate - ``` - - Once activated, your shell will be prefixed with (.venv). The virtual environment can be deactivated at any time by - running `deactivate`. - -- Install west: - - ```sh - pip install west - ``` - -- Get the Zephyr source code: - - ```sh - west init - west update - ``` - -- Install Python dependencies using west packages: - - ```sh - west packages pip --install - ``` - -Continue with [environment settings](#environment-settings). - -### Windows - -- Open a `cmd.exe` terminal window as a regular user. - -- Create a `zephyrproject` directory and change into it: - - ```sh - mkdir zephyrproject - cd zephyrproject - ``` - -- Create a new virtual environment: - - ```sh - python -m venv .venv - ``` - -- Activate the virtual environment: - - ```sh - .venv\Scripts\activate.bat - ``` - - Once activated your shell will be prefixed with (.venv). The virtual environment can be deactivated at any time by - running deactivate. - -- Install west: - - ```sh - pip install west - ``` - -- Get the Zephyr source code: - - ```sh - west init - west update - ``` - -- Install Python dependencies using west packages. - - ```sh - west packages pip --install - ``` - -Continue with [environment settings](#environment-settings). - -### Environment settings - -This repository contains a `.vscode/settings.json` file with the required settings for the Python virtual environment. -If you have followed the instructions without changing folder names, it should work out-of-the-box. If you have created -the Zephyr environment is a different location, adapt the paths to your needs. +> [!NOTE] +> Make sure that you have installed Zephyr as explained in the +> [Keil Studio documentation](https://mdk-packs.github.io/vscode-cmsis-solution-docs/zephyr.html). -## Work with the example +## Quick start -- Open the folder in VS Code. It should install required extensions automatically. +- Clone this repository onto your machine. +- Open it in VS Code. It should install required extensions automatically. - In the CMSIS view, click on **...**, use **Open Solution in Workspace**, and choose "zephyr". - Press the **Manage Solution Settings** button. In the dialog, select the target board and application. - Press the **Build solution** button to build the example. - Press the **Load & Debug application** button to start a debug session. > [!NOTE] -> Check that the **Arm CMSIS Solution** is at least v1.64.0. +> Check that the **Arm CMSIS Solution** extension is at least v1.64.0. ### Switch to a different board diff --git a/blinky/prj.conf b/blinky/prj.conf index 91c3c15..0c6d67a 100644 --- a/blinky/prj.conf +++ b/blinky/prj.conf @@ -1 +1,7 @@ CONFIG_GPIO=y +# Use Newlib from the Arm GNU Toolchain +CONFIG_NEWLIB_LIBC=y +# Disable Picolibc +CONFIG_PICOLIBC=n +CONFIG_PICOLIBC_USE_MODULE=n +CONFIG_MINIMAL_LIBC=n \ No newline at end of file diff --git a/threads/prj.conf b/threads/prj.conf index 1848bb8..a621c2f 100644 --- a/threads/prj.conf +++ b/threads/prj.conf @@ -2,3 +2,9 @@ CONFIG_PRINTK=y CONFIG_HEAP_MEM_POOL_SIZE=256 CONFIG_ASSERT=y CONFIG_GPIO=y +# Use Newlib from the Arm GNU Toolchain +CONFIG_NEWLIB_LIBC=y +# Disable Picolibc +CONFIG_PICOLIBC=n +CONFIG_PICOLIBC_USE_MODULE=n +CONFIG_MINIMAL_LIBC=n diff --git a/zephyr.csolution.yml b/zephyr.csolution.yml index 8914a4f..3ecfe50 100644 --- a/zephyr.csolution.yml +++ b/zephyr.csolution.yml @@ -31,13 +31,8 @@ solution: device: STMicroelectronics::STM32U585AIIx target-set: - set: - debugger: - name: ST-Link@pyOCD - port: 3333 - protocol: swd - clock: 4000000 images: - - project-context: blinky.Debug + - project-context: threads.Debug - type: FRDM-MCXN947 board: NXP::FRDM-MCXN947 @@ -48,11 +43,6 @@ solution: - set: images: - project-context: blinky.Debug - debugger: - name: CMSIS-DAP@pyOCD - port: 3333 - protocol: swd - clock: 10000000 # List of different build configurations. build-types: @@ -60,7 +50,7 @@ solution: west-defs: - CONFIG_DEBUG: y - CONFIG_DEBUG_THREAD_INFO: y - - CONFIG_THREAD_STACK_INFO: y + - CONFIG_THREAD_STACK_INFO: n - CONFIG_DEBUG_OPTIMIZATIONS: y - type: Release west-defs: From 75006f714f86709f16d8ac1bdb4e319c1231e5b3 Mon Sep 17 00:00:00 2001 From: Christopher Seidl Date: Wed, 17 Dec 2025 11:23:05 +0100 Subject: [PATCH 5/5] Updated settings.json --- .vscode/settings.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index d2edebc..2cb9f63 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,5 @@ { - "cmsis-csolution.env": { + "cmsis-csolution.environmentVariables": { "ZEPHYR_BASE": "$HOME/zephyrproject/zephyr", "PATH": "$HOME/zephyrproject/.venv/bin", "VIRTUAL_ENV": "$HOME/zephyrproject/.venv",