Skip to content

Commit

Permalink
Add support for ESP32 IDF version 5.2 (beta) (#2694)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikee47 authored Jan 9, 2024
1 parent e890519 commit 8edfec9
Show file tree
Hide file tree
Showing 20 changed files with 210 additions and 81 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-esp32.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
matrix:
os: [ubuntu-20.04, windows-latest]
variant: [esp32, esp32s2, esp32c3, esp32s3, esp32c2]
idf_version: ["4.3", "4.4", "5.0"]
idf_version: ["4.3", "4.4", "5.0", "5.2"]
exclude:
- variant: esp32s3
idf_version: "4.3"
Expand Down
5 changes: 5 additions & 0 deletions Sming/Arch/Esp32/Components/driver/uart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <driver/SerialBuffer.h>
#include <driver/periph_ctrl.h>
#include <soc/uart_channel.h>
#include <soc/uart_periph.h>
#include <BitManipulations.h>
#include <Data/Range.h>
#include <esp_systemapi.h>
Expand Down Expand Up @@ -567,7 +568,11 @@ uint32_t smg_uart_set_baudrate_reg(int uart_nr, uint32_t baud_rate)
uart_ll_set_baudrate(dev, baud_rate);
return uart_ll_get_baudrate(dev);
#else
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 2, 0)
uart_ll_set_sclk(dev, UART_SCLK_DEFAULT);
#else
uart_ll_set_sclk(dev, soc_module_clk_t(UART_SCLK_DEFAULT));
#endif
uart_ll_set_baudrate(dev, baud_rate, APB_CLK_FREQ);
return uart_ll_get_baudrate(dev, APB_CLK_FREQ);
#endif
Expand Down
113 changes: 96 additions & 17 deletions Sming/Arch/Esp32/Components/esp32/component.mk
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,21 @@ ifeq ($(CREATE_EVENT_TASK),1)
COMPONENT_CPPFLAGS += -DCREATE_EVENT_TASK
endif

IDF_VERSION := $(firstword $(subst -, ,$(IDF_VER)))
IDF_VERSION_4 := $(filter v4%,$(IDF_VERSION))
ifneq (,$(filter v4.%,$(IDF_VERSION)))
IDF_VERSION_4x := 1
ifneq (,$(filter v4.3%,$(IDF_VERSION)))
IDF_VERSION_43 := 1
else ifneq (,$(filter v4.4%,$(IDF_VERSION)))
IDF_VERSION_44 := 1
endif
else ifneq (,$(filter v5.%,$(IDF_VERSION)))
IDF_VERSION_5x := 1
endif
ifneq (,$(filter v5.0%,$(IDF_VERSION)))
IDF_VERSION_50 := 1
else ifneq (,$(filter v5.2%,$(IDF_VERSION)))
IDF_VERSION_52 := 1
endif

ifneq (,$(filter esp32s3-v4.3%,$(ESP_VARIANT)-$(IDF_VER)))
$(error esp32s3 requires ESP IDF v4.4 or later)
Expand All @@ -32,6 +45,7 @@ SDKCONFIG_H := $(SDK_BUILD_BASE)/config/sdkconfig.h

SDK_LIBDIRS := \
esp_wifi/lib/$(ESP_VARIANT) \
esp_coex/lib/$(ESP_VARIANT) \
esp_phy/lib/$(ESP_VARIANT) \
xtensa/$(ESP_VARIANT) \
hal/$(ESP_VARIANT) \
Expand All @@ -52,6 +66,12 @@ endif
ESP32_COMPONENT_PATH := $(COMPONENT_PATH)
SDK_DEFAULT_PATH := $(ESP32_COMPONENT_PATH)/sdk

ifdef IDF_VERSION_52
GLOBAL_CFLAGS += \
-DSOC_XTAL_FREQ_MHZ=CONFIG_XTAL_FREQ \
-DSOC_MMU_PAGE_SIZE=CONFIG_MMU_PAGE_SIZE
endif

