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

Add RISC-V support #2491

merged 38 commits into from
Sep 29, 2024

Conversation

earlephilhower
Copy link
Owner

@earlephilhower earlephilhower commented Sep 23, 2024

This PR's pretty good to go. I'm still not sure it'll be part of the mainstream, but other than the GCC update and a fix to locking, no ARM-related changes were done so it shouldn't actually have any negative impact on the main platform.

Platform.IO runs will fail until it starts pointing to the new GCC 14.2 toolchain. @maxgerhardt any suggestions? Any way of using different tools programmatically?

RISC-V/ARM can be selected through the menus and most things "just work" under RISC-V. Known issues are OTA and some FreeRTOS-related USB stuff not fully implemented.

A new toolchain, GCC 14.2, is required since RISC-V support in 12.4 is not usable, so git clones need to do a get.py to install. This also will increase tool installation size since both ARM and RISCV compiler chains are needed.

@earlephilhower
Copy link
Owner Author

earlephilhower commented Sep 23, 2024

If you pull this PR and run get.py on Linux, then select the Pico2-RiscV and then Tools->C++ Exceptions->Enabled you can build a UF2 (for blink.ino at least). [The exceptions disabled special build in the new GCC14.2 toolchain seems to have had a hiccup and can't link yet.]

However, the binary seems to be DOA,. I'm not having any luck getting OpenOCD running for R5 (not even on the SDK stuff), so if anyone has any good documents on getting R5 debugging running it's be appreciated!

Looks like I can get OpenOCD and GDB running in R5 mode with the toolchain. GDB's crashed a couple times, but if I have an already-running R5-mode binary running (blink from pico-sdk) I can overwrite with a new ELF from the IDE.

The runtime init array was being dropped due to linker differences in GCC14.2,
leading to the chip not actually initting USB or other clocks (among other
things).  Manually force them into the array.

PWMAudio, Blink, and Fade work.
@earlephilhower
Copy link
Owner Author

earlephilhower commented Sep 23, 2024

This PR can now build and run RISC-V code (only) under Linux (haven't rebuilt entire toolchain for all other archs like Mac or Win yet). Tested PWMAudio, Blink, and Fade, and all run on quick inspection. Probably many different peripheral libraries not there yet, but basic sanity is fine.

@earlephilhower
Copy link
Owner Author

earlephilhower commented Sep 24, 2024

P.IO builds here aren't going to work for the RP2350-RISCV until the upstream platform.io builder is updated to select the right compiler. But the IDE and arduino-cli should work for folks now.

@earlephilhower earlephilhower marked this pull request as ready for review September 26, 2024 18:43
@earlephilhower earlephilhower changed the title WIP - RISCV playground Add RISC-V support Sep 26, 2024
@earlephilhower
Copy link
Owner Author

This PR's pretty good to go. I'm still not sure it'll be part of the mainstream, but other than the GCC update and a fix to locking, no ARM-related changes were done so it shouldn't actually have any negative impact on the main platform.

Platform.IO runs will fail until it starts pointing to the new GCC 14.2 toolchain. @maxgerhardt any suggestions? Any way of using different tools programmatically?

RISC-V/ARM can be selected through the menus and most things "just work" under RISC-V. Known issues are OTA and some FreeRTOS-related USB stuff not fully implemented.

A new toolchain, GCC 14.2, is required since RISC-V support in 12.4 is not usable, so git clones need to do a get.py to install. This also will increase tool installation size since both ARM and RISCV compiler chains are needed.

@maxgerhardt
Copy link
Contributor

I'm working on the PIO integration right now.

Some things stand out:

  • the board JSON files for RP2350 boards have their boot2.S files all replaced with none.S? Then the information what boot2 file to use for the regular ARM build got lost?
  • the RISC-V toolchain packages from https://github.com/earlephilhower/pico-quick-toolchain/releases, e.g. aarch64-linux-gnu.riscv32-unknown-elf-8b9df28.240926.tar.gz still has the same toolchain-rp2040-earlephilhower name. Can we rename that to e.g. toolchain-rp2040-earlephilhower-riscv? I'm afraid PlatformIO will redownload / re-unpack the whole toolchain package when a user switches between an ARM and a RISC-V build. We could have both installed in parallel under different package names.

@maxgerhardt
Copy link
Contributor

maxgerhardt commented Sep 27, 2024

The toolchain URLs and toolchain switch was implemented (see commits/develop/). The examples all build now again, for RP2040, RP2350 ARM + RISC-V. Users can switch to the RISC-V build with

; RP2350 based (ARM)
[env:rpipico2]
board = rpipico2

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

It's still weird because the RISC-V build still builds the regular boot2.S file and it works, LED blinking and all. (I have not yet synced the PIO board JSON changes). How does that work here? Does the RISC-V build not need a boot2 file to integrate with the external flash chip?

Also, why do we need special board definitions for RP2350 boards when in RISC-V mode? (variants/rpipico2rv/pins_arduino.h)

@earlephilhower
Copy link
Owner Author

earlephilhower commented Sep 27, 2024

Thanks!

the board JSON files for RP2350 boards have their boot2.S files all replaced with none.S? Then the information what boot2 file to use for the regular ARM build got lost?
...
Does the RISC-V build not need a boot2 file to integrate with the external flash chip?

The boot2 isn't actually used anywhere on the RP2350. On the 2040 ROM they called a specific address where it lived and it was responsible for setting up the QSPI interface. On the 2350 the ROM has add'l intelligence which they say get you running "good enough" with whatever flash. If the app wants to adjust the QSPI timing/etc. then it can do so itself programmatically. We don't. The boot2 files were just being added to the binary image but never accessed.

Also, why do we need special board definitions for RP2350 boards when in RISC-V mode? (variants/rpipico2rv/pins_arduino.h)

A leftover, dropped from the latest pushes. It was a board before, now it's just a build option...

the RISC-V toolchain packages... Can we rename that to e.g. toolchain-rp2040-earlephilhower-riscv...

Will do next build. Also going to try and reduce the R5 GCC image size because it now includes every R5 architecture option...it's a 3hr/32 parallel job/200GB monster now, though, so might be next week when the new files get up there.

@maxgerhardt
Copy link
Contributor

Can you clear the cache for PlatformIO in the Githu actions once per https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/caching-dependencies-to-speed-up-workflows#viewing-cache-entries? It's still using the old platform version and with it the old toolchain, that's why compiling fails.

maxgerhardt and others added 2 commits September 28, 2024 10:30
The previous ones did not include the `-m..` machine flags when compiling assembly code, leading to linker errors.
@earlephilhower earlephilhower merged commit f6973fc into master Sep 29, 2024
26 checks passed
@earlephilhower
Copy link
Owner Author

@maxgerhardt , the toolchain 4.0.1 was rebuilt and uploaded with the fixes JSON entries and smaller d/l and install sizes. When you update the P.IO wrapper let me know and I'll blow away the 4.0.0 one.

@znmeb
Copy link

znmeb commented Sep 30, 2024

How does a PlatformIO end user with an RP2350 board go about designating that the compile / upload should use RISC-V rather than Arm Cortex M33?

@maxgerhardt
Copy link
Contributor

maxgerhardt commented Sep 30, 2024

Tools were updated to 4.0.1 in maxgerhardt/platform-raspberrypi@a7eddaa

Full platformio.ini example with some chippies:

; common settings
[env]
platform = https://github.com/maxgerhardt/platform-raspberrypi.git
framework = arduino

; RP2040 based
[env:pico]
board = rpipico

[env:picow]
board = rpipicow

; RP2350 based (ARM)
[env:rpipico2]
board = rpipico2

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants