Error setting up Zephyr SDK and building MLops Zephyr example with VSCODE

@tjvantoll Your trouble shooting guidance is requested. I am trying to begin my Zephyr migration via your “Establishing a Robust MLOps Workflow for TinyML” Blog/GitHub example. I have the hardware setup, and tried to follow the “Zephyr SDK Getting Set Up Documentation”. After reopening in a Container, I am getting a build error using “Terminal>Run Task…Zephry: Build Application”? Your troubleshooting guidance is much appreciated.

BTW, I think my MacBook had Zephyr previously installed for work with Sparrow. The Docker approach may not have overwritten outdated settings?

Following is the terminal output:

  • Executing task: west build --board swan_r5 --pristine=always /workspaces/mlops-zephyr

– west build: making build dir /workspaces/mlops-zephyr/build pristine
– west build: generating a build system
Loading Zephyr default modules (Zephyr base).
– Application: /workspaces/mlops-zephyr
– CMake version: 3.22.1
– Found Python3: /usr/bin/python3 (found suitable version “3.10.12”, minimum required is “3.8”) found components: Interpreter
– Cache files will be written to: /home/blues/.cache/zephyr
– Zephyr version: 3.5.99 (/home/blues/zephyrproject/zephyr)
– Found west (found suitable version “1.2.0”, minimum required is “0.14.0”)
– Board: swan_r5
– ZEPHYR_TOOLCHAIN_VARIANT not set, trying to locate Zephyr SDK
CMake Error at /home/blues/zephyrproject/zephyr/cmake/modules/FindZephyr-sdk.cmake:109 (find_package):
Could not find a configuration file for package “Zephyr-sdk” that is
compatible with requested version “0.16”.

The following configuration files were considered but not accepted:

/usr/local/zephyr-sdk-0.15.2/cmake/Zephyr-sdkConfig.cmake, version: 0.15.2

Call Stack (most recent call first):
/home/blues/zephyrproject/zephyr/cmake/modules/FindHostTools.cmake:53 (find_package)
/home/blues/zephyrproject/zephyr/cmake/modules/dts.cmake:9 (find_package)
/home/blues/zephyrproject/zephyr/cmake/modules/zephyr_default.cmake:129 (include)
/home/blues/zephyrproject/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:66 (include)
/home/blues/zephyrproject/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:92 (include_boilerplate)
CMakeLists.txt:11 (find_package)

– Configuring incomplete, errors occurred!
FATAL ERROR: command exited with status 1: /usr/bin/cmake -DWEST_PYTHON=/usr/bin/python3 -B/workspaces/mlops-zephyr/build -GNinja -DBOARD=swan_r5 -S/workspaces/mlops-zephyr

  • The terminal process “/bin/bash ‘-c’, ‘west build --board swan_r5 --pristine=always /workspaces/mlops-zephyr’” terminated with exit code: 1.
  • Terminal will be reused by tasks, press any key to close it.

Hey @JimM,

Sorry you ran into issues here. I went ahead and ran a Zephyr build on my Mac so we could compare and contrast the output. (See below.)

It looks like your container is looking for an 0.16 version of the zephyr-sdk but not finding it, but on my machine 0.16.3 is available.

A couple of ideas:

  • If you didn’t do a fresh clone of note-zephyr I’d do that just to make sure you’re definitely working with the latest version of everything: Zephyr SDK - Blues Developers.
  • I’d run docker system prune (outside of any containers) which should help clean up any old or outdated containers that might be interfering.

I’d start there and see how it goes. I’m also going to do some asking around to see if this error looks familiar to anyone else.

TJ

Executing task: west build --board swan_r5 --pristine=always /workspaces/note-zephyr 

-- west build: generating a build system
Loading Zephyr default modules (Zephyr base).
-- Application: /workspaces/note-zephyr
-- CMake version: 3.22.1
-- Found Python3: /usr/bin/python3 (found suitable version "3.10.12", minimum required is "3.8") found components: Interpreter 
-- Cache files will be written to: /home/blues/.cache/zephyr
-- Zephyr version: 3.5.99 (/home/blues/zephyrproject/zephyr)
-- Found west (found suitable version "1.2.0", minimum required is "0.14.0")
-- Board: swan_r5
-- ZEPHYR_TOOLCHAIN_VARIANT not set, trying to locate Zephyr SDK
-- Found host-tools: zephyr 0.16.3 (/usr/local/zephyr-sdk-0.16.3)
-- Found toolchain: zephyr 0.16.3 (/usr/local/zephyr-sdk-0.16.3)
-- Found Dtc: /usr/local/zephyr-sdk-0.16.3/sysroots/aarch64-pokysdk-linux/usr/bin/dtc (found suitable version "1.6.0", minimum required is "1.4.6") 
-- Found BOARD.dts: /home/blues/zephyrproject/zephyr/boards/arm/swan_r5/swan_r5.dts
-- Generated zephyr.dts: /workspaces/note-zephyr/build/zephyr/zephyr.dts
-- Generated devicetree_generated.h: /workspaces/note-zephyr/build/zephyr/include/generated/devicetree_generated.h
-- Including generated dts.cmake file: /workspaces/note-zephyr/build/zephyr/dts.cmake
/workspaces/note-zephyr/build/zephyr/zephyr.dts:577.10-584.5: Warning (simple_bus_reg): /soc/clocks: missing or empty reg/ranges property
Parsing /home/blues/zephyrproject/zephyr/Kconfig
Loaded configuration '/home/blues/zephyrproject/zephyr/boards/arm/swan_r5/swan_r5_defconfig'
Merged configuration '/workspaces/note-zephyr/prj.conf'
Configuration saved to '/workspaces/note-zephyr/build/zephyr/.config'
Kconfig header saved to '/workspaces/note-zephyr/build/zephyr/include/generated/autoconf.h'
-- Found GnuLd: /usr/local/zephyr-sdk-0.16.3/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd (found version "2.38") 
-- The C compiler identification is GNU 12.2.0
-- The CXX compiler identification is GNU 12.2.0
-- The ASM compiler identification is GNU
-- Found assembler: /usr/local/zephyr-sdk-0.16.3/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc
-- Using ccache: /usr/bin/ccache
-- $<JOIN:$<1:$<TARGET_PROPERTY:compiler,no_strict_aliasing>>$<SEMICOLON>-Os$<SEMICOLON>$<TARGET_PROPERTY:compiler,imacros>$<SEMICOLON>/workspaces/note-zephyr/build/zephyr/include/generated/autoconf.h$<SEMICOLON>$<TARGET_PROPERTY:compiler,no_common>$<SEMICOLON>$<TARGET_PROPERTY:compiler,debug>$<SEMICOLON>$<TARGET_PROPERTY:compiler,diagnostic>$<SEMICOLON>-mcpu=cortex-m4$<SEMICOLON>-mthumb$<SEMICOLON>-mabi=aapcs$<SEMICOLON>-mfp16-format=ieee$<SEMICOLON>--sysroot=/usr/local/zephyr-sdk-0.16.3/arm-zephyr-eabi/arm-zephyr-eabi$<SEMICOLON>$<TARGET_PROPERTY:compiler,imacros>$<SEMICOLON>/home/blues/zephyrproject/zephyr/include/zephyr/toolchain/zephyr_stdint.h$<SEMICOLON>$<1:$<TARGET_PROPERTY:compiler,warning_base>>$<SEMICOLON>$<TARGET_PROPERTY:compiler,warning_extended>$<SEMICOLON>$<1:$<TARGET_PROPERTY:compiler,warning_error_implicit_int>>$<SEMICOLON>$<1:$<TARGET_PROPERTY:compiler,no_position_independent>>$<SEMICOLON>-fno-asynchronous-unwind-tables$<SEMICOLON>-fno-reorder-functions$<SEMICOLON>--param=min-pagesize=0$<SEMICOLON>-fno-defer-pop$<SEMICOLON>-fmacro-prefix-map=/workspaces/note-zephyr=CMAKE_SOURCE_DIR$<SEMICOLON>-fmacro-prefix-map=/home/blues/zephyrproject/zephyr=ZEPHYR_BASE$<SEMICOLON>-fmacro-prefix-map=/home/blues/zephyrproject=WEST_TOPDIR$<SEMICOLON>-ffunction-sections$<SEMICOLON>-fdata-sections$<SEMICOLON>$<1:$<TARGET_PROPERTY:compiler,cstd>c99>$<SEMICOLON>$<TARGET_PROPERTY:compiler,nostdinc>, >
-- 
-- $<JOIN:$<1:$<TARGET_PROPERTY:compiler,no_strict_aliasing>>$<SEMICOLON>-Os$<SEMICOLON>$<TARGET_PROPERTY:compiler,imacros>$<SEMICOLON>/workspaces/note-zephyr/build/zephyr/include/generated/autoconf.h$<SEMICOLON>$<TARGET_PROPERTY:compiler,no_common>$<SEMICOLON>$<TARGET_PROPERTY:compiler,debug>$<SEMICOLON>$<TARGET_PROPERTY:compiler,diagnostic>$<SEMICOLON>-mcpu=cortex-m4$<SEMICOLON>-mthumb$<SEMICOLON>-mabi=aapcs$<SEMICOLON>-mfp16-format=ieee$<SEMICOLON>--sysroot=/usr/local/zephyr-sdk-0.16.3/arm-zephyr-eabi/arm-zephyr-eabi$<SEMICOLON>$<TARGET_PROPERTY:compiler,imacros>$<SEMICOLON>/home/blues/zephyrproject/zephyr/include/zephyr/toolchain/zephyr_stdint.h$<SEMICOLON>$<1:$<TARGET_PROPERTY:compiler,warning_base>>$<SEMICOLON>$<TARGET_PROPERTY:compiler,warning_extended>$<SEMICOLON>$<1:$<TARGET_PROPERTY:compiler,warning_error_implicit_int>>$<SEMICOLON>$<1:$<TARGET_PROPERTY:compiler,no_position_independent>>$<SEMICOLON>-fno-asynchronous-unwind-tables$<SEMICOLON>-fno-reorder-functions$<SEMICOLON>--param=min-pagesize=0$<SEMICOLON>-fno-defer-pop$<SEMICOLON>-fmacro-prefix-map=/workspaces/note-zephyr=CMAKE_SOURCE_DIR$<SEMICOLON>-fmacro-prefix-map=/home/blues/zephyrproject/zephyr=ZEPHYR_BASE$<SEMICOLON>-fmacro-prefix-map=/home/blues/zephyrproject=WEST_TOPDIR$<SEMICOLON>-ffunction-sections$<SEMICOLON>-fdata-sections$<SEMICOLON>$<1:$<TARGET_PROPERTY:compiler,cstd>c99>$<SEMICOLON>$<TARGET_PROPERTY:compiler,nostdinc>$<SEMICOLON>-ggdb$<SEMICOLON>-Og$<SEMICOLON>-Wall$<SEMICOLON>-Wno-unused-parameter, >
-- 
-- Configuring done
-- Generating done
-- Build files have been written to: /workspaces/note-zephyr/build
-- west build: building application
[1/152] Preparing syscall dependency handling

