一、平台简介

Rockchip RK3506(典型型号 RK3506J/B)采用 AMP 异构多核架构

  • 3× ARM Cortex-A7(最高 1.5GHz)——可运行 RT-Thread SMP 或 Linux

  • 1× ARM Cortex-M0(最高 200MHz)——适合高实时性裸机/RTOS 控制

  • 支持共享内存 + Mailbox(RPMsg)做核间通信

本文以 Cortex-A7 核运行 RT-Thread Standard(SMP 模式)​ 为例说明移植要点

U-Boot 2017.09-g0d357ad-250310-dirty #huiwei (May 28 2026 - 11:06:38 +0800)

Model: HW3506-CORE
MPIDR: 0xf00
PreSerial: 0, raw, 0xff0a0000
DRAM:  128 MiB
Sysmem: init
Relocation Offset: 06bee000
Relocation fdt: 05bfa6b0 - 05bfede8
CR: M/C/I
Using default environment

DM: v2
SPI Nand ID cd 72 72
Bootdev(atags): mtd 1
PartType: EFI
No misc partition
boot mode: normal
FIT: No boot partition
Failed to load DTB, ret=-19
No valid DTB, ret=-22
Failed to get kernel dtb, ret=-22
Model: HW3506-CORE
rockchip_set_ethaddr: vendor_storage_write failed -5
rockchip_set_serialno: could not find efuse/otp device
CLK: (arm clk use pvtpll, rate = 1200M)
  gpll 1500000 KHz
  v0pll 1179648 KHz
  v1pll 903168 KHz
  clk_gpll_div 187500 KHz
  clk_gpll_div_100m 93750 KHz
  clk_v0pll_div 147456 KHz
  clk_v1pll_div 129024 KHz
  aclk_bus_root 187500 KHz
  hclk_bus_root 147456 KHz
  pclk_bus_root 93750 KHz
  aclk_hsperi_root 147456 KHz
  hclk_ksperi_root 93750 KHz
## Loading loadables from FIT Image at 05dfa080 ...
   Trying 'amp0' loadables subimage
     Description:  rtos-smp
     Type:         Firmware
     Compression:  uncompressed
     Data Start:   0x05dfae80
     Data Size:    572336 Bytes = 558.9 KiB
     Architecture: ARM
     Load Address: 0x00100000
     Hash algo:    sha256
     Hash value:   9870067495b178be20760b5aae7076bc571d27e84063d43a991eedb4e75b4ece
   Verifying Hash Integrity ... sha256+ OK
   Loading loadables from 0x05dfae80 to 0x00100000
AMP: Brought up primary cpu[f00, self] with state 0x10, entry 0x00100000 ...OK
base_mem: BASE = 0x00100000, SIZE = 0x07700000
uncached_heap: BASE = 0x07800000, SIZE = 0x00800000

 \ | /
- RT -     Thread Operating System
 / | \     4.1.1 build May 28 2026 11:06:55
 2006 - 2022 Copyright by RT-Thread team
[I/I2C] I2C bus [i2c0] registered
[I/I2C] I2C bus [i2c2] registered
lwIP-2.1.2 initialized!
Scan block in the tail, blk[2043]=0
  log2_page_size: 11
  log2_ppb: 6
  num_blocks: 1387
  sector_size: 2048
  page_per_block: 64
  capacity(sec): 65008
  capacity(MB): 126
  start_blocks: 656
  num_blocks: 1387
  use count: 139
[HAL INFO] PHY found ID: 0x4f51e928
[HAL INFO] GMAC: enable RX store and forward mode
[HAL INFO] GMAC: enable TX store and forward mode
eth_device_init success
RGA2_core0 probe successfully, irq = 93, hw_version:03.a.07135
rga_multicore module initialized. v1.3.5_for_RT-Thread
[I/sal.skt] Socket Abstraction Layer initialize success.
[E/DFS] mount fs[elm] on /data failed.

