Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BSP/RA6M4-CPK] 添加 CAN、RW007 的支持 #5262

Merged
merged 1 commit into from
Dec 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions bsp/ra6m4-cpk/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/RTE
/Listings
/Objects
ra_cfg.txt

22 changes: 18 additions & 4 deletions bsp/ra6m4-cpk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

| **片上外设** | **支持情况** | **备注** |
| :----------------- | :----------------- | :------------- |
| UART | 支持 | UART7 |
| UART | 支持 | UART7 为默认日志输出端口 |
| GPIO | 支持 | |
| IIC | 支持 | 软件 |
| WDT | 支持 | |
Expand All @@ -41,7 +41,12 @@
| SPI | 支持 | |
| FLASH | 支持 | |
| PWM | 支持 | |
| CAN | 支持 | |
| 持续更新中... | | |
| **外接外设** | **支持情况** | **备注** |
| WiFi | 支持 | [RW007 WiFi 网络模块](https://github.com/RT-Thread-packages/rw007) |
| 温湿度传感器 | 支持 | [HS300x 温湿度模块](https://github.com/Guozhanxin/hs300x) |


## 使用说明

Expand Down Expand Up @@ -148,10 +153,10 @@ void hal_entry(void)

需要修改瑞萨的 BSP 外设配置或添加新的外设端口,需要用到瑞萨的 [FSP](https://www2.renesas.cn/jp/zh/software-tool/flexible-software-package-fsp#document) 配置工具。请务必按照如下步骤完成配置。配置中有任何问题可到[RT-Thread 社区论坛](https://club.rt-thread.org/)中提问。

1. [下载灵活配置软件包 (FSP) | Renesas](https://www.renesas.com/cn/zh/software-tool/flexible-software-package-fsp)
1. [下载灵活配置软件包 (FSP) | Renesas](https://www.renesas.com/cn/zh/software-tool/flexible-software-package-fsp),建议使用 FSP 3.1.0
2. 下载安装完成后,需要添加 CPK-RA6M4 开发板的[官方板级支持包](https://www2.renesas.cn/document/sws/1527176?language=zh&r=1527191)
3. 如何将 BSP 配置包添加到 FSP 中,请参考文档[如何导入板级支持包](https://www2.renesas.cn/document/ppt/1527171?language=zh&r=1527191)
4. 请查看文档:[使用瑞萨 FSP 配置工具](./docs/使用瑞萨FSP配置工具.md)。在 MDK 中通过添加自定义命名来打开当前工程的 FSP 配置
4. 请查看文档:[使用瑞萨 FSP 配置工具](./docs/使用瑞萨FSP配置工具.md)。在 MDK 中通过添加自定义命名来打开当前工程的 FSP 配置

**ENV 配置**

Expand All @@ -165,10 +170,19 @@ void hal_entry(void)
3. 输入`pkgs --update`命令更新软件包。
4. 输入`scons --target=mdk5` 命令重新生成工程。


## FAQ

### 使用 MDK 的 DEBUG 时如果遇到提示 “Error: Flash Download failed Cortex-M33” 怎么办?

可按照下图操作,修改 Utilities 中的选项:

![image-20211214102231248](docs/picture/readme_faq1.png)

## 联系人信息

在使用过程中若您有任何的想法和建议,建议您通过以下方式来联系到我们 [RT-Thread 社区论坛](https://club.rt-thread.org/)

## 贡献代码

如果您对 CPK-RA6M4 感兴趣,并且有一些好玩的项目愿意与大家分享的话欢迎给我们贡献代码,您可以参考 [ RT-Thread 代码贡献](https://www.rt-thread.org/document/site/#/rt-thread-version/rt-thread-standard/development-guide/github/github)
如果您对 CPK-RA6M4 感兴趣,并且有一些好玩的项目愿意与大家分享的话欢迎给我们贡献代码,您可以参考 [如何向 RT-Thread 代码贡献](https://www.rt-thread.org/document/site/#/rt-thread-version/rt-thread-standard/development-guide/github/github)。
Binary file added bsp/ra6m4-cpk/docs/picture/can.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bsp/ra6m4-cpk/docs/picture/can_callback.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bsp/ra6m4-cpk/docs/picture/can_menuconfig.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bsp/ra6m4-cpk/docs/picture/dmac_config.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bsp/ra6m4-cpk/docs/picture/dmac_int.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bsp/ra6m4-cpk/docs/picture/drv_rw007.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bsp/ra6m4-cpk/docs/picture/fsp_version.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bsp/ra6m4-cpk/docs/picture/readme_faq1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bsp/ra6m4-cpk/docs/picture/rw007_int.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bsp/ra6m4-cpk/docs/picture/rw007_mdk.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bsp/ra6m4-cpk/docs/picture/rw007_mempool.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bsp/ra6m4-cpk/docs/picture/rw007_netdev.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bsp/ra6m4-cpk/docs/picture/rw007_ping.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bsp/ra6m4-cpk/docs/picture/rw007_pkg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bsp/ra6m4-cpk/docs/picture/rw007_reset.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bsp/ra6m4-cpk/docs/picture/rw007_spi.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bsp/ra6m4-cpk/docs/picture/rw007_spicfg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bsp/ra6m4-cpk/docs/picture/rw007_test.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bsp/ra6m4-cpk/docs/picture/rw007_wifijoin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bsp/ra6m4-cpk/docs/picture/rw007_wlan.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bsp/ra6m4-cpk/docs/picture/sdhi_config.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bsp/ra6m4-cpk/docs/picture/sdhi_config1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bsp/ra6m4-cpk/docs/picture/sdhi_env.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bsp/ra6m4-cpk/docs/picture/spi_pin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
127 changes: 106 additions & 21 deletions bsp/ra6m4-cpk/docs/使用瑞萨FSP配置工具.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## 在 MDK 中使用 FSP

- 添加RA Smart Config
### 添加RA Smart Config

1. 打开 MDK,选择 “Tools -> Customize Tools Menu…”
2. 点击 “new” 图标,添加一条自定义命令: RA Smart Configurator
Expand All @@ -15,27 +15,38 @@

![image.png](picture/openrasc.png)

- 添加 Device Partition Manager,添加步骤同上。
### 添加 Device Partition Manager,添加步骤同上。

1. 输入命令名称: `Device Partition Manager`
2. Command: 在安装路径选中 `rasc.exe`
3. Initial Folder : `$P`
4. Arguments: `-application com.renesas.cdt.ddsc.dpm.ui.dpmapplication configuration.xml "SL%L"`
1. 输入命令名称:`Device Partition Manager`
2. Command: 在安装路径选中`rasc.exe`
3. Initial Folder :`$P`
4. Arguments:`-application com.renesas.cdt.ddsc.dpm.ui.dpmapplication configuration.xml "SL%L"`

> PS:以上相关操作也可以在 FSP 的说明文档中找到。
>
> 文档路径(本地):在 FSP 的安装目录下 .\fsp_documentation\v3.1.0\fsp_user_manual_v3.1.0\index.html
>
> 文档路径(官网):https://www2.renesas.cn/jp/zh/software-tool/flexible-software-package-fsp#document

### FSP 版本选择

此 BSP 使用 **FSP 3.1.0** 版本为基础制作,优先推荐使用 FSP 3.1.0 版本进行配置修改。

**使用 RASC 前请务必检查 FSP version 、Board、Device 配置项是否正确。**

![fsp_version](picture/fsp_version.png)

## 更新工程配置

使用 FSP 配置完成后如果有新的文件添加进工程中,不会马上添加进去。需要先编译一次,如果弹出如下提醒,选择 “是” 然后再次编译即可。

![img](picture/import_changes.png)

## 如何使用 RASC 添加外设

**注意:文档中的外设添加步骤均为单独配置的说明,排版顺序不代表外设添加顺序,如遇到引脚冲突请查阅开发板及芯片手册的相关章节。**

## UART
### UART

如何添加一个 UART 端口外设配置?

Expand All @@ -45,7 +56,7 @@

2. 配置 UART 参数,因为需要适配 RT-Thread 驱动中使用的命名,所以需要修改命名,设置**name** 、**channel** 、**callback** 是一致的标号。![image.png](picture/rascuart1.png)

## GPIO 中断
### GPIO 中断

如何添加一个 IO 中断?

Expand Down Expand Up @@ -91,7 +102,7 @@
MSH_CMD_EXPORT(icu_sample, icu sample);
```

## WDT
### WDT

1. 创建 WDT

Expand All @@ -105,7 +116,7 @@

![image-20211027183406251](picture/wdt_env.png)

## RTC
### RTC

1. 添加 RTC 设备

Expand All @@ -115,11 +126,11 @@

![image-20211019152627412](picture/rtc_config.png)

3. 如何在 ENV 中打开 RTC 以及[ RTC 接口使用说明](https://www.rt-thread.org/document/site/#/rt-thread-version/rt-thread-standard/programming-manual/device/rtc/rtc)
3. 如何在 ENV 中打开 RTC 以及[ RTC 接口使用说明](https://www.rt-thread.org/document/site/#/rt-thread-version/rt-thread-standard/programming-manual/device/rtc/rtc)

![image-20211027181550233](picture/rtc_env.png)

## Flash
### Flash

1. 创建 Flash

Expand All @@ -133,7 +144,7 @@

![image-20211026123252310](picture/flash_menuconfig.png)

## SPI
### SPI

1. 添加一个 SPI 外设端口

Expand All @@ -143,11 +154,16 @@

![img](picture/spi.png)

3. 如何在 ENV 中打开 SPI 以及 [SPI 接口使用说明](https://www.rt-thread.org/document/site/#/rt-thread-version/rt-thread-standard/programming-manual/device/spi/spi)
3. 在 Pins 中打开 SPI0 ,配置端口引脚。**注意:请勿在此处配置 SSLx 片选引脚,片选引脚的控制在驱动程序中由软件控制。**

![image-20211209162334093](picture/spi_pin.png)


4. 如何在 ENV 中打开 SPI 以及 [SPI 接口使用说明](https://www.rt-thread.org/document/site/#/rt-thread-version/rt-thread-standard/programming-manual/device/spi/spi)

![image-20211027181444023](picture/spi_env.png)

## ADC/DAC
### ADC/DAC

创建 ADC/DAC

Expand Down Expand Up @@ -181,14 +197,13 @@

4. 在 menuconfig 中打开对应的通道

## 通用 PWM 定时器(GPT)
### 通用 PWM 定时器(GPT)

GPT 定时器在该芯片中可作为通用定时器,也可以用于产生 PWM 信号。在将其用于产生 PWM 信号时,GPT 定时器提供了 gpt0 - gpt9 总共 10 个通道,每个通道可以设定两个输出端口。当前版本的 PWM 驱动将每个通道都看做一个单独的 PWM 设备,每个设备都只有一个通道。用户可以选择开启一个通道的任意一个输出端口,或将两个端口均开启,但在同时开启两个端口的情况下,它们输出的波形将完全一致。

1. 添加 GPT 设备

![img](./picture/add_gpt1.png)

2. 配置通道

![img](./picture/add_gpt2.png)
Expand All @@ -200,13 +215,83 @@ GPT 定时器在该芯片中可作为通用定时器,也可以用于产生 PWM
3. 设定 PWM 通道默认输出的占空比,这里为 50% 。
4. 设定 GPT 通道下两个输出端口的使能状态。
5. 此处设置 GPT 通道下两个输出端口各自对应的引脚。

3. 配置输出引脚

![img](./picture/add_gpt3.png)

在完成上一步对 GPT 定时器的设置后,根据图示找到对应 GPT 通道输出引脚设置的界面(这里是 GPT3),将图中标号 **1** 处设置为 ``GTIOCA or GTIOCB`` ,并根据需要在图中标号 **2** 处设置 GPT 通道下两个输出端口各自对应的输出引脚。
4. 在 menuconfig 中打开对应的通道,[RT-Thread 的 pwm 框架介绍](https://www.rt-thread.org/document/site/#/rt-thread-version/rt-thread-standard/programming-manual/device/pwm/pwm)

4. 在 menuconfig 中打开对应的通道,[RT-Thread 的 pwm 框架介绍](https://www.rt-thread.org/document/site/#/rt-thread-version/rt-thread-standard/programming-manual/device/pwm/pwm)

![image-20211103202216381](picture/pwm_env.png)

### CAN

1. 添加CAN

![image-20211102145023112](picture/can.png)

2. 配置Callback为 `can0_callback` 或 `can1_callback`

![image-20211102145227603](picture/can_callback.png)

3. 配置其他选项,并生成代码。

4. 使用ENV使能CAN。[CAN设备使用说明](https://www.rt-thread.org/document/site/#/rt-thread-version/rt-thread-standard/programming-manual/device/can/can)

![image-20211102145613309](picture/can_menuconfig.png)


### 使用 WiFi 模块 [RW007 ](https://github.com/RT-Thread-packages/rw007)

1. 软件包配置中找到 RW007,并修改为下图配置

![image-20211108142805319](picture/rw007_pkg.png)

2. menuconfig 中打开驱动的 RW007 配置,默认使用了 SPI1 端口。所以需要打开 SPI1 总线。

![image-20211108142453678](picture/rw007_spi.png)

![image-20211213212034701](picture/drv_rw007.png)

3. 在设备驱动框架中打开 [WLAN 框架](https://www.rt-thread.org/document/site/#/rt-thread-version/rt-thread-standard/programming-manual/device/wlan/wlan),

![image-20211108143027485](picture/rw007_wlan.png)

在网络配置中打开 NETDEV 组件:

![image-20211108143712513](picture/rw007_netdev.png)

在 kernel 中打开 mempool 配置:

![image-20211209161902884](picture/rw007_mempool.png)

4. FSP 中打开添加 SPI 外设端口,[如何添加SPI](#SPI)。下图以 SPI1 端口为例的配置如下:

![image-20211108183631379](picture/rw007_spicfg.png)

5. RW007 有一个从机控制的 INT 引脚,需要占用一个 IRQ 通道,下图以 P506 为例的配置如下:

![image-20211108183724282](picture/rw007_int.png)

6. RW007 的 RESET 控制引脚修改默认配置,这里在 RASC 中 mode 设为关闭,交由 RW007 中进行控制。

![image-20211213144108558](picture/rw007_reset.png)

7. 配置完成,检查 MDK 工程中是否加入了必要的文件

![image-20211109102232233](picture/rw007_mdk.png)

8. 编译下载,验证结果。

系统启动会自动获取 RW007 的信息,输入`wifi scan` 命令扫描环境中的 WiFi 信号。[更多 WiFi 命令](https://www.rt-thread.org/document/site/#/rt-thread-version/rt-thread-standard/programming-manual/device/wlan/wlan?id=finsh-%e5%91%bd%e4%bb%a4)

![image-20211109103856130](picture/rw007_test.png)

使用 `WiFi join` 命令连接 WiFi 热点 :

![image-20211109104735733](picture/rw007_wifijoin.png)

使用 `ping rt-thread.com` 测试网络连接:

![image-20211109104700939](picture/rw007_ping.png)
50 changes: 48 additions & 2 deletions bsp/ra6m4-cpk/drivers/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ menu "Hardware Drivers Config"
default y
if BSP_USING_I2C1
config BSP_I2C1_SCL_PIN
int "i2c1 scl pin number"
hex "i2c1 scl pin number"
range 0x0000 0x0B0F
default 0x0512
config BSP_I2C1_SDA_PIN
int "I2C1 sda pin number"
hex "I2C1 sda pin number"
range 0x0000 0x0B0F
default 0x0511
endif
Expand Down Expand Up @@ -181,9 +181,55 @@ menu "Hardware Drivers Config"
default n
endif

menuconfig BSP_USING_CAN
bool "Enable CAN"
default n
select RT_USING_CAN
if BSP_USING_CAN
config BSP_USING_CAN0
bool "Enable CAN0"
default n

config BSP_USING_CAN1
bool "Enable CAN1"
default n
endif

endmenu

menu "Board extended module Drivers"

menuconfig BSP_USING_RW007
bool "Enable RW007"
default n
select PKG_USING_RW007
select BSP_USING_SPI

if BSP_USING_RW007
config RA_RW007_SPI_BUS_NAME
string "RW007 BUS NAME"
default "spi1"

config RA_RW007_CS_PIN
hex "(HEX)CS pin index"
default 0x040D

config RA_RW007_BOOT0_PIN
hex "(HEX)BOOT0 pin index (same as spi clk pin)"
default 0x040C

config RA_RW007_BOOT1_PIN
hex "(HEX)BOOT1 pin index (same as spi cs pin)"
default 0x040D

config RA_RW007_INT_BUSY_PIN
hex "(HEX)INT/BUSY pin index"
default 0x0506

config RA_RW007_RST_PIN
hex "(HEX)RESET pin index"
default 0x040F
endif

endmenu
endmenu
3 changes: 3 additions & 0 deletions bsp/ra6m4-cpk/drivers/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ if GetDepend(['BSP_USING_ONCHIP_FLASH']):
if GetDepend(['BSP_USING_PWM']):
src += ['drv_pwm.c']

if GetDepend(['BSP_USING_CAN']):
src += ['drv_can.c']

path = [cwd]
path += [cwd + '/config']

Expand Down
4 changes: 2 additions & 2 deletions bsp/ra6m4-cpk/drivers/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ extern int Image$$RAM_END$$ZI$$Base;
#pragma section="CSTACK"
#define HEAP_BEGIN (__segment_end("CSTACK"))
#else
extern int __bss_end;
#define HEAP_BEGIN (&__bss_end)
extern int __RAM_segment_used_end__;
#define HEAP_BEGIN (&__RAM_segment_used_end__)
#endif

#define HEAP_END RA_SRAM_END
Expand Down
4 changes: 4 additions & 0 deletions bsp/ra6m4-cpk/drivers/config/drv_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ extern "C" {
#include "ra6m4/pwm_config.h"
#endif

#ifdef BSP_USING_CAN
#include "ra6m4/can_config.h"
#endif

#endif/* SOC_SERIES_R7FA6M4AF */

#ifdef __cplusplus
Expand Down
Loading