Skip to content

How to create RL78 FreeRTOS with Code Generator

Shunichiro Nakamura edited this page Jul 13, 2026 · 23 revisions

Renesas/FreeRTOS-Kernel wiki


How to create projects for a microcontroller supported by the Code Generator

The procedure for creating a FreeRTOS project for an RL78 microcontroller supported by the Code Generator is described on this page.

Environment for the Procedure

In the procedure for creation, a project for the following environment is given as an example.

Development Environment

Item Tool Name (Version)
Board RL78/G13 (R5F100LE) Target Board
IDE e2 studio (2026-04.2)
Compiler CC-RL (V1.16.00)
Hardware debug configuration E2 emulator Lite (on-chip debugging functions are used)

Operating Environment

Item Specifications
Main system clock
  • High-speed on-chip oscillator
  • Frequency: 32 MHz
FreeRTOS V11.1.0
(Can be obtained from Blinky Demo (R20AN0819EJ0100))
System timer
  • 12-bit interval timer (IT)
    • Clock source: fIL 15 kHz
  • RTOS tick frequency: 1 tick/ms
FreeRTOS memory allocation implementation heap_4
User application
  • The Blinky Demo is in use
    • LED1 blinks on and off at 1-second intervals
    • LED2 blinks on and off at 2-second intervals

✅ Note:

  • A demonstration program, the Blinky Demo, includes FreeRTOS which includes the portable layer for CC-RL. Download this before creating a project.
  • The items of the operating environment, which are not referred to in the above table, conform with the specifications of the Blinky Demo.
  • Customize the operating environment to suit the requirements of the user system.
  • For details on the RL78/G13 microcontroller or peripheral functions, refer to the RL78/G13 User’s Manual: Hardware.

