Skip to content

Conversation

@shtirlic
Copy link
Contributor

@shtirlic shtirlic commented May 22, 2025

Summary

Add support for RP2350 RISC-V cores, Add Pico 2 board.

Naming

Chip name   : rp23xx-rv
Board name  : raspberrypi-pico-2-rv 
Arch        : risc-v

Changes from ARM rp23xx impl

  • Linker script update
  • ASM head start
  • Update chip start
  • New Hazard3 include regs
  • Remove rp23xx chip hw spinlocks/testset
  • New irq handling (external IRQ interrupt)
  • New timerisr based on RISC-V std MTIME and alarm arch
  • No SMP yet
  • Tickless option
  • Double size for idle, irq and main stacks
  • Board reset via watchdog trigger
    ...

Todo

  • Uart defconfig
  • ostest pass
  • usb defconfig
  • [?] SMP (will be done later)
  • Reset (via watchdog trigger without wd dev)
  • Hazard3 external IRQ
  • [?] More timers (will be done later)
  • [?] Tickless testing (will be done later)
  • Peripherals testing
    • WDOG
    • UART
    • USB
    • PWM
    • I2C
    • SPI
    • DMA
  • Docs
    • Add chip
    • Add board
    • Toolchain info
  • [?] Other boards (will be done later)
  • RISC-V Custom extensions (zba_zbb_zbs_zbkb_zca_zcb_zcmp in defconfig, add to chip?)
  • [?] Compare getprime perf (will be done later)
  • [?] LVGL perf test (will be done later)

Toolchain

Use RISC-V gnu toolchain with soft float abi. Default riscv-collab uses double float abi

This is config for https://github.com/riscv-collab/riscv-gnu-toolchain

./configure --prefix=/opt/riscv --with-arch=rv32imac --with-abi=ilp32

Config

Serial NSH

/tools/configure.sh raspberrypi-pico-2-rv:nsh

USB CDC/ACM Serial NSH

/tools/configure.sh raspberrypi-pico-2-rv:usbnsh

Testing

cpuinfo

nsh> cat /proc/cpuinfo
processor       : 0
hart            : 0
isa             : rv32imac
mmu             : none

nsh> free
      total       used       free    maxused    maxfree  nused  nfree name
     516820       7116     509704      45768     490456     25      3 Umem

getprime

nsh> getprime
Set thread priority to 10
Set thread policy to SCHED_RR
Start thread #0
thread #0 started, looking for primes < 10000, doing 10 run(s)
thread #0 finished, found 1230 primes, last one was 9973
Done
getprime took 4281 msec
ostest nsh output
NuttShell (NSH) NuttX-12.9.0
nsh> 
nsh> ostest
stdio_test: write fd=1
stdio_test: Standard I/O Check: printf
stdio_test: write fd=2
stdio_test: Standard I/O Check: fprintf to stderr
ostest_main: putenv(Variable1=BadValue3)
ostest_main: setenv(Variable1, GoodValue1, TRUE)
ostest_main: setenv(Variable2, BadValue1, FALSE)
ostest_main: setenv(Variable2, GoodValue2, TRUE)
ostest_main: setenv(Variable3, GoodValue3, FALSE)
ostest_main: setenv(Variable3, BadValue2, FALSE)
show_variable: Variable=Variable1 has value=GoodValue1
show_variable: Variable=Variable2 has value=GoodValue2
show_variable: Variable=Variable3 has value=GoodValue3
ostest_main: Started user_main at PID=3

user_main: Begin argument test
user_main: Started with argc=5
user_main: argv[0]="ostest"
user_main: argv[1]="Arg1"
user_main: argv[2]="Arg2"
user_main: argv[3]="Arg3"
user_main: argv[4]="Arg4"

End of test memory usage:
VARIABLE  BEFORE   AFTER
======== ======== ========
arena       7e2d4    7e2d4
ordblks         1        1
mxordblk    79ce8    79ce8
uordblks     45ec     45ec
fordblks    79ce8    79ce8

user_main: getopt() test
getopt():  Simple test
getopt():  Invalid argument
getopt():  Missing optional argument
getopt_long():  Simple test
getopt_long():  No short options
getopt_long():  Argument for --option=argument
getopt_long():  Invalid long option
getopt_long():  Mixed long and short options
getopt_long():  Invalid short option
getopt_long():  Missing optional arguments
getopt_long_only():  Mixed long and short options
getopt_long_only():  Single hyphen long options

End of test memory usage:
VARIABLE  BEFORE   AFTER
======== ======== ========
arena       7e2d4    7e2d4
ordblks         1        1
mxordblk    79ce8    79ce8
uordblks     45ec     45ec
fordblks    79ce8    79ce8

user_main: libc tests

End of test memory usage:
VARIABLE  BEFORE   AFTER
======== ======== ========
arena       7e2d4    7e2d4
ordblks         1        1
mxordblk    79ce8    79ce8
uordblks     45ec     45ec
fordblks    79ce8    79ce8
show_variable: Variable=Variable1 has value=GoodValue1
show_variable: Variable=Variable2 has value=GoodValue2
show_variable: Variable=Variable3 has value=GoodValue3
show_variable: Variable=Variable1 has no value
show_variable: Variable=Variable2 has value=GoodValue2
show_variable: Variable=Variable3 has value=GoodValue3

End of test memory usage:
VARIABLE  BEFORE   AFTER
======== ======== ========
arena       7e2d4    7e2d4
ordblks         1        2
mxordblk    79ce8    79ce8
uordblks     45ec     45cc
fordblks    79ce8    79d08
show_variable: Variable=Variable1 has no value
show_variable: Variable=Variable2 has no value
show_variable: Variable=Variable3 has no value

End of test memory usage:
VARIABLE  BEFORE   AFTER
======== ======== ========
arena       7e2d4    7e2d4
ordblks         2        2
mxordblk    79ce8    79ce8
uordblks     45cc     4554
fordblks    79d08    79d80

user_main: setvbuf test
setvbuf_test: Test NO buffering
setvbuf_test: Using NO buffering
setvbuf_test: Test default FULL buffering
setvbuf_test: Using default FULL buffering
setvbuf_test: Test FULL buffering, buffer size 64
setvbuf_test: Using FULL buffering, buffer size 64
setvbuf_test: Test FULL buffering, pre-allocated buffer
setvbuf_test: Using FULL buffering, pre-allocated buffer
setvbuf_test: Test LINE buffering, buffer size 64
setvbuf_test: Using LINE buffering, buffer size 64
setvbuf_test: Test FULL buffering, pre-allocated buffer
setvbuf_test: Using FULL buffering, pre-allocated buffer

End of test memory usage:
VARIABLE  BEFORE   AFTER
======== ======== ========
arena       7e2d4    7e2d4
ordblks         2        2
mxordblk    79ce8    79ce8
uordblks     4554     4554
fordblks    79d80    79d80

user_main: /dev/null test
dev_null: Read 0 bytes from /dev/null
dev_null: Wrote 1024 bytes to /dev/null

End of test memory usage:
VARIABLE  BEFORE   AFTER
======== ======== ========
arena       7e2d4    7e2d4
ordblks         2        2
mxordblk    79ce8    79ce8
uordblks     4554     4554
fordblks    79d80    79d80

user_main: task_restart test

Test task_restart()
restart_main: setenv(VarName, VarValue, TRUE)
restart_main: Started restart_main at PID=4
restart_main: Started with argc=4
restart_main: argv[0]="ostest"
restart_main: argv[1]="This is argument 1"
restart_main: argv[2]="Argument 2 here"
restart_main: argv[3]="Lastly, the 3rd argument"
restart_main: Variable=VarName has value=VarValue
restart_main: I am still here
restart_main: I am still here
restart_main: Started restart_main at PID=4
restart_main: Started with argc=4
restart_main: argv[0]="ostest"
restart_main: argv[1]="This is argument 1"
restart_main: argv[2]="Argument 2 here"
restart_main: argv[3]="Lastly, the 3rd argument"
restart_main: Variable=VarName has value=VarValue
restart_main: Started with argc=4
restart_main: argv[0]="ostest"
restart_main: argv[1]="This is argument 1"
restart_main: argv[2]="Argument 2 here"
restart_main: argv[3]="Lastly, the 3rd argument"
restart_main: Variable=VarName has value=VarValue
restart_main: Exiting

