Skip to content

Commit 5bf675a

Browse files
committed
Add readme
1 parent 421152d commit 5bf675a

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

README.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Embedded Swift on the Raspberry Pi Pico
2+
3+
A proof of concept for executing Embedded Swift code on the [Raspberry Pi Pico](https://www.raspberrypi.com/products/raspberry-pi-pico/). The main program is written in C (built with the official Pico C SDK) and calls into a statically linked Swift library.
4+
5+
## Prerequisites and Installation
6+
7+
### Hardware
8+
9+
- A [Raspberry Pi Pico](https://www.raspberrypi.com/products/raspberry-pi-pico/)
10+
- Optional but recommended: a [Raspberry Pi Debug Probe](https://www.raspberrypi.com/products/debug-probe/) for more convenient flashing
11+
12+
### Software
13+
14+
- Host OS: macOS 13.x or 14.x
15+
16+
- A recent nightly Swift toolchain from [swift.org](https://www.swift.org/download/). Tested with the December 7, 2023 toolchain.
17+
18+
- A clone of the [Raspberry Pi Pico C/C++ SDK](https://github.com/raspberrypi/pico-sdk/):
19+
20+
```sh
21+
# This project expects to find pico-sdk in a sibling directory to itself.
22+
cd ..
23+
git clone https://github.com/raspberrypi/pico-sdk.git
24+
cd pico-sdk/
25+
git submodule update --init
26+
cd ..
27+
```
28+
29+
- [CMake](https://cmake.org/) and [Ninja](https://ninja-build.org/):
30+
31+
```sh
32+
brew install cmake ninja
33+
```
34+
35+
## Configuration
36+
37+
Open the file `CMakeLists.txt` in the root folder. Edit these two lines to match your setup:
38+
39+
```cmake
40+
41+
set(PICO_SDK_PATH "${CMAKE_CURRENT_LIST_DIR}/../pico-sdk")
42+
43+
set(Swift_Toolchain "org.swift.59202312071a")
44+
45+
```
46+
47+
## Building
48+
49+
```sh
50+
cd pico-embedded-swift
51+
mkdir build
52+
cd build
53+
cmake -G Ninja ..
54+
ninja
55+
```
56+
57+
This produces the executable `PicoLinksSwift.elf` in the `build` directory. You have two options to copy this to the Pico:
58+
59+
1. Via the USB Mass Storage interface: use the provided `build/elf2uf2/elf2uf2` tool to convert the `.elf` file to `.uf2`.
60+
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:
61+
62+
```sh
63+
probe-rs run --chip RP2040 PicoLinksSwift.elf
64+
```

0 commit comments

Comments
 (0)