Skip to content
Snippets Groups Projects
Verified Commit a02ed0f7 authored by Jakub Vaněk's avatar Jakub Vaněk
Browse files

Add a new MicroPython board definition with slower flash clocks

In the production run of OpenCube, it was discovered that some of the
flash chips (3-4 bricks from 25) fail to run at the default 66 MHz.
It was separately tested that at 33 MHz, they work reliably.

To change the clocks, it is necessary to redefine the
PICO_FLASH_SPI_CLKDIV macro. To achieve that, this commits adds
a new MicroPython board based on the Pico reference board.
The PICO_FLASH_SPI_CLKDIV macro is changed via a trick copied from
the "nullbits Bit-C PRO" MicroPython board -- this board had a
custom board config header which includes the PICO_FLASH_SPI_CLKDIV
setting. This setting is now set to 4 to achieve the 33 MHz SPI freq.

However, the way this is done (adding a text-based patch on top of
a MicroPython submodule) is not sustainable in the long-term.
Eventually, this change should be migrated to the MicroPython upstream
(I don't think they would protest much against us adding basic OpenCube
support there). The board definition could also be improved by
specifying the pin names, changing the default pins, etc.
parent 12c7c933
No related branches found
No related tags found
1 merge request!8Add a new MicroPython board definition with slower flash clocks
Pipeline #76756 passed
......@@ -16,13 +16,15 @@ build micropython firmware:
- make -C micropython/mpy/ports/rp2 submodules
# HACK: patch a bug in Pico SDK (https://github.com/raspberrypi/pico-sdk/issues/737)
- patch -p1 --forward -i micropython/timer-bug.patch
# HACK: add a separate OpenCube board with slower flash clocks
- patch -p1 --forward -i micropython/opencube-board.patch
- make -C micropython/mpy/mpy-cross -j $(nproc)
- make -C micropython/mpy/ports/rp2 clean
- make -C micropython/mpy/ports/rp2 USER_C_MODULES=$(pwd)/micropython/modules/micropython.cmake -j $(nproc)
- cp micropython/mpy/ports/rp2/build-PICO/firmware.uf2 opencube_micropython_without_pylibs.uf2
- make -C micropython/mpy/ports/rp2 clean
- make -C micropython/mpy/ports/rp2 USER_C_MODULES=$(pwd)/micropython/modules/micropython.cmake FROZEN_MANIFEST=$(pwd)/micropython/frozen_manifest.py -j $(nproc)
- cp micropython/mpy/ports/rp2/build-PICO/firmware.uf2 opencube_micropython_with_pylibs.uf2
- make -C micropython/mpy/ports/rp2 BOARD=OPENCUBE clean
- make -C micropython/mpy/ports/rp2 BOARD=OPENCUBE USER_C_MODULES=$(pwd)/micropython/modules/micropython.cmake -j $(nproc)
- cp micropython/mpy/ports/rp2/build-OPENCUBE/firmware.uf2 opencube_micropython_without_pylibs.uf2
- make -C micropython/mpy/ports/rp2 BOARD=OPENCUBE clean
- make -C micropython/mpy/ports/rp2 BOARD=OPENCUBE USER_C_MODULES=$(pwd)/micropython/modules/micropython.cmake FROZEN_MANIFEST=$(pwd)/micropython/frozen_manifest.py -j $(nproc)
- cp micropython/mpy/ports/rp2/build-OPENCUBE/firmware.uf2 opencube_micropython_with_pylibs.uf2
artifacts:
paths:
- opencube_micropython_without_pylibs.uf2
......
diff --git a/ports/rp2/boards/OPENCUBE/mpconfigboard.cmake b/ports/rp2/boards/OPENCUBE/mpconfigboard.cmake
new file mode 100644
index 000000000000..35b44cd80b00
--- /dev/null
+++ b/micropython/mpy/ports/rp2/boards/OPENCUBE/mpconfigboard.cmake
@@ -0,0 +1,5 @@
+# cmake file for OpenCube
+
+# copied from nullbits Bit-C PRO
+list(APPEND PICO_BOARD_HEADER_DIRS ${MICROPY_BOARD_DIR})
+set(PICO_BOARD "opencube")
diff --git a/ports/rp2/boards/OPENCUBE/mpconfigboard.h b/ports/rp2/boards/OPENCUBE/mpconfigboard.h
new file mode 100644
index 000000000000..199b3f2a0803
--- /dev/null
+++ b/micropython/mpy/ports/rp2/boards/OPENCUBE/mpconfigboard.h
@@ -0,0 +1,3 @@
+// Board and hardware specific configuration
+#define MICROPY_HW_BOARD_NAME "OpenCube"
+#define MICROPY_HW_FLASH_STORAGE_BYTES (1408 * 1024)
diff --git a/ports/rp2/boards/OPENCUBE/opencube.h b/ports/rp2/boards/OPENCUBE/opencube.h
new file mode 100644
index 000000000000..cebc3eccc674
--- /dev/null
+++ b/micropython/mpy/ports/rp2/boards/OPENCUBE/opencube.h
@@ -0,0 +1,83 @@
+/*
+ * 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
+// -----------------------------------------------------
+
+// This header may be included by other board headers as "boards/pico.h"
+
+#ifndef _BOARDS_PICO_H
+#define _BOARDS_PICO_H
+
+// For board detection
+#define OPENCUBE
+
+// --- 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
+// 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
+
+// used flash is kinda slow: 66 MHz sometimes crashes, 33 MHz is stable
+#ifndef PICO_FLASH_SPI_CLKDIV
+#define PICO_FLASH_SPI_CLKDIV 4
+#endif
+
+#ifndef PICO_FLASH_SIZE_BYTES
+#define PICO_FLASH_SIZE_BYTES (2 * 1024 * 1024)
+#endif
+
+// let's be conservative and say that B0 rev is allowed
+#ifndef PICO_RP2040_B0_SUPPORTED
+#define PICO_RP2040_B0_SUPPORTED 1
+#endif
+
+#endif
diff --git a/ports/rp2/boards/OPENCUBE/pins.csv b/ports/rp2/boards/OPENCUBE/pins.csv
new file mode 100644
index 000000000000..16e334026424
--- /dev/null
+++ b/micropython/mpy/ports/rp2/boards/OPENCUBE/pins.csv
@@ -0,0 +1,28 @@
+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
+GP25,GPIO25
+GP26,GPIO26
+GP27,GPIO27
+GP28,GPIO28
+LED,GPIO25
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment