上手第一步就是点灯
由于 SiRider S1 的特殊性,其中有一个 Cortex-R52 核心,对应的也有 gpio、spi、uart 等基础外设
刚好 radxa 又将其中的 2 个 gpio 给引出来了
基于此我们可以使用这个 Cortex-R52 核心来操作 gpio 点灯
背景
基于官方资料,我们可以清楚的知道以下对应关系
Cortex-R52 GPIO | siengine SE1000 | SiRider S1 pin40 |
---|---|---|
gpio5 | gpio136 | GPIO3_C0 |
gpio6 | gpio137 | GPIO2_B4 |
因此我们只需要在 Cortex-R52 上操作 gpio5 和 gpio6 即可
实践
官方 SIENGINE SDK 中提供了源码,对应的 Cortex-R52 源码位于 src/safetyisland
中
其中 src/safetyisland/src/application/main/main.c
为其主函数,粗略扫读一遍大概就能够知道其基本逻辑:
int main( void )
{
/* Mpu init */
Mpu_Init(&mpu_cfg);
Mpu_Enable(TRUE);
enable_dcache();
enable_icache();
InitSystimeTime();
/*gic init*/
gicInitialization();
/*init console uart*/
PeriUart_Init(UART_SEL, 115200);
/* Log to memory init & level support */
vlog_init();
/* Enable peri1 wdt0 interrupt for SoC boot failure. */
Peri1_Wdt0_Irq_Init();
/* After peri1 wdt0 interrupt init done to set ap boot flag */
ap_boot_flag_set();
log_info("Version:%s", VERSION_STRING);
log_info("Build:%s,%s", __DATE__, __TIME__);
log_info("Boot time: %0.6fs", GetBootupTime());
/* Boot Ready set boot_ready = 1 */
m4_boot_flag_set();
cp_boot_flag_set();
/* safe gpio init after post diagnostic complete */
Syscsr_IO_Init(&Syscsr_IoCfg[0]);
/*irq init*/
Irq_Init(&Irq_Cfg[0]);
/* UART demonstration */
Uart_Init(&Uart_Cfg[0]);
/* timer init */
Timer_Init(&Timer_Cfg[0]);
/* ipc init */
Ipc_Init(&Ipc_Cfg[0]);
/* Display a welcome message via uart */
log_info("Welcome to FreeRTOS's world!");
Application_Init();
/* Start the created tasks running. */
vTaskStartScheduler();
/* Should not reach here as the scheduler is already started. */
for( ; ; )
{
}
return 0;
}
- 初始化 mpu、dcache、icache、中断、时钟、串口、日志等基本外设
- 应用初始化
- 启动 rtos 调度
因此我们只需要在 Application_Init
中实现一个 led 的 app 即可
最终的改动如下:
diff --git a/src/application/main/examples/gpio/gpio_demo.c b/src/application/main/examples/gpio/gpio_demo.c
index d409b27..082e45f 100644
--- a/src/application/main/examples/gpio/gpio_demo.c
+++ b/src/application/main/examples/gpio/gpio_demo.c
@@ -37,6 +37,36 @@ void Gpio_Demo(void)
Gpio_WritePin(GPIO_PIN2, PIN_LEVEL_LOW);
}
+#include "FreeRTOS.h"
+#include "task.h"
+
+static TaskHandle_t vLedDemoTaskHandle;
+
+static void led_task(void *pvParameters)
+{
+ while(1) {
+ mdelay(1000);
+ log_info("Gpio_Pin5 is high.");
+ Gpio_WritePin(GPIO_PIN5, PIN_LEVEL_HIGH);
+ mdelay(1000);
+ log_info("Gpio_Pin5 is low.");
+ Gpio_WritePin(GPIO_PIN5, PIN_LEVEL_LOW);
+ }
+}
+
+int Led_Demo(void)
+{
+ int ret = 0;
+ /* create rpmsg demo task */
+ xTaskCreate(led_task, "led-demo", 512, NULL, \
+ tskIDLE_PRIORITY + 1, &vLedDemoTaskHandle);
+ return ret;
+}
+
+
/****************************************************************************************************
* @brief Soc and mcu gpio interconnection demo
* @note Saf_gpio_4 is output, saf_gpio_3 is input.
diff --git a/src/application/main/examples/gpio/gpio_demo.h b/src/application/main/examples/gpio/gpio_demo.h
index 4367621..0f8ac99 100644
--- a/src/application/main/examples/gpio/gpio_demo.h
+++ b/src/application/main/examples/gpio/gpio_demo.h
@@ -16,6 +16,7 @@
* @note You need to connect pin0(CPU board J16.1) and pin1(CPU board J16.3) on EVB board.
****************************************************************************************************/
void Gpio_Demo(void);
+void Led_Demo(void);
/****************************************************************************************************
* @brief Soc and mcu gpio interconnection demo
diff --git a/src/application/main/main.c b/src/application/main/main.c
index 9e6fa01..5ccea9a 100644
--- a/src/application/main/main.c
+++ b/src/application/main/main.c
@@ -54,6 +54,7 @@
#include "wdt.h"
#include "max967xx.h"
#include "rpmsg_demo/rpmsg_demo.h"
+#include "gpio/gpio_demo.h"
void Application_Init(void)
{
@@ -68,6 +69,8 @@ void Application_Init(void)
Max967xx_Init(2);
/* rpmsg usage demo */
rpmsg_demo();
+
+ Led_Demo();
}
/*-----------------------------------------------------------*/
运行
之后编译烧录即可
# 调用脚本编译
sebuilder firmware r52
# 没问题后将板子进入烧录模式直接烧录
./tools/siengine_downloader/siengine_downloadtool_linux/burn.sh r52
之后将 led 接入到 pin40 接口对应的 io 上(对应 v1.2 原理图 pdf 中 GPIO3_C0
标号的 io 上),然后重启开机
串口连接上 /dev/ttyUSB1 即可看到相关的输出:
[ 0.000189][ RP] INFO main.c : 97: Version:SE-SDK1.8-g30a2571
[ 0.006977][ RP] INFO main.c : 98: Build:Nov 24 2024,23:55:06
[ 0.013890][ RP] INFO main.c : 99: Boot time: 0.166481s
[ 0.020281][ RP] INFO main.c : 115: Welcome to FreeRTOS's world!
[ 0.027376][ RP] INFO rpmsg_io.c : 282: rpmsg_io_device init ok
[ 0.034039][ RP] INFO rpmsg_io.c : 205: rpmsg sync send task is running
[ 0.041339][ RP] INFO rpmsg_io.c : 317: This is task RpmsgRecv 33.
[ 0.048250][ RP] INFO max967xx.c : 696: Max967xx_Task is running.
[ 0.055163][ RP] INFO max967xx.c : 698: panel_name = 2
[ 0.060990][ RP] INFO rpmsg_demo.c : 38: rpmsg_demo task start
[ 0.067458][ RP] INFO console.c : 146: FreeRTOS command server is running.
[ 0.184093][ RP] INFO rpmsg_io.c : 71: get sync 5 !!!!!!!!!!
[ 0.234111][ RP] INFO rpmsg_io.c : 71: get sync 4 !!!!!!!!!!
[ 1.075121][ RP] INFO gpio_demo.c : 49: Gpio_Pin5 is high.
[ 2.081209][ RP] INFO gpio_demo.c : 52: Gpio_Pin5 is low.
[ 3.087218][ RP] INFO gpio_demo.c : 49: Gpio_Pin5 is high.
[ 4.093310][ RP] INFO gpio_demo.c : 52: Gpio_Pin5 is low.
[ 4.535519][ RP] INFO rpmsg_io.c : 71: get sync 0 !!!!!!!!!!
[ 4.541869][ RP] INFO rpmsg_io.c : 71: get sync 1 !!!!!!!!!!
[ 5.099309][ RP] INFO gpio_demo.c : 49: Gpio_Pin5 is high.
[ 6.105397][ RP] INFO gpio_demo.c : 52: Gpio_Pin5 is low.
[ 7.111403][ RP] INFO gpio_demo.c : 49: Gpio_Pin5 is high.
[ 8.117489][ RP] INFO gpio_demo.c : 52: Gpio_Pin5 is low.
[ 9.123487][ RP] INFO gpio_demo.c : 49: Gpio_Pin5 is high.
[ 10.129579][ RP] INFO gpio_demo.c : 52: Gpio_Pin5 is low.
[ 11.135581][ RP] INFO gpio_demo.c : 49: Gpio_Pin5 is high.
[ 12.141669][ RP] INFO gpio_demo.c : 52: Gpio_Pin5 is low.
[ 13.147676][ RP] INFO gpio_demo.c : 49: Gpio_Pin5 is high.
[ 14.153762][ RP] INFO gpio_demo.c : 52: Gpio_Pin5 is low.
[ 15.159762][ RP] INFO gpio_demo.c : 49: Gpio_Pin5 is high.
[ 16.165855][ RP] INFO gpio_demo.c : 52: Gpio_Pin5 is low.
[ 17.171856][ RP] INFO gpio_demo.c : 49: Gpio_Pin5 is high.
[ 18.177944][ RP] INFO gpio_demo.c : 52: Gpio_Pin5 is low.
[ 19.183950][ RP] INFO gpio_demo.c : 49: Gpio_Pin5 is high.
[ 20.190037][ RP] INFO gpio_demo.c : 52: Gpio_Pin5 is low.
[ 21.196035][ RP] INFO gpio_demo.c : 49: Gpio_Pin5 is high.
...