[update] 添加 RA 系列 BSP 开发教程: (#5598)

- 添加 RA 系列 BSP 开发教程
  - 添加 ra6m4-iot PPP 上网
  - 整理 驱动文件
This commit is contained in:
Sherman
2022-03-11 09:17:46 +08:00
committed by GitHub
parent 5b17eeeb9b
commit 7c53d46ba7
353 changed files with 5727 additions and 5495 deletions
+22
View File
@@ -0,0 +1,22 @@
# RA BSP 说明
RA 系列 BSP 目前支持情况如下表所示:
| **BSP 文件夹名称** | **开发板名称** |
|:------------------------- |:-------------------------- |
| **RA6 系列** | |
| [ra6m4-cpk](ra6m4-cpk) | Renesas 官方 CPK-RA6M4 开发板 |
| [ra6m4-iot](ra6m4-iot) | Renesas 官方 IOT-RA6M4 开发板 |
可以通过阅读相应 BSP 下的 README 来快速上手,如果想要使用 BSP 更多功能可参考 docs 文件夹下提供的说明文档,如下表所示:
| **BSP 使用教程** | **简介** |
|:-------------------- |:------------------------------------------------- |
| [外设驱动使用教程](docs/RA系列BSP外设驱动使用教程.md) | 讲解 BSP 上更多外设驱动的使用方法 |
| [外设驱动介绍与应用](docs/RA系列驱动介绍.md) | 讲解 RA 系列 BSP 驱动的支持情况,以及如何利用驱动框架开发应用程序 |
| [使用 FSP 配置外设驱动](docs/RA系列使用FSP配置外设驱动.md) | 介绍如何使用 FSP 工具添加和配置外设 |
| **BSP 制作与提交** | **简介** |
| [BSP 制作教程](docs/RA系列BSP制作教程.md) | 讲解 RA 系列 BSP 的制作方法,以及在制作 BSP 和提交 BSP 时应当遵守的规范 |
| [外设驱动添加指南](docs/RA系列外设驱动添加指南.md) | 讲解 BSP 添加更多设备驱动的方法 |
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,93 @@
# RA系列BSP外设驱动使用教程
## 1. 简介
本文档是为需要在 RT-Thread 操作系统上使用更多开发板资源的开发者准备的。通过使用 ENV 工具对 BSP 进行配置,可以开启更多板载资源,实现更多高级功能。
主要包括以下内容:
1. 如何使用开发板上更多的板载资源
2. 如何使用更多的片上资源
3. 如何添加更多片上资源选项
## 2. 前提要求
- 学会如何使用 ENV 工具,参考:[RT-Thread env 工具用户手册](https://www.rt-thread.org/document/site/programming-manual/env/env/)
- 熟悉 [FSP](https://www2.renesas.cn/jp/zh/software-tool/flexible-software-package-fsp) 配置工具的使用
## 3. 如何使用更多的外设资源
开发板上一般有很多外设资源,如 SPI、SDIO、ADC 等,但是 BSP 工程默认没有开启这些外设驱动。RT-Thread 提供了 ENV 工具来开启或关闭 BSP 的外设驱动。本文以 RA6M4-CPK 开发板上开启 SPI 驱动为例,一步步地展示如何使用 ENV 工具对 BSP 进行配置。
### 3.1 打开配置工具
在 BSP 目录下打开 menuconfig 配置界面。
![image-20220218162910778](figures/menuconfig_ra6m4cpk.png)
打开的配置工具界面如下所示:
![config1](figures/config1.png)
通过键盘上的上下键移动光标,选中 `Hardware Drivers Config`然后按回车键进入硬件驱动配置菜单。
### 3.2 进入硬件驱动配置菜单
在硬件配置菜单里有三个选项,分别是 **板载外设配置菜单**、**片上外设配置菜单**和**扩展模块配置菜单**,使用下键切换到片上外设,按回车键进入配置菜单。
![硬件驱动配置菜单](figures/config2.png)
### 3.3 在板载外设配置菜单里开启 SPI Flash 选项
![image-20220218163357420](figures/menuconfig_spi.png)
![image-20220218163714429](figures/menuconfig_spi1.png)
### 3.4 保存退出
然后右移光标选中 Save 按回车键保存,然后按 Esc 键退出配置工具。
![保存退出](figures/save.png)
### 3.5 生成 MDK5 工程
输入命令 `scons --target=mdk5` 重新生成 MDK5 的工程。
![image-20220218164532436](figures/scons_mdk5.png)
### 3.6 FSP 添加 SPI 外设
![image-20220218171841353](figures/fsp_spi.png)
![image-20220218172446068](figures/fsp_spi1.png)
在 Pins 中配置 SPI1 端口引脚。**注意: SSLx 片选引脚设为 None,片选引脚的控制在驱动程序中由软件控制。**
配置完成,保存退出 FSP。
![image-20220218174145848](figures/fsp_spi2.png)
### 3.7 测试验证
回到生成的 MDK5 工程并编译。使用 FSP 配置完成后如果有新的文件添加进工程中,不会马上添加进去。需要先编译一次,如果弹出如下提醒,选择 “是” 然后再次编译即可。
![image-20220218174811328](figures/mdk_build.png)
编译成功后,点击 debug 按钮下载并进入调试页面。
![image-20220218175442360](figures/mdk_build1.png)
### 3.8 查看运行结果
程序运行后,输入命令 `list_device` 可以看到名为 spi1 的总线设备,此时 SPI1 总线已经可以使用了。
![image-20220218175926965](figures/run_spi1.png)
## 4. 总结
本文以 SPI 为例介绍了外设驱动使用的操作流程,其他类型的外设如何使用和配置请查看:[RA系列使用FSP配置外设驱动.md](RA系列使用FSP配置外设驱动.md)
当开发者需要使用未开启的外设时,只要在 ENV 工具中使能相关的外设,然后在 FSP 中添加即可,重新生成的工程中就会添加对应的驱动文件。
@@ -0,0 +1,63 @@
# RA 系列外设驱动添加指南
## 1. 简介
本文档是为需要给现有的 RA 系列 BSP 添加更多外设驱动的开发者准备的。通过阅读本文,开发者可以按照自己的实际情况给现有 BSP 添加自己需要的驱动。
## 2. 前提要求
- 熟练使用 ENV 工具,参考:[RT-Thread env 工具用户手册](https://www.rt-thread.org/document/site/rtthread-development-guide/rtthread-tool-manual/env/env-user-manual/)
- 熟悉 [Kconfig](https://www.rt-thread.org/document/site/#/development-tools/kconfig/kconfig) 语法
- 熟悉 [FSP](https://www2.renesas.cn/jp/zh/software-tool/flexible-software-package-fsp) 工具
- 了解 RT-Thread [设备驱动框架](https://www.rt-thread.org/document/site/#/rt-thread-version/rt-thread-standard/programming-manual/device/device)
## 3. 如何添加更多的外设驱动选项
本章节以添加片上外设驱动为例,讲解如何为 BSP 添加更多可用驱动。如果想使用的片上外设是 `片上外设配置菜单` 里没有的,就需要开发者自己添加了。下面我们将演示如何为 ra6m4-cpk 添加 UART9 端口。
添加 UART 的外设支持需要以下步骤:
### 3.1 修改 Kconfig 文件
打开 BSP 中的 board\kconfig 文件,添加 UART9 配置。
![image-20220221161853343](figures/add_uart.png)
![image-20220221163152761](figures/add_uart1.png)
修改完成后,在 BSP 目录下打开 ENV 工具,命令行输入 `menuconfig` 命令查看 UART9 配置是否已添加。
![image-20220221164229974](figures/add_uart2.png)
### 3.2 修改 uart_config.h 文件
Kconfig 的配置添加完成,还需要在配置文件和驱动文件中添加相应的配置。
打开 `libraries\HAL_Drivers\config\ra6m4\uart_config.h` 文件添加 UART9 配置。
![image-20220221170945734](figures/add_uart3.png)
### 3.3 修改 drv_usart_v2.h 文件
打开 `libraries\HAL_Drivers\drv_usart_v2.c`,添加如下代码:
![image-20220221171806580](figures/add_uart4.png)
![image-20220221172034531](figures/add_uart5.png)
### 3.4 测试验证
1. 在 menuconfig 中打开 UART9 并保存配置,使用 `scons --target=mdk5` 命令重新生成 MDK 工程。
2. 从 project 工程中打开 FSP 配置工具,添加 UART9 端口
![image-20220221180942314](figures/add_uart6.png)
![image-20220221183752087](figures/add_uart8.png)
3. 配置 UART9 对应的 IO 引脚,保存并退出。
![image-20220221183405828](figures/add_uart7.png)
4. 编译、debug 下载,输入 list_device 命令可以看到 uart9 设备已经注册到内核,说明设备添加成功,接下来就可以使用 UART9 端口进行通信了。
![image-20220221185534932](figures/add_uart9.png)
+62
View File
@@ -0,0 +1,62 @@
# RA系列驱动介绍
在 RT-Thread 实时操作系统中,各种各样的设备驱动是通过一套 I/O 设备管理框架来管理的。设备管理框架给上层应用提供了一套标准的设备操作 API,开发者通过调用这些标准设备操作 API,可以高效地完成和底层硬件外设的交互。设备管理框架的结构如下图所示:
![image-20220308143402996](figures/rtdevice.png)
使用 I/O 设备管理框架开发应用程序,有如下优点:
- 使用同一套标准的 API 开发应用程序,使应用程序具有更好的移植性
- 底层驱动的升级和修改不会影响到上层代码
- 驱动和应用程序相互独立,方便多个开发者协同开发
## 1. 驱动分类介绍
本小节介绍 BSP 提供的不同类别驱动的概念,对一个 BSP 而言,有如下三类驱动:
- **板载外设驱动**(Onboard Peripheral Drivers):指 MCU 之外,开发板上外设,例如 TF 卡、以太网等
- **片上外设驱动**(On-chip Peripheral Drivers):指 MCU 芯片上的外设,例如硬件定时器、ADC 和看门狗等
- **扩展模块驱动**(Board extended module Drivers):指可以通过扩展接口或者杜邦线连接的开发板的模块,例如 RW007 模块
这三种外设的示意图如下所示:
![Peripheral](figures/Peripheral.png)
## 2. 外设驱动的使用方法
当前 RT-Thread 提供的驱动库已经支持 RA 多个系列的 BSP。点击下表中的驱动名称,即可跳转到对应驱动框架的介绍文档。开发者可以通过阅读相关资料,了解如何在应用开发中通过设备驱动框架来使用这些外设驱动。
### 2.1 片上外设
| 驱动 | 简介 |
| ------------------------------------------------------------ | ------------------------------------------------ |
| [GPIO](https://www.rt-thread.org/document/site/programming-manual/device/pin/pin/) | 操作 GPIO 管脚 |
| [UART](https://www.rt-thread.org/document/site/programming-manual/device/uart/uart/) | 通过串口收发数据 |
| [I2C](https://www.rt-thread.org/document/site/programming-manual/device/i2c/i2c/) | 通过软件 I2C 收发数据 |
| [SPI](https://www.rt-thread.org/document/site/programming-manual/device/spi/spi/) | 通过 SPI 收发数据 |
| [ADC](https://www.rt-thread.org/document/site/programming-manual/device/adc/adc/) | 测量管脚上的模拟量 |
| SDIO | 通过 SDIO 读写数据 |
| [TIMER](https://www.rt-thread.org/document/site/programming-manual/device/hwtimer/hwtimer/) | 使用硬件定时器实现测量时间和定时执行回调函数功能 |
| [PWM](https://www.rt-thread.org/document/site/programming-manual/device/pwm/pwm/) | 在特定的管脚输出 PWM 波形 |
| [RTC](https://www.rt-thread.org/document/site/programming-manual/device/rtc/rtc/) | 设置和读取时间 |
| [WDT](https://www.rt-thread.org/document/site/programming-manual/device/watchdog/watchdog/) | 看门狗驱动 |
| [QSPI](https://www.rt-thread.org/document/site/programming-manual/device/spi/spi/#qspi_1) | 通过 SPI(1、2、4线) 收发数据 |
### 2.2 板载外设
| 驱动 | 简介 |
| ------- | --------------------------------------- |
| I2C | 板载 I2C 传感器 |
| SDIO | 适用于 SPI 接口或 SDIO 接口的 SD(TF) 卡 |
### 2.3 扩展模块
| 驱动 | 简介 |
| -------- | ---------------------- |
| [RW007](https://github.com/RT-Thread-packages/rw007) | SPI 接口 WIFI 模块 |
| [HS300x](https://github.com/Guozhanxin/hs300x) | I2C 接口的温湿度传感器 |
| [ZMOD4410](https://github.com/ShermanShao/zmod4410) | I2C 接口的室内空气质量传感器 |
### 2.4 驱动示例代码
在 RT-Thread 的 `examples\test` 目录下,有 RT-Thread 提供的基于不同外设驱动的示例代码。在 env 工具中开启 BSP 中要测试的驱动,并将 `examples\test` 中对应的驱动框架测试文件加入工程,即可快速测试 BSP 中提供的驱动。

Before

Width:  |  Height:  |  Size: 33 KiB

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 99 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 23 KiB

Before

Width:  |  Height:  |  Size: 36 KiB

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Before

Width:  |  Height:  |  Size: 79 KiB

After

Width:  |  Height:  |  Size: 79 KiB

Before

Width:  |  Height:  |  Size: 36 KiB

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 73 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 21 KiB

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 911 KiB

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 24 KiB

Before

Width:  |  Height:  |  Size: 31 KiB

After

Width:  |  Height:  |  Size: 31 KiB

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 17 KiB

Before

Width:  |  Height:  |  Size: 31 KiB

After

Width:  |  Height:  |  Size: 31 KiB

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

Before

Width:  |  Height:  |  Size: 5.8 KiB

After

Width:  |  Height:  |  Size: 5.8 KiB

Before

Width:  |  Height:  |  Size: 34 KiB

After

Width:  |  Height:  |  Size: 34 KiB

Before

Width:  |  Height:  |  Size: 42 KiB

After

Width:  |  Height:  |  Size: 42 KiB

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 25 KiB

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

Before

Width:  |  Height:  |  Size: 36 KiB

After

Width:  |  Height:  |  Size: 36 KiB

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 87 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 25 KiB

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 25 KiB

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

Some files were not shown because too many files have changed in this diff Show More