Skip to content

Commit 6bb9782

Browse files
authored
Merge pull request #16 from philipstarkey/philipstarkey/rp235x
Add support for RP2350
2 parents d817579 + eac7fc3 commit 6bb9782

File tree

9 files changed

+148
-126
lines changed

9 files changed

+148
-126
lines changed

.github/workflows/build.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ jobs:
2424
- name: Upload firmware as artifact
2525
uses: actions/upload-artifact@v4
2626
with:
27-
name: prawnblaster-firmware-${{ github.sha }}
28-
path: build/prawn_do/prawn_do.uf2
27+
name: prawn_do-firmware-${{ github.sha }}
28+
path: build_*/prawn_do/*.uf2
2929

3030
- name: Create release
3131
if: (github.event_name == 'push' && contains(github.ref, '/tags'))
@@ -35,4 +35,5 @@ jobs:
3535
prerelease: false
3636
files: |
3737
LICENSE.txt
38-
build/prawn_do/prawn_do.uf2
38+
build_rp2040/prawn_do/prawn_do_rp2040.uf2
39+
build_rp2350/prawn_do/prawn_do_rp2350.uf2

.gitignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
build/*
2-
!build/*.uf2
1+
build*/*
32
.vscode
43
.DS_Store
5-
cmake-*
4+
cmake-*
5+
pico_sdk_import.cmake

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.13)
1+
cmake_minimum_required(VERSION 3.17)
22

33
include(pico_sdk_import.cmake)
44

README.md

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@ This firmware turns pins 0-15 into programmable digital outputs. Their states ar
66

77
Pin 20 is reserved for optional external clock input.
88

