I'm evaluating the Renesas RX65N MCU EV Kit. In this post: A Blinky, with the GCC toolchain. It's not a real blinky - it's a switchy. The User LED is on when the User Button is pressed. |
Create the Project
In the previous post, I used the Renesas CCRX toolchain to create a project in e2 Studio. Many things are similar when using the GCC tools.
This post expects that you did the activities in the previous blog (e.g.: that you downloaded the evaluation board definition in the configurator's board tab).
File -> New C/C++ Project -> Renesas RX -> GCC for Renesas RC C/C++ Executable Project -> Next
Name your project -> Next.
Toolchain: GCC for Renesas RX, latest installed version
Select the correct tatget for this board (for navigation, see the previous post).
Set the E2 Lite (RX) debugger and create a release configuration too. -> Next
Enable Use Smart Configurator -> Finish.
Configure the Project
In the configurator window that opens, set the board to the Envision kit. Then open the Components tab.
The New Project wizard has created one compinent.
That's the upbringing module that brings you from power-up to main() with a correctly configured controller.
Now we add two modules. One to configure the GPIO pins, and one that gives us the pin definitions anf GPIO API.
On the Components tab, press the + button.
This brings up a list of available components.
The first time, we have to do two steps (Renesas gurus may chime in here to refine what needs to be selected/configured).
Change the IDE configuration to allow that blocked modules are shown.
Configure General Settings -> Enable Allow blocked FIT modules to be displayed -> Apply and Close
Then add all components . This takes a long time.
Download more software components -> Disable Show RX Driver Package only -> Select All -> Download.
Go for a coffee.
Once they are added, select these two:
- Ports: to enable the ports and pins, and set the direction
- r_gpio_rx: to add the pin header file and gpio APIs.
Cick Finish.
The user switch SW2 on the evaluation board is assigned to Port 0 bit 5, the LED2 blue led to Port 7 bit 0.
We'll set these pins as I/O functional inputs and outputs.
Select the Config_PORT module and enable PORT0 and PORT7. 2 new tabs appear.
Select tab PORT0 and set P05 to In.
Select PORT7 and set P00 to Out.
In the MCU package view, these pins have changed colour and definition:
In the Pin tab, they have also changed (here P70 (port 7 pin 0) as example):
That's it. The r_gpio_rx component does not need to be maintained.
Save the configuration file, then Generate Code.
Write the C Code
Activate the IDE's C/C++ perspective.
The configurator has created a project structure. Take some time to familiarise.
Then open the main file, RX65_blinky.c.
Let's add the header file for the driver code, and the pin definitions:
#include "r_gpio_rx_if.h" /* Contains prototypes for the GPIO driver */ #define SW_2 (GPIO_PORT_0_PIN_5) #define LED_2 (GPIO_PORT_7_PIN_0)
Then write a very simple main() loop.
It will check if the button state has changed, and if yes, update the LED state.
void main(void) { gpio_level_t lastLevel = GPIO_LEVEL_LOW; do { gpio_level_t level = R_GPIO_PinRead(SW_2); if (level != lastLevel) {user button on the lft of the board. lastLevel = level; R_GPIO_PinWrite ( LED_2, level); } } while (1); }
Build and Debug
See the previous post for the instructions. It's identical for this project.
If you get a failure at startup, you mmay have skipped the step in that section to set the Power and Frequency options in the debug configuration.
Once the code is running, the blue led next to the USB connector will be on when you push the