Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RISC-V support #2491

Merged
merged 38 commits into from
Sep 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
54e7dc2
WIP - RISCV playground
earlephilhower Sep 23, 2024
96bcdf3
Close to linkage
earlephilhower Sep 23, 2024
d359239
Actually build libs for RISCV, d'oh!
earlephilhower Sep 23, 2024
0036aa0
Add BearSSL for RISCV
earlephilhower Sep 23, 2024
bf1f5a6
Clean up lock wrapper, OTA stub build
earlephilhower Sep 23, 2024
445be78
RP2350 UF2 build fix
earlephilhower Sep 23, 2024
4103e69
Fix MHZ
earlephilhower Sep 23, 2024
5b9139e
Blink.ino with C++ exceptions=1, NO_USB, runs
earlephilhower Sep 23, 2024
2a7fc66
Wrapped functions
earlephilhower Sep 23, 2024
62e1efc
More defines in libpico
earlephilhower Sep 23, 2024
a138b88
Actually link in runtime startup code
earlephilhower Sep 23, 2024
8b64995
Remove debug blinker
earlephilhower Sep 23, 2024
e9ccdd1
Add back ARM tools
earlephilhower Sep 23, 2024
2f350b0
Throw it to CI, see what flies
earlephilhower Sep 24, 2024
dd61178
Copy proper BearSSL libraries for Pico2/Pico2RV
earlephilhower Sep 24, 2024
f575114
Make FreeRTOS-RISCV compile
earlephilhower Sep 24, 2024
b19288f
SDFat RISCV
earlephilhower Sep 24, 2024
f41fd9f
Refactor cmake for define reuse, update p.io scripts
earlephilhower Sep 24, 2024
670d812
Update toolchain, fix no-exceptions builds
earlephilhower Sep 24, 2024
9cfb639
Re-build all BearSSL for sanity, completeness
earlephilhower Sep 24, 2024
a120afe
Remove BOOT2 from RP2350
earlephilhower Sep 24, 2024
03898fc
Select ARM/RISCV for all RP2350 from menus
earlephilhower Sep 24, 2024
a2f642e
Merge branch 'master' into riscv
earlephilhower Sep 24, 2024
31ed320
Rebuild
earlephilhower Sep 24, 2024
7f60f92
CI FQBN update
earlephilhower Sep 24, 2024
1ab4e6c
New toolchain build
earlephilhower Sep 26, 2024
89f1036
Locking update, match RISCV
earlephilhower Sep 26, 2024
bfa085a
Punt on GCC14ARM-only new warnings
earlephilhower Sep 26, 2024
6acf03e
Remove dead board file
earlephilhower Sep 27, 2024
8e835b5
RISC-V OTA support
earlephilhower Sep 27, 2024
0356234
Add R5 OTA example...works!
earlephilhower Sep 27, 2024
77829ec
Codespell unbreakage
earlephilhower Sep 27, 2024
c53119f
Fix compiling assembly (#2500)
maxgerhardt Sep 28, 2024
83073db
Astyle
earlephilhower Sep 28, 2024
6dddb1e
4.0.1 toolchain, smaller R5 instal, fix P.IO JSON
earlephilhower Sep 29, 2024
9b2bb37
Add basic documentation
earlephilhower Sep 29, 2024
d3c1394
TODO was TODONE
earlephilhower Sep 29, 2024
8f9b07c
Remove obsolete OTA.C dummy for RISCV
earlephilhower Sep 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
with:
submodules: false
- name: Run codespell
uses: codespell-project/actions-codespell@master
uses: codespell-project/actions-codespell@v2
with:
skip: ./ArduinoCore-API,./libraries/ESP8266SdFat,./libraries/Adafruit_TinyUSB_Arduino,./libraries/LittleFS/lib,./tools/pyserial,./pico-sdk,./.github,./docs/i2s.rst,./cores/rp2040/api,./libraries/FreeRTOS,./tools/libbearssl/bearssl,./include,./libraries/WiFi/examples/BearSSL_Server,./ota/uzlib,./libraries/http-parser/lib,./libraries/WebServer/examples/HelloServerBearSSL/HelloServerBearSSL.ino,./libraries/HTTPUpdateServer/examples/SecureBearSSLUpdater/SecureBearSSLUpdater.ino,./.git,./libraries/FatFS/lib/fatfs,./libraries/FatFS/src/diskio.h,./libraries/FatFS/src/ff.cpp,./libraries/FatFS/src/ffconf.h,./libraries/FatFS/src/ffsystem.cpp,./libraries/FatFS/src/ff.h,./libraries/lwIP_WINC1500/src/driver,./libraries/lwIP_WINC1500/src/common,./libraries/lwIP_WINC1500/src/bus_wrapper,./libraries/lwIP_WINC1500/src/spi_flash
ignore_words_list: ser,dout,shiftIn,acount
Expand Down Expand Up @@ -101,6 +101,37 @@ jobs:
cd ..
bash ./tests/build-rp2350.sh

# Build all rp2350-riscv examples on linux (core and Arduino IDE)
build-rp2350-riscv-linux:
name: Build RP2350-RISCV ${{ matrix.chunk }}
runs-on: ubuntu-latest
strategy:
matrix:
chunk: [0, 1, 2, 3, 4, 5]
steps:
- uses: actions/checkout@v4
with:
submodules: true
- uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Cache Linux toolchain
id: cache-linux
uses: actions/cache@v4
with:
path: ./tools/dist
key: ${{ runner.os }}-${{ hashFiles('package/package_pico_index.template.json', 'tests/common.sh') }}
- name: Build Sketches
env:
BUILD_PARITY: custom
mod: 6
rem: ${{ matrix.chunk }}
run: |
cd pico-sdk
git submodule update --init
cd ..
bash ./tests/build-rp2350-riscv.sh

# Build TinyUSB examples, requires custom build command line
build-tinyusb:
name: Build TinyUSB Examples
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

Raspberry Pi Pico Arduino core, for all RP2040 and RP2350 boards

This is a port of Arduino to the RP2040 (Raspberry Pi Pico processor) and RP2350 (Raspberry Pi Pico 2 processor). It uses the bare Raspberry Pi Pico SDK and a custom GCC 12.3/Newlib 4.0 toolchain.
This is a port of Arduino to the RP2040 (Raspberry Pi Pico processor) and RP2350 (Raspberry Pi Pico 2 processor). It uses the bare Raspberry Pi Pico SDK and a custom GCC 14.2/Newlib 4.3 toolchain and supports ARM and RISC-V cores.

# Documentation
See https://arduino-pico.readthedocs.io/en/latest/ along with the examples for more detailed usage information.
Expand Down Expand Up @@ -126,6 +126,7 @@ Read the [Contributing Guide](https://github.com/earlephilhower/arduino-pico/blo
* Peripherals: SPI master/slave, Wire(I2C) master/slave, dual UART, emulated EEPROM, I2S audio input/output, Servo
* printf (i.e. debug) output over USB serial
* Transparent use of PSRAM globals and heap (RP2350 only)
* ARM or RISC-V (Hazard3) support for The RP2350

The RP2040 PIO state machines (SMs) are used to generate jitter-free:
* Servos
Expand Down
229 changes: 155 additions & 74 deletions boards.txt

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions boot2/rp2350-riscv/none.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.section .boot2, "ax"

.global __boot2_entry_point
__boot2_entry_point:
25 changes: 0 additions & 25 deletions boot2/rp2350/boot2_generic_03h_2_padded_checksum.S

This file was deleted.

25 changes: 0 additions & 25 deletions boot2/rp2350/boot2_generic_03h_4_padded_checksum.S

This file was deleted.

25 changes: 0 additions & 25 deletions boot2/rp2350/boot2_w25q080_2_padded_checksum.S

This file was deleted.

25 changes: 0 additions & 25 deletions boot2/rp2350/boot2_w25q080_4_padded_checksum.S

This file was deleted.

4 changes: 4 additions & 0 deletions boot2/rp2350/none.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.section .boot2, "ax"

.global __boot2_entry_point
__boot2_entry_point:
2 changes: 1 addition & 1 deletion cores/rp2040/Arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#ifdef abs
#undef abs
#endif // abs
#ifdef __cplusplus
#if defined(__cplusplus) && !defined(__riscv)
using std::abs;
using std::round;
#else
Expand Down
12 changes: 12 additions & 0 deletions cores/rp2040/RP2040Support.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,18 +175,22 @@ class RP2040 {

void begin() {
_epoch = 0;
#if !defined(__riscv)
if (!__isFreeRTOS) {
// Enable SYSTICK exception
exception_set_exclusive_handler(SYSTICK_EXCEPTION, _SystickHandler);
systick_hw->csr = 0x7;
systick_hw->rvr = 0x00FFFFFF;
} else {
#endif
int off = 0;
_ccountPgm = new PIOProgram(&ccount_program);
_ccountPgm->prepare(&_pio, &_sm, &off);
ccount_program_init(_pio, _sm, off);
pio_sm_set_enabled(_pio, _sm, true);
#if !defined(__riscv)
}
#endif
}

// Convert from microseconds to PIO clock cycles
Expand All @@ -208,6 +212,7 @@ class RP2040 {
// Get CPU cycle count. Needs to do magic to extens 24b HW to something longer
volatile uint64_t _epoch = 0;
inline uint32_t getCycleCount() {
#if !defined(__riscv)
if (!__isFreeRTOS) {
uint32_t epoch;
uint32_t ctr;
Expand All @@ -217,11 +222,15 @@ class RP2040 {
} while (epoch != (uint32_t)_epoch);
return epoch + (1 << 24) - ctr; /* CTR counts down from 1<<24-1 */
} else {
#endif
return ccount_read(_pio, _sm);
#if !defined(__riscv)
}
#endif
}

inline uint64_t getCycleCount64() {
#if !defined(__riscv)
if (!__isFreeRTOS) {
uint64_t epoch;
uint64_t ctr;
Expand All @@ -231,8 +240,11 @@ class RP2040 {
} while (epoch != _epoch);
return epoch + (1LL << 24) - ctr;
} else {
#endif
return ccount_read(_pio, _sm);
#if !defined(__riscv)
}
#endif
}

inline int getFreeHeap() {
Expand Down
2 changes: 1 addition & 1 deletion cores/rp2040/_freertos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ typedef struct {
static FMMap *_map = nullptr;
SemaphoreHandle_t __get_freertos_mutex_for_ptr(mutex_t *m, bool recursive) {
if (!_map) {
_map = (FMMap *)calloc(sizeof(FMMap), 16);
_map = (FMMap *)calloc(16, sizeof(FMMap));
}
// Pre-existing map
for (int i = 0; i < 16; i++) {
Expand Down
4 changes: 2 additions & 2 deletions cores/rp2040/lock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ static SemaphoreHandle_t __getFreeRTOSRecursiveMutex(_LOCK_T lock) {
return __get_freertos_mutex_for_ptr((mutex_t *)l, true);
}

void __retarget_lock_init(_LOCK_T *lock) {
void __retarget_lock_init(_LOCK_T lock) {
if (__freeRTOSinitted) {
mutex_t *l = (mutex_t *)lock;
if ((l == &__lock___at_quick_exit_mutex) || (l == &__lock___tz_mutex) || (l == &__lock___dd_hash_mutex) || (l == &__lock___arc4random_mutex)) {
Expand All @@ -113,7 +113,7 @@ void __retarget_lock_init(_LOCK_T *lock) {
}
}

void __retarget_lock_init_recursive(_LOCK_T *lock) {
void __retarget_lock_init_recursive(_LOCK_T lock) {
if (__freeRTOSinitted) {
recursive_mutex_t *l = (recursive_mutex_t *)lock;
if ((l == &__lock___sinit_recursive_mutex) || (l == &__lock___sfp_recursive_mutex) || (l == &__lock___atexit_recursive_mutex) || (l == &__lock___malloc_recursive_mutex) || (l == &__lock___env_recursive_mutex)) {
Expand Down
3 changes: 1 addition & 2 deletions cores/rp2040/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ extern "C" int main() {

// Allocate impure_ptr (newlib temps) if there is a 2nd core running
if (!__isFreeRTOS && (setup1 || loop1)) {
_impure_ptr1 = (struct _reent*)calloc(sizeof(struct _reent), 1);
_impure_ptr1 = (struct _reent*)calloc(1, sizeof(struct _reent));
_REENT_INIT_PTR(_impure_ptr1);
}

Expand Down Expand Up @@ -134,7 +134,6 @@ extern "C" int main() {
}
rp2040.fifo.registerCore();
}

if (!__isFreeRTOS) {
if (setup1 || loop1) {
delay(1); // Needed to make Picoprobe upload start 2nd core
Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ RP2040 (Raspberry Pi Pico processor) and RP2350 (Raspberry Pi Pico 2
processor), intended to make it easier and more fun to use and
program the Raspberry Pi Pico / RP2040 / RP2350 based boards.

This Arduino core uses a custom toolset with GCC 12.3 and Newlib 4.0.0
This Arduino core uses a custom toolset with GCC 14.2 and Newlib 4.3
and doesn't require any system-installed prerequisites.

For the latest version, always check https://github.com/earlephilhower/arduino-pico
Expand Down
13 changes: 13 additions & 0 deletions docs/platformio.rst
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,19 @@ local copy of the core (with e.g. some modifications) on disk (`see documentatio
Note that this can only be done for versions that have the PlatformIO
builder script it in, so versions before 1.9.2 are not supported.

Selecting the CPU architecture
------------------------------

By default Platform.IO will build for the onboard ARM cores on the RP2350. To build RISC-V binaries
adjust the ``board_build.mcu`` option accordingly:

.. code:: ini

; RP2350 based (RISC-V)
[env:rpipico2-riscv]
board = rpipico2
board_build.mcu = rp2350-riscv

Examples
--------

Expand Down
9 changes: 8 additions & 1 deletion docs/rp2350.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ is supported by the core with some minor caveats:

* PSRAM is supported via a new ``pmalloc`` call and ``PSRAM`` variable decorator.
* Both RP2350A and RP2350B (48 GPIOs) are supported.
* Only ARM mode is available. For RISC-V (Hazard3), please use the raw SDK.

ARM and RISC-V Modes
~~~~~~~~~~~~~~~~~~~~

Either set of cores can be used on the RP2350, ARM Cortex-M33 or RISC-V Hazard3.
Select the desired core from the IDE menus under ``Tools->CPU Architecture``.
As of the initial release, all libraries should work under the new RISC-V mode with
the exception of FreeRTOS. If not, patches are always welcome.

P2350-E9 Errata ("Increased leakage current on Bank 0 GPIO when pad input is enabled")
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
2 changes: 1 addition & 1 deletion include/bearssl/bearssl_git.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// Do not edit -- Automatically generated by tools/sdk/ssl/bearssl/Makefile
#define BEARSSL_GIT c2c9d9d
#define BEARSSL_GIT 5b7f3d5
Binary file modified lib/rp2040/libbearssl.a
Binary file not shown.
Binary file modified lib/rp2040/libipv4-big.a
Binary file not shown.
Binary file modified lib/rp2040/libipv4-bt-big.a
Binary file not shown.
Binary file modified lib/rp2040/libipv4-bt.a
Binary file not shown.
Binary file modified lib/rp2040/libipv4-ipv6-big.a
Binary file not shown.
Binary file modified lib/rp2040/libipv4-ipv6-bt-big.a
Binary file not shown.
Binary file modified lib/rp2040/libipv4-ipv6-bt.a
Binary file not shown.
Binary file modified lib/rp2040/libipv4-ipv6.a
Binary file not shown.
Binary file modified lib/rp2040/libipv4.a
Binary file not shown.
Binary file modified lib/rp2040/libpico.a
Binary file not shown.
Binary file modified lib/rp2040/ota.o
Binary file not shown.
Binary file added lib/rp2350-riscv/libbearssl.a
Binary file not shown.
Binary file added lib/rp2350-riscv/libipv4-big.a
Binary file not shown.
Binary file added lib/rp2350-riscv/libipv4-ipv6-big.a
Binary file not shown.
Binary file added lib/rp2350-riscv/libipv4-ipv6.a
Binary file not shown.
Binary file added lib/rp2350-riscv/libipv4.a
Binary file not shown.
Binary file added lib/rp2350-riscv/libpico.a
Binary file not shown.
Loading
Loading