Hi, this is RT-Thread!!
msh />I/TC: Secondare0: 100M
e0: full dumplex
e0: flow control off
e0: link up.

msh />

二、准备开发环境

1. 获取 RT-Thread 源码

git clone https://github.com/RT-Thread/rt-thread.git
cd rt-thread
git checkout master   # 或 v5.x LTS

2. 交叉编译工具链(ARM Cortex-A7)

推荐使用 ARM GNU Toolchain:

# 示例:解压到 /opt
tar -xf gcc-arm-10.3-2021.07-x86_64-arm-none-eabi.tar.xz -C /opt/

# 配置环境变量
export RTT_CC=gcc
export RTT_EXEC_PATH=/opt/gcc-arm-10.3-2021.07-x86_64-arm-none-eabi/bin
export RTT_CC_PREFIX=arm-none-eabi-
export PATH=$RTT_EXEC_PATH:$PATH

帮你整理好了可以直接发到 CSDN 的 RK3506 运行 RT-Thread(RTOS) 技术文档,内容涵盖芯片简介、环境搭建、BSP 目录结构、启动流程、关键移植点、编译烧录及验证,你可以按需微调标题和配图再发布。


Rockchip RK3506 移植运行 RT-Thread RTOS 实战指南

一、平台简介

Rockchip RK3506(典型型号 RK3506J/B)采用 AMP 异构多核架构

  • 3× ARM Cortex-A7(最高 1.5GHz)——可运行 RT-Thread SMP 或 Linux

  • 1× ARM Cortex-M0(最高 200MHz)——适合高实时性裸机/RTOS 控制

  • 支持共享内存 + Mailbox(RPMsg)做核间通信

本文以 Cortex-A7 核运行 RT-Thread Standard(SMP 模式)​ 为例说明移植要点,适用睿擎派(RuiChing)、Firefly ROC-RK3506 等开发板。


二、准备开发环境

1. 获取 RT-Thread 源码

git clone https://github.com/RT-Thread/rt-thread.git
cd rt-thread
git checkout master   # 或 v5.x LTS

2. 交叉编译工具链(ARM Cortex-A7)

推荐使用 ARM GNU Toolchain:

# 示例:解压到 /opt
tar -xf gcc-arm-10.3-2021.07-x86_64-arm-none-eabi.tar.xz -C /opt/

# 配置环境变量
export RTT_CC=gcc
export RTT_EXEC_PATH=/opt/gcc-arm-10.3-2021.07-x86_64-arm-none-eabi/bin
export RTT_CC_PREFIX=arm-none-eabi-
export PATH=$RTT_EXEC_PATH:$PATH

✅ RT-Thread 官方 MPU BSP(如 rk3568/rk3500 参考)也使用类似 aarch32/arm-none-eabi 工具链。

3. 开发工具

  • RT-Thread Studio 

  • 或命令行 scons编译

  • 串口调试工具(波特率通常 1500000)


三、BSP 目录结构与创建

参照 rt-thread/bsp/rockchip/下已有 BSP,新建 bsp/rockchip/rk3506/

bsp/rockchip/rk3506/
├── applications/      # 用户应用(main线程)
├── board/
│   ├── board.c        # rt_hw_board_init()
│   ├── board.h
│   ├── rk3506_crg.c   # 时钟配置(CRU)
│   ├── rk3506_uart.c  # 调试串口驱动(UART0/2)
│   └── rk3506_gic.c   # GIC中断控制器初始化
├── drivers/           # Rockchip HAL + RT-Thread驱动适配
├── linker_scripts/
│   └── link.lds       # 链接脚本(TEXT/DATA/BSS/堆)
├── rtconfig.h         # RT-Thread内核配置
├── Kconfig
├── SConscript
├── SConstruct
└── README.md

四、关键移植要点(Cortex-A7 + GIC)