End of test memory usage:
VARIABLE  BEFORE   AFTER
======== ======== ========
arena       7e2d4    7e2d4
ordblks         2        2
mxordblk    79ce8    77930
uordblks     4554     6944
fordblks    79d80    77990

user_main: waitpid test

Test waitpid()
waitpid_start_child: Started waitpid_main at PID=5
waitpid_start_child: Started waitpid_main at PID=6
waitpid_main: PID 5 Started
waitpid_main: PID 6 Started
waitpid_start_child: Started waitpid_main at PID=7
waitpid_main: PID 7 Started
waitpid_test: Waiting for PID=5 with waitpid()
waitpid_main: PID 5 exitting with result=14
waitpid_main: PID 6 exitting with result=14
waitpid_test: PID 5 waitpid succeeded with stat_loc=0e00
waitpid_last: Waiting for PID=7 with waitpid()
waitpid_main: PID 7 exitting with result=14
waitpid_last: PASS: PID 7 waitpid succeeded with stat_loc=0e00

End of test memory usage:
VARIABLE  BEFORE   AFTER
======== ======== ========
arena       7e2d4    7e2d4
ordblks         2        5
mxordblk    77930    73170
uordblks     6944     a954
fordblks    77990    73980

user_main: mutex test
Initializing mutex
Starting thread 1
Starting thread 2
                Thread1 Thread2
        Loops   32      32
        Errors  0       0

Testing moved mutex
Starting moved mutex thread 1
Starting moved mutex thread 2
                Thread1 Thread2
        Moved Loops     32      32
        Moved Errors    0       0

End of test memory usage:
VARIABLE  BEFORE   AFTER
======== ======== ========
arena       7e2d4    7e2d4
ordblks         5        2
mxordblk    73170    79408
uordblks     a954     4e6c
fordblks    73980    79468

user_main: timed mutex test
mutex_test: Initializing mutex
mutex_test: Starting thread
pthread:  Started
pthread:  Waiting for lock or timeout
mutex_test: Unlocking
pthread:  Got the lock
pthread:  Waiting for lock or timeout
pthread:  Got the timeout.  Terminating
mutex_test: PASSED

End of test memory usage:
VARIABLE  BEFORE   AFTER
======== ======== ========
arena       7e2d4    7e2d4
ordblks         2        2
mxordblk    79408    79408
uordblks     4e6c     4e6c
fordblks    79468    79468

user_main: cancel test
cancel_test: Test 1a: Normal Cancellation
cancel_test: Starting thread
start_thread: Initializing mutex
start_thread: Initializing cond
start_thread: Starting thread
start_thread: Yielding
sem_waiter: Taking mutex
sem_waiter: Starting wait for condition
cancel_test: Canceling thread
cancel_test: Joining
cancel_test: waiter exited with result=0xffffffff
cancel_test: PASS thread terminated with PTHREAD_CANCELED
cancel_test: Test 2: Asynchronous Cancellation
... Skipped
cancel_test: Test 3: Cancellation of detached thread
cancel_test: Re-starting thread
restart_thread: Destroying cond
restart_thread: Destroying mutex
restart_thread: Re-starting thread
start_thread: Initializing mutex
start_thread: Initializing cond
start_thread: Starting thread
start_thread: Yielding
sem_waiter: Taking mutex
sem_waiter: Starting wait for condition
cancel_test: Canceling thread
cancel_test: Joining
cancel_test: PASS pthread_join failed with status=ESRCH
cancel_test: Test 5: Non-cancelable threads
cancel_test: Re-starting thread (non-cancelable)
restart_thread: Destroying cond
restart_thread: Destroying mutex
restart_thread: Re-starting thread
start_thread: Initializing mutex
start_thread: Initializing cond
start_thread: Starting thread
start_thread: Yielding
sem_waiter: Taking mutex
sem_waiter: Starting wait for condition
sem_waiter: Setting non-cancelable
cancel_test: Canceling thread
cancel_test: Joining
sem_waiter: Releasing mutex
sem_waiter: Setting cancelable
cancel_test: waiter exited with result=0xffffffff
cancel_test: PASS thread terminated with PTHREAD_CANCELED
cancel_test: Test 6: Cancel message queue wait
cancel_test: Starting thread (cancelable)
Skipped
cancel_test: Test 7: Cancel signal wait
cancel_test: Starting thread (cancelable)
Skipped

End of test memory usage:
VARIABLE  BEFORE   AFTER
======== ======== ========
arena       7e2d4    7e2d4
ordblks         2        2
mxordblk    79408    77c08
uordblks     4e6c     666c
fordblks    79468    77c68

user_main: robust test
robust_test: Initializing mutex
robust_test: Starting thread
robust_waiter: Taking mutex
robust_waiter: Exiting with mutex
robust_test: Take the lock again
robust_test: Make the mutex consistent again.
robust_test: Take the lock again
robust_test: Joining
robust_test: waiter exited with result=0
robust_test: Test complete with nerrors=0

End of test memory usage:
VARIABLE  BEFORE   AFTER
======== ======== ========
arena       7e2d4    7e2d4
ordblks         2        2
mxordblk    77c08    77c08
uordblks     666c     666c
fordblks    77c68    77c68

user_main: semaphore test
sem_test: Initializing semaphore to 0
sem_test: Starting waiter thread 1
sem_test: Set thread 1 priority to 191
waiter_func: Thread 1 Started
sem_test: Starting waiter thread 2
waiter_func: Thread 1 initial semaphore value = 0
sem_test: Set thread 2 priority to 128
waiter_func: Thread 1 waiting on semaphore
waiter_func: Thread 2 Started
waiter_func: Thread 2 initial semaphore value = -1
waiter_func: Thread 2 waiting on semaphore
sem_test: Starting poster thread 3
sem_test: Set thread 3 priority to 64
poster_func: Thread 3 started
poster_func: Thread 3 semaphore value = -2
poster_func: Thread 3 posting semaphore
waiter_func: Thread 1 awakened
waiter_func: Thread 1 new semaphore value = -1
waiter_func: Thread 1 done
poster_func: Thread 3 new semaphore value = -1
poster_func: Thread 3 semaphore value = -1
poster_func: Thread 3 posting semaphore
waiter_func: Thread 2 awakened
poster_func: Thread 3 new semaphore value = 0
waiter_func: Thread 2 new semaphore value = 0
poster_func: Thread 3 done
waiter_func: Thread 2 done

End of test memory usage:
VARIABLE  BEFORE   AFTER
======== ======== ========
arena       7e2d4    7e2d4
ordblks         2        3
mxordblk    77c08    78248
uordblks     666c     574c
fordblks    77c68    78b88

user_main: timed semaphore test
semtimed_test: Initializing semaphore to 0
semtimed_test: Waiting for two second timeout
semtimed_test: PASS: first test returned timeout
BEFORE: (33 sec, 682764966 nsec)
AFTER:  (35 sec, 690225406 nsec)
semtimed_test: Starting poster thread
semtimed_test: Set thread 1 priority to 191
semtimed_test: Starting poster thread 3
semtimed_test: Set thread 3 priority to 64
semtimed_test: Waiting for two second timeout
poster_func: Waiting for 1 second
poster_func: Posting
semtimed_test: PASS: sem_timedwait succeeded
BEFORE: (35 sec, 693431933 nsec)
AFTER:  (36 sec, 700571253 nsec)

End of test memory usage:
VARIABLE  BEFORE   AFTER
======== ======== ========
arena       7e2d4    7e2d4
ordblks         3        2
mxordblk    78248    79408
uordblks     574c     4e6c
fordblks    78b88    79468

user_main: condition variable test
cond_test: Initializing mutex
cond_test: Initializing cond
cond_test: Starting waiter
cond_test: Set thread 1 priority to 128
waiter_thread: Started
cond_test: Starting signaler
cond_test: Set thread 2 priority to 64
thread_signaler: Started
thread_signaler: Terminating
cond_test: signaler terminated, now cancel the waiter
cond_test:      Waiter  Signaler
cond_test: Loops        32      32
cond_test: Errors       0       0
cond_test:
cond_test: 0 times, waiter did not have to wait for data
cond_test: 0 times, data was already available when the signaler run
cond_test: 0 times, the waiter was in an unexpected state when the signaler ran

