micro-ROS / micro_ros_stm32cubemx_utils

A set of utilities for integrating micro-ROS in a STM32CubeMX project
Apache License 2.0
159 stars 60 forks source link

Unable to Establish Connection between PC and STM32 Board #143

Closed kasunvinod closed 3 months ago

kasunvinod commented 4 months ago

I'm a beginner in STM32 development, and I would really appreciate it if someone could help me with this. I've been trying to set up micro-ROS in an STM32 board for a couple of weeks now. Still, I'm unable to get it to work. I did the following things during the setup process. But I'm unable to establish a connection with the STM32 board using the PC.

image

I've tried the mentioned steps with both NUCLEO-F446RE & NUCLEO-F767ZI multiple times but still no luck.

Important Observations

  1. When building STM32 project for the first time, it had around 40 warnings. Most of them are related to setuptools version. However, I had no errors. Both build and flashing were successful.
  2. STM32 board is connected to the PC over ST-Link, and UART worked perfectly fine when I tested the UART2 with a simple HAL code in another project.

Main Computer - Ubuntu 22.04 with ROS2 Humble STM Board - NUCLEO-F446RE & NUCLEO-F767ZI

Installing micro-ROS Build System All the steps available in this micro-ROS Tutorial related to installing the micro-ROS build system were followed by executing the following commands.

mkdir microros_ws' cd microros_ws git clone -b $ROS_DISTRO https://github.com/micro-ROS/micro_ros_setup.git src/micro_ros_setup sudo apt update && rosdep update rosdep install --from-paths src --ignore-src -y ros2 run micro_ros_setup create_firmware_ws.sh host ros2 run micro_ros_setup build_firmware.sh ros2 run micro_ros_setup create_agent_ws.sh ros2 run micro_ros_setup build_agent.sh

Setting up the STM Board The following steps were followed to setup the STM32 board with micro-ROS using CubeIDE as per the instructions on micro_ros_stm32cubemx_utils page.

  1. Create a new CubeIDE project for your micro-controller.
  2. In System Core -> RCC -> High Speed Clock (HSE) select Crystal/Ceramic Resonator
  3. In System Core -> SYS -> Timebase Source select TIM1
  4. In Middleware -> FREERTOS -> Interface select CMSIS_V2
  5. In Middleware -> FREERTOS -> Configuration -> Task and Queues double click the defaultTask and set a stack size of 3000.
  6. In Connectivity choose the USART2.
  7. In the USART configuration, go to DMA Settings. Click on the Add button. Click on the Select dropdown and choose both RX and TX.
  8. Click on the Rx DMA choose Circular as mode.
  9. For the priority of the DMA choose Very High for both Rx and Tx.
  10. Go to NVIC Settings of the UART and activate the USART2 global interrupt.
  11. Click Generate Code.
  12. Clone the micro_ros_stm32cubemx_utils repo to STM32 project folder.
  13. Go to Project -> Properties -> C/C++ Build -> Settings -> Build Steps Tab and in Pre-build steps add: docker pull microros/micro_ros_static_library_builder:humble && 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:humble
  14. Add micro-ROS include directory. In Project -> Settings -> C/C++ Build -> Settings -> Tool Settings Tab -> MCU GCC Compiler -> Include paths add micro_ros_stm32cubemx_utils/microros_static_library_ide/libmicroros/include
  15. Add the micro-ROS precompiled library. In Project -> Settings -> C/C++ Build -> Settings -> MCU GCC Linker -> Libraries
    • add ../micro_ros_stm32cubemx_utils/microros_static_library_ide/libmicroros in Library search path (-L)
    • add microros in Libraries (-l)
  16. Copy all those files to the source folder of the project (microros_time.c, microros_allocators.c, custom_memory_manager.c, dma_transport.c) from extra_sources folder.
  17. Build and Run the Project.
  18. Run the microROS agent by executing following command in the terminal. ros2 run micro_ros_agent micro_ros_agent serial --dev /dev/ttyACM0
kasunvinod commented 3 months ago

There was a issue with the main.c where i create the publisher. After correcting that I was able to establish the connection with the STM board. But when I execute the ros2 topic list and ros2 node list, the publisher node and topic is not coming up.

microROS-STMIssue1

I'm experiencing the same issue with RaspberryPi pico as well. I have reported that in here.

I was using cyclone dds earlier and I revert it back to fastDDS as per @pablogs9's advice.

kasunvinod commented 3 months ago

SOLVED after changing the ROS_DOMAIN_ID to 0 as per @pablogs9. More info can be found in the above mentioned issue.