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..2cb9f63 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,9 @@ +{ + "cmsis-csolution.environmentVariables": { + "ZEPHYR_BASE": "$HOME/zephyrproject/zephyr", + "PATH": "$HOME/zephyrproject/.venv/bin", + "VIRTUAL_ENV": "$HOME/zephyrproject/.venv", + }, + "debug.hideSlowPreLaunchWarning": true, + "debug.showInStatusBar": "never" +} \ No newline at end of file diff --git a/README.md b/README.md index da8159a..3c2c252 100644 --- a/README.md +++ b/README.md @@ -6,114 +6,23 @@ 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) -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) - -### Linux and macOS - -- 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. - -> [!Note] -> Remember to activate the virtual environment every time you start working. - -- 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 - ``` - -### Windows - -- Open a `cmd.exe` terminal window as a regular user. - -- Create a new virtual environment: - - ```sh - cd %HOMEPATH% - 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. - -> [!Note] -> Remember to activate the virtual environment every time you start working. - -- 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 - ``` - -### Work with the example - > [!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. - -- From the same terminal, start VS Code: +> 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). - ```sh - code . - ``` +## Quick start -- In the CMSIS view, click on **...**, use **Select Active Solution from workspace**, and choose "zephyr". +- 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. -- 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** extension 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 +56,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..0c6d67a --- /dev/null +++ b/blinky/prj.conf @@ -0,0 +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/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..a621c2f --- /dev/null +++ b/threads/prj.conf @@ -0,0 +1,10 @@ +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/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..3ecfe50 100644 --- a/zephyr.csolution.yml +++ b/zephyr.csolution.yml @@ -32,12 +32,7 @@ solution: target-set: - set: images: - - project-context: blinky.Debug - debugger: - name: ST-Link@pyOCD - port: 3333 - protocol: swd - clock: 4000000 + - project-context: threads.Debug - type: FRDM-MCXN947 board: NXP::FRDM-MCXN947 @@ -47,12 +42,7 @@ solution: target-set: - set: images: - - project-context: threads.Debug - debugger: - name: CMSIS-DAP@pyOCD - port: 3333 - protocol: swd - clock: 10000000 + - project-context: blinky.Debug # 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: @@ -69,8 +59,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