9+
## Supported boards
10+
11+
We support either the official [Raspberry Pi Pico (RP2040 chip)](https://www.raspberrypi.com/products/raspberry-pi-pico/) board or the official [Raspberry Pi Pico 2 (RP2350 chip)](https://www.raspberrypi.com/products/raspberry-pi-pico-2/) board.
12+
We recommend the Pico 2 (RP2350) board due to its faster clock and larger RAM.
13+
14+
> [!CAUTION]
15+
> The RP2350 currently has a hardware design bug that impacts the operation of the internal pull-down resistor on GPIO pins configured as inputs.
16+
> This may impact the operation of the PrawnBlaster trigger inputs when using the RP2350, depending on the specs of your trigger. For full details, see errata E9 in the [RP2350 datasheet](https://datasheets.raspberrypi.com/rp2350/rp2350-datasheet.pdf).
17+
> The issue can usually be fixed by providing a suitably sized external pull-down resistor on the relevant input pins.
18+
> RP2040 based boards do not suffer from this issue (but have reduced timing and storage compared to the RP2350).
19+
920
## Specs
1021

1122
All timings are given relative to the default system clock of 100 MHz.
@@ -14,12 +25,21 @@ All timings are given relative to the default system clock of 100 MHz.
1425
* **Minimum Pulse Width**: 5 clock cycles (50 ns)
1526
* **Max Pulse Rate**: 1/10 system clock frequency (10 MHz)
1627
* **Maximum Pulse Width**: 2^32 - 1 clock cycles (42.94967295 s)
17-
* **Max Instructions**: 30,000
28+
* **Max Instructions**: 60,000 (Pico 2 - RP2350) or 30,000 (Pico - RP2040)
1829
* Supports Indefinite Waits and Full Stops
19-
* Max system clock frequency of 133 MHz
30+
* Max system clock frequency of 150 MHz (Pico 2 - RP2350) or 133 MHz (Pico - RP2040)
31+
* Support for referencing the system clock to an external clock source to synchronise with other devices (officially limited to 50MHz on the Pico and Pico 2, but testing has shown it works up to 133MHz).
2032

2133
## Installing the .uf2 file
22-
Before plugging in usb, hold down the bootsel button, which should pop-up a window to drag/drop the .uf2 file into, and when that .uf2 file is added, the window should disappear.
34+
Download the latest prawn_do.uf2 file:
35+
- [Pico 2 - RP2350](https://github.com/labscript-suite/prawn_digital_out/releases/latest/download/prawn_do_rp2350.uf2)
36+
- [Pico - RP2040](https://github.com/labscript-suite/prawn_digital_out/releases/latest/download/prawn_do_rp2040.uf2)
37+
38+
On your Raspberry Pi Pico, hold down the "bootsel" button while plugging the Pico into USB port on a PC (that must already be turned on).
39+
The Pico should mount as a mass storage device (if it doesn't, try again or consult the Pico documentation).
40+
Drag and drop the `.uf2` file into the mounted mass storage device.
41+
The mass storage device should unmount after the copy completes.
42+
Your Pico is now running the Prawn Digital Output firmware!
2343

2444
## Serial Communication
2545
Commands must end with a newline character: `'\n'`.
@@ -43,6 +63,7 @@ These commands can be run at any time (ie during sequence execution).
4363
* `deb` - Turns on debugging mode which adds printed output when adding instructions. By default, debugging is off.
4464
* `ndb` - Turns off debugging mode.
4565
* `ver` - Displays the version of the PrawnDO code.
66+
* `brd` - Responds with a string containing the board version (`pico1` or `pico2`).
4667
* `abt` - Abort execution of a running sequence.
4768

4869
These commands must be run when the running status is `STOPPED`.
@@ -79,7 +100,7 @@ These commands must be run when the running status is `STOPPED`.
79100
* `len` - Print total number of instructions in the programmed sequence.
80101
* `cls` - Clear the current sequence of programmed outputs.
81102

82-
* `clk <src (0: internal, 1: external)> <freq (in decimal Hz)>` - Sets the system clock and frequency. Maximum frequency allowed is 133 MHz. Default is 100 MHz internal clock. External clock frequency input is GPIO pin 20.
103+
* `clk <src (0: internal, 1: external)> <freq (in decimal Hz)>` - Sets the system clock and frequency. Maximum frequency allowed is 150 MHz (Pico 2 - RP2350) or 133 MHz (Pico - RP2040). Default is 100 MHz internal clock. External clock frequency input is GPIO pin 20.
83104
* `frq` - Measure and print system frequencies.
84105
* `prg` - Equivalent to disconnecting the Pico, holding down the "bootsel" button, and reconnecting the Pico. Places the Pico into firmware flashing mode; the PrawnDO serial port should disappear and the Pico should mount as a mass storage device.
85106

@@ -140,7 +161,7 @@ If you want to make changes to the firmware, or want to compile it yourself (bec
140161
2. Clone this repository
141162
3. Open a terminal with the current working directory set to the repository root (the `docker-compose.yaml`` file should be there)
142163
4. Run `docker compose build --pull` to build the docker container
143-
5. Run `docker compose up` to build the PrawnBlaster firmware.
164+
5. Run `docker compose up` to build the PrawnDO firmware.
144165

145166
Step 4 will take a while as it has to build the docker container.
146167
If it is slow to download packages from the Ubuntu package repositories, consider providing an explicit apt mirror that is fast for you: `docker compose build --pull --build-arg APT_MIRROR="http://azure.archive.ubuntu.com/ubuntu/"`.
@@ -151,3 +172,8 @@ Just change the git tag of the pico SDK that gets cloned out by git, then rebuil
151172
Note once the docker container is built, you can run step 5 as many times as you like.
152173
You do not need to rebuild the container, even if you make changes to the source code.
153174
You only need to rebuild the docker container if you modify the `build/docker/Dockerfile` file.
175+
176+
By default, running `docker compose up` builds the all variations of the firmware.
177+
If you only want to build for a specific board, run either `docker compose up build_rp2040_firmware` or `docker compose up build_rp2350_firmware`.
178+
179+
The firmware will be located in `build_rp2xxx/prawn_do/prawn_do_rp2xxx.uf2` where `rp2xxx` will be either `rp2040` or `rp2350`.

docker-compose.yaml

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,30 @@
11
name: prawn_do
22

33
services:
4-
buildfirmware:
4+
prawn_do_firmware_base:
55
build:
66
dockerfile: docker/Dockerfile
7-
command: /bin/bash -c 'cmake .. && make'
7+
image: prawn_digital_output/build-firmware
88
volumes:
99
- .:/prawn_digital_output
10-
working_dir: /prawn_digital_output/build
11-
init: true
10+
command: /bin/bash -c 'cp /pico/pico-sdk/external/pico_sdk_import.cmake /prawn_digital_output/'
11+
container_name: prawn_do_firmware_base
12+
13+
build_rp2040_firmware:
14+
image: prawn_digital_output/build-firmware
15+
command: /bin/bash -c 'cmake .. -D PICO_PLATFORM=rp2040 && make'
16+
volumes:
17+
- .:/prawn_digital_output
18+
working_dir: /prawn_digital_output/build_rp2040
19+
init: true
20+
depends_on:
21+
- prawn_do_firmware_base
22+
build_rp2350_firmware:
23+
image: prawn_digital_output/build-firmware
24+
command: /bin/bash -c 'cmake .. -D PICO_PLATFORM=rp2350 && make'
25+
volumes:
26+
- .:/prawn_digital_output
27+
working_dir: /prawn_digital_output/build_rp2350
28+
init: true
29+
depends_on:
30+
- prawn_do_firmware_base

docker/Dockerfile

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,39 @@ ARG APT_MIRROR="mirror://mirrors.ubuntu.com/mirrors.txt"
66
# ARG APT_MIRROR="http://mirror.aarnet.edu.au/pub/ubuntu/archive/"
77

88
# Configure mirror. Pass --build-arg APT_MIRROR=<mirror URL> to set a mirror if this is slow
9-
RUN sed -i "s#htt[p|ps]://archive.ubuntu.com/ubuntu/#$APT_MIRROR#g" /etc/apt/sources.list
9+
RUN sed -i "s#htt[p|ps]://archive.ubuntu.com/ubuntu/#$APT_MIRROR#g" /etc/apt/sources.list.d/ubuntu.sources
1010

1111
# Install packages
1212
RUN \
1313
apt update && \
1414
apt install -y git python3 && \
15-
apt install -y cmake gcc-arm-none-eabi libnewlib-arm-none-eabi build-essential
15+
# For Pico SDK
16+
apt install -y cmake gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib build-essential
1617

1718
# Install Pico SDK into a new stage
18-
FROM base as buildtools
19+
FROM base AS buildtools
1920

21+
# Install Pico SDK
2022
RUN \
2123
mkdir -p /pico/ && \
2224
cd /pico/ && \
23-
git clone https://github.com/raspberrypi/pico-sdk.git --branch 1.5.1 && \
25+
git clone https://github.com/raspberrypi/pico-sdk.git --branch 2.1.1 && \
2426
cd pico-sdk/ && \
2527
git submodule update --init && \
2628
cd /
2729

2830
# Set the Pico SDK environment variable
29-
ENV PICO_SDK_PATH=/pico/pico-sdk/
31+
ENV PICO_SDK_PATH=/pico/pico-sdk/
32+
33+
# Install picotool
34+
# ensure versions of sdk and picotool match
35+
RUN \
36+
git clone https://github.com/raspberrypi/picotool.git --branch 2.1.1 && \
37+
cd picotool && \
38+
mkdir build && \
39+
cd build && \
40+
cmake .. && \
41+
make -j$(nproc) && \
42+
cmake --install . && \
43+
cd ../.. && \
44+
rm -rf picotool

pico_sdk_import.cmake

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

prawn_do/CMakeLists.txt

Lines changed: 49 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,49 @@
1-
add_executable(prawn_do
2-
prawn_do.c
3-
fast_serial.c
4-
)
5-
6-
pico_generate_pio_header(prawn_do
7-
${CMAKE_CURRENT_LIST_DIR}/prawn_do.pio
8-
)
9-
10-
# add local includes for fast_serial
11-
target_include_directories(prawn_do PRIVATE ${CMAKE_CURRENT_LIST_DIR})
12-
13-
# pull in pico stdlib
14-
target_link_libraries(prawn_do
15-
pico_multicore
16-
pico_stdlib
17-
pico_unique_id
18-
hardware_dma
19-
hardware_pio
20-
tinyusb_device
21-
tinyusb_board
22-
)
23-
24-
# create map/bin/hex/uf2 files
25-
pico_add_extra_outputs(prawn_do)
1+
set(overclocks 0;)
2+
3+
foreach (overclock IN LISTS overclocks)
4+
# Compute firmware name
5+
set(firmware_name prawn_do)
6+
if(PICO_PLATFORM MATCHES "^rp2350")
7+
set(firmware_name "${firmware_name}_rp2350")
8+
else()
9+
set(firmware_name "${firmware_name}_${PICO_PLATFORM}")
10+
endif()
11+
if(overclock)
12+
set(firmware_name "${firmware_name}_overclock")
13+
endif()
14+
15+
add_executable(${firmware_name} prawn_do.c fast_serial.c)
16+
17+
pico_generate_pio_header(${firmware_name} ${CMAKE_CURRENT_LIST_DIR}/prawn_do.pio)
18+
19+
# Pass in number of instructions to firmware as a compiler definition
20+
set(num_instructions 30000)
21+
if(PICO_PLATFORM MATCHES "^rp2350")
22+
set(num_instructions 60000)
23+
endif()
24+
target_compile_definitions(${firmware_name} PUBLIC "PRAWNDO_NUM_INSTRUCTIONS=${num_instructions}")
25+
26+
# Pass in board type to firmware as a compiler definition. Note that PICO_BOARD is passed in by the SDK, but it's passed in a string which isn't valid and so I can't use it...
27+
# This is also, to some extent, a duplicate of the above PRAWNDO_NUM_INSTRUCTIONS but I think it makes sense to keep these seperate.
28+
if (PICO_BOARD STREQUAL "pico")
29+
target_compile_definitions(${firmware_name} PUBLIC "PRAWNDO_PICO_BOARD=1")
30+
elseif (PICO_BOARD STREQUAL "pico2")
31+
target_compile_definitions(${firmware_name} PUBLIC "PRAWNDO_PICO_BOARD=2")
32+
else ()
33+
message(FATAL_ERROR "Unsupported PICO_BOARD")
34+
endif()
35+
36+
37+
# Pass in overclock state to firmware as a compiler definition
38+
if(overclock)
39+
target_compile_definitions(${firmware_name} PUBLIC "PRAWNDO_OVERCLOCK=1")
40+
endif()
41+
42+
# Pull in our pico_stdlib which aggregates commonly used features
43+
target_link_libraries(${firmware_name} pico_stdlib hardware_pio pico_multicore pico_unique_id hardware_clocks hardware_dma tinyusb_device tinyusb_board)
44+
target_include_directories(${firmware_name} PRIVATE ${CMAKE_CURRENT_LIST_DIR})
45+
46+
# create map/bin/hex/uf2 file etc.
47+
pico_add_extra_outputs(${firmware_name})
48+
49+
endforeach()

0 commit comments

Comments
 (0)