1# BSP Peripheral Driver Tutorial of RA Series
2
3## 1. Introduction
4
5This 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.
6
7The main contents are following:
81. How to use more onboard resources on the development board
92. How to use more on-chip resources
103. How to add more on-chip resource options
11
12## 2. Prerequisites
13
14- Learn how to use the ENV tool, refer to: [RT-Thread env programming  manual](https://www.rt-thread.org/document/site/#/development-tools/env/env)
15- Familiar with the use of the [FSP](https://www2.renesas.cn/jp/zh/software-tool/flexible-software-package-fsp)  configuration tool
16
17## 3. How to Use More Peripheral Resources
18
19There 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.
20
21### 3.1 Open The Configuration Tool
22
23Open the menuconfig configuration window in the BSP directory.
24
25![image-20220218162910778](figures_en/menuconfig_ra6m4cpk.png)
26
27The configuration window that opens is as follows:
28 ![config1](figures_en/config1.png)
29
30Move 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.
31
32### 3.2 Enter The Hardware Driver Configuration Menu
33
34There 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.
35
36![Hardware driver configuration menu](figures_en/config2.png)
37
38### 3.3 Enable The SPI Flash Option in The Onboard Peripheral Configuration Menu
39
40![image-20220218163357420](figures_en/menuconfig_spi.png)
41
42![image-20220218163714429](figures_en/menuconfig_spi1.png)
43
44
45
46### 3.4 Save and Exit
47
48Move the cursor to the right to select Save and press Enter, then press Esc to exit the configuration tool.
49
50![Save and exit](figures_en/save.png)
51
52### 3.5 Generate MDK5 Project
53
54Enter the command `scons --target=mdk5` to regenerate the MDK5 project.
55
56![image-20220218164532436](figures_en/scons_mdk5.png)
57
58### 3.6 Add SPI Peripheral to FSP
59
60![image-20220218171841353](figures_en/fsp_spi.png)
61
62![image-20220218172446068](figures_en/fsp_spi1.png)
63
64Configure 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. **
65
66Configuration completes, save and exit FSP.
67
68![image-20220218174145848](figures_en/fsp_spi2.png)
69
70### 3.7 Test Verification
71Back 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.
72
73![image-20220218174811328](figures_en/mdk_build.png)
74
75After the compilation is successful, click the debug button to download and enter the debug page.
76
77![image-20220218175442360](figures_en/mdk_build1.png)
78
79### 3.8 Check Execution Result
80After the program runs, enter the command `list_device` to see the bus device named spi1, and the SPI1 bus is ready to use.
81
82![image-20220218175926965](figures_en/run_spi1.png)
83
84## 4. Summarize
85This 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 )
86
87When 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.
88
89
90This tutorial translated by [Josh Zou](https://github.com/Firmament-Autopilot)