Skip to content

Improve nrfx-blink-sdk example to automatically get Zephyr defines and show using nrfutil instead of nrfjprog #130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions nrfx-blink-sdk/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,24 @@ add_compile_options(
# Disable PIC
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xcc -fno-pic>"

# Assortment of defines for Zephyr
"$<$<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>"

# Add Libc include paths
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xcc -I -Xcc ${ZEPHYR_SDK_INSTALL_DIR}/arm-zephyr-eabi/picolibc/include>"
)

# Add definitions from Zephyr to -Xcc flags
get_target_property(ZEPHYR_DEFINES zephyr_interface INTERFACE_COMPILE_DEFINITIONS)
if(ZEPHYR_DEFINES)
foreach(flag ${ZEPHYR_DEFINES})
# Ignore expressions like "$<SOMETHING>"
string(FIND "${flag}" "$<" start_of_expression)
if(NOT start_of_expression EQUAL -1)
continue()
endif()

add_compile_options("$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xcc -D${flag}>")
endforeach()
endif()

target_sources(app PRIVATE Stubs.c)

# The Swift code providing "main" needs to be in an OBJECT library (instead of STATIC library) to make sure it actually gets linker.
Expand Down
12 changes: 7 additions & 5 deletions nrfx-blink-sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ This example demonstrates how to integrate with the Zephyr SDK via CMake and how
- The West build system.
- A Python virtualenv for Zephyr.
- Zephyr SDK/toolchain.
- 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).
- 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).

- 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:
- Try building and running the "simple/blink" example from Zephyr written in C.
Expand All @@ -20,7 +20,8 @@ This example demonstrates how to integrate with the Zephyr SDK via CMake and how

- Make sure you have a recent nightly Swift toolchain that has Embedded Swift support.
- Build the program in the Zephyr virtualenv, specify the target board type via the `-DBOARD=...` CMake setting:
``` console

```console
$ cd nrfx-blink-sdk
$ source ~/zephyrproject/.venv/bin/activate
(.venv) cmake -B build -G Ninja -DBOARD=nrf52840dk/nrf52840 -DUSE_CCACHE=0 .
Expand All @@ -30,11 +31,12 @@ $ source ~/zephyrproject/.venv/bin/activate
## Running

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

```console
(.venv) nrfjprog --recover --program build/zephyr/zephyr.hex --verify
(.venv) nrfjprog --run
(.venv) nrfutil device program --firmware build/zephyr/zephyr.hex
(.venv) nrfutil device fw-verify --firmware build/zephyr/zephyr.hex
(.venv) nrfutil device reset
```

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