Merge pull request #737 from pimoroni/patch-cleanup-workflows

CI: Tidyup and combine MicroPython builds.
This commit is contained in:
Philip Howard 2023-03-29 11:36:49 +01:00 committed by GitHub
commit 40d4774cf6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
46 changed files with 81 additions and 1072 deletions

View File

@ -1,153 +0,0 @@
name: MicroPython
on:
push:
pull_request:
release:
types: [created]
env:
MICROPYTHON_VERSION: 38e7b842c6bc8122753cbf0845eb141f28fbcb72
jobs:
deps:
runs-on: ubuntu-20.04
name: Dependencies
steps:
- name: Workspace Cache
id: cache
uses: actions/cache@v3
with:
path: ${{runner.workspace}}
key: workspace-micropython-${{env.MICROPYTHON_VERSION}}-with-libs
restore-keys: |
workspace-micropython-${{env.MICROPYTHON_VERSION}}-with-libs
# Check out MicroPython
- name: Checkout MicroPython
if: steps.cache.outputs.cache-hit != 'true'
uses: actions/checkout@v3
with:
repository: micropython/micropython
ref: ${{env.MICROPYTHON_VERSION}}
submodules: false # MicroPython submodules are hideously broken
path: micropython
# Check out MicroPython Libs
- name: Checkout MicroPython Libs
if: steps.cache.outputs.cache-hit != 'true'
uses: actions/checkout@v3
with:
repository: micropython/micropython-lib
path: micropython-lib
- name: Fetch base MicroPython submodules
if: steps.cache.outputs.cache-hit != 'true'
shell: bash
working-directory: micropython
run: git submodule update --init
- name: Fetch Pico SDK submodules
if: steps.cache.outputs.cache-hit != 'true'
shell: bash
working-directory: micropython/lib/pico-sdk
run: git submodule update --init
- name: Build mpy-cross
if: steps.cache.outputs.cache-hit != 'true'
shell: bash
working-directory: micropython/mpy-cross
run: make
build:
needs: deps
name: Build ${{matrix.name}} (${{matrix.board}})
runs-on: ubuntu-20.04
strategy:
matrix:
include:
- name: picow
board: PICO_W
- name: picow_enviro
board: PICO_W_ENVIRO
- name: picow_galactic_unicorn
board: PICO_W
- name: picow_cosmic_unicorn
board: PICO_W
- name: picow_inky_frame
board: PICO_W_INKY
env:
# MicroPython version will be contained in github.event.release.tag_name for releases
RELEASE_FILE: pimoroni-${{matrix.name}}-${{github.event.release.tag_name || github.sha}}-micropython
steps:
- name: Compiler Cache
uses: actions/cache@v3
with:
path: /home/runner/.ccache
key: ccache-micropython-${{matrix.name}}-${{github.ref}}-${{github.sha}}
restore-keys: |
ccache-micropython-${{matrix.name}}-${{github.ref}}
ccache-micropython-${{matrix.name}}-
- name: Workspace Cache
uses: actions/cache@v3
with:
path: ${{runner.workspace}}
key: workspace-micropython-${{env.MICROPYTHON_VERSION}}-with-libs
restore-keys: |
workspace-micropython-${{env.MICROPYTHON_VERSION}}-with-libs
- name: Install Compiler & CCache
if: runner.os == 'Linux'
run: |
sudo apt update && sudo apt install ccache gcc-arm-none-eabi
- uses: actions/checkout@v3
with:
submodules: true
path: pimoroni-pico-${{ github.sha }}
- name: "HACK: MicroPython Board Fixups"
shell: bash
working-directory: micropython/ports/rp2
run: |
../../../pimoroni-pico-${GITHUB_SHA}/micropython/_board/board-fixup.sh ${{matrix.name}} ${{matrix.board}} ../../../pimoroni-pico-${GITHUB_SHA}/micropython/_board
- name: Configure MicroPython
shell: bash
working-directory: micropython/ports/rp2
run: |
cmake -S . -B build-${{matrix.board}} -DPICO_BUILD_DOCS=0 -DUSER_C_MODULES=../../../pimoroni-pico-${GITHUB_SHA}/micropython/modules/micropython-${{matrix.name}}.cmake -DMICROPY_BOARD=${{matrix.board}} -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
- name: Build MicroPython
shell: bash
working-directory: micropython/ports/rp2
run: |
ccache --zero-stats || true
cmake --build build-${{matrix.board}} -j 2
ccache --show-stats || true
- name: Rename .uf2 for artifact
shell: bash
working-directory: micropython/ports/rp2/build-${{matrix.board}}
run: |
cp firmware.uf2 $RELEASE_FILE.uf2
- name: Store .uf2 as artifact
uses: actions/upload-artifact@v3
with:
name: ${{env.RELEASE_FILE}}.uf2
path: micropython/ports/rp2/build-${{matrix.board}}/${{env.RELEASE_FILE}}.uf2
- name: Upload .uf2
if: github.event_name == 'release'
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
with:
asset_path: micropython/ports/rp2/build-${{matrix.board}}/firmware.uf2
upload_url: ${{github.event.release.upload_url}}
asset_name: ${{env.RELEASE_FILE}}.uf2
asset_content_type: application/octet-stream

View File

