MCUXpressoIDE Tutorial

../_images/nxp_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 the MCUXpressoIDE tool.

This project has been tested on the FRDM-MCXN947 board with MCUXpressoIDE 24.12, FreeRTOS v11.0.1 and LwIP v2.2.1. Check Supported platforms for more information.

Note

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

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

../_images/frdm_mcxn947.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 MCUXpressoIDE project that uses the Safe DDS library.

Start by importing the lwip_dhcp_freertos_cm33_core0 SDKExample in MCUXpressoIDE for the target device, and then follow the steps below in the order presented to ensure the project is set up correctly.

1. Convert to C++ project

To convert the project to a C++ project, follow these steps:

  • In the Project Explorer, right-click on the project and select New > Other > C/C++ > Convert to a C/C++ Project.

  • Move to the project properties, navigate to C/C++ Build > Settings > MCU C++ Linker > Managed Linker Script, and set the following parameters:

    • Check Manage linker script.

    • Set library to NewlibNano(nohost).

  • Under C/C++ Build > Settings > MCU C++ Compiler > Includes add the same include paths as the C compiler.

  • Under C/C++ Build > Settings > MCU C++ Compiler > Preprocessor add the same preprocessor definitions as the C compiler.

Note

Consider directly editing the generated .cproject file to add the include paths and preprocessor definitions for the C++ compiler.

2. Configure FreeRTOS for Safe DDS

To configure FreeRTOS memory management, which for this example is set to use the heap_3.c memory management scheme, move to the project properties, navigate to C/C++ Build > Settings > MCU C++ Linker > Managed Linker Script and change Heap Size to 0x10000 (65 KB).

3. Configure LwIP for Safe DDS

To configure LwIP, firstly move to the project properties, navigate to C/C++ Build > Settings > MCU C++ Compiler > Includes, and add lwip/src/include/compat/posix to the include paths.

Then, define the following parameters in the source/lwipopts.h LwIP configuration file:

  • Configure PBUF_POOL_BUFSIZE to MTU size. For the board used in this example, the MTU size is 1500.

  • By default, Safe DDS will use UDP multicast operation, so LWIP_IGMP and SO_REUSE shall be enabled.

  • By default, Safe DDS might require a send operation to be blocking so LWIP_SO_SNDTIMEO shall be enabled.

4. 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, i.e.: Safe-DDS.

  • Navigate to the MCUXpressoIDE 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 + LwIP application on a MCUXpressoIDE environment.

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

  • Move to the project properties and navigate to C/C++ Build > Settings > MCU C++ Compiler > Includes.

  • 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_mcuxpressoide folder.

  • Add the provided SafeDDSApp.cpp file to the source folder inside the application.

  • Add the provided SafeDDSApp.hpp and HelloWorldTypeSupport.hpp files to the source folder inside the application.

2. Configure the Safe DDS Task

Once all necessary files are in place, add the Safe DDS task:

  • Create a Safe DDS task when device has an assigned IP address.

  • A 3 KB Safe DDS task’s stack size shall be sufficient for Safe DDS application.

  • Call safedds_app_init function inside the task, which creates a SafeDDSApp object and spins it forever.

An example of a Safe DDS entry point could be:

// Wait until the device has an IP address
// ...

// Create a task for Safe DDS
if (sys_thread_new("safedds", safedds_task, &netif->ip_addr.addr, 3096, DEFAULT_THREAD_PRIO) == NULL)
{
    LWIP_ASSERT("main(): Task creation failed.", 0);
}

// ...

void safedds_app_init(const uint32_t, const uint32_t);
static void safedds_task(void *arg)
{
    const uint32_t ip_addr = *(uint32_t *)arg;
    const uint32_t port = 8000;

    safedds_app_init(ip_addr, port);
}

Running the application

Build the application in Release mode 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: 4
[DW: 16777217] Message: Hello World from MCXN947! with index: 1
[DW: 16777217] Message: Hello World from MCXN947! with index: 2
[DW: 0] Message: HelloWorld with index: 5
[DW: 16777217] Message: Hello World from MCXN947! with index: 3
[DW: 16777217] Message: Hello World from MCXN947! with index: 4
[DW: 0] Message: HelloWorld with index: 6
[DW: 16777217] Message: Hello World from MCXN947! with index: 5
[DW: 16777217] Message: Hello World from MCXN947! with index: 6
[DW: 0] Message: HelloWorld with index: 7
[DW: 16777217] Message: Hello World from MCXN947! with index: 7
[DW: 16777217] Message: Hello World from MCXN947! with index: 8