End of test memory usage:
VARIABLE  BEFORE   AFTER
======== ======== ========
arena       7e2d4    7e2d4
ordblks         2        3
mxordblk    79408    78b28
uordblks     4e6c     4e6c
fordblks    79468    79468

user_main: pthread_exit() test
pthread_exit_test: Started pthread_exit_main at PID=27
pthread_exit_main 27: Starting pthread_exit_thread
pthread_exit_main 27: Sleeping for 5 seconds
pthread_exit_thread 28: Sleeping for 10 second
pthread_exit_thread 28: Still running...
pthread_exit_main 27: Calling pthread_exit()

End of test memory usage:
VARIABLE  BEFORE   AFTER
======== ======== ========
arena       7e2d4    7e2d4
ordblks         3        2
mxordblk    78b28    77328
uordblks     4e6c     6f4c
fordblks    79468    77388

user_main: pthread_rwlock test
pthread_rwlock: Initializing rwlock
pthread_exit_thread 28: Exiting

End of test memory usage:
VARIABLE  BEFORE   AFTER
======== ======== ========
arena       7e2d4    7e2d4
ordblks         2        3
mxordblk    77328    77328
uordblks     6f4c     4e7c
fordblks    77388    79458

user_main: pthread_rwlock_cancel test
pthread_rwlock_cancel: Starting test

End of test memory usage:
VARIABLE  BEFORE   AFTER
======== ======== ========
arena       7e2d4    7e2d4
ordblks         3        2
mxordblk    77328    79ce8
uordblks     4e7c     459c
fordblks    79458    79d38

user_main: timed wait test
thread_waiter: Initializing mutex
timedwait_test: Initializing cond
timedwait_test: Starting waiter
timedwait_test: Set thread 2 priority to 177
thread_waiter: Taking mutex
thread_waiter: Starting 5 second wait for condition
timedwait_test: Joining
thread_waiter: pthread_cond_timedwait timed out
thread_waiter: Releasing mutex
thread_waiter: Exit with status 0x12345678
timedwait_test: waiter exited with result=0x12345678

End of test memory usage:
VARIABLE  BEFORE   AFTER
======== ======== ========
arena       7e2d4    7e2d4
ordblks         2        2
mxordblk    79ce8    79408
uordblks     459c     4e7c
fordblks    79d38    79458

user_main: message queue test
mqueue_test: Starting receiver
mqueue_test: Set receiver priority to 128
receiver_thread: Starting
mqueue_test: Starting sender
mqueue_test: Set sender thread priority to 64
mqueue_test: Waiting for sender to complete
sender_thread: Starting
receiver_thread: mq_receive succeeded on msg 0
sender_thread: mq_send succeeded on msg 0
receiver_thread: mq_receive succeeded on msg 1
sender_thread: mq_send succeeded on msg 1
receiver_thread: mq_receive succeeded on msg 2
sender_thread: mq_send succeeded on msg 2
receiver_thread: mq_receive succeeded on msg 3
sender_thread: mq_send succeeded on msg 3
receiver_thread: mq_receive succeeded on msg 4
sender_thread: mq_send succeeded on msg 4
receiver_thread: mq_receive succeeded on msg 5
sender_thread: mq_send succeeded on msg 5
receiver_thread: mq_receive succeeded on msg 6
sender_thread: mq_send succeeded on msg 6
receiver_thread: mq_receive succeeded on msg 7
sender_thread: mq_send succeeded on msg 7
receiver_thread: mq_receive succeeded on msg 8
sender_thread: mq_send succeeded on msg 8
receiver_thread: mq_receive succeeded on msg 9
sender_thread: mq_send succeeded on msg 9
sender_thread: returning nerrors=0
mqueue_test: Killing receiver
receiver_thread: mq_receive interrupted!
receiver_thread: returning nerrors=0
mqueue_test: Canceling receiver
mqueue_test: receiver has already terminated

End of test memory usage:
VARIABLE  BEFORE   AFTER
======== ======== ========
arena       7e2d4    7e2d4
ordblks         2        2
mxordblk    79408    77bd8
uordblks     4e7c     66dc
fordblks    79458    77bf8

user_main: timed message queue test
timedmqueue_test: Starting sender
timedmqueue_test: Waiting for sender to complete
sender_thread: Starting
sender_thread: mq_timedsend succeeded on msg 0
sender_thread: mq_timedsend succeeded on msg 1
sender_thread: mq_timedsend succeeded on msg 2
sender_thread: mq_timedsend succeeded on msg 3
sender_thread: mq_timedsend succeeded on msg 4
sender_thread: mq_timedsend succeeded on msg 5
sender_thread: mq_timedsend succeeded on msg 6
sender_thread: mq_timedsend succeeded on msg 7
sender_thread: mq_timedsend succeeded on msg 8
sender_thread: mq_timedsend 9 timed out as expected
sender_thread: returning nerrors=0
timedmqueue_test: Starting receiver
timedmqueue_test: Waiting for receiver to complete
receiver_thread: Starting
receiver_thread: mq_timedreceive succeed on msg 0
receiver_thread: mq_timedreceive succeed on msg 1
receiver_thread: mq_timedreceive succeed on msg 2
receiver_thread: mq_timedreceive succeed on msg 3
receiver_thread: mq_timedreceive succeed on msg 4
receiver_thread: mq_timedreceive succeed on msg 5
receiver_thread: mq_timedreceive succeed on msg 6
receiver_thread: mq_timedreceive succeed on msg 7
receiver_thread: mq_timedreceive succeed on msg 8
receiver_thread: Receive 9 timed out as expected
receiver_thread: returning nerrors=0
timedmqueue_test: Test complete

End of test memory usage:
VARIABLE  BEFORE   AFTER
======== ======== ========
arena       7e2d4    7e2d4
ordblks         2        2
mxordblk    77bd8    77bd8
uordblks     66dc     66dc
fordblks    77bf8    77bf8

user_main: sigprocmask test
sigprocmask_test: SUCCESS

End of test memory usage:
VARIABLE  BEFORE   AFTER
======== ======== ========
arena       7e2d4    7e2d4
ordblks         2        2
mxordblk    77bd8    77bd8
uordblks     66dc     66dc
fordblks    77bf8    77bf8

user_main: signal handler test
sighand_test: Initializing semaphore to 0
sighand_test: Starting waiter task
sighand_test: Started waiter_main pid=44
waiter_main: Waiter started
waiter_main: Unmasking signal 32
waiter_main: Registering signal handler
waiter_main: oact.sigaction=0 oact.sa_flags=0 oact.sa_mask=0000000000000000
waiter_main: Waiting on semaphore
sighand_test: Signaling pid=44 with signo=32 sigvalue=42
waiter_main: sem_wait() successfully interrupted by signal
waiter_main: done
sighand_test: done

End of test memory usage:
VARIABLE  BEFORE   AFTER
======== ======== ========
arena       7e2d4    7e2d4
ordblks         2        1
mxordblk    77bd8    77bc8
uordblks     66dc     670c
fordblks    77bf8    77bc8

user_main: nested signal handler test
signest_test: Starting signal waiter task at priority 101
waiter_main: Waiter started
waiter_main: Setting signal mask
signest_test: Started waiter_main pid=45
waiter_main: Registering signal handler
signest_test: Starting interfering task at priority 102
waiter_main: Waiting on semaphore
interfere_main: Waiting on semaphore
signest_test: Started interfere_main pid=46
signest_test: Simple case:
  Total signalled 1240  Odd=620 Even=620
  Total handled   1240  Odd=620 Even=620
  Total nested    0    Odd=0   Even=0  
signest_test: With task locking
  Total signalled 2480  Odd=1240 Even=1240
  Total handled   2480  Odd=1240 Even=1240
  Total nested    0    Odd=0   Even=0  
signest_test: With intefering thread
  Total signalled 3720  Odd=1860 Even=1860
  Total handled   3720  Odd=1860 Even=1860
  Total nested    0    Odd=0   Even=0  
