From 6e172d5aa2e23872c30d07c4238f3e36773468b4 Mon Sep 17 00:00:00 2001 From: Pablo Garrido Date: Wed, 31 Mar 2021 15:33:31 +0200 Subject: [PATCH] ESP32c3 support (#52) * Initial * Update readme * Avoid low consumption in esp32c3 Update * Increase Stack size and update readme for ESP32C3 Co-authored-by: Antonio cuadros --- .github/workflows/ci.yml | 7 ++++++- .github/workflows/nightly.yml | 6 +++++- README.md | 4 +++- esp32_toolchain.cmake.in | 18 +++++++++++++----- .../int32_publisher/main/Kconfig.projbuild | 2 +- .../main/Kconfig.projbuild | 2 +- .../low_consumption/main/Kconfig.projbuild | 2 +- examples/low_consumption/main/main.c | 2 ++ libmicroros.mk | 6 +++--- 9 files changed, 35 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 17faf8da..8b8b571e 100755 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,11 +12,15 @@ jobs: strategy: fail-fast: false matrix: - idf_target: [ esp32, esp32s2 ] + idf_target: [ esp32, esp32s2, esp32c3] idf_version: [ "espressif/idf:release-v4.1", "espressif/idf:release-v4.2", "espressif/idf:release-v4.3", "espressif/idf:latest" ] exclude: - idf_target: esp32s2 idf_version: "espressif/idf:release-v4.1" + - idf_target: esp32c3 + idf_version: "espressif/idf:release-v4.1" + - idf_target: esp32c3 + idf_version: "espressif/idf:release-v4.2" container: image: ${{ matrix.idf_version }} @@ -48,6 +52,7 @@ jobs: - name: Build sample - low_consumption shell: bash + if: matrix.idf_target != 'esp32c3' run: | . $IDF_PATH/export.sh cd micro_ros_espidf_component/examples/low_consumption diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index e1c806af..08daac3c 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -15,11 +15,15 @@ jobs: fail-fast: false matrix: branch: [foxy, main] - idf_target: [ esp32, esp32s2 ] + idf_target: [ esp32, esp32s2, esp32c3] idf_version: [ "espressif/idf:release-v4.1", "espressif/idf:release-v4.2", "espressif/idf:release-v4.3", "espressif/idf:latest" ] exclude: - idf_target: esp32s2 idf_version: "espressif/idf:release-v4.1" + - idf_target: esp32c3 + idf_version: "espressif/idf:release-v4.1" + - idf_target: esp32c3 + idf_version: "espressif/idf:release-v4.2" container: image: ${{ matrix.idf_version }} diff --git a/README.md b/README.md index db52ea69..89c0cc49 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # micro-ROS component for ESP-IDF -This component has been tested in ESP-IDF v4.1, v4.2 and v4.3 with ESP32 and ESP32-S2. +This component has been tested in ESP-IDF v4.1, v4.2 and v4.3 with ESP32, ESP32-S2 and ESP32-C3. ## Dependencies @@ -32,6 +32,8 @@ In order to test a int32_publisher example: ```bash . $IDF_PATH/export.sh cd examples/int32_publisher +# Set target board [esp32|esp32s2|esp32c3] +idf.py set-target esp32 idf.py menuconfig # Set your micro-ROS configuration and WiFi credentials under micro-ROS Settings idf.py build diff --git a/esp32_toolchain.cmake.in b/esp32_toolchain.cmake.in index 39f34e53..a7b418d5 100644 --- a/esp32_toolchain.cmake.in +++ b/esp32_toolchain.cmake.in @@ -1,7 +1,15 @@ include(CMakeForceCompiler) set(CMAKE_SYSTEM_NAME Generic) -set(CMAKE_SYSTEM_PROCESSOR xtensa) + +set(idf_target "@IDF_TARGET@") + +if("${idf_target}" STREQUAL "esp32c3") + set(CMAKE_SYSTEM_PROCESSOR riscv) +else() + set(CMAKE_SYSTEM_PROCESSOR xtensa) +endif() + set(CMAKE_CROSSCOMPILING 1) set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) set(PLATFORM_NAME "LwIP") @@ -24,7 +32,7 @@ add_definitions(-DLWIP_IPV4 -DLWIP_IPV6) include_directories( "@BUILD_CONFIG_DIR@" ${idf_path}/components/soc/soc/include - ${idf_path}/components/freertos/port/xtensa/include + ${idf_path}/components/freertos/port/${CMAKE_SYSTEM_PROCESSOR}/include ${idf_path}/components/hal/${idf_target}/include ${idf_path}/components/hal/include ${idf_path}/components/esp_hw_support/include @@ -40,7 +48,7 @@ include_directories( ${idf_path}/components/vfs/include ${idf_path}/components/log/include ${idf_path}/components/freertos/include - ${idf_path}/components/freertos/xtensa/include + ${idf_path}/components/freertos/${CMAKE_SYSTEM_PROCESSOR}/include ${idf_path}/components/soc/soc/${idf_target}/include ${idf_path}/components/wifi_provisioning/include ${idf_path}/components/pthread/include @@ -60,8 +68,8 @@ include_directories( ${idf_path}/components/efuse/include ${idf_path}/components/mbedtls/port/include ${idf_path}/components/mbedtls/mbedtls/include - ${idf_path}/components/xtensa/${idf_target}/include - ${idf_path}/components/xtensa/include + ${idf_path}/components/${CMAKE_SYSTEM_PROCESSOR}/${idf_target}/include + ${idf_path}/components/${CMAKE_SYSTEM_PROCESSOR}/include ${idf_path}/components/app_trace/include ${idf_path}/components/nvs_flash/include ${idf_path}/components/jsmn/include diff --git a/examples/int32_publisher/main/Kconfig.projbuild b/examples/int32_publisher/main/Kconfig.projbuild index 3e787833..1ee6dcf2 100644 --- a/examples/int32_publisher/main/Kconfig.projbuild +++ b/examples/int32_publisher/main/Kconfig.projbuild @@ -2,7 +2,7 @@ menu "micro-ROS example-app settings" config MICRO_ROS_APP_STACK int "Stack the micro-ROS app (Bytes)" - default 15000 + default 16000 help Stack size in Bytes of the micro-ROS app diff --git a/examples/int32_publisher_custom_transport/main/Kconfig.projbuild b/examples/int32_publisher_custom_transport/main/Kconfig.projbuild index 3e787833..1ee6dcf2 100644 --- a/examples/int32_publisher_custom_transport/main/Kconfig.projbuild +++ b/examples/int32_publisher_custom_transport/main/Kconfig.projbuild @@ -2,7 +2,7 @@ menu "micro-ROS example-app settings" config MICRO_ROS_APP_STACK int "Stack the micro-ROS app (Bytes)" - default 15000 + default 16000 help Stack size in Bytes of the micro-ROS app diff --git a/examples/low_consumption/main/Kconfig.projbuild b/examples/low_consumption/main/Kconfig.projbuild index 3e787833..1ee6dcf2 100644 --- a/examples/low_consumption/main/Kconfig.projbuild +++ b/examples/low_consumption/main/Kconfig.projbuild @@ -2,7 +2,7 @@ menu "micro-ROS example-app settings" config MICRO_ROS_APP_STACK int "Stack the micro-ROS app (Bytes)" - default 15000 + default 16000 help Stack size in Bytes of the micro-ROS app diff --git a/examples/low_consumption/main/main.c b/examples/low_consumption/main/main.c index 74b22c49..0490f8e2 100644 --- a/examples/low_consumption/main/main.c +++ b/examples/low_consumption/main/main.c @@ -117,6 +117,8 @@ void app_main(void) // automatic light sleep is enabled if tickless idle support is enabled. #ifdef CONFIG_IDF_TARGET_ESP32S2 esp_pm_config_esp32s2_t pm_config = {}; +#elif CONFIG_IDF_TARGET_ESP32C3 + esp_pm_config_esp32c3_t pm_config = {}; #else esp_pm_config_esp32_t pm_config = {}; #endif diff --git a/libmicroros.mk b/libmicroros.mk index 0e79e0ce..ecacc7d3 100644 --- a/libmicroros.mk +++ b/libmicroros.mk @@ -90,9 +90,9 @@ $(EXTENSIONS_DIR)/micro_ros_src/install: $(EXTENSIONS_DIR)/esp32_toolchain.cmake -DCMAKE_TOOLCHAIN_FILE=$(EXTENSIONS_DIR)/esp32_toolchain.cmake \ -DCMAKE_VERBOSE_MAKEFILE=OFF; \ -patch_atomic_esp32s2:$(EXTENSIONS_DIR)/micro_ros_src/install +patch_atomic:$(EXTENSIONS_DIR)/micro_ros_src/install # Workaround https://github.com/micro-ROS/micro_ros_espidf_component/issues/18 -ifeq ($(IDF_TARGET), esp32s2) +ifeq ($(IDF_TARGET),$(filter $(IDF_TARGET),esp32s2 esp32c3)) echo $(UROS_DIR)/atomic_workaround; \ mkdir $(UROS_DIR)/atomic_workaround; cd $(UROS_DIR)/atomic_workaround; \ $(AR) x $(UROS_DIR)/install/lib/librcutils.a; \ @@ -103,7 +103,7 @@ ifeq ($(IDF_TARGET), esp32s2) cd ..; endif -$(EXTENSIONS_DIR)/libmicroros.a: $(EXTENSIONS_DIR)/micro_ros_src/install patch_atomic_esp32s2 +$(EXTENSIONS_DIR)/libmicroros.a: $(EXTENSIONS_DIR)/micro_ros_src/install patch_atomic mkdir -p $(UROS_DIR)/libmicroros; cd $(UROS_DIR)/libmicroros; \ for file in $$(find $(UROS_DIR)/install/lib/ -name '*.a'); do \ folder=$$(echo $$file | sed -E "s/(.+)\/(.+).a/\2/"); \