This tool aims to ease the micro-ROS integration in a STM32CubeMX/IDE project.
- micro-ROS for STM32CubeMX/IDE
This package support the usage of micro-ROS on top of two different middlewares:
- eProsima Micro XRCE-DDS: the default micro-ROS middleware.
- embeddedRTPS: an experimental implementation of a RTPS middleware compatible with ROS 2. Instructions on how to use it available here.
-
Clone this repository in your STM32CubeMX project folder. A sample project can be generated with the provided
sample_project.ioc. -
Make sure that your STM32CubeMX project is using a
Makefiletoolchain underProject Manager -> Project -
Make sure that if you are using FreeRTOS, the micro-ROS task has more than 10 kB of stack: Detail
-
Configure the transport interface on the STM32CubeMX project, check the Transport configuration section for instructions on the custom transports provided.
-
Modify the generated
Makefileto include the following code before thebuild the applicationsection:####################################### # micro-ROS addons ####################################### LDFLAGS += micro_ros_stm32cubemx_utils/microros_static_library/libmicroros/libmicroros.a C_INCLUDES += -Imicro_ros_stm32cubemx_utils/microros_static_library/libmicroros/microros_include # Add micro-ROS utils C_SOURCES += micro_ros_stm32cubemx_utils/extra_sources/custom_memory_manager.c C_SOURCES += micro_ros_stm32cubemx_utils/extra_sources/microros_allocators.c C_SOURCES += micro_ros_stm32cubemx_utils/extra_sources/microros_time.c # Set here the custom transport implementation C_SOURCES += micro_ros_stm32cubemx_utils/extra_sources/microros_transports/dma_transport.c print_cflags: @echo $(CFLAGS)
-
Execute the static library generation tool. Compiler flags will retrieved automatically from your
Makefileand user will be prompted to check if they are correct.docker pull microros/micro_ros_static_library_builder:kilted docker run -it --rm -v $(pwd):/project --env MICROROS_LIBRARY_FOLDER=micro_ros_stm32cubemx_utils/microros_static_library microros/micro_ros_static_library_builder:kilted -
Modify your
main.cto use micro-ROS. An example application can be found insample_main.c. -
Continue your usual workflow building your project and flashing the binary:
make -j$(nproc)
micro-ROS can be used with SMT32CubeIDE following these steps:
-
Clone this repository in your STM32CubeIDE project folder
-
Go to
Project -> Settings -> C/C++ Build -> Settings -> Build Steps Taband inPre-build stepsadd:docker pull microros/micro_ros_static_library_builder:kilted && docker run --rm -v ${workspace_loc:/${ProjName}}:/project --env MICROROS_LIBRARY_FOLDER=micro_ros_stm32cubemx_utils/microros_static_library_ide microros/micro_ros_static_library_builder:kilted
-
Add micro-ROS include directory. In
Project -> Settings -> C/C++ Build -> Settings -> Tool Settings Tab -> MCU GCC Compiler -> Include pathsaddmicro_ros_stm32cubemx_utils/microros_static_library_ide/libmicroros/include -
Add the micro-ROS precompiled library. In
Project -> Settings -> C/C++ Build -> Settings -> MCU GCC Linker -> Libraries- add
<ABSOLUTE_PATH_TO>/micro_ros_stm32cubemx_utils/microros_static_library_ide/libmicrorosinLibrary search path (-L) - add
microrosinLibraries (-l)
- add
-
Add the following source code files to your project, dragging them to source folder:
extra_sources/microros_time.cextra_sources/microros_allocators.cextra_sources/custom_memory_manager.cextra_sources/microros_transports/dma_transport.cor your transport selection.
-
Make sure that if you are using FreeRTOS, the micro-ROS task has more than 10 kB of stack: Detail
-
Configure the transport interface on the STM32CubeMX project, check the Transport configuration section for instructions on the custom transports provided.
-
Build and run your project
micro-ROS can be used with SMT32CubeIDE in Windows 11 OS, following these steps:
- Install Docker Desktop and open it
- Clone this repository in your STM32CubeIDE project folder
- Open a terminal in the project folder and run:
docker pull microros/micro_ros_static_library_builder:humble docker run --rm -v <ABSOLUTE_PATH_TO_PROJECT>:/project --env MICROROS_LIBRARY_FOLDER=micro_ros_stm32cubemx_utils/microros_static_library_ide microros/micro_ros_static_library_builder:humble
Follow steps 4 to 8. Noticed that thist steps where tested with ROS 2 Humble, but should work on any distribution. micro-ROS Agent could be build and run in Ubuntu using WSL.
Available transport for this platform are:
Steps to configure:
- Enable U(S)ART in your STM32CubeMX
- For the selected USART, enable DMA for Tx and Rx under
DMA Settings - Set the DMA priotity to
Very Highfor Tx and Rx - Set the DMA mode to
Circularfor Rx: Detail - For the selected, enable
global interruptunderNVIC Settings: Detail
Steps to configure:
- Enable U(S)ART in your STM32CubeMX
- For the selected USART, enable
global interruptunderNVIC Settings: Detail
Steps to configure:
-
Enable the USB in your STM32CubeMX
Connectivitytab. -
Select the
Communication Device Class (Virtual Port Com)mode on theMiddleware -> USB_DEVICEconfiguration.Note: The micro-ROS transport will override the autogenerated
USB_DEVICE/App/usbd_cdc_if.cmethods.
Steps to configure:
-
Enable Ethernet in your STM32CubeMX/IDE
Connectivitytab. -
Enable LwIP in your STM32CubeMX/IDE
Middlewaretab. -
Make sure that LwIP has the following configuration:
Platform Setting according to your own board LwIP -> General Settings -> LWIP_DHCP -> Disabled LwIP -> General Settings -> IP Address Settings (Set here the board address and mask) LwIP -> General Settings -> LWIP UDP -> Enabled LwIP -> General Settings -> Procols Options -> MEMP_NUM_UDP_PCB -> 15 LwIP -> Key Options -> LWIP_SO_RCVTIMEO -> Enable
Note: Ensure your board and Agent are within the same LAN. The default port is 8888. You can modify it in udp_transport.c.If you are using a board from the STM32H7 series, please set up the MPU correctly.
-
Use
sample_main_udp.cas a reference for writing your application code. -
Start the micro-ROS Agent with the following arguments:
ros2 run micro_ros_agent micro_ros_agent udp4 --port 8888 -v 6
All the micro-ROS configuration can be done in colcon.meta file before step 3. You can find detailed information about how to tune the static memory usage of the library in the Middleware Configuration tutorial.
Note that folders added to microros_static_library/library_generation/extra_packages/ and entries added to /microros_static_library/library_generation/extra_packages/extra_packages.repos will be taken into account by this build system.
This software is not ready for production use. It has neither been developed nor tested for a specific use case. However, the license conditions of the applicable Open Source licenses allow you to adapt the software to your needs. Before using it in a safety relevant setting, make sure that the software fulfills your requirements and adjust it according to any applicable safety standards, e.g., ISO 26262.
This repository is open-sourced under the Apache-2.0 license. See the LICENSE file for details.
For a list of other open-source components included in this repository, see the file 3rd-party-licenses.txt.
There are no known limitations.