signest_test: done

End of test memory usage:
VARIABLE  BEFORE   AFTER
======== ======== ========
arena       7e2d4    7e2d4
ordblks         1        2
mxordblk    77bc8    75398
uordblks     670c     6e6c
fordblks    77bc8    77468

user_main: wdog test
wdog_test start...
wdtest_once 0 ns
wdtest_once 0 ns
wdtest_once 0 ns
wdtest_once 0 ns
wdtest_once 1 ns
wdtest_once 1 ns
wdtest_once 1 ns
wdtest_once 1 ns
wdtest_once 10 ns
wdtest_once 10 ns
wdtest_once 10 ns
wdtest_once 10 ns
wdtest_once 100 ns
wdtest_once 100 ns
wdtest_once 100 ns
wdtest_once 100 ns
wdtest_once 1000 ns
wdtest_once 1000 ns
wdtest_once 1000 ns
wdtest_once 1000 ns
wdtest_once 10000 ns
wdtest_once 10000 ns
wdtest_once 10000 ns
wdtest_once 10000 ns
wdtest_once 100000 ns
wdtest_once 100000 ns
wdtest_once 100000 ns
wdtest_once 100000 ns
wdtest_once 1000000 ns
wdtest_once 1000000 ns
wdtest_once 1000000 ns
wdtest_once 1000000 ns
wd_start with maximum delay, cancel OK, rest 2147483646
wdtest_recursive 1000000us
wd_start with maximum delay, cancel OK, rest 2147483646
wdtest_recursive 1000000us
wd_start with maximum delay, cancel OK, rest 2147483645
wdtest_recursive 1000000us
wd_start with maximum delay, cancel OK, rest 2147483645
wdtest_recursive 1000000us
recursive wdog triggered 6 times, elapsed tick 12
wdtest_recursive 10000000us
recursive wdog triggered 6 times, elapsed tick 12
wdtest_recursive 10000000us
recursive wdog triggered 6 times, elapsed tick 12
wdtest_recursive 10000000us
recursive wdog triggered 6 times, elapsed tick 12
wdtest_recursive 10000000us
recursive wdog triggered 6 times, elapsed tick 12
recursive wdog triggered 6 times, elapsed tick 12
recursive wdog triggered 6 times, elapsed tick 12
recursive wdog triggered 6 times, elapsed tick 12
wdog_test end...

End of test memory usage:
VARIABLE  BEFORE   AFTER
======== ======== ========
arena       7e2d4    7e2d4
ordblks         2        3
mxordblk    75398    75398
uordblks     6e6c     710c
fordblks    77468    771c8

user_main: round-robin scheduler test
rr_test: Set thread priority to 1
rr_test: Set thread policy to SCHED_RR
rr_test: Starting first get_primes_thread
         First get_primes_thread: 55
rr_test: Starting second get_primes_thread
         Second get_primes_thread: 56
rr_test: Waiting for threads to complete -- this should take awhile
         If RR scheduling is working, they should start and complete at
         about the same time
get_primes_thread id=1 started, looking for primes < 10000, doing 10 run(s)
get_primes_thread id=2 started, looking for primes < 10000, doing 10 run(s)
get_primes_thread id=1 finished, found 1230 primes, last one was 9973
get_primes_thread id=2 finished, found 1230 primes, last one was 9973
rr_test: Done

End of test memory usage:
VARIABLE  BEFORE   AFTER
======== ======== ========
arena       7e2d4    7e2d4
ordblks         3        3
mxordblk    75398    75398
uordblks     710c     5f4c
fordblks    771c8    78388

user_main: barrier test
barrier_test: Initializing barrier
barrier_test: Thread 0 created
barrier_test: Thread 1 created
barrier_func: Thread 0 started
barrier_func: Thread 1 started
barrier_test: Thread 2 created
barrier_func: Thread 2 started
barrier_test: Thread 3 created
barrier_func: Thread 3 started
barrier_test: Thread 4 created
barrier_func: Thread 4 started
barrier_test: Thread 5 created
barrier_func: Thread 5 started
barrier_test: Thread 6 created
barrier_func: Thread 6 started
barrier_test: Thread 7 created
barrier_func: Thread 7 started
barrier_func: Thread 0 calling pthread_barrier_wait()
barrier_func: Thread 1 calling pthread_barrier_wait()
barrier_func: Thread 2 calling pthread_barrier_wait()
barrier_func: Thread 3 calling pthread_barrier_wait()
barrier_func: Thread 4 calling pthread_barrier_wait()
barrier_func: Thread 5 calling pthread_barrier_wait()
barrier_func: Thread 6 calling pthread_barrier_wait()
barrier_func: Thread 7 calling pthread_barrier_wait()
barrier_func: Thread 7, back with status=PTHREAD_BARRIER_SERIAL_THREAD (I AM SPECIAL)
barrier_func: Thread 0, back with status=0 (I am not special)
barrier_func: Thread 1, back with status=0 (I am not special)
barrier_func: Thread 2, back with status=0 (I am not special)
barrier_func: Thread 3, back with status=0 (I am not special)
barrier_func: Thread 4, back with status=0 (I am not special)
barrier_func: Thread 5, back with status=0 (I am not special)
barrier_func: Thread 6, back with status=0 (I am not special)
barrier_func: Thread 7 done
barrier_func: Thread 0 done
barrier_func: Thread 1 done
barrier_test: Thread 0 completed with result=0
barrier_test: Thread 1 completed with result=0
barrier_func: Thread 2 done
barrier_func: Thread 3 done
barrier_test: Thread 2 completed with result=0
barrier_test: Thread 3 completed with result=0
barrier_func: Thread 4 done
barrier_func: Thread 5 done
barrier_test: Thread 4 completed with result=0
barrier_test: Thread 5 completed with result=0
barrier_func: Thread 6 done
barrier_test: Thread 6 completed with result=0
barrier_test: Thread 7 completed with result=0

End of test memory usage:
VARIABLE  BEFORE   AFTER
======== ======== ========
arena       7e2d4    7e2d4
ordblks         3        5
mxordblk    75398    75398
uordblks     5f4c     5f4c
fordblks    78388    78388

user_main: scheduler lock test
sched_lock: Starting lowpri_thread at 97
sched_lock: Set lowpri_thread priority to 97
sched_lock: Starting highpri_thread at 98
sched_lock: Set highpri_thread priority to 98
sched_lock: Waiting...
sched_lock: PASSED No pre-emption occurred while scheduler was locked.
sched_lock: Starting lowpri_thread at 97
sched_lock: Set lowpri_thread priority to 97
sched_lock: Starting highpri_thread at 98
sched_lock: Set highpri_thread priority to 98
sched_lock: Waiting...
sched_lock: PASSED No pre-emption occurred while scheduler was locked.
sched_lock: Finished

End of test memory usage:
VARIABLE  BEFORE   AFTER
======== ======== ========
arena       7e2d4    7e2d4
ordblks         5        4
mxordblk    75398    75398
uordblks     5f4c     566c
fordblks    78388    78c68

user_main: vfork() test
vfork_test: Child 73 ran successfully

Final memory usage:
VARIABLE  BEFORE   AFTER
======== ======== ========
arena       7e2d4    7e2d4
ordblks         1        3
mxordblk    79ce8    75398
uordblks     45ec     6d94
fordblks    79ce8    77540
user_main: Exiting
ostest_main: Exiting with status 0

@github-actions github-actions bot added Arch: risc-v Issues related to the RISC-V (32-bit or 64-bit) architecture Board: risc-v Size: XL The size of the change in this PR is very large. Consider breaking down the PR into smaller pieces. labels May 22, 2025
@keever50
Copy link
Contributor

Wow!
That's great. I love RISC-V. I did not expect this RP23xx RISC-V to come to NuttX.
I will be testing this out today as well, thanks!

@acassis
Copy link
Contributor

acassis commented May 22, 2025

@shtirlic amazing! Kudos!!!

@keever50
Copy link
Contributor

Hmm, @shtirlic
configuration fails and I am not entirely sure what this means.
I cloned your branch.

Output of ./tools/configure.sh from NuttX:

