Skip to content

RK3506 CPU2 is compatible with nuttx#19478

Open
Otpvondoiats wants to merge 4 commits into
apache:masterfrom
Otpvondoiats:lk-3506
Open

RK3506 CPU2 is compatible with nuttx#19478
Otpvondoiats wants to merge 4 commits into
apache:masterfrom
Otpvondoiats:lk-3506

Conversation

@Otpvondoiats

Copy link
Copy Markdown
Contributor

Summary

This is a patch for the AMP architecture. RK3506 CPU 0 and 1 run Linux, while CPU 2 runs Nuttx.

Impact

  1. The ARM A7 chip is based on the QEMU bundle.
  2. Add an accessor function to drivers/serial/uart_16550.c in the 16550 serial port driver to expose the internal console device object pointer.
  • Because the shared GIC caused the core to not receive UART interrupts, the board switched to polling to receive characters. Polling requires calling the upper-level uart_recvchars(), which necessitates accessing the driver's internal console uart_dev_t. Therefore, this commit specifically added an accessor to expose it. TX and the per-core private PPI timer are unaffected; only the shared SPI RX has this issue.
  1. The NuttX client cannot access the flash memory; the control terminal is on the Linux side.
  2. Download:
  • https://github.com/Otpvondoiats/lockfox-lyra Download this repository(https://wiki.luckfox.com/zh/Luckfox-Lyra-Zero-W)
  • git clone && cd lockfox-lyra
  • git submodule update --init nuttxos/nuttx nuttxos/nuttx-apps
  • ( cd nuttxos/nuttx && git am ../patches/*.patch ) # Manually apply NuttX patches
  • ./tools/restore-dl-splits.sh # Restore the split DL (SHA256 checksum)
  • ./build.sh rk3506b_buildroot_spinand_amp_nuttx_defconfig
  • ./build.sh # Build big and small cores and image together

Testing

nsh>
nsh>
nsh>
nsh> ps
TID PID PPID PRI POLICY TYPE NPX STATE EVENT SIGMASK STACK COMMAND
0 0 0 0 FIFO Kthread - Ready 0000000000000000 0004072 Idle_Task
1 0 0 224 RR Kthread - Waiting Semaphore 0000000000000000 0004024 hpwork 0x3f00000 0x3f00050
3 0 0 100 RR Kthread - Waiting Signal 0000000000000000 0002008 rxpoll
4 0 0 100 RR Kthread - Waiting Semaphore 0000000000000000 0004032 fakesensor_thread 0x3f0a348
6 6 0 100 RR Task - Running 0000000000000000 0004048 nsh_main
7 0 0 224 RR Kthread - Waiting Semaphore 0000000000000000 0004024 rpmsg-virtio linux 0x3f08698
8 8 6 100 RR Task - Waiting Semaphore 0000000000000000 0004032 sh -c cat
nsh> help
help usage: help [-v] []

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

Builtin Apps:
dd memtester sh uorb_unit_test
fstest nsh uorb_generator
hello ramtest uorb_listener
nsh> free
total used free maxused maxfree nused nfree name
33517568 42448 33475120 42816 33475104 99 2 Umem
nsh> uo
uorb_generator
uorb_listener
uorb_unit_test
nsh> uorb_unit_test
uORB note: try single-topic support
uORB note: PASS single-topic test
uORB note: PASS orb 10-instances
uORB note: try multi-topic support
uORB note: ---------------- LATENCY TEST ------------------
mean: 0 us
std dev: 0 us
min: 0 us
max: 0 us
missed topic updates: 0
uORB note: PASS multi-topic test
uORB note: try multi-topic support subscribing before publishing
uORB note: PASS multi-topic reversed
uORB note: Testing unadvertise
uORB note: Testing multi-topic 2 test (queue simulation)
uORB note: PASS multi-topic 2 test (queue simulation)
uORB note: Testing orb queuing
uORB fail: subscribe failed: 2
FAIL
nsh> uo
uorb_generator
uorb_listener
uorb_unit_test
nsh> uo
uorb_generator
uorb_listener
uorb_unit_test
nsh> uorb_listener -n 5 sensor_accel0

Monitor objects num:1
object_name:sensor_accel, object_instance:0
sensor_accel(now:439274000):0x3f102acB
sensor_accel(now:439375000):0x3f102acB
sensor_accel(now:439476000):0x3f102acB
sensor_accel(now:439577000):0x3f102acB
sensor_accel(now:439678000):0x3f102acB
Object name:sensor_accel0, received:5
Total number of received Message:5/5
nsh>

Expose a pointer to the console uart_dev_t so board logic can drive the
console RX by polling. This is needed on AMP secondary cores where the
UART RX interrupt cannot be delivered reliably through a GIC distributor
that is shared with another OS (e.g. Linux), so the board polls the LSR
and feeds bytes to the upper half via uart_recvchars().

Signed-off-by: likun17 <likun17@xiaomi.com>
Add the RK3506 architecture support for running NuttX as an AMP
secondary subsystem on one Cortex-A7 core (CPU2), brought up by U-Boot
via PSCI alongside Linux on the other cores.

Key points specific to the AMP-shared-GIC environment:

 - up_irqinitialize() only initializes the GIC CPU interface (GICC) and
   disables all SPIs, because the GIC distributor (GICD) is owned by
   Linux. Leftover SPIs targeting CPU2 would otherwise storm the core
   right after up_irq_enable().
 - The generic timer uses the per-CPU PTM path (select ARMV7A_HAVE_PTM),
   since the per-CPU PPI is private and unaffected by Linux reconfiguring
   the shared distributor.
 - Memory map covers DDR (normal) and the 0xff000000 device region; the
   image runs from the AMP-reserved DRAM window.
 - rk3506_boot.c includes a raw UART4 breadcrumb for early bring-up
   debugging, independent of the serial driver.

Signed-off-by: likun17 <likun17@xiaomi.com>
Add the Luckfox Lyra (RK3506) board running NuttX as an AMP subsystem on
Cortex-A7 CPU2. Boot flow: U-Boot psci_cpu_on() jumps to the image in
the AMP-reserved DRAM window, arm_boot() sets up the MMU, and NSH comes
up on UART4 (1.5Mbaud).

The nsh defconfig enables:

 - Console on UART4 (16550, MMIO32, REGINCR=1) with the TX driver and a
   board-side poll thread for RX (the RX interrupt is unreliable on the
   GIC distributor shared with Linux).
 - uORB + sensor framework with a CSV-backed fake accelerometer demo on
   /dev/uorb/sensor_accel0, plus uorb_listener/generator/unit_test.
 - NSH tab-completion and command history.
 - RAM disk tooling (mkrd + FAT + mkfatfs) and the ramtest / memtester /
   fstest utilities.

rk3506_bringup.c writes a small CSV to tmpfs and registers the fake
sensor, and spawns the console RX poll thread.

Signed-off-by: likun17 <likun17@xiaomi.com>
@github-actions github-actions Bot added Area: Build system Arch: arm Issues related to ARM (32-bit) architecture Size: XL The size of the change in this PR is very large. Consider breaking down the PR into smaller pieces. Board: arm labels Jul 19, 2026
@github-actions

github-actions Bot commented Jul 19, 2026

Copy link
Copy Markdown

MemBrowse Memory Report

No memory changes detected for:

CONFIG_RAM_SIZE 0x02000000 (32MB), RAM_START 0x03f00000. Total NuttX
footprint 0x03e00000-0x05f00000 (33MB); the Linux kernel dts amp_reserved
node reserves this whole range (no-map). Hard ceiling is 193MB, bounded by
the 256MB DDR window mapped in the rk3506 MMU setup.

Signed-off-by: likun17 <likun17@xiaomi.com>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Would #18895 help this? Just curious.

Comment on lines +118 to +123
"interval:100\n" /* 10 Hz */
"x,y,z\n"
"0.10,0.00,9.81\n"
"0.20,0.05,9.79\n"
"0.05,-0.05,9.82\n"
"-0.10,0.10,9.80\n";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is unrelated to this PR, but I think you were the author of uorb_generator. Is this CSV format the same format that's expected by uorb_generator -f? Because it seems to also look for a topic in the first line.

struct file f;
int ret;

ret = file_open(&f, path, O_WRONLY | O_CREAT | O_TRUNC, 0644);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I wonder if it would be worthwhile to create a fakesensor interface that allows playback from a string for such a case.

@linguini1 linguini1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Exciting port! Could you:

  • Add both chip and board documentation files in two separate commits with this PR? There is a board template to make that easier if it helps!
  • Include the special build/flash steps in those docs
  • Add a configuration for SMP for users to try? It looks from the code that it's implemented.

Is there any way to use this port without depending on your repository?

*
****************************************************************************/

FAR uart_dev_t *u16550_consoledev(void)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why not disable linux to access it directly?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

let's implement the general rx poll directly

* interrupt-driven RX is unreliable on the AMP-shared GIC).
*/

