Skip to content

Commit d058103

Browse files
committed
Documentation
1 parent 583b652 commit d058103

File tree

3 files changed

+25
-11
lines changed

3 files changed

+25
-11
lines changed

CMakeLists.txt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,27 @@ endif ()
3535
include(pico_sdk_import.cmake)
3636

3737
# Configure Swift. This must happen before `project()`. I don't know why.
38+
# Use nightly Swift compiler, configured for Embedded Swift.
39+
# Find path to swiftc and store it in swiftc_Path
3840
execute_process(
3941
COMMAND xcrun --toolchain "${Swift_Toolchain}" --find swiftc
4042
OUTPUT_VARIABLE swiftc_Path
4143
OUTPUT_STRIP_TRAILING_WHITESPACE
4244
)
43-
# Use nightly Swift compiler, configured for Embedded Swift.
4445
set(CMAKE_Swift_COMPILER
4546
"${swiftc_Path}"
4647
)
4748
set(CMAKE_Swift_FLAGS
48-
# - WMO is always required for Embedded Swift.
49+
# Whole-module optimization is always required for Embedded Swift.
4950
"-enable-experimental-feature Embedded -wmo -target armv6m-none-none-eabi"
5051
)
51-
# Disable CMAKE Swift compiler check. The compiler check always fails for
52-
# Embedded Swift because it tries to compile a Swift program that includes
53-
# `print()`, which isn't available in Embedded Swift.
52+
# Disable CMake’s automatic Swift compiler check. The compiler check always
53+
# fails for Embedded Swift because it tries to compile a Swift program that
54+
# includes `print()`, which isn't available in Embedded Swift.
5455
set(CMAKE_Swift_COMPILER_FORCED TRUE)
5556

57+
# === Begin project configuration
58+
5659
project(PicoLinksSwift LANGUAGES C CXX Swift)
5760

5861
# Initialize the Raspberry Pi Pico SDK

README.md

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,42 @@ A proof of concept for executing Embedded Swift code on the [Raspberry Pi Pico](
1212
### Software
1313

1414
- Host OS: macOS 13.x or 14.x
15+
16+
Tested on macOS 13.6.2. It’ll probably work on Linux with minimal modifications to tell CMake how to find the Swift toolchain, but I haven’t tested this.
1517

16-
- A recent nightly Swift toolchain from [swift.org](https://www.swift.org/download/). Tested with the December 7, 2023 toolchain.
18+
- A recent nightly Swift toolchain from [swift.org](https://www.swift.org/download/). Tested with the Xcode toolchain from December 7, 2023.
1719

1820
- A clone of the [Raspberry Pi Pico C/C++ SDK](https://github.com/raspberrypi/pico-sdk/):
1921

2022
```sh
21-
# This project expects to find pico-sdk in a sibling directory to itself.
2223
cd ..
2324
git clone https://github.com/raspberrypi/pico-sdk.git
2425
cd pico-sdk/
2526
git submodule update --init
2627
cd ..
2728
```
2829

30+
This project expects to find the SDK in a sibling directory named `pico-sdk`. You can change this below if your SDK is in a different place.
31+
32+
- The GCC compiler for ARM embedded platforms
33+
2934
- [CMake](https://cmake.org/) and [Ninja](https://ninja-build.org/):
3035

3136
```sh
3237
brew install cmake ninja
3338
```
3439

40+
The Pico SDK uses CMake as its build system and we’re piggybacking on that. The Swift library is also built with CMake. The unfortunate consequence is that we can’t easily use a [SwiftPM](https://www.swift.org/package-manager/) package for the Swift library as we’d have to tell CMake how to build the package.
41+
3542
## Configuration
3643

3744
Open the file `CMakeLists.txt` in the root folder. Edit these two lines to match your setup:
3845

3946
```cmake
4047
41-
set(PICO_SDK_PATH "${CMAKE_CURRENT_LIST_DIR}/../pico-sdk")
48+
set(PICO_SDK_PATH "${CMAKE_CURRENT_LIST_DIR}/../pico-sdk")
4249
43-
set(Swift_Toolchain "org.swift.59202312071a")
50+
set(Swift_Toolchain "org.swift.59202312071a")
4451
4552
```
4653

@@ -54,7 +61,11 @@ cmake -G Ninja ..
5461
ninja
5562
```
5663

57-
This produces the executable `PicoLinksSwift.elf` in the `build` directory. You have two options to copy this to the Pico:
64+
This produces the executable `PicoLinksSwift.elf` in the `build` directory.
65+
66+
## Running on the Pico
67+
68+
You have two options to copy the executable to the Pico:
5869

5970
1. Via the USB Mass Storage interface: use the provided `build/elf2uf2/elf2uf2` tool to convert the `.elf` file to `.uf2`.
6071
2. Via the debug probe. I use [probe.rs](https://probe.rs/) for this, which is a tool from the Rust community, but it works in this context too:

main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ int main()
88
stdio_init_all();
99
printf("main() start\n");
1010
#ifndef PICO_DEFAULT_LED_PIN
11-
#warning blink example requires a board with a regular LED
11+
#warning Program requires a board with a regular LED (e.g. *not* the Pico W as its LED is wired to the Wi-Fi chip)
1212
#else
1313
const uint LED_PIN = PICO_DEFAULT_LED_PIN;
1414
gpio_init(LED_PIN);

0 commit comments

Comments
 (0)