Renesas e2 studio Tutorial

../_images/Renesas_Electronics_logo.png

This section serves as a comprehensive guide to assist in creating and understanding the key points of a basic Safe DDS application using Renesas e2 studio.

This project has been tested on the EK-RA6M5 board with e2 studio 25.4.0, FSP v5.9.0, FreeRTOS v11.1.0 and FreeRTOS+TCP v4.2.2. Check Supported platforms for more information.

Note

This guide might require adaptations to work with a different hardware, RTOS, network stack or e2 studio version.

In order to get support please contact support@eProsima.com.

../_images/ek-ra6m5_board.png

Note

It is recommended to first read the Getting Started section to gain a better understanding of the basic concepts and terminology used in this section.

Project Configuration

This section describes how to configure an e2 studio project that uses the Safe DDS library.

1. Create a new e2 studio project

  • Create a new Renesas RA C/C++ Project in e2 studio for the target device.

  • Select C++ language, e2 studio managed build, and GNU ARM Embedded Toolchain.

  • Select Build Artifact Type as Executable, and FreeRTOS as the RTOS.

2. Configure the project for FreeRTOS and Safe DDS

To configure the project, set the following parameters in the FSP Configuration window:

  • In the BSP tab, go to the Properties menu and set RA Common > Heap size to 0x3000.

  • In the Components tab, make sure the following components are enabled:

    • Arm > CMSIS > CMSIS5 > CoreM.

    • AWS > Heaps > FreeRTOS > heap_4.

    • AWS > Libraries > FreeRTOS > BufferAllocation2.

    • AWS > Libraries > FreeRTOS_Plus > FreeRTOS_Plus_TCP.

    • AWS > RTOS > FreeRTOS > all.

    • Renesas > Middleware > all > rm_freertos_plus_tcp.

    • Renesas > Middleware > all > rm_freertos_port.

  • Create a new thread by clicking on Stacks > Threads > New Thread.

  • In the Properties menu, set a name for the thread, such as SafeDDS, and set the following parameters:

    • Common > General > Use Newlib Reentrant: Enable.

    • Thread > Stack Size: 0x2000.

    • Thread > Memory Allocation > Support Dynamic Allocation: Enable.

    • Thread > Memory Allocation > Total Heap Size: 0x7000.

  • Add a new FreeRTOS Heap 4 stack to the thread on New Stack > RTOS > FreeRTOS Heap 4.

  • Add a new FreeRTOS+TCP stack to the thread on New Stack > Networking > FreeRTOS+TCP. In the properties menu, set the following parameters:

    • Common > Network Event call vApplicationIPNetworkEventHook: Disable.

    • Common > DHCP Register Hostname: Disable.

    • Common > DHCP callback function: Enable.

    • Common > FreeRTOS_select() (and associated) API function is available: Enable.

  • Select Add Ethernet Driver > New > Ethernet (r_ether) to add the Ethernet driver to the stack. In the Properties menu, set:

    • Common > Interrupt event backward compatibility: Do not keep compatibility.

    • Module g_ether0 Ethernet (r_ether) > Buffers > Number of RX buffer: 4.

In the project properties, navigate to C/C++ Build > Settings > Tool Settings > GNU Arm Cross C++ Linker > Miscellaneous and set the following parameters:

  • Uncheck Use newlib-nano (–specs=nano.specs).

  • Check Do not use syscalls (–specs=nosys.specs).

Now the project is configured and ready to get its content generated by clicking on the Generate Project Content button in the FSP Configuration window.

3. Add a New Source Folder for Safe DDS

To add the Safe DDS library to the project follow these steps:

  • In the Project Explorer, right-click on the project and select New > Source Folder. Name the folder something like Safe-DDS.

  • Navigate to the Renesas e2 studio support package folder and run the create_package.sh script followed by the path to the Safe DDS source release folder. This script generates the required files for a FreeRTOS + FreeRTOS+TCP application on a Renesas e2 studio environment.

  • Copy the Safe DDS src and include generated folders to the folder previously created in the e2 studio project.

  • Move to the project properties and navigate to C/C++ Build > Settings > Tool Settings > GNU Arm Cross C++ Compiler > Includes > Include paths.

  • Add the path to the Safe DDS include folder.

Safe DDS application

After the project has been set up, the next step is to create a Safe DDS application:

1. Add the application files to the project

  • Navigate to the tutorial_renesas_e2studio folder.

  • Add the provided SafeDDSApp.cpp, SafeDDSApp.hpp and HelloWorldTypeSupport.hpp files to the src folder inside the project root.

2. Configure the Safe DDS Task

Once all necessary files are in place, modify the Safe DDS task in the file located in src that has the name of the Safe DDS thread.

  • Make the Safe DDS task wait until the device has an assigned IP address.

  • Since FreeRTOS+TCP does not support listening on multicast, initial peers need to be configured for the discovery process: To do so, set a locator with the IP address and port of the remote peer.

  • Then call safedds_app_init function with the local IP address, local port and the remote locator.

  • safedds_app_init will create a SafeDDSApp object and spin it forever.

An example of a Safe DDS entry point could be:

void safedds_task_entry(void *argument)
{
    // Wait until the device has an IP address
    // ...

    const uint32_t ip_addr = xNd.ulIPAddress;

    // Create a locator for the remote peer
    transport::Locator remote_peer_locator = transport::Locator::from_ipv4({192, 168, 1, 100}, 9999);

    // Define the local port to listen on
    const uint16_t local_port = 8888;

    // Init Safe DDS app:
    safedds_app_init(ip_addr, local_port, remote_peer_locator);
}

Running the application

Build the application and flash it to the device. Run the Getting Started example in a local machine on the same network as the device. The console output should show messages similar to the following:

[DW: 0] Message: HelloWorld with index: 6283
[DW: 16777216] Message: Hello World from RA6M5! with index: 12832
[DW: 16777216] Message: Hello World from RA6M5! with index: 12833
[DW: 0] Message: HelloWorld with index: 6284
[DW: 16777216] Message: Hello World from RA6M5! with index: 12834
[DW: 16777216] Message: Hello World from RA6M5! with index: 12835
[DW: 0] Message: HelloWorld with index: 6285
[DW: 16777216] Message: Hello World from RA6M5! with index: 12836
[DW: 16777216] Message: Hello World from RA6M5! with index: 12837
[DW: 0] Message: HelloWorld with index: 6286
[DW: 16777216] Message: Hello World from RA6M5! with index: 12838
[DW: 16777216] Message: Hello World from RA6M5! with index: 12839
[DW: 0] Message: HelloWorld with index: 6287
[DW: 16777216] Message: Hello World from RA6M5! with index: 12840