Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Changelog for package micro_ros_stmcube
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

3.0.2 (2024-06-03)
------------------
* Add UDP transport (`#134 <https://github.com/micro-ROS/micro_ros_stm32cubemx_utils/issues/134>`_) (`#136 <https://github.com/micro-ROS/micro_ros_stm32cubemx_utils/issues/136>`_)
* Add UDP transport
* Apply suggestions from code review
Co-authored-by: Pablo Garrido <pablogs9@gmail.com>
* Update README and modify recv flag
* Update udp_transport.c
* Apply suggestions from code review
Co-authored-by: Pablo Garrido <pablogs9@gmail.com>
* Update udp_transport.c
* Minor fixes on readme
---------
Co-authored-by: Pablo Garrido <pablogs9@gmail.com>
(cherry picked from commit 0dbe8b656cf48ef6b8194f047029711fc09cc9bb)
Co-authored-by: Lion Hao <haolion520@gmail.com>
* Workaround to use STMCubeIDE in Windows 11 (backport `#127 <https://github.com/micro-ROS/micro_ros_stm32cubemx_utils/issues/127>`_) (`#128 <https://github.com/micro-ROS/micro_ros_stm32cubemx_utils/issues/128>`_)
Co-authored-by: Pablo Garrido <pablogs9@gmail.com>
Co-authored-by: Leonardo <leogarberoglio@hotmail.com>
* Contributors: mergify[bot]

3.0.1 (2023-06-12)
------------------
* Add USB CDC transport (`#89 <https://github.com/micro-ROS/micro_ros_stm32cubemx_utils/issues/89>`_)
* Improved repository clarity (`#74 <https://github.com/micro-ROS/micro_ros_stm32cubemx_utils/issues/74>`_)
* Fix USER_CUSTOM_PACKAGES_DIR (`#67 <https://github.com/micro-ROS/micro_ros_stm32cubemx_utils/issues/67>`_) (`#70 <https://github.com/micro-ROS/micro_ros_stm32cubemx_utils/issues/70>`_)
* microros_component/extra_packages support (`#63 <https://github.com/micro-ROS/micro_ros_stm32cubemx_utils/issues/63>`_) (`#65 <https://github.com/micro-ROS/micro_ros_stm32cubemx_utils/issues/65>`_)

3.0.0 (2022-05-25)
------------------
* Humble release (`#61 <https://github.com/micro-ROS/micro_ros_stm32cubemx_utils/issues/61>`_)
* Update banner (`#56 <https://github.com/micro-ROS/micro_ros_stm32cubemx_utils/issues/56>`_)
* Fix include paths (`#47 <https://github.com/micro-ROS/micro_ros_stm32cubemx_utils/issues/47>`_)
* Add check for NULL input pointer (`#53 <https://github.com/micro-ROS/micro_ros_stm32cubemx_utils/issues/53>`_) (`#55 <https://github.com/micro-ROS/micro_ros_stm32cubemx_utils/issues/55>`_)
* Fix broken pvPortReallocMicroROS() implementation (`#48 <https://github.com/micro-ROS/micro_ros_stm32cubemx_utils/issues/48>`_) (`#49 <https://github.com/micro-ROS/micro_ros_stm32cubemx_utils/issues/49>`_)
* Update STM32CubeMX micro-ROS library paths (backport `#42 <https://github.com/micro-ROS/micro_ros_stm32cubemx_utils/issues/42>`_) (`#43 <https://github.com/micro-ROS/micro_ros_stm32cubemx_utils/issues/43>`_)
* Fix embeddedRTPS build (`#38 <https://github.com/micro-ROS/micro_ros_stm32cubemx_utils/issues/38>`_)
* Fix embeddedRTPS repo (backport `#33 <https://github.com/micro-ROS/micro_ros_stm32cubemx_utils/issues/33>`_) (`#34 <https://github.com/micro-ROS/micro_ros_stm32cubemx_utils/issues/34>`_)
* Fix meta file selection and change rtps branch (backport `#31 <https://github.com/micro-ROS/micro_ros_stm32cubemx_utils/issues/31>`_) (`#32 <https://github.com/micro-ROS/micro_ros_stm32cubemx_utils/issues/32>`_)
* Add embeddedRTPS as experimental middleware (backport `#29 <https://github.com/micro-ROS/micro_ros_stm32cubemx_utils/issues/29>`_) (`#30 <https://github.com/micro-ROS/micro_ros_stm32cubemx_utils/issues/30>`_)
* Update library_generation.sh (`#26 <https://github.com/micro-ROS/micro_ros_stm32cubemx_utils/issues/26>`_) (`#27 <https://github.com/micro-ROS/micro_ros_stm32cubemx_utils/issues/27>`_)
* apt to apt-get (`#20 <https://github.com/micro-ROS/micro_ros_stm32cubemx_utils/issues/20>`_) (`#22 <https://github.com/micro-ROS/micro_ros_stm32cubemx_utils/issues/22>`_)
* multichange tool (`#10 <https://github.com/micro-ROS/micro_ros_stm32cubemx_utils/issues/10>`_) (`#12 <https://github.com/micro-ROS/micro_ros_stm32cubemx_utils/issues/12>`_)
* Initial Rolling port
* Suggested absolute path in step 4 (`#9 <https://github.com/micro-ROS/micro_ros_stm32cubemx_utils/issues/9>`_)
* multichange tool (`#6 <https://github.com/micro-ROS/micro_ros_stm32cubemx_utils/issues/6>`_)
* Add automated IDE support (`#4 <https://github.com/micro-ROS/micro_ros_stm32cubemx_utils/issues/4>`_)
* Add serial interrupt transport (`#2 <https://github.com/micro-ROS/micro_ros_stm32cubemx_utils/issues/2>`_)
* Update
* Update
* Update dockerfile
* Update
* Initial commit
* Initial commit
110 changes: 81 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ This tool aims to ease the micro-ROS integration in a STM32CubeMX/IDE project.
- [Middlewares available](#middlewares-available)
- [Using this package with STM32CubeMX](#using-this-package-with-stm32cubemx)
- [Using this package with STM32CubeIDE](#using-this-package-with-stm32cubeide)
- [Windows 11 (Community Contributed)](#windows-11-community-contributed)
- [Transport configuration](#transport-configuration)
- [U(S)ART with DMA](#usart-with-dma)
- [U(S)ART with Interrupts](#usart-with-interrupts)
- [USB CDC](#usb-cdc)
- [UDP](#udp)
- [Customizing the micro-ROS library](#customizing-the-micro-ros-library)
- [Adding custom packages](#adding-custom-packages)
- [Purpose of the Project](#purpose-of-the-project)
Expand All @@ -31,53 +34,54 @@ This package support the usage of micro-ROS on top of two different middlewares:
4. Configure the transport interface on the STM32CubeMX project, check the [Transport configuration](#Transport-configuration) section for instructions on the custom transports provided.
5. Modify the generated `Makefile` to include the following code **before the `build the application` section**:

<!-- # Removing heap4 manager while being polite with STM32CubeMX
TMPVAR := $(C_SOURCES)
C_SOURCES := $(filter-out Middlewares/Third_Party/FreeRTOS/Source/portable/MemMang/heap_4.c, $(TMPVAR)) -->
<!-- # Removing heap4 manager while being polite with STM32CubeMX
TMPVAR := $(C_SOURCES)
C_SOURCES := $(filter-out Middlewares/Third_Party/FreeRTOS/Source/portable/MemMang/heap_4.c, $(TMPVAR)) -->

```makefile
#######################################
# 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
```makefile
#######################################
# 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
# 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
# Set here the custom transport implementation
C_SOURCES += micro_ros_stm32cubemx_utils/extra_sources/microros_transports/dma_transport.c

print_cflags:
@echo $(CFLAGS)
```
print_cflags:
@echo $(CFLAGS)
```

6. Execute the static library generation tool. Compiler flags will retrieved automatically from your `Makefile` and user will be prompted to check if they are correct.


```bash
docker pull microros/micro_ros_static_library_builder:rolling
docker run -it --rm -v $(pwd):/project --env MICROROS_LIBRARY_FOLDER=micro_ros_stm32cubemx_utils/microros_static_library microros/micro_ros_static_library_builder:rolling
```
```bash
docker pull microros/micro_ros_static_library_builder:humble
docker run -it --rm -v $(pwd):/project --env MICROROS_LIBRARY_FOLDER=micro_ros_stm32cubemx_utils/microros_static_library microros/micro_ros_static_library_builder:humble
```

1. Modify your `main.c` to use micro-ROS. An example application can be found in `sample_main.c`.
2. Continue your usual workflow building your project and flashing the binary:

```bash
make -j$(nproc)
```
```bash
make -j$(nproc)
```

## Using this package with STM32CubeIDE

micro-ROS can be used with SMT32CubeIDE following these steps:

1. Clone this repository in your STM32CubeIDE project folder
2. Go to `Project -> Settings -> C/C++ Build -> Settings -> Build Steps Tab` and in `Pre-build steps` add:

```bash
docker pull microros/micro_ros_static_library_builder:rolling && 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:rolling
```
```bash
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
```

3. 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`
4. Add the micro-ROS precompiled library. In `Project -> Settings -> C/C++ Build -> Settings -> MCU GCC Linker -> Libraries`
Expand All @@ -91,6 +95,21 @@ docker pull microros/micro_ros_static_library_builder:rolling && docker run --rm
6. Make sure that if you are using FreeRTOS, the micro-ROS task **has more than 10 kB of stack**: [Detail](.images/Set_freertos_stack.jpg)
7. Configure the transport interface on the STM32CubeMX project, check the [Transport configuration](#Transport-configuration) section for instructions on the custom transports provided.
8. Build and run your project

### Windows 11 (Community Contributed)

micro-ROS can be used with SMT32CubeIDE in Windows 11 OS, following these steps:

1. Install Docker Desktop and open it
2. Clone this repository in your STM32CubeIDE project folder
3. Open a terminal in the project folder and run:
```bash
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.

## Transport configuration

Available transport for this platform are:
Expand All @@ -109,12 +128,45 @@ Steps to configure:
- Enable U(S)ART in your STM32CubeMX
- For the selected USART, enable `global interrupt` under `NVIC Settings`: [Detail](.images/Set_UART_IT.jpg)

### USB CDC

Steps to configure:
- Enable the USB in your STM32CubeMX `Connectivity` tab.
- Select the `Communication Device Class (Virtual Port Com)` mode on the `Middleware -> USB_DEVICE` configuration.

**Note: The micro-ROS transport will override the autogenerated `USB_DEVICE/App/usbd_cdc_if.c` methods.**

### UDP

Steps to configure:
- Enable Ethernet in your STM32CubeMX/IDE `Connectivity` tab.
- Enable LwIP in your STM32CubeMX/IDE `Middleware` tab.
- 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.c` as 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
```

## Customizing the micro-ROS library

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](https://micro.ros.org/docs/tutorials/advanced/microxrcedds_rmw_configuration/).
## Adding custom packages

Note that folders added to `microros_component/extra_packages` and entries added to `microros_component/extra_packages/extra_packages.repos` will be taken into account by this build system.
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.

## Purpose of the Project

Expand Down
2 changes: 1 addition & 1 deletion embeddedrtps.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ This instructions are an approach to a [STMCubeIDE v1.7.0](https://www.st.com/en
10. Go to `Project -> Settings -> C/C++ Build -> Settings -> Build Steps Tab` and in `Pre-build steps` add:

```bash
docker pull microros/micro_ros_static_library_builder:galactic && docker run --rm -v ${workspace_loc:/${ProjName}}:/project --env MICROROS_USE_EMBEDDEDRTPS=ON --env MICROROS_LIBRARY_FOLDER=micro_ros_stm32cubemx_utils/microros_static_library_ide microros/micro_ros_static_library_builder:galactic
docker pull microros/micro_ros_static_library_builder:humble && docker run --rm -v ${workspace_loc:/${ProjName}}:/project --env MICROROS_USE_EMBEDDEDRTPS=ON --env MICROROS_LIBRARY_FOLDER=micro_ros_stm32cubemx_utils/microros_static_library_ide microros/micro_ros_static_library_builder:humble
```

12. Add the following source code files to your project, dragging them to source folder:
Expand Down
79 changes: 79 additions & 0 deletions extra_sources/microros_transports/udp_transport.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#include <uxr/client/transport.h>

#include <rmw_microxrcedds_c/config.h>

#include "main.h"
#include "cmsis_os.h"

#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <stdbool.h>

// --- LWIP ---
#include "lwip/opt.h"
#include "lwip/sys.h"
#include "lwip/api.h"
#include <lwip/sockets.h>

#ifdef RMW_UXRCE_TRANSPORT_CUSTOM

// --- micro-ROS Transports ---
#define UDP_PORT 8888
static int sock_fd = -1;

bool cubemx_transport_open(struct uxrCustomTransport * transport){
sock_fd = socket(AF_INET, SOCK_DGRAM, 0);
struct sockaddr_in addr;
addr.sin_family = AF_INET;
addr.sin_port = htons(UDP_PORT);
addr.sin_addr.s_addr = htonl(INADDR_ANY);

if (bind(sock_fd, (struct sockaddr *)&addr, sizeof(addr)) == -1)
{
return false;
}

return true;
}

bool cubemx_transport_close(struct uxrCustomTransport * transport){
if (sock_fd != -1)
{
closesocket(sock_fd);
sock_fd = -1;
}
return true;
}

size_t cubemx_transport_write(struct uxrCustomTransport* transport, uint8_t * buf, size_t len, uint8_t * err){
if (sock_fd == -1)
{
return 0;
}
const char * ip_addr = (const char*) transport->args;
struct sockaddr_in addr;
addr.sin_family = AF_INET;
addr.sin_port = htons(UDP_PORT);
addr.sin_addr.s_addr = inet_addr(ip_addr);
int ret = 0;
ret = sendto(sock_fd, buf, len, 0, (struct sockaddr *)&addr, sizeof(addr));
size_t writed = ret>0? ret:0;

return writed;
}

size_t cubemx_transport_read(struct uxrCustomTransport* transport, uint8_t* buf, size_t len, int timeout, uint8_t* err){

int ret = 0;
//set timeout
struct timeval tv_out;
tv_out.tv_sec = timeout / 1000;
tv_out.tv_usec = (timeout % 1000) * 1000;
setsockopt(sock_fd, SOL_SOCKET, SO_RCVTIMEO,&tv_out, sizeof(tv_out));
ret = recv(sock_fd, buf, len, MSG_WAITALL);
size_t readed = ret > 0 ? ret : 0;
return readed;
}

#endif
Loading