Skip to content
This repository was archived by the owner on Dec 8, 2022. It is now read-only.

ESP-IDF release v4.2 upgrade and support for ESP32-S2 #2285

Closed
Closed
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
5 changes: 3 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
branch = v2.4.3
[submodule "freertos_kernel"]
path = freertos_kernel
url = https://github.com/FreeRTOS/FreeRTOS-Kernel.git
url = https://github.com/shubhamkulkarni97/FreeRTOS-Kernel.git
branch = bugfix/upleveling_changes
[submodule "pkcs11"]
path = libraries/3rdparty/pkcs11
url = https://github.com/amazon-freertos/pkcs11.git
Expand All @@ -22,7 +23,7 @@
[submodule "vendors/espressif/esp-idf"]
path = vendors/espressif/esp-idf
url = https://github.com/espressif/esp-afr-sdk.git
branch = release/v3.3
branch = release/v4.2
[submodule "mbedtls"]
path = libraries/3rdparty/mbedtls
url = https://github.com/ARMmbed/mbedtls.git
Expand Down
2 changes: 1 addition & 1 deletion freertos_kernel
Submodule freertos_kernel updated 494 files
1 change: 0 additions & 1 deletion tools/cmake/toolchains/xtensa-esp32.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,5 @@ set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(AFR_COMPILER_NO_WARNINGS "-w" CACHE INTERNAL "")

# Global compiler flags.
set(CMAKE_EXE_LINKER_FLAGS "-nostdlib" CACHE STRING "Linker Base Flags")
set(CMAKE_C_FLAGS "-mlongcalls" CACHE STRING "C Compiler Base Flags")
set(CMAKE_CXX_FLAGS "-mlongcalls" CACHE STRING "C++ Compiler Base Flags")
31 changes: 31 additions & 0 deletions tools/cmake/toolchains/xtensa-esp32s2.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
include("${CMAKE_CURRENT_LIST_DIR}/find_compiler.cmake")

set(CMAKE_SYSTEM_NAME Generic)

# Find GCC for Xtensa-ESP32S2.
afr_find_compiler(AFR_COMPILER_CC xtensa-esp32s2-elf-gcc)
afr_find_compiler(AFR_COMPILER_CXX xtensa-esp32s2-elf-g++)

# Specify the cross compiler.
set(CMAKE_C_COMPILER ${AFR_COMPILER_CC} CACHE FILEPATH "C compiler")
set(CMAKE_CXX_COMPILER ${AFR_COMPILER_CXX} CACHE FILEPATH "C++ compiler")
set(CMAKE_ASM_COMPILER ${AFR_COMPILER_CC} CACHE FILEPATH "ASM compiler")

# Disable compiler checks.
set(CMAKE_C_COMPILER_FORCED TRUE)
set(CMAKE_CXX_COMPILER_FORCED TRUE)

# Add target system root to cmake find path.
get_filename_component(AFR_COMPILER_DIR "${AFR_COMPILER_CC}" DIRECTORY)
get_filename_component(CMAKE_FIND_ROOT_PATH "${AFR_COMPILER_DIR}" DIRECTORY)

# Look for includes and libraries only in the target system prefix.
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)

# Helper variables to abstracts some common compiler flags.
set(AFR_COMPILER_NO_WARNINGS "-w" CACHE INTERNAL "")

# Global compiler flags.
set(CMAKE_C_FLAGS "-mlongcalls" CACHE STRING "C Compiler Base Flags")
set(CMAKE_CXX_FLAGS "-mlongcalls" CACHE STRING "C++ Compiler Base Flags")
74 changes: 74 additions & 0 deletions vendors/espressif/boards/components/freertos/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
set(AMAZON_FREERTOS_KERNEL_DIR "${AFR_KERNEL_DIR}")
set(AMAZON_FREERTOS_FREERTOS_PLUS_DIR "${AFR_MODULES_FREERTOS_PLUS_DIR}")
set(AMAZON_FREERTOS_3RDPARTY_DIR "${AFR_3RDPARTY_DIR}")

string(FIND "${AFR_BOARD_NAME}" "esp32s2" SOC_NAME_ESP32S2)
string(FIND "${AFR_BOARD_NAME}" "esp32" SOC_NAME_ESP32)

if (NOT(${SOC_NAME_ESP32S2} EQUAL -1))
set(SOC_NAME "esp32s2")
elseif(NOT($SOC_NAME_ESP32) EQUAL -1)
set(SOC_NAME "esp32")
endif()

set(
include_dirs
include
${AMAZON_FREERTOS_KERNEL_DIR}/include
${AMAZON_FREERTOS_KERNEL_DIR}/portable/ThirdParty/GCC/Xtensa_ESP32/include
)

if(AFR_ENABLE_TESTS)
list(APPEND include_dirs
"${AMAZON_FREERTOS_FREERTOS_PLUS_DIR}/standard/freertos_plus_posix/include"
"${AMAZON_FREERTOS_3RDPARTY_DIR}/unity/src"
)
if(SOC_NAME STREQUAL "esp32s2")
list(APPEND include_dirs
"${CMAKE_CURRENT_LIST_DIR}/../../esp32s2/aws_tests/config_files"
)
else()
list(APPEND include_dirs
"${CMAKE_CURRENT_LIST_DIR}/../../esp32/aws_tests/config_files"
)
endif()

else()
if(SOC_NAME STREQUAL "esp32s2")
list(APPEND include_dirs
"${CMAKE_CURRENT_LIST_DIR}/../../esp32s2/aws_demos/config_files"
)
else()
list(APPEND include_dirs
"${CMAKE_CURRENT_LIST_DIR}/../../esp32/aws_demos/config_files"
)
endif()
endif()

# Edit following two lines to set component requirements (see docs)
set(COMPONENT_REQUIRES )
set(COMPONENT_PRIV_REQUIRES )

idf_component_register(SRCS "extra.c"
"${AMAZON_FREERTOS_KERNEL_DIR}/portable/ThirdParty/GCC/Xtensa_ESP32/FreeRTOS-openocd.c"
"${AMAZON_FREERTOS_KERNEL_DIR}/portable/ThirdParty/GCC/Xtensa_ESP32/port.c"
"${AMAZON_FREERTOS_KERNEL_DIR}/portable/ThirdParty/GCC/Xtensa_ESP32/portasm.S"
"${AMAZON_FREERTOS_KERNEL_DIR}/portable/ThirdParty/GCC/Xtensa_ESP32/xtensa_context.S"
"${AMAZON_FREERTOS_KERNEL_DIR}/portable/ThirdParty/GCC/Xtensa_ESP32/xtensa_init.c"
"${AMAZON_FREERTOS_KERNEL_DIR}/portable/ThirdParty/GCC/Xtensa_ESP32/xtensa_intr.c"
"${AMAZON_FREERTOS_KERNEL_DIR}/portable/ThirdParty/GCC/Xtensa_ESP32/xtensa_intr_asm.S"
"${AMAZON_FREERTOS_KERNEL_DIR}/portable/ThirdParty/GCC/Xtensa_ESP32/xtensa_loadstore_handler.S"
"${AMAZON_FREERTOS_KERNEL_DIR}/portable/ThirdParty/GCC/Xtensa_ESP32/xtensa_overlay_os_hook.c"
"${AMAZON_FREERTOS_KERNEL_DIR}/portable/ThirdParty/GCC/Xtensa_ESP32/xtensa_vector_defaults.S"
"${AMAZON_FREERTOS_KERNEL_DIR}/portable/ThirdParty/GCC/Xtensa_ESP32/xtensa_vectors.S"
"${AMAZON_FREERTOS_KERNEL_DIR}/croutine.c"
"${AMAZON_FREERTOS_KERNEL_DIR}/event_groups.c"
"${AMAZON_FREERTOS_KERNEL_DIR}/list.c"
"${AMAZON_FREERTOS_KERNEL_DIR}/queue.c"
"${AMAZON_FREERTOS_KERNEL_DIR}/stream_buffer.c"
"${AMAZON_FREERTOS_KERNEL_DIR}/tasks.c"
"${AMAZON_FREERTOS_KERNEL_DIR}/timers.c"
INCLUDE_DIRS "${include_dirs}"
LDFRAGMENTS linker.lf
REQUIRES app_trace esp_timer
PRIV_REQUIRES soc)
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ config FREERTOS_UNICORE

choice FREERTOS_CORETIMER
prompt "Xtensa timer to use as the FreeRTOS tick source"
default CONFIG_FREERTOS_CORETIMER_0
default FREERTOS_CORETIMER_0
help
FreeRTOS needs a timer with an associated interrupt to use as
the main tick source to increase counters, run timers and do
Expand All @@ -38,6 +38,14 @@ config FREERTOS_CORETIMER_1

endchoice

config FREERTOS_OPTIMIZED_SCHEDULER
bool "Enable FreeRTOS pĺatform optimized scheduler"
default y
help
On most platforms there are instructions can speedup the ready task
searching. Enabling this option the FreeRTOS with this instructions
support will be built

config FREERTOS_HZ
int "Tick rate (Hz)"
range 1 1000
Expand Down Expand Up @@ -206,7 +214,7 @@ config FREERTOS_MAX_TASK_NAME_LEN

For most uses, the default of 16 is OK.