Creation Procedure

  1. Creating a bare-metal project

    1. After invoking e2 studio, select File menu - New - Renesas C/C++ Project - Renesas RL78 to open the wizard for creating a new project.

    2. Select Renesas CC-RL C/C++ Executable Project, enter the project name in <Project name>, and select the Target Device to be used. When using the RL78/G13 target board, select Custom for Target Board because no specific settings have been prepared and select R5F100LE as the Target Device.
      After that, click on Next.

    3. Select the Use Peripheral Code Generator checkbox and click on Finish.

      ✅ Note:
      For an RL78 microcontroller that the Smart Configurator does not support, use the Code Generator (Use Peripheral Code Generator function), which only controls code generation.

    4. Change the C language standard to C99.
      Right-click on <project name> in Project Explorer, select Properties - C/C++ Build - Settings then, on the Tool Settings tabbed page, select Compiler - Source - Language, and select C99 language standard for Language standard of C language.

  2. Adding FreeRTOS

    1. Add the FreeRTOS kernel for the CC-RL to the bare-metal project of the user.
      Copy the directory of the kernel of the FreeRTOS supplied with the Blinky Demo to the project.

      • From [Blinky Demo]: r20an0819xx0100-rl78/RL78/rl78g14_fpb_blinky/src/kernel
      • To [User project]: <project name>/src/kernel
    2. Exclude the examples of FreeRTOS from the targets for building.
      Right-click on the <project name>/src/kernel/examples folder in Project Explorer and select Properties - C/C++ Build - Settings, then select the Exclude resource from build checkbox.

    3. Set the include path of the common part of FreeRTOS.
      Right-click on <project name> in Project Explorer, select Properties - C/C++ Build - Settings then, on the Tool Settings tabbed page, select Compiler - Source, and add the following file path to Include file directories.

      • "${workspace_loc:/${ProjName}/src/kernel/include}"
  3. Setting the portable layer of FreeRTOS

    1. Set the portable layer for the CC-RL compiler and the memory management function as the targets for building.

      1. Start by setting portable layer as non-targets for building to simplify operations.
        Right-click on the <project name>/src/kernel/portable folder in Project Explorer and select Properties - C/C++ Build - Settings, then select the Exclude resource from build checkbox.

      2. Return the portable layer for the CC-RL compiler back as a target for building.
        Right-click on the <project name>/src/kernel/portable/Renesas/RL78 folder in Project Explorer and select Properties - C/C++ Build - Settings, then deselect the Exclude resource from build checkbox.

      3. Return the memory management function (heap_4.c) back as a target for building.
        Right-click on the <project name>/src/kernel/portable/MemMang folder in Project Explorer and select Properties - C/C++ Build - Settings, then deselect the Exclude resource from build checkbox.
        Next, right-click on the following files under the <project name>/src/kernel/portable/MemMang folder and select the Properties - C/C++ Build - Settings, then select the Exclude resource from build checkbox.

        • heap_1.c
        • heap_2.c
        • heap_3.c
        • heap_5.c

        ✅ Note:
        Since the operation of excluding targets from building cannot be performed for multiple files at the same time, files must be excluded from building one at a time.

      4. If the settings have been made correctly, the portable layer settings in Project Explorer will become as follows:

    2. Set the include path of the portable layer for the CC-RL compiler.
      Right-click on <project name> in Project Explorer, select Properties - C/C++ Build - Settings then, on the Tool Settings tabbed page, select Compiler - Source, and add the following file path to Include file directories.

      • "${workspace_loc:/${ProjName}/src/kernel/portable/Renesas/RL78}"
    3. Check the interrupt handler of the software interrupt (vector interrupt that is generated by executing a BRK instruction).
      Confirm that the vector table number of _vPortYield in <project name>/src/kernel/portable/Renesas/RL78/portasm.asm is 0x7E. (Since the vector table number of the software interrupt is 0x7E in both the RL78/G13 and RL78/G14, if portasm.asm is the file copied from the Blinky Demo, no changes are required.)

      ;   /* brk */
          _vPortYield     .VECTOR 0x7E

      ✅ Note:
      When using another microcontroller, check the vector table number of the software interrupt in the hardware manual and change it as required.

  4. Setting the system timer

    For the specifications of the system timer given as examples in this procedure, see the operating environment.

    1. Using the Peripheral Code Generator, set up the hardware related to the setting of the system timer in advance.

      ✅ Note:
      Although setting up hardware is properly a procedure that should be performed independently of the setting of the system timer, it is explained here as part of the setting of the system timer for convenience.

      1. Set the peripheral I/O redirection function.
        Double-click on Code Generator - Peripheral Functions - Clock Generator in Project Explorer to open the Pin assignment tabbed page.
        Set the peripheral I/O redirection register (PIOR) to suit the requirements of the user system and click on Fix settings.

      2. Set the clock source of the peripheral timer used for the system timer.
        Double-click on Code Generator - Peripheral Functions - Clock Generator in Project Explorer to open the Clock setting tabbed page.
        Set the frequency of the main system clock or the clock provided to the peripheral timer and related items. Specifically, set the Frequency of the High-speed OCO clock setting to 32 MHz, and set the operation clock of RTC and interval timer operation clock to 15 (fIL) kHz.

    2. Using the Peripheral Code Generator, install the driver of the peripheral timer used for the system timer.

      1. Double-click on Code Generator - Peripheral Functions - 12-Bit Interval Timer in Project Explorer.

      2. Select Used for Interval timer operation setting to enable it.
        Set 1 ms for the Interval value.

        ✅ Note:
        When using a different RTOS tick frequency, adjust the interval value according to the RTOS tick frequency.

    3. Check the interrupt handler for the system timer.
      Confirm that the vector table number of _vPortTickISR in <project name>/src/kernel/portable/Renesas/RL78/portasm.asm is 0x38. (Since the vector table number of the interrupt of the system timer (12-Bit Interval Timer) used in the operating environment is 0x38, if portasm.asm is the file copied from the Blinky Demo, no changes are required.)

      ;   /* 12bit interval timer */
          _vPortTickISR   .VECTOR 0x38

      ✅ Note:
      When using another microcontroller or peripheral timer, check the vector table number of the interrupt of the peripheral timer in the hardware manual and change it as required.

    4. Exclude the default interrupt handler generated by the Code Generator from the targets for building.

      1. Double-click on Code Generator - Peripheral Functions in Project Explorer to open the Code Generator perspective and click on Generate Code. This operation automatically generates the default interrupt handler.

      2. Right-click on the <project name>/src/r_cg_it_user.c file in Project Explorer and select Properties - C/C++ Build - Settings, then select the Exclude resource from build checkbox.

        ✅ Note:
        When using another microcontroller or peripheral timer, a different file is used for implementing the default interrupt handler.
        Though the automatically generated file is placed in src/smc_gen/general/r_cg_<function>_common_user.c by the Smart Configurator, it is placed in src/r_cg_<function>_user.c in the Code Generator (Peripheral Code Generator). Note that the directory and file name differ.

    5. Add the header files generated by the Code Generator.
      Add code to include r_cg_macrodriver.h and r_cg_it.h between the comments of /* Start user code ... and /* End user code ... in src/r_cg_userdefine.h.

      /* Start user code for function. Do not edit comment generated here */
      #include "r_cg_macrodriver.h"
      #include "r_cg_it.h"
      /* End user code. Do not edit comment generated here */
  5. Implementing FreeRTOS-related applications

    1. Make FreeRTOS settings.

      1. Copy the directory of the settings of the FreeRTOS supplied with the Blinky Demo to the project.

        • From [Blinky Demo]: r20an0819xx0100-rl78/RL78/rl78g14_fpb_blinky/src/application/config
        • To [User project]: <project name>/src/application/config
      2. Set the include path of the settings of FreeRTOS.
        Right-click on <project name> in Project Explorer, select Properties - C/C++ Build - Settings then, on the Tool Settings tabbed page, select Compiler - Source, and add the following file path to Include file directories.

        • "${workspace_loc:/${ProjName}/src/application/config}"
      3. Adjust the setting macros of src/application/config/FreeRTOSConfig.h to suit the requirements of the user system.
        For details on the setting macros, refer to the official Web page.

        ✅ Note:
        Note the heap size setting (configTOTAL_HEAP_SIZE) that is dependent on the microcontroller used or the user system requirements.

    2. Implement the hook function and kernel startup processing.

      1. Copy the directory of the startup of the FreeRTOS supplied with the Blinky Demo to the project.

        • From [Blinky Demo]: r20an0819xx0100-rl78/RL78/rl78g14_fpb_blinky/src/application/startup
        • To [User project]: <project name>/src/application/startup
      2. Set the include path for the startup of FreeRTOS.
        Right-click on <project name> in Project Explorer, select Properties - C/C++ Build - Settings then, on the Tool Settings tabbed page, select Compiler - Source, and add the following file path to Include file directories.

        • "${workspace_loc:/${ProjName}/src/application/startup}"
      3. Check the hook function.
        Implementation of the startup for the Blinky Demo (for RL78/G14) is configured to call R_IT_Start() from vApplicationSetupTimerInterrupt() in src/application/startup/freertos_user.c. It matches the system timer (12-Bit Interval Timer) used in the operating environment so that additional modifications are not necessary.

        ✅ Note:
        When using another microcontroller or peripheral timer, modify the hook function to suit the requirements of the user system.

      4. Implement the kernel startup processing.
        Change main() as follows: after calling Processing_Before_Start_Kernel() in src/application/startup/freertos_user.c, call vTaskStartScheduler(), which starts the scheduler.

        ✅ Note:
        main() is implemented in src/application/app/main.c supplied with the Blinky Demo, and is copied to the project in the "Implementing the user application" procedure described later. Therefore, main() does not yet exist in the project at this point in the procedure.

        ✅ Note:
        Processing_Before_Start_Kernel() is provided for the purpose of generating RTOS objects before the scheduler of the kernel is started. The implementation or calling of this function is arbitrary and can be changed to suit the requirements of the user system.
        Also, Processing_Before_Start_Kernel() copied from the Blinky Demo generates a task with main_task() (implemented in src/application/app/main.c) as the entry function. If you are going to use this without change, add an implementation of main_task() to the user application.

  6. Implementing the user application

    1. Copy the directory of the user application supplied with the Blinky Demo to the project.

      • From [Blinky Demo]: r20an0819xx0100-rl78/RL78/rl78g14_fpb_blinky/src/application/app
      • To [User project]: <project name>/src/application/app
    2. Set the include path of the user application.
      Right-click on <project name> in Project Explorer, select Properties - C/C++ Build - Settings then, on the Tool Settings tabbed page, select Compiler - Source, and add the following file path to Include file directories.

      • "${workspace_loc:/${ProjName}/src/application/app}"
    3. Set the LED connection pins (the P62 port pin for LED1 and P63 port pin for LED2) through the Peripheral Code Generator.
      For details on the connection pins, refer to the user’s manual for the board.

      1. Double-click on Code Generator - Peripheral Functions - Port in Project Explorer.

      2. Set P62 and P63 on the Port6 tabbed page to Out.

      3. Click on Generate Code in the Peripheral Code Generator.

      4. Modify the code related to operating the LED port pins in the source code (src/application/app/user_task.c) of the Blinky Demo to match the actual port and pin numbers.

        void vUserTask1(void *pvParameters)
        {
            ...
                // /* LED0 */
                // P4_bit.no3 ^= 1;
                /* LED1 */
                P6_bit.no2 ^= 1;
            ...
        }
        
        void vUserTask2(void *pvParameters)
        {
            ...
                // /* LED1 */
                // P4_bit.no4 ^= 1;
                /* LED2 */
                P6_bit.no3 ^= 1;
            ...
        }
    4. Exclude src/r_main.c from the targets for building. This is to avoid overlapping with main() existing in src/application/app/main.c.
      Right-click on the <project name>/src/r_main.c file in Project Explorer and select Properties - C/C++ Build - Settings, then select the Exclude resource from build checkbox.

    5. Adjust the heap size.

      1. Change configTOTAL_HEAP_SIZE in src/application/config/FreeRTOSConfig.h to 2048.

      2. Change the value of the third argument (uxStackDepth) of xTaskCreate() in src/application/app/user_task.c to 128 (respectively for "UserTask1" and "UserTask2").

        void user_task_start(void)
        {
            // xTaskCreate (vUserTask1, "UserTask1", 256, NULL, CFG_TSKPRI_USER_TASK1, &tskhdl_user_task1);
            // xTaskCreate (vUserTask2, "UserTask2", 256, NULL, CFG_TSKPRI_USER_TASK2, &tskhdl_user_task2);
            xTaskCreate (vUserTask1, "UserTask1", 128, NULL, CFG_TSKPRI_USER_TASK1, &tskhdl_user_task1);
            xTaskCreate (vUserTask2, "UserTask2", 128, NULL, CFG_TSKPRI_USER_TASK2, &tskhdl_user_task2);
        }
    6. Double-click on Code Generator - Peripheral Functions in Project Explorer to open the Code Generator perspective and click on Generate Code.
      This operation automatically generates the source code for the functions that were set in the Peripheral Code Generator.

    ✅ Note:
    When implementing an original user application, implement the tasks, peripheral drivers, and interrupt handlers. A peripheral driver made by Renesas can be added through the Peripheral Code Generator.

  7. Debug configurations

    Make the following settings according to the debug configurations shown in the development environment.

    1. Generate code for using the on-chip debugging functions in the Peripheral Code Generator.

      1. Double-click on Code Generator - Peripheral Functions - Clock Generator in Project Explorer to open the On-chip debug setting tabbed page.

      2. Select Used for On-chip debug operation setting and E2 Lite for Emulator setting.

      3. Click on Generate Code in the Peripheral Code Generator.

    2. Connect the board and debugger (E2 Lite). For the RL78/G13 target board, connect the E2 emulator Lite and board with a prescribed connector for on-chip debugging and supply power to the board.

    3. Select Run menu - Debug Configurations.

    4. Select the debug configuration profile of the project (<project name> HardwareDebug) from the left pane in the pop-up window.

    5. Select E2 Lite (RL78) in Debug hardware on the Debugger tabbed page.

    6. Select Yes in Power Target From The Emulator (MAX 200mA) on the Connection Settings tabbed page on the Debugger tabbed page.

    7. After setting the other debug configurations as required, click on Apply to fix the settings.

  8. Building and program execution

    1. Right-click on <project name> in Project Explorer and select Build Project.

    2. After building has finished successfully, start the debugger by selecting Run menu - Debug As - Renesas GDB Hardware Debugging, then execute the program.

    3. Confirm that the program is running normally.
      When the user application of the Blinky Demo is in use, LED1 and LED2 will blink on and off.

Clone this wiki locally