You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Sources/EmbeddedSwift/Documentation.docc/SDKSupport/IntegrateWithZephyr.md
+39-11Lines changed: 39 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -6,6 +6,20 @@ For an introduction and motivation into Embedded Swift, please see "[A Vision fo
6
6
7
7
The following document outlines how to setup a Swift to Zephyr project for an emulated ARM Cortex M0, explaining a few key concepts along the way. For a complete working example on real hardware, however, refer to the [nrfx-blink-sdk](../../../../nrfx-blink-sdk/) project that is compatible with nRF or other boards.
8
8
9
+
## Zephyr Target Architecture Compatibility
10
+
11
+
Zephyr [supports quite a few target architectures](https://docs.zephyrproject.org/latest/introduction/index.html), but not all are supported by Embedded Swift. Please refer to the following table for an overview of Zephyr-supported architectures that are supported by Swift, along with the correct target triple to use:
Before setting up a Swift project that works with Zephyr, you need to setup dependencies and a Zephyr workspace as per the [Getting Started Guide](https://docs.zephyrproject.org/latest/develop/getting_started/index.html). Regardless of your platform (macOS or Linux), ensure that you can build the blinky example without errors before starting with Swift integration:
Next, set the compiler target to the arch you are building for. For this example we use `armv6m-none-none-eabi` which is compatible with the [Cortex-M0](https://docs.zephyrproject.org/latest/boards/qemu/cortex_m0/doc/index.html) which we will compile for in a later step. The `mfloat-abi=soft`, `-fshort-enums`, and `-fno-pic` flags are specifically for 32-bit arm architectures, so for other architectures they can be removed. However, the other flags and required for building Swift for Embedded and against Zephyr:
130
+
Next, set the compiler target to the arch you are building for. For this example we use `armv6m-none-none-eabi` which is compatible with the [Cortex-M0](https://docs.zephyrproject.org/latest/boards/qemu/cortex_m0/doc/index.html) which we will compile for in a later step. If you are targeting a different architecture, see the [Zephyr Target Architecture Compatibility](#zephyr-target-architecture-compatibility) to see which target triple to use.
117
131
118
132
```cmake
119
133
# Use the armv6m-none-none-eabi target triple for Swift
The following block will automatically grab Zephyr compilation flags (such as `-D__ZEPHYR__=1` and `-DKERNEL`) and set them as Swift compiler definitions. This is required to successfully build Swift code that works with Zephyr:
156
+
There are quite a few other Zephyr flags that must also be imported in order to get Zephyr include paths and flags such `-mcpu`, `-mfloat-abi`, and so on:
157
+
158
+
```cmake
159
+
# Import TOOLCHAIN_C_FLAGS from Zephyr as -Xcc flags
160
+
foreach(flag ${TOOLCHAIN_C_FLAGS})
161
+
# Skip flags that are not known to swiftc
162
+
string(FIND "${flag}" "-imacro" is_imacro)
163
+
string(FIND "${flag}" "-mfp16-format" is_mfp16)
164
+
if(NOT is_imacro EQUAL -1 OR NOT is_mfp16 EQUAL -1)
Next, add the following block to automatically grab Zephyr compilation flags (such as `-D__ZEPHYR__=1` and `-DKERNEL`) and set them as Swift compiler definitions. This is required to successfully build Swift code that works with Zephyr:
145
173
146
174
```cmake
147
175
# Add definitions from Zephyr to -Xcc flags
@@ -287,7 +315,7 @@ Loop
287
315
Loop
288
316
```
289
317
290
-
This setup may also desirable since `west flash` is also available and can be used instead of invoking the flashing tools manually.
318
+
This setup may also be desirable since `west flash` is also available and can be used instead of invoking the flashing tools manually.
291
319
292
320
If compiling a firmware for a real/physical board such as the `nrf52840dk/nrf52840`, `west flash` will work if the SEGGER J-Link host tools are installed. As an example, with the [nrfx-blink-sdk](../../../../nrfx-blink-sdk/) project:
0 commit comments