未验证 提交 1c64c9ef 编写于 作者: S Sherman 提交者: GitHub

[bsp/renesas/docs/] Add English documents (#5985)

* [bsp/renesas/docs/] Add English documents
上级 37d9921a
......@@ -20,3 +20,13 @@ RA 系列 BSP 目前支持情况如下表所示:
| [BSP 制作教程](docs/RA系列BSP制作教程.md) | 讲解 RA 系列 BSP 的制作方法,以及在制作 BSP 和提交 BSP 时应当遵守的规范 |
| [外设驱动添加指南](docs/RA系列外设驱动添加指南.md) | 讲解 BSP 添加更多设备驱动的方法 |
English documents:
| **BSP Tutorial** | **Introduction** |
|:-------------------- |:------------------------------------------------- |
| [BSP Peripheral Driver Tutorial of RA Series](docs/BSP_Peripheral_Driver_Tutorial_of_RA_Series.md) | Explains how to use more peripheral drivers on the BSP |
| [Introduction to RA Series Drives](docs/Introduction_to_RA_Series_Drives.md) | Explains the support of RA series BSP drivers and how to develop applications using the driver framework |
| [RA Series Uses FSP to Configure Peripheral Drivers](docs/RA_Series_Uses_FSP_to_Configure_Peripheral_Drivers.md) | Introduces how to add and configure peripherals using the FSP tool |
| **BSP Production and Submission** | **Introduction** |
| [Building a BSP for the RA Series Dev Board](docs/Building_a_BSP_for_the_RA_Series_Dev_Board.md) | Explains how the RA series BSPs are created and the specifications to be followed when creating and submitting BSPs |
| [Peripheral Driver Addition Guide of RA Series](docs/Peripheral_Driver_Addition_Guide_of_RA_Series.md) | Explains how to add more device drivers to BSP |
# BSP Peripheral Driver Tutorial of RA Series
## 1. Introduction
This document is for developers who need more board resources on RT-Thread RTOS. By configuring the BSP with the ENV tool, more onboard resources can be turned on and more advanced functions can be realized.
The main contents are following:
1. How to use more onboard resources on the development board
2. How to use more on-chip resources
3. How to add more on-chip resource options
## 2. Prerequisites
- Learn how to use the ENV tool, refer to: [RT-Thread env programming manual](https://www.rt-thread.org/document/site/programming-manual/env/env/)
- Familiar with the use of the [FSP](https://www2.renesas.cn/jp/zh/software-tool/flexible-software-package-fsp) configuration tool
## 3. How to Use More Peripheral Resources
There are generally many peripheral resources on-board, such as SPI, SDIO, ADC, etc., but these peripherals' driver are not enabled by default in the BSP project. RT-Thread provides ENV tools to enable or disable BSP peripheral drivers. This article takes the SPI driver on the RA6M4-CPK development board as an example to show step by step how to use the ENV tool to configure the BSP.
### 3.1 Open The Configuration Tool
Open the menuconfig configuration window in the BSP directory.
![image-20220218162910778](figures_en/menuconfig_ra6m4cpk.png)
The configuration window that opens is as follows:
![config1](figures_en/config1.png)
Move the cursor with the up and down keys on the keyboard, select `Hardware Drivers Config` and press Enter to enter the hardware driver configuration menu.
### 3.2 Enter The Hardware Driver Configuration Menu
There are three options in the hardware configuration menu, namely **on-board peripheral configuration menu**, **on-chip peripheral configuration menu** and **extension module configuration menu**, use the down button to switch to on-chip peripherals, Press Enter to enter the configuration menu.
![Hardware driver configuration menu](figures_en/config2.png)
### 3.3 Enable The SPI Flash Option in The Onboard Peripheral Configuration Menu
![image-20220218163357420](figures_en/menuconfig_spi.png)
![image-20220218163714429](figures_en/menuconfig_spi1.png)
### 3.4 Save and Exit
Move the cursor to the right to select Save and press Enter, then press Esc to exit the configuration tool.
![Save and exit](figures_en/save.png)
### 3.5 Generate MDK5 Project
Enter the command `scons --target=mdk5` to regenerate the MDK5 project.
![image-20220218164532436](figures_en/scons_mdk5.png)
### 3.6 Add SPI Peripheral to FSP
![image-20220218171841353](figures_en/fsp_spi.png)
![image-20220218172446068](figures_en/fsp_spi1.png)
Configure the SPI1 pins in Pins. **Note: The SSLx chip select pin is set to None, the chip select pin is controlled by software in the driver. **
Configuration completes, save and exit FSP.
![image-20220218174145848](figures_en/fsp_spi2.png)
### 3.7 Test Verification
Back to the generated MDK5 project and do the compilation. If a new file is added to the project after the FSP configuration is completed, it will not be added immediately. It needs to be compiled once. If the following prompt pops up, select "Yes" and then compile again.
![image-20220218174811328](figures_en/mdk_build.png)
After the compilation is successful, click the debug button to download and enter the debug page.
![image-20220218175442360](figures_en/mdk_build1.png)
### 3.8 Check Execution Result
After the program runs, enter the command `list_device` to see the bus device named spi1, and the SPI1 bus is ready to use.
![image-20220218175926965](figures_en/run_spi1.png)
## 4. Summarize
This article uses SPI as an example to introduce the operation flow of peripheral drivers. For how to use and configure other types of peripherals, please refer to: [RA series use FSP to configure peripheral drivers.md](RA series use FSP to configure peripheral drivers.md )
When developers need to use unenabled peripherals, they only need to enable the related peripherals in the ENV tool, and then add them in the FSP. The corresponding driver files will be added to the regenerated project.
This tutorial translated by [Josh Zou](https://github.com/Firmament-Autopilot)
\ No newline at end of file
# Building a BSP for the RA Series Dev Board
This article introduces how to build a BSP for the RENESAS RA series development board. This tutorial helps developers to build a new RA BSP easily, and obtain a better understanding of the architecture of the RA series BSP.
Each BSP folder includes a template project, the `board` folder, and build scripts for RT-Thread projects. General drivers for the RT-Thread port are inside the folder `renesas\libraries\HAL_Drivers`. These are two essential parts of a complete BSP.
The **[Flexible Software Package](https://www2.renesas.cn/jp/zh/software-tool/flexible-software-package-fsp)** (FSP) configuration tool is introduced in the RA series, which is an accessible and flexible software for embedded system designs using the RA series ARM MCU. FSP includes HAL drivers of high-performance and low memory consumption. Besides, we provide an intelligent code generator and a GUI.
Major features of the RA series BSP include:
- RA Templates that are generated using the FSP tool, making it easier to build a new BSP.
- General drivers for further development.
- Peripherals of the chip can be configured using the FSP configuration tool with a GUI.
## 1. BSP Structure
The structure of a BSP:
![BSP Structure](./figures_en/frame.png)
Each BSP consists of two components: general driver libraries and board specific files. We introduce each component using ra6m4-cpk as an example:
|Component|Folder|Remark|
| - | - | :-- |
| general driver libraries | renesas\libraries\HAL_Drivers | General drivers for RT-Thread |
| board specific files | renesas\ra6m4-cpk | The BSP project of CPK-RA6M4 |
## 2. Prerequisites
To build a proper BSP, you may need to be familiar with the RT-Thread build system:
- Understand how to use RA series BSP
The [BSP Documentation](../README.md) may help you understand how RA BSP works. The *Device Driver Guidance* is a good reference for adding new device drivers.
- Familiar with the [Scons](https://www.rt-thread.org/document/site/#/development-tools/scons/scons) build system
RT-Thread adopts `Scons` as its build system, thus it is necessary to understand how `Scons` works.
- Familiar with [Device Driver Framework](https://www.rt-thread.org/document/site/#/rt-thread-version/rt-thread-standard/programming-manual/device/device)
RT-Thread uses the Device Driver Framework to handle the hardware, thus it could help you build a new BSP.
- Familiar [Kconfig](https://www.rt-thread.org/document/site/#/development-tools/kconfig/kconfig)
RT-Thread is configured through `menuconfig`, and options in `menuconfig` are written in `Kconfig` , thus it is necessary to familiarize `Kconfig` to configure RT-Thread.
- Familiar with the [FSP](https://www2.renesas.cn/jp/zh/software-tool/flexible-software-package-fsp) configuration tool
FSP provides a GUI and smart code generator. The FSP tool is commonly used while building a BSP.
## 3. How to build a BSP
This section introduces how to create a BSP for the CPK-RA6M4 development board. The final BSP will support both MDK and scons.
Creating a new BSP consists of following steps:
1. Create the BSP folder.
2. Create the RA template project.
3. Configure the template project.
4. Modify the `Kconfig` file.
5. Modify the build and configuration file for the project.
6. Re-generate the project.
7. Add GCC link scripts.
8. Modify compiling parameters in `rtconfig.py`.
### 3.1 Create the BSP folder
- To create the BSP folder, you can copy the template from `\renesas\libraries\bsp-template` to `\renesas`, and rename it to be the name of your board. The naming convention could use **ra6m4-cpk** as a reference. As the folder `ra6m4-cpk` already exists, this tutorial uses **ra6m4-test** as the name for the new BSP to be created.
![image-20220217155725977](figures_en/bsp_crate.png)
![image-20220217160140135](figures_en/bsp_crate1.png)
![image-20220217161302858](figures_en/bsp_crate2.png)
### 3.2 Create the RA template project
The first step is to create a RA template using the FSP tool.
- Double click on `/eclipse/rasc.exe` from the FSP installation folder. An interface will be presented to help you create a new project.
![fsp_crate](figures_en/fsp_crate.png)
![fsp_crate1](figures_en/fsp_crate1.png)
![fsp_crate2](figures_en/fsp_crate2.png)
![fsp_crate3](figures_en/fsp_crate3.png)
![fsp_crate4](figures_en/fsp_crate4.png)
![fsp_crate5](figures_en/fsp_crate5.png)
![image-20220211182959790](figures_en/fsp_crate6.png)
Now. you should have a RA template, and basic configuration files and drivers for a BSP, as illustrated above.
### 3.3 Configure the project template
When the RA template project is ready, some modifications are required for basic peripherals such as GPIO, UART.
- Open the template project `template.uvprojx`
![image-20220214174740157](figures_en/template_open.png)
- Modify the MDK project configuration
> **Debug Options:** You may take a screenshot to record default settings. After changing settings in`Device`, part of the settings in the `Debug` page will change, you can reset them to default after changing the `Device`.
![img](figures_en/template_config4.png)
> **Device Options: **Select the device type of the SoC on your board.
![img](figures_en/template_config.png)
> **Output Options:** Change `Name of Exexutable` to be rtthread, and select `Create HEX File` so that it generates the hex file to be flashed.
![image-20220218144358105](figures_en/template_config1.png)
> **User Options:**If TrustZone is utilized, extra commands are invoked to setup the partition for Secure & Non-Secure . If only the Flat mode is used during development, this can be ignored. Otherwhile please add【cmd /c "start "Renesas" /w cmd /c ""$Slauncher\rasc_launcher.bat" "3.5.0" --gensecurebundle --compiler ARMv6 "$Pconfiguration.xml" "$L%L" 2> "%%TEMP%%\rasc_stderr.out"""】
![img](figures_en/template_config2.png)
> C/C++ Options: Some warnings can be suppressed, such as “-Wextra“, ”-Wconversion“, ”-Wshadow ”.
>
> Take ra6m4-cpk as an example, following options are added: -Wno-license-management -Wuninitialized -Wall -Wmissing-declarations -Wpointer-arith -Waggregate-return -Wfloat-equal
![img](figures_en/template_config3.png)
> **Utilities Options**: Select `Use External Tool for Flash Programming`. Click on `OK` to save your settings.
![img](figures_en/template_config5.png)
- Open the FSP from MDK
> **How to open the FSP in MDK:**
>
> 1. Open MDK, choose “Tools -> Customize Tools Menu…”
> 2. Click on the “new” icon, then add a customized command: RA Smart Configurator
> 3. Specify the installation folder of the tool in the Command setting, click on “…” and find the “rasc.exe” in the installation folder (In the folder `setup_fsp_xxxxx`)
> 4. Initial Folder: $P
> 5. Arguments: --device $D --compiler ARMv6 configuration.xml
> 6. Click OK and save the command “Tools -> RA smart Configurator”
![img](figures_en/fsp_config.png)
> 7. Click on the command to open the configuration tool: **RA Smart Config**
![img](figures_en/fsp_config1.png)
- Add the UART port
> Choose the Stacks tab,click on New Stack and find UART.
![image](figures_en/fsp_uart.png)
> Set the UART channel for MSH, and configure the UART parameters, so that it matches RT-Thread drivers. Set **name**, **channel**, **callback** following the convention: channel = **X**,name = g_uart**X**、callback = user_uart**X**_callback
![image](figures_en/fsp_uart1.png)
### 3.4 Modify options in `Kconfig`
This section modifies `board/Kconfig` an `libraries/Kconfig`:
- SoC series and types
- Available Peripheral options on the BSP
Definitions for the SoC are available in`renesas\libraries\Kconfig`. Check if the definition for the SoC to be added exist before making changes. If it's undefined. you need to add definitions for the SoC series first. Naming conventions are described below:
| Macro | Meaning | Format |
| ------------------ | ---------- | ------------------ |
| SOC_R7FA6M4AF | SoC Type | SOC_R7FAxxxxx |
| SOC_SERIES_R7FA6M4 | SoC Series | SOC_SERIES_R7FAxxx |
Add the SoC series:
![image-20220422164816261](figures\Kconfig1.png)
Available peripheral options for the new BSP only need to include GPIO and UART:
![Modify Kconfig](./figures_en/Kconfig.png)
### 3.5 Modify the build and configuration files for the project
- Add config for drivers. Several folders should be created according to different SoC series. You can modify configurations according to supported peripherals.
![image-20220422163750161](figures\drv_config.png)
​ For instance, you can add configurations for the UART accordingly:
![image-20220422164058202](figures\drv_config_uart.png)
- Modify `startup.c`
> Source code path:**ra6m4-cpk\ra\fsp\src\bsp\cmsis\Device\RENESAS\Source\startup.c**
```c
#ifdef __ARMCC_VERSION
main();
#elif defined(__GNUC__)
extern int entry(void);
entry();
#endif
```
![img](figures_en/startup_c.png)
- Change SRAM size
![image-20220303113833249](figures_en/board_config.png)
- Change GPIO interrupt
Change configuration files according to IRQ interrupts supported by the BSP. You can use the FSP configuration tool to look up for the IRQ channel of IO Pins.
![image-20220217174433724](figures_en/bsp_gpio.png)
- Change the code that initializes applications
In RA series BSP, the code for user applications are in `src/hal_entry.c`. Default code generated by the FSP tool should be replaced with the following code, you can remove the code in `while(1)` if there is no onboard LED.
```c
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2021-10-10 Sherman first version
*/
#include <rtthread.h>
#include "hal_data.h"
#include <rtdevice.h>
#define LED_PIN BSP_IO_PORT_01_PIN_06 /* Onboard LED pins */
void hal_entry(void)
{
rt_kprintf("\nHello RT-Thread!\n");
while (1)
{
rt_pin_write(LED_PIN, PIN_HIGH);
rt_thread_mdelay(500);
rt_pin_write(LED_PIN, PIN_LOW);
rt_thread_mdelay(500);
}
}
```
- Change CPU parameters in `rtconfig.py`
![image-20220303165348085](figures_en/rtconfig_py.png)
### 3.6 Re-generate the project
The `env` tool is required to re-generate the project.
- re-generate the `rtconfig.h` file
In the `Env` tool, use the command `menuconfig` to configure the project and generate a new `rtconfig.h` file:
![menuconfig interface](./figures_en/menuconfig_1.png)
Enable the GPIO and UART port for the console.
![Enable peripherals](./figures_en/menuconfig_2.png)
Change the output device name for the console:
![image-20220303103240414](figures_en/menuconfig2.png)
- Generate the MDK project:
In the `env` tool use `scons --target=mdk5` to re-generate the project:
![Re-generate BSP project](./figures_en/menuconfig_3.png)
Successfully re-generated the project:
![Re-generate BSP project](./figures_en/menuconfig_4.png)
Now the BSP is ready for MDK development. If you would like yo use the GCC toolchain, linker scripts for GCC need to be added.
### 3.7 Add GCC linker script
The Linker scripts for GCC can be generated using the IDE: `e2studio`. In a new project created by `e2studio`:
![image-20220218114041568](figures_en/e2studio1.png)
![image-20220218113955219](figures_en/e2studio.png)
![ ](figures_en/e2studio2.png)
![image-20220218114839257](figures_en/e2studio3.png)
![image-20220218115035562](figures_en/e2studio4.png)
![image-20220218115332866](figures_en/e2studio5.png)
After creating the project. we need to copy two `xxx.ld` files to the `script` folder.
![image-20220218115715957](figures_en/e2studio6.png)
- Change the path of the linker script:
> Linker script path:**ra6m4-cpk\script\fsp.ld**
![image-20220215182642126](figures_en/linkscript1.png)
> Copy the following to the text section **inside text{ }**
```shell
/* section information for finsh shell */
. = ALIGN(4);
__fsymtab_start = .;
KEEP(*(FSymTab))
__fsymtab_end = .;
. = ALIGN(4);
__vsymtab_start = .;
KEEP(*(VSymTab))
__vsymtab_end = .;
/* section information for initial. */
. = ALIGN(4);
__rt_init_start = .;
KEEP(*(SORT(.rti_fn*)))
__rt_init_end = .;
. = ALIGN(4);
KEEP(*(FalPartTable))
```
> It should be like:
![img](figures_en/linkscript.png)
### 3.8 Modify compiling parameters in `rtconfig.py`
![image-20220303165348085](figures_en/rtconfig_py.png)
Besides the kernel type, we need to confirm compiler parameters as well. Related configurations are explained in the documentation center. [link](https://www.rt-thread.org/document/site/#/development-tools/scons/scons?id=编译器选项).
Eventually, a basic BSP that supports both GCC and MDK is now ready. We can verify the project compiles successfully using MDK or scons.
Thanks for contributions from every contributor. RT-Thread will grow together with you.
## 4. Contribution Guidelines
This section introduces some guidelines for submitting a new RT-Thread RA BSP. Developers could check if these guidelines are followed before creating a PR.
### 4.1 BSP Guidelines
The guidelines consist of project configuration, ENV configuration, and IDE configuration. Existing RA BSP templates are configured following the guidelines. Please keep these configurations for a new BSP while copying from templates. When the new BSP is ready, it's suggested to test corresponding functionalities before creating a PR.
#### 4.1.1 Project Configuration
- Follow RT-Thread coding guidelines with consistent code comments
- Remain the `main` function consistent
- If there is a LED, the `main` function implements **only one** functionality: blinking the LED at 1HZ.
- Initialize the heap in `rt_hw_board_init`: Invoke `rt_system_heap_init`.
- By default, only initialize GPIO and the serial driver for FinSH, and the DMA should be disabled.
- When enabling onboard device drivers, the project should compile without changing any code.
- Make sure the GCC and MDK compiler compiles with no error.
- Publish the BSP using `scons --dist`, and make sure the project generated functions properly.
#### 4.1.2 ENV Configuration
- The system tick is set as 1000 (The macro: RT_TICK_PER_SECOND)
- Enable asserting in Debug options (The macro: RT_DEBUG)
- The stack size of the system idle thread is set to be 256 (The macro: IDLE_THREAD_STACK_SIZE)
- Enable component auto initialization (The macro: RT_USING_COMPONENTS_INIT)
- Enable the `user main` option (The macro: RT_USING_USER_MAIN)
- Disable `libc` by default (The macro: RT_USING_LIBC)
- Use MSH by default in FinSH (The macro: FINSH_USING_MSH_ONLY)
#### 4.1.3 IDE Configuration
- Enable autorun after downloading the code.
- Enable C99 Support.
- Enable `One ELF Section per Function` (MDK).
- Temporary build files should be placed in the `build` folder (MDK/IAR).
- The hex file generated by MDK/GCC/IAR should be named as `rtthread.hex`.
### 4.2 BSP Contribution Guidelines
- Please modify the `README.md` carefully before submitting a BSP. The list of supported peripherals in `README.md` should all be supported in this BSP. Other BSP could be a good reference. All the drivers are listed in the [Introduction to RA Series Driver](./RA系列驱动介绍.md).
- Two steps to submit a BSP:
- Step1: A basic BSP includes drivers for UART and GPIO, and should be able to use the FinSH console. Support for `MDK5`, `IAR` and `GCC` compilers should be complete. You may omit support for MDK4 if the chip itself does not support MDK4. The `README.md` of the BSP should contain all the drivers to be added in the second step.
- Step 2: Add support for onboard drivers, all onboard peripherals should be ready-to-use with `menuconfig`. Peripherals that are not available on this board can be omitted. Different drivers should be committed separately for future review and merging.
- Only submit necessary files for the BSP. Temporary files should be removed.
- Make sure the BSP compiles using different compilers.
- Make sure the BSP works properly, and follow the project configuration guidelines.
> Translated by: [wuhanstudio](https://github.com/wuhanstudio)
# Introduction to RA Series Drives
In the RT-Thread real-time operating system, a wide variety of device drivers are managed through a set of I/O device management frameworks. The device management framework provides a set of standard device operation APIs for upper-level applications, and developers can efficiently interact with the underlying hardware peripherals by calling these standard device operation APIs. The structure of the Device Management Framework is shown in the following figure:
![image-20220308143402996](figures_en/rtdevice.png)
Developing applications using the I/O Device Management Framework has the following advantages:
- Develop applications using the same standard set of APIs to make applications more portable
- Upgrades and modifications to the underlying drivers do not affect the upper-level code
- Drivers and applications are independent of each other, making it easy for multiple developers to work together
## 1. Introduction to drive classification
This section introduces the different class-driven concepts provided by BSPs, and for a BSP, there are three types of drivers:
- **Onboard Peripheral Drivers**: Refers to peripherals on the development board outside of the MCU, such as TF cards, Ethernet, etc
- **On-chip Peripheral Drivers**: Refers to peripherals on the MCU chip, such as hardware timers, ADCs, and watchdogs
- **Board extended module Drivers**: Refers to modules of a development board that can be connected via an expansion interface or a DuPont wire, such as an RW007 module
A schematic diagram of these three peripherals is shown below:
![Peripheral](figures_en/Peripheral.png)
## 2. How to use peripheral drivers
The driver libraries currently provided by RT-Thread already support multiple series of BSPs for RA. Click on the driver name in the table below to jump to the introductory document for the corresponding driver framework. Developers can read the materials to learn how to use these peripheral drivers through the device driver framework in application development.
### 2.1 On-chip peripherals
| Driver | Introduction |
| ------------------------------------------------------------ | ------------------------------------------------ |
| [GPIO](https://www.rt-thread.org/document/site/programming-manual/device/pin/pin/) | Operate the GPIO pins |
| [UART](https://www.rt-thread.org/document/site/programming-manual/device/uart/uart/) | Send and receive data through serial ports |
| [I2C](https://www.rt-thread.org/document/site/programming-manual/device/i2c/i2c/) | Send and receive data via software I2C |
| [SPI](https://www.rt-thread.org/document/site/programming-manual/device/spi/spi/) | Send and receive data over SPI |
| [ADC](https://www.rt-thread.org/document/site/programming-manual/device/adc/adc/) | Measure the analog data on the pin |
| SDIO | Read and write data through SDIO |
| [TIMER](https://www.rt-thread.org/document/site/programming-manual/device/hwtimer/hwtimer/) | Use hardware timers to implement the function of measuring time and timing execution callback functions |
| [PWM](https://www.rt-thread.org/document/site/programming-manual/device/pwm/pwm/) | Outputs a PWM waveform at a specific pin |
| [RTC](https://www.rt-thread.org/document/site/programming-manual/device/rtc/rtc/) | Set and read times |
| [WDT](https://www.rt-thread.org/document/site/programming-manual/device/watchdog/watchdog/) | Watchdog driver |
| [QSPI](https://www.rt-thread.org/document/site/programming-manual/device/spi/spi/#qspi_1) | Send and receive data via SPI (1, 2, 4-wire). |
### 2.2 On-board peripherals
| Driver | Introduction |
| ---- | --------------------------------------- |
| I2C | On-board I2C sensor |
| SDIO | SD (TF) card for SPI interface or SDIO interface |
### 2.3 Extensions
| Driver | Introduction |
| ---------------------------------------------------- | ---------------------------- |
| [RW007](https://github.com/RT-Thread-packages/rw007) | WIFI module with SPI interface |
| [HS300x](https://github.com/Guozhanxin/hs300x) | Temperature and humidity sensor with I2C interface |
| [ZMOD4410](https://github.com/ShermanShao/zmod4410) | Indoor air quality sensor with I2C interface |
### 2.4 Driver sample code
In RT-Thread's `examples\test` directory, there is sample code provided by RT-Thread based on different peripheral drivers. You can quickly test the drivers provided in BSP by turning on the drivers to be tested in the env tool and adding the corresponding driver framework test files from `examples\test` to the project.
This tutorial translated by [Josh Zou](https://github.com/Firmament-Autopilot)
\ No newline at end of file
# Peripheral Driver Addition Guide of RA Series
## 1. Introduction
This document is intended for developers who need to add more peripheral drivers to their existing RA series BSPs. By reading this article, developers can add their own drivers to existing BSPs according to their actual situation.
## 2. Prerequisites
- Proficiency in using ENV tools, reference: [RT-Thread env tools user manual](https://www.rt-thread.org/document/site/rtthread-development-guide/rtthread-tool-manual/env/env-user-manual/)
- Familiar with [Kconfig](https://www.rt-thread.org/document/site/#/development-tools/kconfig/kconfig) programmer
- Familiar with [FSP](https://www2.renesas.cn/jp/zh/software-tool/flexible-software-package-fsp) tool
- Understanding RT-Thread [Device Driver Framework](https://www.rt-thread.org/document/site/#/rt-thread-version/rt-thread-standard/programming-manual/device/device)
## 3. How to add more peripheral driver options
This section uses the example of adding on-chip peripheral drivers to explain how to add more drivers available to BSPs. If the on-chip peripherals you want to use are not available in the 'On-chip peripheral configuration menu', you need to add them yourself. Below we will demonstrate how to add a UART9 port for ra6m4-cpk.
Adding peripheral support for UART requires the following steps:
### 3.1 Modify the Kconfig file
Open the board\kconfig file in the BSP and add the UART9 configuration.
![image-20220221161853343](figures_en/add_uart.png)
![image-20220221163152761](figures_en/add_uart1.png)
After the modification is complete, open the ENV tool in the BSP directory and enter the 'menuconfig' command on the command line to see if the UART9 configuration has been added.
![image-20220221164229974](figures_en/add_uart2.png)
### 3.2 Modify the uart_config.h file
Once the configuration of Kconfig is added, you also need to add the corresponding configuration in the configuration file and driver file.
Open the file `libraries\HAL_Drivers\config\ra6m4\uart_config.h` to add the UART9 configuration.
![image-20220221170945734](figures_en/add_uart3.png)
### 3.3 Modify the drv_usart_v2.h file
Open `librariesHAL_Driversdrv_usart_v2.c' and add the following code:
![image-20220221171806580](figures_en/add_uart4.png)
![image-20220221172034531](figures_en/add_uart5.png)
### 3.4 Test validation
1. Open UART9 in menuconfig and save the configuration, regenerating the MDK project using the 'scons --target=mdk5' command.
2. Open the FSP Configuration Tool from the project project and add the UART9 port
![image-20220221180942314](figures_en/add_uart6.png)
![image-20220221183752087](figures_en/add_uart8.png)
3. Configure the CORRESPONDING IO pin of UART9, save and exit.
![image-20220221183405828](figures_en/add_uart7.png)
4. Compile, debug download, enter list_device command to see that the uart9 device has been registered to the kernel, indicating that the device was added successfully, and then you can use the UART9 port to communicate.
![image-20220221185534932](figures_en/add_uart9.png)
This tutorial translated by [Josh Zou](https://github.com/Firmament-Autopilot)
\ No newline at end of file
# RA Series Uses FSP to Configure Peripheral Drivers
## 1. Preparation
### 1.1 Add custom command to start FSP in MDK
1. Open MDK, select “Tools -> Customize Tools Menu…”
2. Click the “new” icon to add a custom command: RA Smart Configurator
3. Enter the installation path of the tool in Command, click "**...**" to find the "rasc.exe" file under the installation path and select it (under the rasc installation directory)
4. Enter parameter in Initial Folder: $P
5. Enter parameter in Arguments: --device $D --compiler ARMv6 configuration.xml
6. Click OK to save command
![img](figures_en/customize.png)
7. Click the added command "Tools -> RA smart Configurator", **Open the configuration tool**: RA Smart Config
![image.png](figures_en/openrasc.png)
PS:The above related operations can also be found in the FSP documentation.
FSP Document:https://www2.renesas.cn/jp/zh/software-tool/flexible-software-package-fsp#document
### 1.2 Precautions
#### 1.2.1 FSP Version selection
The RA series has been updated to support the **FSP 3.5.0** version, please use the **FSP 3.5.0** version for configuration modification, **the old version may have compatibility issues**.
**Be sure to check whether the FSP version, Board, Device configuration items are correct before using RASC. **
![fsp_version](figures_en/fsp_version.png)
#### 1.2.2 Update project configuration
After the FSP configuration is completed, if a new file is added to the project, it will not be added immediately. It needs to be compiled once. If the following prompt pops up, select "Yes" and then compile again.
![img](figures_en/import_changes.png)
## 2. Add and configure peripherals using FSP
**PS: The peripheral adding steps in the document are instructions for individual configuration. The typesetting order does not represent the peripheral adding order. If you encounter pin conflicts, please refer to the relevant chapters of the development board and chip manual. **
### UART
How to add a UART port peripheral configuration?
1. Select the Stacks configuration page, click New Stack to find the UART.
![image.png](figures_en/fsp_uart.png)
2. Configure the UART parameters, because it needs to adapt to the naming used in the RT-Thread driver, so you need to modify the naming, and set **name** , **channel** , **callback** to be the same label.
![image.png](figures_en/fsp_uart1.png)
### GPIO Interrupt
How to add an IO interrupt?
1. Select the pin number and enter the configuration, for example, select P105 as the interrupt pin. You can first find the pin to view the IRQx channel number that can be configured.
![image-20211103200949759](figures_en/p105.png)
2. Open ICU interrupt channel IRQ00
![image-20211103200813467](figures_en/irq0.png)
3. Create stack and enter configuration. Because it needs to adapt to the naming used in the RT-Thread driver, it is necessary to modify the naming and set **name** , **channel** , **callback** to be the same label. Select the trigger method you want, and finally save the configuration to generate the configuration code.
![](figures_en/1635929089445.png)
![image-20211103201047103](figures_en/irq1.png)
4. Test whether the interrupt is successfully enabled
```c
#define IRQ_TEST_PIN "p105"
void irq_callback_test(void *args)
{
rt_kprintf("\n IRQ00 triggered \n");
}
void icu_sample(void)
{
/* init */
rt_uint32_t pin = rt_pin_get(IRQ_TEST_PIN);
rt_kprintf("\n pin number : 0x%04X \n", pin);
rt_err_t err = rt_pin_attach_irq(pin, PIN_IRQ_MODE_RISING, irq_callback_test, RT_NULL);
if(RT_EOK != err)
{
rt_kprintf("\n attach irq failed. \n");
}
err = rt_pin_irq_enable(pin, PIN_IRQ_ENABLE);
if(RT_EOK != err)
{
rt_kprintf("\n enable irq failed. \n");
}
}
MSH_CMD_EXPORT(icu_sample, icu sample);
```
### WDT
1. Create WDT
![image-20211019152302939](figures_en/wdt.png)
2. When configuring WDT, it should be noted that only one WDT device is used in RT-Thread, so it is not numbered. If it is a newly created WDT device, you need to pay attention to the name field, which is `g_wdt` by default in the driver.
![image-20211019152407572](figures_en/wdt_config.png)
3. How to open WDT in ENV and [WDT interface usage instructions](https://www.rt-thread.org/document/site/#/rt-thread-version/rt-thread-standard/programming-manual/device/watchdog/watchdog)
![image-20211027183406251](figures_en/wdt_env.png)
### RTC
1. Add RTC device
![image-20211019152536749](figures_en/rtc.png)
2. When configuring RTC, it should be noted that only one RTC device is used in RT-Thread, so it is not numbered. If it is a newly created RTC device, you need to pay attention to the name field, which is `g_rtc` by default in the driver. Modify Callback to rtc_callback
![image-20211019152627412](figures_en/rtc_config.png)
3. How to open RTC in ENV and [RTC Interface Instructions](https://www.rt-thread.org/document/site/#/rt-thread-version/rt-thread-standard/programming-manual/device/rtc/rtc)
![image-20211027181550233](figures_en/rtc_env.png)
### Flash
1. Create Flash
![image-20211026105031200](figures_en/add_flash.png)
2. When configuring the Flash, it should be noted that only one flash device is used in RT-Thread, so it is not numbered. If it is a newly created flash device, you need to pay attention to the name field, which is `g_flash` by default in the driver.
![image-20211026105628706](figures_en/config_flash.png)
3. How to open Flash in ENV
![image-20211026123252310](figures_en/flash_menuconfig.png)
### SPI
1. Add an SPI peripheral port
![image-20211027180820968](figures_en/spi_add.png)
2. Configure parameters such as channel, name, Clock Phase, Clock Polarity, Callback, SPI Mode, etc. The baud rate can be modified in the code through the API, and a default value can be set here.
![img](figures_en/fsp_spi1.png)
3. Open SPI1 in Pins to configure the port pins. **Note: Do not configure the SSLx chip select pins here, the control of the chip select pins is controlled by software in the driver. **
![image-20211209162334093](figures_en/fsp_spi2.png)
4. How to open SPI in ENV and [SPI Interface Instructions](https://www.rt-thread.org/document/site/#/rt-thread-version/rt-thread-standard/programming-manual/device/spi/spi)
![image-20211027181444023](figures_en/spi_env.png)
### ADC/DAC
Create ADC/DAC
![img](figures_en/adc_dac.png)
- **ADC**
1. Configure name, unit, mode, and select the channel number to scan
![img](figures_en/adc_config.png)
2. Configure the pins corresponding to the scan channel
![img](figures_en/adc_config1.png)
3. Open the corresponding channel in menuconfig
- **DAC**
1. You need to turn off the default mode of P014 first
![img](figures_en/dac_config0.png)
2. Enable DAC0 channel
![img](figures_en/dac_config1.png)
3. Modify the channel number to 0, corresponding to DAC0
![img](figures_en/dac_config2.png)
4. Open the corresponding channel in menuconfig
### PWM(GPT)
The GPT timer can be used as a general-purpose timer in this chip, and can also be used to generate PWM signals. When it is used to generate PWM signals, the GPT timer provides a total of 10 channels gpt0 - gpt9, and each channel can be set to two output ports. The current version of the PWM driver treats each channel as a separate PWM device, each with only one channel. Users can choose to turn on any output port of a channel, or turn on both ports, but when both ports are turned on at the same time, their output waveforms will be exactly the same.
1. Add GPT device
![img](./figures_en/add_gpt1.png)
2. Configure channels
![img](./figures_en/add_gpt2.png)
The more critical configuration of GPT is shown in the figure, and the specific explanation is as follows:
1. Set ``Common`` ->``Pin Output Support`` to Enable to enable the PWM output.
2. Specify the GPT channel, and specify the name of the GPT according to the number of channels, for example, specify GPT channel 3 here, so the name of the GPT must be ``g_timer3``. And set the timer mode to PWM and specify the count value for each PWM period.
3. Set the duty cycle of the default output of the PWM channel, here is 50%.
4. Set the enable state of the two output ports under the GPT channel.
5. Here, the corresponding pins of the two output ports under the GPT channel are set.
3. Configure output pins
![img](./figures_en/add_gpt3.png)
After completing the setting of the GPT timer in the previous step, find the interface corresponding to the GPT channel output pin setting (here is GPT3) according to the figure, and set the label **1** in the figure to ``GTIOCA or GTIOCB`` , and set the corresponding output pins of the two output ports under the GPT channel at the label **2** in the figure as required.
4. Open the corresponding channel in menuconfig, [Introduction to RT-Thread's pwm framework](https://www.rt-thread.org/document/site/#/rt-thread-version/rt-thread-standard/programming-manual/device/pwm/pwm)
![image-20211103202216381](figures_en/pwm_env.png)
### CAN
1. Add CAN
![image-20211102145023112](figures_en/can.png)
2. Configure Callback as 'can0_callback' or 'can1_callback'
![image-20211102145227603](figures_en/can_callback.png)
3. Configure additional options and generate code.
4. Enable CAN using ENV. [CAN Equipment Instructions](https://www.rt-thread.org/document/site/#/rt-thread-version/rt-thread-standard/programming-manual/device/can/can)
![image-20211102145613309](figures_en/can_menuconfig.png)
### SDHI
1. Add sdhi drivers
![Add sdhi driver](figures_en/sdhi_config.png)
1. Add DMAC
![Add DMAC](figures_en/dmac_config.png)
2. Configure DMAC interrupt
![Configure DMAC interrupt](figures_en/dmac_int.png)
3. Set the SDHI interrupt and pins
![Configure SDHI](figures_en/sdhi_config1.png)
4. Turn on SDHI in ENV
![Open SDHI](figures_en/sdhi_env.png)
5. Configure DFS in ENV and add file systems such as FatFS
![Configure DFS](figures_en/sdhi_dfs.png)
6. At the command line, format the SD card with 'mkfs sd0 -t elm'
7. At the command line, mount sd0 to '/' using 'mount sd0 /elm'
8. Refer to RT-Thread DFS User Guide [Virtual File System (rt-thread.org)](https://www.rt-thread.org/document/site/#/rt-thread-version/rt-thread-standard/programming-manual/filesystem/filesystem)
### WiFi Module: [RW007 ](https://github.com/RT-Thread-packages/rw007)
1. Locate the RW007 in the package configuration and modify it to the configuration in the following figure.
![image-20211108142805319](figures_en/rw007_pkg.png)
2. The RW007 configuration for the driver is opened in menuconfig, and the SPI1 port is used by default. So you need to open the SPI1 bus.
![image-20211108142453678](figures_en/rw007_spi.png)
![image-20211213212034701](figures_en/drv_rw007.png)
3. Open [WLAN Framework](https://www.rt-thread.org/document/site/#/rt-thread-version/rt-thread-standard/programming-manual/device/wlan/wlan) in the Device Driver Framework
![image-20211108143027485](figures_en/rw007_wlan.png)
Open the NETDEV component in the network configuration:
![image-20211108143712513](figures_en/rw007_netdev.png)
Open the mempool configuration in the kernel:
![image-20211209161902884](figures_en/rw007_mempool.png)
4. Open the Add SPI peripheral port in the FSP, [How to Add SPI] (#SPI). The following figure takes the SPI1 port as an example of the configuration as follows:
![image-20211108183631379](figures_en/fsp_spi1.png)
5. RW007 has a slave-controlled INT pin that requires an IRQ channel, as shown in the following figure, the P506 is configured as follows:
![image-20211108183724282](figures_en/rw007_int.png)
6. The RESET control pin of the RW007 modifies the default configuration, where mode is set to off in RASC and controlled by RW007.
![image-20211213144108558](figures_en/rw007_reset.png)
7. When the configuration is complete, check that the necessary files are included in the MDK project
![image-20211109102232233](figures_en/rw007_mdk.png)
8. Compile the download and verify the results.
The system boots up to automatically get the information for the RW007, entering the 'wifi scan' command to scan the WiFi signal in the environment. [More WiFi Commands](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](figures_en/rw007_test.png)
Connect to a WiFi hotspot using the 'WiFi join' command:
![image-20211109104735733](figures_en/rw007_wifijoin.png)
Test the network connection using 'ping rt-thread.com':
![image-20211109104700939](figures_en/rw007_ping.png)
This tutorial translated by [Josh Zou](https://github.com/Firmament-Autopilot)
\ No newline at end of file
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册