From 4146d27b8f9f89906355a5739060c2d9c14dd438 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dr=2E=20Christian=20Kohlsch=C3=BCtter?= Date: Mon, 22 Aug 2022 13:16:38 +0200 Subject: [PATCH 1/9] Enable configuring target variants (#7019) This change enables picking the right board configuration from the variants/ folder. Previously, we would always pick the default configuration (e.g., "esp32" instead of "heltec_wifi_lora_32_V2"). --- CMakeLists.txt | 6 +++--- Kconfig.projbuild | 9 +++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 53da85a4502..f5c324db580 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -168,7 +168,7 @@ set(BLE_SRCS ) set(includedirs - variants/${IDF_TARGET}/ + variants/${CONFIG_ARDUINO_VARIANT}/ cores/esp32/ libraries/ArduinoOTA/src libraries/AsyncUDP/src @@ -210,13 +210,13 @@ set(priv_requires fatfs nvs_flash app_update spiffs bootloader_support openssl b idf_component_register(INCLUDE_DIRS ${includedirs} PRIV_INCLUDE_DIRS ${priv_includes} SRCS ${srcs} REQUIRES ${requires} PRIV_REQUIRES ${priv_requires}) -string(TOUPPER ${CONFIG_IDF_TARGET} idf_target_caps) +string(TOUPPER ${CONFIG_ARDUINO_VARIANT} idf_target_caps) target_compile_options(${COMPONENT_TARGET} PUBLIC -DARDUINO=10812 -DARDUINO_${idf_target_caps}_DEV -DARDUINO_ARCH_ESP32 -DARDUINO_BOARD="${idf_target_caps}_DEV" - -DARDUINO_VARIANT="${CONFIG_IDF_TARGET}" + -DARDUINO_VARIANT="${CONFIG_ARDUINO_VARIANT}" -DESP32) if(CONFIG_AUTOSTART_ARDUINO) diff --git a/Kconfig.projbuild b/Kconfig.projbuild index 40c594c072a..f7ee920819f 100644 --- a/Kconfig.projbuild +++ b/Kconfig.projbuild @@ -1,5 +1,14 @@ menu "Arduino Configuration" +config ARDUINO_VARIANT + string "Arduino target variant (board)" + default IDF_TARGET + help + The name of a target variant (e.g., a specific board) in the variants/ + folder, e.g. "heltec_wifi_lora_32_V2". The name is case sensitive. + Specifying a variant name different from the target enables additional + customization, for example the definition of GPIO pins. + config ENABLE_ARDUINO_DEPENDS bool select LWIP_SO_RCVBUF From fdf8389ec5e1b2cf97bb0e71a6b30b1ee601c6fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dr=2E=20Christian=20Kohlsch=C3=BCtter?= Date: Mon, 22 Aug 2022 13:16:55 +0200 Subject: [PATCH 2/9] Update .gitignore (#7021) Add entries to gitignore --- .gitignore | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 90f3ff87709..4021fd8abce 100644 --- a/.gitignore +++ b/.gitignore @@ -8,9 +8,17 @@ tools/esptool.exe tools/mkspiffs tools/mklittlefs tools/mkfatfs.exe + +# Ignore editor backup files and macOS system metadata .DS_Store +.*.swp +.*.swo +*~ + +# Ignore build folder +/build -#Ignore files built by Visual Studio/Visual Micro +# Ignore files built by Visual Studio/Visual Micro [Dd]ebug*/ [Rr]elease*/ .vs/ From 3ebb774463181f457a735b5e75094e7b2deb2785 Mon Sep 17 00:00:00 2001 From: Me No Dev Date: Mon, 22 Aug 2022 17:00:42 +0300 Subject: [PATCH 3/9] Update esptool to version 4.2.1 (#7127) * Update esptool to version 4.2.1 * Fix esptool for MacOS * Esptool v4.2.1 for CI Platformio (#7147) to complete the test. Co-authored-by: Jason2866 <24528715+Jason2866@users.noreply.github.com> --- .github/scripts/on-push.sh | 2 +- package/package_esp32_index.template.json | 60 +++++++++++------------ 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/.github/scripts/on-push.sh b/.github/scripts/on-push.sh index a1d681e97ec..a86758e1f41 100755 --- a/.github/scripts/on-push.sh +++ b/.github/scripts/on-push.sh @@ -108,7 +108,7 @@ else replace_script+="data['packages']['toolchain-xtensa-esp32']['optional']=True;" replace_script+="data['packages']['toolchain-xtensa-esp32s3']['optional']=False;" replace_script+="data['packages']['tool-esptoolpy']['owner']='tasmota';" - replace_script+="data['packages']['tool-esptoolpy']['version']='https://github.com/tasmota/esptool/releases/download/v3.3/esptool-3.3.zip';" + replace_script+="data['packages']['tool-esptoolpy']['version']='https://github.com/tasmota/esptool/releases/download/v4.2.1/esptool-4.2.1.zip';" replace_script+="fp.seek(0);fp.truncate();json.dump(data, fp, indent=2);fp.close()" python -c "$replace_script" diff --git a/package/package_esp32_index.template.json b/package/package_esp32_index.template.json index 3c035f97ce8..497b26ccf0d 100644 --- a/package/package_esp32_index.template.json +++ b/package/package_esp32_index.template.json @@ -59,7 +59,7 @@ { "packager": "esp32", "name": "esptool_py", - "version": "3.3.0" + "version": "4.2.1" }, { "packager": "esp32", @@ -297,56 +297,56 @@ }, { "name": "esptool_py", - "version": "3.3.0", + "version": "4.2.1", "systems": [ { "host": "i686-mingw32", - "url": "https://github.com/espressif/arduino-esp32/releases/download/2.0.2/esptool-3.3-windows.zip", - "archiveFileName": "esptool-3.3-windows.zip", - "checksum": "SHA-256:55a1d7165414bf4dbd2bb16ca094e555d671958450f5d1536b457a518d2b15df", - "size": "7436864" + "url": "https://github.com/espressif/arduino-esp32/releases/download/2.0.4/esptool-4.2.1-windows.zip", + "archiveFileName": "esptool-4.2.1-windows.zip", + "checksum": "SHA-256:582560067bfbd9895f4862eb5fdf87558ddee5d4d30e7575c9b8bcb0dd60fd94", + "size": "6368279" }, { "host": "x86_64-mingw32", - "url": "https://github.com/espressif/arduino-esp32/releases/download/2.0.2/esptool-3.3-windows.zip", - "archiveFileName": "esptool-3.3-windows.zip", - "checksum": "SHA-256:55a1d7165414bf4dbd2bb16ca094e555d671958450f5d1536b457a518d2b15df", - "size": "7436864" + "url": "https://github.com/espressif/arduino-esp32/releases/download/2.0.4/esptool-4.2.1-windows.zip", + "archiveFileName": "esptool-4.2.1-windows.zip", + "checksum": "SHA-256:582560067bfbd9895f4862eb5fdf87558ddee5d4d30e7575c9b8bcb0dd60fd94", + "size": "6368279" }, { "host": "x86_64-apple-darwin", - "url": "https://github.com/espressif/arduino-esp32/releases/download/2.0.2/esptool-3.3-macos.tar.gz", - "archiveFileName": "esptool-3.3-macos.tar.gz", - "checksum": "SHA-256:3e5f7b521ae33c8c63f3b48efc909c08f37bef1a083c0eafa408312c09900afd", - "size": "6944975" + "url": "https://github.com/espressif/arduino-esp32/releases/download/2.0.4/esptool-4.2.1-macos.tar.gz", + "archiveFileName": "esptool-4.2.1-macos.tar.gz", + "checksum": "SHA-256:a984f7ad8bdb40c42d0d368bf4bb21b69a9587aed46b7b6d7de23ca58a3f150d", + "size": "5816598" }, { "host": "x86_64-pc-linux-gnu", - "url": "https://github.com/espressif/arduino-esp32/releases/download/2.0.2/esptool-3.3-linux.tar.gz", - "archiveFileName": "esptool-3.3-linux.tar.gz", - "checksum": "SHA-256:fbe91a49e5f5deca4881f5eed32e8903faf97bfd365fe2d0d1512b80bdb67f5e", - "size": "97026" + "url": "https://github.com/espressif/arduino-esp32/releases/download/2.0.4/esptool-4.2.1-linux.tar.gz", + "archiveFileName": "esptool-4.2.1-linux.tar.gz", + "checksum": "SHA-256:5a45fb77eb6574554ec2f45230d0b350f26f9c24ab3b6c13c4031ebdf72a34ab", + "size": "90123" }, { "host": "i686-pc-linux-gnu", - "url": "https://github.com/espressif/arduino-esp32/releases/download/2.0.2/esptool-3.3-linux.tar.gz", - "archiveFileName": "esptool-3.3-linux.tar.gz", - "checksum": "SHA-256:fbe91a49e5f5deca4881f5eed32e8903faf97bfd365fe2d0d1512b80bdb67f5e", - "size": "97026" + "url": "https://github.com/espressif/arduino-esp32/releases/download/2.0.4/esptool-4.2.1-linux.tar.gz", + "archiveFileName": "esptool-4.2.1-linux.tar.gz", + "checksum": "SHA-256:5a45fb77eb6574554ec2f45230d0b350f26f9c24ab3b6c13c4031ebdf72a34ab", + "size": "90123" }, { "host": "arm-linux-gnueabihf", - "url": "https://github.com/espressif/arduino-esp32/releases/download/2.0.2/esptool-3.3-linux.tar.gz", - "archiveFileName": "esptool-3.3-linux.tar.gz", - "checksum": "SHA-256:fbe91a49e5f5deca4881f5eed32e8903faf97bfd365fe2d0d1512b80bdb67f5e", - "size": "97026" + "url": "https://github.com/espressif/arduino-esp32/releases/download/2.0.4/esptool-4.2.1-linux.tar.gz", + "archiveFileName": "esptool-4.2.1-linux.tar.gz", + "checksum": "SHA-256:5a45fb77eb6574554ec2f45230d0b350f26f9c24ab3b6c13c4031ebdf72a34ab", + "size": "90123" }, { "host": "aarch64-linux-gnu", - "url": "https://github.com/espressif/arduino-esp32/releases/download/2.0.2/esptool-3.3-linux.tar.gz", - "archiveFileName": "esptool-3.3-linux.tar.gz", - "checksum": "SHA-256:fbe91a49e5f5deca4881f5eed32e8903faf97bfd365fe2d0d1512b80bdb67f5e", - "size": "97026" + "url": "https://github.com/espressif/arduino-esp32/releases/download/2.0.4/esptool-3.3-linux.tar.gz", + "archiveFileName": "esptool-4.2.1-linux.tar.gz", + "checksum": "SHA-256:5a45fb77eb6574554ec2f45230d0b350f26f9c24ab3b6c13c4031ebdf72a34ab", + "size": "90123" } ] }, From 3f69bcfca4225ead422f322e524008408ae5e170 Mon Sep 17 00:00:00 2001 From: Me No Dev Date: Mon, 22 Aug 2022 17:33:14 +0300 Subject: [PATCH 4/9] Update get.py to support python 3.10+ (#7166) * Update get.py to support python 3.10+ * Use try/except to remove version check --- tools/get.py | 47 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/tools/get.py b/tools/get.py index bec2b51cb1b..088e2f67139 100755 --- a/tools/get.py +++ b/tools/get.py @@ -54,9 +54,17 @@ def mkdir_p(path): def report_progress(count, blockSize, totalSize): if sys.stdout.isatty(): - percent = int(count*blockSize*100/totalSize) - percent = min(100, percent) - sys.stdout.write("\r%d%%" % percent) + if totalSize > 0: + percent = int(count*blockSize*100/totalSize) + percent = min(100, percent) + sys.stdout.write("\r%d%%" % percent) + else: + sofar = (count*blockSize) / 1024 + if sofar >= 1000: + sofar /= 1024 + sys.stdout.write("\r%dMB " % (sofar)) + else: + sys.stdout.write("\r%dKB" % (sofar)) sys.stdout.flush() def unpack(filename, destination): @@ -82,6 +90,32 @@ def unpack(filename, destination): shutil.rmtree(rename_to) shutil.move(dirname, rename_to) +def download_file_with_progress(url,filename): + import ssl + import contextlib + ctx = ssl.create_default_context() + ctx.check_hostname = False + ctx.verify_mode = ssl.CERT_NONE + with contextlib.closing(urlopen(url,context=ctx)) as fp: + total_size = int(fp.getheader("Content-Length",fp.getheader("Content-length","0"))) + block_count = 0 + block_size = 1024 * 8 + block = fp.read(block_size) + if block: + with open(filename,'wb') as out_file: + out_file.write(block) + block_count += 1 + report_progress(block_count, block_size, total_size) + while True: + block = fp.read(block_size) + if not block: + break + out_file.write(block) + block_count += 1 + report_progress(block_count, block_size, total_size) + else: + raise Exception ('nonexisting file or connection error') + def download_file(url,filename): import ssl import contextlib @@ -126,8 +160,11 @@ def get_tool(tool): if is_ci: download_file(url, local_path) else: - urlretrieve(url, local_path, report_progress) - sys.stdout.write("\rDone\n") + try: + urlretrieve(url, local_path, report_progress) + except: + download_file_with_progress(url, local_path) + sys.stdout.write("\rDone \n") sys.stdout.flush() else: print('Tool {0} already downloaded'.format(archive_name)) From d22bcb765b35f8a1869a5ed185886eec77e3fa21 Mon Sep 17 00:00:00 2001 From: Paul Price <56952812+strid3r21@users.noreply.github.com> Date: Wed, 24 Aug 2022 07:20:03 -0400 Subject: [PATCH 5/9] fixed names on the VID and PID for boards (#7144) somehow had duplicated the same name across all my boards. the PID's and VID's were correct, but the name was the same for all of them. that is fixed now. --- boards.txt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/boards.txt b/boards.txt index 363a8d340a8..bc59eab7c60 100644 --- a/boards.txt +++ b/boards.txt @@ -17114,8 +17114,8 @@ department_of_alchemy_minimain_esp32s2.menu.EraseFlash.all.upload.erase_cmd=-e ############################################################## Bee_Motion_S3.name=Bee Motion S3 -Bee_Motion_Mini.vid.0=0x303a -Bee_Motion_Mini.pid.0=0x8113 +Bee_Motion_S3.vid.0=0x303a +Bee_Motion_S3.pid.0=0x8113 Bee_Motion_S3.bootloader.tool=esptool_py Bee_Motion_S3.bootloader.tool.default=esptool_py @@ -17223,8 +17223,8 @@ Bee_Motion_S3.menu.EraseFlash.all.upload.erase_cmd=-e ######################################################################## Bee_Motion.name=Bee Motion -Bee_Motion_Mini.vid.0=0x303a -Bee_Motion_Mini.pid.0=0x810D +Bee_Motion.vid.0=0x303a +Bee_Motion.pid.0=0x810D Bee_Motion.bootloader.tool=esptool_py Bee_Motion.bootloader.tool.default=esptool_py @@ -17440,8 +17440,8 @@ Bee_Motion_Mini.menu.EraseFlash.all.upload.erase_cmd=-e ############################################################### Bee_S3.name=Bee S3 -Bee_Motion_Mini.vid.0=0x303a -Bee_Motion_Mini.pid.0=0x8110 +Bee_S3.vid.0=0x303a +Bee_S3.pid.0=0x8110 Bee_S3.bootloader.tool=esptool_py Bee_S3.bootloader.tool.default=esptool_py From adb01cf0c6c361a0823a4797bb08da3c2ea1b40d Mon Sep 17 00:00:00 2001 From: Daniel Egnor Date: Fri, 26 Aug 2022 01:14:59 -0700 Subject: [PATCH 6/9] Compile error if CONFIG_FREERTOS_HZ != 1000 (#6955) * Compile error if CONFIG_FREERTOS_HZ != 1000 * add a check at the CMake level, per feedback * Set CONFIG_FREERTOS_HZ=1000 in CI test of Arduino-as-component --- .github/workflows/push.yml | 1 + CMakeLists.txt | 6 ++++++ docs/source/esp-idf_component.rst | 3 +-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index f2f75d7b1ac..c2fe46df8c7 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -104,4 +104,5 @@ jobs: run: | . ${IDF_PATH}/export.sh idf.py create-project test + echo CONFIG_FREERTOS_HZ=1000 > test/sdkconfig.defaults idf.py -C test -DEXTRA_COMPONENT_DIRS=$PWD/components build diff --git a/CMakeLists.txt b/CMakeLists.txt index f5c324db580..8e065f90605 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -210,6 +210,12 @@ set(priv_requires fatfs nvs_flash app_update spiffs bootloader_support openssl b idf_component_register(INCLUDE_DIRS ${includedirs} PRIV_INCLUDE_DIRS ${priv_includes} SRCS ${srcs} REQUIRES ${requires} PRIV_REQUIRES ${priv_requires}) +if(NOT CONFIG_FREERTOS_HZ EQUAL 1000 AND NOT "$ENV{ARDUINO_SKIP_TICK_CHECK}") + # See delay() in cores/esp32/esp32-hal-misc.c. + message(FATAL_ERROR "esp32-arduino requires CONFIG_FREERTOS_HZ=1000 " + "(currently ${CONFIG_FREERTOS_HZ})") +endif() + string(TOUPPER ${CONFIG_ARDUINO_VARIANT} idf_target_caps) target_compile_options(${COMPONENT_TARGET} PUBLIC -DARDUINO=10812 diff --git a/docs/source/esp-idf_component.rst b/docs/source/esp-idf_component.rst index f153f267e6b..e2049b4e2bf 100644 --- a/docs/source/esp-idf_component.rst +++ b/docs/source/esp-idf_component.rst @@ -140,8 +140,7 @@ If you are writing code that does not require Arduino to compile and you want yo FreeRTOS Tick Rate (Hz) ----------------------- -You might notice that Arduino-esp32's `delay()` function will only work in multiples of 10ms. That is because, by default, esp-idf handles task events 100 times per second. -To fix that behavior, you need to set FreeRTOS tick rate to 1000Hz in `make menuconfig` -> `Component config` -> `FreeRTOS` -> `Tick rate`. +The Arduino component requires the FreeRTOS tick rate `CONFIG_FREERTOS_HZ` set to 1000Hz in `make menuconfig` -> `Component config` -> `FreeRTOS` -> `Tick rate`. Compilation Errors ------------------ From 01e22291e2fa33d858c3c245fae730fe1def3286 Mon Sep 17 00:00:00 2001 From: Michael Ammann Date: Mon, 29 Aug 2022 11:20:06 +0200 Subject: [PATCH 7/9] Adding u-blox NORA-W10 series (ESP32-S3) (#7191) * Create pins_arduino.h * Update boards.txt * Update boards.txt --- boards.txt | 204 +++++++++++++++++++++++++++++++ variants/nora_w10/pins_arduino.h | 93 ++++++++++++++ 2 files changed, 297 insertions(+) create mode 100644 variants/nora_w10/pins_arduino.h diff --git a/boards.txt b/boards.txt index bc59eab7c60..d556728a1f0 100644 --- a/boards.txt +++ b/boards.txt @@ -4831,6 +4831,210 @@ nina_w10.menu.EraseFlash.all.upload.erase_cmd=-e ############################################################## +nora_w10.name=u-blox NORA-W10 series (ESP32-S3) +nora_w10.vid.0=0x303a +nora_w10.pid.0=0x1001 + +nora_w10.bootloader.tool=esptool_py +nora_w10.bootloader.tool.default=esptool_py + +nora_w10.upload.tool=esptool_py +nora_w10.upload.tool.default=esptool_py +nora_w10.upload.tool.network=esp_ota + +nora_w10.upload.maximum_size=1310720 +nora_w10.upload.maximum_data_size=327680 +nora_w10.upload.flags= +nora_w10.upload.extra_flags= +nora_w10.upload.use_1200bps_touch=false +nora_w10.upload.wait_for_upload_port=false + +nora_w10.serial.disableDTR=false +nora_w10.serial.disableRTS=false + +nora_w10.build.tarch=xtensa +nora_w10.build.bootloader_addr=0x0 +nora_w10.build.target=esp32s3 +nora_w10.build.mcu=esp32s3 +nora_w10.build.core=esp32 +nora_w10.build.variant=nora_w10 +nora_w10.build.board=UBLOX_NORA_W10 + +nora_w10.build.usb_mode=1 +nora_w10.build.cdc_on_boot=0 +nora_w10.build.msc_on_boot=0 +nora_w10.build.dfu_on_boot=0 +nora_w10.build.f_cpu=240000000L +nora_w10.build.flash_size=4MB +nora_w10.build.flash_freq=80m +nora_w10.build.flash_mode=dio +nora_w10.build.boot=qio +nora_w10.build.boot_freq=80m +nora_w10.build.partitions=default +nora_w10.build.defines= +nora_w10.build.loop_core= +nora_w10.build.event_core= +nora_w10.build.psram_type=qspi +nora_w10.build.memory_type={build.boot}_{build.psram_type} + +nora_w10.menu.PSRAM.disabled=Disabled +nora_w10.menu.PSRAM.disabled.build.defines= +nora_w10.menu.PSRAM.disabled.build.psram_type=qspi +nora_w10.menu.PSRAM.enabled=QSPI PSRAM +nora_w10.menu.PSRAM.enabled.build.defines=-DBOARD_HAS_PSRAM +nora_w10.menu.PSRAM.enabled.build.psram_type=qspi +nora_w10.menu.PSRAM.opi=OPI PSRAM +nora_w10.menu.PSRAM.opi.build.defines=-DBOARD_HAS_PSRAM +nora_w10.menu.PSRAM.opi.build.psram_type=opi + +nora_w10.menu.FlashMode.qio=QIO 80MHz +nora_w10.menu.FlashMode.qio.build.flash_mode=dio +nora_w10.menu.FlashMode.qio.build.boot=qio +nora_w10.menu.FlashMode.qio.build.boot_freq=80m +nora_w10.menu.FlashMode.qio.build.flash_freq=80m +nora_w10.menu.FlashMode.qio120=QIO 120MHz +nora_w10.menu.FlashMode.qio120.build.flash_mode=dio +nora_w10.menu.FlashMode.qio120.build.boot=qio +nora_w10.menu.FlashMode.qio120.build.boot_freq=120m +nora_w10.menu.FlashMode.qio120.build.flash_freq=80m +nora_w10.menu.FlashMode.dio=DIO 80MHz +nora_w10.menu.FlashMode.dio.build.flash_mode=dio +nora_w10.menu.FlashMode.dio.build.boot=dio +nora_w10.menu.FlashMode.dio.build.boot_freq=80m +nora_w10.menu.FlashMode.dio.build.flash_freq=80m +nora_w10.menu.FlashMode.opi=OPI 80MHz +nora_w10.menu.FlashMode.opi.build.flash_mode=dout +nora_w10.menu.FlashMode.opi.build.boot=opi +nora_w10.menu.FlashMode.opi.build.boot_freq=80m +nora_w10.menu.FlashMode.opi.build.flash_freq=80m + +nora_w10.menu.FlashSize.4M=4MB (32Mb) +nora_w10.menu.FlashSize.4M.build.flash_size=4MB +nora_w10.menu.FlashSize.8M=8MB (64Mb) +nora_w10.menu.FlashSize.8M.build.flash_size=8MB +nora_w10.menu.FlashSize.8M.build.partitions=default_8MB +#nora_w10.menu.FlashSize.16M=16MB (128Mb) +#nora_w10.menu.FlashSize.16M.build.flash_size=16MB +#nora_w10.menu.FlashSize.32M=32MB (256Mb) +#nora_w10.menu.FlashSize.32M.build.flash_size=32MB + +nora_w10.menu.LoopCore.1=Core 1 +nora_w10.menu.LoopCore.1.build.loop_core=-DARDUINO_RUNNING_CORE=1 +nora_w10.menu.LoopCore.0=Core 0 +nora_w10.menu.LoopCore.0.build.loop_core=-DARDUINO_RUNNING_CORE=0 + +nora_w10.menu.EventsCore.1=Core 1 +nora_w10.menu.EventsCore.1.build.event_core=-DARDUINO_EVENT_RUNNING_CORE=1 +nora_w10.menu.EventsCore.0=Core 0 +nora_w10.menu.EventsCore.0.build.event_core=-DARDUINO_EVENT_RUNNING_CORE=0 + +nora_w10.menu.USBMode.hwcdc=Hardware CDC and JTAG +nora_w10.menu.USBMode.hwcdc.build.usb_mode=1 +nora_w10.menu.USBMode.default=USB-OTG (TinyUSB) +nora_w10.menu.USBMode.default.build.usb_mode=0 + +nora_w10.menu.CDCOnBoot.default=Disabled +nora_w10.menu.CDCOnBoot.default.build.cdc_on_boot=0 +nora_w10.menu.CDCOnBoot.cdc=Enabled +nora_w10.menu.CDCOnBoot.cdc.build.cdc_on_boot=1 + +nora_w10.menu.MSCOnBoot.default=Disabled +nora_w10.menu.MSCOnBoot.default.build.msc_on_boot=0 +nora_w10.menu.MSCOnBoot.msc=Enabled (Requires USB-OTG Mode) +nora_w10.menu.MSCOnBoot.msc.build.msc_on_boot=1 + +nora_w10.menu.DFUOnBoot.default=Disabled +nora_w10.menu.DFUOnBoot.default.build.dfu_on_boot=0 +nora_w10.menu.DFUOnBoot.dfu=Enabled (Requires USB-OTG Mode) +nora_w10.menu.DFUOnBoot.dfu.build.dfu_on_boot=1 + +nora_w10.menu.UploadMode.default=UART0 / Hardware CDC +nora_w10.menu.UploadMode.default.upload.use_1200bps_touch=false +nora_w10.menu.UploadMode.default.upload.wait_for_upload_port=false +nora_w10.menu.UploadMode.cdc=USB-OTG CDC (TinyUSB) +nora_w10.menu.UploadMode.cdc.upload.use_1200bps_touch=true +nora_w10.menu.UploadMode.cdc.upload.wait_for_upload_port=true + +nora_w10.menu.PartitionScheme.default=Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS) +nora_w10.menu.PartitionScheme.default.build.partitions=default +nora_w10.menu.PartitionScheme.defaultffat=Default 4MB with ffat (1.2MB APP/1.5MB FATFS) +nora_w10.menu.PartitionScheme.defaultffat.build.partitions=default_ffat +nora_w10.menu.PartitionScheme.default_8MB=8M Flash (3MB APP/1.5MB FAT) +nora_w10.menu.PartitionScheme.default_8MB.build.partitions=default_8MB +nora_w10.menu.PartitionScheme.default_8MB.upload.maximum_size=3342336 +nora_w10.menu.PartitionScheme.minimal=Minimal (1.3MB APP/700KB SPIFFS) +nora_w10.menu.PartitionScheme.minimal.build.partitions=minimal +nora_w10.menu.PartitionScheme.no_ota=No OTA (2MB APP/2MB SPIFFS) +nora_w10.menu.PartitionScheme.no_ota.build.partitions=no_ota +nora_w10.menu.PartitionScheme.no_ota.upload.maximum_size=2097152 +nora_w10.menu.PartitionScheme.noota_3g=No OTA (1MB APP/3MB SPIFFS) +nora_w10.menu.PartitionScheme.noota_3g.build.partitions=noota_3g +nora_w10.menu.PartitionScheme.noota_3g.upload.maximum_size=1048576 +nora_w10.menu.PartitionScheme.noota_ffat=No OTA (2MB APP/2MB FATFS) +nora_w10.menu.PartitionScheme.noota_ffat.build.partitions=noota_ffat +nora_w10.menu.PartitionScheme.noota_ffat.upload.maximum_size=2097152 +nora_w10.menu.PartitionScheme.noota_3gffat=No OTA (1MB APP/3MB FATFS) +nora_w10.menu.PartitionScheme.noota_3gffat.build.partitions=noota_3gffat +nora_w10.menu.PartitionScheme.noota_3gffat.upload.maximum_size=1048576 +nora_w10.menu.PartitionScheme.huge_app=Huge APP (3MB No OTA/1MB SPIFFS) +nora_w10.menu.PartitionScheme.huge_app.build.partitions=huge_app +nora_w10.menu.PartitionScheme.huge_app.upload.maximum_size=3145728 +nora_w10.menu.PartitionScheme.min_spiffs=Minimal SPIFFS (1.9MB APP with OTA/190KB SPIFFS) +nora_w10.menu.PartitionScheme.min_spiffs.build.partitions=min_spiffs +nora_w10.menu.PartitionScheme.min_spiffs.upload.maximum_size=1966080 +#nora_w10.menu.PartitionScheme.fatflash=16M Flash (2MB APP/12.5MB FAT) +#nora_w10.menu.PartitionScheme.fatflash.build.partitions=ffat +#nora_w10.menu.PartitionScheme.fatflash.upload.maximum_size=2097152 +#nora_w10.menu.PartitionScheme.app3M_fat9M_16MB=16M Flash (3MB APP/9MB FATFS) +#nora_w10.menu.PartitionScheme.app3M_fat9M_16MB.build.partitions=app3M_fat9M_16MB +#nora_w10.menu.PartitionScheme.app3M_fat9M_16MB.upload.maximum_size=3145728 +nora_w10.menu.PartitionScheme.rainmaker=RainMaker +nora_w10.menu.PartitionScheme.rainmaker.build.partitions=rainmaker +nora_w10.menu.PartitionScheme.rainmaker.upload.maximum_size=3145728 + +nora_w10.menu.CPUFreq.240=240MHz (WiFi) +nora_w10.menu.CPUFreq.240.build.f_cpu=240000000L +nora_w10.menu.CPUFreq.160=160MHz (WiFi) +nora_w10.menu.CPUFreq.160.build.f_cpu=160000000L +nora_w10.menu.CPUFreq.80=80MHz (WiFi) +nora_w10.menu.CPUFreq.80.build.f_cpu=80000000L +nora_w10.menu.CPUFreq.40=40MHz +nora_w10.menu.CPUFreq.40.build.f_cpu=40000000L +nora_w10.menu.CPUFreq.20=20MHz +nora_w10.menu.CPUFreq.20.build.f_cpu=20000000L +nora_w10.menu.CPUFreq.10=10MHz +nora_w10.menu.CPUFreq.10.build.f_cpu=10000000L + +nora_w10.menu.UploadSpeed.921600=921600 +nora_w10.menu.UploadSpeed.921600.upload.speed=921600 +nora_w10.menu.UploadSpeed.115200=115200 +nora_w10.menu.UploadSpeed.115200.upload.speed=115200 +nora_w10.menu.UploadSpeed.256000.windows=256000 +nora_w10.menu.UploadSpeed.256000.upload.speed=256000 +nora_w10.menu.UploadSpeed.230400.windows.upload.speed=256000 +nora_w10.menu.UploadSpeed.230400=230400 +nora_w10.menu.UploadSpeed.230400.upload.speed=230400 +nora_w10.menu.UploadSpeed.460800.linux=460800 +nora_w10.menu.UploadSpeed.460800.macosx=460800 +nora_w10.menu.UploadSpeed.460800.upload.speed=460800 +nora_w10.menu.UploadSpeed.512000.windows=512000 +nora_w10.menu.UploadSpeed.512000.upload.speed=512000 + +nora_w10.menu.DebugLevel.none=None +nora_w10.menu.DebugLevel.none.build.code_debug=0 +nora_w10.menu.DebugLevel.error=Error +nora_w10.menu.DebugLevel.error.build.code_debug=1 +nora_w10.menu.DebugLevel.warn=Warn +nora_w10.menu.DebugLevel.warn.build.code_debug=2 +nora_w10.menu.DebugLevel.info=Info +nora_w10.menu.DebugLevel.info.build.code_debug=3 +nora_w10.menu.DebugLevel.debug=Debug +nora_w10.menu.DebugLevel.debug.build.code_debug=4 +nora_w10.menu.DebugLevel.verbose=Verbose +nora_w10.menu.DebugLevel.verbose.build.code_debug=5 + +############################################################## + widora-air.name=Widora AIR widora-air.bootloader.tool=esptool_py diff --git a/variants/nora_w10/pins_arduino.h b/variants/nora_w10/pins_arduino.h new file mode 100644 index 00000000000..64e99c239ce --- /dev/null +++ b/variants/nora_w10/pins_arduino.h @@ -0,0 +1,93 @@ +#ifndef Pins_Arduino_h +#define Pins_Arduino_h + +#include +#include "soc/soc_caps.h" + +#define USB_VID 0x303a +#define USB_PID 0x1001 + +#define EXTERNAL_NUM_INTERRUPTS 46 +#define NUM_DIGITAL_PINS 48 +#define NUM_ANALOG_INPUTS 20 + +#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) +#define digitalPinToInterrupt(p) (((p)<48)?(p):-1) +#define digitalPinHasPWM(p) (p < 46) + +// The pin assignments in this file are based on u-blox EVK-NORA-W1, a Arduino compatible board. +// For your own module design you can freely chose the pins available on the module module pins + +static const uint8_t TX = 43; +static const uint8_t RX = 44; +static const uint8_t RTS = 45; +static const uint8_t CTS = 6; +static const uint8_t DTR = 1; +static const uint8_t DSR = 7; + +static const uint8_t SW1 = 46; +static const uint8_t SW2 = 0; // BOOT +static const uint8_t SW3 = 47; +static const uint8_t SW4 = 48; + +static const uint8_t LED_RED = 5; +static const uint8_t LED_GREEN = 2; +static const uint8_t LED_BLUE = 8; +#define BUILTIN_LED LED_BLUE // backward compatibility +#define LED_BUILTIN LED_BLUE + +static const uint8_t SS = 10; +static const uint8_t MOSI = 11; +static const uint8_t MISO = 13; +static const uint8_t SCK = 12; + +static const uint8_t A0 = 11; +static const uint8_t A1 = 12; +static const uint8_t A2 = 13; +static const uint8_t A3 = 5; +static const uint8_t A4 = 15; +static const uint8_t A5 = 16; + +static const uint8_t D0 = 44; // RX0 +static const uint8_t D1 = 43; // TX0 +static const uint8_t D2 = 46; +static const uint8_t D3 = 4; +static const uint8_t D4 = 3; +static const uint8_t D5 = 2; +static const uint8_t D6 = 14; +static const uint8_t D7 = 10; + +static const uint8_t D8 = 33; +static const uint8_t D9 = 38; +static const uint8_t D10 = 34; // SS +static const uint8_t D11 = 35; // MOSI +static const uint8_t D12 = 37; // MISO +static const uint8_t D13 = 36; // SCK +static const uint8_t SDA1 = 21; +static const uint8_t SCL1 = 0; + +static const uint8_t D14 = 45; // RTS +static const uint8_t D15 = 6; // CTS +static const uint8_t D16 = 1; // DTR +static const uint8_t D17 = 7; // DSR +static const uint8_t D18 = 47; +static const uint8_t D19 = 48; +static const uint8_t SDA = 18; +static const uint8_t SCL = 17; + +static const uint8_t T1 = 1; +static const uint8_t T2 = 2; +static const uint8_t T3 = 3; +static const uint8_t T4 = 4; +static const uint8_t T5 = 5; +static const uint8_t T6 = 6; +static const uint8_t T7 = 7; +static const uint8_t T8 = 8; +static const uint8_t T9 = 9; +static const uint8_t T10 = 10; +static const uint8_t T11 = 11; +static const uint8_t T12 = 12; +static const uint8_t T13 = 13; +static const uint8_t T14 = 14; + +#endif /* Pins_Arduino_h */ From 77065bffb2c57704ee46ad0a43270e50860814f5 Mon Sep 17 00:00:00 2001 From: Sanket Wadekar <67091512+sanketwadekar@users.noreply.github.com> Date: Mon, 29 Aug 2022 15:06:51 +0530 Subject: [PATCH 8/9] Fixed espressif/esp-rainmaker#152 (#7171) --- .../RMakerSonoffDualR3/RMakerSonoffDualR3.ino | 37 +++++++++++-------- .../examples/RMakerSwitch/RMakerSwitch.ino | 19 ++++++---- 2 files changed, 32 insertions(+), 24 deletions(-) diff --git a/libraries/RainMaker/examples/RMakerSonoffDualR3/RMakerSonoffDualR3.ino b/libraries/RainMaker/examples/RMakerSonoffDualR3/RMakerSonoffDualR3.ino index b571f4f5dac..cf9a58b7111 100644 --- a/libraries/RainMaker/examples/RMakerSonoffDualR3/RMakerSonoffDualR3.ino +++ b/libraries/RainMaker/examples/RMakerSonoffDualR3/RMakerSonoffDualR3.ino @@ -31,12 +31,12 @@ LightSwitch switch_ch1 = {gpio_switch1, false}; LightSwitch switch_ch2 = {gpio_switch2, false}; //The framework provides some standard device types like switch, lightbulb, fan, temperature sensor. -static Switch my_switch1("Switch_ch1", &gpio_relay1); -static Switch my_switch2("Switch_ch2", &gpio_relay2); +static Switch my_switch1; +static Switch my_switch2; void sysProvEvent(arduino_event_t *sys_event) { - switch (sys_event->event_id) { + switch (sys_event->event_id) { case ARDUINO_EVENT_PROV_START: #if CONFIG_IDF_TARGET_ESP32 Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on BLE\n", service_name, pop); @@ -44,7 +44,7 @@ void sysProvEvent(arduino_event_t *sys_event) #else Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on SoftAP\n", service_name, pop); printQR(service_name, pop, "softap"); -#endif +#endif break; case ARDUINO_EVENT_WIFI_STA_CONNECTED: Serial.printf("\nConnected to Wi-Fi!\n"); @@ -60,18 +60,18 @@ void write_callback(Device *device, Param *param, const param_val_t val, void *p const char *param_name = param->getParamName(); if(strcmp(device_name, "Switch_ch1") == 0) { - + Serial.printf("Lightbulb = %s\n", val.val.b? "true" : "false"); - + if(strcmp(param_name, "Power") == 0) { Serial.printf("Received value = %s for %s - %s\n", val.val.b? "true" : "false", device_name, param_name); switch_state_ch1 = val.val.b; (switch_state_ch1 == false) ? digitalWrite(gpio_relay1, LOW) : digitalWrite(gpio_relay1, HIGH); param->updateAndReport(val); } - + } else if(strcmp(device_name, "Switch_ch2") == 0) { - + Serial.printf("Switch value = %s\n", val.val.b? "true" : "false"); if(strcmp(param_name, "Power") == 0) { @@ -80,9 +80,9 @@ void write_callback(Device *device, Param *param, const param_val_t val, void *p (switch_state_ch2 == false) ? digitalWrite(gpio_relay2, LOW) : digitalWrite(gpio_relay2, HIGH); param->updateAndReport(val); } - + } - + } void ARDUINO_ISR_ATTR isr(void* arg) { @@ -92,8 +92,9 @@ void ARDUINO_ISR_ATTR isr(void* arg) { void setup() { + uint32_t chipId = 0; - + Serial.begin(115200); // Configure the input GPIOs @@ -102,7 +103,7 @@ void setup() attachInterruptArg(switch_ch1.pin, isr, &switch_ch1, CHANGE); pinMode(switch_ch2.pin, INPUT_PULLUP); attachInterruptArg(switch_ch2.pin, isr, &switch_ch2, CHANGE); - + // Set the Relays GPIOs as output mode pinMode(gpio_relay1, OUTPUT); pinMode(gpio_relay2, OUTPUT); @@ -112,20 +113,24 @@ void setup() digitalWrite(gpio_relay2, DEFAULT_POWER_MODE); digitalWrite(gpio_led, false); - Node my_node; + Node my_node; my_node = RMaker.initNode("Sonoff Dual R3"); + //Initialize switch device + my_switch1 = Switch("Switch_ch1", &gpio_relay1); + my_switch2 = Switch("Switch_ch2", &gpio_relay2); + //Standard switch device my_switch1.addCb(write_callback); my_switch2.addCb(write_callback); - //Add switch device to the node + //Add switch device to the node my_node.addDevice(my_switch1); my_node.addDevice(my_switch2); - //This is optional + //This is optional RMaker.enableOTA(OTA_USING_PARAMS); - //If you want to enable scheduling, set time zone for your region using setTimeZone(). + //If you want to enable scheduling, set time zone for your region using setTimeZone(). //The list of available values are provided here https://rainmaker.espressif.com/docs/time-service.html // RMaker.setTimeZone("Asia/Shanghai"); // Alternatively, enable the Timezone service and let the phone apps set the appropriate timezone diff --git a/libraries/RainMaker/examples/RMakerSwitch/RMakerSwitch.ino b/libraries/RainMaker/examples/RMakerSwitch/RMakerSwitch.ino index 52afe11076e..2da78ad0744 100644 --- a/libraries/RainMaker/examples/RMakerSwitch/RMakerSwitch.ino +++ b/libraries/RainMaker/examples/RMakerSwitch/RMakerSwitch.ino @@ -21,11 +21,11 @@ static int gpio_switch = 16; bool switch_state = true; //The framework provides some standard device types like switch, lightbulb, fan, temperaturesensor. -static Switch my_switch("Switch", &gpio_switch); +static Switch my_switch; void sysProvEvent(arduino_event_t *sys_event) { - switch (sys_event->event_id) { + switch (sys_event->event_id) { case ARDUINO_EVENT_PROV_START: #if CONFIG_IDF_TARGET_ESP32S2 Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on SoftAP\n", service_name, pop); @@ -33,7 +33,7 @@ void sysProvEvent(arduino_event_t *sys_event) #else Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on BLE\n", service_name, pop); printQR(service_name, pop, "ble"); -#endif +#endif break; default:; } @@ -59,18 +59,21 @@ void setup() pinMode(gpio_switch, OUTPUT); digitalWrite(gpio_switch, DEFAULT_POWER_MODE); - Node my_node; + Node my_node; my_node = RMaker.initNode("ESP RainMaker Node"); + //Initialize switch device + my_switch = Switch("Switch", &gpio_switch); + //Standard switch device my_switch.addCb(write_callback); - - //Add switch device to the node + + //Add switch device to the node my_node.addDevice(my_switch); - //This is optional + //This is optional RMaker.enableOTA(OTA_USING_PARAMS); - //If you want to enable scheduling, set time zone for your region using setTimeZone(). + //If you want to enable scheduling, set time zone for your region using setTimeZone(). //The list of available values are provided here https://rainmaker.espressif.com/docs/time-service.html // RMaker.setTimeZone("Asia/Shanghai"); // Alternatively, enable the Timezone service and let the phone apps set the appropriate timezone From 074f315108b1fa1fa53832f75433a1ba55aaed1b Mon Sep 17 00:00:00 2001 From: Valerii Koval Date: Tue, 6 Sep 2022 17:39:03 +0300 Subject: [PATCH 9/9] Update PlatformIO build scripts (#7200) This update includes the following: - Implemented an additional build step that produces an adjusted bootloader image with updated headers according to selected flash mode and size values. This step is only executed for debugging or uploading via debug probes. - Implemented a basic mechanism to dynamically add an extra UF2 bootloader image if corresponding partition is selected (e.g. for Adafruit targets) - Minor code formatting --- tools/platformio-build.py | 197 ++++++++++++++++++++++++++++---------- 1 file changed, 147 insertions(+), 50 deletions(-) diff --git a/tools/platformio-build.py b/tools/platformio-build.py index 5690c046d61..4f27fa64231 100644 --- a/tools/platformio-build.py +++ b/tools/platformio-build.py @@ -24,7 +24,7 @@ # Extends: https://github.com/platformio/platform-espressif32/blob/develop/builder/main.py -from os.path import abspath, isdir, isfile, join +from os.path import abspath, basename, isdir, isfile, join from SCons.Script import DefaultEnvironment, SConscript @@ -32,6 +32,9 @@ platform = env.PioPlatform() board_config = env.BoardConfig() build_mcu = board_config.get("build.mcu", "").lower() +partitions_name = board_config.get( + "build.partitions", board_config.get("build.arduino.partitions", "") +) FRAMEWORK_DIR = platform.get_package_dir("framework-arduinoespressif32") assert isdir(FRAMEWORK_DIR) @@ -41,25 +44,23 @@ # Helpers # + def get_partition_table_csv(variants_dir): fwpartitions_dir = join(FRAMEWORK_DIR, "tools", "partitions") + variant_partitions_dir = join(variants_dir, board_config.get("build.variant", "")) - custom_partition = board_config.get( - "build.partitions", board_config.get("build.arduino.partitions", "") - ) + if partitions_name: + # A custom partitions file is selected + if isfile(join(variant_partitions_dir, partitions_name)): + return join(variant_partitions_dir, partitions_name) - if custom_partition: - partitions_csv = board_config.get("build.partitions", board_config.get( - "build.arduino.partitions", "default.csv")) return abspath( - join(fwpartitions_dir, partitions_csv) - if isfile(join(fwpartitions_dir, partitions_csv)) - else partitions_csv + join(fwpartitions_dir, partitions_name) + if isfile(join(fwpartitions_dir, partitions_name)) + else partitions_name ) - variant_partitions = join( - variants_dir, board_config.get("build.variant", ""), "partitions.csv" - ) + variant_partitions = join(variant_partitions_dir, "partitions.csv") return ( variant_partitions if isfile(variant_partitions) @@ -68,9 +69,16 @@ def get_partition_table_csv(variants_dir): def get_bootloader_image(variants_dir): + bootloader_image_file = "bootloader.bin" + if partitions_name.endswith("tinyuf2.csv"): + bootloader_image_file = "bootloader-tinyuf2.bin" + variant_bootloader = join( - variants_dir, board_config.get("build.variant", ""), "bootloader.bin" + variants_dir, + board_config.get("build.variant", ""), + board_config.get("build.arduino.custom_bootloader", bootloader_image_file), ) + return ( variant_bootloader if isfile(variant_bootloader) @@ -85,6 +93,76 @@ def get_bootloader_image(variants_dir): ) +def get_patched_bootloader_image(original_bootloader_image, bootloader_offset): + patched_bootloader_image = join(env.subst("$BUILD_DIR"), "patched_bootloader.bin") + bootloader_cmd = env.Command( + patched_bootloader_image, + original_bootloader_image, + env.VerboseAction( + " ".join( + [ + '"$PYTHONEXE"', + join( + platform.get_package_dir("tool-esptoolpy") or "", "esptool.py" + ), + "--chip", + build_mcu, + "merge_bin", + "-o", + "$TARGET", + "--flash_mode", + "${__get_board_flash_mode(__env__)}", + "--flash_size", + board_config.get("upload.flash_size", "4MB"), + "--target-offset", + bootloader_offset, + bootloader_offset, + "$SOURCE", + ] + ), + "Updating bootloader headers", + ), + ) + env.Depends("$BUILD_DIR/$PROGNAME$PROGSUFFIX", bootloader_cmd) + + return patched_bootloader_image + + +def add_tinyuf2_extra_image(): + tinuf2_image = board_config.get( + "upload.arduino.tinyuf2_image", + join(variants_dir, board_config.get("build.variant", ""), "tinyuf2.bin"), + ) + + # Add the UF2 image only if it exists and it's not already added + if not isfile(tinuf2_image): + print("Warning! The `%s` UF2 bootloader image doesn't exist" % tinuf2_image) + return + + if any( + "tinyuf2.bin" == basename(extra_image[1]) + for extra_image in env.get("FLASH_EXTRA_IMAGES", []) + ): + print("Warning! An extra UF2 bootloader image is already added!") + return + + env.Append( + FLASH_EXTRA_IMAGES=[ + ( + board_config.get( + "upload.arduino.uf2_bootloader_offset", + ( + "0x2d0000" + if env.subst("$BOARD").startswith("adafruit") + else "0x410000" + ), + ), + tinuf2_image, + ), + ] + ) + + # # Run target-specific script to populate the environment with proper build flags # @@ -99,32 +177,6 @@ def get_bootloader_image(variants_dir): ) ) -# -# Process framework extra images -# - -env.Append( - LIBSOURCE_DIRS=[ - join(FRAMEWORK_DIR, "libraries") - ], - - FLASH_EXTRA_IMAGES=[ - ( - "0x1000" if build_mcu in ("esp32", "esp32s2") else "0x0000", - get_bootloader_image(board_config.get( - "build.variants_dir", join(FRAMEWORK_DIR, "variants"))) - ), - ("0x8000", join(env.subst("$BUILD_DIR"), "partitions.bin")), - ("0xe000", join(FRAMEWORK_DIR, "tools", "partitions", "boot_app0.bin")) - ] - + [ - (offset, join(FRAMEWORK_DIR, img)) - for offset, img in board_config.get( - "upload.arduino.flash_extra_images", [] - ) - ], -) - # # Target: Build Core Library # @@ -137,23 +189,68 @@ def get_bootloader_image(variants_dir): variants_dir = join("$PROJECT_DIR", board_config.get("build.variants_dir")) if "build.variant" in board_config: - env.Append( - CPPPATH=[ - join(variants_dir, board_config.get("build.variant")) - ] - ) + env.Append(CPPPATH=[join(variants_dir, board_config.get("build.variant"))]) env.BuildSources( join("$BUILD_DIR", "FrameworkArduinoVariant"), - join(variants_dir, board_config.get("build.variant")) + join(variants_dir, board_config.get("build.variant")), ) -libs.append(env.BuildLibrary( - join("$BUILD_DIR", "FrameworkArduino"), - join(FRAMEWORK_DIR, "cores", board_config.get("build.core")) -)) +libs.append( + env.BuildLibrary( + join("$BUILD_DIR", "FrameworkArduino"), + join(FRAMEWORK_DIR, "cores", board_config.get("build.core")), + ) +) env.Prepend(LIBS=libs) +# +# Process framework extra images +# + +# Starting with v2.0.4 the Arduino core contains updated bootloader images that have +# innacurate default headers. This results in bootloops if firmware is flashed via +# OpenOCD (e.g. debugging or uploading via debug tools). For this reason, before +# uploading or debugging we need to adjust the bootloader binary according to +# the values of the --flash-size and --flash-mode arguments. +# Note: This behavior doesn't occur if uploading is done via esptoolpy, as esptoolpy +# overrides the binary image headers before flashing. + +bootloader_patch_required = bool( + env.get("PIOFRAMEWORK", []) == ["arduino"] + and ( + "debug" in env.GetBuildType() + or env.subst("$UPLOAD_PROTOCOL") in board_config.get("debug.tools", {}) + or env.IsIntegrationDump() + ) +) + +bootloader_image_path = get_bootloader_image(variants_dir) +bootloader_offset = "0x1000" if build_mcu in ("esp32", "esp32s2") else "0x0000" +if bootloader_patch_required: + bootloader_image_path = get_patched_bootloader_image( + bootloader_image_path, bootloader_offset + ) + +env.Append( + LIBSOURCE_DIRS=[join(FRAMEWORK_DIR, "libraries")], + FLASH_EXTRA_IMAGES=[ + (bootloader_offset, bootloader_image_path), + ("0x8000", join(env.subst("$BUILD_DIR"), "partitions.bin")), + ("0xe000", join(FRAMEWORK_DIR, "tools", "partitions", "boot_app0.bin")), + ] + + [ + (offset, join(FRAMEWORK_DIR, img)) + for offset, img in board_config.get("upload.arduino.flash_extra_images", []) + ], +) + +# Add an extra UF2 image if the 'TinyUF2' partition is selected +if partitions_name.endswith("tinyuf2.csv") or board_config.get( + "upload.arduino.tinyuf2_image", "" +): + add_tinyuf2_extra_image() + # # Generate partition table #