Skip to content

Commit

Permalink
Merge pull request #716 from pimoroni/feature/bluetooth
Browse files Browse the repository at this point in the history
MicroPython: Pico W Bluetooth Support
  • Loading branch information
Gadgetoid authored Jun 16, 2023
2 parents 9d96d06 + 090ce9d commit d523ede
Show file tree
Hide file tree
Showing 12 changed files with 64 additions and 34 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/micropython.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ on:
types: [created]

env:
MICROPYTHON_VERSION: v1.20.0
WORKFLOW_VERSION: v0
MICROPYTHON_VERSION: 856e08b1931b88271816a2f60648f6ff332235b2
WORKFLOW_VERSION: v1

jobs:
deps:
Expand Down Expand Up @@ -53,6 +53,7 @@ jobs:
git submodule update --init ../../lib/mbedtls
git submodule update --init ../../lib/micropython-lib
git submodule update --init ../../lib/tinyusb
git submodule update --init ../../lib/btstack
- name: Build mpy-cross
if: steps.cache.outputs.cache-hit != 'true'
Expand Down
3 changes: 2 additions & 1 deletion micropython/board/PICO_W/board.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"Breadboard friendly",
"Castellated Pads",
"Micro USB",
"WiFi"
"WiFi",
"Bluetooth"
],
"id": "rp2-pico-w",
"images": [
Expand Down
3 changes: 3 additions & 0 deletions micropython/board/PICO_W/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@

require("bundle-networking")

# Bluetooth
require("aioble")

include("../manifest_picow.py")
13 changes: 10 additions & 3 deletions micropython/board/PICO_W/mpconfigboard.cmake
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
# cmake file for Raspberry Pi Pico W

# The C malloc is needed by cyw43-driver Bluetooth and Pimoroni Pico modules
set(MICROPY_C_HEAP_SIZE 4096)

set(MICROPY_PY_LWIP ON)
set(MICROPY_PY_NETWORK_CYW43 ON)

# Board specific version of the frozen manifest
set(MICROPY_FROZEN_MANIFEST ${MICROPY_BOARD_DIR}/manifest.py)
# Bluetooth
set(MICROPY_PY_BLUETOOTH ON)
set(MICROPY_BLUETOOTH_BTSTACK ON)
set(MICROPY_PY_BLUETOOTH_CYW43 ON)

set(MICROPY_C_HEAP_SIZE 4096)
# Board specific version of the frozen manifest
set(MICROPY_FROZEN_MANIFEST ${MICROPY_BOARD_DIR}/manifest.py)
3 changes: 2 additions & 1 deletion micropython/board/PICO_W_ENVIRO/board.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"Breadboard friendly",
"Castellated Pads",
"Micro USB",
"WiFi"
"WiFi",
"Bluetooth"
],
"id": "rp2-pico-w",
"images": [
Expand Down
3 changes: 3 additions & 0 deletions micropython/board/PICO_W_ENVIRO/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@
require("bundle-networking")
require("umqtt.simple")

# Bluetooth
require("aioble")

freeze("../../modules_py", "pimoroni.py")
freeze("../../modules_py", "boot.py")
11 changes: 9 additions & 2 deletions micropython/board/PICO_W_ENVIRO/mpconfigboard.cmake
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
# cmake file for Pimoroni Enviro with Raspberry Pi Pico W
set(MICROPY_BOARD PICO_W)

# The C malloc is needed by cyw43-driver Bluetooth and Pimoroni Pico modules
set(MICROPY_C_HEAP_SIZE 4096)

set(MICROPY_PY_LWIP ON)
set(MICROPY_PY_NETWORK_CYW43 ON)

set(MICROPY_FROZEN_MANIFEST ${MICROPY_BOARD_DIR}/manifest.py)
# Bluetooth
set(MICROPY_PY_BLUETOOTH ON)
set(MICROPY_BLUETOOTH_BTSTACK ON)
set(MICROPY_PY_BLUETOOTH_CYW43 ON)

set(MICROPY_C_HEAP_SIZE 4096)
# Board specific version of the frozen manifest
set(MICROPY_FROZEN_MANIFEST ${MICROPY_BOARD_DIR}/manifest.py)
20 changes: 9 additions & 11 deletions micropython/board/PICO_W_ENVIRO/pico_sdk.patch
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/src/rp2_common/pico_runtime/runtime.c b/src/rp2_common/pico_runtime/runtime.c
index f9018d0..ae8c479 100644
index 144ace1..52bb6c9 100644
--- a/src/rp2_common/pico_runtime/runtime.c
+++ b/src/rp2_common/pico_runtime/runtime.c
@@ -20,6 +20,7 @@
Expand Down Expand Up @@ -58,19 +58,19 @@ index f9018d0..ae8c479 100644
// (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
index 7d29f76..799ce19 100644
--- a/src/rp2_common/pico_standard_link/crt0.S
+++ b/src/rp2_common/pico_standard_link/crt0.S
@@ -10,6 +10,8 @@
@@ -11,6 +11,8 @@
#include "hardware/regs/addressmap.h"
#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:
@@ -225,6 +227,23 @@ _reset_handler:
cmp r0, #0
bne hold_non_core0_in_bootrom

Expand All @@ -94,7 +94,7 @@ index d061108..e48d870 100644
// 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:
@@ -251,6 +270,10 @@ bss_fill_test:
cmp r1, r2
bne bss_fill_loop

Expand All @@ -105,7 +105,7 @@ index d061108..e48d870 100644
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:
@@ -310,6 +333,18 @@ data_cpy_table:
runtime_init:
bx lr

Expand All @@ -120,13 +120,12 @@ index d061108..e48d870 100644
+.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
@@ -350,3 +385,9 @@ spacer_section .heap
.p2align 2
.equ HeapSize, PICO_HEAP_SIZE
.space HeapSize
+
Expand All @@ -135,4 +134,3 @@ index d061108..e48d870 100644
+.align 4
+runtime_wakeup_gpio_state:
+.word 0x00000000
\ No newline at end of file
3 changes: 2 additions & 1 deletion micropython/board/PICO_W_INKY/board.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"Breadboard friendly",
"Castellated Pads",
"Micro USB",
"WiFi"
"WiFi",
"Bluetooth"
],
"id": "rp2-pico-w",
"images": [
Expand Down
3 changes: 3 additions & 0 deletions micropython/board/PICO_W_INKY/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@
require("urllib.urequest")
require("umqtt.simple")

# Bluetooth
require("aioble")

freeze("../../modules_py", "pimoroni.py")
freeze("../../modules_py", "boot.py")
11 changes: 9 additions & 2 deletions micropython/board/PICO_W_INKY/mpconfigboard.cmake
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
# cmake file for Pimoroni Inky with Raspberry Pi Pico W
set(MICROPY_BOARD PICO_W)

# The C malloc is needed by cyw43-driver Bluetooth and Pimoroni Pico modules
set(MICROPY_C_HEAP_SIZE 4096)

set(MICROPY_PY_LWIP ON)
set(MICROPY_PY_NETWORK_CYW43 ON)

set(MICROPY_FROZEN_MANIFEST ${MICROPY_BOARD_DIR}/manifest.py)
# Bluetooth
set(MICROPY_PY_BLUETOOTH ON)
set(MICROPY_BLUETOOTH_BTSTACK ON)
set(MICROPY_PY_BLUETOOTH_CYW43 ON)

set(MICROPY_C_HEAP_SIZE 4096)
# Board specific version of the frozen manifest
set(MICROPY_FROZEN_MANIFEST ${MICROPY_BOARD_DIR}/manifest.py)
20 changes: 9 additions & 11 deletions micropython/board/PICO_W_INKY/pico_sdk.patch
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/src/rp2_common/pico_runtime/runtime.c b/src/rp2_common/pico_runtime/runtime.c
index f9018d0..ae8c479 100644
index 144ace1..52bb6c9 100644
--- a/src/rp2_common/pico_runtime/runtime.c
+++ b/src/rp2_common/pico_runtime/runtime.c
@@ -20,6 +20,7 @@
Expand Down Expand Up @@ -58,19 +58,19 @@ index f9018d0..ae8c479 100644
// (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
index 7d29f76..799ce19 100644
--- a/src/rp2_common/pico_standard_link/crt0.S
+++ b/src/rp2_common/pico_standard_link/crt0.S
@@ -10,6 +10,8 @@
@@ -11,6 +11,8 @@
#include "hardware/regs/addressmap.h"
#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:
@@ -225,6 +227,23 @@ _reset_handler:
cmp r0, #0
bne hold_non_core0_in_bootrom

Expand All @@ -94,7 +94,7 @@ index d061108..e48d870 100644
// 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:
@@ -251,6 +270,10 @@ bss_fill_test:
cmp r1, r2
bne bss_fill_loop

Expand All @@ -105,7 +105,7 @@ index d061108..e48d870 100644
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:
@@ -310,6 +333,18 @@ data_cpy_table:
runtime_init:
bx lr

Expand All @@ -120,13 +120,12 @@ index d061108..e48d870 100644
+.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
@@ -350,3 +385,9 @@ spacer_section .heap
.p2align 2
.equ HeapSize, PICO_HEAP_SIZE
.space HeapSize
+
Expand All @@ -135,4 +134,3 @@ index d061108..e48d870 100644
+.align 4
+runtime_wakeup_gpio_state:
+.word 0x00000000
\ No newline at end of file

0 comments on commit d523ede

Please sign in to comment.