@ -19,9 +19,9 @@ jobs:
uses: actions/cache@v3
with:
path: ${{runner.workspace}}
key: workspace-micropython-${{env.MICROPYTHON_VERSION}}
key: workspace-micropython-${{env.MICROPYTHON_VERSION}}-with-libs
restore-keys: |
workspace-micropython-${{env.MICROPYTHON_VERSION}}
workspace-micropython-${{env.MICROPYTHON_VERSION}}-with-libs
# Check out MicroPython
- name: Checkout MicroPython
@ -33,6 +33,14 @@ jobs:
submodules: false # MicroPython submodules are hideously broken
path: micropython
# Check out MicroPython Libs
- name: Checkout MicroPython Libs
if: steps.cache.outputs.cache-hit != 'true'
uses: actions/checkout@v3
with:
repository: micropython/micropython-lib
path: micropython-lib
- name: Fetch base MicroPython submodules
if: steps.cache.outputs.cache-hit != 'true'
shell: bash
@ -53,13 +61,15 @@ jobs:
build:
needs: deps
name: Build ${{matrix.board}}
name: ${{matrix.name}} (${{matrix.board}})
runs-on: ubuntu-20.04
strategy:
matrix:
include:
- name: pico
board: PICO
- name: picow
board: PICO_W
- name: tiny2040
board: PIMORONI_TINY2040
- name: picolipo_4mb
@ -68,10 +78,25 @@ jobs:
board: PIMORONI_PICOLIPO_16MB
- name: tufty2040
board: PIMORONI_TUFTY2040
local_board_dir: true
- name: enviro
board: PICO_W_ENVIRO
local_board_dir: true
patch: true
- name: galactic_unicorn
board: PICO_W
- name: cosmic_unicorn
board: PICO_W
- name: inky_frame
board: PICO_W_INKY
local_board_dir: true
patch: true
env:
# MicroPython version will be contained in github.event.release.tag_name for releases
RELEASE_FILE: pimoroni-${{matrix.name}}-${{github.event.release.tag_name || github.sha}}-micropython.uf2
RELEASE_FILE: pimoroni-${{matrix.name}}-${{github.event.release.tag_name || github.sha}}-micropython
MICROPY_BOARD_DIR: "$GITHUB_WORKSPACE/pimoroni-pico-${{ github.sha }}/micropython/board/${{ matrix.BOARD }}"
USER_C_MODULES: "$GITHUB_WORKSPACE/pimoroni-pico-${{ github.sha }}/micropython/modules/micropython-${{matrix.name}}.cmake"
steps:
- name: Compiler Cache
@ -101,18 +126,27 @@ jobs:
submodules: true
path: pimoroni-pico-${{ github.sha }}
- name: "HACK: MicroPython Board Fixups"
- name: "HACK: Pico SDK Patch"
if: matrix.patch == true
shell: bash
working-directory: micropython
run: |
$GITHUB_WORKSPACE/pimoroni-pico-${{ github.sha }}/micropython/board/pico-sdk-patch.sh ${{matrix.board}}
- name: Configure MicroPython (Local Board Dir)
if: matrix.local_board_dir == true
shell: bash
working-directory: micropython/ports/rp2
run: |
../../../pimoroni-pico-${GITHUB_SHA}/micropython/_board/board-fixup.sh ${{matrix.name}} ${{matrix.board}} ../../../pimoroni-pico-${GITHUB_SHA}/micropython/_board
- name: Configure MicroPython
cmake -S . -B build-${{matrix.board}} -DPICO_BUILD_DOCS=0 -DUSER_C_MODULES=${{env.USER_C_MODULES}} -DMICROPY_BOARD_DIR=${{env.MICROPY_BOARD_DIR}} -DMICROPY_BOARD=${{matrix.board}} -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
- name: Configure MicroPython (Upstream Board Dir)
if: matrix.local_board_dir != true
shell: bash
working-directory: micropython/ports/rp2
run: |
cmake -S . -B build-${{matrix.board}} -DPICO_BUILD_DOCS=0 -DUSER_C_MODULES=../../../pimoroni-pico-${GITHUB_SHA}/micropython/modules/micropython-${{matrix.name}}.cmake -DMICROPY_BOARD=${{matrix.board}} -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
cmake -S . -B build-${{matrix.board}} -DPICO_BUILD_DOCS=0 -DUSER_C_MODULES=${{env.USER_C_MODULES}} -DMICROPY_BOARD=${{matrix.board}} -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
- name: Build MicroPython
shell: bash
working-directory: micropython/ports/rp2
@ -124,13 +158,14 @@ jobs:
- name: Rename .uf2 for artifact
shell: bash
working-directory: micropython/ports/rp2/build-${{matrix.board}}
run: cp firmware.uf2 $RELEASE_FILE
run: |
cp firmware.uf2 $RELEASE_FILE.uf2
- name: Store .uf2 as artifact
uses: actions/upload-artifact@v3
with:
name: ${{env.RELEASE_FILE}}
path: micropython/ports/rp2/build-${{matrix.board}}/${{env.RELEASE_FILE}}
name: ${{env.RELEASE_FILE}}.uf2
path: micropython/ports/rp2/build-${{matrix.board}}/${{env.RELEASE_FILE}}.uf2
- name: Upload .uf2
if: github.event_name == 'release'
@ -140,5 +175,5 @@ jobs:
with:
asset_path: micropython/ports/rp2/build-${{matrix.board}}/firmware.uf2
upload_url: ${{github.event.release.upload_url}}
asset_name: ${{env.RELEASE_FILE}}
asset_name: ${{env.RELEASE_FILE}}.uf2
asset_content_type: application/octet-stream

View File

@ -1,17 +0,0 @@
{
"deploy": [
"../deploy.md"
],
"docs": "",
"features": [
"296*128 e-Ink",
"Buttons"
],
"images": [
],
"mcu": "rp2040",
"product": "Badger2040 (2MiB)",
"thumbnail": "",
"url": "https://shop.pimoroni.com/products/badger-2040",
"vendor": "Pimoroni"
}

View File

@ -1 +0,0 @@
# cmake file for Pimoroni Badger 2040

View File

@ -1,3 +0,0 @@
// This is a hack! Need to replace with upstream board definition.
#define MICROPY_HW_BOARD_NAME "Pimoroni Badger2040 2MB"
#define MICROPY_HW_FLASH_STORAGE_BYTES (1024 * 1024)

View File

@ -1,6 +0,0 @@
SRC_DIR=$1
DST_DIR=$2
echo "Applying wakeup_gpio.patch"
cd "$DST_DIR/../../lib/pico-sdk"
git apply "$SRC_DIR/wakeup_gpio.patch"

View File

