Skip to content

Commit 7e1f25f

Browse files
Use dynamic Zephyr defines and switch to nrfutil tooling (#130)
Removes hardcoded Zephyr -D flags in favor of defines from the zephyr_interface target. Replaces use of nrfjprog with nrfutil in both documentation and example usage.
1 parent 9b5ee6c commit 7e1f25f

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

nrfx-blink-sdk/CMakeLists.txt

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,24 @@ add_compile_options(
2828
# Disable PIC
2929
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xcc -fno-pic>"
3030

31-
# Assortment of defines for Zephyr
32-
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xcc -DKERNEL -Xcc -DNRF52840_XXAA -Xcc -DPICOLIBC_INTEGER_PRINTF_SCANF -Xcc -D_FORTIFY_SOURCE=1 -Xcc -D_POSIX_C_SOURCE=200809 -Xcc -D__LINUX_ERRNO_EXTENSIONS__ -Xcc -D__PROGRAM_START -Xcc -D__ZEPHYR__=1>"
33-
3431
# Add Libc include paths
3532
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xcc -I -Xcc ${ZEPHYR_SDK_INSTALL_DIR}/arm-zephyr-eabi/picolibc/include>"
3633
)
3734

35+
# Add definitions from Zephyr to -Xcc flags
36+
get_target_property(ZEPHYR_DEFINES zephyr_interface INTERFACE_COMPILE_DEFINITIONS)
37+
if(ZEPHYR_DEFINES)
38+
foreach(flag ${ZEPHYR_DEFINES})
39+
# Ignore expressions like "$<SOMETHING>"
40+
string(FIND "${flag}" "$<" start_of_expression)
41+
if(NOT start_of_expression EQUAL -1)
42+
continue()
43+
endif()
44+
45+
add_compile_options("$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xcc -D${flag}>")
46+
endforeach()
47+
endif()
48+
3849
target_sources(app PRIVATE Stubs.c)
3950

4051
# The Swift code providing "main" needs to be in an OBJECT library (instead of STATIC library) to make sure it actually gets linker.

nrfx-blink-sdk/README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ This example demonstrates how to integrate with the Zephyr SDK via CMake and how
1111
- The West build system.
1212
- A Python virtualenv for Zephyr.
1313
- Zephyr SDK/toolchain.
14-
- Host flash/debug tools for the board you're using. For example, for the nRF52840-DK board you'll need the [nRF Command Line Tools](https://www.nordicsemi.com/Products/Development-tools/nrf-command-line-tools).
14+
- Host flash/debug tools for the board you're using. For example, for the nRF52840-DK board you'll need the [nRF Util](https://www.nordicsemi.com/Products/Development-tools/nRF-Util).
1515

1616
- Before trying to use Swift with the Zephyr SDK, make sure your environment works and can build the provided C/C++ sample projects, in particular:
1717
- Try building and running the "simple/blink" example from Zephyr written in C.
@@ -20,7 +20,8 @@ This example demonstrates how to integrate with the Zephyr SDK via CMake and how
2020

2121
- Make sure you have a recent nightly Swift toolchain that has Embedded Swift support.
2222
- Build the program in the Zephyr virtualenv, specify the target board type via the `-DBOARD=...` CMake setting:
23-
``` console
23+
24+
```console
2425
$ cd nrfx-blink-sdk
2526
$ source ~/zephyrproject/.venv/bin/activate
2627
(.venv) cmake -B build -G Ninja -DBOARD=nrf52840dk/nrf52840 -DUSE_CCACHE=0 .
@@ -30,11 +31,12 @@ $ source ~/zephyrproject/.venv/bin/activate
3031
## Running
3132

3233
- Connect the nRF52840-DK board over a USB cable to your Mac using the J-Link connector on the board.
33-
- Use `nrfjprog` to upload the firmware and to run it:
34+
- Use the `nrfutil device` command to upload the firmware and to run it:
3435

3536
```console
36-
(.venv) nrfjprog --recover --program build/zephyr/zephyr.hex --verify
37-
(.venv) nrfjprog --run
37+
(.venv) nrfutil device program --firmware build/zephyr/zephyr.hex
38+
(.venv) nrfutil device fw-verify --firmware build/zephyr/zephyr.hex
39+
(.venv) nrfutil device reset
3840
```
3941

4042
- The green LED should now be blinking in a pattern.

0 commit comments

Comments
 (0)