1# RA Series Uses FSP to Configure Peripheral Drivers 2 3## 1. Preparation 4 5### 1.1 Add custom command to start FSP in MDK 6 71. Open MDK, select “Tools -> Customize Tools Menu…” 82. Click the “new” icon to add a custom command: RA Smart Configurator 93. 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) 104. Enter parameter in Initial Folder: $P 115. Enter parameter in Arguments: --device $D --compiler ARMv6 configuration.xml 126. Click OK to save command 13 14 15 167. Click the added command "Tools -> RA smart Configurator", **Open the configuration tool**: RA Smart Config 17 18 19 20PS:The above related operations can also be found in the FSP documentation. 21 22FSP Document:https://www2.renesas.cn/jp/zh/software-tool/flexible-software-package-fsp#document 23 24### 1.2 Precautions 25 26#### 1.2.1 FSP Version selection 27 28The 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**. 29 30**Be sure to check whether the FSP version, Board, Device configuration items are correct before using RASC. ** 31 32 33 34#### 1.2.2 Update project configuration 35 36After 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. 37 38 39 40## 2. Add and configure peripherals using FSP 41 42**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. ** 43 44### UART 45 46How to add a UART port peripheral configuration? 47 481. Select the Stacks configuration page, click New Stack to find the UART. 49 50 512. 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. 52 53 54### GPIO Interrupt 55 56How to add an IO interrupt? 57 581. 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. 59 60 61 622. Open ICU interrupt channel IRQ00 63 64 65 663. 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** to be the same label. Select the trigger method you want, and finally save the configuration to generate the configuration code. 67 68 69 70 71 724. Test whether the interrupt is successfully enabled 73 74 ```c 75 #define IRQ_TEST_PIN "p105" 76 void irq_callback_test(void *args) 77 { 78 rt_kprintf("\n IRQ00 triggered \n"); 79 } 80 81 void icu_sample(void) 82 { 83 /* init */ 84 rt_uint32_t pin = rt_pin_get(IRQ_TEST_PIN); 85 rt_kprintf("\n pin number : 0x%04X \n", pin); 86 rt_err_t err = rt_pin_attach_irq(pin, PIN_IRQ_MODE_RISING, irq_callback_test, RT_NULL); 87 if(RT_EOK != err) 88 { 89 rt_kprintf("\n attach irq failed. \n"); 90 } 91 err = rt_pin_irq_enable(pin, PIN_IRQ_ENABLE); 92 if(RT_EOK != err) 93 { 94 rt_kprintf("\n enable irq failed. \n"); 95 } 96 } 97 MSH_CMD_EXPORT(icu_sample, icu sample); 98 ``` 99 100### WDT 101 1021. Create WDT 103 104 105 1062. 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. 107 108 109 1103. 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) 111 112 113 114### RTC 115 1161. Add RTC device 117 118 119 1202. 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 121 122 123 1243. 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) 125 126 127 128### Flash 129 1301. Create Flash 131 132 133 1342. 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. 135 136 137 1383. How to open Flash in ENV 139 140 141 142### SPI 143 1441. Add an SPI peripheral port 145 146 147 1482. 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. 149 150 151 1523. 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. ** 153 154 155 156 1574. 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) 158 159  160 161### ADC/DAC 162 163Create ADC/DAC 164 165 166 167- **ADC** 168 1691. Configure name, unit, mode, and select the channel number to scan 170 171 172 1732. Configure the pins corresponding to the scan channel 174 175 176 1773. Open the corresponding channel in menuconfig 178 179- **DAC** 180 1811. You need to turn off the default mode of P014 first 182 183 184 1852. Enable DAC0 channel 186 187 188 1893. Modify the channel number to 0, corresponding to DAC0 190 191 192 1934. Open the corresponding channel in menuconfig 194 195### PWM(GPT) 196 197The 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. 198 1991. Add GPT device 200 201 202 2032. Configure channels 204 205 206 207The more critical configuration of GPT is shown in the figure, and the specific explanation is as follows: 208 209 1. Set ``Common`` ->``Pin Output Support`` to Enable to enable the PWM output. 210 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. 211 3. Set the duty cycle of the default output of the PWM channel, here is 50%. 212 4. Set the enable state of the two output ports under the GPT channel. 213 5. Here, the corresponding pins of the two output ports under the GPT channel are set. 2143. Configure output pins 215 216 217 218 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. 219 220 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) 221 222 223 224### CAN 225 2261. Add CAN 227 228 229 2302. Configure Callback as 'can0_callback' or 'can1_callback' 231 232 233 2343. Configure additional options and generate code. 235 2364. 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) 237 238 239 240### SDHI 241 2421. Add sdhi drivers 243 244 245 2461. Add DMAC 247 248 249 2502. Configure DMAC interrupt 251 252 253 2543. Set the SDHI interrupt and pins 255 256 257 2584. Turn on SDHI in ENV 259 260 261 2625. Configure DFS in ENV and add file systems such as FatFS 263 264 265 2666. At the command line, format the SD card with 'mkfs sd0 -t elm' 267 2687. At the command line, mount sd0 to '/' using 'mount sd0 /elm' 269 2708. 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) 271 272### WiFi Module: [RW007 ](https://github.com/RT-Thread-packages/rw007) 273 2741. Locate the RW007 in the package configuration and modify it to the configuration in the following figure. 275 276 277 2782. 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. 279 280 281 282 283 2843. 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 285 286 287 288Open the NETDEV component in the network configuration: 289 290 291 292Open the mempool configuration in the kernel: 293 294 295 2964. 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: 297 298 299 3005. RW007 has a slave-controlled INT pin that requires an IRQ channel, as shown in the following figure, the P506 is configured as follows: 301 302 303 3046. The RESET control pin of the RW007 modifies the default configuration, where mode is set to off in RASC and controlled by RW007. 305 306 307 3087. When the configuration is complete, check that the necessary files are included in the MDK project 309 310 311 3128. Compile the download and verify the results. 313 314The 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) 315 316 317 318Connect to a WiFi hotspot using the 'WiFi join' command: 319 320 321 322Test the network connection using 'ping rt-thread.com': 323 324 325 326 327 328 329 330This tutorial translated by [Josh Zou](https://github.com/Firmament-Autopilot)