mkkconfig in /home/martini/projects/cleannuttx/nuttx-apps
warning: the choice symbol RP23XX_CLK_GPOUT0_SRC_REF (defined at arch/arm/src/rp23xx/Kconfig:835, arch/risc-v/src/rp23xx-riscv/Kconfig:826) is defined with a prompt outside the choice
warning: the choice symbol RP23XX_CLK_GPOUT0_SRC_SYS (defined at arch/arm/src/rp23xx/Kconfig:842, arch/risc-v/src/rp23xx-riscv/Kconfig:833) is defined with a prompt outside the choice
warning: the choice symbol RP23XX_CLK_GPOUT0_SRC_USB (defined at arch/arm/src/rp23xx/Kconfig:848, arch/risc-v/src/rp23xx-riscv/Kconfig:839) is defined with a prompt outside the choice
warning: the choice symbol RP23XX_CLK_GPOUT0_SRC_ADC (defined at arch/arm/src/rp23xx/Kconfig:853, arch/risc-v/src/rp23xx-riscv/Kconfig:844) is defined with a prompt outside the choice
warning: the choice symbol RP23XX_CLK_GPOUT0_SRC_PERI (defined at arch/arm/src/rp23xx/Kconfig:858, arch/risc-v/src/rp23xx-riscv/Kconfig:849) is defined with a prompt outside the choice
warning: the choice symbol RP23XX_CLK_GPOUT0_SRC_HSTX (defined at arch/arm/src/rp23xx/Kconfig:863, arch/risc-v/src/rp23xx-riscv/Kconfig:854) is defined with a prompt outside the choice
warning: the choice symbol RP23XX_CLK_GPOUT1_SRC_REF (defined at arch/arm/src/rp23xx/Kconfig:891, arch/risc-v/src/rp23xx-riscv/Kconfig:882) is defined with a prompt outside the choice
warning: the choice symbol RP23XX_CLK_GPOUT1_SRC_SYS (defined at arch/arm/src/rp23xx/Kconfig:898, arch/risc-v/src/rp23xx-riscv/Kconfig:889) is defined with a prompt outside the choice
warning: the choice symbol RP23XX_CLK_GPOUT1_SRC_USB (defined at arch/arm/src/rp23xx/Kconfig:904, arch/risc-v/src/rp23xx-riscv/Kconfig:895) is defined with a prompt outside the choice
warning: the choice symbol RP23XX_CLK_GPOUT1_SRC_ADC (defined at arch/arm/src/rp23xx/Kconfig:909, arch/risc-v/src/rp23xx-riscv/Kconfig:900) is defined with a prompt outside the choice
warning: the choice symbol RP23XX_CLK_GPOUT1_SRC_PERI (defined at arch/arm/src/rp23xx/Kconfig:914, arch/risc-v/src/rp23xx-riscv/Kconfig:905) is defined with a prompt outside the choice
warning: the choice symbol RP23XX_CLK_GPOUT1_SRC_HSTX (defined at arch/arm/src/rp23xx/Kconfig:919, arch/risc-v/src/rp23xx-riscv/Kconfig:910) is defined with a prompt outside the choice
warning: the choice symbol RP23XX_CLK_GPOUT2_SRC_REF (defined at arch/arm/src/rp23xx/Kconfig:947, arch/risc-v/src/rp23xx-riscv/Kconfig:938) is defined with a prompt outside the choice
warning: the choice symbol RP23XX_CLK_GPOUT2_SRC_SYS (defined at arch/arm/src/rp23xx/Kconfig:954, arch/risc-v/src/rp23xx-riscv/Kconfig:945) is defined with a prompt outside the choice
warning: the choice symbol RP23XX_CLK_GPOUT2_SRC_USB (defined at arch/arm/src/rp23xx/Kconfig:960, arch/risc-v/src/rp23xx-riscv/Kconfig:951) is defined with a prompt outside the choice
warning: the choice symbol RP23XX_CLK_GPOUT2_SRC_ADC (defined at arch/arm/src/rp23xx/Kconfig:965, arch/risc-v/src/rp23xx-riscv/Kconfig:956) is defined with a prompt outside the choice
warning: the choice symbol RP23XX_CLK_GPOUT2_SRC_PERI (defined at arch/arm/src/rp23xx/Kconfig:970, arch/risc-v/src/rp23xx-riscv/Kconfig:961) is defined with a prompt outside the choice
warning: the choice symbol RP23XX_CLK_GPOUT2_SRC_HSTX (defined at arch/arm/src/rp23xx/Kconfig:975, arch/risc-v/src/rp23xx-riscv/Kconfig:966) is defined with a prompt outside the choice
warning: the choice symbol RP23XX_CLK_GPOUT3_SRC_REF (defined at arch/arm/src/rp23xx/Kconfig:1003, arch/risc-v/src/rp23xx-riscv/Kconfig:994) is defined with a prompt outside the choice
warning: the choice symbol RP23XX_CLK_GPOUT3_SRC_SYS (defined at arch/arm/src/rp23xx/Kconfig:1010, arch/risc-v/src/rp23xx-riscv/Kconfig:1001) is defined with a prompt outside the choice
warning: the choice symbol RP23XX_CLK_GPOUT3_SRC_USB (defined at arch/arm/src/rp23xx/Kconfig:1016, arch/risc-v/src/rp23xx-riscv/Kconfig:1007) is defined with a prompt outside the choice
warning: the choice symbol RP23XX_CLK_GPOUT3_SRC_ADC (defined at arch/arm/src/rp23xx/Kconfig:1021, arch/risc-v/src/rp23xx-riscv/Kconfig:1012) is defined with a prompt outside the choice
warning: the choice symbol RP23XX_CLK_GPOUT3_SRC_PERI (defined at arch/arm/src/rp23xx/Kconfig:1026, arch/risc-v/src/rp23xx-riscv/Kconfig:1017) is defined with a prompt outside the choice
warning: the choice symbol RP23XX_CLK_GPOUT3_SRC_HSTX (defined at arch/arm/src/rp23xx/Kconfig:1031, arch/risc-v/src/rp23xx-riscv/Kconfig:1022) is defined with a prompt outside the choice
warning: the choice symbol RP23XX_CLK_GPOUT0_SRC_REF (defined at arch/arm/src/rp23xx/Kconfig:835, arch/risc-v/src/rp23xx-riscv/Kconfig:826) is defined with a prompt outside the choice
warning: the choice symbol RP23XX_CLK_GPOUT0_SRC_SYS (defined at arch/arm/src/rp23xx/Kconfig:842, arch/risc-v/src/rp23xx-riscv/Kconfig:833) is defined with a prompt outside the choice
warning: the choice symbol RP23XX_CLK_GPOUT0_SRC_USB (defined at arch/arm/src/rp23xx/Kconfig:848, arch/risc-v/src/rp23xx-riscv/Kconfig:839) is defined with a prompt outside the choice
warning: the choice symbol RP23XX_CLK_GPOUT0_SRC_ADC (defined at arch/arm/src/rp23xx/Kconfig:853, arch/risc-v/src/rp23xx-riscv/Kconfig:844) is defined with a prompt outside the choice
warning: the choice symbol RP23XX_CLK_GPOUT0_SRC_PERI (defined at arch/arm/src/rp23xx/Kconfig:858, arch/risc-v/src/rp23xx-riscv/Kconfig:849) is defined with a prompt outside the choice
warning: the choice symbol RP23XX_CLK_GPOUT0_SRC_HSTX (defined at arch/arm/src/rp23xx/Kconfig:863, arch/risc-v/src/rp23xx-riscv/Kconfig:854) is defined with a prompt outside the choice
warning: the choice symbol RP23XX_CLK_GPOUT1_SRC_REF (defined at arch/arm/src/rp23xx/Kconfig:891, arch/risc-v/src/rp23xx-riscv/Kconfig:882) is defined with a prompt outside the choice
warning: the choice symbol RP23XX_CLK_GPOUT1_SRC_SYS (defined at arch/arm/src/rp23xx/Kconfig:898, arch/risc-v/src/rp23xx-riscv/Kconfig:889) is defined with a prompt outside the choice
warning: the choice symbol RP23XX_CLK_GPOUT1_SRC_USB (defined at arch/arm/src/rp23xx/Kconfig:904, arch/risc-v/src/rp23xx-riscv/Kconfig:895) is defined with a prompt outside the choice
warning: the choice symbol RP23XX_CLK_GPOUT1_SRC_ADC (defined at arch/arm/src/rp23xx/Kconfig:909, arch/risc-v/src/rp23xx-riscv/Kconfig:900) is defined with a prompt outside the choice
warning: the choice symbol RP23XX_CLK_GPOUT1_SRC_PERI (defined at arch/arm/src/rp23xx/Kconfig:914, arch/risc-v/src/rp23xx-riscv/Kconfig:905) is defined with a prompt outside the choice
warning: the choice symbol RP23XX_CLK_GPOUT1_SRC_HSTX (defined at arch/arm/src/rp23xx/Kconfig:919, arch/risc-v/src/rp23xx-riscv/Kconfig:910) is defined with a prompt outside the choice
warning: the choice symbol RP23XX_CLK_GPOUT2_SRC_REF (defined at arch/arm/src/rp23xx/Kconfig:947, arch/risc-v/src/rp23xx-riscv/Kconfig:938) is defined with a prompt outside the choice
warning: the choice symbol RP23XX_CLK_GPOUT2_SRC_SYS (defined at arch/arm/src/rp23xx/Kconfig:954, arch/risc-v/src/rp23xx-riscv/Kconfig:945) is defined with a prompt outside the choice
warning: the choice symbol RP23XX_CLK_GPOUT2_SRC_USB (defined at arch/arm/src/rp23xx/Kconfig:960, arch/risc-v/src/rp23xx-riscv/Kconfig:951) is defined with a prompt outside the choice
warning: the choice symbol RP23XX_CLK_GPOUT2_SRC_ADC (defined at arch/arm/src/rp23xx/Kconfig:965, arch/risc-v/src/rp23xx-riscv/Kconfig:956) is defined with a prompt outside the choice
warning: the choice symbol RP23XX_CLK_GPOUT2_SRC_PERI (defined at arch/arm/src/rp23xx/Kconfig:970, arch/risc-v/src/rp23xx-riscv/Kconfig:961) is defined with a prompt outside the choice
warning: the choice symbol RP23XX_CLK_GPOUT2_SRC_HSTX (defined at arch/arm/src/rp23xx/Kconfig:975, arch/risc-v/src/rp23xx-riscv/Kconfig:966) is defined with a prompt outside the choice
warning: the choice symbol RP23XX_CLK_GPOUT3_SRC_REF (defined at arch/arm/src/rp23xx/Kconfig:1003, arch/risc-v/src/rp23xx-riscv/Kconfig:994) is defined with a prompt outside the choice
warning: the choice symbol RP23XX_CLK_GPOUT3_SRC_SYS (defined at arch/arm/src/rp23xx/Kconfig:1010, arch/risc-v/src/rp23xx-riscv/Kconfig:1001) is defined with a prompt outside the choice
warning: the choice symbol RP23XX_CLK_GPOUT3_SRC_USB (defined at arcLoaded configuration '.config'
Configuration saved to '.config'
h/arm/src/rp23xx/Kconfig:1016, arch/risc-v/src/rp23xx-riscv/Kconfig:1007) is defined with a prompt outside the choice
warning: the choice symbol RP23XX_CLK_GPOUT3_SRC_ADC (defined at arch/arm/src/rp23xx/Kconfig:1021, arch/risc-v/src/rp23xx-riscv/Kconfig:1012) is defined with a prompt outside the choice
warning: the choice symbol RP23XX_CLK_GPOUT3_SRC_PERI (defined at arch/arm/src/rp23xx/Kconfig:1026, arch/risc-v/src/rp23xx-riscv/Kconfig:1017) is defined with a prompt outside the choice
warning: the choice symbol RP23XX_CLK_GPOUT3_SRC_HSTX (defined at arch/arm/src/rp23xx/Kconfig:1031, arch/risc-v/src/rp23xx-riscv/Kconfig:1022) is defined with a prompt outside the choice
make: *** [tools/Unix.mk:726: olddefconfig] Error 1
ERROR: failed to refresh

