Skip to content

Commit a809407

Browse files
authored
Add ESP32 support (#680)
* Fix wifi example * Update ci and library properties * Add esp32 build step * Update readme * Add esp32 library to test CI * Fix CI * Fix build for Arduino nano * Fix esp32 CI compilation * Install pyserial for esp32 * Install pip3 on CI * Revert commit and add pip3 * Update library_generation.sh with changes check * Remove redundant code * Trigger build
1 parent 3e02186 commit a809407

File tree

9 files changed

+70
-24
lines changed

9 files changed

+70
-24
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,21 @@ jobs:
1919
- name: Build
2020
run: |
2121
apt update
22-
apt install -y git curl lib32z1 wget libfontconfig libxft2 xz-utils rsync
22+
apt install -y git curl lib32z1 wget libfontconfig libxft2 xz-utils rsync python-is-python3 python3-pip
23+
pip3 install pyserial
2324
curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | sh
2425
mkdir -p /github/home/Arduino/libraries/micro_ros_arduino/
2526
cp -R checkout/* /github/home/Arduino/libraries/micro_ros_arduino/
2627
echo '''board_manager:
2728
additional_urls:
28-
- https://raw.githubusercontent.com/ROBOTIS-GIT/OpenCR/master/arduino/opencr_release/package_opencr_index.json''' > arduino-cli.yaml
29+
- https://raw.githubusercontent.com/ROBOTIS-GIT/OpenCR/master/arduino/opencr_release/package_opencr_index.json
30+
- https://github.com/espressif/arduino-esp32/releases/download/2.0.2/package_esp32_index.json''' > arduino-cli.yaml
2931
export PATH=$PATH:/github/workspace/bin:/__w/micro_ros_arduino/micro_ros_arduino/bin
3032
arduino-cli core install OpenCR:OpenCR -v
3133
arduino-cli core install arduino:samd -v
3234
arduino-cli core install arduino:sam -v
3335
arduino-cli core install arduino:mbed -v
36+
arduino-cli core install esp32:esp32 -v
3437
#
3538
# INSTALLING TEENSY SUPPORT
3639
wget https://downloads.arduino.cc/arduino-1.8.13-linux64.tar.xz
@@ -79,4 +82,6 @@ jobs:
7982
arduino-cli compile --fqbn arduino:sam:arduino_due_x /github/home/Arduino/libraries/micro_ros_arduino/examples/micro-ros_publisher -v
8083
# arduino-cli compile --fqbn arduino:mbed:envie_m4 /github/home/Arduino/libraries/micro_ros_arduino/examples/micro-ros_publisher -v
8184
arduino-cli compile --fqbn arduino:mbed:envie_m7 /github/home/Arduino/libraries/micro_ros_arduino/examples/micro-ros_publisher -v
82-
arduino-cli compile --fqbn arduino:mbed:envie_m7 /github/home/Arduino/libraries/micro_ros_arduino/examples/micro-ros_publisher_wifi -v
85+
arduino-cli compile --fqbn arduino:mbed:envie_m7 /github/home/Arduino/libraries/micro_ros_arduino/examples/micro-ros_publisher_wifi -v
86+
arduino-cli compile --fqbn esp32:esp32:esp32 /github/home/Arduino/libraries/micro_ros_arduino/examples/micro-ros_publisher -v
87+
arduino-cli compile --fqbn esp32:esp32:esp32 /github/home/Arduino/libraries/micro_ros_arduino/examples/micro-ros_publisher_wifi -v

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Supported boards are:
3131
| [Teensy 3.2/3.1](https://www.pjrc.com/store/teensy32.html) | v1.8.5 | Supported | [Based on Teensyduino](https://www.pjrc.com/teensy/td_download.html) | `colcon_lowmem.meta` |
3232
| [Teensy 3.5](https://www.pjrc.com/store/teensy35.html) | v1.8.5 | Not tested | [Based on Teensyduino](https://www.pjrc.com/teensy/td_download.html) | `colcon_lowmem.meta` |
3333
| [Teensy 3.6](https://www.pjrc.com/store/teensy36.html) | v1.8.5 | Supported | [Based on Teensyduino](https://www.pjrc.com/teensy/td_download.html) | `colcon_lowmem.meta` |
34+
| [ESP32 Dev Module](https://docs.espressif.com/projects/arduino-esp32/en/latest/boards/ESP32-DevKitC-1.html) | v1.8.5 | Supported | [Arduino core for the ESP32 (v2.0.2)](https://github.com/espressif/arduino-esp32/releases/tag/2.0.2) | `colcon.meta` |
3435

3536
Community contributed boards are:
3637

@@ -135,3 +136,4 @@ see the file [3rd-party-licenses.txt](3rd-party-licenses.txt).
135136
- When using provided precompiled libraries, users should take into account the already configured static memory pools in middleware layers. [More info here](https://micro-ros.github.io/docs/tutorials/core/microxrcedds_rmw_configuration/).
136137
- micro-ROS transports should be refactored in order to provide a pluggable mechanims. Only USB serial transports are provided.
137138
- Teensyduino support files have to be patched in order to use precompiled libraries.
139+
- To solve Python errors on ESP32 compilation: `apt install python-is-python3 && pip3 install pyserial`

built_packages

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@ https://github.com/ament/ament_lint.git 4bc68c815ce308b3443e3cb38fd71e2b03ffdc40
3232
https://github.com/ament/uncrustify_vendor.git 8945c291fbd36d7980f7e4fd641601c277c178ec
3333
https://github.com/ament/ament_index.git 7c8a2762453bf928909cc3dd65d2164b2f67dbaf
3434
https://github.com/ros2/ament_cmake_ros.git 7b6b599c3fc8023806db2a97b344e8610902adac
35+

examples/micro-ros_publisher_wifi/micro-ros_publisher_wifi.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
#include <std_msgs/msg/int32.h>
1010

11-
#if !defined(TARGET_PORTENTA_H7_M7) && !defined(ARDUINO_NANO_RP2040_CONNECT)
12-
#error This example is only avaible for Arduino Portenta and Arduino Nano RP2040 Connect
11+
#if !defined(ESP32) && !defined(TARGET_PORTENTA_H7_M7) && !defined(ARDUINO_NANO_RP2040_CONNECT)
12+
#error This example is only avaible for Arduino Portenta, Arduino Nano RP2040 Connect and ESP32 Dev module
1313
#endif
1414

1515
rcl_publisher_t publisher;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
SET(CMAKE_SYSTEM_NAME Generic)
2+
set(CMAKE_CROSSCOMPILING 1)
3+
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
4+
5+
set(CMAKE_C_COMPILER $ENV{TOOLCHAIN_PREFIX}gcc)
6+
set(CMAKE_CXX_COMPILER $ENV{TOOLCHAIN_PREFIX}g++)
7+
8+
SET(CMAKE_C_COMPILER_WORKS 1 CACHE INTERNAL "")
9+
SET(CMAKE_CXX_COMPILER_WORKS 1 CACHE INTERNAL "")
10+
11+
set(FLAGS "-Os -mlongcalls -ffunction-sections -fdata-sections -D'RCUTILS_LOG_MIN_SEVERITY=RCUTILS_LOG_MIN_SEVERITY_NONE'" CACHE STRING "" FORCE)
12+
13+
set(CMAKE_C_FLAGS_INIT "-std=c11 ${FLAGS} -DCLOCK_MONOTONIC=0 -D'__attribute__(x)='" CACHE STRING "" FORCE)
14+
set(CMAKE_CXX_FLAGS_INIT "-std=c++14 ${FLAGS} -DCLOCK_MONOTONIC=0 -D'__attribute__(x)='" CACHE STRING "" FORCE)
15+
16+
set(__BIG_ENDIAN__ 0)

extras/library_generation/library_generation.sh

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ if [ $OPTIND -eq 1 ]; then
2121
# PLATFORMS+=("portenta-m4")
2222
PLATFORMS+=("portenta-m7")
2323
PLATFORMS+=("kakutef7-m7")
24+
PLATFORMS+=("esp32")
2425
fi
2526

2627
shift $((OPTIND-1))
@@ -53,10 +54,19 @@ pushd firmware/mcu_ws > /dev/null
5354

5455
popd > /dev/null
5556

56-
# Workaround. Remove when https://github.com/ros2/rosidl/pull/596 is merged
57-
touch firmware/mcu_ws/ros2/common_interfaces/actionlib_msgs/COLCON_IGNORE;
58-
touch firmware/mcu_ws/ros2/common_interfaces/std_srvs/COLCON_IGNORE;
59-
touch firmware/mcu_ws/ros2/example_interfaces/COLCON_IGNORE;
57+
cd firmware
58+
echo "" > /project/built_packages
59+
for f in $(find $(pwd) -name .git -type d); do pushd $f > /dev/null; echo $(git config --get remote.origin.url) $(git rev-parse HEAD) >> /project/built_packages; popd > /dev/null; done;
60+
61+
cd /project
62+
if [[ `git diff-index --name-only HEAD | grep built_packages` ]]; then
63+
echo "Changes detected"
64+
else
65+
echo "No changes detected"
66+
exit 0
67+
fi
68+
69+
cd /uros_ws
6070

6171
######## Clean and source ########
6272
find /project/src/ ! -name micro_ros_arduino.h ! -name *.c ! -name *.cpp ! -name *.c.in -delete
@@ -220,13 +230,23 @@ if [[ " ${PLATFORMS[@]} " =~ " kakutef7-m7 " ]]; then
220230
cp -R firmware/build/libmicroros.a /project/src/cortex-m7/fpv5-sp-d16-hardfp/libmicroros.a
221231
fi
222232

233+
######## Build for ESP 32 ########
234+
if [[ " ${PLATFORMS[@]} " =~ " esp32 " ]]; then
235+
rm -rf firmware/build
236+
237+
export TOOLCHAIN_PREFIX=/uros_ws/xtensa-esp32-elf/bin/xtensa-esp32-elf-
238+
ros2 run micro_ros_setup build_firmware.sh /project/extras/library_generation/esp32_toolchain.cmake /project/extras/library_generation/colcon.meta
239+
240+
find firmware/build/include/ -name "*.c" -delete
241+
cp -R firmware/build/include/* /project/src/
242+
243+
mkdir -p /project/src/esp32
244+
cp -R firmware/build/libmicroros.a /project/src/esp32/libmicroros.a
245+
fi
246+
223247
######## Generate extra files ########
224248
find firmware/mcu_ws/ros2 \( -name "*.srv" -o -name "*.msg" -o -name "*.action" \) | awk -F"/" '{print $(NF-2)"/"$NF}' > /project/available_ros2_types
225249
find firmware/mcu_ws/extra_packages \( -name "*.srv" -o -name "*.msg" -o -name "*.action" \) | awk -F"/" '{print $(NF-2)"/"$NF}' >> /project/available_ros2_types
226250

227-
cd firmware
228-
echo "" > /project/built_packages
229-
for f in $(find $(pwd) -name .git -type d); do pushd $f > /dev/null; echo $(git config --get remote.origin.url) $(git rev-parse HEAD) >> /project/built_packages; popd > /dev/null; done;
230-
231251
######## Fix permissions ########
232252
sudo chmod -R 777 .

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ paragraph=micro-ROS Arduino library
77
url=https://github.com/micro-ROS
88
precompiled=true
99
category=Other
10-
architectures=stm32,OpenCR,Teensyduino,samd,sam,mbed
10+
architectures=stm32,OpenCR,Teensyduino,samd,sam,mbed, esp32

src/micro_ros_arduino.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,12 @@ static inline void set_microros_native_ethernet_udp_transports(byte mac[], IPAdd
8181

8282
#endif
8383

84-
#if defined(TARGET_PORTENTA_H7_M7) || defined(ARDUINO_NANO_RP2040_CONNECT)
84+
#if defined(ESP32) || defined(TARGET_PORTENTA_H7_M7) || defined(ARDUINO_NANO_RP2040_CONNECT)
8585

86-
#if defined(TARGET_PORTENTA_H7_M7)
86+
#if defined(ESP32) || defined(TARGET_PORTENTA_H7_M7)
8787
#include <WiFi.h>
8888
#include <WiFiUdp.h>
89-
#else defined(ARDUINO_NANO_RP2040_CONNECT)
89+
#elif defined(ARDUINO_NANO_RP2040_CONNECT)
9090
#include <SPI.h>
9191
#include <WiFiNINA.h>
9292
#endif
@@ -102,10 +102,12 @@ struct micro_ros_agent_locator {
102102
};
103103

104104
static inline void set_microros_wifi_transports(char * ssid, char * pass, char * agent_ip, uint agent_port){
105-
while (WiFi.begin(ssid, pass) != WL_CONNECTED)
106-
{
107-
delay(500);
108-
}
105+
106+
WiFi.begin(ssid, pass);
107+
108+
while (WiFi.status() != WL_CONNECTED) {
109+
delay(500);
110+
}
109111

110112
static struct micro_ros_agent_locator locator;
111113
locator.address.fromString(agent_ip);

src/wifi_transport.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
#if defined(TARGET_PORTENTA_H7_M7) || defined(ARDUINO_NANO_RP2040_CONNECT)
1+
#if defined(ESP32) || defined(TARGET_PORTENTA_H7_M7) || defined(ARDUINO_NANO_RP2040_CONNECT)
22

33
#include <Arduino.h>
44

55

6-
#if defined(TARGET_PORTENTA_H7_M7)
6+
#if defined(ESP32) || defined(TARGET_PORTENTA_H7_M7)
77
#include <WiFi.h>
88
#include <WiFiUdp.h>
9-
#else defined(ARDUINO_NANO_RP2040_CONNECT)
9+
#elif defined(ARDUINO_NANO_RP2040_CONNECT)
1010
#include <SPI.h>
1111
#include <WiFiNINA.h>
1212
#endif

0 commit comments

Comments
 (0)