1. 启动汇编(start.S / reset_handler)

RK3506 上电由 BootROM → SPL/UBoot 引导 RT-Thread bin,也可由 U-Boot booti加载。BSP 需提供 A7 异常向量表与模式切换:

_start:
    ldr sp, =__stack_top      @ 设置 SVC 模式栈
    bl  disable_mmu_icache
    bl  cpu_mode_init         @ 切到 SVC, 关 IRQ/FIQ
    bl  rt_hw_board_init
    bl  rtthread_startup      @ 不返回

2. rt_hw_board_init()(board.c)

void rt_hw_board_init(void)
{
    /* 1. 关闭全局中断 */
    rt_hw_interrupt_disable();

    /* 2. 芯片级初始化 —— CRU时钟、PMU */
    HAL_CRU_Init();
    
    /* 3. GIC 中断控制器初始化(Cortex-A7 GICv2) */
    rt_hw_gic_init();          // 设置 GICD/GICC base addr

    /* 4. 调试串口(固定 UART2@115200 或按 DTS) */
    rt_hw_uart_init();
    rt_console_set_device("uart2");

    /* 5. 系统节拍 —— Generic Timer / 私有 Timer */
    rt_hw_timer_init();

    /* 6. 堆内存初始化 */
    rt_system_heap_init(RT_HEAP_BEGIN, RT_HEAP_END);
}

3. GIC 中断适配(libcpu/arm/cortex-a/gic.c)

RT-Thread 已内置 libcpu/arm/cortex-a/的 GIC 支持,需确认:

  • GICD_BASEGICC_BASE匹配 RK3506 TRM(通常 GICD=0xFF810000, GICC=0xFF820000,以手册为准)

  • rt_hw_trap_irq()统一处理 EOI,不要在 ISR 内手动调 HAL_GIC_EndOfInterrupt(),避免嵌套计数异常

4. OS Tick(定时器)

Cortex-A7 Private Timer(每核)或 Generic Timer 均可:

void rt_hw_timer_init(void)
{
    arm_private_timer_init(RT_TICK_PER_SECOND);
    rt_hw_interrupt_install(IRQ_ID_PTIMER, timer_isr, RT_NULL, "tick");
    arm_private_timer_enable();
}

5. 链接脚本(link.lds 节选)

MEMORY { RAM : ORIGIN = 0x60000000, LENGTH = 64M }
SECTIONS {
    .text : { *(.vectors) *(.text*) *(.rodata*) } > RAM
    .data : { *(.data*) } > RAM
    .bss  : { *(.bss*) *(COMMON) } > RAM
    _end = .;
}

五、RT-Thread SMP 配置(多 A7 核)

若使用 SMP 模式(2~3 个 A7 运行 RT-Thread),需在 rtconfig.h开启:

#define RT_USING_SMP
#define RT_CPUS_NR         3      /* RK3506 最多3个A7 */
#define RT_USING_GIC
#define RT_USING_HW_CPU_TIMER

并在 secondary core 启动代码中调用 rt_hw_secondary_cpu_up(cpu_id)进行 IPI 唤醒。


六、编译与烧录

编译

cd bsp/rockchip/rk3506
scons
# 生成 rtthread.bin / rtthread.elf

通过 U-Boot 运行(SD/TFTP 示例)

fatload mmc 1:1 0x60000000 rtthread.bin
go 0x60000000
# 或 booti 0x60000000 - 0x8300000 (如有 DTB)

官方推荐 RKDevTool / 睿擎下载工具烧写 APP.img(含 APP.dtb + rtthread.bin)。


七、验证与 FinSH Shell

系统正常启动后,串口应看到:

\ | /
- RT -     Thread Operating System
 / | \     5.x.x build May 28 2026
 2006 - 2026 Copyright by RealThread
msh />

测试:

msh /> list_thread
msh /> list_device
msh /> ps
Logo

AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。

更多推荐