Possibly something to do with the RISCV tool chain I have to install and configure?
I did install it into my system using 'yay' from 'AUR'.

Any idea?

@keever50
Copy link
Contributor

Okay manually compiled the toolchain with the correct configuration, but as probably expected, this did not make the nuttx configuration work 🤔

@shtirlic
Copy link
Contributor Author

Okay manually compiled the toolchain with the correct configuration, but as probably expected, this did not make the nuttx configuration work 🤔

It's just a warning(not sorted out yet) did you try to make it? Yeah toolchain from aur built with double float, that's why we have to build with soft ABI for Arch.

@shtirlic
Copy link
Contributor Author

@keever50 I updated the branch, check pls

@keever50
Copy link
Contributor

@shtirlic Nice, the warnings are gone!

How do i make this using the custom built toolchain?
It's targeting the wrong one.

riscv32-unknown-elf-ld: /opt/riscv32-gnu-toolchain-elf-bin/bin/../lib/gcc/riscv32-unknown-elf/14.2.0/libgcc.a(_udivdi3.o): can't link double-float modules with soft-float modules
riscv32-unknown-elf-ld: failed to merge target specific data of file /opt/riscv32-gnu-toolchain-elf-bin/bin/../lib/gcc/riscv32-unknown-elf/14.2.0/libgcc.a(_udivdi3.o)

Not entirely sure how it's finding the toolchain, but i might have to change something to make it find the correct (custom) one.

@shtirlic
Copy link
Contributor Author

shtirlic commented May 22, 2025

@shtirlic Nice, the warnings are gone!

How do i make this using the custom built toolchain? It's targeting the wrong one.

riscv32-unknown-elf-ld: /opt/riscv32-gnu-toolchain-elf-bin/bin/../lib/gcc/riscv32-unknown-elf/14.2.0/libgcc.a(_udivdi3.o): can't link double-float modules with soft-float modules
riscv32-unknown-elf-ld: failed to merge target specific data of file /opt/riscv32-gnu-toolchain-elf-bin/bin/../lib/gcc/riscv32-unknown-elf/14.2.0/libgcc.a(_udivdi3.o)

Not entirely sure how it's finding the toolchain, but i might have to change something to make it find the correct (custom) one.

You should add it to the PATH env something like this

export PATH=/opt/riscv/bin:$PATH

@keever50
Copy link
Contributor

@shtirlic
Nice! I confirmed this works perfectly fine with ostest. The serial output also looks consistent.

The problem I had was quite simple. Doing make distclean after changing toolchain path fixed the problem.

@keever50
Copy link
Contributor

@shtirlic
I have a suggestion. This could save some big headaches for developers in the future using this config.
I suggest increasing the stacksize of nsh_main by changing the default task stacksize.
See kconfig below

config INIT_STACKSIZE
int "Main thread stack size"
default DEFAULT_TASK_STACKSIZE(=2048)
help
The size of the stack to allocate for the user initialization thread
that is started as soon as the OS completes its initialization.

As you can see, default is 2k, which is exceeded after enabling some basic debugging or applications in kconfig. Causing crashes without notice.
See image below for stack usage:

image

This chip has plenty of memory and I consider that few kB of extra memory usage to prevent headaches worth it.
4k should be more than enough.

@shtirlic
Copy link
Contributor Author

shtirlic commented May 23, 2025

Update:
changed the chip name to rp23xx-rv and board name to raspberrypi-pico-2-rv to me more consistent
@keever50

29 .. CONFIG_IDLETHREAD_STACKSIZE=2048
30 29 CONFIG_INIT_ENTRYPOINT="nsh_main"
31 .. CONFIG_INIT_STACKSIZE=4096
32 .. CONFIG_IRQ_WORK_STACKSIZE=4096

Remember always do: make distclean before updating the branch

@keever50
Copy link
Contributor

Update:
changed the chip name to rp23xx-rv and board name to raspberrypi-pico-2-rv to me more consistent
@keever50

