Request for RISCV LLVM compiler option in SDK #2228
Labels
No labels
bazel
bluetooth
board settings
boot_stage2
bug
build
c++
can't reproduce
clang
clib-interface
cmsis
code cleanliness
code size
compiler version issues
cyw43_driver
debug
discussion
documentation
duplicate
dynamic_clock
elf2uf2
enhancement
errata
filesystem
flash layout
floating point
FreeRTOS
hardware_adc
hardware_claim
hardware_clocks
hardware_dma
hardware_exception
hardware_flash
hardware_gpio
hardware_i2c
hardware_irq
hardware_pio
hardware_pwm
hardware_rcp
hardware_rtc
hardware_spi
hardware_sync
hardware_uart
hardware_vreg
hardware_watchdog
hardware_xosc
help wanted
host
IAR
installation
invalid
linker scripts
lto
lwip
mbedtls
missing API
needs reporter detail
networking
newlib
newlib-multicore
non-c
non-cmake
non-gcc
openocd
orphan PR
OS integration
pico_async_context
pico_base
pico_binary_info
pico_flash
picolibc
pico_lwip
pico_malloc
pico_multicore
pico_printf
pico_runtime
pico_stdio
pico_stdio_usb
pico_sync
pico_time
pico_util
pioasm
port
question
review
review2
rtos interop
runtime init
static library
svd
test
tinyusb
vscode
wifi integration
wontfix
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-raspberrypi/pico-sdk#2228
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
because... why not :D But messing with scripts and hardcoding, and deleting stuff, managed to compile some program that works. There was some warnings and SDK required some changes. Stable release and top-of-tree both has RISCV LLVM option. Latter one has newer 19.0.0 (and it's GCC/LLVM combo), and it works with
-march=rv32ima_zicsr_zifencei_zba_zbb_zbs_zbkb_zca_zcb_zcmp, that is required after changing instruction:github.com/raspberrypi/pico-sdk@95ea6acad1/src/rp2_common/hardware_irq/irq_handler_chain.S (L75)and
github.com/raspberrypi/pico-sdk@95ea6acad1/src/rp2_common/hardware_irq/irq_handler_chain.S (L91)to its commented out form. Stable (16 something) was not complying with
rv32imac_zicsr_zifencei_zba_zbb_zbs_zbkb. They both are shipped withnewlibsoset(PICO_CLIB newlib). Pico 2 W has similar instruction incompatibility somewhere incyw43driverI believe, but there was not comment for that :D So deleting it, and it compiled spiting outuf2file. I don't have Pico 2 W to test it, but I bet it might lack one instruction. I didn't dig deep enough for the replacement. Anyway, compiler is available (for Linux and macOS only in a binary form) and at the first glance it works.So,
pico_riscv_clang.cmakeneeds to be created here: https://github.com/raspberrypi/pico-sdk/tree/master/cmake/preload/toolchains:and
pico_riscv_clang_common.cmakehere: https://github.com/raspberrypi/pico-sdk/tree/master/cmake/preload/toolchains/util:For Pico 2 W, the problematic line is:
github.com/raspberrypi/pico-sdk@95ea6acad1/src/rp2_common/pico_cyw43_driver/cyw43_bus_pio_spi.c (L90)but I think solution is there https://github.com/raspberrypi/pico-sdk/issues/1922:
I had a little play, and the linker crashes with
stdio_usbe.g.hello_usbfrom pico-examples.I dont have a lot of cycles to look at this right now, but if you want to have a poke around, that might help me drop this in in the next release as a "pre-release" - it would be good if it could compile everything though ;-)
actually i did just check; it is anything that uses
tinyusbFYI
Doesn't tell you much; i didn't find the right version of the code - my guess is a linker bug
Updated RISC-V compiler to version from
09 Mar 2025havingClang 21. Whencopy_to_ramorno_flashit compiles some https://github.com/bitbank2/JPEGDEC project having USB serial output enabled successfully:but with default binary type: without
pico_set_binary_type(<program> <binary_type>)I've got:And the last one is the same for pico-examples. But
set(PICO_DEFAULT_BINARY_TYPE=copy_to_ram)andset(PICO_COPY_TO_RAM=1)seems to do nothting - won't set binary type (they do nothing, it should beset(PICO_DEFAULT_BINARY_TYPE copy_to_ram)). Localpico_set_binary_type(<program> <binary_type>)is successfull at doing that.Closed by accident.
BTW, succesfull and failing one have both
Is it safe?
And yes, with default binary type and:
it compiles just fine:
It's again:
but compiles.
So with
set(PICO_DEFAULT_BINARY_TYPE copy_to_ram)and:it compiles. Same warnings repeats:
But for
no_flashpico-examples new error appears:For
pico2_wit will fail due to RAM overflow at some examples whencopy_to_ram. Some standalone project comiles withno_flash.PS. My bad, it should be
set(PICO_DEFAULT_BINARY_TYPE copy_to_ram)notset(PICO_DEFAULT_BINARY_TYPE=copy_to_ram).I had another play (spent way too long really - the embecosm one hasn't been updated in forever, so still segfaults, and https://github.com/riscv-collab/riscv-gnu-toolchain/releases to work got closer with some nasty manual lib/include path stuff but is missing
libclang_rt.builtins.apunting to next release; we may have to build our own
Vanilla upstream LLVM from Google's Fuchsia might be a good candidate, you've already adpoted it in SDK. Latest
23.1.0-rc3: https://chrome-infra-packages.appspot.com/p/fuchsia/third_party/clang/linux-amd64/+/git_revision:7196f931f212fc7c406066b2628a0ff4ea0ee344 tested withdevelopPico SDK (developTinyUSB and BTstack as well) works fine with only little bumps here and there.It uses llvm_libc, but is provided with
ilp32fonly. To getilp32and_zcmpincludinglibclang_rt.builtins.a😉:but
riscv32-unknown-elf-clangandriscv32-unknown-elf-clang++symlinks tollvmbinary needs to be created first, asclangandclang++targetsx86_64-unknown-linux-gnu. All configurations above are taken out from:github.com/llvm/llvm-project@7196f931f2/clang/cmake/caches/Fuchsia-stage2.cmake. I provideilp32precompiled libraries here: clang-linux-amd64.zipThen it compiles some project with
printfby TinyUSB just fine:with some nasty looking memory usage output. Taken out from Bazel scripts are:
but since:
I've just commented
--unwindlib=out. Forpico2_w:github.com/raspberrypi/pico-sdk@3383fb1e12/src/rp2_common/hardware_exception/exception_table_riscv.S (L14)needs to be changed to:
as it was failing linking with errors below:
Since:
github.com/raspberrypi/pico-sdk@3383fb1e12/src/rp2_common/pico_cyw43_driver/cyw43_bus_pio_spi.c (L90)wasn't changed in
develop, it needs to be changed too, to: