How to Build and Run RTI Connext DDS Micro on a Microcontroller
Written by Jesus Checa Hidalgo
December 21, 2017
As you might know, we ship a buildable source for RTI Connext DDS Micro so you can build it for your own architecture. In the past few months, we have noticed that customers are interested in building our product for microcontrollers without a Memory Management Unit (MMU), and they’re using a uClibc-based OS. The purpose of this post is to support this expressed need and illustrate how to port RTI Connext DDS Micro to uCLinux with relatively few changes. The development board that we will use in this practical example is STM32F769I-DISCO. You should be able to extrapolate it to any other board by knowing your toolchain. You can even extrapolate it to any other OS that uses uClibc!
Let’s get started.
Enabling Multithreading Support
In order to work with RTI Connext DDS Micro, you will need support for pthreads library. Make sure to enable it in your uCLinux OS. The uClibc included in codesourcery toolchain does not have posix threads support. For our board, Emcraft implemented it and shipped it with their board support package. You will need access to their cross development environment. Unpack it in any folder you want (we will call it <cross-dev-dir> here), and follow the instructions in the EMCraft web link provided.
After following the steps, you should find the libs (including pthread) in the following folder:
And the header files in this one:
Finally, you should have the toolchain in:
And the binaries (gcc, g++, gdb…):
You can run the ACTIVATE.sh script provided by Emcraft or just add <cross-dev-env-dir>/tools/arm-2010q1/bin to your path. After that, you can build your threaded application with the following line:
arm-uclinuxeabi-gcc pthreadapp.c -o pthreadapp \
-I <cross-dev-dir>/A2F/root/usr/include \
-mthumb -march=armv7 -mfix-cortex-m3-ldrd \
-L <cross-dev-dir>/A2F/root/usr/lib -pthread
Compile Static Micro Libraries
- Get the cross development and toolchain, and install them as explained in *Enabling multithreading support*.
- Make sure to have
<cross-dev-dir>/tools/arm-2010q1/binin your PATH.
- Get the buildable sources for Micro. Unpack them in a different dir. We will work in the
<buildable_source_folder>/source/unix/directory, so all paths will part from there.
resource/cmake/cmake_module.txtfile with this patch file. This allows us to not compile dynamic libraries since uCLinux does not support dynamic linking. To patch the file, copy the
cmake_modules.txt.patchto resource/cmake/ and run the following command:
patch < cmake_module.txt.patch
- Configure the target architecture. To do so you will need two files:
- Implement the necessary code changes:
- In src/osapi/posix/posixHeap.c (OSAPI_Heap_allocate_buffer() func): Replace malloc_usable_size() with the RTI_UINT32 size variable.
- In src/osapi/posix/posisSystem.c (OSAPI_SystemPosix_timer_thread() func):
Replace clock_nanosleep() calls with nanosleep() function. Leave only the last two arguments in the call to nanosleep.
- In src/osapi/posix/posix/posixThread.c (OSAPI_Thread_sleep() func):
The same as in b
Note: you can also avoid errors in 6.b and 6.c by adding the line ADD_DEFINITIONS(-DUSE_TIMER_THREAD_SLEEP) to the uCLinux.tc file downloaded in step 5.a
- (From <buildable_source_folder>/source/unix) Run the rtime_make script:
--target uCLinux \
--name armSTM32uCLinuxgcc4.4.1 \
-G "Unix Makefiles" \
Note that you can use
--config Debugto build the corresponding libs.
- You should find the built libraries in <buildable_source_folder>/lib/armSTM32uCLinuxgcc4.4.1 (or the lib name you chose)
Compile and run a DDS publisher/subscriber application
Currently there isn’t any support for multicast in this board, so you will need to disable multicast transport. To do it, add the following to the qos settings before creating the participant:
Then you only have to edit the makefile for your application, to use the correct compiler, and the right flags, headers, and includes. You will have to use the cross development environment folder. Add the following to your makefile:
- Header files: add the folder
- Library files: add the folder:
- Compiler flags:
-mthumb -march=armv7 -mfix-cortex-m3-ldrd
As a simple test, we will use the shipped HelloWorld_dpde example with a properly-modified Makefile. To avoid hardcoding paths, it’s assumed that you will put the cross development environment path into an environment variable called CDE_DIR. Also include the arm-uclinuxeabi-gcc in your PATH, and set RTIMEHOME and RTIMEARCH as usual. You can find the modified Makefile here.
That’s it! For more information and additional tutorials head on over to the RTI Community. If you’re up for some more fun, I suggest you visit RTI Labs and take one of our experimental projects for a test drive.