From bdbc44474f92db19a40b5f710a140a0bf70fb0ec Mon Sep 17 00:00:00 2001 From: Matt Trentini Date: Thu, 7 Apr 2022 23:33:36 +1000 Subject: [PATCH] rp2/boards/WEACTSTUDIO: Add WEACTSTUDIO with multiple variants. This supports 2, 4, 8 and 16MB flash variants. --- ports/rp2/boards/WEACTSTUDIO/README.md | 34 ++++++++++ ports/rp2/boards/WEACTSTUDIO/board.json | 23 +++++++ ports/rp2/boards/WEACTSTUDIO/deploy.md | 8 +++ ports/rp2/boards/WEACTSTUDIO/manifest.py | 2 + ports/rp2/boards/WEACTSTUDIO/modules/board.py | 4 ++ .../boards/WEACTSTUDIO/mpconfigboard.cmake | 26 ++++++++ ports/rp2/boards/WEACTSTUDIO/mpconfigboard.h | 4 ++ .../rp2/boards/WEACTSTUDIO/weactstudio_16mb.h | 18 ++++++ .../rp2/boards/WEACTSTUDIO/weactstudio_2mb.h | 18 ++++++ .../rp2/boards/WEACTSTUDIO/weactstudio_4mb.h | 18 ++++++ .../rp2/boards/WEACTSTUDIO/weactstudio_8mb.h | 18 ++++++ .../boards/WEACTSTUDIO/weactstudio_common.h | 62 +++++++++++++++++++ 12 files changed, 235 insertions(+) create mode 100644 ports/rp2/boards/WEACTSTUDIO/README.md create mode 100644 ports/rp2/boards/WEACTSTUDIO/board.json create mode 100644 ports/rp2/boards/WEACTSTUDIO/deploy.md create mode 100644 ports/rp2/boards/WEACTSTUDIO/manifest.py create mode 100644 ports/rp2/boards/WEACTSTUDIO/modules/board.py create mode 100644 ports/rp2/boards/WEACTSTUDIO/mpconfigboard.cmake create mode 100644 ports/rp2/boards/WEACTSTUDIO/mpconfigboard.h create mode 100644 ports/rp2/boards/WEACTSTUDIO/weactstudio_16mb.h create mode 100644 ports/rp2/boards/WEACTSTUDIO/weactstudio_2mb.h create mode 100644 ports/rp2/boards/WEACTSTUDIO/weactstudio_4mb.h create mode 100644 ports/rp2/boards/WEACTSTUDIO/weactstudio_8mb.h create mode 100644 ports/rp2/boards/WEACTSTUDIO/weactstudio_common.h diff --git a/ports/rp2/boards/WEACTSTUDIO/README.md b/ports/rp2/boards/WEACTSTUDIO/README.md new file mode 100644 index 0000000000..ae0acfd2c7 --- /dev/null +++ b/ports/rp2/boards/WEACTSTUDIO/README.md @@ -0,0 +1,34 @@ +# WeAct Studio RP2040 + +The WeAct Studio RP2040 Board is based on the Raspberry Pi RP2040 and can be +purchased with 2/4/8/16 MiB of flash. + +These boards are available from a number of resellers and often have the name +"Pico Board RP2040". WeAct maintain the [WeActStudio.RP2040CoreBoard](https://github.com/WeActTC/WeActStudio.RP2040CoreBoard/tree/master) +repository containing information on the board. + +## Build notes + +Builds can be configured with the `BOARD_VARIANT` parameter. Valid variants +can be displayed with the `query-variant` target. An example: + +```bash +> cd ports/rp2 +> make BOARD=WEACTSTUDIO query-variants +VARIANTS: flash_2mb flash_4mb flash_8mb flash_16mb +> make BOARD=WEACTSTUDIO BOARD_VARIANT=flash_8mb submodules all # Build the 8 MiB variant +``` + +`flash_16mb` is the default if `BOARD_VARIANT` is not supplied. + +## Board-specific modules + +The `board` module contains definitions for the onboard LED and user button. + +Example: + +```python +> import board +> board.led.toggle() # Toggles the state of the on-board LED +> board.key.value() # Returns 0 or 1 corresponding to the state of the user key +``` diff --git a/ports/rp2/boards/WEACTSTUDIO/board.json b/ports/rp2/boards/WEACTSTUDIO/board.json new file mode 100644 index 0000000000..bac5263627 --- /dev/null +++ b/ports/rp2/boards/WEACTSTUDIO/board.json @@ -0,0 +1,23 @@ +{ + "deploy": [ + "deploy.md" + ], + "docs": "", + "features": [ + "Breadboard Friendly", + "SPI Flash", + "USB-C" + ], + "images": [ + "weact_rp2040.jpg" + ], + "mcu": "rp2040", + "product": "WeAct Studio RP2040", + "url": "https://github.com/WeActTC/WeActStudio.RP2040CoreBoard", + "variants": { + "flash_2mb": "2 MiB Flash", + "flash_4mb": "4 MiB Flash", + "flash_8mb": "8 MiB Flash" + }, + "vendor": "WeAct" +} diff --git a/ports/rp2/boards/WEACTSTUDIO/deploy.md b/ports/rp2/boards/WEACTSTUDIO/deploy.md new file mode 100644 index 0000000000..b4db7675eb --- /dev/null +++ b/ports/rp2/boards/WEACTSTUDIO/deploy.md @@ -0,0 +1,8 @@ +### Flashing via UF2 bootloader + +To get the board in bootloader mode ready for the firmware update, execute +`machine.bootloader()` at the MicroPython REPL. Alternatively, hold +down the BOOTSEL button while pressing reset (NRST). The uf2 file below +should then be copied to the USB mass storage device that appears. Once +programming of the new firmware is complete the device will automatically reset +and be ready for use. diff --git a/ports/rp2/boards/WEACTSTUDIO/manifest.py b/ports/rp2/boards/WEACTSTUDIO/manifest.py new file mode 100644 index 0000000000..f993d4fa6b --- /dev/null +++ b/ports/rp2/boards/WEACTSTUDIO/manifest.py @@ -0,0 +1,2 @@ +include("$(PORT_DIR)/boards/manifest.py") +freeze("./modules") diff --git a/ports/rp2/boards/WEACTSTUDIO/modules/board.py b/ports/rp2/boards/WEACTSTUDIO/modules/board.py new file mode 100644 index 0000000000..dd3b31b805 --- /dev/null +++ b/ports/rp2/boards/WEACTSTUDIO/modules/board.py @@ -0,0 +1,4 @@ +from machine import Pin + +led = Pin(25, Pin.OUT, value=0) +key = Pin(23, Pin.IN, Pin.PULL_UP) diff --git a/ports/rp2/boards/WEACTSTUDIO/mpconfigboard.cmake b/ports/rp2/boards/WEACTSTUDIO/mpconfigboard.cmake new file mode 100644 index 0000000000..5fd3eec897 --- /dev/null +++ b/ports/rp2/boards/WEACTSTUDIO/mpconfigboard.cmake @@ -0,0 +1,26 @@ +# CMake file for WeAct Studio RP2040 boards + +# The WeAct Studio boards don't have official pico-sdk support so we define it +# See also: https://github.com/raspberrypi/pico-sdk/tree/master/src/boards/include/boards +list(APPEND PICO_BOARD_HEADER_DIRS ${MICROPY_BOARD_DIR}) + +# Freeze board.py +set(MICROPY_FROZEN_MANIFEST ${MICROPY_BOARD_DIR}/manifest.py) + +# Provide different variants for the downloads page +set(BOARD_VARIANTS "flash_2mb flash_4mb flash_8mb flash_16mb") + +# Select the 16MB variant as the default +set(PICO_BOARD "weactstudio_16mb") + +if("${BOARD_VARIANT}" STREQUAL "flash_2mb") + set(PICO_BOARD "weactstudio_2mb") +endif() + +if("${BOARD_VARIANT}" STREQUAL "flash_4mb") +set(PICO_BOARD "weactstudio_4mb") +endif() + +if("${BOARD_VARIANT}" STREQUAL "flash_8mb") +set(PICO_BOARD "weactstudio_8mb") +endif() diff --git a/ports/rp2/boards/WEACTSTUDIO/mpconfigboard.h b/ports/rp2/boards/WEACTSTUDIO/mpconfigboard.h new file mode 100644 index 0000000000..3c72ef4fca --- /dev/null +++ b/ports/rp2/boards/WEACTSTUDIO/mpconfigboard.h @@ -0,0 +1,4 @@ +#define MICROPY_HW_BOARD_NAME "WeAct Studio RP2040" + +// Allow 1MB for the firmware image itself, allocate the remainder to the filesystem +#define MICROPY_HW_FLASH_STORAGE_BYTES (PICO_FLASH_SIZE_BYTES - (1 * 1024 * 1024)) diff --git a/ports/rp2/boards/WEACTSTUDIO/weactstudio_16mb.h b/ports/rp2/boards/WEACTSTUDIO/weactstudio_16mb.h new file mode 100644 index 0000000000..b6208c6897 --- /dev/null +++ b/ports/rp2/boards/WEACTSTUDIO/weactstudio_16mb.h @@ -0,0 +1,18 @@ +// A pico-sdk board definition is required since the WeAct Studio boards are +// not officially supported. +// +// Officially supported boards: +// https://github.com/raspberrypi/pico-sdk/tree/master/src/boards/include/boards + +#ifndef _BOARDS_WEACTSTUDIO_16MB_H +#define _BOARDS_WEACTSTUDIO_16MB_H + +#include "weactstudio_common.h" + +#define WEACTSTUDIO_16MB + +#ifndef PICO_FLASH_SIZE_BYTES +#define PICO_FLASH_SIZE_BYTES (16 * 1024 * 1024) +#endif + +#endif diff --git a/ports/rp2/boards/WEACTSTUDIO/weactstudio_2mb.h b/ports/rp2/boards/WEACTSTUDIO/weactstudio_2mb.h new file mode 100644 index 0000000000..e6a21ea3bc --- /dev/null +++ b/ports/rp2/boards/WEACTSTUDIO/weactstudio_2mb.h @@ -0,0 +1,18 @@ +// A pico-sdk board definition is required since the WeAct Studio boards are +// not officially supported. +// +// Officially supported boards: +// https://github.com/raspberrypi/pico-sdk/tree/master/src/boards/include/boards + +#ifndef _BOARDS_WEACTSTUDIO_2MB_H +#define _BOARDS_WEACTSTUDIO_2MB_H + +#include "weactstudio_common.h" + +#define WEACTSTUDIO_2MB + +#ifndef PICO_FLASH_SIZE_BYTES +#define PICO_FLASH_SIZE_BYTES (2 * 1024 * 1024) +#endif + +#endif diff --git a/ports/rp2/boards/WEACTSTUDIO/weactstudio_4mb.h b/ports/rp2/boards/WEACTSTUDIO/weactstudio_4mb.h new file mode 100644 index 0000000000..7a2836ab4a --- /dev/null +++ b/ports/rp2/boards/WEACTSTUDIO/weactstudio_4mb.h @@ -0,0 +1,18 @@ +// A pico-sdk board definition is required since the WeAct Studio boards are +// not officially supported. +// +// Officially supported boards: +// https://github.com/raspberrypi/pico-sdk/tree/master/src/boards/include/boards + +#ifndef _BOARDS_WEACTSTUDIO_4MB_H +#define _BOARDS_WEACTSTUDIO_4MB_H + +#include "weactstudio_common.h" + +#define WEACTSTUDIO_4MB + +#ifndef PICO_FLASH_SIZE_BYTES +#define PICO_FLASH_SIZE_BYTES (4 * 1024 * 1024) +#endif + +#endif diff --git a/ports/rp2/boards/WEACTSTUDIO/weactstudio_8mb.h b/ports/rp2/boards/WEACTSTUDIO/weactstudio_8mb.h new file mode 100644 index 0000000000..82baf6688e --- /dev/null +++ b/ports/rp2/boards/WEACTSTUDIO/weactstudio_8mb.h @@ -0,0 +1,18 @@ +// A pico-sdk board definition is required since the WeAct Studio boards are +// not officially supported. +// +// Officially supported boards: +// https://github.com/raspberrypi/pico-sdk/tree/master/src/boards/include/boards + +#ifndef _BOARDS_WEACTSTUDIO_8MB_H +#define _BOARDS_WEACTSTUDIO_8MB_H + +#include "weactstudio_common.h" + +#define WEACTSTUDIO_8MB + +#ifndef PICO_FLASH_SIZE_BYTES +#define PICO_FLASH_SIZE_BYTES (8 * 1024 * 1024) +#endif + +#endif diff --git a/ports/rp2/boards/WEACTSTUDIO/weactstudio_common.h b/ports/rp2/boards/WEACTSTUDIO/weactstudio_common.h new file mode 100644 index 0000000000..f1c6903601 --- /dev/null +++ b/ports/rp2/boards/WEACTSTUDIO/weactstudio_common.h @@ -0,0 +1,62 @@ +// Common configuration to all WeAct Studio boards (only flash size differs) + +#ifndef _BOARDS_WEACTSTUDIO_COMMON_H +#define _BOARDS_WEACTSTUDIO_COMMON_H + +// --- 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 --- +#ifndef PICO_DEFAULT_LED_PIN +#define PICO_DEFAULT_LED_PIN 25 +#endif + +// --- 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 + +// All boards have B1 RP2040 +#ifndef PICO_RP2040_B0_SUPPORTED +#define PICO_RP2040_B0_SUPPORTED 0 +#endif + +#endif