[2/152] Generating include/generated/version.h
-- Zephyr version: 3.5.99 (/home/blues/zephyrproject/zephyr), build: zephyr-v3.5.0-3160-g29b19bcf8bc8
[30/152] Building C object CMakeFiles/app.dir/src/main.c.obj
/workspaces/note-zephyr/src/main.c:26:9: note: '#pragma message: PRODUCT_UID is not defined in this example. Please ensure your Notecard has a product identifier set before running this example or define it in code here. More details at https://bit.ly/product-uid'
   26 | #pragma message "PRODUCT_UID is not defined in this example. Please ensure your Notecard has a product identifier set before running this example or define it in code here. More details at https://bit.ly/product-uid"
      |         ^~~~~~~
[151/152] Linking C executable zephyr/zephyr.elf
Memory region         Used Size  Region Size  %age Used
           FLASH:       65388 B         2 MB      3.12%
             RAM:        7040 B       640 KB      1.07%
        IDT_LIST:          0 GB         2 KB      0.00%
[152/152] cd /workspaces/note-zephyr/build/zephyr && /u...lf-file=/workspaces/note-zephyr/build/zephyr/zephyr.elf

@tjvantoll As suggested, I deleted folders and per the SDK quickstart, did the “git clone GitHub - blues/note-zephyr: Zephyr RTOS Examples for Notecard and Swan applications --recursive”. I did the Docker Prune. BTW, should the SDK quickstart guide step one under Compiling (Open this folder in VS Code) explicitly state the folder to open is “note-zephyr”?
I see two errors when trying build to Zephyr: Build Application. One I notice in main.c that the #include <zephyr/drivers/gpio.h> and #inlcude <zephyr/kernel.h> links are marked as errors (missing). I am not sure how to fix the link to the correct cmake?? Below is the error message from trying to build (btw, I am using an intel i9 based Mac):

– west build: generating a build system
CMake Error: The current CMakeCache.txt directory /workspaces/note-zephyr/build/CMakeCache.txt is different than the directory /Users/jimmeckstroth/note-zephyr/build where CMakeCache.txt was created. This may result in binaries being created in the wrong place. If you are not sure, reedit the CMakeCache.txt
CMake Error: The source “/workspaces/note-zephyr/CMakeLists.txt” does not match the source “/Users/jimmeckstroth/note-zephyr/CMakeLists.txt” used to generate cache. Re-run cmake with a different source directory.
FATAL ERROR: command exited with status 1: /usr/bin/cmake -DWEST_PYTHON=/usr/bin/python3 -B/workspaces/note-zephyr/build -GNinja -DBOARD=swan_r5 -S/workspaces/note-zephyr

Also, specific VS Code Problems listed:
#include errors detected. Please update includePath.
cannot open source file “zephyr/drivers/gpio.h”
cannot open source file “zephyr/kernel.h”

QUESTION: Does following Zaks Zephyr SDK setup actually install all of zephyr components? Or, am I missing some aspect that is part of the Zephyr docs?

should the SDK quickstart guide step one under Compiling (Open this folder in VS Code) explicitly state the folder to open is “note-zephyr”?

Yes, good catch. I’ll update that.

QUESTION: Does following Zaks Zephyr SDK setup actually install all of zephyr components? Or, am I missing some aspect that is part of the Zephyr docs?

The Zephyr components are installed as part of the Docker Container. And actually, can you confirm you are running the build within the Container? The docs do mention this, but they probably should spell it out in a lot more detail. (I can update that too.)

TJ

@tjvantoll Just confirming VSCode lower left status is “Dev Container: Zephyr Development Environment”. I made sure Docker desktop was running and did the reopen in container per the docs.

Trying to start over again with installing the Zephyr SDK…
When I open folder “Note-zephyr” in VS Code, I get this error:
Configure failed. Would you like to attempt to configure with the CMake Debugger?

In CMakeLists.txt: line 11 is marked as error ( find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}).

I see there is no folder “zephyr-sdk-0.16.3” either.

I may have missed this error previously.

Hi Jim,

I got curious and gave this a try as well. I started with a pristine system, and it also worked for me.

I believe this line in the build log is our source of divergence.

-- ZEPHYR_TOOLCHAIN_VARIANT not set, trying to locate Zephyr SDK
-- Found host-tools: zephyr 0.16.3 (/usr/local/zephyr-sdk-0.16.3)
-- Found toolchain: zephyr 0.16.3 (/usr/local/zephyr-sdk-0.16.3)

It’s very odd that your container specifically references an older version of the SDK (/usr/local/zephyr-sdk-0.15.2), because the version is hard-coded into the Dockerfile. This means it’s not possible for 0.15.2 to exist in the image.

All this makes me think you have a stale image. If I were you, I would remove and rebuild the image.

NOTE: If you’re not that familiar with Docker, then you can install the official Microsoft Docker extension in VSCode, and use it to manage your images directly.

First delete any CONTAINERS with the name zephyr in them (typically vsc-note-zephyr*), then delete any IMAGES with the name zephyr.

Once you’ve purged all the old Zephyr images, then try going down the “Reopen in Container” path again.

Best,
Zak

@zfields Your guidance is much appreciated. I am new to Docker (and junior on VS Code) as you can tell. I do already have Microsoft Docker extension installed in my VSCode, but thought it was for creating containers. I used the VS Code Docker Command to Prune all, which only listed the one I just used.

I am wondering how to get to a “clean” system to achieve success…

I updated Docker Desktop to V4.26.1.

I deleted folder Note-zephyr.

From VS Code terminal I ran “git clone GitHub - blues/note-zephyr: Zephyr RTOS Examples for Notecard and Swan applications --recursive”

In VS Code I opened the folder Note-Zephyr

[edit: I repeated all the above and now get these output errors below before reopening in a DEV Container]

I reopened in DEV Container. Below is the VS Code Terminal Output (Ninja exist with code 1, & CMAKE ERRORS).

[proc] Executing command: cmake --version

[proc] Executing command: cmake -E capabilities

[variant] Loaded new set of variants

[proc] Executing command: /usr/bin/cmake --version