LIBDIRS += \
$(SDK_COMPONENT_LIBDIR) \
$(SDK_BUILD_BASE)/esp-idf/mbedtls/mbedtls/library \
Expand All @@ -65,13 +85,10 @@ LIBDIRS += \
SDK_INCDIRS := \
app_update/include \
bootloader_support/include \
bootloader_support/include_bootloader \
driver/$(ESP_VARIANT)/include \
driver/include \
esp_pm/include \
esp_rom/include/$(ESP_VARIANT) \
esp_rom/include \
$(ESP_VARIANT)/include \
esp_ringbuf/include \
esp_timer/include \
soc/include \
Expand All @@ -82,27 +99,44 @@ SDK_INCDIRS := \
nvs_flash/include \
esp_event/include \
lwip/lwip/src/include \
lwip/port/esp32/include \
newlib/platform_include \
spi_flash/include \
wpa_supplicant/include \
wpa_supplicant/port/include \
esp_hw_support/include \
esp_hw_support/include/soc \
hal/include \
hal/platform_port/include \
hal/$(ESP_VARIANT)/include \
esp_system/include \
esp_common/include \
esp_netif/include \
esp_eth/include \
esp_wifi/include \
lwip/include/apps/sntp

ifdef IDF_VERSION_4x
SDK_INCDIRS += \
$(ESP_VARIANT)/include
endif

ifdef IDF_VERSION_43
SDK_INCDIRS += \
esp_wifi/esp32/include \
lwip/include/apps/sntp \
wpa_supplicant/include/esp_supplicant
else
SDK_INCDIRS += \
hal/platform_port/include
endif

ifdef IDF_VERSION_4
ifndef IDF_VERSION_52
SDK_INCDIRS += \
driver/$(ESP_VARIANT)/include \
lwip/port/esp32/include
endif

ifdef IDF_VERSION_4x
SDK_INCDIRS += \
bootloader_support/include_bootloader \
esp_adc_cal/include \
esp_ipc/include \
freertos/include \
Expand All @@ -119,13 +153,29 @@ SDK_INCDIRS += \
freertos/esp_additions/include/freertos \
driver/deprecated
FREERTOS_PORTABLE := freertos/FreeRTOS-Kernel/portable
ifeq (v5.2,$(IDF_VERSION))
SDK_INCDIRS += \
driver/gpio/include \
driver/ledc/include \
driver/spi/include \
lwip/port/include \
lwip/port/freertos/include \
lwip/port/esp32xx/include \
esp_bootloader_format/include \
esp_adc/$(ESP_VARIANT)/include \
freertos/config/include \
freertos/config/include/freertos
endif
endif



ifeq ($(ENABLE_BLUETOOTH),1)
ifeq (esp32s3-v5.2,$(ESP_VARIANT)-$(IDF_VERSION))
ESP_BT_VARIANT := esp32c3
else
ESP_BT_VARIANT := $(ESP_VARIANT)
endif
SDK_INCDIRS += \
bt/include/$(ESP_VARIANT)/include \
bt/include/$(ESP_BT_VARIANT)/include \
bt/common/api/include/api \
bt/common/btc/profile/esp/blufi/include \
bt/common/btc/profile/esp/include \
Expand All @@ -148,17 +198,31 @@ SDK_INCDIRS += \
bt/host/nimble/nimble/nimble/host/store/config/include \
bt/host/nimble/esp-hci/include \
bt/host/nimble/port/include
ifdef IDF_VERSION_52
SDK_INCDIRS += \
bt/host/nimble/nimble/nimble/transport/include
endif
endif

ifdef IDF_TARGET_ARCH_RISCV
SDK_INCDIRS += \
$(FREERTOS_PORTABLE)/riscv/include \
$(FREERTOS_PORTABLE)/riscv/include/freertos \
freertos/config/riscv \
freertos/config/riscv/include \
riscv/include
else
SDK_INCDIRS += \
xtensa/include \
xtensa/$(ESP_VARIANT)/include \
$(FREERTOS_PORTABLE)/xtensa/include
$(FREERTOS_PORTABLE)/xtensa/include \
$(FREERTOS_PORTABLE)/xtensa/include/freertos
ifdef IDF_VERSION_52
SDK_INCDIRS += \
freertos/config/xtensa \
freertos/config/xtensa/include \
xtensa/deprecated_include
endif
endif


Expand Down Expand Up @@ -193,13 +257,13 @@ SDK_COMPONENTS := \
soc \
spi_flash

ifneq (,$(filter v4.3%,$(IDF_VERSION)))
ifdef IDF_VERSION_43
SDK_COMPONENTS += $(ESP_VARIANT)
else
SDK_COMPONENTS += esp_phy
endif

