Skip to content

Replace pico-blink build.sh #110

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 2 commits into from
May 2, 2025
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
26 changes: 26 additions & 0 deletions Tools/Toolsets/pico.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"schemaVersion": "1.0",
"swiftCompiler": {
"extraCLIOptions": [
"-Xfrontend", "-disable-stack-protector",
"-enable-experimental-feature", "Embedded",
"-Xcc", "-mcpu=cortex-m0plus"
]
},
"linker": {
"extraCLIOptions": [
"-arch", "armv6m",
"-dead_strip",
"-static",
"-e", "_reset",
"-no_zero_fill_sections",
"-segalign", "4",
"-segaddr", "__RESET", "0x20000000",
"-segaddr", "__VECTORS", "0x20000100",
"-seg1addr", "0x20000200",
"-pagezero_size", "0",
"-allow_dead_duplicates"
]
}
}

61 changes: 61 additions & 0 deletions pico-blink/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
##===----------------------------------------------------------------------===##
##
## This source file is part of the Swift open source project
##
## Copyright (c) 2025 Apple Inc. and the Swift project authors.
## Licensed under Apache License v2.0 with Runtime Library Exception
##
## See https://swift.org/LICENSE.txt for license information
##
##===----------------------------------------------------------------------===##

# Paths
REPOROOT := $(shell git rev-parse --show-toplevel)
TOOLSROOT := $(REPOROOT)/Tools
TOOLSET := $(TOOLSROOT)/Toolsets/pico.json
MACHO2UF2 := $(TOOLSROOT)/macho2uf2.py
SWIFT_BUILD := swift build

# Flags
PICO_FAMILY := rp2040
ARCH := armv6m
TARGET := $(ARCH)-apple-none-macho
SWIFT_BUILD_ARGS := \
--configuration release \
--triple $(TARGET) \
--toolset $(TOOLSET) \
--disable-local-rpath
BUILDROOT := $(shell $(SWIFT_BUILD) $(SWIFT_BUILD_ARGS) --show-bin-path)

.PHONY: build
build:
@echo "building..."
$(SWIFT_BUILD) \
$(SWIFT_BUILD_ARGS) \
-Xlinker -map -Xlinker $(BUILDROOT)/Application.mangled.map \
--verbose

@echo "demangling linker map..."
cat $(BUILDROOT)/Application.mangled.map \
| c++filt | swift demangle > $(BUILDROOT)/Application.map

@echo "disassembling..."
otool \
-arch $(ARCH) -v -V -d -t \
$(BUILDROOT)/Application \
| c++filt | swift demangle > $(BUILDROOT)/Application.disassembly

@echo "extracting binary..."
$(MACHO2UF2) \
--pico-family "$(PICO_FAMILY)" \
"$(BUILDROOT)/Application" \
"$(BUILDROOT)/Application.uf2" \
--base-address 0x20000000 \
--segments '__TEXT,__DATA,__VECTORS,__RESET'


.PHONY: clean
clean:
@echo "cleaning..."
@swift package clean
@rm -rf .build
7 changes: 3 additions & 4 deletions pico-blink/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import PackageDescription
let package = Package(
name: "RP2040",
products: [
.library(name: "Blinky", type: .static, targets: ["Blinky"])
.executable(name: "Application", targets: ["Application"])
],
targets: [
.target(name: "Blinky", dependencies: ["RP2040"]),
.executableTarget(name: "Application", dependencies: ["RP2040"]),
.target(name: "Support"),
.target(name: "RP2040", dependencies: ["Support"]),
]
)
])
6 changes: 4 additions & 2 deletions pico-blink/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
- 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).
- Make sure you have a recent nightly Swift toolchain that has Embedded Swift support.
- 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):

``` console
$ cd pico-blink
$ TOOLCHAINS='<toolchain-identifier>' ./build.sh
$ cp .build/blink.uf2 /Volumes/RP2040
$ make
$ cp .build/Application.uf2 /Volumes/RP2040
```

- The green LED should now be blinking in a pattern.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import RP2040

@main
struct Main {
struct Application {
// swift-format-ignore: NeverUseImplicitlyUnwrappedOptionals
static var board: RP2040! = nil

Expand Down
44 changes: 0 additions & 44 deletions pico-blink/build.sh

This file was deleted.

2 changes: 1 addition & 1 deletion stm32-neopixel/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
##
## This source file is part of the Swift open source project
##
## Copyright (c) 2023 Apple Inc. and the Swift project authors.
## Copyright (c) 2025 Apple Inc. and the Swift project authors.
## Licensed under Apache License v2.0 with Runtime Library Exception
##
## See https://swift.org/LICENSE.txt for license information
Expand Down
Loading