29 .. CONFIG_IDLETHREAD_STACKSIZE=2048
30 29 CONFIG_INIT_ENTRYPOINT="nsh_main"
31 .. CONFIG_INIT_STACKSIZE=4096
32 .. CONFIG_IRQ_WORK_STACKSIZE=4096

Remember always do: make distclean before updating the branch

That's perfect thank you!

@shtirlic shtirlic changed the title arch/risc-v/rp23xx-riscv: Initial rp23xx RISC-V support arch/risc-v/rp23xx-riscv: Initial rp23xx(rp2350) (Pico 2) RISC-V support May 23, 2025
@shtirlic shtirlic force-pushed the riscvrp23xx branch 4 times, most recently from bee91f0 to 9d164e5 Compare May 24, 2025 18:21
@shtirlic
Copy link
Contributor Author

shtirlic commented Aug 4, 2025

Updated to recent fixes from arm arch

@xiaoxiang781216
Copy link
Contributor

is this huge patch ready for merging? @shtirlic

@shtirlic
Copy link
Contributor Author

shtirlic commented Aug 4, 2025

@xiaoxiang781216 I am planning to do some testing, docs and will make it ready for review this week.

jerpelea
jerpelea previously approved these changes Aug 5, 2025
@github-actions github-actions bot added the Area: Documentation Improvements or additions to documentation label Aug 6, 2025
@shtirlic shtirlic changed the title arch/risc-v/rp23xx-riscv: Initial rp23xx(rp2350) (Pico 2) RISC-V support arch/risc-v/rp23xx-riscv: Add rp23xx(rp2350) (Pico 2 board) RISC-V support Aug 6, 2025
@shtirlic
Copy link
Contributor Author

shtirlic commented Aug 6, 2025

Update: Added docs, some fixes

@shtirlic shtirlic marked this pull request as ready for review August 7, 2025 03:25
@shtirlic
Copy link
Contributor Author

shtirlic commented Aug 7, 2025

Updated docs, made available for review

Chip name   : rp23xx-rv
Board name  : raspberrypi-pico-2-rv
Arch        : risc-v

Changes from ARM rp23xx impl

- Linker script update
- ASM head start
- Update chip start
- New Hazard3 registers
- Remove rp23xx chip hw spinlocks/testset
- New irq handling (external IRQ interrupt Hazard3)
- New timerisr based on RISC-V std MTIME and alarm arch
- No SMP yet
- Tickless option
- Double size for idle, irq and main stacks
- Board reset via watchdog trigger

Signed-off-by: Serg Podtynnyi <serg@podtynnyi.com>
@shtirlic
Copy link
Contributor Author

@acassis @jerpelea please have a look.

Copy link
Contributor

@cederom cederom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Big Thank You @shtirlic AMAZING WORK!! =)

Build works flawlessly but I had problems running after flashing. Does the board need additional setup to run generated nuttx.uf2 or this is my local setup problem? I am using picotool 2.2.0 for flashing and this is great fresh tool that was missing not that long ago :-)

% uname -a
FreeBSD hexagon 14.2-RELEASE-p1 FreeBSD 14.2-RELEASE-p1 GENERIC amd64

% git branch
(HEAD detached at shtirlic/riscvrp23xx)


% ./tools/configure.sh -B raspberrypi-pico-2-rv:usbnsh
  Copy files
  Select CONFIG_HOST_BSD=y
  Refreshing...
(..)
#
# configuration written to .config
#


% /usr/bin/time -h gmake -j24
Create version.h
LN: platform/board to /XXX/nuttx-apps.git/platform/dummy
Register: hello
Register: nsh
Register: sh
Register: getprime
Register: dd
Register: ostest
CPP:  /XXX/nuttx.git/boards/risc-v/rp23xx-rv/raspberrypi-pico-2-rv/scripts/memmap_default.ld-> XXX
LD: nuttx
riscv32-unknown-elf-ld: warning: /XXX/nuttx.git/nuttx has a LOAD segment with RWX permissions
Memory region         Used Size  Region Size  %age Used
           FLASH:      168992 B         4 MB      4.03%
             RAM:       14916 B       512 KB      2.85%
       SCRATCH_X:           0 B         4 KB      0.00%
       SCRATCH_Y:           0 B         4 KB      0.00%
Generating: nuttx.uf2
Done.
        6,68s real              34,00s user             14,97s sys

% picotool version
picotool v2.2.0 (FreeBSD, Clang-18.1.6, Release)

% picotool load nuttx.uf2
Family ID 'rp2350-riscv' can be downloaded in absolute space:
  00000000->02000000
Loading into Flash:   [==============================]  100%

% picotool reboot
The device was rebooted into application mode.

After flashing I get no /dev/cuaUn that should show up. Tried on rPI Pico2 and Pico2W the result is the same. I played with picotool erase etc, also tried to copy nuttx.uf2 to /dev/da0s1.

After some trial and error I made board to show up as:

Aug 10 19:55:46 hexagon kernel: ugen1.12: <NuttX CDC/ACM Serial> at usbus1
Aug 10 19:55:46 hexagon kernel: umodem0 on uhub10
Aug 10 19:55:46 hexagon kernel: umodem0: <NuttX CDC/ACM Serial, class 2/0, rev 2.00/1.01, addr 22> on usbus1
Aug 10 19:55:46 hexagon kernel: umodem0: data interface 1, has CM over data, has break

Then I had only echo on the console.. after some time NuttX prompt showed up.

Not sure if this is indented behavior or my local setup problem, but for sure this is a good starting point for updates :-)

@shtirlic
Copy link
Contributor Author

@cederom thanks, my bet is that your pico was in arm mode and uf2/picotool not switched the pico board to risc-v cores. I researched the initial boot format that should be in the final firmware file and made it according to the spec, maybe there are some more markers that should force the pico into risc-v mode. Try picotool info on the uf2 file, is it correct?

@cederom
Copy link
Contributor

cederom commented Aug 10, 2025

Thanks @shtirlic yup it looks I need to switch to RISC-V as default somehow :-)

% picotool info -a
Program Information
 target chip:            RP2350
 image type:             RISC-V

Fixed Pin Information
 none

Build Information
 none

Metadata Block 1
 address:                0x10000000
 next block address:     0x10000000
 block type:             image def
 target chip:            RP2350
 image type:             RISC-V
 entry point:            EP 0x10000020, SP 0x00000000

Metadata Block 2
 address:                0x10000000
 next block address:     0x10000000
 block type:             image def
 target chip:            RP2350
 image type:             RISC-V
 entry point:            EP 0x10000020, SP 0x00000000

Device Information
 type:                   RP2350
 revision:               A2
 package:                QFN60
 chipid:                 0x996c542f7e443d4b
 flash devinfo:          0x0c00
 current cpu:            ARM
 available cpus:         ARM, RISC-V
 default cpu:            ARM
 secure boot:            0
 debug enable:           1
 secure debug enable:    1
 boot_random:            26366d21:6cea5311:a63e5037:e0b6d52e
 boot type:              bootsel
 last booted partition:  none
 diagnostic source:      slot 0
 last boot diagnostics:  0x00000000
 reboot param 0:         0x00000000
 reboot param 1:         0x00000000
 rom gitrev:             0x312e22fa
 flash size:             4096K

% picotool partition info
there is no partition table
un-partitioned_space : S(rw) NSBOOT(rw) NS(rw), uf2 { 'absolute', 'rp2350-arm-s', 'rp2350-riscv', 'data' }

The image seems to be correctly created for RV:

% picotool info -a nuttx.uf2
File nuttx.uf2 family ID 'rp2350-riscv':

Program Information
 target chip:         RP2350
 image type:          RISC-V

Fixed Pin Information
 none

Build Information
 none

Metadata Block 1
 address:             0x10000000
 next block address:  0x10000000
 block type:          image def
 target chip:         RP2350
 image type:          RISC-V
 entry point:         EP 0x10000020, SP 0x00000000

Metadata Block 2
 address:             0x10000000
 next block address:  0x10000000
 block type:          image def
 target chip:         RP2350
 image type:          RISC-V
 entry point:         EP 0x10000020, SP 0x00000000

Loader recognises it as RV:

% picotool load nuttx.uf2
Family ID 'rp2350-riscv' can be downloaded in absolute space:
  00000000->02000000
