tgsong / amazon-freertos-examples

31 stars 24 forks source link

Update project to support esp32s2? #6

Open bhusang opened 4 years ago

bhusang commented 4 years ago

Hi @tgsong,

We have been using this project successfully (big thank you!) to build our application for the ESP32 with AFR. We are now looking at using the ESP32S2. There is a newer branch of amazon-freertos which supports this processor (https://github.com/aws/amazon-freertos/tree/feature/idf_uplevel_v4.2). However, it turns out that it is not straightforward to use that branch with this repo due to differences between esp-idf 3.3 and 4.2. Right off the bat, we are not cmake experts so our ability to fix this is very limited. Second, please refer to this comment (https://github.com/aws/amazon-freertos/pull/2285#issuecomment-676101469) for some more background. It would be very helpful to get a version of the cmake project files that will work with both the newer AFR branch and esp-idf. After some debugging, it seems that the issue is at this level (and not the freertos or esp-idf as they both now build and compile without issues). The command

cmake -DVENDOR=espressif -DBOARD=esp32s2_saola_1 -DCOMPILER=xtensa-esp32s2 -DCMAKE_TOOLCHAIN_FILE=freertos/tools/cmake/toolchains/xtensa-esp32s2.cmake     -S . -B build -GNinja

works fine in the root dir of the freertos (amazon-freertos) repo to build and compile the demo project (without the define for CMAKE_TOOLCHAIN_FILE). But it does not create a successful build setup in this project. The output:

-- The C compiler identification is GNU 8.2.0
-- The CXX compiler identification is GNU 8.2.0
-- The ASM compiler identification is GNU
-- Found assembler: /Users/bgupta/.espressif/tools/xtensa-esp32s2-elf/esp-2020r2-8.2.0/xtensa-esp32s2-elf/bin/xtensa-esp32s2-elf-gcc
-- Found Git: /usr/bin/git (found version "2.24.3 (Apple Git-128)")
-- Submodule update
CMake Warning at freertos/vendors/espressif/esp-idf/tools/cmake/idf.cmake:24 (message):
  IDF_PATH environment variable not found.  Setting IDF_PATH to
  '/Users/bgupta/src/LeakSentinel/esp/compare/amazon-freertos-examples/freertos/vendors/espressif/esp-idf'.
Call Stack (most recent call first):
  freertos/vendors/espressif/boards/esp32s2/CMakeLists.txt:23 (include)
  freertos/CMakeLists.txt:70 (include)

-- Component directory /Users/bgupta/src/LeakSentinel/esp/compare/amazon-freertos-examples/freertos/vendors/espressif/esp-idf/components/mbedtls does not contain a CMakeLists.txt file. No component will be added
-- Component directory /Users/bgupta/src/LeakSentinel/esp/compare/amazon-freertos-examples/freertos/vendors/espressif/esp-idf/components/unity does not contain a CMakeLists.txt file. No component will be added
-- Checking Python dependencies...
Python requirements from /Users/bgupta/src/LeakSentinel/esp/compare/amazon-freertos-examples/freertos/vendors/espressif/esp-idf/requirements.txt are satisfied.
Loading defaults file /Users/bgupta/src/LeakSentinel/esp/compare/amazon-freertos-examples/build/sdkconfig.defaults...
/var/folders/nh/p3xs3b3j72d4c6w8wxqsvww00000gn/T/confgen_tmpYa68rj:1 line was updated to CONFIG_ESP_INT_WDT=n
/var/folders/nh/p3xs3b3j72d4c6w8wxqsvww00000gn/T/confgen_tmpYa68rj:2 line was updated to CONFIG_ESP_TASK_WDT=n
-- App "freertos_examples" version: 1
-- Adding linker script /Users/bgupta/src/LeakSentinel/esp/compare/amazon-freertos-examples/freertos/vendors/espressif/esp-idf/components/esp_rom/esp32s2/ld/esp32s2.rom.ld
-- Adding linker script /Users/bgupta/src/LeakSentinel/esp/compare/amazon-freertos-examples/freertos/vendors/espressif/esp-idf/components/esp_rom/esp32s2/ld/esp32s2.rom.libgcc.ld
-- Adding linker script /Users/bgupta/src/LeakSentinel/esp/compare/amazon-freertos-examples/freertos/vendors/espressif/esp-idf/components/esp_rom/esp32s2/ld/esp32s2.rom.newlib-data.ld
-- Adding linker script /Users/bgupta/src/LeakSentinel/esp/compare/amazon-freertos-examples/freertos/vendors/espressif/esp-idf/components/esp_rom/esp32s2/ld/esp32s2.rom.newlib-funcs.ld
-- Adding linker script /Users/bgupta/src/LeakSentinel/esp/compare/amazon-freertos-examples/freertos/vendors/espressif/esp-idf/components/esp_rom/esp32s2/ld/esp32s2.rom.spiflash.ld
-- Adding linker script /Users/bgupta/src/LeakSentinel/esp/compare/amazon-freertos-examples/build/esp-idf/esp32s2/esp32s2_out.ld
-- Adding linker script /Users/bgupta/src/LeakSentinel/esp/compare/amazon-freertos-examples/freertos/vendors/espressif/esp-idf/components/esp32s2/ld/esp32s2.project.ld.in
-- Adding linker script /Users/bgupta/src/LeakSentinel/esp/compare/amazon-freertos-examples/freertos/vendors/espressif/esp-idf/components/esp32s2/ld/esp32s2.peripherals.ld
CMake Error at freertos/vendors/espressif/esp-idf/tools/cmake/build.cmake:468 (set_property):
  set_property could not find TARGET aws_demos.  Perhaps it has not yet been
  created.
Call Stack (most recent call first):
  freertos/vendors/espressif/boards/esp32s2/CMakeLists.txt:467 (idf_build_executable)
  freertos/CMakeLists.txt:70 (include)

=========================Resolving dependencies==========================
module disabled: ble_hal
reason:          ble_hal::mcu_port is not defined by vendor.
dependency path: ble->ble_hal->ble_hal::mcu_port

module disabled: posix
reason:          posix::mcu_port is not defined by vendor.
dependency path: posix->posix::mcu_port

====================Configuration for FreeRTOS====================
  Version:                 202007.00
  Git version:             202007.00-109-g569761515

Target microcontroller:
  vendor:                  Espressif
  board:                   ESP32S2-Saola-1
  description:             Development board produced by Espressif that comes in two
                           variants either with ESP32-S2-WROOM or ESP32-S2-WROVER module
  family:                  ESP32S2
  data ram size:           320KB
  program memory size:     4MB

Host platform:
  OS:                      Darwin-19.6.0
  Toolchain:               xtensa-esp32s2
  Toolchain path:          /Users/bgupta/.espressif/tools/xtensa-esp32s2-elf/esp-2020r2-8.
                           2.0/xtensa-esp32s2-elf
  CMake generator:         Ninja

FreeRTOS modules:
  Modules to build:        common, crypto, defender, dev_mode_key_provisioning,
                           greengrass, https, kernel, mqtt, ota, pkcs11, pkcs11_
                           implementation, platform, secure_sockets, serializer, shadow,
                           tls, wifi
  Enabled by user:         defender, greengrass, https, mqtt, ota, pkcs11, pkcs11_
                           implementation, platform, secure_sockets, shadow, wifi
  Enabled by dependency:   common, crypto, demo_base, dev_mode_key_provisioning,
                           freertos, kernel, ota_http, ota_mqtt, pkcs11_mbedtls,
                           serializer, tls, utils
  3rdparty dependencies:   http_parser, jsmn, mbedtls, pkcs11, tinycbor
  Available demos:         demo_defender, demo_greengrass_connectivity, demo_https,
                           demo_mqtt, demo_ota, demo_shadow, demo_tcp
  Available tests:
=========================================================================

-- Configuring incomplete, errors occurred!
See also "/Users/bgupta/src/LeakSentinel/esp/compare/amazon-freertos-examples/build/CMakeFiles/CMakeOutput.log".

CMakeOutput.log

tgsong commented 4 years ago

@bhusang Thanks for trying this out. I briefly checked the branch that you mentioned, looks like espressif has changed a lot of things. I did notice one mistake in their CMake file, if you dig more into this error message,

all Stack (most recent call first):
  freertos/vendors/espressif/boards/esp32s2/CMakeLists.txt:467 (idf_build_executable)
  freertos/CMakeLists.txt:70 (include)

you can see that in freertos/vendors/espressif/boards/esp32s2/CMakeLists.txt:467 they're using the hardcoded afr executable name, which is either aws_demos or aws_tests depending on if we're building demos or tests. I think they should instead use IDF_PROJECT_EXECUTABLE, which is set by the CMake file in this repo, https://github.com/tgsong/amazon-freertos-examples/blob/8f9c4ce081f85adeabc9fc12d1e3fa977ff5c1be/CMakeLists.txt#L8 Line freertos/vendors/espressif/boards/esp32s2/CMakeLists.txt:467 is not in the master branch, it's the new code they're adding which is breaking this example repo.

bhusang commented 4 years ago

@tgsong Thanks for looking into this. I have referenced your comment back to the author of that branch to see how he wants to fix it.