发帖
2 0 0

【BW20-12F开发板评测】6、Zephyr初步

sujingliang
论坛元老

27

主题

17

回帖

8485

积分

论坛元老

积分
8485
BW系列 44 2 昨天 15:20
[i=s] 本帖最后由 sujingliang 于 2025-11-27 15:22 编辑 [/i]

Zephyr是一个小型、可扩展的实时操作系统(RTOS),专为资源受限的嵌入式设备设计。它由 Linux 基金会托管,是一个开源项目。

开发板已经部分支持Zephyr SDK。

文档参考:https://aiot.realmcu.com/cn/latest/rst_zephyr/index.html

一、Zephyr SDK安装

Realtek Ameba-IoT 系列产品的 Zephyr SDK 采用多仓库管理方式,主清单文件仓库托管于 GitHub:https://github.com/Ameba-AIoT/nuwa

1、安装 west 工具

pip3 install --user -U west

2、下载 Ameba NUWA Project SDK

官网给的命令是:

west init -m git@github.com:Ameba-AIoT/nuwa.git

但是运行时报错了:

截图_20251127141017.png

所以只能:

git clone https://github.com/Ameba-AIoT/nuwa.git

得到west.yml
然后修改west.yml内容:

截图_20251127141456.png
原来url-base是git@github.com:Ameba-AIoT/nuwa.git

$ west init -l nuwa

nuwa为west.yml所在目录

$ west update
$ ln -sf tools/meta_tools/nuwa.py nuwa.py
$ ./nuwa.py setup

最后得到:

截图_deepin-terminal_20251127142356.png

二、SDK使用

仍然需要使用venv环境,可以借用之前freeRTOS的环境:

source ameba.sh

1、编译

编译helloworld:

./nuwa.py build -a zephyr/samples/hello_world -d rtl872xda_evb

编译blinky

./nuwa.py build -a zephyr/samples/basic/blinky -d rtl872xda_evb

直接编译blinky会保错,因为没有配置DTS

修改/home/sujingliang/mcu/Ameba-rtos/nuwa/zephyr/boards/realtek/rtl872xda_evb/rtl872xda_evb.dts内容,加入:
aliases{
led0 = &led_0;
};

gpio-led {
compatible = "gpio-leds";
led_0: led_0 {
gpios = <&gpiob 17 0>;
};
};

再编译

2、下载

从ameba-rtos/amebadplus_gcc_project下拷贝一个flash.py过来,
增加:
IMAGE_DIR= os.path.realpath(os.path.join(PROJECT_ROOT_DIR, "images/"))

修改:
if not images:
cmds.append(f"--image-dir")
cmds.append(IMAGE_DIR)
else:

原来的内容替换为IMAGE_DIR

本质就是修改bin文件的路径
通过命令就可以下载了:./flash.py -p /dev/ttyCH341USB0

3、运行

3.jpg

/*

  • Copyright (c) 2016 Intel Corporation
  • SPDX-License-Identifier: Apache-2.0
    */

#include <stdio.h>
#include <zephyr/kernel.h>
#include <zephyr/drivers/gpio.h>

/* 1000 msec = 1 sec */
#define SLEEP_TIME_MS 1000

/* The devicetree node identifier for the "led0" alias. /
#define LED0_NODE DT_ALIAS(led0)
/

  • A build error on this line means your board is unsupported.
  • See the sample documentation for information on how to fix this.
    */
    static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED0_NODE, gpios);

int main(void)
{
int ret;
bool led_state = true;

if (!gpio_is_ready_dt(&led)) {
	return 0;
}

ret = gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE);
if (ret < 0) {
	return 0;
}

while (1) {
	ret = gpio_pin_toggle_dt(&led);
	if (ret < 0) {
		return 0;
	}

	led_state = !led_state;
	printf("LED state: %s\n", led_state ? "ON" : "OFF");
	k_msleep(SLEEP_TIME_MS);
}
return 0;

}

──── 0人觉得很赞 ────

使用道具 举报

赞个👍
5 小时前
哇,感谢分享!
您需要登录后才可以回帖 立即登录
高级模式
返回
统计信息
  • 会员数: 30203 个
  • 话题数: 44408 篇