Skip to content

Commit d717396

Browse files
KarlK90tzarc
andauthored
[Core] Add Raspberry Pi RP2040 support (qmk#14877)
* Disable RESET keycode because of naming conflicts * Add Pico SDK as submodule * Add RP2040 build support to QMK * Adjust USB endpoint structs for RP2040 * Add RP2040 bootloader and double-tap reset routine * Add generic and pro micro RP2040 boards * Add RP2040 onekey keyboard * Add WS2812 PIO DMA enabled driver and documentation Supports regular and open-drain output configuration. RP2040 GPIOs are sadly not 5V tolerant, so this is a bit use-less or needs extra hardware or you take the risk to fry your hardware. * Adjust SIO Driver for RP2040 * Adjust I2C Driver for RP2040 * Adjust SPI Driver for RP2040 * Add PIO serial driver and documentation * Add general RP2040 documentation * Apply suggestions from code review Co-authored-by: Nick Brassel <nick@tzarc.org> Co-authored-by: Nick Brassel <nick@tzarc.org>
1 parent d206c17 commit d717396

43 files changed

Lines changed: 2026 additions & 96 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.gitmodules‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,6 @@
1818
[submodule "lib/printf"]
1919
path = lib/printf
2020
url = https://github.com/qmk/printf
21+
[submodule "lib/pico-sdk"]
22+
path = lib/pico-sdk
23+
url = https://github.com/qmk/pico-sdk.git

‎Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ ifndef SKIP_GIT
401401
if [ ! -e lib/lufa ]; then git submodule sync lib/lufa && git submodule update --depth 50 --init lib/lufa; fi
402402
if [ ! -e lib/vusb ]; then git submodule sync lib/vusb && git submodule update --depth 50 --init lib/vusb; fi
403403
if [ ! -e lib/printf ]; then git submodule sync lib/printf && git submodule update --depth 50 --init lib/printf; fi
404+
if [ ! -e lib/pico-sdk ]; then git submodule sync lib/pico-sdk && git submodule update --depth 50 --init lib/pico-sdk; fi
404405
git submodule status --recursive 2>/dev/null | \
405406
while IFS= read -r x; do \
406407
case "$$x" in \

‎builddefs/bootloader.mk‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,10 @@ ifeq ($(strip $(BOOTLOADER)), tinyuf2)
200200
OPT_DEFS += -DBOOTLOADER_TINYUF2
201201
BOOTLOADER_TYPE = tinyuf2
202202
endif
203+
ifeq ($(strip $(BOOTLOADER)), rp2040)
204+
OPT_DEFS += -DBOOTLOADER_RP2040
205+
BOOTLOADER_TYPE = rp2040
206+
endif
203207
ifeq ($(strip $(BOOTLOADER)), halfkay)
204208
OPT_DEFS += -DBOOTLOADER_HALFKAY
205209
BOOTLOADER_TYPE = halfkay

‎builddefs/common_features.mk‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ ifeq ($(strip $(BACKLIGHT_ENABLE)), yes)
547547
endif
548548
endif
549549

550-
VALID_WS2812_DRIVER_TYPES := bitbang pwm spi i2c
550+
VALID_WS2812_DRIVER_TYPES := bitbang pwm spi i2c vendor
551551

552552
WS2812_DRIVER ?= bitbang
553553
ifeq ($(strip $(WS2812_DRIVER_REQUIRED)), yes)
@@ -637,7 +637,7 @@ ifneq ($(strip $(DEBOUNCE_TYPE)), custom)
637637
endif
638638

639639

640-
VALID_SERIAL_DRIVER_TYPES := bitbang usart
640+
VALID_SERIAL_DRIVER_TYPES := bitbang usart vendor
641641

642642
SERIAL_DRIVER ?= bitbang
643643
ifeq ($(filter $(SERIAL_DRIVER),$(VALID_SERIAL_DRIVER_TYPES)),)

‎builddefs/mcu_selection.mk‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,41 @@ ifneq ($(findstring MK66FX1M0, $(MCU)),)
116116
BOARD ?= PJRC_TEENSY_3_6
117117
endif
118118

119+
ifneq ($(findstring RP2040, $(MCU)),)
120+
# Cortex version
121+
MCU = cortex-m0plus
122+
123+
# ARM version, CORTEX-M0/M1 are 6, CORTEX-M3/M4/M7 are 7
124+
CHIBIOS_PORT = ARMv6-M-RP2
125+
126+
## chip/board settings
127+
# - the next two should match the directories in
128+
# <chibios[-contrib]>/os/hal/ports/$(MCU_PORT_NAME)/$(MCU_SERIES)
129+
# OR
130+
# <chibios[-contrib]>/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES)
131+
MCU_FAMILY = RP
132+
MCU_SERIES = RP2040
133+
134+
# Linker script to use
135+
# - it should exist either in <chibios>/os/common/ports/ARMCMx/compilers/GCC/ld/
136+
# or <keyboard_dir>/ld/
137+
STARTUPLD_CONTRIB = $(CHIBIOS_CONTRIB)/os/common/startup/ARMCMx/compilers/GCC/ld
138+
MCU_LDSCRIPT ?= RP2040_FLASH
139+
LDFLAGS += -L $(STARTUPLD_CONTRIB)
140+
141+
# Startup code to use
142+
# - it should exist in <chibios>/os/common/startup/ARMCMx/compilers/GCC/mk/
143+
MCU_STARTUP ?= rp2040
144+
145+
# Board: it should exist either in <chibios>/os/hal/boards/,
146+
# <keyboard_dir>/boards/, or drivers/boards/
147+
BOARD ?= GENERIC_PROMICRO_RP2040
148+
149+
# Default UF2 Bootloader settings
150+
UF2_FAMILY ?= RP2040
151+
FIRMWARE_FORMAT ?= uf2
152+
endif
153+
119154
ifneq ($(findstring STM32F042, $(MCU)),)
120155
# Cortex version
121156
MCU = cortex-m0

‎data/schemas/definitions.jsonschema‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@
101101
"type": "string",
102102
"pattern": "^LINE_PIN\\d{1,2}$"
103103
},
104+
{
105+
"type": "string",
106+
"pattern": "^GP\\d{1,2}$"
107+
},
104108
{
105109
"type": "integer"
106110
},

‎data/schemas/keyboard.jsonschema‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
},
4343
"processor": {
4444
"type": "string",
45-
"enum": ["cortex-m0", "cortex-m0plus", "cortex-m3", "cortex-m4", "MKL26Z64", "MK20DX128", "MK20DX256", "MK66FX1M0", "STM32F042", "STM32F072", "STM32F103", "STM32F303", "STM32F401", "STM32F405", "STM32F407", "STM32F411", "STM32F446", "STM32G431", "STM32G474", "STM32L412", "STM32L422", "STM32L432", "STM32L433", "STM32L442", "STM32L443", "GD32VF103", "WB32F3G71", "WB32FQ95", "atmega16u2", "atmega32u2", "atmega16u4", "atmega32u4", "at90usb162", "at90usb646", "at90usb647", "at90usb1286", "at90usb1287", "atmega32a", "atmega328p", "atmega328", "attiny85", "unknown"]
45+
"enum": ["cortex-m0", "cortex-m0plus", "cortex-m3", "cortex-m4", "MKL26Z64", "MK20DX128", "MK20DX256", "MK66FX1M0", "RP2040", "STM32F042", "STM32F072", "STM32F103", "STM32F303", "STM32F401", "STM32F405", "STM32F407", "STM32F411", "STM32F446", "STM32G431", "STM32G474", "STM32L412", "STM32L422", "STM32L432", "STM32L433", "STM32L442", "STM32L443", "GD32VF103", "WB32F3G71", "WB32FQ95", "atmega16u2", "atmega32u2", "atmega16u4", "atmega32u4", "at90usb162", "at90usb646", "at90usb647", "at90usb1286", "at90usb1287", "atmega32a", "atmega328p", "atmega328", "attiny85", "unknown"]
4646
},
4747
"audio": {
4848
"type": "object",
@@ -86,7 +86,7 @@
8686
},
8787
"bootloader": {
8888
"type": "string",
89-
"enum": ["atmel-dfu", "bootloadhid", "bootloadHID", "custom", "caterina", "halfkay", "kiibohd", "lufa-dfu", "lufa-ms", "md-boot", "qmk-dfu", "qmk-hid", "stm32-dfu", "stm32duino", "gd32v-dfu", "wb32-dfu", "unknown", "usbasploader", "USBasp", "tinyuf2"],
89+
"enum": ["atmel-dfu", "bootloadhid", "bootloadHID", "custom", "caterina", "halfkay", "kiibohd", "lufa-dfu", "lufa-ms", "md-boot", "qmk-dfu", "qmk-hid", "stm32-dfu", "stm32duino", "gd32v-dfu", "wb32-dfu", "unknown", "usbasploader", "USBasp", "tinyuf2", "rp2040"],
9090
},
9191
"bootloader_instructions": {
9292
"type": "string",

‎docs/_summary.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@
165165
* Arm/ChibiOS
166166
* [Selecting an MCU](platformdev_selecting_arm_mcu.md)
167167
* [Early initialization](platformdev_chibios_earlyinit.md)
168+
* [Raspberry Pi RP2040](platformdev_rp2040.md)
168169

169170
* QMK Reference
170171
* [Contributing to QMK](contributing.md)

‎docs/compatible_microcontrollers.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ You can also use any ARM chip with USB that [ChibiOS](https://www.chibios.org) s
6565
* [MK66FX1M0](https://www.nxp.com/products/processors-and-microcontrollers/arm-microcontrollers/general-purpose-mcus/k-series-cortex-m4/k6x-ethernet/kinetis-k66-180-mhz-dual-high-speed-full-speed-usbs-2mb-flash-microcontrollers-mcus-based-on-arm-cortex-m4-core:K66_180)
6666
* PJRC Teensy 3.6
6767

68+
### Raspberry Pi
69+
70+
* [RP2040](https://www.raspberrypi.com/documentation/microcontrollers/rp2040.html)
71+
72+
For a detailed overview about the RP2040 support by QMK see the [dedicated RP2040 page](platformdev_rp2040.md).
73+
6874
## Atmel ATSAM
6975

7076
There is limited support for one of Atmel's ATSAM microcontrollers, that being the [ATSAMD51J18A](https://www.microchip.com/wwwproducts/en/ATSAMD51J18A) used by the [Massdrop keyboards](https://github.com/qmk/qmk_firmware/tree/master/keyboards/massdrop). However, it is not recommended to design a board with this microcontroller as the support is quite specialized to Massdrop hardware.

‎docs/flashing.md‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,3 +362,42 @@ CLI Flashing sequence:
362362
### `make` Targets
363363

364364
* `:uf2-split-left` and `:uf2-split-right`: Flashes the firmware but also sets the handedness setting in EEPROM by generating a side specific firmware.
365+
366+
## Raspberry Pi RP2040 UF2
367+
368+
The `rules.mk` setting for this bootloader is `rp2040`, and can be specified at the keymap or user level.
369+
370+
To ensure compatibility with the rp2040 bootloader, make sure this block is present in your `rules.mk`:
371+
372+
```make
373+
# Bootloader selection
374+
BOOTLOADER = rp2040
375+
```
376+
377+
Compatible flashers:
378+
379+
* Any application able to copy a file from one place to another, such as _macOS Finder_ or _Windows Explorer_.
380+
381+
Flashing sequence:
382+
383+
1. Enter the bootloader using any of the following methods:
384+
* Tap the `QK_BOOTLOADER` keycode
385+
* Hold the `BOOTSEL` button on the PCB while plugin in the usb cable.
386+
* Double-tap the `RESET` button on the PCB<sup>1</sup>.
387+
2. Wait for the OS to detect the device
388+
3. Copy the .uf2 file to the new USB disk
389+
4. Wait for the keyboard to become available
390+
391+
or
392+
393+
CLI Flashing sequence:
394+
395+
1. Enter the bootloader using any of the following methods:
396+
* Tap the `QK_BOOTLOADER` keycode
397+
* Hold the `BOOTSEL` button on the PCB while plugin in the usb cable.
398+
* Double-tap the `RESET` button on the PCB<sup>1</sup>.
399+
2. Wait for the OS to detect the device
400+
3. Flash via QMK CLI eg. `qmk flash --keyboard handwired/onekey/rpi_pico --keymap default`
401+
4. Wait for the keyboard to become available
402+
403+
<sup>1</sup>: This works only if QMK was compiled with `RP2040_BOOTLOADER_DOUBLE_TAP_RESET` defined.

0 commit comments

Comments
 (0)