ifdef IDF_VERSION_4
ifdef IDF_VERSION_4x
SDK_COMPONENTS += \
esp_ipc \
esp_adc_cal
Expand All @@ -210,6 +274,12 @@ SDK_COMPONENTS += \
esp_partition
endif

ifeq (v5.2,$(IDF_VERSION))
SDK_COMPONENTS += \
esp_mm \
esp_coex
endif


ifneq ($(DISABLE_NETWORK),1)
SDK_COMPONENTS += \
Expand Down Expand Up @@ -302,10 +372,14 @@ LDFLAGS_esp32s3 := \
LDFLAGS_esp32c2 := \
$(call LinkerScript,rom.newlib) \
$(call LinkerScript,rom.version) \
$(call LinkerScript,rom.newlib-time) \
$(call LinkerScript,rom.heap) \
$(call LinkerScript,rom.mbedtls)

ifneq (v5.2,$(IDF_VERSION))
LDFLAGS_esp32c2 += \
$(call LinkerScript,rom.newlib-time)
endif

SDK_WRAP_SYMBOLS :=
SDK_UNDEF_SYMBOLS :=

Expand All @@ -329,7 +403,7 @@ EXTRA_LDFLAGS := \
$(call Undef,$(SDK_UNDEF_SYMBOLS)) \
$(call Wrap,$(SDK_WRAP_SYMBOLS))

ifneq (,$(filter v4.3%,$(IDF_VERSION)))
ifdef IDF_VERSION_43
EXTRA_LDFLAGS += \
-T $(ESP_VARIANT)_out.ld \
$(call LinkerScript,project)
Expand Down Expand Up @@ -440,3 +514,8 @@ sdk-help: ##Get SDK build options
.PHONY: sdk
sdk: ##Pass options to IDF builder, e.g. `make sdk -- --help` or `make sdk menuconfig`
$(Q) $(SDK_BUILD) $(filter-out sdk,$(MAKECMDGOALS))


.PHONY: check-incdirs
check-incdirs: ##Check IDF include paths and report any not found in this SDK version
$(Q) $(foreach d,$(SDK_INCDIRS),$(if $(wildcard $(SDK_COMPONENTS_PATH)/$d),,$(info $d)))
6 changes: 4 additions & 2 deletions Sming/Arch/Esp32/Components/esp32/src/clk.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@
#include <esp_pm.h>
#include <debug_progmem.h>

#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 2, 0)
#define EXPAND(a) a
#define CONCAT3a(a, b, c) a##b##c
#define CONCAT3(a, b, c) CONCAT3a(a, b, c)
typedef CONCAT3(esp_pm_config_, SMING_SOC, _t) pm_config_t;
typedef CONCAT3(esp_pm_config_, SMING_SOC, _t) esp_pm_config_t;
#endif

int esp_clk_cpu_freq(void);

static esp_pm_lock_handle_t handle;

bool system_update_cpu_freq(uint32_t freq)
{
pm_config_t config = {};
esp_pm_config_t config = {};
esp_err_t err = esp_pm_get_configuration(&config);
if(err != ESP_OK) {
debug_e("[PM] Failed to read PM config %u", err);
Expand Down
8 changes: 6 additions & 2 deletions Sming/Arch/Esp32/Core/Digital.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
#include <driver/rtc_io.h>
#if SOC_RTCIO_INPUT_OUTPUT_SUPPORTED
#include <hal/rtc_io_ll.h>
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 2, 0)
#define RTCIO_LL_FUNC_RTC RTCIO_FUNC_RTC
#define RTCIO_LL_FUNC_DIGITAL RTCIO_FUNC_DIGITAL
#endif
#endif

void pinMode(uint16_t pin, uint8_t mode)
Expand All @@ -38,7 +42,7 @@ void pinMode(uint16_t pin, uint8_t mode)
return; // Already in ADC mode
}

rtcio_ll_function_select(rtc, RTCIO_FUNC_RTC);
rtcio_ll_function_select(rtc, RTCIO_LL_FUNC_RTC);
rtcio_ll_input_disable(rtc);
rtcio_ll_output_disable(rtc);
rtcio_ll_pullup_disable(rtc);
Expand All @@ -48,7 +52,7 @@ void pinMode(uint16_t pin, uint8_t mode)
}

