Skip to content

Commit fd1a9e0

Browse files
authored
update practical-zephyr series to recent versions of Zephyr and the nRF Connect SDK (memfault#620)
Due to deprecation of the Nordic toolchain manager I'm trying to update the series to Zephyr 4.3.0 and the nRF Connect SDK 3.2.1. I didn't check every single file that I quoted, though I hope everything is aligned. With this there are two pull requests in the accompanying repositories: - lmapii/practical-zephyr#8 - lmapii/practical-zephyr-manifest-repository#5 If you give me a heads-up then I can merge those before merging the PR to Interrupt.
1 parent 70986d4 commit fd1a9e0

6 files changed

Lines changed: 225 additions & 171 deletions

_posts/2024-01-10-practical_zephyr_basics.md

Lines changed: 75 additions & 37 deletions
Large diffs are not rendered by default.

_posts/2024-01-24-practical_zephyr_kconfig.md

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ The simplest way to log text in Zephyr is the `printk` function. `printk` can ta
4646
#include <zephyr/kernel.h>
4747
#define SLEEP_TIME_MS 100U
4848

49-
void main(void)
49+
int main(void)
5050
{
5151
printk("Message in a bottle.\n");
5252
while (1)
@@ -67,7 +67,7 @@ As mentioned in the previous article, we're using a development kit from [Nordic
6767
The connection settings for the UART interface are configured using [devicetree](https://docs.zephyrproject.org/latest/build/dts/index.html) - which we'll explore in a later article. Since these default settings are all we need for now, let's focus on Kconfig. We build and flash the project as follows:
6868
6969
```bash
70-
$ west build --board nrf52840dk_nrf52840 --build-dir ../build
70+
$ west build --no-sysbuild --board nrf52840dk/nrf52840 --build-dir ../build
7171
$ west flash --build-dir ../build
7272
```
7373

@@ -157,7 +157,7 @@ In the header file `zephyr/lib/os/printk.h` we can see that `printk` is replaced
157157
With `printk` disabled in our application configuration file, let's try to rerun our application to verify that the output is indeed disabled:
158158

159159
```bash
160-
$ west build --board nrf52840dk_nrf52840 --build-dir ../build --pristine
160+
$ west build --no-sysbuild --board nrf52840dk/nrf52840 --build-dir ../build --pristine
161161
$ west flash --build-dir ../build
162162
```
163163

@@ -202,7 +202,7 @@ Zephyr contains _hundreds_ of so-called Kconfig _fragments_. It is therefore alm
202202
For the `build` command, _West_ has some builtin _targets_, two of which are used for _Kconfig_:
203203

204204
```bash
205-
$ west build --build-dir ../build -t usage
205+
$ west build --no-sysbuild --build-dir ../build -t usage
206206
-- west build: running target usage
207207
...
208208
Kconfig targets:
@@ -276,7 +276,7 @@ The downside of saving the configuration to `zephyr/.config` in the build direct
276276
The people at [Golioth](https://golioth.io/) published a [short article](https://blog.golioth.io/zephyr-quick-tip-show-what-menuconfig-changed-and-make-changes-persistent/) that shows how to leverage the `diff` command to find out which configuration options have changed when using the normal _Save_ operation: Before writing the changes to the `zephyr/.config` file, Kconfig stores the old configuration in `build/zephyr/.config.old`. Thus, all changes that you make between a _Save_ operation are reflected by the differences between `zephyr/.config` and `build/zephyr/.config.old`:
277277

278278
```bash
279-
$ west build --board nrf52840dk_nrf52840 -d ../build --pristine
279+
$ west build --no-sysbuild --board nrf52840dk/nrf52840 -d ../build --pristine
280280
$ west build -d ../build -t menuconfig
281281
# Within menuconfig:
282282
# - Disable BOOT_BANNER and PRINTK.
@@ -306,7 +306,7 @@ Both `menuconfig` and `guiconfig` have the _Save minimal config_ option. As the
306306
Let's try this out with our settings for the `BOOT_BANNER` and `PRINTK` symbols.
307307

308308
```bash
309-
$ west build --board nrf52840dk_nrf52840 -d ../build --pristine
309+
$ west build --no-sysbuild --board nrf52840dk/nrf52840 -d ../build --pristine
310310
$ west build -d ../build -t menuconfig
311311
# Within menuconfig:
312312
# - Disable BOOT_BANNER and PRINTK.
@@ -331,7 +331,7 @@ CONFIG_UART_CONSOLE=y
331331
CONFIG_EARLY_CONSOLE=y
332332
```
333333

334-
As you can see, this minimal configuration contains a lot more options than we changed within `menuconfig`. Some of these options come from the selected board, in my case `zephyr/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840_defconfig`, but are still listed since they do not use default values. However, the two changes to `PRINTK` and `BOOT_BANNER` are still visible. We can just take those options and write them to our application configuration file:
334+
As you can see, this minimal configuration contains a lot more options than we changed within `menuconfig`. Some of these options come from the selected board, in my case `zephyr/boards/nordic/nrf52840dk/nrf52840dk_nrf52840_defconfig`, but are still listed since they do not use default values. However, the two changes to `PRINTK` and `BOOT_BANNER` are still visible. We can just take those options and write them to our application configuration file:
335335

336336
```bash
337337
$ cat prj.conf
@@ -359,9 +359,9 @@ At the time of writing and for this repository, the following configuration opti
359359

360360
```json
361361
{
362-
"nrf-connect.toolchain.path": "${nrf-connect.toolchain:2.4.0}",
363-
"nrf-connect.topdir": "${nrf-connect.sdk:2.4.0}",
364-
"kconfig.zephyr.base": "${nrf-connect.sdk:2.4.0}",
362+
"nrf-connect.toolchain.path": "${nrf-connect.toolchain:3.2.1}",
363+
"nrf-connect.topdir": "${nrf-connect.sdk:3.2.1}",
364+
"kconfig.zephyr.base": "${nrf-connect.sdk:3.2.1}",
365365
"nrf-connect.applications": ["${workspaceFolder}/path/to/app"]
366366
}
367367
```
@@ -425,14 +425,14 @@ We can now instruct _West_ to use this `prj_release.conf` _instead_ of our `prj.
425425

426426
```bash
427427
$ rm -rf ../build
428-
$ west build --board nrf52840dk_nrf52840 -d ../build -- -DCONF_FILE=prj_release.conf
428+
$ west build --no-sysbuild --board nrf52840dk/nrf52840 -d ../build -- -DCONF_FILE=prj_release.conf
429429
```
430430

431431
If you scroll through the output of the `west build` command, you'll notice that _Kconfig_ merged `prj_release.conf` into our final configuration:
432432

433433
```
434-
Parsing /opt/nordic/ncs/v2.4.0/zephyr/Kconfig
435-
Loaded configuration '/opt/nordic/ncs/v2.4.0/zephyr/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840_defconfig'
434+
Parsing /opt/nordic/ncs/v3.2.1/zephyr/Kconfig
435+
Loaded configuration '/opt/nordic/ncs/v3.2.1/zephyr/boards/nordic/nrf52840dk/nrf52840dk_nrf52840_defconfig'
436436
Merged configuration '/path/to/01_kconfig/prj_release.conf'
437437
Configuration saved to '/path/to/zephyr_practical/build/zephyr/.config'
438438
```
@@ -447,7 +447,7 @@ Aside from the application configuration file [prj.conf](https://github.com/lmap
447447

448448
E.g., throughout this guide, we're using the nRF52840 development kit, which has the board name `nrf52840dk_nrf52840`. Thus, the file `boards/nrf52840dk_nrf52840.conf` is automatically merged into the `Kconfig` configuration during the build, if present.
449449

450-
Let's try this by disabling UART as console output using a new fragment `boards/nrf52840dk_nrf52840.conf`. For the nRF52840 development kit, this symbol is enabled by default. You can go ahead and verify this by checking the default configuration `zephyr/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840_defconfig` - or take my word for it:
450+
Let's try this by disabling UART as console output using a new fragment `boards/nrf52840dk_nrf52840.conf`. For the nRF52840 development kit, this symbol is enabled by default. You can go ahead and verify this by checking the default configuration `zephyr/boards/nordic/nrf52840dk/nrf52840dk_nrf52840_defconfig` - or take my word for it:
451451

452452
```bash
453453
tree --charset=utf-8 --dirsfirst
@@ -470,19 +470,19 @@ CONFIG_UART_CONSOLE=n
470470
Then, we perform a _pristine_ build of the project. Notice that a `--pristine` build is required at this point because otherwise, the build system does not pick up our newly added `.conf` file. This is one of the very few occasions where a pristine build is actually required.
471471

472472
```bash
473-
$ west build --board nrf52840dk_nrf52840 -d ../build --pristine
473+
$ west build --no-sysbuild --board nrf52840dk/nrf52840 -d ../build --pristine
474474
```
475475

476476
In the output of `west build` shown below you can see that the new file `boards/nrf52840dk_nrf52840.conf` is indeed merged into the `Kconfig` configuration. You can also see a warning that the Zephyr library `drivers__console` is excluded from the build since it now has no `SOURCES`:
477477

478478
```
479-
Parsing /opt/nordic/ncs/v2.4.0/zephyr/Kconfig
480-
Loaded configuration '/opt/nordic/ncs/v2.4.0/zephyr/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840_defconfig'
479+
Parsing /opt/nordic/ncs/v3.2.1/zephyr/Kconfig
480+
Loaded configuration '/opt/nordic/ncs/v3.2.1/zephyr/boards/nordic/nrf52840dk/nrf52840dk_nrf52840_defconfig'
481481
Merged configuration '/path/to/01_kconfig/prj.conf'
482482
Merged configuration '/path/to/01_kconfig/boards/nrf52840dk_nrf52840.conf'
483483
Configuration saved to '/path/to/build/zephyr/.config'
484484
...
485-
CMake Warning at /opt/nordic/ncs/v2.4.0/zephyr/CMakeLists.txt:838 (message):
485+
CMake Warning at /opt/nordic/ncs/v3.2.1/zephyr/CMakeLists.txt:838 (message):
486486
No SOURCES given to Zephyr library: drivers__console
487487
Excluding target from build.
488488
```
@@ -495,12 +495,12 @@ How are board fragments used by our previously created `release` build type? Let
495495

496496
```bash
497497
$ rm -rf ../build
498-
$ west build --board nrf52840dk_nrf52840 -d ../build -- -DCONF_FILE=prj_release.conf
498+
$ west build --no-sysbuild --board nrf52840dk/nrf52840 -d ../build -- -DCONF_FILE=prj_release.conf
499499
```
500500

501501
```
502-
Parsing /opt/nordic/ncs/v2.4.0/zephyr/Kconfig
503-
Loaded configuration '/opt/nordic/ncs/v2.4.0/zephyr/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840_defconfig'
502+
Parsing /opt/nordic/ncs/v3.2.1/zephyr/Kconfig
503+
Loaded configuration '/opt/nordic/ncs/v3.2.1/zephyr/boards/nordic/nrf52840dk/nrf52840dk_nrf52840_defconfig'
504504
Merged configuration '/path/to/01_kconfig/prj_release.conf'
505505
Configuration saved to '/path/to/build/zephyr/.config'
506506
```
@@ -533,12 +533,12 @@ Now, when we rebuild the project, we see that our board fragment is merged into
533533

534534
```bash
535535
$ rm -rf ../build
536-
$ west build --board nrf52840dk_nrf52840 -d ../build -- -DCONF_FILE=prj_release.conf
536+
$ west build --no-sysbuild --board nrf52840dk/nrf52840 -d ../build -- -DCONF_FILE=prj_release.conf
537537
```
538538

539539
```
540-
Parsing /opt/nordic/ncs/v2.4.0/zephyr/Kconfig
541-
Loaded configuration '/opt/nordic/ncs/v2.4.0/zephyr/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840_defconfig'
540+
Parsing /opt/nordic/ncs/v3.2.1/zephyr/Kconfig
541+
Loaded configuration '/opt/nordic/ncs/v3.2.1/zephyr/boards/nordic/nrf52840dk/nrf52840dk_nrf52840_defconfig'
542542
Merged configuration '/path/to/01_kconfig/prj_release.conf'
543543
Merged configuration '/path/to/01_kconfig/boards/nrf52840dk_nrf52840_release.conf'
544544
Configuration saved to '/path/to/build/zephyr/.config'
@@ -579,13 +579,13 @@ We can now pass the two extra configuration fragments to the build system using
579579

580580
```bash
581581
$ rm -rf ../build
582-
$ west build --board nrf52840dk_nrf52840 -d ../build -- \
582+
$ west build --no-sysbuild --board nrf52840dk/nrf52840 -d ../build -- \
583583
-DEXTRA_CONF_FILE="extra0.conf;extra1.conf"
584584
```
585585

586586
```
587-
Parsing /opt/nordic/ncs/v2.4.0/zephyr/Kconfig
588-
Loaded configuration '/opt/nordic/ncs/v2.4.0/zephyr/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840_defconfig'
587+
Parsing /opt/nordic/ncs/v3.2.1/zephyr/Kconfig
588+
Loaded configuration '/opt/nordic/ncs/v3.2.1/zephyr/boards/nordic/nrf52840dk/nrf52840dk_nrf52840_defconfig'
589589
Merged configuration '/path/to/01_kconfig/prj.conf'
590590
Merged configuration '/path/to/01_kconfig/boards/nrf52840dk_nrf52840.conf'
591591
Merged configuration '/path/to/01_kconfig/extra0.conf'
@@ -597,14 +597,14 @@ The fragments specified using the `EXTRA_CONF_FILE` variable are merged into the
597597

598598
```bash
599599
$ rm -rf ../build
600-
$ west build --board nrf52840dk_nrf52840 -d ../build -- \
600+
$ west build --no-sysbuild --board nrf52840dk/nrf52840 -d ../build -- \
601601
-DCONF_FILE="prj_release.conf" \
602602
-DEXTRA_CONF_FILE="extra1.conf;extra0.conf"
603603
```
604604

605605
```
606-
Parsing /opt/nordic/ncs/v2.4.0/zephyr/Kconfig
607-
Loaded configuration '/opt/nordic/ncs/v2.4.0/zephyr/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840_defconfig'
606+
Parsing /opt/nordic/ncs/v3.2.1/zephyr/Kconfig
607+
Loaded configuration '/opt/nordic/ncs/v3.2.1/zephyr/boards/nordic/nrf52840dk/nrf52840dk_nrf52840_defconfig'
608608
Merged configuration '/path/to/01_kconfig/prj_release.conf'
609609
Merged configuration '/path/to/01_kconfig/boards/nrf52840dk_nrf52840_release.conf'
610610
Merged configuration '/path/to/01_kconfig/extra1.conf'
@@ -620,13 +620,13 @@ We can use this tool to check our normal and _release_ configurations:
620620

621621
```bash
622622
$ # test normal build
623-
$ west build --board nrf52840dk_nrf52840 \
623+
$ west build --no-sysbuild --board nrf52840dk/nrf52840 \
624624
-d ../build \
625625
--pristine \
626626
-t hardenconfig
627627

628628
$ # test release build
629-
$ west build --board nrf52840dk_nrf52840 \
629+
$ west build --no-sysbuild --board nrf52840dk/nrf52840 \
630630
-d ../build \
631631
--pristine \
632632
-t hardenconfig \
@@ -637,7 +637,7 @@ For the normal build using `prj.conf`, the hardening tool displays a table of al
637637

638638
```
639639
-- west build: running target hardenconfig
640-
[0/1] cd /path/to/zephyr/kconfig/hardenconfig.py /opt/nordic/ncs/v2.4.0/zephyr/Kconfig
640+
[0/1] cd /path/to/zephyr/kconfig/hardenconfig.py /opt/nordic/ncs/v3.2.1/zephyr/Kconfig
641641
name | current | recommended || check result
642642
==============================================================================
643643
CONFIG_OVERRIDE_FRAME_POINTER_DEFAULT | n | y || FAIL
@@ -707,12 +707,12 @@ By sourcing the `Kconfig.zephr` file, we're loading all _Kconfig_ menus and symb
707707
Let's rebuild our application without configuring `USR_FUN` and have a look at the build output. A `--pristine` build is required to pick up the new `Kconfig` file:
708708

709709
```bash
710-
$ west build --board nrf52840dk_nrf52840 -d ../build --pristine
710+
$ west build --no-sysbuild --board nrf52840dk/nrf52840 -d ../build --pristine
711711
```
712712

713713
```
714714
Parsing /path/to/01_kconfig/Kconfig
715-
Loaded configuration '/opt/nordic/ncs/v2.4.0/zephyr/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840_defconfig'
715+
Loaded configuration '/opt/nordic/ncs/v3.2.1/zephyr/boards/nordic/nrf52840dk/nrf52840dk_nrf52840_defconfig'
716716
Merged configuration '/path/to/01_kconfig/prj.conf'
717717
Merged configuration '/path/to/01_kconfig/boards/nrf52840dk_nrf52840.conf'
718718
Configuration saved to '/path/to/build/zephyr/.config'
@@ -721,7 +721,7 @@ Kconfig
721721

722722
Have a good look at the very first line of the _Kconfig_-related output:
723723
* In our previous builds, this line indicated the use of Zephyr's default `Kconfig` file as follows:
724-
`Parsing /opt/nordic/ncs/v2.4.0/zephyr/Kconfig`,
724+
`Parsing /opt/nordic/ncs/v3.2.1/zephyr/Kconfig`,
725725
* Whereas now it uses our newly created `Kconfig` file:
726726
`Parsing /path/to/01_kconfig/Kconfig`.
727727

@@ -813,7 +813,7 @@ Let's first extend our `main.c` file to use `usr_fun` regardless of any configur
813813

814814
#define SLEEP_TIME_MS 100U
815815

816-
void main(void)
816+
int main(void)
817817
{
818818
printk("Message in a bottle.\n");
819819
usr_fun();
@@ -828,7 +828,7 @@ void main(void)
828828
Unsurprisingly, building this application fails since `usr_fun.c` is not included in the build:
829829
830830
```bash
831-
$ west build --board nrf52840dk_nrf52840 -d ../build --pristine
831+
$ west build --no-sysbuild --board nrf52840dk/nrf52840 -d ../build --pristine
832832
```
833833

834834
```
@@ -860,7 +860,7 @@ This, however, defeats the purpose of having a configurable build: The build wou
860860

861861
#define SLEEP_TIME_MS 100U
862862

863-
void main(void)
863+
int main(void)
864864
{
865865
printk("Message in a bottle.\n");
866866

0 commit comments

Comments
 (0)