目标平台:FPB RA6E2开发板
Zephyr 版本:v4.3.99 (main 分支)
【工程创建】
1、创建一个文件夹,命令为ra6e2_led。
2、在该文夹内加入src文件夹,文件夹下创建main.c
3、文件夹内添加CMakeLists.txt与prj.conf
添加好后结构如下:
├── CMakeLists.txt ├── README.rst ├── prj.conf └── src └── main.c 1 directory, 4 files
4、查看Zephyr 是否已支持RA6E2:
lugl@lugl:~/zephyrproject/app/ra6e2_hello$ west boards | grep -i ra6e2 fpb_ra6e2 ek_ra6e2
从结果看支持fpb_ra6e2,咱们就可以愉快的开始zephyr之旅了。
5、编写prj.conf
CONFIG_GPIO=y
6、编写CMakeLists.txt
cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(RA6E2_LED)
target_sources(app PRIVATE src/main.c)7、编写应用代码(main.c)
/*
* Copyright (c) 2012-2014 Wind River Systems, Inc.
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <stdio.h>
#include <zephyr/kernel.h>
#include <zephyr/device.h>
#include <zephyr/drivers/gpio.h>
#define LED0_NODE DT_ALIAS(led0)
#if DT_NODE_HAS_STATUS(LED0_NODE, okay)
static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED0_NODE, gpios);
#else
#error "led0 alias not defined in devicetree"
#endif
void main(void)
{
int ret;
/* 检查设备是否就绪 */
if (!device_is_ready(led.port))
{
printf("Error: LED GPIO device not ready\n");
return;
}
/* 配置引脚为输出 */
ret = gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE);
if (ret < 0)
{
printf("Error: Failed to configure LED pin\n");
return;
}
printf("RA6E2 LED Blink Start!\n");
while (1)
{
/* Toggle LED */
gpio_pin_toggle_dt(&led);
k_msleep(500); // 500ms 间隔
}
}7、构建
west build -b fpb_ra6e2 [145/145] Linking C executable zephyr/zephyr.elf Memory region Used Size Region Size %age Used FLASH: 22488 B 256 KB 8.58% RAM: 4832 B 40 KB 11.80% OFS_OFS0_MEMORY: 4 B 4 B 100.00% OFS_OSIS_MEMORY: 16 B 16 B 100.00% OFS_OFS1_SEC_MEMORY: 4 B 4 B 100.00% OFS_BPS_SEC_MEMORY: 4 B 4 B 100.00% OFS_PBPS_SEC_MEMORY: 4 B 4 B 100.00% IDT_LIST: 0 GB 32 KB 0.00% Generating files from /home/lugl/zephyrproject/app/ra6e2_led/build/zephyr/zephyr.elf for board: fpb_ra6e2
8、烧录
开发板上板载了Jlink-ob因此可以方便的使用jlink来下载。
lugl@lugl:~/zephyrproject/app/ra6e2_hello$ west flash --runner jlink -- west flash: rebuilding ninja: no work to do. -- west flash: using runner jlink -- runners.jlink: reset after flashing requested -- runners.jlink: JLink version: 8.76 -- runners.jlink: Flashing file: /home/lugl/zephyrproject/app/ra6e2_led/build/zephyr/zephyr.hex
【验证】
打开串口终端就可以看到输出如下:

【总结】
zephyr生态完美支持RA6E2,可以轻松的上手RA6E2。
优点,不需要下载复杂的fsp,不用安装IDE等等
【附件】
我要赚赏金
