Skip to content

Commit 88ab1fe

Browse files
authored
Replace pico-blink build.sh (#110)
Removes the legacy build.sh script used to build the pico-blink firmware and replaces it with a makefile leveraging SwiftPM + a new pico.json toolset file. This means we no longer have to handle build flags in the build script directly and SwiftPM can handle invoking the linker.
1 parent 0ad8cfe commit 88ab1fe

File tree

7 files changed

+96
-52
lines changed

7 files changed

+96
-52
lines changed

Tools/Toolsets/pico.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"schemaVersion": "1.0",
3+
"swiftCompiler": {
4+
"extraCLIOptions": [
5+
"-Xfrontend", "-disable-stack-protector",
6+
"-enable-experimental-feature", "Embedded",
7+
"-Xcc", "-mcpu=cortex-m0plus"
8+
]
9+
},
10+
"linker": {
11+
"extraCLIOptions": [
12+
"-arch", "armv6m",
13+
"-dead_strip",
14+
"-static",
15+
"-e", "_reset",
16+
"-no_zero_fill_sections",
17+
"-segalign", "4",
18+
"-segaddr", "__RESET", "0x20000000",
19+
"-segaddr", "__VECTORS", "0x20000100",
20+
"-seg1addr", "0x20000200",
21+
"-pagezero_size", "0",
22+
"-allow_dead_duplicates"
23+
]
24+
}
25+
}
26+

pico-blink/Makefile

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
##===----------------------------------------------------------------------===##
2+
##
3+
## This source file is part of the Swift open source project
4+
##
5+
## Copyright (c) 2025 Apple Inc. and the Swift project authors.
6+
## Licensed under Apache License v2.0 with Runtime Library Exception
7+
##
8+
## See https://swift.org/LICENSE.txt for license information
9+
##
10+
##===----------------------------------------------------------------------===##
11+
12+
# Paths
13+
REPOROOT := $(shell git rev-parse --show-toplevel)
14+
TOOLSROOT := $(REPOROOT)/Tools
15+
TOOLSET := $(TOOLSROOT)/Toolsets/pico.json
16+
MACHO2UF2 := $(TOOLSROOT)/macho2uf2.py
17+
SWIFT_BUILD := swift build
18+
19+
# Flags
20+
PICO_FAMILY := rp2040
21+
ARCH := armv6m
22+
TARGET := $(ARCH)-apple-none-macho
23+
SWIFT_BUILD_ARGS := \
24+
--configuration release \
25+
--triple $(TARGET) \
26+
--toolset $(TOOLSET) \
27+
--disable-local-rpath
28+
BUILDROOT := $(shell $(SWIFT_BUILD) $(SWIFT_BUILD_ARGS) --show-bin-path)
29+
30+
.PHONY: build
31+
build:
32+
@echo "building..."
33+
$(SWIFT_BUILD) \
34+
$(SWIFT_BUILD_ARGS) \
35+
-Xlinker -map -Xlinker $(BUILDROOT)/Application.mangled.map \
36+
--verbose
37+
38+
@echo "demangling linker map..."
39+
cat $(BUILDROOT)/Application.mangled.map \
40+
| c++filt | swift demangle > $(BUILDROOT)/Application.map
41+
42+
@echo "disassembling..."
43+
otool \
44+
-arch $(ARCH) -v -V -d -t \
45+
$(BUILDROOT)/Application \
46+
| c++filt | swift demangle > $(BUILDROOT)/Application.disassembly
47+
48+
@echo "extracting binary..."
49+
$(MACHO2UF2) \
50+
--pico-family "$(PICO_FAMILY)" \
51+
"$(BUILDROOT)/Application" \
52+
"$(BUILDROOT)/Application.uf2" \
53+
--base-address 0x20000000 \
54+
--segments '__TEXT,__DATA,__VECTORS,__RESET'
55+
56+
57+
.PHONY: clean
58+
clean:
59+
@echo "cleaning..."
60+
@swift package clean
61+
@rm -rf .build

pico-blink/Package.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ import PackageDescription
55
let package = Package(
66
name: "RP2040",
77
products: [
8-
.library(name: "Blinky", type: .static, targets: ["Blinky"])
8+
.executable(name: "Application", targets: ["Application"])
99
],
1010
targets: [
11-
.target(name: "Blinky", dependencies: ["RP2040"]),
11+
.executableTarget(name: "Application", dependencies: ["RP2040"]),
1212
.target(name: "Support"),
1313
.target(name: "RP2040", dependencies: ["Support"]),
14-
]
15-
)
14+
])

pico-blink/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111
- Connect the Pico board via a USB cable to your Mac, and make sure it's in the USB Mass Storage firmware upload mode (either hold the BOOTSEL button while plugging the board, or make sure your Flash memory doesn't contain any valid firmware).
1212
- Make sure you have a recent nightly Swift toolchain that has Embedded Swift support.
1313
- Build and copy the program in the UF2 format to the Mass Storage device to trigger flashing the program into memory (after which the device will reboot and run the firmware):
14+
1415
``` console
1516
$ cd pico-blink
16-
$ TOOLCHAINS='<toolchain-identifier>' ./build.sh
17-
$ cp .build/blink.uf2 /Volumes/RP2040
17+
$ make
18+
$ cp .build/Application.uf2 /Volumes/RP2040
1819
```
20+
1921
- The green LED should now be blinking in a pattern.

pico-blink/Sources/Blinky/Blinky.swift renamed to pico-blink/Sources/Application/Application.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import RP2040
1313

1414
@main
15-
struct Main {
15+
struct Application {
1616
// swift-format-ignore: NeverUseImplicitlyUnwrappedOptionals
1717
static var board: RP2040! = nil
1818

pico-blink/build.sh

Lines changed: 0 additions & 44 deletions
This file was deleted.

stm32-neopixel/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
##
33
## This source file is part of the Swift open source project
44
##
5-
## Copyright (c) 2023 Apple Inc. and the Swift project authors.
5+
## Copyright (c) 2025 Apple Inc. and the Swift project authors.
66
## Licensed under Apache License v2.0 with Runtime Library Exception
77
##
88
## See https://swift.org/LICENSE.txt for license information

0 commit comments

Comments
 (0)