Welcome to ROSMASTER M3 repository
5.Compile the microros driver library
Compile the microros driver library
Compile the microros driver library1. Install the cross-compiler2. Get the STM32-microros library file3. Modify parameters4. Add environment variables5. Start compiling6. Solve the include problem7. The final file8. Import STM32CUBEIDE project
Note: You must use Ubuntu to compile the microros driver library. Ubuntu 22.04 is recommended.
1. Install the cross-compiler
Open the download address and download the Linux version of the cross-compiler.
xxxxxxxxxxhttps://developer.arm.com/downloads/-/gnu-rm

After decompression, put the file in the following path
xxxxxxxxxx/opt/gcc-arm-none-eabi
And add the executable file path to the .bashrc environment variable in the user directory.
xxxxxxxxxxexport PATH=$PATH:/opt/gcc-arm-none-eabi/bin
2. Get the STM32-microros library file
Download and compile the microros setup tool
xxxxxxxxxxmkdir uros_ws && cd uros_wsgit clone -b humble https://github.com/micro-ROS/micro_ros_setup.git src/micro_ros_setuprosdep update && rosdep install --from-paths src --ignore-src -ycolcon buildsource install/local_setup.bash
Use the microros setup tool to generate the STM32-microros library file.
xxxxxxxxxxros2 run micro_ros_setup create_firmware_ws.sh generate_lib

Check the workspace. We should now have five folders, among which the firmware folder contains the STM32-microros library files. build firmware install log src