if(rtc >= 0) {
rtcio_ll_function_select(rtc, RTCIO_FUNC_DIGITAL);
rtcio_ll_function_select(rtc, RTCIO_LL_FUNC_DIGITAL);
rtcio_ll_pulldown_disable(rtc);
if(mode == INPUT_PULLUP) {
rtcio_ll_pullup_enable(rtc);
Expand Down
16 changes: 9 additions & 7 deletions Sming/Arch/Esp32/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ Build variables
Requirements
------------

In order to be able to compile for the ESP32 architecture you should have ESP-IDF v4.3 installed.
Some slight changes are required to enable code to compile correctly for C++,
so a fork has been created here https://github.com/mikee47/esp-idf/tree/sming/release/v4.3
which you may clone.
Sming requires a slightly modified version of the Espressif SDK.
You can find the SDK here https://github.com/mikee47/esp-idf/tree/sming/release/v5.2.
See `idf_versions`_ below for further details.

The Sming installers do all this for you - see :doc:`/getting-started/index`.
Using the Sming installation scripts are the recommended way to install these SDK versions.
See :doc:`/getting-started/index`.

You can find further details in the `ESP-IDF documentation <https://docs.espressif.com/projects/esp-idf/en/v4.3/get-started/index.html#installation-step-by-step>`__.

Expand Down Expand Up @@ -101,14 +101,16 @@ Each variant uses a different build directory, e.g. ``out/Esp32/esp32c3/...`` to
See :component-esp32:`esp32` for further details.


.. _idf_versions:

IDF versions
------------

Sming currently supports IDF versions 4.3, 4.4 and 5.0.
Sming currently supports IDF versions 4.3, 4.4, 5.0 and 5.2.

The default installed IDF version is 4.4. This can be changed as follows::

INSTALL_IDF_VER=5.0 $SMING_HOME/../Tools/install.sh esp32
INSTALL_IDF_VER=5.2 $SMING_HOME/../Tools/install.sh esp32

The installation script creates a soft-link in ``/opt/esp-idf`` pointing to the last version installed.
Use the `IDF_PATH` environment variable or change the soft-link to select which one to use.
Expand Down
2 changes: 1 addition & 1 deletion Sming/Arch/Esp32/Tools/ci/build.run.cmd
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
REM Esp32 build.run.cmd

%MAKE_PARALLEL% Basic_Blink Basic_Ethernet Basic_WiFi HttpServer_ConfigNetwork DEBUG_VERBOSE_LEVEL=3 STRICT=1 || goto :error
%MAKE_PARALLEL% Basic_Ssl ENABLE_SSL=Bearssl DEBUG_VERBOSE_LEVEL=3 STRICT=1 || goto :error
%MAKE_PARALLEL% Basic_Ssl ENABLE_SSL=Axtls DEBUG_VERBOSE_LEVEL=3 STRICT=1 || goto :error

REM make sure that the Ota Library sample compiles for ESP32
%MAKE_PARALLEL% -C %SMING_HOME%\Libraries\OtaUpgradeMqtt\samples\Upgrade
Expand Down
28 changes: 16 additions & 12 deletions Sming/Arch/Esp32/Tools/idf_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,23 @@ def get_tool_info(soc):

compiler_prefix = None
compiler_version = None
gcc_path = gdb_path = None
for tool in tools_info['tools']:
if soc in tool['supported_targets']:
desc = tool['description']
if desc.startswith('Toolchain'):
compiler_prefix = tool['name']
compiler_version = tool['versions'][0]['name']
break
print(f"{compiler_prefix} {compiler_version}")

# ESP32_COMPILER_PREFIX=compiler_prefix
# IDF_TARGET_ARCH_RISCV=is_riscv


if tool.get('install') != 'always':
continue
if soc not in tool['supported_targets']:
continue
desc = tool['description'].lower()
export_path = "/".join(tool['export_paths'][0])
tool_name = tool['name']
tool_version = tool['versions'][0]['name']
path = f"{tool_name}/{tool_version}/{export_path}"
if 'gcc' in desc and not gcc_path:
gcc_path = path
if 'gdb' in desc and not gdb_path:
gdb_path = path

print(gcc_path, gdb_path)


if __name__ == '__main__':
Expand Down
Loading

0 comments on commit 8edfec9

Please sign in to comment.