Skip to content

Add ESP32 support (backport #680) #686

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 12, 2022
Merged
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
11 changes: 8 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,21 @@ jobs:
- name: Build
run: |
apt update
apt install -y git curl lib32z1 wget libfontconfig libxft2 xz-utils rsync
apt install -y git curl lib32z1 wget libfontconfig libxft2 xz-utils rsync python-is-python3 python3-pip
pip3 install pyserial
curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | sh
mkdir -p /github/home/Arduino/libraries/micro_ros_arduino/
cp -R checkout/* /github/home/Arduino/libraries/micro_ros_arduino/
echo '''board_manager:
additional_urls:
- https://raw.githubusercontent.com/ROBOTIS-GIT/OpenCR/master/arduino/opencr_release/package_opencr_index.json''' > arduino-cli.yaml
- https://raw.githubusercontent.com/ROBOTIS-GIT/OpenCR/master/arduino/opencr_release/package_opencr_index.json
- https://github.com/espressif/arduino-esp32/releases/download/2.0.2/package_esp32_index.json''' > arduino-cli.yaml
export PATH=$PATH:/github/workspace/bin:/__w/micro_ros_arduino/micro_ros_arduino/bin
arduino-cli core install OpenCR:OpenCR -v
arduino-cli core install arduino:samd -v
arduino-cli core install arduino:sam -v
arduino-cli core install arduino:mbed -v
arduino-cli core install esp32:esp32 -v
#
# INSTALLING TEENSY SUPPORT
wget https://downloads.arduino.cc/arduino-1.8.13-linux64.tar.xz
Expand Down Expand Up @@ -78,4 +81,6 @@ jobs:
arduino-cli compile --fqbn arduino:sam:arduino_due_x /github/home/Arduino/libraries/micro_ros_arduino/examples/micro-ros_publisher -v
# arduino-cli compile --fqbn arduino:mbed:envie_m4 /github/home/Arduino/libraries/micro_ros_arduino/examples/micro-ros_publisher -v
arduino-cli compile --fqbn arduino:mbed:envie_m7 /github/home/Arduino/libraries/micro_ros_arduino/examples/micro-ros_publisher -v
arduino-cli compile --fqbn arduino:mbed:envie_m7 /github/home/Arduino/libraries/micro_ros_arduino/examples/micro-ros_publisher_wifi -v
arduino-cli compile --fqbn arduino:mbed:envie_m7 /github/home/Arduino/libraries/micro_ros_arduino/examples/micro-ros_publisher_wifi -v
arduino-cli compile --fqbn esp32:esp32:esp32 /github/home/Arduino/libraries/micro_ros_arduino/examples/micro-ros_publisher -v
arduino-cli compile --fqbn esp32:esp32:esp32 /github/home/Arduino/libraries/micro_ros_arduino/examples/micro-ros_publisher_wifi -v
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Supported boards are:
| [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` |
| [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` |
| [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` |
| [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` |

Community contributed boards are:

Expand Down Expand Up @@ -135,3 +136,4 @@ see the file [3rd-party-licenses.txt](3rd-party-licenses.txt).
- 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/).
- micro-ROS transports should be refactored in order to provide a pluggable mechanims. Only USB serial transports are provided.
- Teensyduino support files have to be patched in order to use precompiled libraries.
- To solve Python errors on ESP32 compilation: `apt install python-is-python3 && pip3 install pyserial`
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

#include <std_msgs/msg/int32.h>

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

rcl_publisher_t publisher;
Expand Down
16 changes: 16 additions & 0 deletions extras/library_generation/esp32_toolchain.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
SET(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_CROSSCOMPILING 1)
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)

set(CMAKE_C_COMPILER $ENV{TOOLCHAIN_PREFIX}gcc)
set(CMAKE_CXX_COMPILER $ENV{TOOLCHAIN_PREFIX}g++)

SET(CMAKE_C_COMPILER_WORKS 1 CACHE INTERNAL "")
SET(CMAKE_CXX_COMPILER_WORKS 1 CACHE INTERNAL "")

set(FLAGS "-Os -mlongcalls -ffunction-sections -fdata-sections -D'RCUTILS_LOG_MIN_SEVERITY=RCUTILS_LOG_MIN_SEVERITY_NONE'" CACHE STRING "" FORCE)

set(CMAKE_C_FLAGS_INIT "-std=c11 ${FLAGS} -DCLOCK_MONOTONIC=0 -D'__attribute__(x)='" CACHE STRING "" FORCE)
set(CMAKE_CXX_FLAGS_INIT "-std=c++14 ${FLAGS} -DCLOCK_MONOTONIC=0 -D'__attribute__(x)='" CACHE STRING "" FORCE)

set(__BIG_ENDIAN__ 0)
33 changes: 29 additions & 4 deletions extras/library_generation/library_generation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ if [ $OPTIND -eq 1 ]; then
# PLATFORMS+=("portenta-m4")
PLATFORMS+=("portenta-m7")
PLATFORMS+=("kakutef7-m7")
PLATFORMS+=("esp32")
fi

shift $((OPTIND-1))
Expand Down Expand Up @@ -53,6 +54,20 @@ pushd firmware/mcu_ws > /dev/null

popd > /dev/null

cd firmware
echo "" > /project/built_packages
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;

cd /project
if [[ `git diff-index --name-only HEAD | grep built_packages` ]]; then
echo "Changes detected"
else
echo "No changes detected"
exit 0
fi

cd /uros_ws

######## Clean and source ########
find /project/src/ ! -name micro_ros_arduino.h ! -name *.c ! -name *.cpp ! -name *.c.in -delete

Expand Down Expand Up @@ -215,13 +230,23 @@ if [[ " ${PLATFORMS[@]} " =~ " kakutef7-m7 " ]]; then
cp -R firmware/build/libmicroros.a /project/src/cortex-m7/fpv5-sp-d16-hardfp/libmicroros.a
fi

######## Build for ESP 32 ########
if [[ " ${PLATFORMS[@]} " =~ " esp32 " ]]; then
rm -rf firmware/build

export TOOLCHAIN_PREFIX=/uros_ws/xtensa-esp32-elf/bin/xtensa-esp32-elf-
ros2 run micro_ros_setup build_firmware.sh /project/extras/library_generation/esp32_toolchain.cmake /project/extras/library_generation/colcon.meta

find firmware/build/include/ -name "*.c" -delete
cp -R firmware/build/include/* /project/src/

mkdir -p /project/src/esp32
cp -R firmware/build/libmicroros.a /project/src/esp32/libmicroros.a
fi

######## Generate extra files ########
find firmware/mcu_ws/ros2 \( -name "*.srv" -o -name "*.msg" -o -name "*.action" \) | awk -F"/" '{print $(NF-2)"/"$NF}' > /project/available_ros2_types
find firmware/mcu_ws/extra_packages \( -name "*.srv" -o -name "*.msg" -o -name "*.action" \) | awk -F"/" '{print $(NF-2)"/"$NF}' >> /project/available_ros2_types

cd firmware
echo "" > /project/built_packages
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;

######## Fix permissions ########
sudo chmod -R 777 .
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ paragraph=micro-ROS Arduino library
url=https://github.com/micro-ROS
precompiled=true
category=Other
architectures=stm32,OpenCR,Teensyduino,samd,sam,mbed
architectures=stm32,OpenCR,Teensyduino,samd,sam,mbed, esp32
16 changes: 9 additions & 7 deletions src/micro_ros_arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ static inline void set_microros_native_ethernet_udp_transports(byte mac[], IPAdd

#endif

#if defined(TARGET_PORTENTA_H7_M7) || defined(ARDUINO_NANO_RP2040_CONNECT)
#if defined(ESP32) || defined(TARGET_PORTENTA_H7_M7) || defined(ARDUINO_NANO_RP2040_CONNECT)

#if defined(TARGET_PORTENTA_H7_M7)
#if defined(ESP32) || defined(TARGET_PORTENTA_H7_M7)
#include <WiFi.h>
#include <WiFiUdp.h>
#else defined(ARDUINO_NANO_RP2040_CONNECT)
#elif defined(ARDUINO_NANO_RP2040_CONNECT)
#include <SPI.h>
#include <WiFiNINA.h>
#endif
Expand All @@ -102,10 +102,12 @@ struct micro_ros_agent_locator {
};

static inline void set_microros_wifi_transports(char * ssid, char * pass, char * agent_ip, uint agent_port){
while (WiFi.begin(ssid, pass) != WL_CONNECTED)
{
delay(500);
}

WiFi.begin(ssid, pass);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
}

static struct micro_ros_agent_locator locator;
locator.address.fromString(agent_ip);
Expand Down
6 changes: 3 additions & 3 deletions src/wifi_transport.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#if defined(TARGET_PORTENTA_H7_M7) || defined(ARDUINO_NANO_RP2040_CONNECT)
#if defined(ESP32) || defined(TARGET_PORTENTA_H7_M7) || defined(ARDUINO_NANO_RP2040_CONNECT)

#include <Arduino.h>


#if defined(TARGET_PORTENTA_H7_M7)
#if defined(ESP32) || defined(TARGET_PORTENTA_H7_M7)
#include <WiFi.h>
#include <WiFiUdp.h>
#else defined(ARDUINO_NANO_RP2040_CONNECT)
#elif defined(ARDUINO_NANO_RP2040_CONNECT)
#include <SPI.h>
#include <WiFiNINA.h>
#endif
Expand Down