@ -1,116 +0,0 @@
/*
* Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
// -----------------------------------------------------
// NOTE: THIS HEADER IS ALSO INCLUDED BY ASSEMBLER SO
// SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES
// -----------------------------------------------------
#ifndef _BOARDS_PIMORONI_BADGER2040_H
#define _BOARDS_PIMORONI_BADGER2040_H
// For board detection
#define PIMORONI_BADGER2040
// --- BOARD SPECIFIC ---
#define BADGER2040_UART 0
#define BADGER2040_TX_PIN 0
#define BADGER2040_RX_PIN 1
#define BADGER2040_I2C 0
#define BADGER2040_INT_PIN 3
#define BADGER2040_SDA_PIN 4
#define BADGER2040_SCL_PIN 5
#define BADGER2040_3V3_EN_PIN 10
#define BADGER2040_SW_DOWN_PIN 11
#define BADGER2040_SW_A_PIN 12
#define BADGER2040_SW_B_PIN 13
#define BADGER2040_SW_C_PIN 14
#define BADGER2040_SW_UP_PIN 15
#define BADGER2040_INKY_SPI 0
#define BADGER2040_INKY_MISO_PIN 16
#define BADGER2040_INKY_CSN_PIN 17
#define BADGER2040_INKY_SCK_PIN 18
#define BADGER2040_INKY_MOSI_PIN 19
#define BADGER2040_INKY_DC_PIN 20
#define BADGER2040_INKY_RESET_PIN 21
#define BADGER2040_INKY_BUSY_PIN 26
#define BADGER2040_USER_SW_PIN 23
#define BADGER2040_USER_LED_PIN 25
#define BADGER2040_VBUS_DETECT_PIN 24
#define BADGER2040_VREF_POWER_PIN 27
#define BADGER2040_1V2_REF_PIN 28
#define BADGER2040_BAT_SENSE_PIN 29
// --- UART ---
#ifndef PICO_DEFAULT_UART
#define PICO_DEFAULT_UART BADGER2040_UART
#endif
#ifndef PICO_DEFAULT_UART_TX_PIN
#define PICO_DEFAULT_UART_TX_PIN BADGER2040_TX_PIN
#endif
#ifndef PICO_DEFAULT_UART_RX_PIN
#define PICO_DEFAULT_UART_RX_PIN BADGER2040_RX_PIN
#endif
// --- LED ---
#ifndef PICO_DEFAULT_LED_PIN
#define PICO_DEFAULT_LED_PIN BADGER2040_USER_LED_PIN
#endif
// no PICO_DEFAULT_WS2812_PIN
// --- I2C ---
#ifndef PICO_DEFAULT_I2C
#define PICO_DEFAULT_I2C BADGER2040_I2C
#endif
#ifndef PICO_DEFAULT_I2C_SDA_PIN
#define PICO_DEFAULT_I2C_SDA_PIN BADGER2040_SDA_PIN
#endif
#ifndef PICO_DEFAULT_I2C_SCL_PIN
#define PICO_DEFAULT_I2C_SCL_PIN BADGER2040_SCL_PIN
#endif
// --- SPI ---
#ifndef PICO_DEFAULT_SPI
#define PICO_DEFAULT_SPI BADGER2040_INKY_SPI
#endif
#ifndef PICO_DEFAULT_SPI_SCK_PIN
#define PICO_DEFAULT_SPI_SCK_PIN BADGER2040_INKY_SCK_PIN
#endif
#ifndef PICO_DEFAULT_SPI_TX_PIN
#define PICO_DEFAULT_SPI_TX_PIN BADGER2040_INKY_MOSI_PIN
#endif
#ifndef PICO_DEFAULT_SPI_RX_PIN
#define PICO_DEFAULT_SPI_RX_PIN BADGER2040_INKY_MISO_PIN
#endif
#ifndef PICO_DEFAULT_SPI_CSN_PIN
#define PICO_DEFAULT_SPI_CSN_PIN BADGER2040_INKY_CSN_PIN
#endif
// --- FLASH ---
#define PICO_BOOT_STAGE2_CHOOSE_W25Q080 1
#ifndef PICO_FLASH_SPI_CLKDIV
#define PICO_FLASH_SPI_CLKDIV 2
#endif
#ifndef PICO_FLASH_SIZE_BYTES
#define PICO_FLASH_SIZE_BYTES (2 * 1024 * 1024)
#endif
// All boards have B1 RP2040
#ifndef PICO_RP2040_B0_SUPPORTED
#define PICO_RP2040_B0_SUPPORTED 0
#endif
#endif

View File

@ -1,138 +0,0 @@
diff --git a/src/rp2_common/pico_runtime/runtime.c b/src/rp2_common/pico_runtime/runtime.c
index f9018d0..ae8c479 100644
--- a/src/rp2_common/pico_runtime/runtime.c
+++ b/src/rp2_common/pico_runtime/runtime.c
@@ -20,6 +20,7 @@
#include "hardware/clocks.h"
#include "hardware/irq.h"
#include "hardware/resets.h"
+#include "hardware/gpio.h"
#include "pico/mutex.h"
#include "pico/time.h"
@@ -35,6 +36,21 @@
#include "pico/bootrom.h"
#endif
+// Pins to toggle on wakeup
+#ifndef PICO_WAKEUP_PIN_MASK
+#define PICO_WAKEUP_PIN_MASK ((0b1 << 10) | (0b1 << 25))
+#endif
+
+// Direction
+#ifndef PICO_WAKEUP_PIN_DIR
+#define PICO_WAKEUP_PIN_DIR ((0b1 << 10) | (0b1 << 25))
+#endif
+
+// Value
+#ifndef PICO_WAKEUP_PIN_VALUE
+#define PICO_WAKEUP_PIN_VALUE ((0b1 << 10) | (0b1 << 25))
+#endif
+
extern char __StackLimit; /* Set by linker. */
uint32_t __attribute__((section(".ram_vector_table"))) ram_vector_table[48];
@@ -64,7 +80,13 @@ void runtime_install_stack_guard(void *stack_bottom) {
| 0x10000000; // XN = disable instruction fetch; no other bits means no permissions
}
-void runtime_init(void) {
+void runtime_user_init(void) {
+ gpio_init_mask(PICO_WAKEUP_PIN_MASK);
+ gpio_set_dir_masked(PICO_WAKEUP_PIN_MASK, PICO_WAKEUP_PIN_DIR);
+ gpio_put_masked(PICO_WAKEUP_PIN_MASK, PICO_WAKEUP_PIN_VALUE);
+}
+
+void runtime_reset_peripherals(void) {
// Reset all peripherals to put system into a known state,
// - except for QSPI pads and the XIP IO bank, as this is fatal if running from flash
// - and the PLLs, as this is fatal if clock muxing has not been reset on this boot
@@ -89,7 +111,9 @@ void runtime_init(void) {
RESETS_RESET_UART1_BITS |
RESETS_RESET_USBCTRL_BITS
));
+}
+void runtime_init(void) {
// pre-init runs really early since we need it even for memcpy and divide!
// (basically anything in aeabi that uses bootrom)
diff --git a/src/rp2_common/pico_standard_link/crt0.S b/src/rp2_common/pico_standard_link/crt0.S
index d061108..e48d870 100644
--- a/src/rp2_common/pico_standard_link/crt0.S
+++ b/src/rp2_common/pico_standard_link/crt0.S
@@ -10,6 +10,8 @@
#include "hardware/regs/sio.h"
#include "pico/asm_helper.S"
#include "pico/binary_info/defs.h"
+#include "hardware/regs/resets.h"
+#include "hardware/regs/rosc.h"
#ifdef NDEBUG
#ifndef COLLAPSE_IRQS
@@ -226,6 +228,23 @@ _reset_handler:
cmp r0, #0
bne hold_non_core0_in_bootrom
+ // Increase ROSC frequency to ~48MHz (range 14.4 - 96)
+ // Startup drops from ~160ms to ~32ms on Pico W MicroPython
+ ldr r0, =(ROSC_BASE + ROSC_DIV_OFFSET)
+ ldr r1, =0xaa2
+ str r1, [r0]
+
+ ldr r1, =runtime_reset_peripherals
+ blx r1
+
+ ldr r1, =runtime_user_init
+ blx r1
+
+ // Read GPIO state for front buttons and store
+ movs r3, 0xd0 // Load 0xd0 into r3
+ lsls r3, r3, 24 // Shift left 24 to get 0xd0000000
+ ldr r6, [r3, 4] // Load GPIO state (0xd0000004) into r6
+
// In a NO_FLASH binary, don't perform .data copy, since it's loaded
// in-place by the SRAM load. Still need to clear .bss
#if !PICO_NO_FLASH
@@ -252,6 +271,10 @@ bss_fill_test:
cmp r1, r2
bne bss_fill_loop
+ // runtime_wakeup_gpio_state gets zero init above
+ ldr r2, =runtime_wakeup_gpio_state // Load output var addr into r2
+ str r6, [r2] // Store r6 to r2
+
platform_entry: // symbol for stack traces
// Use 32-bit jumps, in case these symbols are moved out of branch range
// (e.g. if main is in SRAM and crt0 in flash)
@@ -311,6 +334,19 @@ data_cpy_table:
runtime_init:
bx lr
+.weak runtime_user_init
+.type runtime_user_init,%function
+.thumb_func
+runtime_user_init:
+ bx lr
+
+.weak runtime_reset_peripherals
+.type runtime_reset_peripherals,%function
+.thumb_func
+runtime_reset_peripherals:
+ bx lr
+
+
// ----------------------------------------------------------------------------
// If core 1 somehow gets into crt0 due to a spectacular VTOR mishap, we need to
// catch it and send back to the sleep-and-launch code in the bootrom. Shouldn't
@@ -335,3 +371,9 @@ hold_non_core0_in_bootrom:
.align 2
.equ HeapSize, PICO_HEAP_SIZE
.space HeapSize
+
+.section .data._reset_handler
+.global runtime_wakeup_gpio_state
+.align 4
+runtime_wakeup_gpio_state:
+.word 0x00000000
\ No newline at end of file

View File

@ -1,17 +0,0 @@
{
"deploy": [
"../deploy.md"
],
"docs": "",
"features": [
"296*128 e-Ink",
"Buttons"
],
"images": [
],
"mcu": "rp2040",
"product": "Badger2040 W (2MiB)",
"thumbnail": "",
"url": "https://shop.pimoroni.com/products/badger-2040w",
"vendor": "Pimoroni"
}

View File

@ -1,7 +0,0 @@
include("../manifest.py")
require("mip")
require("ntptime")
require("urequests")
require("urllib.urequest")
require("umqtt.simple")

View File

@ -1,8 +0,0 @@
# cmake file for Pimoroni Badger 2040W
set(MICROPY_BOARD PICO_W)
set(MICROPY_PY_LWIP ON)
set(MICROPY_PY_NETWORK_CYW43 ON)
# Board specific version of the frozen manifest
set(MICROPY_FROZEN_MANIFEST ${CMAKE_SOURCE_DIR}/boards/PIMORONI_BADGER2040W/manifest.py)

View File

@ -1,20 +0,0 @@
// This is a hack! Need to replace with upstream board definition.
#define MICROPY_HW_BOARD_NAME "Pimoroni Badger2040W 2MB"
#define MICROPY_HW_FLASH_STORAGE_BYTES (848 * 1024)
// Enable networking.
#define MICROPY_PY_NETWORK 1
// CYW43 driver configuration.
#define CYW43_USE_SPI (1)
#define CYW43_LWIP (1)
#define CYW43_GPIO (1)
#define CYW43_SPI_PIO (1)
// For debugging mbedtls - also set
// Debug level (0-4) 1=warning, 2=info, 3=debug, 4=verbose
// #define MODUSSL_MBEDTLS_DEBUG_LEVEL 1
#define MICROPY_HW_PIN_EXT_COUNT CYW43_WL_GPIO_COUNT
#define MICROPY_HW_PIN_RESERVED(i) ((i) == CYW43_PIN_WL_HOST_WAKE || (i) == CYW43_PIN_WL_REG_ON)

View File

@ -1,30 +0,0 @@
GP0,GPIO0
GP1,GPIO1
GP2,GPIO2
GP3,GPIO3
GP4,GPIO4
GP5,GPIO5
GP6,GPIO6
GP7,GPIO7
GP8,GPIO8
GP9,GPIO9
GP10,GPIO10
GP11,GPIO11
GP12,GPIO12
GP13,GPIO13
GP14,GPIO14
GP15,GPIO15
GP16,GPIO16
GP17,GPIO17
GP18,GPIO18
GP19,GPIO19
GP20,GPIO20
GP21,GPIO21
GP22,GPIO22
GP26,GPIO26
GP27,GPIO27
GP28,GPIO28
WL_GPIO0,EXT_GPIO0
WL_GPIO1,EXT_GPIO1
WL_GPIO2,EXT_GPIO2
LED,EXT_GPIO0
1 GP0 GPIO0
2 GP1 GPIO1
3 GP2 GPIO2
4 GP3 GPIO3
5 GP4 GPIO4
6 GP5 GPIO5
7 GP6 GPIO6
8 GP7 GPIO7
9 GP8 GPIO8
10 GP9 GPIO9
11 GP10 GPIO10
12 GP11 GPIO11
13 GP12 GPIO12
14 GP13 GPIO13
15 GP14 GPIO14
16 GP15 GPIO15
17 GP16 GPIO16
18 GP17 GPIO17
19 GP18 GPIO18
20 GP19 GPIO19
21 GP20 GPIO20
22 GP21 GPIO21
23 GP22 GPIO22
24 GP26 GPIO26
25 GP27 GPIO27
26 GP28 GPIO28
27 WL_GPIO0 EXT_GPIO0
28 WL_GPIO1 EXT_GPIO1
29 WL_GPIO2 EXT_GPIO2
30 LED EXT_GPIO0

View File

@ -1,6 +0,0 @@
SRC_DIR=$1
DST_DIR=$2
echo "Applying wakeup_gpio.patch"
cd "$DST_DIR/../../lib/pico-sdk"
git apply "$SRC_DIR/wakeup_gpio.patch"

View File

@ -1,137 +0,0 @@
/*
* Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
// -----------------------------------------------------
// NOTE: THIS HEADER IS ALSO INCLUDED BY ASSEMBLER SO
// SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES
// -----------------------------------------------------
#ifndef _BOARDS_PIMORONI_BADGER2040_H
#define _BOARDS_PIMORONI_BADGER2040_H
// For board detection
#define RASPBERRYPI_PICO_W
#define PIMORONI_BADGER2040
#define PIMORONI_BADGER2040W
// --- BOARD SPECIFIC ---
#define BADGER2040_UART 0
#define BADGER2040_TX_PIN 0
#define BADGER2040_RX_PIN 1
#define BADGER2040_I2C 0
#define BADGER2040_INT_PIN 3
#define BADGER2040_SDA_PIN 4
#define BADGER2040_SCL_PIN 5
#define BADGER2040_3V3_EN_PIN 10
#define BADGER2040_SW_DOWN_PIN 11
#define BADGER2040_SW_A_PIN 12
#define BADGER2040_SW_B_PIN 13
#define BADGER2040_SW_C_PIN 14
#define BADGER2040_SW_UP_PIN 15
#define BADGER2040_INKY_SPI 0
#define BADGER2040_INKY_MISO_PIN 16
#define BADGER2040_INKY_CSN_PIN 17
#define BADGER2040_INKY_SCK_PIN 18
#define BADGER2040_INKY_MOSI_PIN 19
#define BADGER2040_INKY_DC_PIN 20
#define BADGER2040_INKY_RESET_PIN 21
#define BADGER2040_INKY_BUSY_PIN 26
#define BADGER2040_USER_SW_PIN 23
#define BADGER2040_USER_LED_PIN 25
#define BADGER2040_VBUS_DETECT_PIN 24
#define BADGER2040_VREF_POWER_PIN 27
#define BADGER2040_1V2_REF_PIN 28
#define BADGER2040_BAT_SENSE_PIN 29
// --- UART ---
#ifndef PICO_DEFAULT_UART
#define PICO_DEFAULT_UART BADGER2040_UART
#endif
#ifndef PICO_DEFAULT_UART_TX_PIN
#define PICO_DEFAULT_UART_TX_PIN BADGER2040_TX_PIN
#endif
#ifndef PICO_DEFAULT_UART_RX_PIN
#define PICO_DEFAULT_UART_RX_PIN BADGER2040_RX_PIN
#endif
// --- LED ---
#ifndef PICO_DEFAULT_LED_PIN
#define PICO_DEFAULT_LED_PIN BADGER2040_USER_LED_PIN
#endif
// no PICO_DEFAULT_WS2812_PIN
// --- I2C ---
#ifndef PICO_DEFAULT_I2C
#define PICO_DEFAULT_I2C BADGER2040_I2C
#endif
#ifndef PICO_DEFAULT_I2C_SDA_PIN
#define PICO_DEFAULT_I2C_SDA_PIN BADGER2040_SDA_PIN
#endif
#ifndef PICO_DEFAULT_I2C_SCL_PIN
#define PICO_DEFAULT_I2C_SCL_PIN BADGER2040_SCL_PIN
#endif
// --- SPI ---
#ifndef PICO_DEFAULT_SPI
#define PICO_DEFAULT_SPI BADGER2040_INKY_SPI
#endif
#ifndef PICO_DEFAULT_SPI_SCK_PIN
#define PICO_DEFAULT_SPI_SCK_PIN BADGER2040_INKY_SCK_PIN
#endif
#ifndef PICO_DEFAULT_SPI_TX_PIN
#define PICO_DEFAULT_SPI_TX_PIN BADGER2040_INKY_MOSI_PIN
#endif
#ifndef PICO_DEFAULT_SPI_RX_PIN
#define PICO_DEFAULT_SPI_RX_PIN BADGER2040_INKY_MISO_PIN
#endif
#ifndef PICO_DEFAULT_SPI_CSN_PIN
#define PICO_DEFAULT_SPI_CSN_PIN BADGER2040_INKY_CSN_PIN
#endif
// --- FLASH ---
#define PICO_BOOT_STAGE2_CHOOSE_W25Q080 1
#ifndef PICO_FLASH_SPI_CLKDIV
#define PICO_FLASH_SPI_CLKDIV 2
#endif
#ifndef PICO_FLASH_SIZE_BYTES
#define PICO_FLASH_SIZE_BYTES (2 * 1024 * 1024)
#endif
#ifndef PICO_RP2040_B0_SUPPORTED
#define PICO_RP2040_B0_SUPPORTED 0
#endif
#ifndef PICO_RP2040_B1_SUPPORTED
#define PICO_RP2040_B1_SUPPORTED 0
#endif
#ifndef CYW43_PIN_WL_HOST_WAKE
#define CYW43_PIN_WL_HOST_WAKE 24
#endif
#ifndef CYW43_PIN_WL_REG_ON
#define CYW43_PIN_WL_REG_ON 23
#endif
#ifndef CYW43_WL_GPIO_COUNT
#define CYW43_WL_GPIO_COUNT 3
#endif
#ifndef CYW43_WL_GPIO_LED_PIN
#define CYW43_WL_GPIO_LED_PIN 0
#endif
#endif

View File

@ -1,138 +0,0 @@
diff --git a/src/rp2_common/pico_runtime/runtime.c b/src/rp2_common/pico_runtime/runtime.c
index f9018d0..ae8c479 100644
--- a/src/rp2_common/pico_runtime/runtime.c
+++ b/src/rp2_common/pico_runtime/runtime.c
@@ -20,6 +20,7 @@
#include "hardware/clocks.h"
#include "hardware/irq.h"
#include "hardware/resets.h"
+#include "hardware/gpio.h"
#include "pico/mutex.h"
#include "pico/time.h"
@@ -35,6 +36,21 @@
#include "pico/bootrom.h"
#endif
+// Pins to toggle on wakeup
+#ifndef PICO_WAKEUP_PIN_MASK
+#define PICO_WAKEUP_PIN_MASK ((0b1 << 10) | (0b1 << 22))
+#endif
+
+// Direction
+#ifndef PICO_WAKEUP_PIN_DIR
+#define PICO_WAKEUP_PIN_DIR ((0b1 << 10) | (0b1 << 22))
+#endif
+
+// Value
+#ifndef PICO_WAKEUP_PIN_VALUE
+#define PICO_WAKEUP_PIN_VALUE ((0b1 << 10) | (0b1 << 22))
+#endif
+
extern char __StackLimit; /* Set by linker. */
uint32_t __attribute__((section(".ram_vector_table"))) ram_vector_table[48];
@@ -64,7 +80,13 @@ void runtime_install_stack_guard(void *stack_bottom) {
| 0x10000000; // XN = disable instruction fetch; no other bits means no permissions
}
-void runtime_init(void) {
+void runtime_user_init(void) {
+ gpio_init_mask(PICO_WAKEUP_PIN_MASK);
+ gpio_set_dir_masked(PICO_WAKEUP_PIN_MASK, PICO_WAKEUP_PIN_DIR);
+ gpio_put_masked(PICO_WAKEUP_PIN_MASK, PICO_WAKEUP_PIN_VALUE);
+}
+
+void runtime_reset_peripherals(void) {
// Reset all peripherals to put system into a known state,
// - except for QSPI pads and the XIP IO bank, as this is fatal if running from flash
// - and the PLLs, as this is fatal if clock muxing has not been reset on this boot
@@ -89,7 +111,9 @@ void runtime_init(void) {
RESETS_RESET_UART1_BITS |
RESETS_RESET_USBCTRL_BITS
));
+}
+void runtime_init(void) {
// pre-init runs really early since we need it even for memcpy and divide!
// (basically anything in aeabi that uses bootrom)
diff --git a/src/rp2_common/pico_standard_link/crt0.S b/src/rp2_common/pico_standard_link/crt0.S
index d061108..e48d870 100644
--- a/src/rp2_common/pico_standard_link/crt0.S
+++ b/src/rp2_common/pico_standard_link/crt0.S
@@ -10,6 +10,8 @@
#include "hardware/regs/sio.h"
#include "pico/asm_helper.S"
#include "pico/binary_info/defs.h"
+#include "hardware/regs/resets.h"
+#include "hardware/regs/rosc.h"
#ifdef NDEBUG
#ifndef COLLAPSE_IRQS
@@ -226,6 +228,23 @@ _reset_handler:
cmp r0, #0
bne hold_non_core0_in_bootrom
+ // Increase ROSC frequency to ~48MHz (range 14.4 - 96)
+ // Startup drops from ~160ms to ~32ms on Pico W MicroPython
+ ldr r0, =(ROSC_BASE + ROSC_DIV_OFFSET)
+ ldr r1, =0xaa2
+ str r1, [r0]
+
+ ldr r1, =runtime_reset_peripherals
+ blx r1
+
+ ldr r1, =runtime_user_init
+ blx r1
+
+ // Read GPIO state for front buttons and store
+ movs r3, 0xd0 // Load 0xd0 into r3
+ lsls r3, r3, 24 // Shift left 24 to get 0xd0000000
+ ldr r6, [r3, 4] // Load GPIO state (0xd0000004) into r6
+
// In a NO_FLASH binary, don't perform .data copy, since it's loaded
// in-place by the SRAM load. Still need to clear .bss
#if !PICO_NO_FLASH
@@ -252,6 +271,10 @@ bss_fill_test:
cmp r1, r2
bne bss_fill_loop
+ // runtime_wakeup_gpio_state gets zero init above
+ ldr r2, =runtime_wakeup_gpio_state // Load output var addr into r2
+ str r6, [r2] // Store r6 to r2
+
platform_entry: // symbol for stack traces
// Use 32-bit jumps, in case these symbols are moved out of branch range
// (e.g. if main is in SRAM and crt0 in flash)
@@ -311,6 +334,19 @@ data_cpy_table:
runtime_init:
bx lr
+.weak runtime_user_init
+.type runtime_user_init,%function
+.thumb_func
+runtime_user_init:
+ bx lr
+
+.weak runtime_reset_peripherals
+.type runtime_reset_peripherals,%function
+.thumb_func
+runtime_reset_peripherals:
+ bx lr
+
+
// ----------------------------------------------------------------------------
// If core 1 somehow gets into crt0 due to a spectacular VTOR mishap, we need to
// catch it and send back to the sleep-and-launch code in the bootrom. Shouldn't
@@ -335,3 +371,9 @@ hold_non_core0_in_bootrom:
.align 2
.equ HeapSize, PICO_HEAP_SIZE
.space HeapSize
+
+.section .data._reset_handler
+.global runtime_wakeup_gpio_state
+.align 4
+runtime_wakeup_gpio_state:
+.word 0x00000000
\ No newline at end of file

View File

@ -1,21 +0,0 @@
NAME=$1
BOARD=$2
FIXUP_DIR=$3
MPY_DIR=`pwd`
echo "Fixup: $NAME $BOARD $MPY_DIR"
if [[ ! -f "$MPY_DIR/../../lib/pico-sdk/src/boards/include/boards/pimoroni_$NAME.h" ]] && [[ -f "$FIXUP_DIR/$NAME/pimoroni_$NAME.h" ]]; then
echo "Missing Pico SDK board .h. Copying: $FIXUP_DIR/$NAME/pimoroni_$NAME.h to $MPY_DIR/../../lib/pico-sdk/src/boards/include/boards/pimoroni_$NAME.h"
cp "$FIXUP_DIR/$NAME/pimoroni_$NAME.h" "$MPY_DIR/../../lib/pico-sdk/src/boards/include/boards/pimoroni_$NAME.h"
fi
if [[ ! -d "$MPY_DIR/boards/$BOARD" ]] && [[ -d "$FIXUP_DIR/$NAME/$BOARD/" ]]; then
echo "Missing board dir. Copying: $FIXUP_DIR/$NAME/$BOARD/ to $MPY_DIR/boards/"
cp -r "$FIXUP_DIR/$NAME/$BOARD/" "$MPY_DIR/boards/"
fi
if [[ -f "$FIXUP_DIR/$NAME/fixup.sh" ]]; then
echo "Running custom fixup.sh"
bash "$FIXUP_DIR/$NAME/fixup.sh" "$FIXUP_DIR/$NAME" "$MPY_DIR"
fi

View File

@ -1,6 +0,0 @@
include("../manifest.py")
require("mip")
require("ntptime")
require("urequests")
require("umqtt.simple")

View File

@ -1,8 +0,0 @@
# cmake file for Raspberry Pi Pico W
set(MICROPY_BOARD PICO_W)
set(MICROPY_PY_LWIP ON)
set(MICROPY_PY_NETWORK_CYW43 ON)
# Board specific version of the frozen manifest
set(MICROPY_FROZEN_MANIFEST ${CMAKE_SOURCE_DIR}/boards/PICO_W_ENVIRO/manifest.py)

View File

@ -1,6 +0,0 @@
SRC_DIR=$1
DST_DIR=$2
echo "Applying wakeup_gpio.patch"
cd "$DST_DIR/../../lib/pico-sdk"
git apply "$SRC_DIR/wakeup_gpio.patch"

View File

@ -1,102 +0,0 @@
/*
* Copyright (c) 2022 Raspberry Pi (Trading) Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
// -----------------------------------------------------
// NOTE: THIS HEADER IS ALSO INCLUDED BY ASSEMBLER SO
// SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES
// -----------------------------------------------------
// This header may be included by other board headers as "boards/pico.h"
#ifndef _BOARDS_PICO_W_H
#define _BOARDS_PICO_W_H
// For board detection
#define RASPBERRYPI_PICO_W
// --- UART ---
#ifndef PICO_DEFAULT_UART
#define PICO_DEFAULT_UART 0
#endif
#ifndef PICO_DEFAULT_UART_TX_PIN
#define PICO_DEFAULT_UART_TX_PIN 0
#endif
#ifndef PICO_DEFAULT_UART_RX_PIN
#define PICO_DEFAULT_UART_RX_PIN 1
#endif
// --- LED ---
// no PICO_DEFAULT_LED_PIN - LED is on Wireless chip
// no PICO_DEFAULT_WS2812_PIN
// --- I2C ---
#ifndef PICO_DEFAULT_I2C
#define PICO_DEFAULT_I2C 0
#endif
#ifndef PICO_DEFAULT_I2C_SDA_PIN
#define PICO_DEFAULT_I2C_SDA_PIN 4
#endif
#ifndef PICO_DEFAULT_I2C_SCL_PIN
#define PICO_DEFAULT_I2C_SCL_PIN 5
#endif
// --- SPI ---
#ifndef PICO_DEFAULT_SPI
#define PICO_DEFAULT_SPI 0
#endif
#ifndef PICO_DEFAULT_SPI_SCK_PIN
#define PICO_DEFAULT_SPI_SCK_PIN 18
#endif
#ifndef PICO_DEFAULT_SPI_TX_PIN
#define PICO_DEFAULT_SPI_TX_PIN 19
#endif
#ifndef PICO_DEFAULT_SPI_RX_PIN
#define PICO_DEFAULT_SPI_RX_PIN 16
#endif
#ifndef PICO_DEFAULT_SPI_CSN_PIN
#define PICO_DEFAULT_SPI_CSN_PIN 17
#endif
// --- FLASH ---
#define PICO_BOOT_STAGE2_CHOOSE_W25Q080 1
#ifndef PICO_FLASH_SPI_CLKDIV
#define PICO_FLASH_SPI_CLKDIV 2
#endif
#ifndef PICO_FLASH_SIZE_BYTES
#define PICO_FLASH_SIZE_BYTES (2 * 1024 * 1024)
#endif
// note the SMSP mode pin is on WL_GPIO1
// #define PICO_SMPS_MODE_PIN
#ifndef PICO_RP2040_B0_SUPPORTED
#define PICO_RP2040_B0_SUPPORTED 0
#endif
#ifndef PICO_RP2040_B1_SUPPORTED
#define PICO_RP2040_B1_SUPPORTED 0
#endif
#ifndef CYW43_PIN_WL_HOST_WAKE
#define CYW43_PIN_WL_HOST_WAKE 24
#endif
#ifndef CYW43_PIN_WL_REG_ON
#define CYW43_PIN_WL_REG_ON 23
#endif
#ifndef CYW43_WL_GPIO_COUNT
#define CYW43_WL_GPIO_COUNT 3
#endif
#ifndef CYW43_WL_GPIO_LED_PIN
#define CYW43_WL_GPIO_LED_PIN 0
#endif
#endif

View File

@ -1,8 +0,0 @@
# cmake file for Raspberry Pi Pico W
set(MICROPY_BOARD PICO_W)
set(MICROPY_PY_LWIP ON)
set(MICROPY_PY_NETWORK_CYW43 ON)
# Board specific version of the frozen manifest
set(MICROPY_FROZEN_MANIFEST ${CMAKE_SOURCE_DIR}/boards/PICO_W_INKY/manifest.py)

View File

@ -1,6 +0,0 @@
SRC_DIR=$1
DST_DIR=$2
echo "Applying wakeup_gpio.patch"
cd "$DST_DIR/../../lib/pico-sdk"
git apply "$SRC_DIR/wakeup_gpio.patch"

View File

@ -1,102 +0,0 @@
/*
* Copyright (c) 2022 Raspberry Pi (Trading) Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
// -----------------------------------------------------
// NOTE: THIS HEADER IS ALSO INCLUDED BY ASSEMBLER SO
// SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES
// -----------------------------------------------------
// This header may be included by other board headers as "boards/pico.h"
#ifndef _BOARDS_PICO_W_H
#define _BOARDS_PICO_W_H
// For board detection
#define RASPBERRYPI_PICO_W
// --- UART ---
#ifndef PICO_DEFAULT_UART
#define PICO_DEFAULT_UART 0
#endif
#ifndef PICO_DEFAULT_UART_TX_PIN
#define PICO_DEFAULT_UART_TX_PIN 0
#endif
#ifndef PICO_DEFAULT_UART_RX_PIN
#define PICO_DEFAULT_UART_RX_PIN 1
#endif
// --- LED ---
// no PICO_DEFAULT_LED_PIN - LED is on Wireless chip
// no PICO_DEFAULT_WS2812_PIN
// --- I2C ---
#ifndef PICO_DEFAULT_I2C
#define PICO_DEFAULT_I2C 0
#endif
#ifndef PICO_DEFAULT_I2C_SDA_PIN
#define PICO_DEFAULT_I2C_SDA_PIN 4
#endif
#ifndef PICO_DEFAULT_I2C_SCL_PIN
#define PICO_DEFAULT_I2C_SCL_PIN 5
#endif
// --- SPI ---
#ifndef PICO_DEFAULT_SPI
#define PICO_DEFAULT_SPI 0
#endif
#ifndef PICO_DEFAULT_SPI_SCK_PIN
#define PICO_DEFAULT_SPI_SCK_PIN 18
#endif
#ifndef PICO_DEFAULT_SPI_TX_PIN
#define PICO_DEFAULT_SPI_TX_PIN 19
#endif
#ifndef PICO_DEFAULT_SPI_RX_PIN
#define PICO_DEFAULT_SPI_RX_PIN 16
#endif
#ifndef PICO_DEFAULT_SPI_CSN_PIN
#define PICO_DEFAULT_SPI_CSN_PIN 17
#endif
// --- FLASH ---
#define PICO_BOOT_STAGE2_CHOOSE_W25Q080 1
#ifndef PICO_FLASH_SPI_CLKDIV
#define PICO_FLASH_SPI_CLKDIV 2
#endif
#ifndef PICO_FLASH_SIZE_BYTES
#define PICO_FLASH_SIZE_BYTES (2 * 1024 * 1024)
#endif
// note the SMSP mode pin is on WL_GPIO1
// #define PICO_SMPS_MODE_PIN
#ifndef PICO_RP2040_B0_SUPPORTED
#define PICO_RP2040_B0_SUPPORTED 0
#endif
#ifndef PICO_RP2040_B1_SUPPORTED
#define PICO_RP2040_B1_SUPPORTED 0
#endif
#ifndef CYW43_PIN_WL_HOST_WAKE
#define CYW43_PIN_WL_HOST_WAKE 24
#endif
#ifndef CYW43_PIN_WL_REG_ON
#define CYW43_PIN_WL_REG_ON 23
#endif
#ifndef CYW43_WL_GPIO_COUNT
#define CYW43_WL_GPIO_COUNT 3
#endif
#ifndef CYW43_WL_GPIO_LED_PIN
#define CYW43_WL_GPIO_LED_PIN 0
#endif
#endif

View File

@ -1 +0,0 @@
# cmake file for Pimoroni Tufty 2040

View File

@ -0,0 +1,6 @@
include("$(PORT_DIR)/boards/manifest.py")
require("mip")
require("ntptime")
require("urequests")
require("umqtt.simple")

View File

@ -0,0 +1,5 @@
# cmake file for Raspberry Pi Pico W
set(MICROPY_BOARD PICO_W)
set(MICROPY_PY_LWIP ON)
set(MICROPY_PY_NETWORK_CYW43 ON)

View File

@ -1,4 +1,4 @@
include("../manifest.py")
include("$(PORT_DIR)/boards/manifest.py")
require("mip")
require("ntptime")

View File

@ -0,0 +1,5 @@
# cmake file for Raspberry Pi Pico W
set(MICROPY_BOARD PICO_W)
set(MICROPY_PY_LWIP ON)
set(MICROPY_PY_NETWORK_CYW43 ON)

View File

@ -0,0 +1,5 @@
# cmake file for Pimoroni Tufty 2040
set(PICO_BOARD "pimoroni_tufty2040")
# Allow Pico SDK to locate "pimoroni_tufty2040.h" in this directory.
list(APPEND PICO_BOARD_HEADER_DIRS "${CMAKE_CURRENT_LIST_DIR}")

View File

@ -0,0 +1,10 @@
BOARD=$1
FIXUP_DIR="$(dirname -- "$(readlink -f "${BASH_SOURCE}")")"
MPY_DIR=`pwd`
if [[ -f "$FIXUP_DIR/$BOARD/pico_sdk.patch" ]]; then
echo "Applying pico_sdk.patch"
cd $MPY_DIR/lib/pico-sdk
git apply "$FIXUP_DIR/$BOARD/pico_sdk.patch"
fi