Loading into Flash:   [==============================]  100%

% picotool info -a
Program Information
 target chip:            RP2350
 image type:             RISC-V

Fixed Pin Information
 none

Build Information
 none

Metadata Block 1
 address:                0x10000000
 next block address:     0x10000000
 block type:             image def
 target chip:            RP2350
 image type:             RISC-V
 entry point:            EP 0x10000020, SP 0x00000000

Metadata Block 2
 address:                0x10000000
 next block address:     0x10000000
 block type:             image def
 target chip:            RP2350
 image type:             RISC-V
 entry point:            EP 0x10000020, SP 0x00000000

Device Information
 type:                   RP2350
 revision:               A2
 package:                QFN60
 chipid:                 0x0463264565439716
 flash devinfo:          0x0c00
 current cpu:            ARM
 available cpus:         ARM, RISC-V
 default cpu:            ARM
 secure boot:            0
 debug enable:           1
 secure debug enable:    1
 boot_random:            284fb521:297f0d2d:0df8f529:18799e1a
 boot type:              bootsel
 last booted partition:  none
 diagnostic source:      slot 0
 last boot diagnostics:  0x00000000
 reboot param 0:         0x00000000
 reboot param 1:         0x00000000
 rom gitrev:             0x312e22fa
 flash size:             4096K

hexagon% picotool reboot

It now worked for some reason :-)

Aug 10 21:24:59 hexagon kernel: ugen1.12: <NuttX CDC/ACM Serial> at usbus1
Aug 10 21:24:59 hexagon kernel: umodem0 on uhub10
Aug 10 21:24:59 hexagon kernel: umodem0: <NuttX CDC/ACM Serial, class 2/0, rev 2.00/1.01, addr 45> on usbus1
Aug 10 21:24:59 hexagon kernel: umodem0: data interface 1, has CM over data, has break

And the NuttX shell is here after some time:

Welcome to minicom 2.10

OPTIONS: I18n
Compiled on Apr 25 2025, 21:24:42.
Port /dev/cuaU0, 21:24:59 [U]

Press CTRL-A Z for help on special keys


eloo



NuttShell (NSH) NuttX-10.4.0
nsh> uname -a
NuttX 10.4.0 35fdf7e495 Aug 10 2025 21:23:16 risc-v raspberrypi-pico-2-rv
nsh> help
help usage:<cmd>]

         cp          exit        ls          rm          uname
    [           cmp         expr        mkdir       rmdir       umount
    ?           dirname     false       mkrd        set         unset
    alias       date        fdinfo      mount       sleep       uptime
    unalias     df          free        mv          source      usleep
    basename    dmesg       help        pidof       test        watch
    break       echo        hexdump     printf      time        xd
    cat         env         kill        ps          true        wait
    cd          exec        pkill       pwd         truncate

Builtin Apps:
    dd          getprime    hello       nsh         ostest      sh
nsh> getprime
Set thread priority to 10
Set thread policy to SCHED_RR
Start thread #0
thread #0 started, looking for primes < 10000, doing 10 run(s)
thread #0 finished, found 1230 primes, last one was 9973
Done
getprime took 4274 msec

Then I disconnect, reconnect, and there is no NuttX :-( Maybe a bug in picotool / pico-sdk (using latest release tag 2.2.0 from git clone)?

Tested on Pico W and 2W:

  • picotool load nuttx.uf2; picotool reboot -> that gives NuttX CDC ACM over USB.
  • Disconnect, reconnect and there is no USB NuttX.
  • After reconnect ARM core seems to be selected as default.
  • Maybe some additional bits / steps needs to be perfomed to set RV core as default?
  • Can anyone observe this behavior too?

@cederom
Copy link
Contributor

cederom commented Aug 10, 2025

This picotool is great, I have asked questions on their project Issues, maybe finally automated testing will be possible without manual interaction to flash / reboot :-)

@xiaoxiang781216 xiaoxiang781216 merged commit 2e7f75f into apache:master Aug 11, 2025
18 checks passed
@shtirlic
Copy link
Contributor Author

shtirlic commented Aug 11, 2025

@cederom there are some pages in rp2350 datasheet 5.1.20. Automatic Architecture Switching and 3.9. Arm/RISC-V Architecture Switching and for my board as I remember I set the ARCHSEL OTP register with optiion 4.

1. If CRIT0_ARM_DISABLE is set, only RISC-V is allowed.
2. Else if CRIT0_RISCV_DISABLE is set, only Arm is allowed.
3. Else if CRIT1_SECURE_BOOT_ENABLE is set, only Arm is allowed.
4. Else if CRIT1_BOOT_ARCH is set, both architectures are permitted, and the default is RISC-V.
5. If none of the above flags are set, both architectures are permitted, and the default is Arm.
No CRIT1 flags are set by default, so on devices where both architectures are available, the default is Arm. To change the
default architecture to RISC-V, set the CRIT1_BOOT_ARCH flag to 1.

my OTP looks like this, see the BOOT_ARCH bit set to 1

luksdev> picotool otp get OTP_DATA_CRIT1
ROW 0x0040: OTP_DATA_CRIT1
        "Page 1 critical boot flags (RBIT-8)"

    VALUE 0x000008

    field GLITCH_DETECTOR_SENS (bits 5-6) = 0
        "Increase the sensitivity of the glitch detectors from their default."
    field GLITCH_DETECTOR_ENABLE (bit 4) = 0
        "Arm the glitch detectors to reset the system if an abnormal clock/power event is observed."
    field BOOT_ARCH (bit 3) = 1
        "Set the default boot architecture, 0=ARM 1=RISC-V. Ignored if ARM_DISABLE, RISCV_DISABLE or SECURE_BOOT_ENABLE is set."
    field DEBUG_DISABLE (bit 2) = 0
        "Disable all debug access"
    field SECURE_DEBUG_DISABLE (bit 1) = 0
        "Disable Secure debug access"
    field SECURE_BOOT_ENABLE (bit 0) = 0
        "Enable boot signature enforcement, and permanently disable the RISC-V cores."

and picotool info -a

Device Information
 type:                   RP2350
 revision:               A2
 package:                QFN60
 chipid:                 0x87485d01e86f300a
 flash devinfo:          0x0c00
 current cpu:            RISC-V
 available cpus:         ARM, RISC-V
 default cpu:            RISC-V
 secure boot:            0
 debug enable:           1
 secure debug enable:    1
 boot_random:            c403df64:02852428:7ac04dce:1d37e89f
 boot type:              bootsel
 last booted partition:  none
 diagnostic source:      slot 0
 last boot diagnostics:  0x00000000
 reboot param 0:         0x00000000
 reboot param 1:         0x00000000
 rom gitrev:             0x312e22fa
 flash size:             4096K

@shtirlic
Copy link
Contributor Author

This picotool is great, I have asked questions on their project Issues, maybe finally automated testing will be possible without manual interaction to flash / reboot :-)

I also found that there is option for picotool reboot like picotool reboot -c riscv to reboot in risc-v mode

@cederom
Copy link
Contributor

cederom commented Aug 11, 2025

  1. OTP is nice, but its one-time-programable, so we should be careful to write over there as the changes are irreversible :-P
  2. yes reboot works for me, the problem after power cycle is still ARM is selected as default.

Maybe picotool thread will help us somehow :-) Sorry I am not really familiar with picos just bought 4 of them for testing (Pico, PicoW, Pico2, Pico2W). Other people who start with Pico will probably have the same issues as me :-P

@cederom
Copy link
Contributor

cederom commented Aug 20, 2025

Sorry for the delay @shtirlic I am kinda overloaded.. I have moment to take a look again.
This picotool reboot -c riscv with raspberrypi-pico-2-rv:usbnsh does not reboot into application :-(

Would it be possible to create a dedicated configuration like led-blinker so I can see with bare eyes if the application works? Maybe this is the usbnsh problem on my machine does not reiterating USB device?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Arch: risc-v Issues related to the RISC-V (32-bit or 64-bit) architecture Area: Documentation Improvements or additions to documentation Board: risc-v Size: XL The size of the change in this PR is very large. Consider breaking down the PR into smaller pieces.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants