FreeRTOS for Renesas RX113 (RX100)
Supporting GCC, IAR and Renesas compilers
[RTOS Ports]


Renesas RX113 RSK


Introduction

This page documents the RTOS demo applications that targets the Renesas RX113 family of microcontrollers.

Three projects are provided:

  1. An e2studio project that uses the GCC compiler.

  2. An e2studio project that uses the Renesas compiler.

  3. An IAR Embedded Workbench project that uses the IAR compiler.

All three projects include build options that allow the creation of a simple blinky demo or a comprehensive demo, and target the RX113 RSK (Renesas Start Kit) evaluation board. The comprehensive demo includes a command line interface implemented with FreeRTOS+CLI.



IMPORTANT! Notes on using the RX113 RTOS demo projects

Please read all the following points before using this RTOS port.

  1. Source Code Organisation
  2. The Demo Application
  3. RTOS Configuration and Usage Details
See also the FAQ My application does not run, what could be wrong?



Source Code Organisation

The FreeRTOS download contains the source code for all the RTOS ports, so contains lots more files than are required by the RX113 projects. See the Source Code Organization section of this website for more information.

The IAR project is called RTOSDemo.eww, and is located in the /FreeRTOS/Demo/RX100_RX113-RSK_GCC_e2studio_IAR directory.

The e2studio projects have the usual Eclipse project name .project. The project that uses the GCC compiler is also located in the /FreeRTOS/Demo/RX100_RX113-RSK_GCC_e2studio_IAR directory, and the project that uses the Renesas compiler is located in the /FreeRTOS/Demo/RX100_RX113-RSK_Renesas_e2studio directory. These are the directories that must be selected when importing the projects into the e2studio Eclipse workspace.



Building and Running the Renesas RX113 RTOS Demo

The RTOS demo projects can be configured to build either a simple blinky project, or a comprehensive test and demo project. The constant mainCREATE_SIMPLE_BLINKY_DEMO_ONLY, which is defined at the top of main.c, is used to switch between the two. The comprehensive project is created when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0. The simple demo is created when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1.

The demos use an LED and the UART to USB converter built onto the RSK development board, so no hardware set up is required.


Building with e2studio (GCC and Renesas compilers)

Note: Some of the C source files built by the e2studio projects are included in the project using a project relative path, so the project will fail to build if the FreeRTOS directory structure has been altered from that provided in the official .zip file download.
  1. Start the e2studio Eclipse IDE, and either create a new or select an existing workspace when prompted.

  2. Select "Import" from the IDE's "File" menu. The dialogue box shown below will appear. Select "General->Existing Project into Workspace", as shown below.

    Importing the RX113 project into the e2studio Eclipse IDE
    The dialogue box that appears when "Import" is first clicked


  3. In the next dialogue box, select /FreeRTOS/Demo/RX100_RX113-RSK_GCC_e2studio_IAR as the root directory if you are using the GCC compiler, or /FreeRTOS/Demo/RX100_RX113-RSK_Renesas_e2studio if you are using the Renesas compiler.


  4. Make sure the RTOSDemo project is checked in the "Projects" area, and that the Copy Projects Into Workspace check box is not checked, before clicking the Finish button (see the image below for the correct check box states).

    Selecting the RTOS source code when importing into Eclipse CDT
    Make sure RTOSDemo is checked, and "Copy projects into workspace" is not checked


  5. Open main.c and locate the mainCREATE_SIMPLE_BLINKY_DEMO_ONLY definition, which is near the top of the file. Set mainCREATE_SIMPLE_BLINKY_DEMO_ONLY to 1 to build the simply blinky style (starter) project. Set mainCREATE_SIMPLE_BLINKY_DEMO_ONLY to 0 to build the comprehensive test and demo application.

  6. Select "Build All" from the e2studio Eclipse "Project" menu to build the demo project, and wait for the build to complete.

  7. Ensure the E1 debug adapter (which comes with the RSK starter kit) is connected between the RX113 RSK board and the computer running e2studio. If you configure the launch configurations as per the images below then there is no need for a separate power supply.

  8. Select "Debug Configurations" from the Eclipse "Run" menu to configure a launch configuration that can be used to program the microcontroller flash memory, and start a debug session. Configure the debug launch configuration as shown in the images below.



    Click images to enlarge


Demo Application Functionality

The simply blinky example

The blinky example is built when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1 in main.c. When this is done, main() calls main_blinky():


The comprehensive test and demo application

RTOS CLI The comprehensive example is created when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0 in main.c. When this is done, main() calls main_full():



RTOS Configuration and Usage Details


RX113 RTOS port specific configuration

Configuration items specific to this demo are contained in /FreeRTOS/Demo/RX100_RX113-RSK_GCC_e2studio_IAR/src/FreeRTOSConfig.h for the IAR and GCC projects, and /FreeRTOS/Demo/RX100_RX113-RSK_Renesas_e2studio/src/FreeRTOSConfig.h for the Renesas compiler project. The constants defined in these files can be edited to suit your application. In particular - The RX100 port layer #defines 'BaseType_t' to 'long'.


Writing interrupt service routines (ISRs)

Interrupts can be written using the standard compiler syntax. Examples for all three supported compilers are provided below.

Often an ISR wants to cause a context switch so the task that is returned to when the ISR completes is different to the task that the ISR originally interrupted. This would be the case if the ISR caused a task to unblock, and the unblocked task had a priority above that of the task that was already in the Running state. This can be achieved by calling portYIELD_FROM_ISR(), which takes a single parameter. The parameter must be 0 if a context switch is not required, or non-zero if a context switch is required. portYIELD_FROM_ISR() is used in the examples below.

/* Pragma used to install the interrupt.  The 'enable' used in the pragma
tells the compiler to enable interrupts before executing the user code. */
#pragma interrupt ( Excep_PERIB_INTB128( vect = 128, enable ) )

/* Function definition. */
void Excep_PERIB_INTB128( void )
{
long lHigherPriorityTaskWoken;

    /* Interrupts are already enabled here.  See comment above. */

    /* vTaskNotifyGiveFromISR() is an interrupt safe FreeRTOS function.  It is
    assumed the task handle has already been stored.  If notifying the task
    unblocks the task, and the task that is unblocked has a priority above the
    priority of the currently executing task, then the lHigherPriorityTaskWoken
    parameter will get set to pdTRUE inside the vTaskNotifyGiveFromISR()
    function. */
    vTaskNotifyGiveFromISR( xTask, &lHigherPriorityTaskWoken );
    portYIELD_FROM_ISR( lHigherPriorityTaskWoken );
}
An example interrupt service routine using the Renesas compiler syntax


/* Pragma used to install the interrupt.  */
#pragma vector = VECT_TMR0_CMIA0

/* Function definition. */
__interrupt void vT0_1_InterruptHandler( void )
{
long lHigherPriorityTaskWoken;

    /* Unlike when using the Renesas compiler, interrupts must be explicitly
    re-enabled inside the interrupt service routine. */
    __enable_interrupt();

    /* vTaskNotifyGiveFromISR() is an interrupt safe FreeRTOS function.  It is
    assumed the task handle has already been stored.  If notifying the task
    unblocks the task, and the task that is unblocked has a priority above the
    priority of the currently executing task, then the lHigherPriorityTaskWoken
    parameter will get set to pdTRUE inside the vTaskNotifyGiveFromISR()
    function. */
    vTaskNotifyGiveFromISR( xTask, &lHigherPriorityTaskWoken );
    portYIELD_FROM_ISR( lHigherPriorityTaskWoken );
}
An example interrupt service routine using the IAR compiler syntax


/* The function prototype uses the interrupt attribute.  The then function
must be manually inserted into the interrupt vector table. */
static void vT0_1_InterruptHandler( void ) __attribute__((interrupt));

/* Function definition. */
void Excep_PERIB_INTB128( void )
{
long lHigherPriorityTaskWoken;

    /* Unlike when using the Renesas compiler, interrupts must be explicitly
    re-enabled inside the interrupt service routine. */
    __asm volatile( "SETPSW	I" );


    /* vTaskNotifyGiveFromISR() is an interrupt safe FreeRTOS function.  It is
    assumed the task handle has already been stored.  If notifying the task
    unblocks the task, and the task that is unblocked has a priority above the
    priority of the currently executing task, then the lHigherPriorityTaskWoken
    parameter will get set to pdTRUE inside the vTaskNotifyGiveFromISR()
    function. */
    vTaskNotifyGiveFromISR( xTask, &lHigherPriorityTaskWoken );
    portYIELD_FROM_ISR( lHigherPriorityTaskWoken );
}
An example interrupt service routine using the GCC compiler syntax


Generating the RTOS tick interrupt

FreeRTOS requires exclusive use of a timer that is capable of generating the tick interrupt - but it is up to the application writer to define which timer is used. To do this, the application must define a function called vApplicationSetupTimerInterrupt() that configures a timer to generate an interrupt at the frequency specified by the configTICK_RATE_HZ setting in FreeRTOSConfig.h, then install the RTOS tick interrupt handler in the corresponding location within the interrupt vector table.

When using the IAR and Renesas compilers the RTOS tick handler is installed simply by defining configTICK_VECTOR to the appropriate vector number in FreeRTOSConfig.h.

When using the GCC compiler the RTOS tick handler and RTOS software interrupt handler must be manually added to the appropriate vectors in the vector table definition. The RTOS tick handler is called vPortTickISR(), and the RTOS software interrupt handler is called vPortSoftwareInterruptISR(). See the source file vector_table.c in the GCC project for an example.

It is suggested that a compare match timer is used to generate the tick interrupt, and an example implementation of vApplicationSetupTimerInterrupt() that uses compare match timer 0 is included in main.c within each RX100 demo application.


Resources used by FreeRTOS

FreeRTOS requires exclusive use of the software interrupt.


Compiler options

As with all the ports, it is essential that the correct compiler options are used. The best way to ensure this is to base your application on the provided demo application files.


Memory allocation

Source/Portable/MemMang/heap_4.c is included in the RX113 demo application project to provide the memory allocation required by the RTOS kernel. Please refer to the Memory Management section of the API documentation for full information.


Miscellaneous

Note that vPortEndScheduler() has not been implemented.