kthread_create("rxpoll", 100, 2048, rk3506_rxpoll, NULL);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why not use wdog

#ifdef CONFIG_SENSORS_FAKESENSOR
/* Register a demo accelerometer (CSV-backed) on /dev/uorb/sensor_accel0. */

rk3506_fakesensor_setup();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why use fakesensor on the real device

CONFIG_NSH_FILEIOSIZE=512
CONFIG_NSH_READLINE=y
CONFIG_RAM_SIZE=15728640
CONFIG_RAM_SIZE=33554432

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

merge with the previous patch

@@ -0,0 +1,37 @@
# ##############################################################################
# arch/arm/src/qemu/CMakeLists.txt

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

fix the path in all file

@@ -0,0 +1,36 @@
############################################################################
# arch/arm/src/qemu/Make.defs

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ditto

*/

void rk3506_rawuart_puts(const char *s);
void rk3506_dbgmark(const char *tag);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why add the unused symbols

UART4_FCR = 0x07; /* enable+clear FIFOs */
}

void rk3506_rawuart_puts(const char *s)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why not implement up_lowputc and up_lowputs

@acassis acassis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@Otpvondoiats please add Documentation to explain about this port. Since it runs in an specific CPU, please include this information there. Including all the steps to test it.

@Otpvondoiats

Otpvondoiats commented Jul 20, 2026

Copy link
Copy Markdown
Contributor Author

I'll revise everyone's comments first, test it, and then reply to everyone.

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

Labels

Arch: arm Issues related to ARM (32-bit) architecture Area: Build system Board: arm 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.

4 participants