config SUPPORT_STATIC_ALLOCATION
config FREERTOS_SUPPORT_STATIC_ALLOCATION
bool "Enable FreeRTOS static allocation API"
default n
help
Expand Down Expand Up @@ -234,9 +242,9 @@ config SUPPORT_STATIC_ALLOCATION
It allows the RTOS to be used in applications that simply don't allow any dynamic memory allocation
(although FreeRTOS includes allocation schemes that can overcome most objections).

config ENABLE_STATIC_TASK_CLEAN_UP_HOOK
config FREERTOS_ENABLE_STATIC_TASK_CLEAN_UP
bool "Enable static task clean up hook"
depends on SUPPORT_STATIC_ALLOCATION
depends on FREERTOS_SUPPORT_STATIC_ALLOCATION
default n
help
Enable this option to make FreeRTOS call the static task clean up hook when a task is deleted.
Expand All @@ -247,7 +255,7 @@ config ENABLE_STATIC_TASK_CLEAN_UP_HOOK
// place clean up code here
}

config TIMER_TASK_PRIORITY
config FREERTOS_TIMER_TASK_PRIORITY
int "FreeRTOS timer task priority"
range 1 25
default 1
Expand All @@ -258,7 +266,7 @@ config TIMER_TASK_PRIORITY

Use this constant to define the priority that the timer task will run at.

config TIMER_TASK_STACK_DEPTH
config FREERTOS_TIMER_TASK_STACK_DEPTH
int "FreeRTOS timer task stack size"
range 1536 32768
default 2048
Expand All @@ -269,7 +277,7 @@ config TIMER_TASK_STACK_DEPTH

Use this constant to define the size (in bytes) of the stack allocated for the timer task.

config TIMER_QUEUE_LENGTH
config FREERTOS_TIMER_QUEUE_LENGTH
int "FreeRTOS timer queue length"
range 5 20
default 10
Expand Down Expand Up @@ -385,6 +393,17 @@ config FREERTOS_IDLE_TIME_BEFORE_SLEEP
FreeRTOS will enter light sleep mode if no tasks need to run for this number
of ticks.

config FREERTOS_TASK_FUNCTION_WRAPPER
bool "Enclose all task functions in a wrapper function"
depends on COMPILER_OPTIMIZATION_DEFAULT
default y
help
If enabled, all FreeRTOS task functions will be enclosed in a wrapper function.
If a task function mistakenly returns (i.e. does not delete), the call flow will
return to the wrapper function. The wrapper function will then log an error and
abort the application. This option is also required for GDB backtraces and C++
exceptions to work correctly inside top-level task functions.

menuconfig FREERTOS_DEBUG_INTERNALS
bool "Debug FreeRTOS internals"
default n
Expand Down Expand Up @@ -414,4 +433,12 @@ endif #FREERTOS_UNICORE

endif # FREERTOS_DEBUG_INTERNALS

config FREERTOS_FPU_IN_ISR
bool "Allow use of float inside Level 1 ISR (EXPERIMENTAL)"
depends on IDF_TARGET_ESP32
default n
help
When enabled, the usage of float type is allowed inside Level 1
ISRs.

endmenu
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
AMAZON_FREERTOS_LIB_DIR := ../../../../../../libraries
AMAZON_FREERTOS_KERNEL_DIR := ../../../../../../freertos_kernel
AMAZON_FREERTOS_LIB_DIR := ../../../../../libraries
AMAZON_FREERTOS_KERNEL_DIR := ../../../../../freertos_kernel
ifndef AMAZON_FREERTOS_ENABLE_UNIT_TEST
AMAZON_FREERTOS_ESP32 := ../../../../../../vendors/espressif/boards/esp32/aws_demos
AMAZON_FREERTOS_ESP32 := ../../../../../vendors/espressif/boards/esp32/aws_demos
else
AMAZON_FREERTOS_ESP32 := ../../../../../../vendors/espressif/boards/esp32/aws_tests
AMAZON_FREERTOS_ESP32 := ../../../../../vendors/espressif/boards/esp32/aws_tests
endif


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "esp_err.h"
#include "queue.h"
#include "task.h"
#include "string.h"

extern void pthread_local_storage_cleanup(TaskHandle_t task);

Expand All @@ -40,3 +41,18 @@ void vPortCleanUpTCB ( void *pxTCB )
{
pthread_local_storage_cleanup(pxTCB);
}

void __attribute__((weak)) vApplicationStackOverflowHook( TaskHandle_t xTask, char *pcTaskName )
{
#define ERR_STR1 "***ERROR*** A stack overflow in task "
#define ERR_STR2 " has been detected."
const char *str[] = {ERR_STR1, pcTaskName, ERR_STR2};

char buf[sizeof(ERR_STR1) + CONFIG_FREERTOS_MAX_TASK_NAME_LEN + sizeof(ERR_STR2) + 1 /* null char */] = { 0 };

char *dest = buf;
for (int i = 0 ; i < sizeof(str)/ sizeof(str[0]); i++) {
dest = strcat(dest, str[i]);
}
esp_system_abort(buf);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include <xtensa_rtos.h>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[mapping]
[mapping:freertos]
archive: libfreertos.a
entries:
* (noflash_text)
Expand Down
101 changes: 101 additions & 0 deletions vendors/espressif/boards/components/mbedtls/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
idf_component_register()

set(FREERTOS_COMPONENT_DIR "${CMAKE_CURRENT_LIST_DIR}/../freertos")
set(MBEDTLS_DIR "${AFR_VENDORS_DIR}/espressif/esp-idf/components/mbedtls")

string(FIND "${AFR_BOARD_NAME}" "esp32s2" SOC_NAME_ESP32S2)
string(FIND "${AFR_BOARD_NAME}" "esp32" SOC_NAME_ESP32)

if (NOT(${SOC_NAME_ESP32S2} EQUAL -1))
set(SOC_NAME "esp32s2")
elseif(NOT($SOC_NAME_ESP32) EQUAL -1)
set(SOC_NAME "esp32")
endif()

target_compile_options(
afr_3rdparty_mbedtls
PUBLIC
${IDF_COMPILE_OPTIONS}
$<$<COMPILE_LANGUAGE:C>:${IDF_C_COMPILE_OPTIONS}>
$<$<COMPILE_LANGUAGE:CXX>:${IDF_CXX_COMPILE_OPTIONS}>
"-Wno-maybe-uninitialized"
)

set(
include_dirs
${IDF_INCLUDE_DIRECTORIES}
${MBEDTLS_DIR}/port/include
"${AFR_VENDORS_DIR}/espressif/esp-idf/components/xtensa/include"
"${AFR_VENDORS_DIR}/espressif/esp-idf/components/soc/soc/include"
)

if("${SOC_NAME}" STREQUAL "esp32s2")
list(APPEND include_dirs
"${AFR_VENDORS_DIR}/espressif/esp-idf/components/soc/src/esp32s2/include"
"${AFR_VENDORS_DIR}/espressif/esp-idf/components/esp32s2/include"
)
else()
list(APPEND include_dirs
"${AFR_VENDORS_DIR}/espressif/esp-idf/components/soc/src/esp32/include"
)
endif()

target_include_directories(
afr_3rdparty_mbedtls
BEFORE
PRIVATE
"${AFR_VENDORS_DIR}/espressif/esp-idf/components/vfs/include"
"${AFR_VENDORS_DIR}/espressif/esp-idf/components/soc/soc/include/soc"
${FREERTOS_COMPONENT_DIR}/include
PUBLIC
${include_dirs}
)

set(
mbedtls_srcs
"${MBEDTLS_DIR}/port/esp_bignum.c"
"${MBEDTLS_DIR}/port/esp_mem.c"
"${MBEDTLS_DIR}/port/esp_hardware.c"
"${MBEDTLS_DIR}/port/mbedtls_debug.c"
"${MBEDTLS_DIR}/port/esp_aes_xts.c"
)

if("${SOC_NAME}" STREQUAL "esp32s2")
list(APPEND mbedtls_srcs
"${MBEDTLS_DIR}/port/esp32s2/aes.c"
"${MBEDTLS_DIR}/port/esp32s2/sha.c"
"${MBEDTLS_DIR}/port/esp32s2/bignum.c"
"${MBEDTLS_DIR}/port/esp32s2/esp_sha1.c"
"${MBEDTLS_DIR}/port/esp32s2/esp_sha512.c"
"${MBEDTLS_DIR}/port/esp32s2/esp_sha256.c"
"${AFR_VENDORS_DIR}/espressif/esp-idf/components/esp32s2/esp_crypto_lock.c"
)
else()
list(APPEND mbedtls_srcs
"${MBEDTLS_DIR}/port/esp32/aes.c"
"${MBEDTLS_DIR}/port/esp32/sha.c"
"${MBEDTLS_DIR}/port/esp32/bignum.c"
"${MBEDTLS_DIR}/port/esp32/esp_sha1.c"
"${MBEDTLS_DIR}/port/esp32/esp_sha512.c"
"${MBEDTLS_DIR}/port/esp32/esp_sha256.c"
)
endif()

target_sources(
afr_3rdparty_mbedtls
PUBLIC
${mbedtls_srcs}
)

target_compile_definitions(
afr_3rdparty_mbedtls
PUBLIC
${IDF_COMPILE_DEFINITIONS}
-DMBEDTLS_CONFIG_FILE="${MBEDTLS_DIR}/port/include/mbedtls/esp_config.h"
)

target_link_libraries(
${COMPONENT_TARGET}
INTERFACE
afr_3rdparty_mbedtls
)
Loading