从零开始学习 sg200x 多核开发之小核 FreeRTOS 运行

发布于:2024-12-06 ⋅ 阅读:(118) ⋅ 点赞:(0)

sophpi 小核支持默认运行 FreeRTOS,并且已经启动,小核的运行固件被打包在 fip.bin文件中,由 fsbl 负责加载。

启动后,小核会运行 FreeRTOS,并输出日志到串口。串口日志输出在 UART0 上,波特率 115200,与大核共用同一个 uart,所以在运行中需要特别留意相关日志信息。

1. 启动 FreeRTOS

build/boards/cv181x/sg2002_wevb_riscv64_sd/sg2002_wevb_riscv64_sd_defconfig 中已经配置了启动 FreeRTOS。

CONFIG_ENABLE_FREERTOS=y
CONFIG_ENABLE_RTOS_DUMP_PRINT=y
CONFIG_DUMP_PRINT_SZ_IDX=17

2. 创建任务

freertos/cvitek/task/comm/src/riscv64/comm_main.c 中创建初始 task, 并启动了调度器。

void main_cvirtos(void)
{
	printf("create cvi task\n");

	request_irq(MBOX_INT_C906_2ND, prvQueueISR, 0, "mailbox", (void *)0);

#ifdef FAST_IMAGE_ENABLE
	start_camera(0);
#endif

	main_create_tasks();

	/* Start the tasks and timer running. */
	vTaskStartScheduler();

    /* If all is well, the scheduler will now be running, and the following
    line will never be reached.  If the following line does execute, then
    there was either insufficient FreeRTOS heap memory available for the idle
    and/or timer tasks to be created, or vTaskStartScheduler() was called from
    User mode.  See the memory management section on the FreeRTOS web site for
    more details on the FreeRTOS heap http://www.freertos.org/a00111.html.  The
    mode from which main() is called is set in the C start up code and must be
    a privileged mode (not user mode). */
    for (;;)
        ;
}

我们在 main_create_tasks 之前创建了一个简单的任务 xTaskCreate(app_task, "app_task", 1024, NULL, 1, NULL);,每隔 1s 打印一次日志。

void app_task(void * param)
{
  while(1) {
    printf("Hello RiSC-V!\r\n");
    vTaskDelay(1000);
  }
}

编译后烧录 SD 卡,即可看到启动日志中,FreeRTOS 已经正常启动。

SCS/0/0.WD.URPL.SDI/25000000/6000000.BS/SD.PS.SD/0x0/0x1000/0x1000/0.PE.BS.SD/0x1000/0x8400/0x8400/0.BE.J.
FSBL Jb2829:g4d4fdd79b-dirty:2024-11-30T12:18:01+08:00
st_on_reason=d0000
st_off_reason=0
P2S/0x1000/0xc00a400.
SD/0x9400/0x1000/0x1000/0.P2E.
DPS/0xa400/0x2000.
SD/0xa400/0x2000/0x2000/0.DPE.
cv181x DDR init.
ddr_param[0]=0x78075562.
pkg_type=5
D1_3_2
DDR3-2G-QFN
Data rate=1866.
DDR BIST PASS
PLLS.
PLLE.
C2S/0xc400/0x8fe00000/0x13400.
[2RET:. 0/0x13400/0x13400/0.RSC.
 1MS./4607x917f880]0Pr/e0 xs8y00s0te0m0 0i0n/0ixt 1dco2n0e0.

RT: [1.473814]CVIRTOS Build Date:Nov 30 2024  (Time :21:47:36) 
RT: [1.479389]Post system init done
RT: [1.482475]dump_print_enable & log will not print

看上面最后一句 log 可以发现默认情况下关闭了小核的打印,需要通过大核通过核间通信打开打印功能。
我们可以手工开启一下测试,在 freertos/cvitek/task/comm/src/riscv64/comm_main.cdump_uart_init() 函数中将 dump_print_enable(); 修改为 dump_uart_disable(),重新编译后烧录 SD 卡,启动后可以看到小核的日志输出。

并在 Linux 启动后也会间隔 5s 打印 RT: [1.359588]Hello RiSC-V!

查看 freertos/cvitek/kernel/include/riscv64/FreeRTOSConfig.h 中配置的

#define configTICK_RATE_HZ				( ( TickType_t ) 200 )

所以 FreeRTOS 的 tick 是 5ms。


网站公告

今日签到

点亮在社区的每一天
去签到