ARM编译大家都会,也很容易,毕竟ARM工具链已经很成熟了,但是RISC-V却要自己编译工具链,为什么不能用现成的?那就问为什么树莓派非要用这么怪的ARCH了.
第一步是编译工具链.
git clone https://github.com/riscv-collab/riscv-gnu-toolchain
cd riscv-gnu-toolchain && ./configure --with-arch=rv32imac_zicsr_zifencei_zba_zbb_zbkb_zbs --with-abi=ilp32
sudo make -j40
接着就是编译SDK,在pico-examples库中就可以完成,需要先安装好环境.
git clone https://github.com/raspberrypi/pico-examples
cd pico-examples
mkdir build
cd build/
cmake -DCMAKE_BUILD_TYPE=Debug -DPICO_PLATFORM=rp2350-riscv -DPICO_BOARD=pico2 ..
编译一个RP2350 Hello World.
taterli@taterli-desktop:~/pico-examples/build/hello_world$ make
[ 0%] Built target bs2_default
[ 0%] Built target bs2_default_padded_checksummed_asm
[ 0%] Building C object hello_world/serial/CMakeFiles/hello_serial.dir/hello_serial.c.obj
[ 0%] Building C object hello_world/serial/CMakeFiles/hello_serial.dir/home/taterli/pico/pico-sdk/src/rp2_common/pico_stdlib/stdlib.c.obj
[ 0%] Building C object hello_world/serial/CMakeFiles/hello_serial.dir/home/taterli/pico/pico-sdk/src/rp2_common/hardware_gpio/gpio.c.obj
[ 0%] Building C object hello_world/serial/CMakeFiles/hello_serial.dir/home/taterli/pico/pico-sdk/src/rp2350/pico_platform/platform.c.obj
[ 0%] Building C object hello_world/serial/CMakeFiles/hello_serial.dir/home/taterli/pico/pico-sdk/src/rp2_common/pico_platform_panic/panic.c.obj
[ 0%] Building C object hello_world/serial/CMakeFiles/hello_serial.dir/home/taterli/pico/pico-sdk/src/common/hardware_claim/claim.c.obj
[ 0%] Building C object hello_world/serial/CMakeFiles/hello_serial.dir/home/taterli/pico/pico-sdk/src/rp2_common/hardware_sync/sync.c.obj
[ 0%] Building C object hello_world/serial/CMakeFiles/hello_serial.dir/home/taterli/pico/pico-sdk/src/rp2_common/hardware_sync_spin_lock/sync_spin_lock.c.obj
[ 0%] Building C object hello_world/serial/CMakeFiles/hello_serial.dir/home/taterli/pico/pico-sdk/src/rp2_common/hardware_irq/irq.c.obj
[ 0%] Building ASM object hello_world/serial/CMakeFiles/hello_serial.dir/home/taterli/pico/pico-sdk/src/rp2_common/hardware_irq/irq_handler_chain.S.obj
[ 0%] Building C object hello_world/serial/CMakeFiles/hello_serial.dir/home/taterli/pico/pico-sdk/src/common/pico_sync/sem.c.obj
[ 0%] Building C object hello_world/serial/CMakeFiles/hello_serial.dir/home/taterli/pico/pico-sdk/src/common/pico_sync/lock_core.c.obj
[ 0%] Building C object hello_world/serial/CMakeFiles/hello_serial.dir/home/taterli/pico/pico-sdk/src/common/pico_sync/mutex.c.obj
[ 0%] Building C object hello_world/serial/CMakeFiles/hello_serial.dir/home/taterli/pico/pico-sdk/src/common/pico_sync/critical_section.c.obj
[ 0%] Building C object hello_world/serial/CMakeFiles/hello_serial.dir/home/taterli/pico/pico-sdk/src/common/pico_time/time.c.obj
[ 0%] Building C object hello_world/serial/CMakeFiles/hello_serial.dir/home/taterli/pico/pico-sdk/src/common/pico_time/timeout_helper.c.obj
[ 0%] Building C object hello_world/serial/CMakeFiles/hello_serial.dir/home/taterli/pico/pico-sdk/src/rp2_common/hardware_timer/timer.c.obj
[ 0%] Building C object hello_world/serial/CMakeFiles/hello_serial.dir/home/taterli/pico/pico-sdk/src/common/pico_util/datetime.c.obj
[ 0%] Building C object hello_world/serial/CMakeFiles/hello_serial.dir/home/taterli/pico/pico-sdk/src/common/pico_util/pheap.c.obj
[ 0%] Building C object hello_world/serial/CMakeFiles/hello_serial.dir/home/taterli/pico/pico-sdk/src/common/pico_util/queue.c.obj
[ 0%] Building C object hello_world/serial/CMakeFiles/hello_serial.dir/home/taterli/pico/pico-sdk/src/rp2_common/hardware_uart/uart.c.obj
[ 0%] Building C object hello_world/serial/CMakeFiles/hello_serial.dir/home/taterli/pico/pico-sdk/src/rp2_common/hardware_clocks/clocks.c.obj
[ 0%] Building C object hello_world/serial/CMakeFiles/hello_serial.dir/home/taterli/pico/pico-sdk/src/rp2_common/hardware_pll/pll.c.obj
[ 0%] Building C object hello_world/serial/CMakeFiles/hello_serial.dir/home/taterli/pico/pico-sdk/src/rp2_common/hardware_vreg/vreg.c.obj
[ 0%] Building C object hello_world/serial/CMakeFiles/hello_serial.dir/home/taterli/pico/pico-sdk/src/rp2_common/hardware_watchdog/watchdog.c.obj
[ 0%] Building C object hello_world/serial/CMakeFiles/hello_serial.dir/home/taterli/pico/pico-sdk/src/rp2_common/hardware_ticks/ticks.c.obj
[ 0%] Building C object hello_world/serial/CMakeFiles/hello_serial.dir/home/taterli/pico/pico-sdk/src/rp2_common/hardware_xosc/xosc.c.obj
[ 0%] Building C object hello_world/serial/CMakeFiles/hello_serial.dir/home/taterli/pico/pico-sdk/src/rp2_common/hardware_divider/divider.c.obj
[ 0%] Building C object hello_world/serial/CMakeFiles/hello_serial.dir/home/taterli/pico/pico-sdk/src/rp2_common/pico_runtime/runtime.c.obj
[ 0%] Building C object hello_world/serial/CMakeFiles/hello_serial.dir/home/taterli/pico/pico-sdk/src/rp2_common/pico_runtime_init/runtime_init.c.obj
[ 0%] Building C object hello_world/serial/CMakeFiles/hello_serial.dir/home/taterli/pico/pico-sdk/src/rp2_common/pico_runtime_init/runtime_init_clocks.c.obj
[ 0%] Building C object hello_world/serial/CMakeFiles/hello_serial.dir/home/taterli/pico/pico-sdk/src/rp2_common/pico_runtime_init/runtime_init_stack_guard.c.obj
[ 0%] Building ASM object hello_world/serial/CMakeFiles/hello_serial.dir/home/taterli/pico/pico-sdk/src/rp2_common/pico_bit_ops/bit_ops_aeabi.S.obj
[ 0%] Building C object hello_world/serial/CMakeFiles/hello_serial.dir/home/taterli/pico/pico-sdk/src/rp2_common/pico_bootrom/bootrom.c.obj
[ 0%] Building C object hello_world/serial/CMakeFiles/hello_serial.dir/home/taterli/pico/pico-sdk/src/rp2_common/pico_bootrom/bootrom_lock.c.obj
[ 0%] Building C object hello_world/serial/CMakeFiles/hello_serial.dir/home/taterli/pico/pico-sdk/src/rp2_common/hardware_boot_lock/boot_lock.c.obj
[ 0%] Building C object hello_world/serial/CMakeFiles/hello_serial.dir/home/taterli/pico/pico-sdk/src/rp2_common/pico_divider/divider_compiler.c.obj
[ 0%] Building C object hello_world/serial/CMakeFiles/hello_serial.dir/home/taterli/pico/pico-sdk/src/rp2_common/pico_malloc/malloc.c.obj
[ 0%] Building C object hello_world/serial/CMakeFiles/hello_serial.dir/home/taterli/pico/pico-sdk/src/rp2_common/pico_atomic/atomic.c.obj
[ 50%] Building CXX object hello_world/serial/CMakeFiles/hello_serial.dir/home/taterli/pico/pico-sdk/src/rp2_common/pico_cxx_options/new_delete.cpp.obj
[ 50%] Building C object hello_world/serial/CMakeFiles/hello_serial.dir/home/taterli/pico/pico-sdk/src/rp2_common/pico_standard_binary_info/standard_binary_info.c.obj
[ 50%] Building C object hello_world/serial/CMakeFiles/hello_serial.dir/home/taterli/pico/pico-sdk/src/rp2_common/pico_printf/printf.c.obj
[ 50%] Building ASM object hello_world/serial/CMakeFiles/hello_serial.dir/home/taterli/pico/pico-sdk/src/rp2_common/pico_crt0/crt0_riscv.S.obj
[ 50%] Building C object hello_world/serial/CMakeFiles/hello_serial.dir/home/taterli/pico/pico-sdk/src/rp2_common/pico_clib_interface/newlib_interface.c.obj
[ 50%] Building C object hello_world/serial/CMakeFiles/hello_serial.dir/home/taterli/pico/pico-sdk/src/rp2_common/pico_stdio/stdio.c.obj
[ 50%] Building C object hello_world/serial/CMakeFiles/hello_serial.dir/home/taterli/pico/pico-sdk/src/rp2_common/pico_stdio_uart/stdio_uart.c.obj
[ 50%] Linking CXX executable hello_serial.elf
[ 50%] Built target hello_serial
[ 50%] Building C object hello_world/usb/CMakeFiles/hello_usb.dir/hello_usb.c.obj
[ 50%] Building C object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/src/rp2_common/pico_stdlib/stdlib.c.obj
[ 50%] Building C object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/src/rp2_common/hardware_gpio/gpio.c.obj
[ 50%] Building C object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/src/rp2350/pico_platform/platform.c.obj
[ 50%] Building C object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/src/rp2_common/pico_platform_panic/panic.c.obj
[ 50%] Building C object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/src/common/hardware_claim/claim.c.obj
[ 50%] Building C object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/src/rp2_common/hardware_sync/sync.c.obj
[ 50%] Building C object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/src/rp2_common/hardware_sync_spin_lock/sync_spin_lock.c.obj
[ 50%] Building C object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/src/rp2_common/hardware_irq/irq.c.obj
[ 50%] Building ASM object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/src/rp2_common/hardware_irq/irq_handler_chain.S.obj
[ 50%] Building C object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/src/common/pico_sync/sem.c.obj
[ 50%] Building C object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/src/common/pico_sync/lock_core.c.obj
[ 50%] Building C object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/src/common/pico_sync/mutex.c.obj
[ 50%] Building C object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/src/common/pico_sync/critical_section.c.obj
[ 50%] Building C object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/src/common/pico_time/time.c.obj
[ 50%] Building C object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/src/common/pico_time/timeout_helper.c.obj
[ 50%] Building C object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/src/rp2_common/hardware_timer/timer.c.obj
[ 50%] Building C object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/src/common/pico_util/datetime.c.obj
[ 50%] Building C object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/src/common/pico_util/pheap.c.obj
[ 50%] Building C object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/src/common/pico_util/queue.c.obj
[ 50%] Building C object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/src/rp2_common/hardware_uart/uart.c.obj
[ 50%] Building C object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/src/rp2_common/hardware_clocks/clocks.c.obj
[ 50%] Building C object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/src/rp2_common/hardware_pll/pll.c.obj
[ 50%] Building C object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/src/rp2_common/hardware_vreg/vreg.c.obj
[ 50%] Building C object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/src/rp2_common/hardware_watchdog/watchdog.c.obj
[ 50%] Building C object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/src/rp2_common/hardware_ticks/ticks.c.obj
[ 50%] Building C object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/src/rp2_common/hardware_xosc/xosc.c.obj
[ 50%] Building C object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/src/rp2_common/hardware_divider/divider.c.obj
[ 50%] Building C object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/src/rp2_common/pico_runtime/runtime.c.obj
[ 50%] Building C object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/src/rp2_common/pico_runtime_init/runtime_init.c.obj
[ 50%] Building C object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/src/rp2_common/pico_runtime_init/runtime_init_clocks.c.obj
[ 50%] Building C object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/src/rp2_common/pico_runtime_init/runtime_init_stack_guard.c.obj
[ 50%] Building ASM object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/src/rp2_common/pico_bit_ops/bit_ops_aeabi.S.obj
[ 50%] Building C object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/src/rp2_common/pico_bootrom/bootrom.c.obj
[ 50%] Building C object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/src/rp2_common/pico_bootrom/bootrom_lock.c.obj
[ 50%] Building C object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/src/rp2_common/hardware_boot_lock/boot_lock.c.obj
[ 50%] Building C object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/src/rp2_common/pico_divider/divider_compiler.c.obj
[ 50%] Building C object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/src/rp2_common/pico_malloc/malloc.c.obj
[ 50%] Building C object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/src/rp2_common/pico_atomic/atomic.c.obj
[ 50%] Building CXX object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/src/rp2_common/pico_cxx_options/new_delete.cpp.obj
[ 50%] Building C object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/src/rp2_common/pico_standard_binary_info/standard_binary_info.c.obj
[ 50%] Building C object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/src/rp2_common/pico_printf/printf.c.obj
[ 50%] Building ASM object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/src/rp2_common/pico_crt0/crt0_riscv.S.obj
[ 50%] Building C object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/src/rp2_common/pico_clib_interface/newlib_interface.c.obj
[ 50%] Building C object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/src/rp2_common/pico_stdio/stdio.c.obj
[ 50%] Building C object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/src/rp2_common/pico_stdio_usb/reset_interface.c.obj
[ 50%] Building C object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/src/rp2_common/pico_stdio_usb/stdio_usb.c.obj
[ 50%] Building C object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/src/rp2_common/pico_stdio_usb/stdio_usb_descriptors.c.obj
[ 50%] Building C object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/src/rp2_common/pico_unique_id/unique_id.c.obj
[ 50%] Building C object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/src/rp2_common/hardware_flash/flash.c.obj
[ 50%] Building C object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/lib/tinyusb/src/portable/raspberrypi/rp2040/dcd_rp2040.c.obj
[ 50%] Building C object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/lib/tinyusb/src/portable/raspberrypi/rp2040/rp2040_usb.c.obj
[ 50%] Building C object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/lib/tinyusb/src/device/usbd.c.obj
[ 50%] Building C object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/lib/tinyusb/src/device/usbd_control.c.obj
[ 50%] Building C object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/lib/tinyusb/src/class/audio/audio_device.c.obj
[ 50%] Building C object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/lib/tinyusb/src/class/cdc/cdc_device.c.obj
[ 50%] Building C object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/lib/tinyusb/src/class/dfu/dfu_device.c.obj
[ 50%] Building C object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/lib/tinyusb/src/class/dfu/dfu_rt_device.c.obj
[ 50%] Building C object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/lib/tinyusb/src/class/hid/hid_device.c.obj
[ 50%] Building C object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/lib/tinyusb/src/class/midi/midi_device.c.obj
[ 50%] Building C object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/lib/tinyusb/src/class/msc/msc_device.c.obj
[ 50%] Building C object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/lib/tinyusb/src/class/net/ecm_rndis_device.c.obj
[ 50%] Building C object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/lib/tinyusb/src/class/net/ncm_device.c.obj
[ 50%] Building C object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/lib/tinyusb/src/class/usbtmc/usbtmc_device.c.obj
[ 50%] Building C object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/lib/tinyusb/src/class/vendor/vendor_device.c.obj
[ 50%] Building C object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/lib/tinyusb/src/class/video/video_device.c.obj
[ 50%] Building C object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/lib/tinyusb/src/tusb.c.obj
[ 50%] Building C object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/lib/tinyusb/src/common/tusb_fifo.c.obj
[ 50%] Building C object hello_world/usb/CMakeFiles/hello_usb.dir/home/taterli/pico/pico-sdk/src/rp2_common/pico_fix/rp2040_usb_device_enumeration/rp2040_usb_device_enumeration.c.obj
[100%] Linking CXX executable hello_usb.elf
[100%] Built target hello_usb
taterli@taterli-desktop:~/pico-examples/build/hello_world$ file usb/hello_usb.elf
usb/hello_usb.elf: ELF 32-bit LSB executable, UCB RISC-V, RVC, soft-float ABI, version 1 (SYSV), statically linked, with debug_info, not stripped
taterli@taterli-desktop:~/pico-examples/build/hello_world$ cp usb/hello_usb.uf2 /media/taterli/RP2350/
taterli@taterli-desktop:~/pico-examples/build/hello_world$
编译结果
串口验证
如果项目涉及FreeRTOS,则需要使用树莓派官方目前维护的分支才可以.
git clone https://github.com/raspberrypi/FreeRTOS-Kernel
export FREERTOS_KERNEL_PATH=~/FreeRTOS
需要重新cmake才能识别,最后跑一下Coremark.
https://github.com/protik09/CoreMark-RP2040
需要修改为单线程跑,因为目前多核支持还是不很完善.主要是core_portme.h,修改MULTITHREAD=1,使用Release进行编译,结果如下.
2K performance run parameters for coremark.
CoreMark Size : 666
Total ticks : 6657757
Total time (secs): 13.315515
Iterations/Sec : 225.301086
Iterations : 6000
Compiler version : GCC13.2.0
Compiler flags : og
Memory location : STACK
seedcrc : 0xe9f5
[0]crclist : 0xe714
[0]crcmatrix : 0x1fd7
[0]crcstate : 0x8e3a
[0]crcfinal : 0xa14c
Correct operation validated. See README.md for run and reporting rules.
CoreMark 1.0 : 225.301086 / GCC13.2.0 og / STACK
作为对比,我也编译了ARM核测试,性能确实高很多.
2K performance run parameters for coremark.
CoreMark Size : 666
Total ticks : 13479668
Total time (secs): 13.479668
Iterations/Sec : 445.114820
Iterations : 6000
Compiler version : GCC13.2.1 20231009
Compiler flags : og
Memory location : STACK
seedcrc : 0xe9f5
[0]crclist : 0xe714
[0]crcmatrix : 0x1fd7
[0]crcstate : 0x8e3a
[0]crcfinal : 0xa14c
Correct operation validated. See README.md for run and reporting rules.
CoreMark 1.0 : 445.114820 / GCC13.2.1 20231009 og / STACK