Here’s a quick update: my first success with Zephyr: I figured you’d find this useful, and I may do my own writeup about the experience. I did everything with the command line and skipped using any plugins.
After hours of scouring through and tinkering with Zephyr to learn how to build things, I tried two things
(1) I tried building Zephyr through 3.5.99 and downloading the example from Zephyr project: It did not work right out of the box.
(.venv) jkarch@Joshuas-MacBook-Pro zephyrproject % git clone https://github.com/zephyrproject-rtos/example-application my-app
Cloning into 'my-app'...
remote: Enumerating objects: 397, done.
remote: Counting objects: 100% (233/233), done.
remote: Compressing objects: 100% (122/122), done.
remote: Total 397 (delta 140), reused 111 (delta 111), pack-reused 164
Receiving objects: 100% (397/397), 59.92 KiB | 11.98 MiB/s, done.
Resolving deltas: 100% (165/165), done.
(.venv) jkarch@Joshuas-MacBook-Pro zephyrproject % cd my-app
(.venv) jkarch@Joshuas-MacBook-Pro my-app % unset ZEPHYR_BASE
(.venv) jkarch@Joshuas-MacBook-Pro my-app % source ~/zephyrproject/zephyr/zephyr-env.sh
(.venv) jkarch@Joshuas-MacBook-Pro my-app % west build -b custom_plank app
...
...
...
No board named 'custom_plank' found.
The error found was that the board was missing, it could not find custom_plank and told me to select another board.
So I tried again: (I run rm -rf build) in between each run to get rid of the caching of CMake.
west build -b custom_plank app -DBOARD_ROOT=$PWD
I received the following error:
/Users/jkarch/zephyrproject/my-app/app/src/main.c:47: undefined reference to
__device_dts_ord_4′`
To me, this means that 3.5.99 isn’t properly using the libraries to work with the ncs HW. I still don’t know yet how to debug this, but I decided to skip this error and continue, using NCS’ specific build.
I then decided to download the ncs-example-application and followed the steps in README.md and run the setup scripts initialized in:
https://github.com/nrfconnect/ncs-example-application/tree/main
source ~/my-workspace/zephyr/zephyr-env.sh
This is the NCS zephyr environment.
The app obtained by cloning the stock example-application repository built successfully:
-- Zephyr version: 3.4.99 (/Users/jkarch/my-workspace/zephyr), build: v3.4.99-ncs1-105-gf8dc8ac55203
[138/138] Linking C executable zephyr/zephyr.elf
Memory region Used Size Region Size %age Used
FLASH: 20928 B 1 MB 2.00%
RAM: 6348 B 256 KB 2.42%
IDT_LIST: 0 GB 2 KB 0.00%
Great, progress. Next, I decided to try to build this app for the nrf52dk_nrf52832. I copied an nrf42dk_nrf52832 overlay file over containing the “examplesensor0” device tree entry.
`/ {
examplesensor0: examplesensor_0 {
compatible = "zephyr,examplesensor";
input-gpios = <&gpio0 11 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
};
};
`
(.venv) jkarch@Joshuas-MacBook-Pro my-app % rm -rf build
(.venv) jkarch@Joshuas-MacBook-Pro my-app % west build -b nrf52dk_nrf52832 app -- -DDTC_OVERLAY_FILE=$(PWD)/boards/nrf52dk_nrf52832.overlay
And mission success! So basically I learned a few things:
(1) It seems that the example application is having linker errors with 3.5.99
(2) you need to point either the current BOARD_ROOT or the custom DTC_OVERLAY_FILE to make use of the board. That file is set in the boards directory at the same level as the app.
So I finally see a structure on how to create an app. Next step is to try this with my custom driver. Thanks Jared for the initial pointers and getting started! I’ll post an update when I get that working… But it is starting to become clear to me that the automation tools are abstracting away the commands, making it hard to compile custom projects as easily. I’m sure if I now open this up with VSCode, I might be able to make this work as well, but at least I understand the structure a bit better.