I'm evaluating the Renesas RX65N MCU EV Kit. In this post: A Blinky, with the FreeRTOS managing the clock. |
Create the Project
As usual, use Blog #1 to create the project.
The only extra action is to select FreeRTOS while going through the project creation steps:
First, let's add an RTOS task that will blink the LED.
In the Smart Configurator, select the correct board, then go to Components.
Select FreeRTOS_Object, and in the Task tab, push the button.
Enter
In a few steps, when we generate the code from the configurator, this will create a file /src/frtos_skeleton/vBlinkTask.c, where we'll write the blink code.
Because we need the RX65 GPIO registers, we need to add the r_gpio_rx block in the configurator. Use the dd Component button to add this (see also blog post 2a for a step-by-step guide for this).
When using FreeRTOS projects, it seems that the "Ports" SmartConfig module can't be used.
That's the one that sets in- and outputs. No worries. We'll set the LED2 pin on our board to output mode in our RTOS task.
Now it's time to save the configuration and generate the code.
Let's first modify the main task now. It needs to be modified for each project.
In the Renesas port, this task can be used to manually create tasks.
But we will not do that because our task is started by the kernel (we selected that earlier in the configurator).
In the main_task function, delete the while(1) placeholder.
If you forget to do this, your project will forever loop there, without giving control to the FreeRTOS scheduler.
The FreeRTOS Blinky Task
The main goal of this project is to create a task that will be called every so many ms and toggle LED2.
The configuarator has created /src/frtos_skeleton/vBlinkTask.c for us.
We'll adopt that file. Take care to always put your code between the placeholders in that file.
/* Start user code for *****. Do not edit comment generated here */ // your code here /* End user code. Do not edit comment generated here */
This will take care that the next time you generate from the configurator, your code is preserved.
Anything you put outside these comment pairs will be lost.
First, let's include the gpio register definitions and define LED2:
/* Start user code for import. Do not edit comment generated here */ #include "r_gpio_rx_if.h" /* Contains prototypes for the GPIO driver */ #define LED_2 PORT7.PODR.BIT.B0 /* End user code. Do not edit comment generated here */
Then, write the main task (again, stay within the comments to preserve your code.
Anything before the for(;;) construct will run once, at the first run of the task.
This is where we define the pin for the LED as output.
The code in the for() loop itself will be activated every 1000 ms by the FreeRTOS task manager.
That's where we toggle LED2.
void vBlinkTask(void * pvParameters) { /* Start user code for function. Do not edit comment generated here */ // initialise /* ---- Set the PORT7.PODR register ---- */ PORT7.PODR.BYTE |= 0x01; /* high output pin: P70 */ /* ---- Set the PORT7.PDR register ---- */ PORT7.PDR.BYTE |= 0x01; /* output pin: P70 */ for(;;) { /* Toggle LED2 with timer tick */ LED_2 = ~LED_2; // Toggle LED2 with each callback vTaskDelay(1000); } /* End user code. Do not edit comment generated here */ }
Make and Run. That's it. Have fun. The e2 studio project is attached.
The FreeRTOS configuration modules from Renesas require that you use the CC-RX toolchain. FreeRTOS itself should work on the Renesas with GCC, however. I haven' tried this. |