3. Modify parameters
Open the toolchain.cmake file
xxxxxxxxxxvim ~/uros_ws/firmware/toolchain.cmake
Copy the following content into
xxxxxxxxxxset(CMAKE_SYSTEM_NAME Generic)set(CMAKE_CROSSCOMPILING 1)set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)# SET HERE THE PATH TO YOUR C99 AND C++ COMPILERS# Add the compiler path hereset(PIX /opt/gcc-arm-none-eabi/bin)set(CMAKE_C_COMPILER ${PIX}/arm-none-eabi-gcc)set(CMAKE_CXX_COMPILER ${PIX}/arm-none-eabi-g++)set(CMAKE_C_COMPILER_WORKS 1 CACHE INTERNAL "")set(CMAKE_CXX_COMPILER_WORKS 1 CACHE INTERNAL "")# SET HERE YOUR BUILDING FLAGSset(FLAGS "-O2 -ffunction-sections -fdata-sections -fno-exceptions -mcpu=cortex-m7 -mfpu=fpv5-d16 -mfloat-abi=hard -nostdlib -mthumb --param max-inline-insns-single=500 -D'RCUTILS_LOG_MIN_SEVERITY=RCUTILS_LOG_MIN_SEVERITY_NONE'" CACHE STRING "" FORCE)# -mcpu=cortex-m7 indicates the microcontroller architecture# -mfpu=fpv5-d16 -mfloat-abi=hard indicates support for hardware floating-point compilationset(CMAKE_C_FLAGS_INIT "-std=c11 ${FLAGS} -DCLOCK_MONOTONIC=0 -D'__attribute__(x)='" CACHE STRING "" FORCE)set(CMAKE_CXX_FLAGS_INIT "-std=c++11 ${FLAGS} -fno-rtti -DCLOCK_MONOTONIC=0 -D'__attribute__(x)='" CACHE STRING "" FORCE)set(__BIG_ENDIAN__ 0)
Save and exit.
Open the colcon.meta file
xxxxxxxxxxvim ~/uros_ws/firmware/colcon.meta
Copy the following content into
xxxxxxxxxx{"names": {"tracetools": {"cmake-args": ["-DTRACETOOLS_DISABLED=ON","-DTRACETOOLS_STATUS_CHECKING_TOOL=OFF"]},"rosidl_typesupport": {"cmake-args": ["-DROSIDL_TYPESUPPORT_SINGLE_TYPESUPPORT=ON"]},"rcl": {"cmake-args": ["-DBUILD_TESTING=OFF","-DRCL_COMMAND_LINE_ENABLED=OFF","-DRCL_LOGGING_ENABLED=OFF"]},"rcutils": {"cmake-args": ["-DENABLE_TESTING=OFF","-DRCUTILS_NO_FILESYSTEM=ON","-DRCUTILS_NO_THREAD_SUPPORT=ON","-DRCUTILS_NO_64_ATOMIC=ON","-DRCUTILS_AVOID_DYNAMIC_ALLOCATION=ON"]},"microxrcedds_client": {"cmake-args": ["-DUCLIENT_PIC=OFF","-DUCLIENT_PROFILE_UDP=OFF","-DUCLIENT_PROFILE_TCP=OFF","-DUCLIENT_PROFILE_DISCOVERY=OFF","-DUCLIENT_PROFILE_SERIAL=OFF","-UCLIENT_PROFILE_STREAM_FRAMING=ON","-DUCLIENT_PROFILE_CUSTOM_TRANSPORT=ON","-DUCLIENT_PROFILE_SHARED_MEMORY=ON","-DUCLIENT_SHARED_MEMORY_MAX_ENTITIES=20"]},"rmw_microxrcedds": {"cmake-args": ["-DRMW_UXRCE_MAX_NODES=1","-DRMW_UXRCE_MAX_PUBLISHERS=10","-DRMW_UXRCE_MAX_SUBSCRIPTIONS=10","-DRMW_UXRCE_MAX_SERVICES=1","-DRMW_UXRCE_MAX_CLIENTS=1","-DRMW_UXRCE_MAX_HISTORY=10","-DRMW_UXRCE_TRANSPORT=custom"]}}}
"-DRMW_UXRCE_MAX_NODES=1", #maximum number of nodes;
"-DRMW_UXRCE_MAX_PUBLISHERS=10", #maximum number of publisher;
"-DRMW_UXRCE_MAX_SUBSCRIPTIONS=10", #maximum number of subscribers;
"-DRMW_UXRCE_MAX_SERVICES=1", #maximum number of servers;
"-DRMW_UXRCE_MAX_CLIENTS=1", #maximum number of clients;
"-DRMW_UXRCE_MAX_HISTORY=10", #history;
"-DRMW_UXRCE_TRANSPORT=custom" #custom transport interface
Save and exit.
4. Add environment variables
xxxxxxxxxxexport RMW_IMPLEMENTATION=rmw_microxrcedds
5. Start compiling
xxxxxxxxxxcd ~/uros_ws/ros2 run micro_ros_setup build_firmware.sh $(pwd)/firmware/toolchain.cmake $(pwd)/firmware/colcon.meta
Note: Since the compilation process requires downloading many files, and most file servers are located abroad, if there is a network anomaly, please solve the network download problem yourself.
View the generated static library and header files
xxxxxxxxxxls firmware/build
6. Solve the include problem
Since the generated include folder path is too long, you need to use a script to fix it.
Create a new fix_include.sh script in the firmware folder
xxxxxxxxxxcd ~/uros_ws/firmwarevim fix_include.sh
Copy the following content into
xxxxxxxxxx#!/bin/bash######## Fix include paths ########BASE_PATH=buildpushd mcu_ws > /dev/nullINCLUDE_ROS2_PACKAGES=$(colcon list | awk '{print $1}' | awk -vd=" " '{s=(NR==1?s:sd)$0}END{print s}')popd > /dev/nullfor var in ${INCLUDE_ROS2_PACKAGES}; doif [ -d "${BASE_PATH}/include/${var}/${var}" ]; thenrsync -r ${BASE_PATH}/include/${var}/${var}/* $BASE_PATH/include/${var}rm -rf ${BASE_PATH}/include/${var}/${var}fidonemkdir ${BASE_PATH}/libmicrorosmv ${BASE_PATH}/libmicroros.a ${BASE_PATH}/libmicroros
Save and exit.
Run the following command to fix the include folder problem.
xxxxxxxxxxbash fix_include.sh
7. The final file
xxxxxxxxxxls ~/uros_ws/firmware/buildls ~/uros_ws/firmware/build/libmicrorosls ~/uros_ws/firmware/build/include

8. Import STM32CUBEIDE project
Create a new Microros folder in the project, and then copy the include and libmicroros folders generated by the previous step into Microros.

Right-click to open the project properties, then click [Settings]->[MCU/MPU GCC Compiler]->[include paths] to add the microros include directory path, and then click [Apply] to take effect.

Add the microros folder as the project source code path.

Import the microros library path

Link the microros library file to the project. Make sure the name matches the libmicroros.a static library file name (excluding the prefix and suffix "microros").
