Skip to content

Commit

Permalink
pkg/esp32_sdk: add ESP32 SDK without libraries as package
Browse files Browse the repository at this point in the history
The vendor binary libraries of ESP-IDF are provided as a separate GIT repository. These libraries are defined as separate package for two reasons: 1. RIOT packages don't support to clone GIT repositories recursively; 2. ESP-IDF pulls a lot of other GIT repositories that are not needed when it is cloned recursively.
  • Loading branch information
gschorcht committed Jan 1, 2022
1 parent fded044 commit b639123
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 36 deletions.
1 change: 1 addition & 0 deletions cpu/esp32/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ config CPU_FAM_ESP32
select HAS_PERIPH_RTT_SET_COUNTER
select HAS_PERIPH_RTT_OVERFLOW

select PACKAGE_ESP32_SDK if TEST_KCONFIG
select MODULE_PERIPH_RTT if HAS_PERIPH_RTT && MODULE_PM_LAYERED
select MODULE_RTT_RTC if HAS_PERIPH_RTT && MODULE_PERIPH_RTC
select MODULE_PS if MODULE_SHELL
Expand Down
1 change: 1 addition & 0 deletions cpu/esp32/Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

include $(RIOTCPU)/esp_common/Makefile.dep

USEPKG += esp32_sdk
USEMODULE += esp_idf_driver
USEMODULE += esp_idf_esp32
USEMODULE += esp_idf_soc
Expand Down
9 changes: 0 additions & 9 deletions cpu/esp32/Makefile.include
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
# check some environment variables first
ifndef ESP32_SDK_DIR
$(info ESP32_SDK_DIR should be defined as /path/to/esp-idf directory)
$(info ESP32_SDK_DIR is set by default to /opt/esp/esp-idf)
export ESP32_SDK_DIR=/opt/esp/esp-idf
endif

ESP_SDK_DIR = $(ESP32_SDK_DIR)

# ESP32 specific flashing options
FLASH_CHIP = esp32
FLASH_MODE ?= dout
Expand Down
28 changes: 5 additions & 23 deletions cpu/esp32/doc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -408,31 +408,13 @@ export PATH=$PATH:$HOME/esp/xtensa-esp32-elf/bin

[Back to table of contents](#esp32_toc)

### Installation of ESP-IDF (Espressif IoT Development Framework) {#esp32_installation_of_esp_idf}
### ESP-IDF (Espressif IoT Development Framework) {#esp32_installation_of_esp_idf}

ESP-IDF, the official SDK from Espressif, can be downloaded and installed as GIT repository.
RIOT-OS uses the ESP-IDF, the official SDK from Espressif, as part of the
build. It is downloaded as a package at build-time and there is no need to
install it separately.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cd $HOME/esp
git clone https://github.com/espressif/esp-idf.git
cd esp-idf
git checkout f198339ec09e90666150672884535802304d23ec
git submodule init
git submodule update
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

@note Please take care to checkout correct branches which were used for the port. Newer versions
might also work but were not tested.

Since we only use a few header files, ESP-IDF does not need to be compiled in any way. To use the
installed ESP-IDF, just set the variable `ESP32_SDK_DIR` accordingly.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
export ESP32_SDK_DIR=$HOME/esp/esp-idf
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

[Back to table of contents](#esp32_toc)

### Installation of esptool.py (ESP flash programmer tool) {#esp32_installation_of_esptool}
### Installation of `esptool.py` (ESP flash programmer tool) {#esp32_installation_of_esptool}

The RIOT port does not work with the `esptool.py` ESP flasher program
available on [GitHub](https://github.com/espressif/esptool) or
Expand Down
8 changes: 4 additions & 4 deletions cpu/esp_common/Makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ CFLAGS += $(if $(findstring dout,$(FLASH_MODE)),-DFLASH_MODE_DOUT=1)
ARCHIVES += -lhal -lg -lc

LINKFLAGS += $(CFLAGS_OPT) $(CFLAGS_DBG)
ifneq ($(CPU),esp8266)
#ifneq ($(CPU),esp8266)
# esp8266 flags are added by the SDK pkg in pkg/esp8266_sdk
LINKFLAGS += -L$(ESP_SDK_DIR)/components/$(CPU)
LINKFLAGS += -L$(ESP_SDK_DIR)/components/$(CPU)/lib
endif
#LINKFLAGS += -L$(ESP_SDK_DIR)/components/$(CPU)
#LINKFLAGS += -L$(ESP_SDK_DIR)/components/$(CPU)/lib
#endif
LINKFLAGS += -nostdlib -Wl,-gc-sections -Wl,-static

# use the wrapper functions for calloc to add correct overflow detection missing
Expand Down
1 change: 1 addition & 0 deletions pkg/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ rsource "driver_bme680/Kconfig"
rsource "driver_sx126x/Kconfig"
rsource "elk/Kconfig"
rsource "emlearn/Kconfig"
rsource "esp32_sdk/Kconfig"
rsource "esp8266_sdk/Kconfig"
rsource "fff/Kconfig"
rsource "gecko_sdk/Kconfig"
Expand Down
13 changes: 13 additions & 0 deletions pkg/esp32_sdk/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (c) 2021 Gunar Schorcht
#
# This file is subject to the terms and conditions of the GNU Lesser
# General Public License v2.1. See the file LICENSE in the top level
# directory for more details.
#

config PACKAGE_ESP32_SDK
bool "ESP32 SDK for the ESP32 MCU support"
depends on TEST_KCONFIG
depends on HAS_ARCH_ESP32
help
Vendor SDK without libraries for ESP32 MCU support by Espressif
32 changes: 32 additions & 0 deletions pkg/esp32_sdk/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
PKG_NAME=esp32_sdk
PKG_URL=https://github.com/espressif/esp-idf
# This is a version in the v3.1 beta1 release branch
PKG_VERSION=f198339ec09e90666150672884535802304d23ec
PKG_LICENSE=Apache-2.0

include $(RIOTBASE)/pkg/pkg.mk

# This directory is shared across all apps since there's no need to replicate
# these libraries on each app.
ESP32_SDK_BUILD_DIR = $(PKG_SOURCE_DIR)/build-libs
ESP32_SDK_VER_FILE = $(PKG_SOURCE_DIR)/components/esp32_idf_version.h
ESP32_SDK_VER_CMD = $(shell git -C $(PKG_SOURCE_DIR) describe --tags $(PKG_VERSION))

# We need to place all binary libraries shipped with the SDK in a common
# directory.
ESP32_SDK_COMPONENT_LIBS = libhal.a

ESP32_SDK_LIBS = $(addprefix $(ESP32_SDK_BUILD_DIR)/, $(ESP32_SDK_COMPONENT_LIBS))

all: $(ESP32_SDK_LIBS) $(ESP32_SDK_VER_FILE)

$(ESP32_SDK_BUILD_DIR):
$(Q)mkdir -p $(ESP32_SDK_BUILD_DIR)

# Set the SDK version from the SDK hash/tag. For example "v3.1-51-g913a06a9".
$(ESP32_SDK_VER_FILE):
$(Q)echo "#define IDF_VER \"$(ESP32_SDK_VER_CMD)\"" > $@

$(ESP32_SDK_BUILD_DIR)/lib%.a: \
$(PKG_SOURCE_DIR)/components/esp32/lib%.a | $(ESP32_SDK_BUILD_DIR)
$(Q)cp $? $(ESP32_SDK_BUILD_DIR)
2 changes: 2 additions & 0 deletions pkg/esp32_sdk/Makefile.dep
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# This package can only be used with the ESP32 CPU
FEATURES_REQUIRED += arch_esp32
24 changes: 24 additions & 0 deletions pkg/esp32_sdk/Makefile.include
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Directory with the SDK source checkout. Some modules in the cpu/esp32 use
# internal parts of the SDK and for that they need access to the
# ESP32_SDK_DIR path.
export ESP32_SDK_DIR = $(PKGDIRBASE)/esp32_sdk

# Directory where we built the modified libraries and headers.
ESP32_SDK_BUILD_DIR ?= $(ESP32_SDK_DIR)/build-libs

INCLUDES += -I$(ESP32_SDK_DIR)/components
INCLUDES += -I$(ESP32_SDK_DIR)/components/driver/include
INCLUDES += -I$(ESP32_SDK_DIR)/components/esp32/include
INCLUDES += -I$(ESP32_SDK_DIR)/components/heap/include
INCLUDES += -I$(ESP32_SDK_DIR)/components/soc/esp32/include
INCLUDES += -I$(ESP32_SDK_DIR)/components/soc/include

ifneq (,$(filter esp_eth,$(USEMODULE)))
INCLUDES += -I$(ESP32_SDK_DIR)/components/ethernet/include
endif

# Modified binary libraries are built here in the Makefile.
LINKFLAGS += -L$(ESP32_SDK_BUILD_DIR)

# esp32_sdk doesn't generate any .a
PSEUDOMODULES += esp32_sdk
6 changes: 6 additions & 0 deletions pkg/esp32_sdk/doc.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* @defgroup pkg_esp32_sdk ESP32 SDK for the ESP32 MCU support
* @ingroup pkg
* @brief Vendor SDK without libraries for ESP32 MCU support by Espressif
* @see https://github.com/espressif/esp-idf
*/

0 comments on commit b639123

Please sign in to comment.