[proc] Executing command: /usr/bin/cmake -E capabilities

[proc] Executing command: /usr/bin/cmake -S/workspaces/note-zephyr -B/workspaces/note-zephyr/build -G Ninja

[proc] The command: /usr/bin/cmake -S/workspaces/note-zephyr -B/workspaces/note-zephyr/build -G Ninja exited with code: 1

[main] Configuring project: note-zephyr

[proc] Executing command: /usr/bin/cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -S/workspaces/note-zephyr -B/workspaces/note-zephyr/build -G Ninja

[cmake] CMake Error: The current CMakeCache.txt directory /workspaces/note-zephyr/build/CMakeCache.txt is different than the directory /Users/jimmeckstroth/note-zephyr/build where CMakeCache.txt was created. This may result in binaries being created in the wrong place. If you are not sure, reedit the CMakeCache.txt

[cmake] CMake Error: The source “/workspaces/note-zephyr/CMakeLists.txt” does not match the source “/Users/jimmeckstroth/note-zephyr/CMakeLists.txt” used to generate cache. Re-run cmake with a different source directory.

[cmake] Not searching for unused variables given on the command line.

[proc] The command: /usr/bin/cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -S/workspaces/note-zephyr -B/workspaces/note-zephyr/build -G Ninja exited with code: 1

cmake debug text:
Exception has occurred: FATAL_ERROR
CMake Error at CMakeLists.txt:11 (find_package):
Could not find a package configuration file provided by “Zephyr” with any
of the following names:

ZephyrConfig.cmake
zephyr-config.cmake

Add the installation prefix of “Zephyr” to CMAKE_PREFIX_PATH or set
“Zephyr_DIR” to a directory containing one of the above files. If “Zephyr”
provides a separate development package or SDK, be sure it has been
installed.

Hi Jim,

I know Docker can be a little confusing when you’re first getting started with it. The repository folder does not matter to Docker. To clean the Containers and Images, you must use the Docker engine.

I would strongly recommend installing the official Microsoft VSCode Extension for Docker to interact with the Docker engine (shown below).

First stop and delete (remove) any CONTAINERS with the name matching vsc-note-zephyr-*, then delete (remove) any IMAGES with the name matching vsc-note-zephyr-*.

Once you have done that, then you can “Reopen in Container”, and it will rebuild the image and should work.

Let us know once you’ve gotten those steps completed.

Best,
Zak

I think I properly used Docker within VS Code to remove the containers and images:

Dev Containers: Reopen in Container seems to have created the virtual workspace:

I still get the errors as shown:

Now VS Code Docker shows error also:

.

I suspect a simple/stupid error that I keep making, but I keep tripping up with similar results…

The #include errors can exist until the first build occurs and artifacts are created (that’s a VSCode thing).

The Docker extension will not work from inside the container, so “Failed to connect” is expected from inside the container.

Deleting your Zephyr containers and images with the extension should have been done before you entered the container. If so, then I think you may actually be good to go.

Try to build, and see what happens.

~Zak

@zfields Building within the Container results:

I am not seeing how the cmake file misalignment is occurring with the WEST build, if that is the root cause. Or how to make the CMakeCache.txt proper edits.

My next step was to reopen the folder locally. It shows an error in the CMakeLists.txt file in NOTE-ZEPYR folder.

if it matters, Cmake seems to not be properly configured within the Container??

@zfields Not to get the troubleshooting off on a tangent, but I tried to setup the Blues Zephyr SDK on my iMac’ VS Code as well over the weekend (also an Intel i9 machine), and got the same results as with my MacBook Pro. Whatever I am doing wrong is at least consistent??!

To be clear, when using the DOCKER extension in VS Code, I do not have DOCKER desktop app open.

@tjvantoll @zfields Error resolved! By deleting the BUILD folder, the application now builds fine and I was able to load the firmware into the SWAN!

I’ll have to make a note of this one because I would’ve never thought to try that :sweat_smile: Glad you got it working!

1 Like

@tjvantoll very minor documentation typo to bring to your attention. In the “Getting Set Up” section of the “Zephyr SDK” portion of the “Tools & SDKs” documentation, the COPY link for the Note on “if you failed to properly update devcontainer.json…” copies the entire text window instead of just the command.

Thanks @JimM :+1: Made the fix and it’ll go out with our next doc release.

TJ

1 Like