Преглед изворни кода

Add esp_flasher/lib/esp-serial-flasher from https://github.com/0xchocolate/esp-serial-flasher

git-subtree-dir: esp_flasher/lib/esp-serial-flasher
git-subtree-mainline: 6fd2938c7430f1b6c6f15b30448a877acb504154
git-subtree-split: 81805a34394a09b0cc03f85fb02123b8a8eb9fc1
Willy-JL пре 2 година
родитељ
комит
2190703c59
100 измењених фајлова са 5569 додато и 0 уклоњено
  1. 47 0
      esp_flasher/lib/esp-serial-flasher/.github/ISSUE_TEMPLATE/bug_report.yml
  2. 34 0
      esp_flasher/lib/esp-serial-flasher/.github/ISSUE_TEMPLATE/feature_request.yml
  3. 20 0
      esp_flasher/lib/esp-serial-flasher/.github/workflows/issue_comment.yml
  4. 20 0
      esp_flasher/lib/esp-serial-flasher/.github/workflows/new_issues.yml
  5. 25 0
      esp_flasher/lib/esp-serial-flasher/.github/workflows/new_prs.yml
  6. 6 0
      esp_flasher/lib/esp-serial-flasher/.gitignore
  7. 139 0
      esp_flasher/lib/esp-serial-flasher/.gitlab-ci.yml
  8. 3 0
      esp_flasher/lib/esp-serial-flasher/.gitmodules
  9. 1 0
      esp_flasher/lib/esp-serial-flasher/.gitsubtree
  10. 145 0
      esp_flasher/lib/esp-serial-flasher/CMakeLists.txt
  11. 38 0
      esp_flasher/lib/esp-serial-flasher/Kconfig
  12. 202 0
      esp_flasher/lib/esp-serial-flasher/LICENSE
  13. 163 0
      esp_flasher/lib/esp-serial-flasher/README.md
  14. BIN
      esp_flasher/lib/esp-serial-flasher/examples/binaries/ESP32_AT_Firmware/Firmware.bin
  15. BIN
      esp_flasher/lib/esp-serial-flasher/examples/binaries/Hello-world/ESP32/bootloader.bin
  16. BIN
      esp_flasher/lib/esp-serial-flasher/examples/binaries/Hello-world/ESP32/hello_world.bin
  17. BIN
      esp_flasher/lib/esp-serial-flasher/examples/binaries/Hello-world/ESP32/partition-table.bin
  18. BIN
      esp_flasher/lib/esp-serial-flasher/examples/binaries/Hello-world/ESP32_C2/bootloader.bin
  19. BIN
      esp_flasher/lib/esp-serial-flasher/examples/binaries/Hello-world/ESP32_C2/hello_world.bin
  20. BIN
      esp_flasher/lib/esp-serial-flasher/examples/binaries/Hello-world/ESP32_C2/partition-table.bin
  21. BIN
      esp_flasher/lib/esp-serial-flasher/examples/binaries/Hello-world/ESP32_C3/bootloader.bin
  22. BIN
      esp_flasher/lib/esp-serial-flasher/examples/binaries/Hello-world/ESP32_C3/hello_world.bin
  23. BIN
      esp_flasher/lib/esp-serial-flasher/examples/binaries/Hello-world/ESP32_C3/partition-table.bin
  24. BIN
      esp_flasher/lib/esp-serial-flasher/examples/binaries/Hello-world/ESP32_C6/bootloader.bin
  25. BIN
      esp_flasher/lib/esp-serial-flasher/examples/binaries/Hello-world/ESP32_C6/hello_world.bin
  26. BIN
      esp_flasher/lib/esp-serial-flasher/examples/binaries/Hello-world/ESP32_C6/partition-table.bin
  27. BIN
      esp_flasher/lib/esp-serial-flasher/examples/binaries/Hello-world/ESP32_H2/bootloader.bin
  28. BIN
      esp_flasher/lib/esp-serial-flasher/examples/binaries/Hello-world/ESP32_H2/hello_world.bin
  29. BIN
      esp_flasher/lib/esp-serial-flasher/examples/binaries/Hello-world/ESP32_H2/partition-table.bin
  30. BIN
      esp_flasher/lib/esp-serial-flasher/examples/binaries/Hello-world/ESP32_H4/bootloader.bin
  31. BIN
      esp_flasher/lib/esp-serial-flasher/examples/binaries/Hello-world/ESP32_H4/hello_world.bin
  32. BIN
      esp_flasher/lib/esp-serial-flasher/examples/binaries/Hello-world/ESP32_H4/partition-table.bin
  33. BIN
      esp_flasher/lib/esp-serial-flasher/examples/binaries/Hello-world/ESP32_S2/bootloader.bin
  34. BIN
      esp_flasher/lib/esp-serial-flasher/examples/binaries/Hello-world/ESP32_S2/hello_world.bin
  35. BIN
      esp_flasher/lib/esp-serial-flasher/examples/binaries/Hello-world/ESP32_S2/partition-table.bin
  36. BIN
      esp_flasher/lib/esp-serial-flasher/examples/binaries/Hello-world/ESP32_S3/bootloader.bin
  37. BIN
      esp_flasher/lib/esp-serial-flasher/examples/binaries/Hello-world/ESP32_S3/hello_world.bin
  38. BIN
      esp_flasher/lib/esp-serial-flasher/examples/binaries/Hello-world/ESP32_S3/partition-table.bin
  39. BIN
      esp_flasher/lib/esp-serial-flasher/examples/binaries/Hello-world/ESP8266/bootloader.bin
  40. BIN
      esp_flasher/lib/esp-serial-flasher/examples/binaries/Hello-world/ESP8266/hello-world.bin
  41. BIN
      esp_flasher/lib/esp-serial-flasher/examples/binaries/Hello-world/ESP8266/partition-table.bin
  42. BIN
      esp_flasher/lib/esp-serial-flasher/examples/binaries/RAM_APP/ESP32/app.bin
  43. BIN
      esp_flasher/lib/esp-serial-flasher/examples/binaries/RAM_APP/ESP32_C2/app.bin
  44. BIN
      esp_flasher/lib/esp-serial-flasher/examples/binaries/RAM_APP/ESP32_C3/app.bin
  45. BIN
      esp_flasher/lib/esp-serial-flasher/examples/binaries/RAM_APP/ESP32_C6/app.bin
  46. BIN
      esp_flasher/lib/esp-serial-flasher/examples/binaries/RAM_APP/ESP32_H2/app.bin
  47. BIN
      esp_flasher/lib/esp-serial-flasher/examples/binaries/RAM_APP/ESP32_H4/app.bin
  48. BIN
      esp_flasher/lib/esp-serial-flasher/examples/binaries/RAM_APP/ESP32_S2/app.bin
  49. BIN
      esp_flasher/lib/esp-serial-flasher/examples/binaries/RAM_APP/ESP32_S3/app.bin
  50. 15 0
      esp_flasher/lib/esp-serial-flasher/examples/binaries/RAM_APP/source/CMakeLists.txt
  51. 2 0
      esp_flasher/lib/esp-serial-flasher/examples/binaries/RAM_APP/source/main/CMakeLists.txt
  52. 16 0
      esp_flasher/lib/esp-serial-flasher/examples/binaries/RAM_APP/source/main/main.c
  53. 11 0
      esp_flasher/lib/esp-serial-flasher/examples/binaries/RAM_APP/source/sdkconfig.defaults
  54. 20 0
      esp_flasher/lib/esp-serial-flasher/examples/common/bin2array.cmake
  55. 402 0
      esp_flasher/lib/esp-serial-flasher/examples/common/example_common.c
  56. 63 0
      esp_flasher/lib/esp-serial-flasher/examples/common/example_common.h
  57. 7 0
      esp_flasher/lib/esp-serial-flasher/examples/esp32_example/CMakeLists.txt
  58. 78 0
      esp_flasher/lib/esp-serial-flasher/examples/esp32_example/README.md
  59. 22 0
      esp_flasher/lib/esp-serial-flasher/examples/esp32_example/main/CMakeLists.txt
  60. 54 0
      esp_flasher/lib/esp-serial-flasher/examples/esp32_example/main/main.c
  61. 4 0
      esp_flasher/lib/esp-serial-flasher/examples/esp32_example/partitions.csv
  62. 1 0
      esp_flasher/lib/esp-serial-flasher/examples/esp32_example/sdkconfig.defaults
  63. 7 0
      esp_flasher/lib/esp-serial-flasher/examples/esp32_load_ram_example/CMakeLists.txt
  64. 14 0
      esp_flasher/lib/esp-serial-flasher/examples/esp32_load_ram_example/main/CMakeLists.txt
  65. 80 0
      esp_flasher/lib/esp-serial-flasher/examples/esp32_load_ram_example/main/main.c
  66. 7 0
      esp_flasher/lib/esp-serial-flasher/examples/esp32_spi_load_ram_example/CMakeLists.txt
  67. 80 0
      esp_flasher/lib/esp-serial-flasher/examples/esp32_spi_load_ram_example/README.md
  68. 14 0
      esp_flasher/lib/esp-serial-flasher/examples/esp32_spi_load_ram_example/main/CMakeLists.txt
  69. 97 0
      esp_flasher/lib/esp-serial-flasher/examples/esp32_spi_load_ram_example/main/main.c
  70. 4 0
      esp_flasher/lib/esp-serial-flasher/examples/esp32_spi_load_ram_example/sdkconfig.defaults
  71. 17 0
      esp_flasher/lib/esp-serial-flasher/examples/raspberry_example/CMakeLists.txt
  72. 76 0
      esp_flasher/lib/esp-serial-flasher/examples/raspberry_example/README.md
  73. 81 0
      esp_flasher/lib/esp-serial-flasher/examples/raspberry_example/Src/main.c
  74. 46 0
      esp_flasher/lib/esp-serial-flasher/examples/stm32_example/CMakeLists.txt
  75. 73 0
      esp_flasher/lib/esp-serial-flasher/examples/stm32_example/Core/Inc/main.h
  76. 515 0
      esp_flasher/lib/esp-serial-flasher/examples/stm32_example/Core/Inc/stm32h7xx_hal_conf.h
  77. 66 0
      esp_flasher/lib/esp-serial-flasher/examples/stm32_example/Core/Inc/stm32h7xx_it.h
  78. 197 0
      esp_flasher/lib/esp-serial-flasher/examples/stm32_example/Core/Src/libc_compat.c
  79. 352 0
      esp_flasher/lib/esp-serial-flasher/examples/stm32_example/Core/Src/main.c
  80. 209 0
      esp_flasher/lib/esp-serial-flasher/examples/stm32_example/Core/Src/stm32h7xx_hal_msp.c
  81. 203 0
      esp_flasher/lib/esp-serial-flasher/examples/stm32_example/Core/Src/stm32h7xx_it.c
  82. 52 0
      esp_flasher/lib/esp-serial-flasher/examples/stm32_example/README.md
  83. 192 0
      esp_flasher/lib/esp-serial-flasher/examples/stm32_example/stm32_flasher.ioc
  84. 27 0
      esp_flasher/lib/esp-serial-flasher/examples/zephyr_example/CMakeLists.txt
  85. 86 0
      esp_flasher/lib/esp-serial-flasher/examples/zephyr_example/README.md
  86. 34 0
      esp_flasher/lib/esp-serial-flasher/examples/zephyr_example/boards/esp32_devkitc_wroom.overlay
  87. 34 0
      esp_flasher/lib/esp-serial-flasher/examples/zephyr_example/boards/esp32_devkitc_wrover.overlay
  88. 4 0
      esp_flasher/lib/esp-serial-flasher/examples/zephyr_example/prj.conf
  89. 9 0
      esp_flasher/lib/esp-serial-flasher/examples/zephyr_example/sample.yaml
  90. 81 0
      esp_flasher/lib/esp-serial-flasher/examples/zephyr_example/src/main.c
  91. 3 0
      esp_flasher/lib/esp-serial-flasher/idf_component.yml
  92. 299 0
      esp_flasher/lib/esp-serial-flasher/include/esp_loader.h
  93. 112 0
      esp_flasher/lib/esp-serial-flasher/include/esp_loader_io.h
  94. 24 0
      esp_flasher/lib/esp-serial-flasher/include/serial_io.h
  95. 181 0
      esp_flasher/lib/esp-serial-flasher/port/esp32_port.c
  96. 59 0
      esp_flasher/lib/esp-serial-flasher/port/esp32_port.h
  97. 298 0
      esp_flasher/lib/esp-serial-flasher/port/esp32_spi_port.c
  98. 60 0
      esp_flasher/lib/esp-serial-flasher/port/esp32_spi_port.h
  99. 302 0
      esp_flasher/lib/esp-serial-flasher/port/raspberry_port.c
  100. 36 0
      esp_flasher/lib/esp-serial-flasher/port/raspberry_port.h

+ 47 - 0
esp_flasher/lib/esp-serial-flasher/.github/ISSUE_TEMPLATE/bug_report.yml

@@ -0,0 +1,47 @@
+name: Bug report
+description: Report a problem with esp-serial-flasher operation
+labels: ['Type: Bug']
+body:
+  - type: markdown
+    attributes:
+      value: |
+        * Please ensure you are using the latest version of `esp-serial-flasher`.
+        * Try using one of the examples from the `examples` directory and following the example documentation.
+        * If your board is a custom design, consider using our [free-of-charge schematic and PCB review service](https://www.espressif.com/en/contact-us/circuit-schematic-pcb-design-review).
+        * If still experiencing issues, please provide as many details as possible below about your hardware and software setup.
+  - type: input
+    id: port
+    attributes:
+      label: Port
+      description: Which port are you experiencing the issue with?
+      placeholder: ex. ESP, STM32
+    validations:
+      required: true
+  - type: input
+    id: target
+    attributes:
+      label: Target chip
+      description: Which chip are you trying to flash?
+      placeholder: ex. ESP8266, ESP32, ESP32-C3
+    validations:
+      required: true
+  - type: textarea
+    id: other-hw
+    attributes:
+      label: Hardware Configuration
+      description: What dev boards/custom PCB are you using, how are the chips connected, which baudrate are you trying to flash with?
+    validations:
+      required: true
+    id: output
+  - type: textarea
+    attributes:
+      label: Log output
+      description: Enable tracing with SERIAL_FLASHER_DEBUG_TRACE and provide the full log.
+      render: plain
+    validations:
+      required: true
+  - type: textarea
+    id: more-info
+    attributes:
+      label: More Information
+      description: Provide any additional information relevant to the issue.

+ 34 - 0
esp_flasher/lib/esp-serial-flasher/.github/ISSUE_TEMPLATE/feature_request.yml

@@ -0,0 +1,34 @@
+name: Feature request
+description: Suggest an idea for this project
+labels: ['Type: Feature Request']
+body:
+  - type: markdown
+    attributes:
+      value: |
+        * We welcome any ideas or feature requests! It's helpful if you can explain exactly why the feature would be useful.
+        * Please check if the feature has already been suggested in [existing issues](https://github.com/espressif/esp-serial-flasher/issues) or [pull requests](https://github.com/espressif/esp-serial-flasher/pulls).
+        * Please provide enough context so that the reasoning behind the suggestion can be understood.
+  - type: textarea
+    id: problem-related
+    attributes:
+      label: Is your feature request related to a problem?
+      description: Please provide a clear and concise description of what the problem is.
+    validations:
+      required: true
+  - type: textarea
+    id: solution
+    attributes:
+      label: Describe the solution you'd like
+      description: Please provide a clear and concise description of a solution of the described problem or usecase.
+    validations:
+      required: true
+  - type: textarea
+    id: alternatives
+    attributes:
+      label: Describe alternatives you've considered
+      description: Please provide a clear and concise description of any alternative solutions or features you've considered.
+  - type: textarea
+    id: context
+    attributes:
+      label: Additional context
+      description: Please add any other context here.

+ 20 - 0
esp_flasher/lib/esp-serial-flasher/.github/workflows/issue_comment.yml

@@ -0,0 +1,20 @@
+name: Sync issue comments to JIRA
+
+# This workflow will be triggered when new issue comment is created (including PR comments)
+on: issue_comment
+
+jobs:
+  sync_issue_comments_to_jira:
+    name: Sync Issue Comments to Jira
+    runs-on: ubuntu-latest
+    steps:
+      - uses: actions/checkout@master
+      - name: Sync issue comments to JIRA
+        uses: espressif/github-actions/sync_issues_to_jira@master
+        env:
+          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+          JIRA_PASS: ${{ secrets.JIRA_PASS }}
+          JIRA_PROJECT: ESF
+          JIRA_COMPONENT: GitHub
+          JIRA_URL: ${{ secrets.JIRA_URL }}
+          JIRA_USER: ${{ secrets.JIRA_USER }}

+ 20 - 0
esp_flasher/lib/esp-serial-flasher/.github/workflows/new_issues.yml

@@ -0,0 +1,20 @@
+name: Sync issues to Jira
+
+# This workflow will be triggered when a new issue is opened
+on: issues
+
+jobs:
+  sync_issues_to_jira:
+    name: Sync issues to Jira
+    runs-on: ubuntu-latest
+    steps:
+      - uses: actions/checkout@master
+      - name: Sync GitHub issues to Jira project
+        uses: espressif/github-actions/sync_issues_to_jira@master
+        env:
+          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+          JIRA_PASS: ${{ secrets.JIRA_PASS }}
+          JIRA_PROJECT: ESF
+          JIRA_COMPONENT: GitHub
+          JIRA_URL: ${{ secrets.JIRA_URL }}
+          JIRA_USER: ${{ secrets.JIRA_USER }}

+ 25 - 0
esp_flasher/lib/esp-serial-flasher/.github/workflows/new_prs.yml

@@ -0,0 +1,25 @@
+name: Sync remain PRs to Jira
+
+# This workflow will be triggered every hour, to sync remaining PRs (i.e. PRs with zero comment) to Jira project
+# Note that, PRs can also get synced when new PR comment is created
+on:
+  schedule:
+    - cron: "0 * * * *"
+
+jobs:
+  sync_prs_to_jira:
+    name: Sync PRs to Jira
+    runs-on: ubuntu-latest
+    steps:
+      - uses: actions/checkout@master
+      - name: Sync PRs to Jira project
+        uses: espressif/github-actions/sync_issues_to_jira@master
+        with:
+          cron_job: true
+        env:
+          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+          JIRA_PASS: ${{ secrets.JIRA_PASS }}
+          JIRA_PROJECT: ESF
+          JIRA_COMPONENT: GitHub
+          JIRA_URL: ${{ secrets.JIRA_URL }}
+          JIRA_USER: ${{ secrets.JIRA_USER }}

+ 6 - 0
esp_flasher/lib/esp-serial-flasher/.gitignore

@@ -0,0 +1,6 @@
+build
+sdkconfig
+sdkconfig.old
+empty_file.bin
+binaries.c
+*.lock

+ 139 - 0
esp_flasher/lib/esp-serial-flasher/.gitlab-ci.yml

@@ -0,0 +1,139 @@
+stages:
+  - build
+  - test
+  - deploy
+
+workflow:
+  rules:
+    - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
+    - if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS && $CI_PIPELINE_SOURCE == "push"
+      when: never
+    - if: "$CI_COMMIT_BRANCH"
+
+variables:
+  STM32_CUBE_H7_REPO: https://github.com/STMicroelectronics/STM32CubeH7
+  STM32_CUBE_H7_REPO_TAG: v1.11.1
+  ARM_TOOLCHAIN_URL: https://developer.arm.com/-/media/Files/downloads/gnu/13.2.rel1/binrel/arm-gnu-toolchain-13.2.rel1-x86_64-arm-none-eabi.tar.xz?rev=e434b9ea4afc4ed7998329566b764309&hash=CA590209F5774EE1C96E6450E14A3E26
+  QEMU_PATH: /opt/qemu/bin/qemu-system-xtensa
+  ZEPHYR_REPO: https://github.com/zephyrproject-rtos/zephyr.git
+  ZEPHYR_REPO_REV: v3.5.0
+  ZEPHYR_TOOLCHAIN: https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.16.3/toolchain_linux-x86_64_xtensa-espressif_esp32_zephyr-elf.tar.xz
+  ZEPHYR_SDK: https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.16.3/zephyr-sdk-0.16.3_linux-aarch64_minimal.tar.xz
+
+.build_idf_template:
+  stage: build
+  image: espressif/idf:latest
+  tags:
+    - build
+    - internet
+  variables:
+    PEDANTIC_FLAGS: "-Werror=all -Werror=extra"
+    EXTRA_CFLAGS: "${PEDANTIC_FLAGS}"
+    EXTRA_CXXFLAGS: "${PEDANTIC_FLAGS}"
+  script:
+    - cd $CI_PROJECT_DIR/examples/esp32_example
+    - idf.py build -DMD5_ENABLED=1
+    - idf.py build -DMD5_ENABLED=0
+    - cd $CI_PROJECT_DIR/examples/esp32_load_ram_example
+    - idf.py build
+    - cd $CI_PROJECT_DIR/examples/esp32_spi_load_ram_example
+    - idf.py build
+
+build_idf_v4.2:
+  extends: .build_idf_template
+  image: espressif/idf:release-v4.2
+
+build_idf_v4.3:
+  extends: .build_idf_template
+  image: espressif/idf:release-v4.3
+
+build_idf_v4.4:
+  extends: .build_idf_template
+  image: espressif/idf:release-v4.4
+
+build_idf_v5.0:
+  extends: .build_idf_template
+  image: espressif/idf:release-v5.0
+
+build_idf_v5.1:
+  extends: .build_idf_template
+  image: espressif/idf:release-v5.1
+
+build_idf_master:
+  extends: .build_idf_template
+  image: espressif/idf:latest
+
+build_stm32:
+  stage: build
+  # IDF is not necessary for STM32 build, but this image is already used in another job
+  # and it comes with a recent enough CMake version.
+  image: espressif/idf:latest
+  tags:
+    - build
+    - internet
+  script:
+    - cd $CI_PROJECT_DIR
+    - git submodule update --init
+    - git clone --depth=1 -b ${STM32_CUBE_H7_REPO_TAG} ${STM32_CUBE_H7_REPO}
+    - wget --no-verbose -O gcc-arm-none-eabi.tar.xz ${ARM_TOOLCHAIN_URL}
+    - tar xf gcc-arm-none-eabi.tar.xz
+    - mv arm-gnu-toolchain-* gcc-arm-none-eabi
+    - mkdir $CI_PROJECT_DIR/examples/stm32_example/build
+    - cd $CI_PROJECT_DIR/examples/stm32_example/build
+    - cmake -DSTM32_TOOLCHAIN_PATH=$CI_PROJECT_DIR/gcc-arm-none-eabi -DSTM32_CUBE_H7_PATH=$CI_PROJECT_DIR/STM32CubeH7 -G Ninja ..
+    - cmake --build .
+
+build_zephyr:
+  stage: build
+  image: espressif/idf:latest
+  tags:
+    - build
+    - internet
+  script:
+    - mkdir $CI_PROJECT_DIR/zephyrproject-rtos
+    - cd $CI_PROJECT_DIR/zephyrproject-rtos
+    - git clone --single-branch --depth=1 -b ${ZEPHYR_REPO_REV} ${ZEPHYR_REPO}
+    - mkdir $CI_PROJECT_DIR/zephyrproject-rtos/zephyr-sdk
+    - cd $CI_PROJECT_DIR/zephyrproject-rtos/zephyr-sdk
+    - wget --no-verbose -O zephyr_sdk.tar.xz ${ZEPHYR_SDK}
+    - tar xvf zephyr_sdk.tar.xz --strip-components=1
+    - wget --no-verbose -O esp32_toolchain.tar.xz ${ZEPHYR_TOOLCHAIN}
+    - tar xvf esp32_toolchain.tar.xz
+    - export ZEPHYR_SDK_INSTALL_DIR=$(pwd)
+    - export ZEPHYR_TOOLCHAIN_VARIANT="zephyr"
+    - cd $CI_PROJECT_DIR/zephyrproject-rtos/zephyr
+    - export ZEPHYR_BASE=$(pwd)
+    - pip install -r scripts/requirements.txt
+    - pip install wheel
+    - if [[ ! -d "$CI_PROJECT_DIR/zephyrproject-rtos/.west" ]]; then
+    - west init -l .
+    - fi
+    - unset IDF_PATH
+    - west zephyr-export
+    - west update hal_espressif
+    - west build -p -b esp32_devkitc_wroom $CI_PROJECT_DIR/examples/zephyr_example -DZEPHYR_EXTRA_MODULES=$CI_PROJECT_DIR
+
+run_tests:
+  stage: test
+  image: ${CI_DOCKER_REGISTRY}/qemu:esp-develop-20191124
+  tags:
+    - build
+    - internet
+  script:
+    - cd $CI_PROJECT_DIR/test
+    - export QEMU_PATH=/opt/qemu/bin/qemu-system-xtensa
+    - ./run_test.sh qemu
+    - ./run_test.sh host
+
+push_to_the_components_registry:
+  stage: deploy
+  image: python:3.10-alpine
+  tags:
+    - build
+    - internet
+  rules:
+    - if: '$CI_COMMIT_BRANCH == "master"'
+    - if: '$FORCE_PUSH_COMPONENT == "1"'
+  script:
+    - pip install idf-component-manager
+    - python -m idf_component_manager upload-component --allow-existing --name=esp-serial-flasher --namespace=espressif

+ 3 - 0
esp_flasher/lib/esp-serial-flasher/.gitmodules

@@ -0,0 +1,3 @@
+[submodule "submodules/stm32-cmake"]
+	path = submodules/stm32-cmake
+	url = https://github.com/ObKo/stm32-cmake.git

+ 1 - 0
esp_flasher/lib/esp-serial-flasher/.gitsubtree

@@ -0,0 +1 @@
+https://github.com/0xchocolate/esp-serial-flasher master /

+ 145 - 0
esp_flasher/lib/esp-serial-flasher/CMakeLists.txt

@@ -0,0 +1,145 @@
+cmake_minimum_required(VERSION 3.5)
+
+set(srcs
+    src/esp_targets.c
+    src/md5_hash.c
+    src/esp_loader.c
+    src/protocol_common.c
+)
+
+if (DEFINED ESP_PLATFORM)
+    if (${CONFIG_SERIAL_FLASHER_INTERFACE_UART})
+        list(APPEND srcs
+            src/protocol_uart.c
+            src/slip.c
+            port/esp32_port.c
+        )
+    elseif (${CONFIG_SERIAL_FLASHER_INTERFACE_SPI})
+        list(APPEND srcs
+            src/protocol_spi.c
+            port/esp32_spi_port.c
+        )
+    endif()
+    # Register component to esp-idf build system
+    if ("${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}" VERSION_GREATER "4.0")
+        # esp_timer component was introduced in v4.2
+        set(priv_requires driver)
+        if("${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}" VERSION_GREATER "4.1")
+            list(APPEND priv_requires esp_timer)
+        endif()
+
+        idf_component_register(SRCS ${srcs}
+                               INCLUDE_DIRS include port
+                               PRIV_INCLUDE_DIRS private_include
+                               PRIV_REQUIRES ${priv_requires})
+
+        set(target ${COMPONENT_LIB})
+        component_compile_options(-Wstrict-prototypes)
+    else()
+        # Remove when dropping support for IDF 3.3
+        set(COMPONENT_SRCS ${srcs})
+        set(COMPONENT_ADD_INCLUDEDIRS include port)
+        set(COMPONENT_PRIV_INCLUDEDIRS private_include)
+        register_component()
+        set(target ${COMPONENT_TARGET})
+    endif()
+
+else()
+    if (NOT DEFINED SERIAL_FLASHER_INTERFACE_UART AND NOT DEFINED SERIAL_FLASHER_INTERFACE_SPI)
+        set(SERIAL_FLASHER_INTERFACE_UART true)
+    endif()
+
+    if (DEFINED SERIAL_FLASHER_INTERFACE_UART)
+        list(APPEND srcs
+            src/protocol_uart.c
+            src/slip.c
+        )
+    elseif (DEFINED SERIAL_FLASHER_INTERFACE_SPI)
+        list(APPEND srcs src/protocol_spi.c)
+    endif()
+
+    # Create traditional CMake target
+    add_library(flasher ${srcs})
+
+    target_include_directories(flasher PUBLIC include port PRIVATE private_include)
+
+    if(PORT STREQUAL "STM32")
+        stm32_get_chip_info(${STM32_CHIP} FAMILY DEVICE_FAMILY DEVICE DEVICE_CODE)
+        if(DEFINED CORE_USED)
+            string(APPEND DEVICE_FAMILY ::${CORE_USED})
+            string(APPEND DEVICE_CODE ::${CORE_USED})
+        endif()
+        target_link_libraries(flasher PRIVATE
+            HAL::STM32::${DEVICE_FAMILY}::GPIO
+            HAL::STM32::${DEVICE_FAMILY}::UART
+            CMSIS::STM32::${DEVICE_CODE}
+        )
+        target_sources(flasher PRIVATE port/stm32_port.c)
+    elseif(PORT STREQUAL "RASPBERRY_PI")
+        find_library(pigpio_LIB pigpio)
+        target_link_libraries(flasher PUBLIC ${pigpio_LIB})
+        target_sources(flasher PRIVATE port/raspberry_port.c)
+    else()
+        message(FATAL_ERROR "Selected port is not supported")
+    endif()
+
+    set(target flasher)
+
+endif()
+
+if (DEFINED SERIAL_FLASHER_INTERFACE_UART OR CONFIG_SERIAL_FLASHER_INTERFACE_UART STREQUAL "y")
+    target_compile_definitions(${target}
+    PUBLIC
+        SERIAL_FLASHER_INTERFACE_UART
+    )
+    if (DEFINED MD5_ENABLED OR CONFIG_SERIAL_FLASHER_MD5_ENABLED)
+        target_compile_definitions(${target} PUBLIC MD5_ENABLED=1)
+    endif()
+elseif (DEFINED SERIAL_FLASHER_INTERFACE_SPI OR CONFIG_SERIAL_FLASHER_INTERFACE_SPI STREQUAL "y")
+    target_compile_definitions(${target}
+    PUBLIC
+        SERIAL_FLASHER_INTERFACE_SPI
+    )
+endif()
+
+if(DEFINED SERIAL_FLASHER_DEBUG_TRACE OR CONFIG_SERIAL_FLASHER_DEBUG_TRACE)
+    target_compile_definitions(${target} PUBLIC SERIAL_FLASHER_DEBUG_TRACE)
+endif()
+
+if(DEFINED CONFIG_SERIAL_FLASHER_RESET_HOLD_TIME_MS AND DEFINED CONFIG_SERIAL_FLASHER_BOOT_HOLD_TIME_MS)
+    target_compile_definitions(${target}
+    PUBLIC
+        SERIAL_FLASHER_RESET_HOLD_TIME_MS=${CONFIG_SERIAL_FLASHER_RESET_HOLD_TIME_MS}
+        SERIAL_FLASHER_BOOT_HOLD_TIME_MS=${CONFIG_SERIAL_FLASHER_BOOT_HOLD_TIME_MS}
+    )
+else()
+    if(NOT DEFINED SERIAL_FLASHER_RESET_HOLD_TIME_MS)
+        target_compile_definitions(${target}
+        PUBLIC
+            SERIAL_FLASHER_RESET_HOLD_TIME_MS=100
+        )
+    endif()
+    if(NOT DEFINED SERIAL_FLASHER_BOOT_HOLD_TIME_MS)
+        target_compile_definitions(${target}
+        PUBLIC
+            SERIAL_FLASHER_BOOT_HOLD_TIME_MS=50
+        )
+    endif()
+endif()
+
+if (DEFINED CONFIG_SERIAL_FLASHER_WRITE_BLOCK_RETRIES)
+    target_compile_definitions(${target}
+    PUBLIC
+        SERIAL_FLASHER_WRITE_BLOCK_RETRIES=${CONFIG_SERIAL_FLASHER_WRITE_BLOCK_RETRIES}
+    )
+elseif (DEFINED SERIAL_FLASHER_WRITE_BLOCK_RETRIES)
+    target_compile_definitions(${target}
+    PUBLIC
+        SERIAL_FLASHER_WRITE_BLOCK_RETRIES=${SERIAL_FLASHER_WRITE_BLOCK_RETRIES}
+    )
+else()
+    target_compile_definitions(${target}
+    PUBLIC
+        SERIAL_FLASHER_WRITE_BLOCK_RETRIES=3
+    )
+endif()

+ 38 - 0
esp_flasher/lib/esp-serial-flasher/Kconfig

@@ -0,0 +1,38 @@
+menu "ESP serial flasher"
+    config SERIAL_FLASHER_MD5_ENABLED
+        bool "Enable MD5 check"
+        default y
+        help
+            Select this option to enable MD5 hashsum check after flashing.
+
+    choice SERIAL_FLASHER_INTERFACE
+        prompt "Hardware interface to use for firmware download"
+        default SERIAL_FLASHER_INTERFACE_UART
+        help
+            esp-serial-flasher can work with UART and SPI interfaces.
+
+        config SERIAL_FLASHER_INTERFACE_UART
+            bool "UART"
+
+        config SERIAL_FLASHER_INTERFACE_SPI
+            bool "SPI (Only supports downloading to RAM, experimental)"
+
+    endchoice
+
+    config SERIAL_FLASHER_RESET_HOLD_TIME_MS
+        int "Time for which the reset pin is asserted when doing a hard reset"
+        default 100
+
+    config SERIAL_FLASHER_BOOT_HOLD_TIME_MS
+        int "Time for which the boot pin is asserted when doing a hard reset"
+        default 50
+
+    config SERIAL_FLASHER_DEBUG_TRACE
+        bool "Enable debug tracing output (only transfer data tracing is supported at the time)"
+        default n
+
+    config SERIAL_FLASHER_WRITE_BLOCK_RETRIES
+        int "Number of retries when writing blocks either to target flash or RAM"
+        default 3
+
+endmenu

+ 202 - 0
esp_flasher/lib/esp-serial-flasher/LICENSE

@@ -0,0 +1,202 @@
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.

+ 163 - 0
esp_flasher/lib/esp-serial-flasher/README.md

@@ -0,0 +1,163 @@
+# esp-serial-flasher
+
+`esp-serial-flasher` is a portable C library for flashing or loading apps to RAM of Espressif SoCs from other host microcontrollers.
+
+## Using the library
+Espressif SoCs are normally programmed via serial interface (UART). The port layer for the given host microcontroller has to be implemented if not available. Details can be found in section below.
+
+Supported **host** microcontrollers:
+
+- STM32
+- Raspberry Pi SBC
+- ESP32
+- Any MCU running Zephyr OS
+
+Supported **target** microcontrollers:
+
+- ESP32
+- ESP8266
+- ESP32-S2
+- ESP32-S3
+- ESP32-C3
+- ESP32-C2
+- ESP32-H2
+- ESP32-C6
+
+Supported hardware interfaces:
+- UART
+- SPI (only for RAM download, experimental)
+
+For example usage check the `examples` directory.
+
+## Supporting a new host target
+
+In order to support a new target, following functions have to be implemented by user:
+
+- `loader_port_read()`
+- `loader_port_write()`
+- `loader_port_enter_bootloader()`
+- `loader_port_delay_ms()`
+- `loader_port_start_timer()`
+- `loader_port_remaining_time()`
+
+For the SPI interface ports
+- `loader_port_spi_set_cs()`
+needs to be implemented as well.
+
+The following functions are part of the [io.h](include/io.h) header for convenience, however, the user does not have to strictly follow function signatures, as there are not called directly from library.
+
+- `loader_port_change_transmission_rate()`
+- `loader_port_reset_target()`
+- `loader_port_debug_print()`
+
+Prototypes of all functions mentioned above can be found in [io.h](include/io.h).
+
+## Configuration
+
+These are the configuration toggles available to the user:
+
+* `SERIAL_FLASHER_INTERFACE_UART/SERIAL_FLASHER_INTERFACE_SPI`
+
+This defines the hardware interface to use. SPI interface only supports RAM download mode and is in experimental stage and can undergo changes.
+
+Default: SERIAL_FLASHER_INTERFACE_UART
+
+* `MD5_ENABLED`
+
+If enabled, `esp-serial-flasher` is capable of verifying flash integrity after writing to flash.
+
+Default: Enabled
+> Warning: As ROM bootloader of the ESP8266 does not support MD5_CHECK, this option has to be disabled!
+
+* `SERIAL_FLASHER_WRITE_BLOCK_RETRIES`
+
+This configures the amount of retries for writing blocks either to target flash or RAM.
+
+Default: 3
+
+* `SERIAL_FLASHER_RESET_HOLD_TIME_MS`
+
+This is the time for which the reset pin is asserted when doing a hard reset in milliseconds.
+
+Default: 100
+
+* `SERIAL_FLASHER_BOOT_HOLD_TIME_MS`
+
+This is the time for which the boot pin is asserted when doing a hard reset in milliseconds.
+
+Default: 50
+
+Configuration can be passed to `cmake` via command line:
+
+```
+cmake -DMD5_ENABLED=1 .. && cmake --build .
+```
+
+### STM32 support
+
+The STM32 port makes use of STM32 HAL libraries, and these do not come with CMake support. In order to compile the project, `stm32-cmake` (a `CMake` support package) has to be pulled as submodule.
+
+```
+git clone --recursive https://github.com/espressif/esp-serial-flasher.git
+```
+
+If you have cloned this repository without the `--recursive` flag, you can initialize the submodule using the following command:
+
+```
+git submodule update --init
+```
+
+In addition to configuration parameters mentioned above, following definitions has to be set:
+
+- STM32_TOOLCHAIN_PATH: path to arm toolchain (i.e /home/user/gcc-arm-none-eabi-9-2019-q4-major)
+- STM32_CUBE_<CHIP_FAMILY>_PATH: path to STM32 Cube libraries (i.e /home/user/STM32Cube/Repository/STM32Cube_FW_F4_V1.25.0)
+- STM32_CHIP: name of STM32 for which project should be compiled (i.e STM32F407VG)
+- CORE_USED: core used on multicore devices (i.e. M7 or M4 on some STM32H7 chips)
+- PORT: STM32
+
+This can be achieved by passing definitions to the command line, such as:
+
+```
+cmake -DSTM32_TOOLCHAIN_PATH="path_to_toolchain" -DSTM32_CUBE_<CHIP_FAMILY>_PATH="path_to_cube_libraries" -DSTM32_CHIP="STM32F407VG" -DPORT="STM32" .. && cmake --build .
+```
+
+Alternatively, those variables can be set in the top level `cmake` directory:
+
+```
+set(STM32_TOOLCHAIN_PATH path_to_toolchain)
+set(STM32_CUBE_H7_PATH path_to_cube_libraries)
+set(STM32_CHIP STM32H743VI)
+set(CORE_USED M7)
+set(PORT STM32)
+```
+
+### Zephyr support
+
+The Zephyr port is ready to be integrated into Zephyr apps as a Zephyr module. In the manifest file (west.yml), add:
+
+```
+    - name: esp-flasher
+      url: https://github.com/espressif/esp-serial-flasher
+      revision: master
+      path: modules/lib/esp_flasher
+```
+
+And add
+
+```
+CONFIG_ESP_SERIAL_FLASHER=y
+CONFIG_CONSOLE_GETCHAR=y
+CONFIG_SERIAL_FLASHER_MD5_ENABLED=y
+```
+
+to the project configuration `prj.conf`.
+
+For the C/C++ source code, the example code provided in `examples/zephyr_example` can be used as a starting point.
+
+## Licence
+
+Code is distributed under Apache 2.0 license.
+
+## Known limitations
+
+Size of new binary image has to be known before flashing.

BIN
esp_flasher/lib/esp-serial-flasher/examples/binaries/ESP32_AT_Firmware/Firmware.bin


BIN
esp_flasher/lib/esp-serial-flasher/examples/binaries/Hello-world/ESP32/bootloader.bin


BIN
esp_flasher/lib/esp-serial-flasher/examples/binaries/Hello-world/ESP32/hello_world.bin


BIN
esp_flasher/lib/esp-serial-flasher/examples/binaries/Hello-world/ESP32/partition-table.bin


BIN
esp_flasher/lib/esp-serial-flasher/examples/binaries/Hello-world/ESP32_C2/bootloader.bin


BIN
esp_flasher/lib/esp-serial-flasher/examples/binaries/Hello-world/ESP32_C2/hello_world.bin


BIN
esp_flasher/lib/esp-serial-flasher/examples/binaries/Hello-world/ESP32_C2/partition-table.bin


BIN
esp_flasher/lib/esp-serial-flasher/examples/binaries/Hello-world/ESP32_C3/bootloader.bin


BIN
esp_flasher/lib/esp-serial-flasher/examples/binaries/Hello-world/ESP32_C3/hello_world.bin


BIN
esp_flasher/lib/esp-serial-flasher/examples/binaries/Hello-world/ESP32_C3/partition-table.bin


BIN
esp_flasher/lib/esp-serial-flasher/examples/binaries/Hello-world/ESP32_C6/bootloader.bin


BIN
esp_flasher/lib/esp-serial-flasher/examples/binaries/Hello-world/ESP32_C6/hello_world.bin


BIN
esp_flasher/lib/esp-serial-flasher/examples/binaries/Hello-world/ESP32_C6/partition-table.bin


BIN
esp_flasher/lib/esp-serial-flasher/examples/binaries/Hello-world/ESP32_H2/bootloader.bin


BIN
esp_flasher/lib/esp-serial-flasher/examples/binaries/Hello-world/ESP32_H2/hello_world.bin


BIN
esp_flasher/lib/esp-serial-flasher/examples/binaries/Hello-world/ESP32_H2/partition-table.bin


BIN
esp_flasher/lib/esp-serial-flasher/examples/binaries/Hello-world/ESP32_H4/bootloader.bin


BIN
esp_flasher/lib/esp-serial-flasher/examples/binaries/Hello-world/ESP32_H4/hello_world.bin


BIN
esp_flasher/lib/esp-serial-flasher/examples/binaries/Hello-world/ESP32_H4/partition-table.bin


BIN
esp_flasher/lib/esp-serial-flasher/examples/binaries/Hello-world/ESP32_S2/bootloader.bin


BIN
esp_flasher/lib/esp-serial-flasher/examples/binaries/Hello-world/ESP32_S2/hello_world.bin


BIN
esp_flasher/lib/esp-serial-flasher/examples/binaries/Hello-world/ESP32_S2/partition-table.bin


BIN
esp_flasher/lib/esp-serial-flasher/examples/binaries/Hello-world/ESP32_S3/bootloader.bin


BIN
esp_flasher/lib/esp-serial-flasher/examples/binaries/Hello-world/ESP32_S3/hello_world.bin


BIN
esp_flasher/lib/esp-serial-flasher/examples/binaries/Hello-world/ESP32_S3/partition-table.bin


BIN
esp_flasher/lib/esp-serial-flasher/examples/binaries/Hello-world/ESP8266/bootloader.bin


BIN
esp_flasher/lib/esp-serial-flasher/examples/binaries/Hello-world/ESP8266/hello-world.bin


BIN
esp_flasher/lib/esp-serial-flasher/examples/binaries/Hello-world/ESP8266/partition-table.bin


BIN
esp_flasher/lib/esp-serial-flasher/examples/binaries/RAM_APP/ESP32/app.bin


BIN
esp_flasher/lib/esp-serial-flasher/examples/binaries/RAM_APP/ESP32_C2/app.bin


BIN
esp_flasher/lib/esp-serial-flasher/examples/binaries/RAM_APP/ESP32_C3/app.bin


BIN
esp_flasher/lib/esp-serial-flasher/examples/binaries/RAM_APP/ESP32_C6/app.bin


BIN
esp_flasher/lib/esp-serial-flasher/examples/binaries/RAM_APP/ESP32_H2/app.bin


BIN
esp_flasher/lib/esp-serial-flasher/examples/binaries/RAM_APP/ESP32_H4/app.bin


BIN
esp_flasher/lib/esp-serial-flasher/examples/binaries/RAM_APP/ESP32_S2/app.bin


BIN
esp_flasher/lib/esp-serial-flasher/examples/binaries/RAM_APP/ESP32_S3/app.bin


+ 15 - 0
esp_flasher/lib/esp-serial-flasher/examples/binaries/RAM_APP/source/CMakeLists.txt

@@ -0,0 +1,15 @@
+# The following lines of boilerplate have to be in your project's
+# CMakeLists in this exact order for cmake to work correctly
+cmake_minimum_required(VERSION 3.16)
+
+# Here we remove all unecessary components from the build to make the binary smaller
+set(COMPONENTS main)
+
+include($ENV{IDF_PATH}/tools/cmake/project.cmake)
+project(hello_world)
+
+# This generates a binary file from the elf, as the RAM build doesn't do that automatically
+add_custom_command(TARGET ${PROJECT_NAME}.elf
+    POST_BUILD
+    COMMAND esptool.py --chip ${IDF_TARGET} elf2image --output app.bin ${PROJECT_NAME}.elf
+)

+ 2 - 0
esp_flasher/lib/esp-serial-flasher/examples/binaries/RAM_APP/source/main/CMakeLists.txt

@@ -0,0 +1,2 @@
+idf_component_register(SRCS "main.c"
+                    INCLUDE_DIRS "")

+ 16 - 0
esp_flasher/lib/esp-serial-flasher/examples/binaries/RAM_APP/source/main/main.c

@@ -0,0 +1,16 @@
+/*
+ * SPDX-FileCopyrightText: 2010-2023 Espressif Systems (Shanghai) CO LTD
+ *
+ * SPDX-License-Identifier: CC0-1.0
+ */
+
+#include "freertos/FreeRTOS.h"
+#include "freertos/task.h"
+
+void app_main(void)
+{
+    while (true) {
+        esp_rom_printf("Hello world!\n");
+        vTaskDelay(1000 / portTICK_PERIOD_MS);
+    }
+}

+ 11 - 0
esp_flasher/lib/esp-serial-flasher/examples/binaries/RAM_APP/source/sdkconfig.defaults

@@ -0,0 +1,11 @@
+# This file was generated using idf.py save-defconfig. It can be edited manually.
+# Espressif IoT Development Framework (ESP-IDF) Project Minimal Configuration
+#
+CONFIG_APP_BUILD_TYPE_ELF_RAM=y
+CONFIG_COMPILER_OPTIMIZATION_SIZE=y
+CONFIG_APP_NO_BLOBS=y
+CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE=y
+CONFIG_COMPILER_OPTIMIZATION_CHECKS_SILENT=y
+# CONFIG_ESP_ERR_TO_NAME_LOOKUP is not set
+CONFIG_ESP_SYSTEM_PANIC_SILENT_REBOOT=y
+CONFIG_LOG_DEFAULT_LEVEL_NONE=y

+ 20 - 0
esp_flasher/lib/esp-serial-flasher/examples/common/bin2array.cmake

@@ -0,0 +1,20 @@
+# Creates C resources file from files in given directory recursively
+function(create_resources dir output)
+    # Create empty output file
+    file(WRITE ${output} "#include <stdint.h>\n\n")
+    # Collect input files
+    file(GLOB bin_paths ${dir}/ESP*/*)
+    # Iterate through input files
+    foreach(bin ${bin_paths})
+        # Get short filenames, by discarding relative path
+        file(GLOB name RELATIVE ${dir} ${bin})
+        # Replace filename spaces & extension separator for C compatibility
+        string(REGEX REPLACE "[\\./-]" "_" filename ${name})
+        # Read hex data from file
+        file(READ ${bin} filedata HEX)
+        # Convert hex data for C compatibility
+        string(REGEX REPLACE "([0-9a-f][0-9a-f])" "0x\\1," filedata ${filedata})
+        # Append data to output file
+        file(APPEND ${output} "const uint8_t  ${filename}[] = {${filedata}};\nconst uint32_t ${filename}_size = sizeof(${filename});\n")
+    endforeach()
+endfunction()

+ 402 - 0
esp_flasher/lib/esp-serial-flasher/examples/common/example_common.c

@@ -0,0 +1,402 @@
+/* Copyright 2020-2023 Espressif Systems (Shanghai) CO LTD
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <inttypes.h>
+#include <sys/param.h>
+#include "esp_loader_io.h"
+#include "esp_loader.h"
+#include "example_common.h"
+
+#ifndef SINGLE_TARGET_SUPPORT
+
+
+// For esp8266, esp32, esp32s2
+#define BOOTLOADER_ADDRESS_V0       0x1000
+// For esp32s3 and later chips
+#define BOOTLOADER_ADDRESS_V1       0x0
+#define PARTITION_ADDRESS           0x8000
+#define APPLICATION_ADDRESS         0x10000
+
+extern const uint8_t  ESP32_bootloader_bin[];
+extern const uint32_t ESP32_bootloader_bin_size;
+extern const uint8_t  ESP32_hello_world_bin[];
+extern const uint32_t ESP32_hello_world_bin_size;
+extern const uint8_t  ESP32_partition_table_bin[];
+extern const uint32_t ESP32_partition_table_bin_size;
+
+extern const uint8_t  ESP32_S2_bootloader_bin[];
+extern const uint32_t ESP32_S2_bootloader_bin_size;
+extern const uint8_t  ESP32_S2_hello_world_bin[];
+extern const uint32_t ESP32_S2_hello_world_bin_size;
+extern const uint8_t  ESP32_S2_partition_table_bin[];
+extern const uint32_t ESP32_S2_partition_table_bin_size;
+
+extern const uint8_t  ESP32_S3_bootloader_bin[];
+extern const uint32_t ESP32_S3_bootloader_bin_size;
+extern const uint8_t  ESP32_S3_hello_world_bin[];
+extern const uint32_t ESP32_S3_hello_world_bin_size;
+extern const uint8_t  ESP32_S3_partition_table_bin[];
+extern const uint32_t ESP32_S3_partition_table_bin_size;
+
+
+
+extern const uint8_t  ESP8266_bootloader_bin[];
+extern const uint32_t ESP8266_bootloader_bin_size;
+extern const uint8_t  ESP8266_hello_world_bin[];
+extern const uint32_t ESP8266_hello_world_bin_size;
+extern const uint8_t  ESP8266_partition_table_bin[];
+extern const uint32_t ESP8266_partition_table_bin_size;
+
+extern const uint8_t  ESP32_H4_bootloader_bin[];
+extern const uint32_t ESP32_H4_bootloader_bin_size;
+extern const uint8_t  ESP32_H4_hello_world_bin[];
+extern const uint32_t ESP32_H4_hello_world_bin_size;
+extern const uint8_t  ESP32_H4_partition_table_bin[];
+extern const uint32_t ESP32_H4_partition_table_bin_size;
+
+extern const uint8_t  ESP32_H2_bootloader_bin[];
+extern const uint32_t ESP32_H2_bootloader_bin_size;
+extern const uint8_t  ESP32_H2_hello_world_bin[];
+extern const uint32_t ESP32_H2_hello_world_bin_size;
+extern const uint8_t  ESP32_H2_partition_table_bin[];
+extern const uint32_t ESP32_H2_partition_table_bin_size;
+
+extern const uint8_t  ESP32_C2_bootloader_bin[];
+extern const uint32_t ESP32_C2_bootloader_bin_size;
+extern const uint8_t  ESP32_C2_hello_world_bin[];
+extern const uint32_t ESP32_C2_hello_world_bin_size;
+extern const uint8_t  ESP32_C2_partition_table_bin[];
+extern const uint32_t ESP32_C2_partition_table_bin_size;
+
+extern const uint8_t  ESP32_C3_bootloader_bin[];
+extern const uint32_t ESP32_C3_bootloader_bin_size;
+extern const uint8_t  ESP32_C3_hello_world_bin[];
+extern const uint32_t ESP32_C3_hello_world_bin_size;
+extern const uint8_t  ESP32_C3_partition_table_bin[];
+extern const uint32_t ESP32_C3_partition_table_bin_size;
+
+extern const uint8_t  ESP32_C6_bootloader_bin[];
+extern const uint32_t ESP32_C6_bootloader_bin_size;
+extern const uint8_t  ESP32_C6_hello_world_bin[];
+extern const uint32_t ESP32_C6_hello_world_bin_size;
+extern const uint8_t  ESP32_C6_partition_table_bin[];
+extern const uint32_t ESP32_C6_partition_table_bin_size;
+
+void get_example_binaries(target_chip_t target, example_binaries_t *bins)
+{
+    if (target == ESP8266_CHIP) {
+        bins->boot.data = ESP8266_bootloader_bin;
+        bins->boot.size = ESP8266_bootloader_bin_size;
+        bins->boot.addr = BOOTLOADER_ADDRESS_V0;
+        bins->part.data = ESP8266_partition_table_bin;
+        bins->part.size = ESP8266_partition_table_bin_size;
+        bins->part.addr = PARTITION_ADDRESS;
+        bins->app.data  = ESP8266_hello_world_bin;
+        bins->app.size  = ESP8266_hello_world_bin_size;
+        bins->app.addr  = APPLICATION_ADDRESS;
+    } else if (target == ESP32_CHIP) {
+        bins->boot.data = ESP32_bootloader_bin;
+        bins->boot.size = ESP32_bootloader_bin_size;
+        bins->boot.addr = BOOTLOADER_ADDRESS_V0;
+        bins->part.data = ESP32_partition_table_bin;
+        bins->part.size = ESP32_partition_table_bin_size;
+        bins->part.addr = PARTITION_ADDRESS;
+        bins->app.data  = ESP32_hello_world_bin;
+        bins->app.size  = ESP32_hello_world_bin_size;
+        bins->app.addr  = APPLICATION_ADDRESS;
+    } else if (target == ESP32S2_CHIP) {
+        bins->boot.data = ESP32_S2_bootloader_bin;
+        bins->boot.size = ESP32_S2_bootloader_bin_size;
+        bins->boot.addr = BOOTLOADER_ADDRESS_V0;
+        bins->part.data = ESP32_S2_partition_table_bin;
+        bins->part.size = ESP32_S2_partition_table_bin_size;
+        bins->part.addr = PARTITION_ADDRESS;
+        bins->app.data  = ESP32_S2_hello_world_bin;
+        bins->app.size  = ESP32_S2_hello_world_bin_size;
+        bins->app.addr  = APPLICATION_ADDRESS;
+    } else if (target == ESP32H4_CHIP){
+        bins->boot.data = ESP32_H4_bootloader_bin;
+        bins->boot.size = ESP32_H4_bootloader_bin_size;
+        bins->boot.addr = BOOTLOADER_ADDRESS_V1;
+        bins->part.data = ESP32_H4_partition_table_bin;
+        bins->part.size = ESP32_H4_partition_table_bin_size;
+        bins->part.addr = PARTITION_ADDRESS;
+        bins->app.data  = ESP32_H4_hello_world_bin;
+        bins->app.size  = ESP32_H4_hello_world_bin_size;
+        bins->app.addr  = APPLICATION_ADDRESS;
+    } else if (target == ESP32H2_CHIP){
+        bins->boot.data = ESP32_H2_bootloader_bin;
+        bins->boot.size = ESP32_H2_bootloader_bin_size;
+        bins->boot.addr = BOOTLOADER_ADDRESS_V1;
+        bins->part.data = ESP32_H2_partition_table_bin;
+        bins->part.size = ESP32_H2_partition_table_bin_size;
+        bins->part.addr = PARTITION_ADDRESS;
+        bins->app.data  = ESP32_H2_hello_world_bin;
+        bins->app.size  = ESP32_H2_hello_world_bin_size;
+        bins->app.addr  = APPLICATION_ADDRESS;
+    } else if (target == ESP32C2_CHIP){
+        bins->boot.data = ESP32_C2_bootloader_bin;
+        bins->boot.size = ESP32_C2_bootloader_bin_size;
+        bins->boot.addr = BOOTLOADER_ADDRESS_V1;
+        bins->part.data = ESP32_C2_partition_table_bin;
+        bins->part.size = ESP32_C2_partition_table_bin_size;
+        bins->part.addr = PARTITION_ADDRESS;
+        bins->app.data  = ESP32_C2_hello_world_bin;
+        bins->app.size  = ESP32_C2_hello_world_bin_size;
+        bins->app.addr  = APPLICATION_ADDRESS;
+    } else if (target == ESP32C3_CHIP){
+        bins->boot.data = ESP32_C3_bootloader_bin;
+        bins->boot.size = ESP32_C3_bootloader_bin_size;
+        bins->boot.addr = BOOTLOADER_ADDRESS_V1;
+        bins->part.data = ESP32_C3_partition_table_bin;
+        bins->part.size = ESP32_C3_partition_table_bin_size;
+        bins->part.addr = PARTITION_ADDRESS;
+        bins->app.data  = ESP32_C3_hello_world_bin;
+        bins->app.size  = ESP32_C3_hello_world_bin_size;
+        bins->app.addr  = APPLICATION_ADDRESS;
+    } else if (target == ESP32C6_CHIP){
+        bins->boot.data = ESP32_C6_bootloader_bin;
+        bins->boot.size = ESP32_C6_bootloader_bin_size;
+        bins->boot.addr = BOOTLOADER_ADDRESS_V1;
+        bins->part.data = ESP32_C6_partition_table_bin;
+        bins->part.size = ESP32_C6_partition_table_bin_size;
+        bins->part.addr = PARTITION_ADDRESS;
+        bins->app.data  = ESP32_C6_hello_world_bin;
+        bins->app.size  = ESP32_C6_hello_world_bin_size;
+        bins->app.addr  = APPLICATION_ADDRESS;
+
+    } else if (target == ESP32S3_CHIP){
+        bins->boot.data = ESP32_S3_bootloader_bin;
+        bins->boot.size = ESP32_S3_bootloader_bin_size;
+        bins->boot.addr = BOOTLOADER_ADDRESS_V1;
+        bins->part.data = ESP32_S3_partition_table_bin;
+        bins->part.size = ESP32_S3_partition_table_bin_size;
+        bins->part.addr = PARTITION_ADDRESS;
+        bins->app.data  = ESP32_S3_hello_world_bin;
+        bins->app.size  = ESP32_S3_hello_world_bin_size;
+        bins->app.addr  = APPLICATION_ADDRESS;
+    }
+    else {
+        abort();
+    }
+}
+
+
+extern const uint8_t  ESP32_app_bin[];
+extern const uint32_t ESP32_app_bin_size;
+extern const uint8_t  ESP32_C2_app_bin[];
+extern const uint32_t ESP32_C2_app_bin_size;
+extern const uint8_t  ESP32_C3_app_bin[];
+extern const uint32_t ESP32_C3_app_bin_size;
+extern const uint8_t  ESP32_H2_app_bin[];
+extern const uint32_t ESP32_H2_app_bin_size;
+extern const uint8_t  ESP32_H4_app_bin[];
+extern const uint32_t ESP32_H4_app_bin_size;
+extern const uint8_t  ESP32_S3_app_bin[];
+extern const uint32_t ESP32_S3_app_bin_size;
+extern const uint8_t  ESP32_C6_app_bin[];
+extern const uint32_t ESP32_C6_app_bin_size;
+
+void get_example_ram_app_binary(target_chip_t target, example_ram_app_binary_t *bin)
+{
+    switch (target) {
+        case ESP32_CHIP: {
+            bin->ram_app.data = ESP32_app_bin;
+            bin->ram_app.size = ESP32_app_bin_size;
+            break;
+        }
+        case ESP32C2_CHIP: {
+            bin->ram_app.data = ESP32_C2_app_bin;
+            bin->ram_app.size = ESP32_C2_app_bin_size;
+            break;
+        }
+        case ESP32C3_CHIP: {
+            bin->ram_app.data = ESP32_C3_app_bin;
+            bin->ram_app.size = ESP32_C3_app_bin_size;
+            break;
+        }
+        case ESP32H2_CHIP: {
+            bin->ram_app.data = ESP32_H2_app_bin;
+            bin->ram_app.size = ESP32_H2_app_bin_size;
+            break;
+        }
+        case ESP32H4_CHIP: {
+            bin->ram_app.data = ESP32_H4_app_bin;
+            bin->ram_app.size = ESP32_H4_app_bin_size;
+            break;
+        }
+        case ESP32S3_CHIP: {
+            bin->ram_app.data = ESP32_S3_app_bin;
+            bin->ram_app.size = ESP32_S3_app_bin_size;
+            break;
+        }
+        case ESP32C6_CHIP: {
+            bin->ram_app.data = ESP32_C6_app_bin;
+            bin->ram_app.size = ESP32_C6_app_bin_size;
+            break;
+        }
+        default: {
+            abort();
+        }
+    }
+}
+
+#endif
+
+esp_loader_error_t connect_to_target(uint32_t higher_transmission_rate)
+{
+    esp_loader_connect_args_t connect_config = ESP_LOADER_CONNECT_DEFAULT();
+
+    esp_loader_error_t err = esp_loader_connect(&connect_config);
+    if (err != ESP_LOADER_SUCCESS) {
+        printf("Cannot connect to target. Error: %u\n", err);
+        return err;
+    }
+    printf("Connected to target\n");
+
+#ifdef SERIAL_FLASHER_INTERFACE_UART
+    if (higher_transmission_rate && esp_loader_get_target() != ESP8266_CHIP) {
+        err = esp_loader_change_transmission_rate(higher_transmission_rate);
+        if (err == ESP_LOADER_ERROR_UNSUPPORTED_FUNC) {
+            printf("ESP8266 does not support change transmission rate command.");
+            return err;
+        } else if (err != ESP_LOADER_SUCCESS) {
+            printf("Unable to change transmission rate on target.");
+            return err;
+        } else {
+            err = loader_port_change_transmission_rate(higher_transmission_rate);
+            if (err != ESP_LOADER_SUCCESS) {
+                printf("Unable to change transmission rate.");
+                return err;
+            }
+            printf("Transmission rate changed changed\n");
+        }
+    }
+#endif /* SERIAL_FLASHER_INTERFACE_UART */
+
+    return ESP_LOADER_SUCCESS;
+}
+
+#ifdef SERIAL_FLASHER_INTERFACE_UART
+esp_loader_error_t flash_binary(const uint8_t *bin, size_t size, size_t address)
+{
+    esp_loader_error_t err;
+    static uint8_t payload[1024];
+    const uint8_t *bin_addr = bin;
+
+    printf("Erasing flash (this may take a while)...\n");
+    err = esp_loader_flash_start(address, size, sizeof(payload));
+    if (err != ESP_LOADER_SUCCESS) {
+        printf("Erasing flash failed with error %d.\n", err);
+        return err;
+    }
+    printf("Start programming\n");
+
+    size_t binary_size = size;
+    size_t written = 0;
+
+    while (size > 0) {
+        size_t to_read = MIN(size, sizeof(payload));
+        memcpy(payload, bin_addr, to_read);
+
+        err = esp_loader_flash_write(payload, to_read);
+        if (err != ESP_LOADER_SUCCESS) {
+            printf("\nPacket could not be written! Error %d.\n", err);
+            return err;
+        }
+
+        size -= to_read;
+        bin_addr += to_read;
+        written += to_read;
+
+        int progress = (int)(((float)written / binary_size) * 100);
+        printf("\rProgress: %d %%", progress);
+        fflush(stdout);
+    };
+
+    printf("\nFinished programming\n");
+
+#if MD5_ENABLED
+    err = esp_loader_flash_verify();
+    if (err == ESP_LOADER_ERROR_UNSUPPORTED_FUNC) {
+        printf("ESP8266 does not support flash verify command.");
+        return err;
+    } else if (err != ESP_LOADER_SUCCESS) {
+        printf("MD5 does not match. err: %d\n", err);
+        return err;
+    }
+    printf("Flash verified\n");
+#endif
+
+    return ESP_LOADER_SUCCESS;
+}
+#endif /* SERIAL_FLASHER_INTERFACE_UART */
+
+esp_loader_error_t load_ram_binary(const uint8_t *bin)
+{
+    printf("Start loading\n");
+    esp_loader_error_t err;
+    const esp_loader_bin_header_t *header = (const esp_loader_bin_header_t *)bin;
+    esp_loader_bin_segment_t segments[header->segments];
+
+    // Parse segments
+    uint32_t seg;
+    uint32_t *cur_seg_pos;
+    for (seg=0, cur_seg_pos = (uint32_t *)(&bin[BIN_FIRST_SEGMENT_OFFSET]);
+         seg < header->segments;
+         seg++) {
+        segments[seg].addr = *cur_seg_pos++;
+        segments[seg].size = *cur_seg_pos++;
+        segments[seg].data = (uint8_t *)cur_seg_pos;
+        cur_seg_pos += (segments[seg].size) / 4;
+    }
+
+    // Download segments
+    for (seg=0; seg < header->segments; seg++) {
+        printf("Downloading %"PRIu32" bytes at 0x%08"PRIx32"...\n", segments[seg].size, segments[seg].addr);
+
+        err = esp_loader_mem_start(segments[seg].addr, segments[seg].size, ESP_RAM_BLOCK);
+        if (err != ESP_LOADER_SUCCESS) {
+            printf("Loading ram start with error %d.\n", err);
+            return err;
+        }
+
+        size_t remain_size = segments[seg].size;
+        uint8_t *data_pos = segments[seg].data;
+        while(remain_size > 0) {
+            size_t data_size = MIN(ESP_RAM_BLOCK, remain_size);
+            err = esp_loader_mem_write(data_pos, data_size);
+            if (err != ESP_LOADER_SUCCESS) {
+                printf("\nPacket could not be written! Error %d.\n", err);
+                return err;
+            }
+            data_pos += data_size;
+            remain_size -= data_size;
+        }
+    }
+
+    err = esp_loader_mem_finish(header->entrypoint);
+    if (err != ESP_LOADER_SUCCESS) {
+        printf("\nLoad ram finish with Error %d.\n", err);
+        return err;
+    }
+    printf("\nFinished loading\n");
+
+    return ESP_LOADER_SUCCESS;
+}
+

+ 63 - 0
esp_flasher/lib/esp-serial-flasher/examples/common/example_common.h

@@ -0,0 +1,63 @@
+/* Copyright 2020-2023 Espressif Systems (Shanghai) CO LTD
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#define BIN_FIRST_SEGMENT_OFFSET    0x18
+// Maximum block sized for RAM and Flash writes, respectively.
+#define ESP_RAM_BLOCK               0x1800
+
+typedef struct {
+    const uint8_t *data;
+    uint32_t size;
+    uint32_t addr;
+} partition_attr_t;
+
+typedef struct {
+    partition_attr_t boot;
+    partition_attr_t part;
+    partition_attr_t app;
+} example_binaries_t;
+
+typedef struct {
+    partition_attr_t ram_app;
+} example_ram_app_binary_t;
+
+/**
+ * @brief esptool portable bin header format
+ */
+typedef struct example_bin_header {
+    uint8_t magic;
+    uint8_t segments;
+    uint8_t flash_mode;
+    uint8_t flash_size_freq;
+    uint32_t entrypoint;
+} example_bin_header_t;
+
+/**
+ * @brief esptool portable bin segment format
+ */
+typedef struct example_bin_segment {
+    uint32_t addr;
+    uint32_t size;
+    uint8_t *data;
+} example_bin_segment_t;
+
+
+void get_example_binaries(target_chip_t target, example_binaries_t *binaries);
+void get_example_ram_app_binary(target_chip_t target, example_ram_app_binary_t *bin);
+esp_loader_error_t connect_to_target(uint32_t higher_transmission_rate);
+esp_loader_error_t flash_binary(const uint8_t *bin, size_t size, size_t address);
+esp_loader_error_t load_ram_binary(const uint8_t *bin);

+ 7 - 0
esp_flasher/lib/esp-serial-flasher/examples/esp32_example/CMakeLists.txt

@@ -0,0 +1,7 @@
+# The following lines of boilerplate have to be in your project's CMakeLists
+# in this exact order for cmake to work correctly
+cmake_minimum_required(VERSION 3.5)
+
+set(EXTRA_COMPONENT_DIRS ../../)
+include($ENV{IDF_PATH}/tools/cmake/project.cmake)
+project(esp-serial-flasher)

+ 78 - 0
esp_flasher/lib/esp-serial-flasher/examples/esp32_example/README.md

@@ -0,0 +1,78 @@
+# Flash multiple partitions example
+
+## Overview
+
+Example demonstrates how to flash ESP32/ESP32-S2/ESP8266 from another (host) MCU using esp_serial_flash component API. In this case, ESP32 is also used as host MCU. Binaries to be flashed from host MCU to another Espressif SoC can be found in `binaries` folder and are converted into C-array during build process.
+
+Following steps are performed in order to re-program target's memory:
+
+1. Filesystem is initialized and mounted.
+2. UART1 through which new binary will be transfered is initialized.
+3. Host puts slave device into boot mode tries to connect by calling `esp_loader_connect()`.
+4. Binary file is opened and its size is acquired, as it has to be known before flashing.
+5. Then `esp_loader_flash_start()` is called to enter flashing mode and erase amount of memory to be flashed.
+6. `esp_loader_flash_write()` function is called repeatedly until the whole binary image is transfered.
+
+Note: In addition, to steps mentioned above, `esp_loader_change_transmission_rate`  is called after connection is established in order to increase flashing speed. This does not apply for ESP8266, as its bootloader does not support this command. However, ESP8266 is capable of detecting baud rate during connection phase, and can be changed before calling `esp_loader_connect`, if necessary.
+
+## SPI pin initialization
+
+In majority of cases `ESP_LOADER_CONNECT_DEFAULT` helper macro is used in order to initialize `loader_connect_args_t` data structure passed to `esp_loader_connect`. Helper macro sets `spi_pin_config` field of the data structure to zero, thus, default SPI pins are used to connect to FLASH memory. In special cases, such as custom design in which FLASH is connected to different pins, `spi_pin_config` field has to be set accordingly. For more detailed information refer to [serial protocol](https://docs.espressif.com/projects/esptool/en/latest/esp32s3/advanced-topics/serial-protocol.html).
+
+## Hardware Required
+
+* Two development boards with ESP32 SoC (e.g., ESP32-DevKitC, ESP-WROVER-KIT, etc.).
+* One or two USB cables for power supply and programming.
+
+## Hardware connection
+
+Table below shows connection between two ESP32 devices.
+
+| ESP32 (host) | ESP32 (slave) |
+|:------------:|:-------------:|
+|    IO26      |      IO0      |
+|    IO25      |     RESET     |
+|    IO4       |      RX0      |
+|    IO5       |      TX0      |
+
+Note: interconnection is the same for all three targets (slaves). 
+
+## Build and flash
+
+To run the example, type the following command:
+
+```CMake
+idf.py -p PORT flash monitor
+```
+
+(To exit the serial monitor, type ``Ctrl-]``.)
+
+See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.
+
+## Configuration
+
+For details about available configuration option, please refer to top level [README.md](../../README.md). 
+Compile definitions can be specified on command line when running `idf.py`, for example:
+
+```
+idf.py build -DMD5_ENABLED=1
+```
+Binaries to be flashed are placed in separate folder (binaries.c) for each possible target and converted to C-array. Without explicitly enabling MD5 check, flash integrity verification is disabled by default.
+
+## Example output
+
+Here is the example's console output:
+
+```
+...
+I (342) example: Initializing SPIFFS
+I (482) example: Image size: 144672
+I (902) example: Connected to target
+I (1732) example: Start programming
+I (1832) example: packet: 0  written: 1024 B
+I (1932) example: packet: 1  written: 1024 B
+...
+I (16052) example: packet: 140  written: 1024 B
+I (16152) example: packet: 141  written: 288 B
+I (16152) example: Finished programming
+```

+ 22 - 0
esp_flasher/lib/esp-serial-flasher/examples/esp32_example/main/CMakeLists.txt

@@ -0,0 +1,22 @@
+set(srcs main.c ../../common/example_common.c)
+set(include_dirs . ../../common)
+
+if ("${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}" VERSION_GREATER "4.0")
+    idf_component_register(SRCS ${srcs}
+                           INCLUDE_DIRS ${include_dirs})
+    set(target ${COMPONENT_LIB})
+else()
+    # remove when dropping IDF 3.3 support
+    set(COMPONENT_SRCS ${srcs})
+    set(COMPONENT_ADD_INCLUDEDIRS ${include_dirs})
+    register_component()
+    set(target ${COMPONENT_TARGET})
+endif()
+
+# Embed binaries into the app.
+# In ESP-IDF this can also be done using EMBED_FILES option of idf_component_register.
+# Here an external tool is used to make file embedding similar with other ports.
+include(${CMAKE_CURRENT_LIST_DIR}/../../common/bin2array.cmake)
+create_resources(${CMAKE_CURRENT_LIST_DIR}/../../binaries/Hello-world ${CMAKE_BINARY_DIR}/binaries.c)
+set_property(SOURCE ${CMAKE_BINARY_DIR}/binaries.c PROPERTY GENERATED 1)
+target_sources(${target} PRIVATE ${CMAKE_BINARY_DIR}/binaries.c)

+ 54 - 0
esp_flasher/lib/esp-serial-flasher/examples/esp32_example/main/main.c

@@ -0,0 +1,54 @@
+/* Flash multiple partitions example
+
+   This example code is in the Public Domain (or CC0 licensed, at your option.)
+
+   Unless required by applicable law or agreed to in writing, this
+   software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
+   CONDITIONS OF ANY KIND, either express or implied.
+*/
+
+#include <sys/param.h>
+#include <string.h>
+#include "esp_err.h"
+#include "esp_log.h"
+#include "driver/uart.h"
+#include "driver/gpio.h"
+#include "esp32_port.h"
+#include "esp_loader.h"
+#include "example_common.h"
+
+static const char *TAG = "serial_flasher";
+
+#define HIGHER_BAUDRATE 230400
+
+void app_main(void)
+{
+    example_binaries_t bin;
+
+    const loader_esp32_config_t config = {
+        .baud_rate = 115200,
+        .uart_port = UART_NUM_1,
+        .uart_rx_pin = GPIO_NUM_5,
+        .uart_tx_pin = GPIO_NUM_4,
+        .reset_trigger_pin = GPIO_NUM_25,
+        .gpio0_trigger_pin = GPIO_NUM_26,
+    };
+
+    if (loader_port_esp32_init(&config) != ESP_LOADER_SUCCESS) {
+        ESP_LOGE(TAG, "serial initialization failed.");
+        return;
+    }
+
+    if (connect_to_target(HIGHER_BAUDRATE) == ESP_LOADER_SUCCESS) {
+
+        get_example_binaries(esp_loader_get_target(), &bin);
+
+        ESP_LOGI(TAG, "Loading bootloader...");
+        flash_binary(bin.boot.data, bin.boot.size, bin.boot.addr);
+        ESP_LOGI(TAG, "Loading partition table...");
+        flash_binary(bin.part.data, bin.part.size, bin.part.addr);
+        ESP_LOGI(TAG, "Loading app...");
+        flash_binary(bin.app.data,  bin.app.size,  bin.app.addr);
+        ESP_LOGI(TAG, "Done!");
+    }
+}

+ 4 - 0
esp_flasher/lib/esp-serial-flasher/examples/esp32_example/partitions.csv

@@ -0,0 +1,4 @@
+# Name,   Type, SubType, Offset,  Size, Flags
+nvs,      data, nvs,     ,        0x6000,
+phy_init, data, phy,     ,        0x1000,
+factory,  app,  factory, ,        1920K,

+ 1 - 0
esp_flasher/lib/esp-serial-flasher/examples/esp32_example/sdkconfig.defaults

@@ -0,0 +1 @@
+CONFIG_PARTITION_TABLE_CUSTOM=y

+ 7 - 0
esp_flasher/lib/esp-serial-flasher/examples/esp32_load_ram_example/CMakeLists.txt

@@ -0,0 +1,7 @@
+# The following lines of boilerplate have to be in your project's CMakeLists
+# in this exact order for cmake to work correctly
+cmake_minimum_required(VERSION 3.5)
+
+set(EXTRA_COMPONENT_DIRS ../../)
+include($ENV{IDF_PATH}/tools/cmake/project.cmake)
+project(esp32-serial-ram-loader)

+ 14 - 0
esp_flasher/lib/esp-serial-flasher/examples/esp32_load_ram_example/main/CMakeLists.txt

@@ -0,0 +1,14 @@
+set(srcs main.c ../../common/example_common.c)
+set(include_dirs . ../../common)
+
+idf_component_register(SRCS ${srcs}
+                       INCLUDE_DIRS ${include_dirs})
+set(target ${COMPONENT_LIB})
+
+# Embed binaries into the app.
+# In ESP-IDF this can also be done using EMBED_FILES option of idf_component_register.
+# Here an external tool is used to make file embedding similar with other ports.
+include(${CMAKE_CURRENT_LIST_DIR}/../../common/bin2array.cmake)
+create_resources(${CMAKE_CURRENT_LIST_DIR}/../../binaries/RAM_APP ${CMAKE_BINARY_DIR}/binaries.c)
+set_property(SOURCE ${CMAKE_BINARY_DIR}/binaries.c PROPERTY GENERATED 1)
+target_sources(${target} PRIVATE ${CMAKE_BINARY_DIR}/binaries.c)

+ 80 - 0
esp_flasher/lib/esp-serial-flasher/examples/esp32_load_ram_example/main/main.c

@@ -0,0 +1,80 @@
+/* Example of loading the program into RAM
+
+   This example code is in the Public Domain (or CC0 licensed, at your option.)
+
+   Unless required by applicable law or agreed to in writing, this
+   software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
+   CONDITIONS OF ANY KIND, either express or implied.
+*/
+
+#include <sys/param.h>
+#include <string.h>
+#include "esp_err.h"
+#include "esp_log.h"
+#include "esp_task_wdt.h"
+#include "driver/uart.h"
+#include "driver/gpio.h"
+#include "esp32_port.h"
+#include "esp_loader.h"
+#include "example_common.h"
+#include "freertos/FreeRTOS.h"
+
+static const char *TAG = "serial_ram_loader";
+
+// This can be set to a higher baud rate, but because it takes some time to
+// switch the uart baud rate in slave_monitor task, the log at slave starup
+// time will be lost or garbled.
+#define HIGHER_BAUDRATE 115200
+
+// Max line size
+#define BUF_LEN 128
+static uint8_t buf[BUF_LEN] = {0};
+
+void slave_monitor(void *arg)
+{
+#if (HIGHER_BAUDRATE != 115200)
+    uart_flush_input(UART_NUM_1);
+    uart_flush(UART_NUM_1);
+    uart_set_baudrate(UART_NUM_1, 115200);
+#endif
+    while (1) {
+        int rxBytes = uart_read_bytes(UART_NUM_1, buf, BUF_LEN, 100 / portTICK_PERIOD_MS);
+        buf[rxBytes] = '\0';
+        printf("%s", buf);
+    }
+}
+
+void app_main(void)
+{
+    example_ram_app_binary_t bin;
+
+    const loader_esp32_config_t config = {
+        .baud_rate = 115200,
+        .uart_port = UART_NUM_1,
+        .uart_rx_pin = GPIO_NUM_5,
+        .uart_tx_pin = GPIO_NUM_4,
+        .reset_trigger_pin = GPIO_NUM_25,
+        .gpio0_trigger_pin = GPIO_NUM_26,
+    };
+
+    if (loader_port_esp32_init(&config) != ESP_LOADER_SUCCESS) {
+        ESP_LOGE(TAG, "serial initialization failed.");
+        abort();
+    }
+
+    if (connect_to_target(HIGHER_BAUDRATE) == ESP_LOADER_SUCCESS) {
+        get_example_ram_app_binary(esp_loader_get_target(), &bin);
+        ESP_LOGI(TAG, "Loading app to RAM ...");
+        esp_loader_error_t err = load_ram_binary(bin.ram_app.data);
+        if (err == ESP_LOADER_SUCCESS) {
+            // Forward slave's serial output
+            ESP_LOGI(TAG, "********************************************");
+            ESP_LOGI(TAG, "*** Logs below are print from slave .... ***");
+            ESP_LOGI(TAG, "********************************************");
+            xTaskCreate(slave_monitor, "slave_monitor", 2048, NULL, configMAX_PRIORITIES, NULL);
+        } else {
+            ESP_LOGE(TAG, "Loading to ram failed ...");
+        }
+    }
+    vTaskDelete(NULL);
+}

+ 7 - 0
esp_flasher/lib/esp-serial-flasher/examples/esp32_spi_load_ram_example/CMakeLists.txt

@@ -0,0 +1,7 @@
+# The following lines of boilerplate have to be in your project's CMakeLists
+# in this exact order for cmake to work correctly
+cmake_minimum_required(VERSION 3.16)
+
+set(EXTRA_COMPONENT_DIRS ../../)
+include($ENV{IDF_PATH}/tools/cmake/project.cmake)
+project(esp32-spi-ram-loader)

+ 80 - 0
esp_flasher/lib/esp-serial-flasher/examples/esp32_spi_load_ram_example/README.md

@@ -0,0 +1,80 @@
+# Example of loading the program into RAM through SPI
+
+## Overview
+
+This example demonstrates how to upload an app to RAM of an Espressif MCU with SPI download support from another (host) MCU using the `esp_serial_flash` component API. In this case, another Espressif MCU is used as the host. Binaries to be uploaded to RAM from host MCU to the target MCU can be found in `binaries/RAM_APP` folder and are converted into C-array during build process.
+
+Following steps are performed in order to re-program the target's memory:
+
+1. SPI2 through which the binary will be transfered is initialized.
+2. Host puts slave device into SPI download mode tries to connect by calling `esp_loader_connect()`.
+3. Then `esp_loader_mem_start()` is called for each segment in RAM.
+4. `esp_loader_flash_write()` function is called repeatedly for every segment until the whole binary image is transfered.
+5. `esp_loader_mem_finish()` is called with the binary entrypoint, telling the chip to start the uploaded program.
+6. UART2 is initialized for the connection to the target
+7. Target output is continually read and printed
+
+## Hardware Required
+
+* Two development boards, one with any Espressif MCU (e.g., ESP32-DevKitC, ESP-WROVER-KIT, etc.) and one with an Espressif MCU with SPI download support. Here is a short list of supported MCUs:
+1. ESP32-C3
+2. ESP32-C2
+3. ESP32-S3
+4. ESP32-S2
+5. ESP32-H2
+* One or two USB cables for power supply and programming.
+
+## Hardware connection
+
+Table below shows connection between two Espressif MCUs.
+
+| Host         | Slave         |
+|    IO_5      |    RESET      |
+|    IO_12     |    CLK        |
+|    IO_10     |    CS         |
+|    IO_13     |    MISO       |
+|    IO_11     |    MOSI       |
+|    IO_14     |    QUADWP     |
+|    IO_9      |    QUADHD     |
+|    IO_13     |    STRAP_B0   |
+|    IO_2      |    STRAP_B1   |
+|    IO_3      |    STRAP_B2   |
+|    IO_4      |    STRAP_B3   |
+|    IO_6      |    UART0_RX   |
+|    IO_7      |    UART0_TX   |
+
+> Note 1: Strapping bit pins are documented in the TRM for each respective chip
+
+> Note 2: For achieving highest speeds, check which pins go through the IO MUX bypassing the GPIO matrix and use those. Pins chosen here are IO MUX pins for ESP32S3 and ESP32S2 chips.
+
+## Build and flash
+
+To run the example, type the following command:
+
+```CMake
+idf.py -p PORT flash monitor
+```
+
+(To exit the serial monitor, type ``Ctrl-]``.)
+
+See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.
+
+## Example output
+
+Here is the example's console output:
+
+```
+Connected to target
+I (682) spi_ram_loader: Loading app to RAM ...
+Start loading
+Downloading 7840 bytes at 0x3fc96e00...
+Downloading 312 bytes at 0x3fca0020...
+Downloading 93164 bytes at 0x40380000...
+Finished loading
+I (802) spi_ram_loader: ********************************************
+I (802) spi_ram_loader: *** Logs below are print from slave .... ***
+I (812) spi_ram_loader: ********************************************
+Hello world!
+Hello world!
+...
+```

+ 14 - 0
esp_flasher/lib/esp-serial-flasher/examples/esp32_spi_load_ram_example/main/CMakeLists.txt

@@ -0,0 +1,14 @@
+set(srcs main.c ../../common/example_common.c)
+set(include_dirs . ../../common)
+
+idf_component_register(SRCS ${srcs}
+                       INCLUDE_DIRS ${include_dirs})
+set(target ${COMPONENT_LIB})
+
+# Embed binaries into the app.
+# In ESP-IDF this can also be done using EMBED_FILES option of idf_component_register.
+# Here an external tool is used to make file embedding similar with other ports.
+include(${CMAKE_CURRENT_LIST_DIR}/../../common/bin2array.cmake)
+create_resources(${CMAKE_CURRENT_LIST_DIR}/../../binaries/RAM_APP ${CMAKE_BINARY_DIR}/binaries.c)
+set_property(SOURCE ${CMAKE_BINARY_DIR}/binaries.c PROPERTY GENERATED 1)
+target_sources(${target} PRIVATE ${CMAKE_BINARY_DIR}/binaries.c)

+ 97 - 0
esp_flasher/lib/esp-serial-flasher/examples/esp32_spi_load_ram_example/main/main.c

@@ -0,0 +1,97 @@
+/* Example of loading the program into RAM through SPI
+
+   This example code is in the Public Domain (or CC0 licensed, at your option.)
+
+   Unless required by applicable law or agreed to in writing, this
+   software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
+   CONDITIONS OF ANY KIND, either express or implied.
+*/
+
+#include <sys/param.h>
+#include <string.h>
+#include "esp_err.h"
+#include "esp_log.h"
+#include "esp_task_wdt.h"
+#include "driver/spi_master.h"
+#include "driver/uart.h"
+#include "driver/gpio.h"
+#include "esp32_spi_port.h"
+#include "esp_loader.h"
+#include "example_common.h"
+#include "freertos/FreeRTOS.h"
+
+static const char *TAG = "spi_ram_loader";
+
+// Max line size
+#define BUF_LEN 128
+static uint8_t buf[BUF_LEN] = {0};
+
+void slave_monitor(void *arg)
+{
+    // Initialize UART
+    uart_config_t uart_config = {
+        .baud_rate = 115200,
+        .data_bits = UART_DATA_8_BITS,
+        .parity    = UART_PARITY_DISABLE,
+        .stop_bits = UART_STOP_BITS_1,
+        .flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
+#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
+        .source_clk = UART_SCLK_DEFAULT,
+#endif
+    };
+
+    ESP_ERROR_CHECK(uart_param_config(UART_NUM_2, &uart_config));
+
+    ESP_ERROR_CHECK(uart_set_pin(UART_NUM_2, GPIO_NUM_6, GPIO_NUM_7,
+                                 UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE));
+
+    ESP_ERROR_CHECK(uart_driver_install(UART_NUM_2, BUF_LEN * 4, BUF_LEN * 4, 0, NULL, 0));
+
+    while (1) {
+        int rxBytes = uart_read_bytes(UART_NUM_2, buf, BUF_LEN, 100 / portTICK_PERIOD_MS);
+        buf[rxBytes] = '\0';
+        printf("%s", buf);
+    }
+}
+
+void app_main(void)
+{
+    example_ram_app_binary_t bin;
+
+    const loader_esp32_spi_config_t config = {
+        .spi_bus = SPI2_HOST,
+        .frequency = 20 * 1000000,
+        .reset_trigger_pin = GPIO_NUM_5,
+        .spi_clk_pin = GPIO_NUM_12,
+        .spi_cs_pin = GPIO_NUM_10,
+        .spi_miso_pin = GPIO_NUM_13,
+        .spi_mosi_pin = GPIO_NUM_11,
+        .spi_quadwp_pin = GPIO_NUM_14,
+        .spi_quadhd_pin = GPIO_NUM_9,
+        .strap_bit0_pin = GPIO_NUM_13,
+        .strap_bit1_pin = GPIO_NUM_2,
+        .strap_bit2_pin = GPIO_NUM_3,
+        .strap_bit3_pin = GPIO_NUM_4,
+    };
+
+    if (loader_port_esp32_spi_init(&config) != ESP_LOADER_SUCCESS) {
+        ESP_LOGE(TAG, "SPI initialization failed.");
+        abort();
+    }
+
+    if (connect_to_target(0) == ESP_LOADER_SUCCESS) {
+        get_example_ram_app_binary(esp_loader_get_target(), &bin);
+        ESP_LOGI(TAG, "Loading app to RAM ...");
+        esp_loader_error_t err = load_ram_binary(bin.ram_app.data);
+        if (err == ESP_LOADER_SUCCESS) {
+            // Forward slave's serial output
+            ESP_LOGI(TAG, "********************************************");
+            ESP_LOGI(TAG, "*** Logs below are print from slave .... ***");
+            ESP_LOGI(TAG, "********************************************");
+            xTaskCreate(slave_monitor, "slave_monitor", 2048, NULL, configMAX_PRIORITIES, NULL);
+        } else {
+            ESP_LOGE(TAG, "Loading to RAM failed ...");
+        }
+    }
+    vTaskDelete(NULL);
+}

+ 4 - 0
esp_flasher/lib/esp-serial-flasher/examples/esp32_spi_load_ram_example/sdkconfig.defaults

@@ -0,0 +1,4 @@
+# This file was generated using idf.py save-defconfig. It can be edited manually.
+# Espressif IoT Development Framework (ESP-IDF) Project Minimal Configuration
+#
+CONFIG_SERIAL_FLASHER_INTERFACE_SPI=y

+ 17 - 0
esp_flasher/lib/esp-serial-flasher/examples/raspberry_example/CMakeLists.txt

@@ -0,0 +1,17 @@
+cmake_minimum_required(VERSION 3.5)
+
+set(FLASHER_DIR ${CMAKE_CURRENT_LIST_DIR}/../..)
+set(PORT RASPBERRY_PI)
+
+project(raspberry_flasher)
+    
+add_executable(${CMAKE_PROJECT_NAME} Src/main.c ../common/example_common.c)
+
+target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE ../common/)
+
+add_subdirectory(${FLASHER_DIR} ${CMAKE_BINARY_DIR}/flasher)
+
+target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE flasher)
+
+# This example only supports one target (ESP32) and uses specific binary to be flashed.
+target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE -DSINGLE_TARGET_SUPPORT=1)

+ 76 - 0
esp_flasher/lib/esp-serial-flasher/examples/raspberry_example/README.md

@@ -0,0 +1,76 @@
+# Raspberry Pi example
+
+## Overview
+
+Example demonstrates how to flash ESP32 from Raspberry Pi 4 (Model B) using esp_serial_flash component API. AT command firmware to be flashed from Raspberry Pi to ESP32 can be found in `binaries`. USART0 is dedicated for communication with ESP32.
+
+Following steps are performed in order to re-program target's memory:
+
+1. Peripherals are initialized.
+2. Host puts slave device into boot mode tries to connect by calling `esp_loader_connect()`.
+3. Then `esp_loader_flash_start()` is called to enter flashing mode and erase amount of memory to be flashed.
+4. `esp_loader_flash_write()` function is called repeatedly until the whole binary image is transfered.
+5. At the end, `loader_port_reset_target()` is called to restart ESP32 and execute updated firmware.
+
+Note: In addition, to steps mentioned above, `esp_loader_change_transmission_rate`  is called after connection is established in order to increase flashing speed. Bootloader is also capable of detecting baud rate during connection phase, and can be changed before calling `esp_loader_connect`. However, it is recommended to start at lower speed and then use dedicated command to increase baud rate. This does not apply for ESP8266, as its bootloader does not support this command, therefore, baud rate can only be changed before connection phase in this case.
+
+## Hardware Required
+
+* Raspberry Pi 4 Model B. 
+* A development board with ESP32 SoC (e.g. ESP-WROVER-KIT, ESP32-DevKitC, etc.).
+* USB cable in case ESP32 board is powered from USB. ESP32 can be powered by Raspberry Pi as well.
+
+## Hardware connection
+
+Table below shows connection between Raspberry Pi and ESP32.
+
+| Raspberry Pi (host) |    ESP32 (slave)    |
+|:-------------------:|:-------------------:|
+|        GPIO3        |         IO0         |
+|        GPIO2        |         RST         |
+|        GPIO14       |         RX0         |
+|        GPIO15       |         TX0         |
+|         GND         |         GND         |
+
+Optionally, UART-to-USB bridge can be connected to PD5(RX) and PD6(TX) for debug purposes.
+
+## Installation
+
+### GPIO library
+Raspberry Pi makes use of [pigpio](http://abyz.me.uk/rpi/pigpio/) library in order to simplify controlling GPIO pins. Some distributions of 'Raspberry Pi OS' may come with `pigpio` already installed. Presence of the library in the system can checked by running command:
+```
+pigpiod -v
+```
+
+If not present, run following commands to install the library. 
+```
+sudo apt-get update
+sudo apt-get install pigpio
+```
+
+### Enable UART
+On Raspberry Pi 4, primary UART (UART0) is connected to the On-board Bluetooth module by default.
+In order to enable serial communication on this UART, run following command in terminal:
+```
+sudo raspi-config
+```
+
+* Navigate to **Interfacing Options -> Serial**.
+* Then it will ask for login shell to be accessible over Serial, select **No**.
+* After that, it will ask for enabling Hardware Serial port, select **Yes**.
+* Reboot the Raspberry Pi.
+
+## Build and run
+
+To compile the example:
+
+Create and navigate to `build` directory:
+```
+mkdir build && cd build
+```
+Run cmake, build example and run example: 
+```
+cmake .. && cmake --build . && ./raspberry_flasher
+```
+
+For more details regarding to esp_serial_flasher configuration, please refer to top level [README.md](../../README.md).

+ 81 - 0
esp_flasher/lib/esp-serial-flasher/examples/raspberry_example/Src/main.c

@@ -0,0 +1,81 @@
+/* Flash multiple partitions example
+
+   This example code is in the Public Domain (or CC0 licensed, at your option.)
+
+   Unless required by applicable law or agreed to in writing, this
+   software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
+   CONDITIONS OF ANY KIND, either express or implied.
+*/
+
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/param.h>
+#include "esp_loader.h"
+#include "example_common.h"
+#include "raspberry_port.h"
+
+#define TARGET_RST_Pin 2
+#define TARGET_IO0_Pin 3
+
+#define DEFAULT_BAUD_RATE 115200
+#define HIGHER_BAUD_RATE  460800
+#define SERIAL_DEVICE     "/dev/ttyS0"
+
+#define BINARY_PATH       "../../binaries/ESP32_AT_Firmware/Firmware.bin"
+
+
+static void upload_file(const char *path, size_t address)
+{
+    char *buffer = NULL;
+
+    FILE *image = fopen(path, "r");
+    if (image == NULL) {
+        printf("Error:Failed to open file %s\n", path);
+        return;
+    }
+
+    fseek(image, 0L, SEEK_END);
+    size_t size = ftell(image);
+    rewind(image);
+
+    printf("File %s opened. Size: %u bytes\n", path, size);
+
+    buffer = (char *)malloc(size);
+    if (buffer == NULL) {
+        printf("Error: Failed allocate memory\n");
+        goto cleanup;
+    }
+
+    // copy file content to buffer
+    size_t bytes_read = fread(buffer, 1, size, image);
+    if (bytes_read != size) {
+        printf("Error occurred while reading file");
+        goto cleanup;
+    }
+
+    flash_binary(buffer, size, address);
+
+cleanup:
+    fclose(image);
+    free(buffer);
+}
+
+int main(void)
+{
+    const loader_raspberry_config_t config = {
+        .device = SERIAL_DEVICE,
+        .baudrate = DEFAULT_BAUD_RATE,
+        .reset_trigger_pin = TARGET_RST_Pin,
+        .gpio0_trigger_pin = TARGET_IO0_Pin,
+    };
+
+    loader_port_raspberry_init(&config);
+
+    if (connect_to_target(HIGHER_BAUD_RATE) == ESP_LOADER_SUCCESS) {
+        upload_file(BINARY_PATH, 0);
+    }
+
+    loader_port_reset_target();
+}

+ 46 - 0
esp_flasher/lib/esp-serial-flasher/examples/stm32_example/CMakeLists.txt

@@ -0,0 +1,46 @@
+cmake_minimum_required(VERSION 3.16)
+
+set(FLASHER_DIR ${CMAKE_CURRENT_LIST_DIR}/../..)
+set(CMAKE_TOOLCHAIN_FILE ${FLASHER_DIR}/submodules/stm32-cmake/cmake/stm32_gcc.cmake)
+
+project(stm32_flasher C ASM)
+
+find_package(CMSIS COMPONENTS STM32H7_M7 REQUIRED)
+find_package(HAL COMPONENTS STM32H7_M7 PWR RCC GPIO UART CORTEX REQUIRED)
+
+include_directories(${CMAKE_CURRENT_SOURCE_DIR} Core/Inc)
+
+include(${CMAKE_CURRENT_LIST_DIR}/../common/bin2array.cmake)
+create_resources(${CMAKE_CURRENT_LIST_DIR}/../binaries/Hello-world Core/Src/binaries.c)
+
+add_executable(${CMAKE_PROJECT_NAME} 
+    ../common/example_common.c
+    Core/Src/main.c
+    Core/Src/stm32h7xx_hal_msp.c
+    Core/Src/stm32h7xx_it.c
+    Core/Src/libc_compat.c
+    Core/Src/binaries.c
+)
+
+target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE ../common)
+
+set(PORT STM32)
+set(STM32_CHIP STM32H743VI)
+set(CORE_USED M7)
+add_subdirectory(${FLASHER_DIR} ${CMAKE_BINARY_DIR}/flasher)
+
+target_link_libraries(${CMAKE_PROJECT_NAME}
+PRIVATE
+    HAL::STM32::H7::M7::PWREx
+    HAL::STM32::H7::M7::RCCEx
+    HAL::STM32::H7::M7::GPIO
+    HAL::STM32::H7::M7::UARTEx
+    HAL::STM32::H7::M7::CORTEX
+    CMSIS::STM32::H743VI::M7
+    STM32::Nano
+    flasher
+)
+
+stm32_print_size_of_target(${CMAKE_PROJECT_NAME})
+stm32_generate_binary_file(${CMAKE_PROJECT_NAME})
+stm32_generate_hex_file(${CMAKE_PROJECT_NAME})

+ 73 - 0
esp_flasher/lib/esp-serial-flasher/examples/stm32_example/Core/Inc/main.h

@@ -0,0 +1,73 @@
+/* USER CODE BEGIN Header */
+/**
+  ******************************************************************************
+  * @file           : main.h
+  * @brief          : Header for main.c file.
+  *                   This file contains the common defines of the application.
+  ******************************************************************************
+  * @attention
+  *
+  * Copyright (c) 2023 STMicroelectronics.
+  * All rights reserved.
+  *
+  * This software is licensed under terms that can be found in the LICENSE file
+  * in the root directory of this software component.
+  * If no LICENSE file comes with this software, it is provided AS-IS.
+  *
+  ******************************************************************************
+  */
+/* USER CODE END Header */
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __MAIN_H
+#define __MAIN_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm32h7xx_hal.h"
+
+/* Private includes ----------------------------------------------------------*/
+/* USER CODE BEGIN Includes */
+
+/* USER CODE END Includes */
+
+/* Exported types ------------------------------------------------------------*/
+/* USER CODE BEGIN ET */
+
+/* USER CODE END ET */
+
+/* Exported constants --------------------------------------------------------*/
+/* USER CODE BEGIN EC */
+
+/* USER CODE END EC */
+
+/* Exported macro ------------------------------------------------------------*/
+/* USER CODE BEGIN EM */
+
+/* USER CODE END EM */
+
+/* Exported functions prototypes ---------------------------------------------*/
+void Error_Handler(void);
+
+/* USER CODE BEGIN EFP */
+
+/* USER CODE END EFP */
+
+/* Private defines -----------------------------------------------------------*/
+#define TARGET_IO0_Pin GPIO_PIN_12
+#define TARGET_IO0_GPIO_Port GPIOB
+#define TARGET_RESET_Pin GPIO_PIN_13
+#define TARGET_RESET_GPIO_Port GPIOB
+
+/* USER CODE BEGIN Private defines */
+
+/* USER CODE END Private defines */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __MAIN_H */

+ 515 - 0
esp_flasher/lib/esp-serial-flasher/examples/stm32_example/Core/Inc/stm32h7xx_hal_conf.h

@@ -0,0 +1,515 @@
+/* USER CODE BEGIN Header */
+/**
+  ******************************************************************************
+  * @file    stm32h7xx_hal_conf.h
+  * @author  MCD Application Team
+  * @brief   HAL configuration file.
+  ******************************************************************************
+  * @attention
+  *
+  * Copyright (c) 2017 STMicroelectronics.
+  * All rights reserved.
+  *
+  * This software is licensed under terms that can be found in the LICENSE file
+  * in the root directory of this software component.
+  * If no LICENSE file comes with this software, it is provided AS-IS.
+  *
+  ******************************************************************************
+  */
+/* USER CODE END Header */
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef STM32H7xx_HAL_CONF_H
+#define STM32H7xx_HAL_CONF_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+/* Exported types ------------------------------------------------------------*/
+/* Exported constants --------------------------------------------------------*/
+
+/* ########################## Module Selection ############################## */
+/**
+  * @brief This is the list of modules to be used in the HAL driver
+  */
+#define HAL_MODULE_ENABLED
+
+  /* #define HAL_ADC_MODULE_ENABLED   */
+/* #define HAL_FDCAN_MODULE_ENABLED   */
+/* #define HAL_FMAC_MODULE_ENABLED   */
+/* #define HAL_CEC_MODULE_ENABLED   */
+/* #define HAL_COMP_MODULE_ENABLED   */
+/* #define HAL_CORDIC_MODULE_ENABLED   */
+/* #define HAL_CRC_MODULE_ENABLED   */
+/* #define HAL_CRYP_MODULE_ENABLED   */
+/* #define HAL_DAC_MODULE_ENABLED   */
+/* #define HAL_DCMI_MODULE_ENABLED   */
+/* #define HAL_DMA2D_MODULE_ENABLED   */
+/* #define HAL_ETH_MODULE_ENABLED   */
+/* #define HAL_ETH_LEGACY_MODULE_ENABLED   */
+/* #define HAL_NAND_MODULE_ENABLED   */
+/* #define HAL_NOR_MODULE_ENABLED   */
+/* #define HAL_OTFDEC_MODULE_ENABLED   */
+/* #define HAL_SRAM_MODULE_ENABLED   */
+/* #define HAL_SDRAM_MODULE_ENABLED   */
+/* #define HAL_HASH_MODULE_ENABLED   */
+/* #define HAL_HRTIM_MODULE_ENABLED   */
+/* #define HAL_HSEM_MODULE_ENABLED   */
+/* #define HAL_GFXMMU_MODULE_ENABLED   */
+/* #define HAL_JPEG_MODULE_ENABLED   */
+/* #define HAL_OPAMP_MODULE_ENABLED   */
+/* #define HAL_OSPI_MODULE_ENABLED   */
+/* #define HAL_OSPI_MODULE_ENABLED   */
+/* #define HAL_I2S_MODULE_ENABLED   */
+/* #define HAL_SMBUS_MODULE_ENABLED   */
+/* #define HAL_IWDG_MODULE_ENABLED   */
+/* #define HAL_LPTIM_MODULE_ENABLED   */
+/* #define HAL_LTDC_MODULE_ENABLED   */
+/* #define HAL_QSPI_MODULE_ENABLED   */
+/* #define HAL_RAMECC_MODULE_ENABLED   */
+/* #define HAL_RNG_MODULE_ENABLED   */
+/* #define HAL_RTC_MODULE_ENABLED   */
+/* #define HAL_SAI_MODULE_ENABLED   */
+/* #define HAL_SD_MODULE_ENABLED   */
+/* #define HAL_MMC_MODULE_ENABLED   */
+/* #define HAL_SPDIFRX_MODULE_ENABLED   */
+/* #define HAL_SPI_MODULE_ENABLED   */
+/* #define HAL_SWPMI_MODULE_ENABLED   */
+/* #define HAL_TIM_MODULE_ENABLED   */
+#define HAL_UART_MODULE_ENABLED
+/* #define HAL_USART_MODULE_ENABLED   */
+/* #define HAL_IRDA_MODULE_ENABLED   */
+/* #define HAL_SMARTCARD_MODULE_ENABLED   */
+/* #define HAL_WWDG_MODULE_ENABLED   */
+/* #define HAL_PCD_MODULE_ENABLED   */
+/* #define HAL_HCD_MODULE_ENABLED   */
+/* #define HAL_DFSDM_MODULE_ENABLED   */
+/* #define HAL_DSI_MODULE_ENABLED   */
+/* #define HAL_JPEG_MODULE_ENABLED   */
+/* #define HAL_MDIOS_MODULE_ENABLED   */
+/* #define HAL_PSSI_MODULE_ENABLED   */
+/* #define HAL_DTS_MODULE_ENABLED   */
+#define HAL_GPIO_MODULE_ENABLED
+#define HAL_DMA_MODULE_ENABLED
+#define HAL_MDMA_MODULE_ENABLED
+#define HAL_RCC_MODULE_ENABLED
+#define HAL_FLASH_MODULE_ENABLED
+#define HAL_EXTI_MODULE_ENABLED
+#define HAL_PWR_MODULE_ENABLED
+#define HAL_I2C_MODULE_ENABLED
+#define HAL_CORTEX_MODULE_ENABLED
+#define HAL_HSEM_MODULE_ENABLED
+
+/* ########################## Oscillator Values adaptation ####################*/
+/**
+  * @brief Adjust the value of External High Speed oscillator (HSE) used in your application.
+  *        This value is used by the RCC HAL module to compute the system frequency
+  *        (when HSE is used as system clock source, directly or through the PLL).
+  */
+#if !defined  (HSE_VALUE)
+#define HSE_VALUE    (25000000UL) /*!< Value of the External oscillator in Hz : FPGA case fixed to 60MHZ */
+#endif /* HSE_VALUE */
+
+#if !defined  (HSE_STARTUP_TIMEOUT)
+  #define HSE_STARTUP_TIMEOUT    (100UL)   /*!< Time out for HSE start up, in ms */
+#endif /* HSE_STARTUP_TIMEOUT */
+
+/**
+  * @brief Internal  oscillator (CSI) default value.
+  *        This value is the default CSI value after Reset.
+  */
+#if !defined  (CSI_VALUE)
+  #define CSI_VALUE    (4000000UL) /*!< Value of the Internal oscillator in Hz*/
+#endif /* CSI_VALUE */
+
+/**
+  * @brief Internal High Speed oscillator (HSI) value.
+  *        This value is used by the RCC HAL module to compute the system frequency
+  *        (when HSI is used as system clock source, directly or through the PLL).
+  */
+#if !defined  (HSI_VALUE)
+  #define HSI_VALUE    (64000000UL) /*!< Value of the Internal oscillator in Hz*/
+#endif /* HSI_VALUE */
+
+/**
+  * @brief External Low Speed oscillator (LSE) value.
+  *        This value is used by the UART, RTC HAL module to compute the system frequency
+  */
+#if !defined  (LSE_VALUE)
+  #define LSE_VALUE    (32768UL) /*!< Value of the External oscillator in Hz*/
+#endif /* LSE_VALUE */
+
+#if !defined  (LSE_STARTUP_TIMEOUT)
+  #define LSE_STARTUP_TIMEOUT    (5000UL)   /*!< Time out for LSE start up, in ms */
+#endif /* LSE_STARTUP_TIMEOUT */
+
+#if !defined  (LSI_VALUE)
+  #define LSI_VALUE  (32000UL)              /*!< LSI Typical Value in Hz*/
+#endif /* LSI_VALUE */                      /*!< Value of the Internal Low Speed oscillator in Hz
+                                              The real value may vary depending on the variations
+                                              in voltage and temperature.*/
+
+/**
+  * @brief External clock source for I2S peripheral
+  *        This value is used by the I2S HAL module to compute the I2S clock source
+  *        frequency, this source is inserted directly through I2S_CKIN pad.
+  */
+#if !defined  (EXTERNAL_CLOCK_VALUE)
+  #define EXTERNAL_CLOCK_VALUE    12288000UL /*!< Value of the External clock in Hz*/
+#endif /* EXTERNAL_CLOCK_VALUE */
+
+/* Tip: To avoid modifying this file each time you need to use different HSE,
+   ===  you can define the HSE value in your toolchain compiler preprocessor. */
+
+/* ########################### System Configuration ######################### */
+/**
+  * @brief This is the HAL system configuration section
+  */
+#define  VDD_VALUE                    (3300UL) /*!< Value of VDD in mv */
+#define  TICK_INT_PRIORITY            (15UL) /*!< tick interrupt priority */
+#define  USE_RTOS                     0
+#define  USE_SD_TRANSCEIVER           0U               /*!< use uSD Transceiver */
+#define  USE_SPI_CRC	              0U               /*!< use CRC in SPI */
+
+#define  USE_HAL_ADC_REGISTER_CALLBACKS     0U /* ADC register callback disabled     */
+#define  USE_HAL_CEC_REGISTER_CALLBACKS     0U /* CEC register callback disabled     */
+#define  USE_HAL_COMP_REGISTER_CALLBACKS    0U /* COMP register callback disabled    */
+#define  USE_HAL_CORDIC_REGISTER_CALLBACKS  0U /* CORDIC register callback disabled  */
+#define  USE_HAL_CRYP_REGISTER_CALLBACKS    0U /* CRYP register callback disabled    */
+#define  USE_HAL_DAC_REGISTER_CALLBACKS     0U /* DAC register callback disabled     */
+#define  USE_HAL_DCMI_REGISTER_CALLBACKS    0U /* DCMI register callback disabled    */
+#define  USE_HAL_DFSDM_REGISTER_CALLBACKS   0U /* DFSDM register callback disabled   */
+#define  USE_HAL_DMA2D_REGISTER_CALLBACKS   0U /* DMA2D register callback disabled   */
+#define  USE_HAL_DSI_REGISTER_CALLBACKS     0U /* DSI register callback disabled     */
+#define  USE_HAL_DTS_REGISTER_CALLBACKS     0U /* DTS register callback disabled     */
+#define  USE_HAL_ETH_REGISTER_CALLBACKS     0U /* ETH register callback disabled     */
+#define  USE_HAL_FDCAN_REGISTER_CALLBACKS   0U /* FDCAN register callback disabled   */
+#define  USE_HAL_FMAC_REGISTER_CALLBACKS    0U /* FMAC register callback disabled  */
+#define  USE_HAL_NAND_REGISTER_CALLBACKS    0U /* NAND register callback disabled    */
+#define  USE_HAL_NOR_REGISTER_CALLBACKS     0U /* NOR register callback disabled     */
+#define  USE_HAL_SDRAM_REGISTER_CALLBACKS   0U /* SDRAM register callback disabled   */
+#define  USE_HAL_SRAM_REGISTER_CALLBACKS    0U /* SRAM register callback disabled    */
+#define  USE_HAL_HASH_REGISTER_CALLBACKS    0U /* HASH register callback disabled    */
+#define  USE_HAL_HCD_REGISTER_CALLBACKS     0U /* HCD register callback disabled     */
+#define  USE_HAL_GFXMMU_REGISTER_CALLBACKS  0U /* GFXMMU register callback disabled  */
+#define  USE_HAL_HRTIM_REGISTER_CALLBACKS   0U /* HRTIM register callback disabled   */
+#define  USE_HAL_I2C_REGISTER_CALLBACKS     0U /* I2C register callback disabled     */
+#define  USE_HAL_I2S_REGISTER_CALLBACKS     0U /* I2S register callback disabled     */
+#define  USE_HAL_IRDA_REGISTER_CALLBACKS    0U /* IRDA register callback disabled    */
+#define  USE_HAL_JPEG_REGISTER_CALLBACKS    0U /* JPEG register callback disabled    */
+#define  USE_HAL_LPTIM_REGISTER_CALLBACKS   0U /* LPTIM register callback disabled   */
+#define  USE_HAL_LTDC_REGISTER_CALLBACKS    0U /* LTDC register callback disabled    */
+#define  USE_HAL_MDIOS_REGISTER_CALLBACKS   0U /* MDIO register callback disabled    */
+#define  USE_HAL_MMC_REGISTER_CALLBACKS     0U /* MMC register callback disabled     */
+#define  USE_HAL_OPAMP_REGISTER_CALLBACKS   0U /* MDIO register callback disabled    */
+#define  USE_HAL_OSPI_REGISTER_CALLBACKS    0U /* OSPI register callback disabled    */
+#define  USE_HAL_OTFDEC_REGISTER_CALLBACKS  0U /* OTFDEC register callback disabled  */
+#define  USE_HAL_PCD_REGISTER_CALLBACKS     0U /* PCD register callback disabled     */
+#define  USE_HAL_QSPI_REGISTER_CALLBACKS    0U /* QSPI register callback disabled    */
+#define  USE_HAL_RNG_REGISTER_CALLBACKS     0U /* RNG register callback disabled     */
+#define  USE_HAL_RTC_REGISTER_CALLBACKS     0U /* RTC register callback disabled     */
+#define  USE_HAL_SAI_REGISTER_CALLBACKS     0U /* SAI register callback disabled     */
+#define  USE_HAL_SD_REGISTER_CALLBACKS      0U /* SD register callback disabled      */
+#define  USE_HAL_SMARTCARD_REGISTER_CALLBACKS  0U /* SMARTCARD register callback disabled */
+#define  USE_HAL_SPDIFRX_REGISTER_CALLBACKS 0U /* SPDIFRX register callback disabled */
+#define  USE_HAL_SMBUS_REGISTER_CALLBACKS   0U /* SMBUS register callback disabled   */
+#define  USE_HAL_SPI_REGISTER_CALLBACKS     0U /* SPI register callback disabled     */
+#define  USE_HAL_SWPMI_REGISTER_CALLBACKS   0U /* SWPMI register callback disabled   */
+#define  USE_HAL_TIM_REGISTER_CALLBACKS     0U /* TIM register callback disabled     */
+#define  USE_HAL_UART_REGISTER_CALLBACKS    0U /* UART register callback disabled    */
+#define  USE_HAL_USART_REGISTER_CALLBACKS   0U /* USART register callback disabled   */
+#define  USE_HAL_WWDG_REGISTER_CALLBACKS    0U /* WWDG register callback disabled    */
+
+/* ########################### Ethernet Configuration ######################### */
+#define ETH_TX_DESC_CNT         4U  /* number of Ethernet Tx DMA descriptors */
+#define ETH_RX_DESC_CNT         4U  /* number of Ethernet Rx DMA descriptors */
+
+#define ETH_MAC_ADDR0    (0x02UL)
+#define ETH_MAC_ADDR1    (0x00UL)
+#define ETH_MAC_ADDR2    (0x00UL)
+#define ETH_MAC_ADDR3    (0x00UL)
+#define ETH_MAC_ADDR4    (0x00UL)
+#define ETH_MAC_ADDR5    (0x00UL)
+
+/* ########################## Assert Selection ############################## */
+/**
+  * @brief Uncomment the line below to expanse the "assert_param" macro in the
+  *        HAL drivers code
+  */
+/* #define USE_FULL_ASSERT    1U */
+
+/* Includes ------------------------------------------------------------------*/
+/**
+  * @brief Include module's header file
+  */
+
+#ifdef HAL_RCC_MODULE_ENABLED
+  #include "stm32h7xx_hal_rcc.h"
+#endif /* HAL_RCC_MODULE_ENABLED */
+
+#ifdef HAL_GPIO_MODULE_ENABLED
+  #include "stm32h7xx_hal_gpio.h"
+#endif /* HAL_GPIO_MODULE_ENABLED */
+
+#ifdef HAL_DMA_MODULE_ENABLED
+  #include "stm32h7xx_hal_dma.h"
+#endif /* HAL_DMA_MODULE_ENABLED */
+
+#ifdef HAL_MDMA_MODULE_ENABLED
+ #include "stm32h7xx_hal_mdma.h"
+#endif /* HAL_MDMA_MODULE_ENABLED */
+
+#ifdef HAL_HASH_MODULE_ENABLED
+  #include "stm32h7xx_hal_hash.h"
+#endif /* HAL_HASH_MODULE_ENABLED */
+
+#ifdef HAL_DCMI_MODULE_ENABLED
+  #include "stm32h7xx_hal_dcmi.h"
+#endif /* HAL_DCMI_MODULE_ENABLED */
+
+#ifdef HAL_DMA2D_MODULE_ENABLED
+  #include "stm32h7xx_hal_dma2d.h"
+#endif /* HAL_DMA2D_MODULE_ENABLED */
+
+#ifdef HAL_DSI_MODULE_ENABLED
+  #include "stm32h7xx_hal_dsi.h"
+#endif /* HAL_DSI_MODULE_ENABLED */
+
+#ifdef HAL_DFSDM_MODULE_ENABLED
+  #include "stm32h7xx_hal_dfsdm.h"
+#endif /* HAL_DFSDM_MODULE_ENABLED */
+
+#ifdef HAL_DTS_MODULE_ENABLED
+ #include "stm32h7xx_hal_dts.h"
+#endif /* HAL_DTS_MODULE_ENABLED */
+
+#ifdef HAL_ETH_MODULE_ENABLED
+  #include "stm32h7xx_hal_eth.h"
+#endif /* HAL_ETH_MODULE_ENABLED */
+
+#ifdef HAL_ETH_LEGACY_MODULE_ENABLED
+  #include "stm32h7xx_hal_eth_legacy.h"
+#endif /* HAL_ETH_LEGACY_MODULE_ENABLED */
+
+#ifdef HAL_EXTI_MODULE_ENABLED
+  #include "stm32h7xx_hal_exti.h"
+#endif /* HAL_EXTI_MODULE_ENABLED */
+
+#ifdef HAL_CORTEX_MODULE_ENABLED
+  #include "stm32h7xx_hal_cortex.h"
+#endif /* HAL_CORTEX_MODULE_ENABLED */
+
+#ifdef HAL_ADC_MODULE_ENABLED
+  #include "stm32h7xx_hal_adc.h"
+#endif /* HAL_ADC_MODULE_ENABLED */
+
+#ifdef HAL_FDCAN_MODULE_ENABLED
+  #include "stm32h7xx_hal_fdcan.h"
+#endif /* HAL_FDCAN_MODULE_ENABLED */
+
+#ifdef HAL_CEC_MODULE_ENABLED
+  #include "stm32h7xx_hal_cec.h"
+#endif /* HAL_CEC_MODULE_ENABLED */
+
+#ifdef HAL_COMP_MODULE_ENABLED
+  #include "stm32h7xx_hal_comp.h"
+#endif /* HAL_COMP_MODULE_ENABLED */
+
+#ifdef HAL_CORDIC_MODULE_ENABLED
+  #include "stm32h7xx_hal_cordic.h"
+#endif /* HAL_CORDIC_MODULE_ENABLED */
+
+#ifdef HAL_CRC_MODULE_ENABLED
+  #include "stm32h7xx_hal_crc.h"
+#endif /* HAL_CRC_MODULE_ENABLED */
+
+#ifdef HAL_CRYP_MODULE_ENABLED
+  #include "stm32h7xx_hal_cryp.h"
+#endif /* HAL_CRYP_MODULE_ENABLED */
+
+#ifdef HAL_DAC_MODULE_ENABLED
+  #include "stm32h7xx_hal_dac.h"
+#endif /* HAL_DAC_MODULE_ENABLED */
+
+#ifdef HAL_FLASH_MODULE_ENABLED
+  #include "stm32h7xx_hal_flash.h"
+#endif /* HAL_FLASH_MODULE_ENABLED */
+
+#ifdef HAL_GFXMMU_MODULE_ENABLED
+  #include "stm32h7xx_hal_gfxmmu.h"
+#endif /* HAL_GFXMMU_MODULE_ENABLED */
+
+#ifdef HAL_FMAC_MODULE_ENABLED
+  #include "stm32h7xx_hal_fmac.h"
+#endif /* HAL_FMAC_MODULE_ENABLED */
+
+#ifdef HAL_HRTIM_MODULE_ENABLED
+  #include "stm32h7xx_hal_hrtim.h"
+#endif /* HAL_HRTIM_MODULE_ENABLED */
+
+#ifdef HAL_HSEM_MODULE_ENABLED
+  #include "stm32h7xx_hal_hsem.h"
+#endif /* HAL_HSEM_MODULE_ENABLED */
+
+#ifdef HAL_SRAM_MODULE_ENABLED
+  #include "stm32h7xx_hal_sram.h"
+#endif /* HAL_SRAM_MODULE_ENABLED */
+
+#ifdef HAL_NOR_MODULE_ENABLED
+  #include "stm32h7xx_hal_nor.h"
+#endif /* HAL_NOR_MODULE_ENABLED */
+
+#ifdef HAL_NAND_MODULE_ENABLED
+  #include "stm32h7xx_hal_nand.h"
+#endif /* HAL_NAND_MODULE_ENABLED */
+
+#ifdef HAL_I2C_MODULE_ENABLED
+ #include "stm32h7xx_hal_i2c.h"
+#endif /* HAL_I2C_MODULE_ENABLED */
+
+#ifdef HAL_I2S_MODULE_ENABLED
+ #include "stm32h7xx_hal_i2s.h"
+#endif /* HAL_I2S_MODULE_ENABLED */
+
+#ifdef HAL_IWDG_MODULE_ENABLED
+ #include "stm32h7xx_hal_iwdg.h"
+#endif /* HAL_IWDG_MODULE_ENABLED */
+
+#ifdef HAL_JPEG_MODULE_ENABLED
+ #include "stm32h7xx_hal_jpeg.h"
+#endif /* HAL_JPEG_MODULE_ENABLED */
+
+#ifdef HAL_MDIOS_MODULE_ENABLED
+ #include "stm32h7xx_hal_mdios.h"
+#endif /* HAL_MDIOS_MODULE_ENABLED */
+
+#ifdef HAL_MMC_MODULE_ENABLED
+ #include "stm32h7xx_hal_mmc.h"
+#endif /* HAL_MMC_MODULE_ENABLED */
+
+#ifdef HAL_LPTIM_MODULE_ENABLED
+#include "stm32h7xx_hal_lptim.h"
+#endif /* HAL_LPTIM_MODULE_ENABLED */
+
+#ifdef HAL_LTDC_MODULE_ENABLED
+#include "stm32h7xx_hal_ltdc.h"
+#endif /* HAL_LTDC_MODULE_ENABLED */
+
+#ifdef HAL_OPAMP_MODULE_ENABLED
+#include "stm32h7xx_hal_opamp.h"
+#endif /* HAL_OPAMP_MODULE_ENABLED */
+
+#ifdef HAL_OSPI_MODULE_ENABLED
+ #include "stm32h7xx_hal_ospi.h"
+#endif /* HAL_OSPI_MODULE_ENABLED */
+
+#ifdef HAL_OTFDEC_MODULE_ENABLED
+#include "stm32h7xx_hal_otfdec.h"
+#endif /* HAL_OTFDEC_MODULE_ENABLED */
+
+#ifdef HAL_PSSI_MODULE_ENABLED
+ #include "stm32h7xx_hal_pssi.h"
+#endif /* HAL_PSSI_MODULE_ENABLED */
+
+#ifdef HAL_PWR_MODULE_ENABLED
+ #include "stm32h7xx_hal_pwr.h"
+#endif /* HAL_PWR_MODULE_ENABLED */
+
+#ifdef HAL_QSPI_MODULE_ENABLED
+ #include "stm32h7xx_hal_qspi.h"
+#endif /* HAL_QSPI_MODULE_ENABLED */
+
+#ifdef HAL_RAMECC_MODULE_ENABLED
+ #include "stm32h7xx_hal_ramecc.h"
+#endif /* HAL_RAMECC_MODULE_ENABLED */
+
+#ifdef HAL_RNG_MODULE_ENABLED
+ #include "stm32h7xx_hal_rng.h"
+#endif /* HAL_RNG_MODULE_ENABLED */
+
+#ifdef HAL_RTC_MODULE_ENABLED
+ #include "stm32h7xx_hal_rtc.h"
+#endif /* HAL_RTC_MODULE_ENABLED */
+
+#ifdef HAL_SAI_MODULE_ENABLED
+ #include "stm32h7xx_hal_sai.h"
+#endif /* HAL_SAI_MODULE_ENABLED */
+
+#ifdef HAL_SD_MODULE_ENABLED
+ #include "stm32h7xx_hal_sd.h"
+#endif /* HAL_SD_MODULE_ENABLED */
+
+#ifdef HAL_SDRAM_MODULE_ENABLED
+ #include "stm32h7xx_hal_sdram.h"
+#endif /* HAL_SDRAM_MODULE_ENABLED */
+
+#ifdef HAL_SPI_MODULE_ENABLED
+ #include "stm32h7xx_hal_spi.h"
+#endif /* HAL_SPI_MODULE_ENABLED */
+
+#ifdef HAL_SPDIFRX_MODULE_ENABLED
+ #include "stm32h7xx_hal_spdifrx.h"
+#endif /* HAL_SPDIFRX_MODULE_ENABLED */
+
+#ifdef HAL_SWPMI_MODULE_ENABLED
+ #include "stm32h7xx_hal_swpmi.h"
+#endif /* HAL_SWPMI_MODULE_ENABLED */
+
+#ifdef HAL_TIM_MODULE_ENABLED
+ #include "stm32h7xx_hal_tim.h"
+#endif /* HAL_TIM_MODULE_ENABLED */
+
+#ifdef HAL_UART_MODULE_ENABLED
+ #include "stm32h7xx_hal_uart.h"
+#endif /* HAL_UART_MODULE_ENABLED */
+
+#ifdef HAL_USART_MODULE_ENABLED
+ #include "stm32h7xx_hal_usart.h"
+#endif /* HAL_USART_MODULE_ENABLED */
+
+#ifdef HAL_IRDA_MODULE_ENABLED
+ #include "stm32h7xx_hal_irda.h"
+#endif /* HAL_IRDA_MODULE_ENABLED */
+
+#ifdef HAL_SMARTCARD_MODULE_ENABLED
+ #include "stm32h7xx_hal_smartcard.h"
+#endif /* HAL_SMARTCARD_MODULE_ENABLED */
+
+#ifdef HAL_SMBUS_MODULE_ENABLED
+ #include "stm32h7xx_hal_smbus.h"
+#endif /* HAL_SMBUS_MODULE_ENABLED */
+
+#ifdef HAL_WWDG_MODULE_ENABLED
+ #include "stm32h7xx_hal_wwdg.h"
+#endif /* HAL_WWDG_MODULE_ENABLED */
+
+#ifdef HAL_PCD_MODULE_ENABLED
+ #include "stm32h7xx_hal_pcd.h"
+#endif /* HAL_PCD_MODULE_ENABLED */
+
+#ifdef HAL_HCD_MODULE_ENABLED
+ #include "stm32h7xx_hal_hcd.h"
+#endif /* HAL_HCD_MODULE_ENABLED */
+
+/* Exported macro ------------------------------------------------------------*/
+#ifdef  USE_FULL_ASSERT
+/**
+  * @brief  The assert_param macro is used for function's parameters check.
+  * @param  expr: If expr is false, it calls assert_failed function
+  *         which reports the name of the source file and the source
+  *         line number of the call that failed.
+  *         If expr is true, it returns no value.
+  * @retval None
+  */
+  #define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__))
+/* Exported functions ------------------------------------------------------- */
+  void assert_failed(uint8_t *file, uint32_t line);
+#else
+  #define assert_param(expr) ((void)0U)
+#endif /* USE_FULL_ASSERT */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* STM32H7xx_HAL_CONF_H */

+ 66 - 0
esp_flasher/lib/esp-serial-flasher/examples/stm32_example/Core/Inc/stm32h7xx_it.h

@@ -0,0 +1,66 @@
+/* USER CODE BEGIN Header */
+/**
+  ******************************************************************************
+  * @file    stm32h7xx_it.h
+  * @brief   This file contains the headers of the interrupt handlers.
+  ******************************************************************************
+  * @attention
+  *
+  * Copyright (c) 2023 STMicroelectronics.
+  * All rights reserved.
+  *
+  * This software is licensed under terms that can be found in the LICENSE file
+  * in the root directory of this software component.
+  * If no LICENSE file comes with this software, it is provided AS-IS.
+  *
+ ******************************************************************************
+  */
+/* USER CODE END Header */
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __STM32H7xx_IT_H
+#define __STM32H7xx_IT_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+/* Private includes ----------------------------------------------------------*/
+/* USER CODE BEGIN Includes */
+
+/* USER CODE END Includes */
+
+/* Exported types ------------------------------------------------------------*/
+/* USER CODE BEGIN ET */
+
+/* USER CODE END ET */
+
+/* Exported constants --------------------------------------------------------*/
+/* USER CODE BEGIN EC */
+
+/* USER CODE END EC */
+
+/* Exported macro ------------------------------------------------------------*/
+/* USER CODE BEGIN EM */
+
+/* USER CODE END EM */
+
+/* Exported functions prototypes ---------------------------------------------*/
+void NMI_Handler(void);
+void HardFault_Handler(void);
+void MemManage_Handler(void);
+void BusFault_Handler(void);
+void UsageFault_Handler(void);
+void SVC_Handler(void);
+void DebugMon_Handler(void);
+void PendSV_Handler(void);
+void SysTick_Handler(void);
+/* USER CODE BEGIN EFP */
+
+/* USER CODE END EFP */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __STM32H7xx_IT_H */

+ 197 - 0
esp_flasher/lib/esp-serial-flasher/examples/stm32_example/Core/Src/libc_compat.c

@@ -0,0 +1,197 @@
+/* libc_compat
+
+   This code is in the Public Domain (or CC0 licensed, at your option.)
+
+   Unless required by applicable law or agreed to in writing, this
+   software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
+   CONDITIONS OF ANY KIND, either express or implied.
+*/
+
+#include <errno.h>
+#include <sys/stat.h>
+#include <sys/times.h>
+#include <sys/unistd.h>
+#include <sys/time.h>
+
+#if defined STM32C0
+# include <stm32c0xx_hal.h>
+#elif defined STM32F0
+# include <stm32f0xx_hal.h>
+#elif defined STM32F1
+# include <stm32f1xx_hal.h>
+#elif defined STM32F2
+# include <stm32f2xx_hal.h>
+#elif defined STM32F3
+# include <stm32f3xx_hal.h>
+#elif defined STM32F4
+# include <stm32f4xx_hal.h>
+#elif defined STM32F7
+# include <stm32f7xx_hal.h>
+#elif defined STM32G0
+# include <stm32g0xx_hal.h>
+#elif defined STM32G4
+# include <stm32g4xx_hal.h>
+#elif defined STM32H5
+#include <stm32h5xx_hal.h>
+#elif defined STM32H7
+#include <stm32h7xx_hal.h>
+#endif
+
+extern uint32_t __get_MSP(void);
+extern UART_HandleTypeDef huart2;
+extern uint64_t virtualTimer;
+
+#undef errno
+extern int errno;
+
+char *__env[1] = { 0 };
+char **environ = __env;
+
+int _write(int file, char *ptr, int len);
+
+void _exit(int status)
+{
+    while (1);
+}
+
+int _close(int file)
+{
+    return -1;
+}
+
+int _execve(char *name, char **argv, char **env)
+{
+    errno = ENOMEM;
+    return -1;
+}
+
+int _fork()
+{
+    errno = EAGAIN;
+    return -1;
+}
+
+int _fstat(int file, struct stat *st)
+{
+    st->st_mode = S_IFCHR;
+    return 0;
+}
+
+int _getpid()
+{
+    return 1;
+}
+
+int _gettimeofday(struct timeval *tv, struct timezone *tz)
+{
+    tv->tv_sec = HAL_GetTick() / 1000;
+    tv->tv_usec = (HAL_GetTick() % 1000) * 1000;
+    return 0;
+}
+
+int _isatty(int file)
+{
+    switch (file)
+    {
+    case STDOUT_FILENO:
+    case STDERR_FILENO:
+    case STDIN_FILENO:
+        return 1;
+    default:
+        //errno = ENOTTY;
+        errno = EBADF;
+        return 0;
+    }
+}
+
+int _kill(int pid, int sig)
+{
+    errno = EINVAL;
+    return (-1);
+}
+
+int _link(char *old, char *new)
+{
+    errno = EMLINK;
+    return -1;
+}
+
+int _lseek(int file, int ptr, int dir)
+{
+    return 0;
+}
+
+caddr_t _sbrk(int incr)
+{
+    extern char _ebss;
+    static char *heap_end= &_ebss;
+    char *prev_heap_end;
+
+    prev_heap_end = heap_end;
+
+    char * stack = (char*) __get_MSP();
+    if (heap_end + incr > stack)
+    {
+        _write(STDERR_FILENO, "Heap and stack collision\n", 25);
+        errno = ENOMEM;
+        return (caddr_t) - 1;
+        //abort ();
+    }
+
+    heap_end += incr;
+    return (caddr_t) prev_heap_end;
+
+}
+
+int _read(int file, char *ptr, int len)
+{
+    switch (file)
+    {
+    case STDIN_FILENO:
+        HAL_UART_Receive(&huart2, (uint8_t *)ptr, 1, HAL_MAX_DELAY);
+        return 1;
+    default:
+        errno = EBADF;
+        return -1;
+    }
+}
+
+int _stat(const char *filepath, struct stat *st)
+{
+    st->st_mode = S_IFCHR;
+    return 0;
+}
+
+clock_t _times(struct tms *buf)
+{
+    return -1;
+}
+
+int _unlink(char *name)
+{
+    errno = ENOENT;
+    return -1;
+}
+
+int _wait(int *status)
+{
+    errno = ECHILD;
+    return -1;
+}
+
+int _write(int file, char *ptr, int len)
+{
+    switch (file)
+    {
+    case STDOUT_FILENO: /*stdout*/
+        HAL_UART_Transmit(&huart2, (uint8_t*)ptr, len, HAL_MAX_DELAY);
+        break;
+    case STDERR_FILENO: /* stderr */
+        HAL_UART_Transmit(&huart2, (uint8_t*)ptr, len, HAL_MAX_DELAY);
+        break;
+    default:
+        errno = EBADF;
+        return -1;
+    }
+    return len;
+}

+ 352 - 0
esp_flasher/lib/esp-serial-flasher/examples/stm32_example/Core/Src/main.c

@@ -0,0 +1,352 @@
+/* USER CODE BEGIN Header */
+/**
+  ******************************************************************************
+  * @file           : main.c
+  * @brief          : Main program body
+  ******************************************************************************
+  * @attention
+  *
+  * Copyright (c) 2023 STMicroelectronics.
+  * All rights reserved.
+  *
+  * This software is licensed under terms that can be found in the LICENSE file
+  * in the root directory of this software component.
+  * If no LICENSE file comes with this software, it is provided AS-IS.
+  *
+  ******************************************************************************
+  */
+/* USER CODE END Header */
+/* Includes ------------------------------------------------------------------*/
+#include "main.h"
+
+/* Private includes ----------------------------------------------------------*/
+/* USER CODE BEGIN Includes */
+#include <stdio.h>
+#include <stdint.h>
+#include <string.h>
+#include <sys/param.h>
+#include "stm32_port.h"
+#include "esp_loader.h"
+#include "example_common.h"
+/* USER CODE END Includes */
+
+/* Private typedef -----------------------------------------------------------*/
+/* USER CODE BEGIN PTD */
+
+/* USER CODE END PTD */
+
+/* Private define ------------------------------------------------------------*/
+/* USER CODE BEGIN PD */
+#define HIGHER_BAUDRATE 230400
+/* USER CODE END PD */
+
+/* Private macro -------------------------------------------------------------*/
+/* USER CODE BEGIN PM */
+
+/* USER CODE END PM */
+
+/* Private variables ---------------------------------------------------------*/
+
+UART_HandleTypeDef huart1;
+UART_HandleTypeDef huart2;
+
+/* USER CODE BEGIN PV */
+
+/* USER CODE END PV */
+
+/* Private function prototypes -----------------------------------------------*/
+void SystemClock_Config(void);
+static void MX_GPIO_Init(void);
+static void MX_USART1_UART_Init(void);
+static void MX_USART2_UART_Init(void);
+/* USER CODE BEGIN PFP */
+
+/* USER CODE END PFP */
+
+/* Private user code ---------------------------------------------------------*/
+/* USER CODE BEGIN 0 */
+
+/* USER CODE END 0 */
+
+/**
+  * @brief  The application entry point.
+  * @retval int
+  */
+int main(void)
+{
+  /* USER CODE BEGIN 1 */
+  example_binaries_t bin;
+  /* USER CODE END 1 */
+
+  /* MCU Configuration--------------------------------------------------------*/
+
+  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
+  HAL_Init();
+
+  /* USER CODE BEGIN Init */
+
+  /* USER CODE END Init */
+
+  /* Configure the system clock */
+  SystemClock_Config();
+
+  /* USER CODE BEGIN SysInit */
+
+  /* USER CODE END SysInit */
+
+  /* Initialize all configured peripherals */
+  MX_GPIO_Init();
+  MX_USART1_UART_Init();
+  MX_USART2_UART_Init();
+  /* USER CODE BEGIN 2 */
+
+  loader_stm32_config_t config = {
+      .huart = &huart1,
+      .port_io0 = TARGET_IO0_GPIO_Port,
+      .pin_num_io0 = TARGET_IO0_Pin,
+      .port_rst = TARGET_RESET_GPIO_Port,
+      .pin_num_rst = TARGET_RESET_Pin,
+  };
+
+  loader_port_stm32_init(&config);
+    
+  if (connect_to_target(HIGHER_BAUDRATE) == ESP_LOADER_SUCCESS) {
+        
+    get_example_binaries(esp_loader_get_target(), &bin);
+
+    flash_binary(bin.boot.data, bin.boot.size, bin.boot.addr);
+    flash_binary(bin.part.data, bin.part.size, bin.part.addr);
+    flash_binary(bin.app.data,  bin.app.size,  bin.app.addr);
+  }
+  /* USER CODE END 2 */
+
+  /* Infinite loop */
+  /* USER CODE BEGIN WHILE */
+  while (1)
+  {
+    /* USER CODE END WHILE */
+
+    /* USER CODE BEGIN 3 */
+  }
+  /* USER CODE END 3 */
+}
+
+/**
+  * @brief System Clock Configuration
+  * @retval None
+  */
+void SystemClock_Config(void)
+{
+  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
+  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
+
+  /** Supply configuration update enable
+  */
+  HAL_PWREx_ConfigSupply(PWR_LDO_SUPPLY);
+
+  /** Configure the main internal regulator output voltage
+  */
+  __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
+
+  while(!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {}
+
+  /** Initializes the RCC Oscillators according to the specified parameters
+  * in the RCC_OscInitTypeDef structure.
+  */
+  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
+  RCC_OscInitStruct.HSIState = RCC_HSI_DIV1;
+  RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
+  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
+  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
+  RCC_OscInitStruct.PLL.PLLM = 4;
+  RCC_OscInitStruct.PLL.PLLN = 15;
+  RCC_OscInitStruct.PLL.PLLP = 2;
+  RCC_OscInitStruct.PLL.PLLQ = 2;
+  RCC_OscInitStruct.PLL.PLLR = 2;
+  RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1VCIRANGE_3;
+  RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOWIDE;
+  RCC_OscInitStruct.PLL.PLLFRACN = 0;
+  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
+  {
+    Error_Handler();
+  }
+
+  /** Initializes the CPU, AHB and APB buses clocks
+  */
+  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
+                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2
+                              |RCC_CLOCKTYPE_D3PCLK1|RCC_CLOCKTYPE_D1PCLK1;
+  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
+  RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV1;
+  RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV1;
+  RCC_ClkInitStruct.APB3CLKDivider = RCC_APB3_DIV2;
+  RCC_ClkInitStruct.APB1CLKDivider = RCC_APB1_DIV2;
+  RCC_ClkInitStruct.APB2CLKDivider = RCC_APB2_DIV2;
+  RCC_ClkInitStruct.APB4CLKDivider = RCC_APB4_DIV2;
+
+  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)
+  {
+    Error_Handler();
+  }
+}
+
+/**
+  * @brief USART1 Initialization Function
+  * @param None
+  * @retval None
+  */
+static void MX_USART1_UART_Init(void)
+{
+
+  /* USER CODE BEGIN USART1_Init 0 */
+
+  /* USER CODE END USART1_Init 0 */
+
+  /* USER CODE BEGIN USART1_Init 1 */
+
+  /* USER CODE END USART1_Init 1 */
+  huart1.Instance = USART1;
+  huart1.Init.BaudRate = 115200;
+  huart1.Init.WordLength = UART_WORDLENGTH_8B;
+  huart1.Init.StopBits = UART_STOPBITS_1;
+  huart1.Init.Parity = UART_PARITY_NONE;
+  huart1.Init.Mode = UART_MODE_TX_RX;
+  huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
+  huart1.Init.OverSampling = UART_OVERSAMPLING_16;
+  huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
+  huart1.Init.ClockPrescaler = UART_PRESCALER_DIV1;
+  huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
+  if (HAL_UART_Init(&huart1) != HAL_OK)
+  {
+    Error_Handler();
+  }
+  if (HAL_UARTEx_SetTxFifoThreshold(&huart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK)
+  {
+    Error_Handler();
+  }
+  if (HAL_UARTEx_SetRxFifoThreshold(&huart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK)
+  {
+    Error_Handler();
+  }
+  if (HAL_UARTEx_DisableFifoMode(&huart1) != HAL_OK)
+  {
+    Error_Handler();
+  }
+  /* USER CODE BEGIN USART1_Init 2 */
+
+  /* USER CODE END USART1_Init 2 */
+
+}
+
+/**
+  * @brief USART2 Initialization Function
+  * @param None
+  * @retval None
+  */
+static void MX_USART2_UART_Init(void)
+{
+
+  /* USER CODE BEGIN USART2_Init 0 */
+
+  /* USER CODE END USART2_Init 0 */
+
+  /* USER CODE BEGIN USART2_Init 1 */
+
+  /* USER CODE END USART2_Init 1 */
+  huart2.Instance = USART2;
+  huart2.Init.BaudRate = 115200;
+  huart2.Init.WordLength = UART_WORDLENGTH_8B;
+  huart2.Init.StopBits = UART_STOPBITS_1;
+  huart2.Init.Parity = UART_PARITY_NONE;
+  huart2.Init.Mode = UART_MODE_TX_RX;
+  huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
+  huart2.Init.OverSampling = UART_OVERSAMPLING_16;
+  huart2.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
+  huart2.Init.ClockPrescaler = UART_PRESCALER_DIV1;
+  huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
+  if (HAL_UART_Init(&huart2) != HAL_OK)
+  {
+    Error_Handler();
+  }
+  if (HAL_UARTEx_SetTxFifoThreshold(&huart2, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK)
+  {
+    Error_Handler();
+  }
+  if (HAL_UARTEx_SetRxFifoThreshold(&huart2, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK)
+  {
+    Error_Handler();
+  }
+  if (HAL_UARTEx_DisableFifoMode(&huart2) != HAL_OK)
+  {
+    Error_Handler();
+  }
+  /* USER CODE BEGIN USART2_Init 2 */
+
+  /* USER CODE END USART2_Init 2 */
+
+}
+
+/**
+  * @brief GPIO Initialization Function
+  * @param None
+  * @retval None
+  */
+static void MX_GPIO_Init(void)
+{
+  GPIO_InitTypeDef GPIO_InitStruct = {0};
+/* USER CODE BEGIN MX_GPIO_Init_1 */
+/* USER CODE END MX_GPIO_Init_1 */
+
+  /* GPIO Ports Clock Enable */
+  __HAL_RCC_GPIOA_CLK_ENABLE();
+  __HAL_RCC_GPIOB_CLK_ENABLE();
+
+  /*Configure GPIO pin Output Level */
+  HAL_GPIO_WritePin(GPIOB, TARGET_IO0_Pin|TARGET_RESET_Pin, GPIO_PIN_RESET);
+
+  /*Configure GPIO pins : TARGET_IO0_Pin TARGET_RESET_Pin */
+  GPIO_InitStruct.Pin = TARGET_IO0_Pin|TARGET_RESET_Pin;
+  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
+  GPIO_InitStruct.Pull = GPIO_NOPULL;
+  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
+  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
+
+/* USER CODE BEGIN MX_GPIO_Init_2 */
+/* USER CODE END MX_GPIO_Init_2 */
+}
+
+/* USER CODE BEGIN 4 */
+
+/* USER CODE END 4 */
+
+/**
+  * @brief  This function is executed in case of error occurrence.
+  * @retval None
+  */
+void Error_Handler(void)
+{
+  /* USER CODE BEGIN Error_Handler_Debug */
+  /* User can add his own implementation to report the HAL error return state */
+  __disable_irq();
+  while (1)
+  {
+  }
+  /* USER CODE END Error_Handler_Debug */
+}
+
+#ifdef  USE_FULL_ASSERT
+/**
+  * @brief  Reports the name of the source file and the source line number
+  *         where the assert_param error has occurred.
+  * @param  file: pointer to the source file name
+  * @param  line: assert_param error line source number
+  * @retval None
+  */
+void assert_failed(uint8_t *file, uint32_t line)
+{
+  /* USER CODE BEGIN 6 */
+  /* User can add his own implementation to report the file name and line number,
+     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
+  /* USER CODE END 6 */
+}
+#endif /* USE_FULL_ASSERT */

+ 209 - 0
esp_flasher/lib/esp-serial-flasher/examples/stm32_example/Core/Src/stm32h7xx_hal_msp.c

@@ -0,0 +1,209 @@
+/* USER CODE BEGIN Header */
+/**
+  ******************************************************************************
+  * @file         stm32h7xx_hal_msp.c
+  * @brief        This file provides code for the MSP Initialization
+  *               and de-Initialization codes.
+  ******************************************************************************
+  * @attention
+  *
+  * Copyright (c) 2023 STMicroelectronics.
+  * All rights reserved.
+  *
+  * This software is licensed under terms that can be found in the LICENSE file
+  * in the root directory of this software component.
+  * If no LICENSE file comes with this software, it is provided AS-IS.
+  *
+  ******************************************************************************
+  */
+/* USER CODE END Header */
+
+/* Includes ------------------------------------------------------------------*/
+#include "main.h"
+
+/* USER CODE BEGIN Includes */
+
+/* USER CODE END Includes */
+
+/* Private typedef -----------------------------------------------------------*/
+/* USER CODE BEGIN TD */
+
+/* USER CODE END TD */
+
+/* Private define ------------------------------------------------------------*/
+/* USER CODE BEGIN Define */
+
+/* USER CODE END Define */
+
+/* Private macro -------------------------------------------------------------*/
+/* USER CODE BEGIN Macro */
+
+/* USER CODE END Macro */
+
+/* Private variables ---------------------------------------------------------*/
+/* USER CODE BEGIN PV */
+
+/* USER CODE END PV */
+
+/* Private function prototypes -----------------------------------------------*/
+/* USER CODE BEGIN PFP */
+
+/* USER CODE END PFP */
+
+/* External functions --------------------------------------------------------*/
+/* USER CODE BEGIN ExternalFunctions */
+
+/* USER CODE END ExternalFunctions */
+
+/* USER CODE BEGIN 0 */
+
+/* USER CODE END 0 */
+/**
+  * Initializes the Global MSP.
+  */
+void HAL_MspInit(void)
+{
+  /* USER CODE BEGIN MspInit 0 */
+
+  /* USER CODE END MspInit 0 */
+
+  __HAL_RCC_SYSCFG_CLK_ENABLE();
+
+  /* System interrupt init*/
+
+  /* USER CODE BEGIN MspInit 1 */
+
+  /* USER CODE END MspInit 1 */
+}
+
+/**
+* @brief UART MSP Initialization
+* This function configures the hardware resources used in this example
+* @param huart: UART handle pointer
+* @retval None
+*/
+void HAL_UART_MspInit(UART_HandleTypeDef* huart)
+{
+  GPIO_InitTypeDef GPIO_InitStruct = {0};
+  RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
+  if(huart->Instance==USART1)
+  {
+  /* USER CODE BEGIN USART1_MspInit 0 */
+
+  /* USER CODE END USART1_MspInit 0 */
+
+  /** Initializes the peripherals clock
+  */
+    PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USART1;
+    PeriphClkInitStruct.Usart16ClockSelection = RCC_USART16CLKSOURCE_D2PCLK2;
+    if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
+    {
+      Error_Handler();
+    }
+
+    /* Peripheral clock enable */
+    __HAL_RCC_USART1_CLK_ENABLE();
+
+    __HAL_RCC_GPIOB_CLK_ENABLE();
+    /**USART1 GPIO Configuration
+    PB14     ------> USART1_TX
+    PB15     ------> USART1_RX
+    */
+    GPIO_InitStruct.Pin = GPIO_PIN_14|GPIO_PIN_15;
+    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
+    GPIO_InitStruct.Pull = GPIO_NOPULL;
+    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
+    GPIO_InitStruct.Alternate = GPIO_AF4_USART1;
+    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
+
+  /* USER CODE BEGIN USART1_MspInit 1 */
+
+  /* USER CODE END USART1_MspInit 1 */
+  }
+  else if(huart->Instance==USART2)
+  {
+  /* USER CODE BEGIN USART2_MspInit 0 */
+
+  /* USER CODE END USART2_MspInit 0 */
+
+  /** Initializes the peripherals clock
+  */
+    PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USART2;
+    PeriphClkInitStruct.Usart234578ClockSelection = RCC_USART234578CLKSOURCE_D2PCLK1;
+    if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
+    {
+      Error_Handler();
+    }
+
+    /* Peripheral clock enable */
+    __HAL_RCC_USART2_CLK_ENABLE();
+
+    __HAL_RCC_GPIOA_CLK_ENABLE();
+    /**USART2 GPIO Configuration
+    PA2     ------> USART2_TX
+    PA3     ------> USART2_RX
+    */
+    GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_3;
+    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
+    GPIO_InitStruct.Pull = GPIO_NOPULL;
+    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
+    GPIO_InitStruct.Alternate = GPIO_AF7_USART2;
+    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
+
+  /* USER CODE BEGIN USART2_MspInit 1 */
+
+  /* USER CODE END USART2_MspInit 1 */
+  }
+
+}
+
+/**
+* @brief UART MSP De-Initialization
+* This function freeze the hardware resources used in this example
+* @param huart: UART handle pointer
+* @retval None
+*/
+void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
+{
+  if(huart->Instance==USART1)
+  {
+  /* USER CODE BEGIN USART1_MspDeInit 0 */
+
+  /* USER CODE END USART1_MspDeInit 0 */
+    /* Peripheral clock disable */
+    __HAL_RCC_USART1_CLK_DISABLE();
+
+    /**USART1 GPIO Configuration
+    PB14     ------> USART1_TX
+    PB15     ------> USART1_RX
+    */
+    HAL_GPIO_DeInit(GPIOB, GPIO_PIN_14|GPIO_PIN_15);
+
+  /* USER CODE BEGIN USART1_MspDeInit 1 */
+
+  /* USER CODE END USART1_MspDeInit 1 */
+  }
+  else if(huart->Instance==USART2)
+  {
+  /* USER CODE BEGIN USART2_MspDeInit 0 */
+
+  /* USER CODE END USART2_MspDeInit 0 */
+    /* Peripheral clock disable */
+    __HAL_RCC_USART2_CLK_DISABLE();
+
+    /**USART2 GPIO Configuration
+    PA2     ------> USART2_TX
+    PA3     ------> USART2_RX
+    */
+    HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2|GPIO_PIN_3);
+
+  /* USER CODE BEGIN USART2_MspDeInit 1 */
+
+  /* USER CODE END USART2_MspDeInit 1 */
+  }
+
+}
+
+/* USER CODE BEGIN 1 */
+
+/* USER CODE END 1 */

+ 203 - 0
esp_flasher/lib/esp-serial-flasher/examples/stm32_example/Core/Src/stm32h7xx_it.c

@@ -0,0 +1,203 @@
+/* USER CODE BEGIN Header */
+/**
+  ******************************************************************************
+  * @file    stm32h7xx_it.c
+  * @brief   Interrupt Service Routines.
+  ******************************************************************************
+  * @attention
+  *
+  * Copyright (c) 2023 STMicroelectronics.
+  * All rights reserved.
+  *
+  * This software is licensed under terms that can be found in the LICENSE file
+  * in the root directory of this software component.
+  * If no LICENSE file comes with this software, it is provided AS-IS.
+  *
+  ******************************************************************************
+  */
+/* USER CODE END Header */
+
+/* Includes ------------------------------------------------------------------*/
+#include "main.h"
+#include "stm32h7xx_it.h"
+/* Private includes ----------------------------------------------------------*/
+/* USER CODE BEGIN Includes */
+/* USER CODE END Includes */
+
+/* Private typedef -----------------------------------------------------------*/
+/* USER CODE BEGIN TD */
+
+/* USER CODE END TD */
+
+/* Private define ------------------------------------------------------------*/
+/* USER CODE BEGIN PD */
+
+/* USER CODE END PD */
+
+/* Private macro -------------------------------------------------------------*/
+/* USER CODE BEGIN PM */
+
+/* USER CODE END PM */
+
+/* Private variables ---------------------------------------------------------*/
+/* USER CODE BEGIN PV */
+
+/* USER CODE END PV */
+
+/* Private function prototypes -----------------------------------------------*/
+/* USER CODE BEGIN PFP */
+
+/* USER CODE END PFP */
+
+/* Private user code ---------------------------------------------------------*/
+/* USER CODE BEGIN 0 */
+
+/* USER CODE END 0 */
+
+/* External variables --------------------------------------------------------*/
+
+/* USER CODE BEGIN EV */
+
+/* USER CODE END EV */
+
+/******************************************************************************/
+/*           Cortex Processor Interruption and Exception Handlers          */
+/******************************************************************************/
+/**
+  * @brief This function handles Non maskable interrupt.
+  */
+void NMI_Handler(void)
+{
+  /* USER CODE BEGIN NonMaskableInt_IRQn 0 */
+
+  /* USER CODE END NonMaskableInt_IRQn 0 */
+  /* USER CODE BEGIN NonMaskableInt_IRQn 1 */
+  while (1)
+  {
+  }
+  /* USER CODE END NonMaskableInt_IRQn 1 */
+}
+
+/**
+  * @brief This function handles Hard fault interrupt.
+  */
+void HardFault_Handler(void)
+{
+  /* USER CODE BEGIN HardFault_IRQn 0 */
+
+  /* USER CODE END HardFault_IRQn 0 */
+  while (1)
+  {
+    /* USER CODE BEGIN W1_HardFault_IRQn 0 */
+    /* USER CODE END W1_HardFault_IRQn 0 */
+  }
+}
+
+/**
+  * @brief This function handles Memory management fault.
+  */
+void MemManage_Handler(void)
+{
+  /* USER CODE BEGIN MemoryManagement_IRQn 0 */
+
+  /* USER CODE END MemoryManagement_IRQn 0 */
+  while (1)
+  {
+    /* USER CODE BEGIN W1_MemoryManagement_IRQn 0 */
+    /* USER CODE END W1_MemoryManagement_IRQn 0 */
+  }
+}
+
+/**
+  * @brief This function handles Pre-fetch fault, memory access fault.
+  */
+void BusFault_Handler(void)
+{
+  /* USER CODE BEGIN BusFault_IRQn 0 */
+
+  /* USER CODE END BusFault_IRQn 0 */
+  while (1)
+  {
+    /* USER CODE BEGIN W1_BusFault_IRQn 0 */
+    /* USER CODE END W1_BusFault_IRQn 0 */
+  }
+}
+
+/**
+  * @brief This function handles Undefined instruction or illegal state.
+  */
+void UsageFault_Handler(void)
+{
+  /* USER CODE BEGIN UsageFault_IRQn 0 */
+
+  /* USER CODE END UsageFault_IRQn 0 */
+  while (1)
+  {
+    /* USER CODE BEGIN W1_UsageFault_IRQn 0 */
+    /* USER CODE END W1_UsageFault_IRQn 0 */
+  }
+}
+
+/**
+  * @brief This function handles System service call via SWI instruction.
+  */
+void SVC_Handler(void)
+{
+  /* USER CODE BEGIN SVCall_IRQn 0 */
+
+  /* USER CODE END SVCall_IRQn 0 */
+  /* USER CODE BEGIN SVCall_IRQn 1 */
+
+  /* USER CODE END SVCall_IRQn 1 */
+}
+
+/**
+  * @brief This function handles Debug monitor.
+  */
+void DebugMon_Handler(void)
+{
+  /* USER CODE BEGIN DebugMonitor_IRQn 0 */
+
+  /* USER CODE END DebugMonitor_IRQn 0 */
+  /* USER CODE BEGIN DebugMonitor_IRQn 1 */
+
+  /* USER CODE END DebugMonitor_IRQn 1 */
+}
+
+/**
+  * @brief This function handles Pendable request for system service.
+  */
+void PendSV_Handler(void)
+{
+  /* USER CODE BEGIN PendSV_IRQn 0 */
+
+  /* USER CODE END PendSV_IRQn 0 */
+  /* USER CODE BEGIN PendSV_IRQn 1 */
+
+  /* USER CODE END PendSV_IRQn 1 */
+}
+
+/**
+  * @brief This function handles System tick timer.
+  */
+void SysTick_Handler(void)
+{
+  /* USER CODE BEGIN SysTick_IRQn 0 */
+
+  /* USER CODE END SysTick_IRQn 0 */
+  HAL_IncTick();
+  /* USER CODE BEGIN SysTick_IRQn 1 */
+
+  /* USER CODE END SysTick_IRQn 1 */
+}
+
+/******************************************************************************/
+/* STM32H7xx Peripheral Interrupt Handlers                                    */
+/* Add here the Interrupt Handlers for the used peripherals.                  */
+/* For the available peripheral interrupt handler names,                      */
+/* please refer to the startup file (startup_stm32h7xx.s).                    */
+/******************************************************************************/
+
+/* USER CODE BEGIN 1 */
+
+/* USER CODE END 1 */

+ 52 - 0
esp_flasher/lib/esp-serial-flasher/examples/stm32_example/README.md

@@ -0,0 +1,52 @@
+# STM32 example
+
+## Overview
+
+Example demonstrates how to flash ESP32 from another STM32 (host MCU) using esp_serial_flash component API. WeActStudio [MiniSTM32H7xx](https://github.com/WeActStudio/MiniSTM32H7xx) board is used in this example, as STM32H743VIT has FLASH memory large enough to fit all the example binaries to be flashed from host MCU to ESP32 which can be found in `binaries` directory and converted into C-arrays during build process. USART1 is dedicated for communication with ESP32, whereas, USART2 can be used for debug purposes by attaching UART-to-USB bridge.
+
+Following steps are performed in order to re-program target's memory:
+
+1. Peripherals are initialized.
+2. Host puts slave device into boot mode tries to connect by calling `esp_loader_connect()`.
+3. Then `esp_loader_flash_start()` is called to enter flashing mode and erase amount of memory to be flashed.
+4. `esp_loader_flash_write()` function is called repeatedly until the whole binary image is transfered.
+
+Note: In addition, to steps mentioned above, `esp_loader_change_transmission_rate`  is called after connection is established in order to increase flashing speed. Bootloader is also capable of detecting baud rate during connection phase, and can be changed before calling `esp_loader_connect`. However, it is recommended to start at lower speed and then use dedicated command to increase baud rate. This does not apply for ESP8266, as its bootloader does not support this command, therefore, baud rate can only be changed before connection phase in this case.
+
+## Hardware Required
+
+* WeActStudio [MiniSTM32H7xx](https://github.com/WeActStudio/MiniSTM32H7xx) board with the STM32H743VIT chip
+* A development board with ESP32 SoC (e.g. ESP-WROVER-KIT, ESP32-DevKitC, etc.).
+* One or two USB cables for power supply and programming.
+
+## Hardware connection
+
+Table below shows connection between STM32 and ESP32.
+
+| STM32 (host) | ESP32 (slave) |
+|:------------:|:-------------:|
+|    PB12      |      IO0      |
+|    PB13      |      RST      |
+|    PB14      |      RX0      |
+|    PB15      |      TX0      |
+
+Optionally, UART-to-USB bridge can be connected to PA3(RX) and PA2(TX) for debug purposes.
+
+## Build and flash
+
+To compile the example:
+
+Create and navigate to `build` directory:
+```
+mkdir build && cd build
+```
+Run cmake (with appropriate parameters) and build: 
+```
+cmake -DSTM32_TOOLCHAIN_PATH="path_to_toolchain" -DSTM32_CUBE_H7_PATH="path_to_cube_libraries" .. && cmake --build .
+```
+
+Binaries to be flashed are placed in separate folder (binaries.c) for each possible target and converted to C-array. Flash integrity verification is enabled by default.
+
+For more details regarding to esp_serial_flasher configuration and STM32 support, please refer to top level [README.md](../../README.md).
+
+> Note: CMake 3.16 or later is required.

+ 192 - 0
esp_flasher/lib/esp-serial-flasher/examples/stm32_example/stm32_flasher.ioc

@@ -0,0 +1,192 @@
+#MicroXplorer Configuration settings - do not modify
+CAD.formats=[]
+CAD.pinconfig=Project naming
+CAD.provider=
+CORTEX_M7.CPU_DCache=Disabled
+CORTEX_M7.CPU_ICache=Disabled
+CORTEX_M7.IPParameters=CPU_ICache,CPU_DCache,default_mode_Activation
+CORTEX_M7.default_mode_Activation=0
+File.Version=6
+GPIO.groupedBy=Group By Peripherals
+KeepUserPlacement=false
+Mcu.CPN=STM32H743VIT6
+Mcu.Family=STM32H7
+Mcu.IP0=CORTEX_M7
+Mcu.IP1=DEBUG
+Mcu.IP2=NVIC
+Mcu.IP3=RCC
+Mcu.IP4=SYS
+Mcu.IP5=USART1
+Mcu.IP6=USART2
+Mcu.IPNb=7
+Mcu.Name=STM32H743VITx
+Mcu.Package=LQFP100
+Mcu.Pin0=PA2
+Mcu.Pin1=PA3
+Mcu.Pin2=PB12
+Mcu.Pin3=PB13
+Mcu.Pin4=PB14
+Mcu.Pin5=PB15
+Mcu.Pin6=PA13 (JTMS/SWDIO)
+Mcu.Pin7=PA14 (JTCK/SWCLK)
+Mcu.Pin8=VP_SYS_VS_Systick
+Mcu.PinsNb=9
+Mcu.ThirdPartyNb=0
+Mcu.UserConstants=
+Mcu.UserName=STM32H743VITx
+MxCube.Version=6.9.2
+MxDb.Version=DB.6.0.92
+NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
+NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
+NVIC.ForceEnableDMAVector=true
+NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
+NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
+NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
+NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
+NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4
+NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
+NVIC.SysTick_IRQn=true\:15\:0\:false\:false\:true\:false\:true\:false
+NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
+PA13\ (JTMS/SWDIO).Mode=Serial_Wire
+PA13\ (JTMS/SWDIO).Signal=DEBUG_JTMS-SWDIO
+PA14\ (JTCK/SWCLK).Mode=Serial_Wire
+PA14\ (JTCK/SWCLK).Signal=DEBUG_JTCK-SWCLK
+PA2.Mode=Asynchronous
+PA2.Signal=USART2_TX
+PA3.Mode=Asynchronous
+PA3.Signal=USART2_RX
+PB12.GPIOParameters=GPIO_Label
+PB12.GPIO_Label=TARGET_IO0
+PB12.Locked=true
+PB12.Signal=GPIO_Output
+PB13.GPIOParameters=GPIO_Label
+PB13.GPIO_Label=TARGET_RESET
+PB13.Locked=true
+PB13.Signal=GPIO_Output
+PB14.Mode=Asynchronous
+PB14.Signal=USART1_TX
+PB15.Mode=Asynchronous
+PB15.Signal=USART1_RX
+PinOutPanel.RotationAngle=0
+ProjectManager.AskForMigrate=true
+ProjectManager.BackupPrevious=false
+ProjectManager.CompilerOptimize=6
+ProjectManager.ComputerToolchain=false
+ProjectManager.CoupleFile=false
+ProjectManager.CustomerFirmwarePackage=
+ProjectManager.DefaultFWLocation=true
+ProjectManager.DeletePrevious=true
+ProjectManager.DeviceId=STM32H743VITx
+ProjectManager.FirmwarePackage=STM32Cube FW_H7 V1.11.1
+ProjectManager.FreePins=false
+ProjectManager.HalAssertFull=true
+ProjectManager.HeapSize=0x000
+ProjectManager.KeepUserCode=true
+ProjectManager.LastFirmware=true
+ProjectManager.LibraryCopy=1
+ProjectManager.MainLocation=Core/Src
+ProjectManager.NoMain=false
+ProjectManager.PreviousToolchain=
+ProjectManager.ProjectBuild=false
+ProjectManager.ProjectFileName=stm32_flasher.ioc
+ProjectManager.ProjectName=stm32_flasher
+ProjectManager.ProjectStructure=
+ProjectManager.RegisterCallBack=
+ProjectManager.StackSize=0x400
+ProjectManager.TargetToolchain=Makefile
+ProjectManager.ToolChainLocation=
+ProjectManager.UAScriptAfterPath=
+ProjectManager.UAScriptBeforePath=
+ProjectManager.UnderRoot=false
+ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL-true,2-SystemClock_Config-RCC-false-HAL-false,3-MX_USART1_UART_Init-USART1-false-HAL-true,4-MX_USART2_UART_Init-USART2-false-HAL-true,0-MX_CORTEX_M7_Init-CORTEX_M7-false-HAL-true
+RCC.ADCFreq_Value=129000000
+RCC.AHB12Freq_Value=120000000
+RCC.AHB4Freq_Value=120000000
+RCC.APB1Freq_Value=60000000
+RCC.APB2Freq_Value=60000000
+RCC.APB3Freq_Value=60000000
+RCC.APB4Freq_Value=60000000
+RCC.AXIClockFreq_Value=120000000
+RCC.CECFreq_Value=32000
+RCC.CKPERFreq_Value=64000000
+RCC.CortexFreq_Value=120000000
+RCC.CpuClockFreq_Value=120000000
+RCC.D1CPREFreq_Value=120000000
+RCC.D1PPRE=RCC_APB3_DIV2
+RCC.D2PPRE1=RCC_APB1_DIV2
+RCC.D2PPRE2=RCC_APB2_DIV2
+RCC.D3PPRE=RCC_APB4_DIV2
+RCC.DFSDMACLkFreq_Value=120000000
+RCC.DFSDMFreq_Value=60000000
+RCC.DIVM1=4
+RCC.DIVN1=15
+RCC.DIVP1Freq_Value=120000000
+RCC.DIVP2Freq_Value=129000000
+RCC.DIVP3Freq_Value=129000000
+RCC.DIVQ1Freq_Value=120000000
+RCC.DIVQ2Freq_Value=129000000
+RCC.DIVQ3Freq_Value=129000000
+RCC.DIVR1Freq_Value=120000000
+RCC.DIVR2Freq_Value=129000000
+RCC.DIVR3Freq_Value=129000000
+RCC.FDCANFreq_Value=120000000
+RCC.FMCFreq_Value=120000000
+RCC.FamilyName=M
+RCC.HCLK3ClockFreq_Value=120000000
+RCC.HCLKFreq_Value=120000000
+RCC.HRTIMFreq_Value=120000000
+RCC.HSE_VALUE=25000000
+RCC.I2C123Freq_Value=60000000
+RCC.I2C4Freq_Value=60000000
+RCC.IPParameters=ADCFreq_Value,AHB12Freq_Value,AHB4Freq_Value,APB1Freq_Value,APB2Freq_Value,APB3Freq_Value,APB4Freq_Value,AXIClockFreq_Value,CECFreq_Value,CKPERFreq_Value,CortexFreq_Value,CpuClockFreq_Value,D1CPREFreq_Value,D1PPRE,D2PPRE1,D2PPRE2,D3PPRE,DFSDMACLkFreq_Value,DFSDMFreq_Value,DIVM1,DIVN1,DIVP1Freq_Value,DIVP2Freq_Value,DIVP3Freq_Value,DIVQ1Freq_Value,DIVQ2Freq_Value,DIVQ3Freq_Value,DIVR1Freq_Value,DIVR2Freq_Value,DIVR3Freq_Value,FDCANFreq_Value,FMCFreq_Value,FamilyName,HCLK3ClockFreq_Value,HCLKFreq_Value,HRTIMFreq_Value,HSE_VALUE,I2C123Freq_Value,I2C4Freq_Value,LPTIM1Freq_Value,LPTIM2Freq_Value,LPTIM345Freq_Value,LPUART1Freq_Value,LTDCFreq_Value,MCO1PinFreq_Value,MCO2PinFreq_Value,PLL2FRACN,PLL3FRACN,PLLFRACN,PWR_Regulator_Voltage_Scale,QSPIFreq_Value,RNGFreq_Value,RTCFreq_Value,SAI1Freq_Value,SAI23Freq_Value,SAI4AFreq_Value,SAI4BFreq_Value,SDMMCFreq_Value,SPDIFRXFreq_Value,SPI123Freq_Value,SPI45Freq_Value,SPI6Freq_Value,SWPMI1Freq_Value,SYSCLKFreq_VALUE,SYSCLKSource,Tim1OutputFreq_Value,Tim2OutputFreq_Value,TraceFreq_Value,USART16Freq_Value,USART234578Freq_Value,USBFreq_Value,VCO1OutputFreq_Value,VCO2OutputFreq_Value,VCO3OutputFreq_Value,VCOInput1Freq_Value,VCOInput2Freq_Value,VCOInput3Freq_Value
+RCC.LPTIM1Freq_Value=60000000
+RCC.LPTIM2Freq_Value=60000000
+RCC.LPTIM345Freq_Value=60000000
+RCC.LPUART1Freq_Value=60000000
+RCC.LTDCFreq_Value=129000000
+RCC.MCO1PinFreq_Value=64000000
+RCC.MCO2PinFreq_Value=120000000
+RCC.PLL2FRACN=0
+RCC.PLL3FRACN=0
+RCC.PLLFRACN=0
+RCC.PWR_Regulator_Voltage_Scale=PWR_REGULATOR_VOLTAGE_SCALE1
+RCC.QSPIFreq_Value=120000000
+RCC.RNGFreq_Value=48000000
+RCC.RTCFreq_Value=32000
+RCC.SAI1Freq_Value=120000000
+RCC.SAI23Freq_Value=120000000
+RCC.SAI4AFreq_Value=120000000
+RCC.SAI4BFreq_Value=120000000
+RCC.SDMMCFreq_Value=120000000
+RCC.SPDIFRXFreq_Value=120000000
+RCC.SPI123Freq_Value=120000000
+RCC.SPI45Freq_Value=60000000
+RCC.SPI6Freq_Value=60000000
+RCC.SWPMI1Freq_Value=60000000
+RCC.SYSCLKFreq_VALUE=120000000
+RCC.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK
+RCC.Tim1OutputFreq_Value=120000000
+RCC.Tim2OutputFreq_Value=120000000
+RCC.TraceFreq_Value=120000000
+RCC.USART16Freq_Value=60000000
+RCC.USART234578Freq_Value=60000000
+RCC.USBFreq_Value=120000000
+RCC.VCO1OutputFreq_Value=240000000
+RCC.VCO2OutputFreq_Value=258000000
+RCC.VCO3OutputFreq_Value=258000000
+RCC.VCOInput1Freq_Value=16000000
+RCC.VCOInput2Freq_Value=2000000
+RCC.VCOInput3Freq_Value=2000000
+USART1.FIFOMode=FIFOMODE_DISABLE
+USART1.IPParameters=VirtualMode-Asynchronous,TXFIFOThreshold,RXFIFOThreshold,FIFOMode
+USART1.RXFIFOThreshold=RXFIFO_THRESHOLD_1EIGHTHFULL
+USART1.TXFIFOThreshold=TXFIFO_THRESHOLD_1EIGHTHFULL
+USART1.VirtualMode-Asynchronous=VM_ASYNC
+USART2.IPParameters=VirtualMode-Asynchronous,TXFIFOThreshold,RXFIFOThreshold,OneBitSampling
+USART2.OneBitSampling=UART_ONE_BIT_SAMPLE_DISABLE
+USART2.RXFIFOThreshold=RXFIFO_THRESHOLD_1EIGHTHFULL
+USART2.TXFIFOThreshold=TXFIFO_THRESHOLD_1EIGHTHFULL
+USART2.VirtualMode-Asynchronous=VM_ASYNC
+VP_SYS_VS_Systick.Mode=SysTick
+VP_SYS_VS_Systick.Signal=SYS_VS_Systick
+board=custom

+ 27 - 0
esp_flasher/lib/esp-serial-flasher/examples/zephyr_example/CMakeLists.txt

@@ -0,0 +1,27 @@
+# SPDX-License-Identifier: Apache-2.0
+
+cmake_minimum_required(VERSION 3.20.0)
+
+find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
+project(zephyr_flasher)
+
+zephyr_compile_definitions_ifdef(CONFIG_SERIAL_FLASHER_MD5_ENABLED MD5_ENABLED)
+
+zephyr_library_sources(
+  ../common/example_common.c
+  )
+
+zephyr_library_include_directories(
+  ../common
+  ../binaries
+  )
+
+# Needed for example_common
+add_compile_definitions(SERIAL_FLASHER_INTERFACE_UART)
+
+# Embed binaries into the app.
+include(${CMAKE_CURRENT_LIST_DIR}/../common/bin2array.cmake)
+create_resources(${CMAKE_CURRENT_LIST_DIR}/../binaries/Hello-world ${CMAKE_BINARY_DIR}/binaries.c)
+set_property(SOURCE ${CMAKE_BINARY_DIR}/binaries.c PROPERTY GENERATED 1)
+
+target_sources(app PRIVATE src/main.c  ${CMAKE_BINARY_DIR}/binaries.c)

+ 86 - 0
esp_flasher/lib/esp-serial-flasher/examples/zephyr_example/README.md

@@ -0,0 +1,86 @@
+# ESP32 Zephyr example
+
+## Overview
+
+This sample code demonstrates how to flash an Espressif SoC from another (host) MCU using
+esp_serial_flash component API. In this case, the ESP32 is used as host MCU.
+Binaries to be flashed from host MCU to another Espressif SoC can be found in `binaries` folder
+and are converted into C-array during build process.
+
+Following steps are performed in order to re-program target's memory:
+
+1. Peripherals are initialized (GPIO for BOOT and EN pins and UART).
+2. UART1 (can be changed) through which new binary will be transfered is initialized.
+3. Host puts target device into boot mode tries to connect by calling `esp_loader_connect()`.
+4. Binary file is opened and its size is acquired, as it has to be known before flashing.
+5. Then `esp_loader_flash_start()` is called to enter flashing mode and erase amount of memory to be flashed.
+6. `esp_loader_flash_write()` function is called repeatedly until the whole binary image is transfered.
+
+Note: In addition, to steps mentioned above, `esp_loader_change_transmission_rate`  is called after connection
+is established in order to increase flashing speed. This does not apply for ESP8266, as its bootloader
+does not support this command. However, ESP8266 is capable of detecting baud rate during connection
+phase, and can be changed before calling `esp_loader_connect`, if necessary.
+
+## Hardware Required
+
+* Any supported Espressif SoC board for the target
+* An ESP32-DevKitC board for the host
+* One or two USB cables for power supply and programming.
+
+## Hardware connection
+
+Table below shows connection between the two devices:
+
+| ESP32 (host) | Espressif SoC (target) |
+|:------------:|:----------------------:|
+|    IO4       |           IO0          |
+|    IO2       |          RESET         |
+|    IO9       |           TX0          |
+|    IO10      |           RX0          |
+
+## Build and flash
+
+To run the example, type the following commands:
+
+```c
+west init
+west update
+west build -p -b <supported board>
+west flash
+west espressif monitor
+```
+>**Note:** You can find the supported boards in the boards folder.
+
+(To exit the serial monitor, type ``ctrl-c``.)
+
+For more information, check [Zephyr's Getting Started](https://docs.zephyrproject.org/latest/develop/getting_started/index.html)
+
+## Configuration
+
+For details about available configuration option, please refer to top level [README.md](../../README.md).
+Compile definitions can be specified in `prj.conf` file.
+
+Binaries to be flashed are placed in separate folder (binaries.c) for each possible target and converted to C-array. Without explicitly enabling MD5 check, flash integrity verification is disabled by default.
+
+## Example output
+
+Here is the example's console output:
+
+```
+*** Booting Zephyr OS build zephyr-v3.2.0-3548-ga1bb9c9d1736 ***
+Running ESP Flasher from Zephyr
+Connected to target
+Baudrate changed
+Erasing flash (this may take a while)...
+Start programming
+Progress: 100 %
+Finished programming
+Erasing flash (this may take a while)...
+Start programming
+Progress: 100 %
+Finished programming
+Erasing flash (this may take a while)...
+Start programming
+Progress: 100 %
+Finished programming
+```

+ 34 - 0
esp_flasher/lib/esp-serial-flasher/examples/zephyr_example/boards/esp32_devkitc_wroom.overlay

@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2022 Espressif Systems (Shanghai) Co., Ltd.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+#include <zephyr/dt-bindings/pinctrl/esp-pinctrl-common.h>
+#include <dt-bindings/pinctrl/esp32-pinctrl.h>
+#include <zephyr/dt-bindings/pinctrl/esp32-gpio-sigmap.h>
+
+/ {
+	aliases {
+		en = &en_button;
+		boot = &boot_button;
+		uart = &uart1;
+	};
+
+	gpio_keys {
+		compatible = "gpio-keys";
+		en_button: en_button {
+			gpios = <&gpio0 2 (GPIO_PULL_UP | GPIO_ACTIVE_HIGH)>;
+		};
+		boot_button: boot_button {
+			gpios = <&gpio0 4 (GPIO_PULL_UP | GPIO_ACTIVE_HIGH)>;
+		};
+	};
+};
+
+&uart1 {
+	status = "okay";
+	current-speed = <115200>;
+	pinctrl-0 = <&uart1_default>;
+	pinctrl-names = "default";
+};

+ 34 - 0
esp_flasher/lib/esp-serial-flasher/examples/zephyr_example/boards/esp32_devkitc_wrover.overlay

@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2022 Espressif Systems (Shanghai) Co., Ltd.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+#include <zephyr/dt-bindings/pinctrl/esp-pinctrl-common.h>
+#include <dt-bindings/pinctrl/esp32-pinctrl.h>
+#include <zephyr/dt-bindings/pinctrl/esp32-gpio-sigmap.h>
+
+/ {
+	aliases {
+		en = &en_button;
+		boot = &boot_button;
+		uart = &uart1;
+	};
+
+	gpio_keys {
+		compatible = "gpio-keys";
+		en_button: en_button {
+			gpios = <&gpio0 2 (GPIO_PULL_UP | GPIO_ACTIVE_HIGH)>;
+		};
+		boot_button: boot_button {
+			gpios = <&gpio0 4 (GPIO_PULL_UP | GPIO_ACTIVE_HIGH)>;
+		};
+	};
+};
+
+&uart1 {
+	status = "okay";
+	current-speed = <115200>;
+	pinctrl-0 = <&uart1_default>;
+	pinctrl-names = "default";
+};

+ 4 - 0
esp_flasher/lib/esp-serial-flasher/examples/zephyr_example/prj.conf

@@ -0,0 +1,4 @@
+# nothing here
+CONFIG_CONSOLE=y
+CONFIG_CONSOLE_GETCHAR=y
+CONFIG_NEWLIB_LIBC=y

+ 9 - 0
esp_flasher/lib/esp-serial-flasher/examples/zephyr_example/sample.yaml

@@ -0,0 +1,9 @@
+sample:
+  description: ESP Serial Flasher sample code
+  name: zephyr_flasher
+tests:
+  sample.esp_flasher.zephyr_example:
+    platform_allow:
+      - esp32_devkitc_wroom
+      - esp32_devkitc_wrover
+    tags: esp32

+ 81 - 0
esp_flasher/lib/esp-serial-flasher/examples/zephyr_example/src/main.c

@@ -0,0 +1,81 @@
+/*
+ * ESP Flasher Library Example for Zephyr
+ * Written in 2022 by KT-Elektronik, Klaucke und Partner GmbH
+ * This example code is in the Public Domain (or CC0 licensed, at your option.)
+ * Unless required by applicable law or agreed to in writing, this
+ * software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
+ * CONDITIONS OF ANY KIND, either express or implied.
+ *
+ * Copyright (c) 2023 Espressif Systems (Shanghai) Co., Ltd.
+ */
+
+#include <zephyr/kernel.h>
+#include <zephyr/device.h>
+#include <zephyr/devicetree.h>
+#include <zephyr/drivers/gpio.h>
+#include <zephyr/sys/util.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <zephyr_port.h>
+#include <esp_loader.h>
+#include "example_common.h"
+
+#define HIGHER_BAUDRATE 230400
+#define DEFAULT_BAUDRATE 115200
+
+/* Get UART DTS entry used as flash interface */
+static const struct device *esp_uart_dev = DEVICE_DT_GET(DT_ALIAS(uart));
+/* Get GPIO pin connected to the ESP's enable pin. */
+static const struct gpio_dt_spec esp_enable_spec = GPIO_DT_SPEC_GET(DT_ALIAS(en), gpios);
+/* Get GPIO pin  connected to the ESP's boot pin. */
+static const struct gpio_dt_spec esp_boot_spec = GPIO_DT_SPEC_GET(DT_ALIAS(boot), gpios);
+
+int main(void)
+{
+	example_binaries_t bin;
+
+	const loader_zephyr_config_t config = {
+		.uart_dev = esp_uart_dev,
+		.enable_spec = esp_enable_spec,
+		.boot_spec = esp_boot_spec
+	};
+
+	printk("Running ESP Flasher from Zephyr\r\n");
+
+	if (!device_is_ready(esp_uart_dev)) {
+		printk("ESP UART not ready");
+		return;
+	}
+
+	if (!device_is_ready(esp_boot_spec.port)) {
+		printk("ESP boot GPIO not ready");
+		return;
+	}
+
+	if (!device_is_ready(esp_enable_spec.port)) {
+		printk("Bluetooth Enable GPIO not ready");
+		return;
+	}
+
+	gpio_pin_configure_dt(&esp_boot_spec, GPIO_OUTPUT_ACTIVE);
+	gpio_pin_configure_dt(&esp_enable_spec, GPIO_OUTPUT_INACTIVE);
+
+	if (loader_port_zephyr_init(&config) != ESP_LOADER_SUCCESS) {
+		printk("ESP loader init failed");
+		return;
+	}
+
+	if (connect_to_target(HIGHER_BAUDRATE) == ESP_LOADER_SUCCESS) {
+
+		get_example_binaries(esp_loader_get_target(), &bin);
+
+		flash_binary(bin.boot.data, bin.boot.size, bin.boot.addr);
+		flash_binary(bin.part.data, bin.part.size, bin.part.addr);
+		flash_binary(bin.app.data,  bin.app.size,  bin.app.addr);
+	}
+
+	esp_loader_reset_target();
+
+	return 0;
+}

+ 3 - 0
esp_flasher/lib/esp-serial-flasher/idf_component.yml

@@ -0,0 +1,3 @@
+version: "0.5.0"
+description: Serial flasher component provides portable library for flashing or loading ram loadble app to Espressif SoCs from other host microcontroller
+url: https://github.com/espressif/esp-serial-flasher

+ 299 - 0
esp_flasher/lib/esp-serial-flasher/include/esp_loader.h

@@ -0,0 +1,299 @@
+/* Copyright 2020-2023 Espressif Systems (Shanghai) CO LTD
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <stdint.h>
+#include <stdbool.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Used for backwards compatibility with the previous API */
+#define esp_loader_change_baudrate esp_loader_change_transmission_rate
+
+/**
+ * Macro which can be used to check the error code,
+ * and return in case the code is not ESP_LOADER_SUCCESS.
+ */
+#define RETURN_ON_ERROR(x) do {         \
+    esp_loader_error_t _err_ = (x);     \
+    if (_err_ != ESP_LOADER_SUCCESS) {  \
+        return _err_;                   \
+    }                                   \
+} while(0)
+
+/**
+ * @brief Error codes
+ */
+typedef enum {
+    ESP_LOADER_SUCCESS,                /*!< Success */
+    ESP_LOADER_ERROR_FAIL,             /*!< Unspecified error */
+    ESP_LOADER_ERROR_TIMEOUT,          /*!< Timeout elapsed */
+    ESP_LOADER_ERROR_IMAGE_SIZE,       /*!< Image size to flash is larger than flash size */
+    ESP_LOADER_ERROR_INVALID_MD5,      /*!< Computed and received MD5 does not match */
+    ESP_LOADER_ERROR_INVALID_PARAM,    /*!< Invalid parameter passed to function */
+    ESP_LOADER_ERROR_INVALID_TARGET,   /*!< Connected target is invalid */
+    ESP_LOADER_ERROR_UNSUPPORTED_CHIP, /*!< Attached chip is not supported */
+    ESP_LOADER_ERROR_UNSUPPORTED_FUNC, /*!< Function is not supported on attached target */
+    ESP_LOADER_ERROR_INVALID_RESPONSE  /*!< Internal error */
+} esp_loader_error_t;
+
+/**
+ * @brief Supported targets
+ */
+typedef enum {
+    ESP8266_CHIP = 0,
+    ESP32_CHIP   = 1,
+    ESP32S2_CHIP = 2,
+    ESP32C3_CHIP = 3,
+    ESP32S3_CHIP = 4,
+    ESP32C2_CHIP = 5,
+    ESP32H4_CHIP = 6,
+    ESP32H2_CHIP = 7,
+    ESP32C6_CHIP = 8,
+    ESP_MAX_CHIP = 9,
+    ESP_UNKNOWN_CHIP = 9
+} target_chip_t;
+
+/**
+ * @brief Application binary header
+ */
+typedef struct {
+  uint8_t magic;
+  uint8_t segments;
+  uint8_t flash_mode;
+  uint8_t flash_size_freq;
+  uint32_t entrypoint;
+} esp_loader_bin_header_t;
+
+/**
+ * @brief Segment binary header
+ */
+typedef struct {
+    uint32_t addr;
+    uint32_t size;
+    uint8_t *data;
+} esp_loader_bin_segment_t;
+
+/**
+ * @brief Connection arguments
+ */
+typedef struct {
+    uint32_t sync_timeout;  /*!< Maximum time to wait for response from serial interface. */
+    int32_t trials;         /*!< Number of trials to connect to target. If greater than 1,
+                               100 millisecond delay is inserted after each try. */
+} esp_loader_connect_args_t;
+
+#define ESP_LOADER_CONNECT_DEFAULT() { \
+  .sync_timeout = 100, \
+  .trials = 10, \
+}
+
+/**
+  * @brief Connects to the target
+  *
+  * @param connect_args[in] Timing parameters to be used for connecting to target.
+  *
+  * @return
+  *     - ESP_LOADER_SUCCESS Success
+  *     - ESP_LOADER_ERROR_TIMEOUT Timeout
+  *     - ESP_LOADER_ERROR_INVALID_RESPONSE Internal error
+  */
+esp_loader_error_t esp_loader_connect(esp_loader_connect_args_t *connect_args);
+
+/**
+  * @brief   Returns attached target chip.
+  *
+  * @warning This function can only be called after connection with target
+  *          has been successfully established by calling esp_loader_connect().
+  *
+  * @return  One of target_chip_t
+  */
+target_chip_t esp_loader_get_target(void);
+
+
+#ifdef SERIAL_FLASHER_INTERFACE_UART
+/**
+  * @brief Initiates flash operation
+  *
+  * @param offset[in]       Address from which flash operation will be performed.
+  * @param image_size[in]   Size of the whole binary to be loaded into flash.
+  * @param block_size[in]   Size of buffer used in subsequent calls to esp_loader_flash_write.
+  *
+  * @note  image_size is size of the whole image, whereas, block_size is chunk of data sent
+  *        to the target, each time esp_loader_flash_write function is called.
+  *
+  * @return
+  *     - ESP_LOADER_SUCCESS Success
+  *     - ESP_LOADER_ERROR_TIMEOUT Timeout
+  *     - ESP_LOADER_ERROR_INVALID_RESPONSE Internal error
+  */
+esp_loader_error_t esp_loader_flash_start(uint32_t offset, uint32_t image_size, uint32_t block_size);
+
+/**
+  * @brief Writes supplied data to target's flash memory.
+  *
+  * @param payload[in]      Data to be flashed into target's memory.
+  * @param size[in]         Size of payload in bytes.
+  *
+  * @note  size must not be greater that block_size supplied to previously called
+  *        esp_loader_flash_start function. If size is less than block_size,
+  *        remaining bytes of payload buffer will be padded with 0xff.
+  *        Therefore, size of payload buffer has to be equal or greater than block_size.
+  *
+  * @return
+  *     - ESP_LOADER_SUCCESS Success
+  *     - ESP_LOADER_ERROR_TIMEOUT Timeout
+  *     - ESP_LOADER_ERROR_INVALID_RESPONSE Internal error
+  */
+esp_loader_error_t esp_loader_flash_write(void *payload, uint32_t size);
+
+/**
+  * @brief Ends flash operation.
+  *
+  * @param reboot[in]       reboot the target if true.
+  *
+  * @return
+  *     - ESP_LOADER_SUCCESS Success
+  *     - ESP_LOADER_ERROR_TIMEOUT Timeout
+  *     - ESP_LOADER_ERROR_INVALID_RESPONSE Internal error
+  */
+esp_loader_error_t esp_loader_flash_finish(bool reboot);
+#endif /* SERIAL_FLASHER_INTERFACE_UART */
+
+
+/**
+  * @brief Initiates mem operation, initiates loading for program into target RAM
+  *
+  * @param offset[in]       Address from which mem operation will be performed.
+  * @param size[in]         Size of the whole binary to be loaded into mem.
+  * @param block_size[in]   Size of buffer used in subsequent calls to esp_loader_mem_write.
+  *
+  * @note  image_size is size of the whole image, whereas, block_size is chunk of data sent
+  *        to the target, each time esp_mem_flash_write function is called.
+  *
+  * @return
+  *     - ESP_LOADER_SUCCESS Success
+  *     - ESP_LOADER_ERROR_TIMEOUT Timeout
+  *     - ESP_LOADER_ERROR_INVALID_RESPONSE Internal error
+  */
+esp_loader_error_t esp_loader_mem_start(uint32_t offset, uint32_t size, uint32_t block_size);
+
+
+/**
+  * @brief Writes supplied data to target's mem memory.
+  *
+  * @param payload[in]      Data to be loaded into target's memory.
+  * @param size[in]         Size of data in bytes.
+  *
+  * @note  size must not be greater that block_size supplied to previously called
+  *        esp_loader_mem_start function.
+  *        Therefore, size of data buffer has to be equal or greater than block_size.
+  *
+  * @return
+  *     - ESP_LOADER_SUCCESS Success
+  *     - ESP_LOADER_ERROR_TIMEOUT Timeout
+  *     - ESP_LOADER_ERROR_INVALID_RESPONSE Internal error
+  */
+esp_loader_error_t esp_loader_mem_write(const void *payload, uint32_t size);
+
+
+/**
+  * @brief Ends mem operation, finish loading for program into target RAM
+  *        and send the entrypoint of ram_loadable app
+  *
+  * @param entrypoint[in]       entrypoint of ram program.
+  *
+  * @return
+  *     - ESP_LOADER_SUCCESS Success
+  *     - ESP_LOADER_ERROR_TIMEOUT Timeout
+  *     - ESP_LOADER_ERROR_INVALID_RESPONSE Internal error
+  */
+esp_loader_error_t esp_loader_mem_finish(uint32_t entrypoint);
+
+
+/**
+  * @brief Writes register.
+  *
+  * @param address[in]      Address of register.
+  * @param reg_value[in]    New register value.
+  *
+  * @return
+  *     - ESP_LOADER_SUCCESS Success
+  *     - ESP_LOADER_ERROR_TIMEOUT Timeout
+  *     - ESP_LOADER_ERROR_INVALID_RESPONSE Internal error
+  */
+esp_loader_error_t esp_loader_write_register(uint32_t address, uint32_t reg_value);
+
+/**
+  * @brief Reads register.
+  *
+  * @param address[in]      Address of register.
+  * @param reg_value[out]   Register value.
+  *
+  * @return
+  *     - ESP_LOADER_SUCCESS Success
+  *     - ESP_LOADER_ERROR_TIMEOUT Timeout
+  *     - ESP_LOADER_ERROR_INVALID_RESPONSE Internal error
+  */
+esp_loader_error_t esp_loader_read_register(uint32_t address, uint32_t *reg_value);
+
+/**
+  * @brief Change baud rate.
+  *
+  * @note  Baud rate has to be also adjusted accordingly on host MCU, as
+  *        target's baud rate is changed upon return from this function.
+  *
+  * @param transmission_rate[in]     new baud rate to be set.
+  *
+  * @return
+  *     - ESP_LOADER_SUCCESS Success
+  *     - ESP_LOADER_ERROR_TIMEOUT Timeout
+  *     - ESP_LOADER_ERROR_INVALID_RESPONSE Internal error
+  *     - ESP_LOADER_ERROR_UNSUPPORTED_FUNC Unsupported on the target
+  */
+esp_loader_error_t esp_loader_change_transmission_rate(uint32_t transmission_rate);
+
+/**
+  * @brief Verify target's flash integrity by checking MD5.
+  *        MD5 checksum is computed from data pushed to target's memory by calling
+  *        esp_loader_flash_write() function and compared against target's MD5.
+  *        Target computes checksum based on offset and image_size passed to
+  *        esp_loader_flash_start() function.
+  *
+  * @note  This function is only available if MD5_ENABLED is set.
+  *
+  * @return
+  *     - ESP_LOADER_SUCCESS Success
+  *     - ESP_LOADER_ERROR_INVALID_MD5 MD5 does not match
+  *     - ESP_LOADER_ERROR_TIMEOUT Timeout
+  *     - ESP_LOADER_ERROR_INVALID_RESPONSE Internal error
+  *     - ESP_LOADER_ERROR_UNSUPPORTED_FUNC Unsupported on the target
+  */
+#if MD5_ENABLED
+esp_loader_error_t esp_loader_flash_verify(void);
+#endif
+/**
+  * @brief Toggles reset pin.
+  */
+void esp_loader_reset_target(void);
+
+
+
+#ifdef __cplusplus
+}
+#endif

+ 112 - 0
esp_flasher/lib/esp-serial-flasher/include/esp_loader_io.h

@@ -0,0 +1,112 @@
+/* Copyright 2020-2023 Espressif Systems (Shanghai) CO LTD
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+ #pragma once
+
+#include <stdint.h>
+#include "esp_loader.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+  * @brief Changes the transmission rate of the used peripheral.
+  */
+esp_loader_error_t loader_port_change_transmission_rate(uint32_t transmission_rate);
+
+/**
+  * @brief Writes data over the io interface.
+  *
+  * @param data[in]     Buffer with data to be written.
+  * @param size[in]     Size of data in bytes.
+  * @param timeout[in]  Timeout in milliseconds.
+  *
+  * @return
+  *     - ESP_LOADER_SUCCESS Success
+  *     - ESP_LOADER_ERROR_TIMEOUT Timeout elapsed
+  */
+esp_loader_error_t loader_port_write(const uint8_t *data, uint16_t size, uint32_t timeout);
+
+/**
+  * @brief Reads data from the io interface.
+  *
+  * @param data[out]    Buffer into which received data will be written.
+  * @param size[in]     Number of bytes to read.
+  * @param timeout[in]  Timeout in milliseconds.
+  *
+  * @return
+  *     - ESP_LOADER_SUCCESS Success
+  *     - ESP_LOADER_ERROR_TIMEOUT Timeout elapsed
+  */
+esp_loader_error_t loader_port_read(uint8_t *data, uint16_t size, uint32_t timeout);
+
+/**
+  * @brief Delay in milliseconds.
+  *
+  * @param ms[in]   Number of milliseconds.
+  *
+  */
+void loader_port_delay_ms(uint32_t ms);
+
+/**
+  * @brief Starts timeout timer.
+  *
+  * @param ms[in]   Number of milliseconds.
+  *
+  */
+void loader_port_start_timer(uint32_t ms);
+
+/**
+  * @brief Returns remaining time since timer was started by calling esp_loader_start_timer.
+  *        0 if timer has elapsed.
+  *
+  * @return   Number of milliseconds.
+  *
+  */
+uint32_t loader_port_remaining_time(void);
+
+/**
+  * @brief Asserts bootstrap pins to enter boot mode and toggles reset pin.
+  *
+  * @note  Reset pin should stay asserted for at least 20 milliseconds.
+  */
+void loader_port_enter_bootloader(void);
+
+/**
+  * @brief Toggles reset pin.
+  *
+  * @note  Reset pin should stay asserted for at least 20 milliseconds.
+  */
+void loader_port_reset_target(void);
+
+/**
+  * @brief Function can be defined by user to print debug message.
+  *
+  * @note  Empty weak function is used, otherwise.
+  *
+  */
+void loader_port_debug_print(const char *str);
+
+#ifdef SERIAL_FLASHER_INTERFACE_SPI
+/**
+  * @brief Sets the chip select to a defined level
+  */
+void loader_port_spi_set_cs(uint32_t level);
+#endif /* SERIAL_FLASHER_INTERFACE_SPI */
+
+#ifdef __cplusplus
+}
+#endif

+ 24 - 0
esp_flasher/lib/esp-serial-flasher/include/serial_io.h

@@ -0,0 +1,24 @@
+/* Copyright 2020-2023 Espressif Systems (Shanghai) CO LTD
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#warning Please replace serial_io.h with esp_loader_io.h and change the function names \
+         to match the new API
+
+/* Defines used to avoid breaking existing ports */
+#define loader_port_change_baudrate loader_port_change_transmission_rate
+#define loader_port_serial_write loader_port_write
+#define loader_port_serial_read loader_port_read
+
+#include "esp_loader_io.h"

+ 181 - 0
esp_flasher/lib/esp-serial-flasher/port/esp32_port.c

@@ -0,0 +1,181 @@
+/* Copyright 2020-2023 Espressif Systems (Shanghai) CO LTD
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "esp32_port.h"
+#include "driver/uart.h"
+#include "driver/gpio.h"
+#include "esp_timer.h"
+#include "esp_log.h"
+#include "esp_idf_version.h"
+#include <unistd.h>
+
+#ifdef SERIAL_FLASHER_DEBUG_TRACE
+static void transfer_debug_print(const uint8_t *data, uint16_t size, bool write)
+{
+    static bool write_prev = false;
+
+    if (write_prev != write) {
+        write_prev = write;
+        printf("\n--- %s ---\n", write ? "WRITE" : "READ");
+    }
+
+    for (uint32_t i = 0; i < size; i++) {
+        printf("%02x ", data[i]);
+    }
+}
+#endif
+
+static int64_t s_time_end;
+static int32_t s_uart_port;
+static int32_t s_reset_trigger_pin;
+static int32_t s_gpio0_trigger_pin;
+
+esp_loader_error_t loader_port_esp32_init(const loader_esp32_config_t *config)
+{
+    s_uart_port = config->uart_port;
+    s_reset_trigger_pin = config->reset_trigger_pin;
+    s_gpio0_trigger_pin = config->gpio0_trigger_pin;
+
+    // Initialize UART
+    uart_config_t uart_config = {
+        .baud_rate = config->baud_rate,
+        .data_bits = UART_DATA_8_BITS,
+        .parity    = UART_PARITY_DISABLE,
+        .stop_bits = UART_STOP_BITS_1,
+        .flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
+#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
+        .source_clk = UART_SCLK_DEFAULT,
+#endif
+    };
+
+    int rx_buffer_size = config->rx_buffer_size ? config->rx_buffer_size : 400;
+    int tx_buffer_size = config->tx_buffer_size ? config->tx_buffer_size : 400;
+    QueueHandle_t *uart_queue = config->uart_queue ? config->uart_queue : NULL;
+    int queue_size = config->queue_size ? config->queue_size : 0;
+
+    if ( uart_param_config(s_uart_port, &uart_config) != ESP_OK ) {
+        return ESP_LOADER_ERROR_FAIL;
+    }
+    if ( uart_set_pin(s_uart_port, config->uart_tx_pin, config->uart_rx_pin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE) != ESP_OK ) {
+        return ESP_LOADER_ERROR_FAIL;
+    }
+    if ( uart_driver_install(s_uart_port, rx_buffer_size, tx_buffer_size, queue_size, uart_queue, 0) != ESP_OK ) {
+        return ESP_LOADER_ERROR_FAIL;
+    }
+
+    // Initialize boot pin selection pins
+    gpio_reset_pin(s_reset_trigger_pin);
+    gpio_set_pull_mode(s_reset_trigger_pin, GPIO_PULLUP_ONLY);
+    gpio_set_direction(s_reset_trigger_pin, GPIO_MODE_OUTPUT);
+
+    gpio_reset_pin(s_gpio0_trigger_pin);
+    gpio_set_pull_mode(s_gpio0_trigger_pin, GPIO_PULLUP_ONLY);
+    gpio_set_direction(s_gpio0_trigger_pin, GPIO_MODE_OUTPUT);
+
+    return ESP_LOADER_SUCCESS;
+}
+
+void loader_port_esp32_deinit(void)
+{
+    uart_driver_delete(s_uart_port);
+}
+
+
+esp_loader_error_t loader_port_write(const uint8_t *data, uint16_t size, uint32_t timeout)
+{
+    uart_write_bytes(s_uart_port, (const char *)data, size);
+    esp_err_t err = uart_wait_tx_done(s_uart_port, pdMS_TO_TICKS(timeout));
+
+    if (err == ESP_OK) {
+#ifdef SERIAL_FLASHER_DEBUG_TRACE
+        transfer_debug_print(data, size, true);
+#endif
+        return ESP_LOADER_SUCCESS;
+    } else if (err == ESP_ERR_TIMEOUT) {
+        return ESP_LOADER_ERROR_TIMEOUT;
+    } else {
+        return ESP_LOADER_ERROR_FAIL;
+    }
+}
+
+
+esp_loader_error_t loader_port_read(uint8_t *data, uint16_t size, uint32_t timeout)
+{
+    int read = uart_read_bytes(s_uart_port, data, size, pdMS_TO_TICKS(timeout));
+
+    if (read < 0) {
+        return ESP_LOADER_ERROR_FAIL;
+    } else if (read < size) {
+#ifdef SERIAL_FLASHER_DEBUG_TRACE
+        transfer_debug_print(data, read, false);
+#endif
+        return ESP_LOADER_ERROR_TIMEOUT;
+    } else {
+#ifdef SERIAL_FLASHER_DEBUG_TRACE
+        transfer_debug_print(data, read, false);
+#endif
+        return ESP_LOADER_SUCCESS;
+    }
+}
+
+
+// Set GPIO0 LOW, then
+// assert reset pin for 50 milliseconds.
+void loader_port_enter_bootloader(void)
+{
+    gpio_set_level(s_gpio0_trigger_pin, 0);
+    loader_port_reset_target();
+    loader_port_delay_ms(SERIAL_FLASHER_BOOT_HOLD_TIME_MS);
+    gpio_set_level(s_gpio0_trigger_pin, 1);
+}
+
+
+void loader_port_reset_target(void)
+{
+    gpio_set_level(s_reset_trigger_pin, 0);
+    loader_port_delay_ms(SERIAL_FLASHER_RESET_HOLD_TIME_MS);
+    gpio_set_level(s_reset_trigger_pin, 1);
+}
+
+
+void loader_port_delay_ms(uint32_t ms)
+{
+    usleep(ms * 1000);
+}
+
+
+void loader_port_start_timer(uint32_t ms)
+{
+    s_time_end = esp_timer_get_time() + ms * 1000;
+}
+
+
+uint32_t loader_port_remaining_time(void)
+{
+    int64_t remaining = (s_time_end - esp_timer_get_time()) / 1000;
+    return (remaining > 0) ? (uint32_t)remaining : 0;
+}
+
+
+void loader_port_debug_print(const char *str)
+{
+    printf("DEBUG: %s\n", str);
+}
+
+esp_loader_error_t loader_port_change_transmission_rate(uint32_t baudrate)
+{
+    esp_err_t err = uart_set_baudrate(s_uart_port, baudrate);
+    return (err == ESP_OK) ? ESP_LOADER_SUCCESS : ESP_LOADER_ERROR_FAIL;
+}

+ 59 - 0
esp_flasher/lib/esp-serial-flasher/port/esp32_port.h

@@ -0,0 +1,59 @@
+/* Copyright 2020-2023 Espressif Systems (Shanghai) CO LTD
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+ #pragma once
+
+#include "esp_loader_io.h"
+#include "freertos/FreeRTOS.h"
+#include "freertos/queue.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct
+{
+  uint32_t baud_rate;     /*!< Initial baud rate, can be changed later */
+  uint32_t uart_port;     /*!< UART port */
+  uint32_t uart_rx_pin;   /*!< This pin will be configured as UART Rx pin */
+  uint32_t uart_tx_pin;   /*!< This pin will be configured as UART Tx pin */
+  uint32_t reset_trigger_pin; /*!< This pin will be used to reset target chip */
+  uint32_t gpio0_trigger_pin; /*!< This pin will be used to toggle set IO0 of target chip */
+  uint32_t rx_buffer_size;    /*!< Set to zero for default RX buffer size */
+  uint32_t tx_buffer_size;    /*!< Set to zero for default TX buffer size */
+  uint32_t queue_size;        /*!< Set to zero for default UART queue size */
+  QueueHandle_t *uart_queue;  /*!< Set to NULL, if UART queue handle is not
+                                   necessary. Otherwise, it will be assigned here */
+} loader_esp32_config_t;
+
+/**
+  * @brief Initializes serial interface.
+  *
+  * @param baud_rate[in]       Communication speed.
+  *
+  * @return
+  *     - ESP_LOADER_SUCCESS Success
+  *     - ESP_LOADER_ERROR_FAIL Initialization failure
+  */
+esp_loader_error_t loader_port_esp32_init(const loader_esp32_config_t *config);
+
+/**
+  * @brief Deinitialize serial interface.
+  */
+void loader_port_esp32_deinit(void);
+
+#ifdef __cplusplus
+}
+#endif

+ 298 - 0
esp_flasher/lib/esp-serial-flasher/port/esp32_spi_port.c

@@ -0,0 +1,298 @@
+/* Copyright 2020-2023 Espressif Systems (Shanghai) CO LTD
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "esp32_spi_port.h"
+#include "esp_log.h"
+#include "driver/gpio.h"
+#include "esp_timer.h"
+#include "esp_log.h"
+#include "esp_idf_version.h"
+#include <unistd.h>
+
+// #define SERIAL_DEBUG_ENABLE
+
+#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 3, 0)
+#define DMA_CHAN SPI_DMA_CH_AUTO
+#else
+#define DMA_CHAN 1
+#endif
+
+#define WORD_ALIGNED(ptr) ((size_t)ptr % sizeof(size_t) == 0)
+
+#ifdef SERIAL_DEBUG_ENABLE
+
+static void dec_to_hex_str(const uint8_t dec, uint8_t hex_str[3])
+{
+    static const uint8_t dec_to_hex[] = {
+        '0', '1', '2', '3', '4', '5', '6', '7',
+        '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
+    };
+
+    hex_str[0] = dec_to_hex[dec >> 4];
+    hex_str[1] = dec_to_hex[dec & 0xF];
+    hex_str[2] = '\0';
+}
+
+static void serial_debug_print(const uint8_t *data, uint16_t size, bool write)
+{
+    static bool write_prev = false;
+    uint8_t hex_str[3];
+
+    if(write_prev != write) {
+        write_prev = write;
+        printf("\n--- %s ---\n", write ? "WRITE" : "READ");
+    }
+
+    for(uint32_t i = 0; i < size; i++) {
+        dec_to_hex_str(data[i], hex_str);
+        printf("%s ", hex_str);
+    }
+}
+
+#else
+static void serial_debug_print(const uint8_t *data, uint16_t size, bool write) { }
+#endif
+
+static spi_host_device_t s_spi_bus;
+static spi_bus_config_t s_spi_config;
+static spi_device_handle_t s_device_h;
+static spi_device_interface_config_t s_device_config;
+static int64_t s_time_end;
+static uint32_t s_reset_trigger_pin;
+static uint32_t s_strap_bit0_pin;
+static uint32_t s_strap_bit1_pin;
+static uint32_t s_strap_bit2_pin;
+static uint32_t s_strap_bit3_pin;
+static uint32_t s_spi_cs_pin;
+
+esp_loader_error_t loader_port_esp32_spi_init(const loader_esp32_spi_config_t *config)
+{
+    /* Initialize the global static variables*/
+    s_spi_bus = config->spi_bus;
+    s_reset_trigger_pin = config->reset_trigger_pin;
+    s_strap_bit0_pin = config->strap_bit0_pin;
+    s_strap_bit1_pin = config->strap_bit1_pin;
+    s_strap_bit2_pin = config->strap_bit2_pin;
+    s_strap_bit3_pin = config->strap_bit3_pin;
+    s_spi_cs_pin = config->spi_cs_pin;
+
+    /* Configure and initialize the SPI bus*/
+    s_spi_config.mosi_io_num = config->spi_mosi_pin;
+    s_spi_config.miso_io_num = config->spi_miso_pin;
+    s_spi_config.sclk_io_num = config->spi_clk_pin;
+    s_spi_config.quadwp_io_num = config->spi_quadwp_pin;
+    s_spi_config.quadhd_io_num = config->spi_quadhd_pin;
+    s_spi_config.max_transfer_sz = 4096 * 4;
+
+    if (spi_bus_initialize(s_spi_bus, &s_spi_config, DMA_CHAN) != ESP_OK) {
+        return ESP_LOADER_ERROR_FAIL;
+    }
+
+    /* Configure and add the device */
+    s_device_config.clock_speed_hz = config->frequency;
+    s_device_config.spics_io_num = -1; /* We're using the chip select pin as GPIO as we need to
+                                          chain multiple transactions with CS pulled down */
+    s_device_config.flags = SPI_DEVICE_HALFDUPLEX;
+    s_device_config.queue_size = 16;
+
+    if (spi_bus_add_device(s_spi_bus, &s_device_config, &s_device_h) != ESP_OK) {
+        return ESP_LOADER_ERROR_FAIL;
+    }
+
+    /* Initialize the pins except for the strapping ones */
+    gpio_reset_pin(s_reset_trigger_pin);
+    gpio_set_pull_mode(s_reset_trigger_pin, GPIO_PULLUP_ONLY);
+    gpio_set_direction(s_reset_trigger_pin, GPIO_MODE_OUTPUT);
+    gpio_set_level(s_reset_trigger_pin, 1);
+
+    gpio_reset_pin(s_spi_cs_pin);
+    gpio_set_pull_mode(s_spi_cs_pin, GPIO_PULLUP_ONLY);
+    gpio_set_direction(s_spi_cs_pin, GPIO_MODE_OUTPUT);
+    gpio_set_level(s_spi_cs_pin, 1);
+
+    return ESP_LOADER_SUCCESS;
+}
+
+
+void loader_port_esp32_spi_deinit(void)
+{
+    gpio_reset_pin(s_reset_trigger_pin);
+    gpio_reset_pin(s_spi_cs_pin);
+    spi_bus_remove_device(s_device_h);
+    spi_bus_free(s_spi_bus);
+}
+
+
+void loader_port_spi_set_cs(const uint32_t level) {
+    gpio_set_level(s_spi_cs_pin, level);
+}
+
+
+esp_loader_error_t loader_port_write(const uint8_t *data, const uint16_t size, const uint32_t timeout)
+{
+    /* Due to the fact that the SPI driver uses DMA for larger transfers,
+       and the DMA requirements, the buffer must be word aligned */
+    if (data == NULL || !WORD_ALIGNED(data)) {
+        return ESP_LOADER_ERROR_INVALID_PARAM;
+    }
+
+    serial_debug_print(data, size, true);
+
+    spi_transaction_t transaction = {
+        .tx_buffer = data,
+        .rx_buffer = NULL,
+        .length = size * 8U,
+        .rxlength = 0,
+    };
+
+    esp_err_t err = spi_device_transmit(s_device_h, &transaction);
+
+    if (err == ESP_OK) {
+        serial_debug_print(data, size, false);
+        return ESP_LOADER_SUCCESS;
+    } else if (err == ESP_ERR_TIMEOUT) {
+        return ESP_LOADER_ERROR_TIMEOUT;
+    } else {
+        return ESP_LOADER_ERROR_FAIL;
+    }
+}
+
+
+esp_loader_error_t loader_port_read(uint8_t *data, const uint16_t size, const uint32_t timeout)
+{
+    /* Due to the fact that the SPI driver uses DMA for larger transfers,
+       and the DMA requirements, the buffer must be word aligned */
+    if (data == NULL || !WORD_ALIGNED(data)) {
+        return ESP_LOADER_ERROR_INVALID_PARAM;
+    }
+
+    serial_debug_print(data, size, true);
+
+    spi_transaction_t transaction = {
+        .tx_buffer = NULL,
+        .rx_buffer = data,
+        .rxlength = size * 8,
+    };
+
+    esp_err_t err = spi_device_transmit(s_device_h, &transaction);
+
+    if (err == ESP_OK) {
+        serial_debug_print(data, size, false);
+        return ESP_LOADER_SUCCESS;
+    } else if (err == ESP_ERR_TIMEOUT) {
+        return ESP_LOADER_ERROR_TIMEOUT;
+    } else {
+        return ESP_LOADER_ERROR_FAIL;
+    }
+}
+
+
+void loader_port_enter_bootloader(void)
+{
+    /*
+        We have to initialize the GPIO pins for the target strapping pins here,
+        as they may overlap with target SPI pins.
+        For instance in the case of ESP32C3 MISO and strapping bit 0 pins overlap.
+    */
+    spi_bus_remove_device(s_device_h);
+    spi_bus_free(s_spi_bus);
+
+    gpio_reset_pin(s_strap_bit0_pin);
+    gpio_set_pull_mode(s_strap_bit0_pin, GPIO_PULLUP_ONLY);
+    gpio_set_direction(s_strap_bit0_pin, GPIO_MODE_OUTPUT);
+
+    gpio_reset_pin(s_strap_bit1_pin);
+    gpio_set_pull_mode(s_strap_bit1_pin, GPIO_PULLUP_ONLY);
+    gpio_set_direction(s_strap_bit1_pin, GPIO_MODE_OUTPUT);
+
+    gpio_reset_pin(s_strap_bit2_pin);
+    gpio_set_pull_mode(s_strap_bit2_pin, GPIO_PULLUP_ONLY);
+    gpio_set_direction(s_strap_bit2_pin, GPIO_MODE_OUTPUT);
+
+    gpio_reset_pin(s_strap_bit3_pin);
+    gpio_set_pull_mode(s_strap_bit3_pin, GPIO_PULLUP_ONLY);
+    gpio_set_direction(s_strap_bit3_pin, GPIO_MODE_OUTPUT);
+
+    /* Set the strapping pins and perform the reset sequence */
+    gpio_set_level(s_strap_bit0_pin, 1);
+    gpio_set_level(s_strap_bit1_pin, 0);
+    gpio_set_level(s_strap_bit2_pin, 0);
+    gpio_set_level(s_strap_bit3_pin, 0);
+    loader_port_reset_target();
+    loader_port_delay_ms(SERIAL_FLASHER_BOOT_HOLD_TIME_MS);
+    gpio_set_level(s_strap_bit3_pin, 1);
+    gpio_set_level(s_strap_bit0_pin, 0);
+
+    /* Disable the strapping pins so they can be used by the slave later */
+    gpio_reset_pin(s_strap_bit0_pin);
+    gpio_reset_pin(s_strap_bit1_pin);
+    gpio_reset_pin(s_strap_bit2_pin);
+    gpio_reset_pin(s_strap_bit3_pin);
+
+    /* Restore the SPI bus pins */
+    spi_bus_initialize(s_spi_bus, &s_spi_config, DMA_CHAN);
+    spi_bus_add_device(s_spi_bus, &s_device_config, &s_device_h);
+}
+
+
+void loader_port_reset_target(void)
+{
+    gpio_set_level(s_reset_trigger_pin, 0);
+    loader_port_delay_ms(SERIAL_FLASHER_RESET_HOLD_TIME_MS);
+    gpio_set_level(s_reset_trigger_pin, 1);
+}
+
+
+void loader_port_delay_ms(const uint32_t ms)
+{
+    usleep(ms * 1000);
+}
+
+
+void loader_port_start_timer(const uint32_t ms)
+{
+    s_time_end = esp_timer_get_time() + ms * 1000;
+}
+
+
+uint32_t loader_port_remaining_time(void)
+{
+    int64_t remaining = (s_time_end - esp_timer_get_time()) / 1000;
+    return (remaining > 0) ? (uint32_t)remaining : 0;
+}
+
+
+void loader_port_debug_print(const char *str)
+{
+    printf("DEBUG: %s\n", str);
+}
+
+
+esp_loader_error_t loader_port_change_transmission_rate(const uint32_t frequency)
+{
+    if (spi_bus_remove_device(s_device_h) != ESP_OK) {
+        return ESP_LOADER_ERROR_FAIL;
+    }
+
+    uint32_t old_frequency = s_device_config.clock_speed_hz;
+    s_device_config.clock_speed_hz = frequency;
+
+    if (spi_bus_add_device(s_spi_bus, &s_device_config, &s_device_h) != ESP_OK) {
+        s_device_config.clock_speed_hz = old_frequency;
+        return ESP_LOADER_ERROR_FAIL;
+    }
+
+    return ESP_LOADER_SUCCESS;
+}

+ 60 - 0
esp_flasher/lib/esp-serial-flasher/port/esp32_spi_port.h

@@ -0,0 +1,60 @@
+/* Copyright 2020-2023 Espressif Systems (Shanghai) CO LTD
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+ #pragma once
+
+#include "esp_loader_io.h"
+#include "driver/spi_master.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct
+{
+    spi_host_device_t spi_bus;
+    uint32_t frequency;
+    uint32_t spi_clk_pin;
+    uint32_t spi_miso_pin;
+    uint32_t spi_mosi_pin;
+    uint32_t spi_cs_pin;
+    uint32_t spi_quadwp_pin;
+    uint32_t spi_quadhd_pin;
+    uint32_t reset_trigger_pin;
+    uint32_t strap_bit0_pin;
+    uint32_t strap_bit1_pin;
+    uint32_t strap_bit2_pin;
+    uint32_t strap_bit3_pin;
+} loader_esp32_spi_config_t;
+
+/**
+  * @brief Initializes the SPI interface.
+  *
+  * @param config[in] Configuration structure
+  *
+  * @return
+  *     - ESP_LOADER_SUCCESS Success
+  *     - ESP_LOADER_ERROR_FAIL Initialization failure
+  */
+esp_loader_error_t loader_port_esp32_spi_init(const loader_esp32_spi_config_t *config);
+
+/**
+  * @brief Deinitializes the SPI interface.
+  */
+void loader_port_esp32_spi_deinit(void);
+
+#ifdef __cplusplus
+}
+#endif

+ 302 - 0
esp_flasher/lib/esp-serial-flasher/port/raspberry_port.c

@@ -0,0 +1,302 @@
+/* Copyright 2020-2023 Espressif Systems (Shanghai) CO LTD
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "esp_loader_io.h"
+#include "protocol.h"
+#include <pigpio.h>
+#include "raspberry_port.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <termios.h>
+#include <time.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <stdarg.h>
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/param.h>
+
+#ifdef SERIAL_FLASHER_DEBUG_TRACE
+static void transfer_debug_print(const uint8_t *data, uint16_t size, bool write)
+{
+    static bool write_prev = false;
+
+    if (write_prev != write) {
+        write_prev = write;
+        printf("\n--- %s ---\n", write ? "WRITE" : "READ");
+    }
+
+    for (uint32_t i = 0; i < size; i++) {
+        printf("%02x ", data[i]);
+    }
+}
+#endif
+
+static int serial;
+static int64_t s_time_end;
+static int32_t s_reset_trigger_pin;
+static int32_t s_gpio0_trigger_pin;
+
+
+static speed_t convert_baudrate(int baud)
+{
+    switch (baud) {
+        case 50: return B50;
+        case 75: return B75;
+        case 110: return B110;
+        case 134: return B134;
+        case 150: return B150;
+        case 200: return B200;
+        case 300: return B300;
+        case 600: return B600;
+        case 1200: return B1200;
+        case 1800: return B1800;
+        case 2400: return B2400;
+        case 4800: return B4800;
+        case 9600: return B9600;
+        case 19200: return B19200;
+        case 38400: return B38400;
+        case 57600: return B57600;
+        case 115200: return B115200;
+        case 230400: return B230400;
+        case 460800: return B460800;
+        case 500000: return B500000;
+        case 576000: return B576000;
+        case 921600: return B921600;
+        case 1000000: return B1000000;
+        case 1152000: return B1152000;
+        case 1500000: return B1500000;
+        case 2000000: return B2000000;
+        case 2500000: return B2500000;
+        case 3000000: return B3000000;
+        case 3500000: return B3500000;
+        case 4000000: return B4000000;
+        default: return -1;
+    }
+}
+
+static int serialOpen (const char *device, uint32_t baudrate)
+{
+    struct termios options;
+    int status, fd;
+
+    if ((fd = open (device, O_RDWR | O_NOCTTY | O_NDELAY | O_NONBLOCK)) == -1) {
+        printf("Error occured while opening serial port !\n");
+        return -1 ;
+    }
+
+    fcntl (fd, F_SETFL, O_RDWR) ;
+
+    // Get and modify current options:
+
+    tcgetattr (fd, &options);
+    speed_t baud = convert_baudrate(baudrate);
+
+    if(baud < 0) {
+        printf("Invalid baudrate!\n");
+        return -1;
+    }
+
+    cfmakeraw   (&options) ;
+    cfsetispeed (&options, baud) ;
+    cfsetospeed (&options, baud) ;
+
+    options.c_cflag |= (CLOCAL | CREAD) ;
+    options.c_cflag &= ~(PARENB | CSTOPB | CSIZE) ;
+    options.c_cflag |= CS8 ;
+    options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG) ;
+    options.c_oflag &= ~OPOST ;
+    options.c_iflag &= ~(IXON | IXOFF | IXANY); // Turn off s/w flow ctrl
+    options.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL); // Disable any special handling of received bytes
+
+    options.c_cc [VMIN]  = 0 ;
+    options.c_cc [VTIME] = 10 ; // 1 Second
+
+    tcsetattr (fd, TCSANOW, &options) ;
+
+    ioctl (fd, TIOCMGET, &status);
+
+    status |= TIOCM_DTR ;
+    status |= TIOCM_RTS ;
+
+    ioctl (fd, TIOCMSET, &status);
+
+    usleep (10000) ;  // 10mS
+
+    return fd ;
+}
+
+static esp_loader_error_t change_baudrate(int file_desc, int baudrate)
+{
+    struct termios options;
+    speed_t baud = convert_baudrate(baudrate);
+
+    if(baud < 0) {
+        return ESP_LOADER_ERROR_INVALID_PARAM;
+    }
+
+    tcgetattr (file_desc, &options);
+
+    cfmakeraw   (&options) ;
+    cfsetispeed (&options, baud);
+    cfsetospeed (&options, baud);
+
+    tcsetattr (file_desc, TCSANOW, &options);
+
+    return ESP_LOADER_SUCCESS;
+}
+
+static void set_timeout(uint32_t timeout)
+{
+    struct termios options;
+
+    timeout /= 100;
+    timeout = MAX(timeout, 1);
+
+    tcgetattr(serial, &options);
+    options.c_cc[VTIME] = timeout;
+    tcsetattr(serial, TCSANOW, &options);
+}
+
+static esp_loader_error_t read_char(char *c, uint32_t timeout)
+{
+    set_timeout(timeout);
+    int read_bytes = read(serial, c, 1);
+
+    if (read_bytes == 1) {
+        return ESP_LOADER_SUCCESS;
+    } else if (read_bytes == 0) {
+        return ESP_LOADER_ERROR_TIMEOUT;
+    } else {
+        return ESP_LOADER_ERROR_FAIL;
+    }
+}
+
+static esp_loader_error_t read_data(char *buffer, uint32_t size)
+{
+    for (int i = 0; i < size; i++) {
+        uint32_t remaining_time = loader_port_remaining_time();
+        RETURN_ON_ERROR( read_char(&buffer[i], remaining_time) );
+    }
+
+    return ESP_LOADER_SUCCESS;
+}
+
+esp_loader_error_t loader_port_raspberry_init(const loader_raspberry_config_t *config)
+{
+    s_reset_trigger_pin = config->reset_trigger_pin;
+    s_gpio0_trigger_pin = config->gpio0_trigger_pin;
+
+    serial = serialOpen(config->device, config->baudrate);
+    if (serial < 0) {
+        printf("Serial port could not be opened!\n");
+        return ESP_LOADER_ERROR_FAIL;
+    }
+
+    if (gpioInitialise() < 0) {
+        printf("pigpio initialisation failed\n");
+        return ESP_LOADER_ERROR_FAIL;
+    }
+
+    gpioSetMode(config->reset_trigger_pin, PI_OUTPUT);
+    gpioSetMode(config->gpio0_trigger_pin, PI_OUTPUT);
+
+    return ESP_LOADER_SUCCESS;
+}
+
+
+esp_loader_error_t loader_port_write(const uint8_t *data, uint16_t size, uint32_t timeout)
+{
+    int written = write(serial, data, size);
+
+    if (written < 0) {
+        return ESP_LOADER_ERROR_FAIL;
+    } else if (written < size) {
+#ifdef SERIAL_FLASHER_DEBUG_TRACE
+        transfer_debug_print(data, written, true);
+#endif
+        return ESP_LOADER_ERROR_TIMEOUT;
+    } else {
+#ifdef SERIAL_FLASHER_DEBUG_TRACE
+        transfer_debug_print(data, written, true);
+#endif
+        return ESP_LOADER_SUCCESS;
+    }
+}
+
+
+esp_loader_error_t loader_port_read(uint8_t *data, uint16_t size, uint32_t timeout)
+{
+    RETURN_ON_ERROR( read_data(data, size) );
+
+#ifdef SERIAL_FLASHER_DEBUG_TRACE
+    transfer_debug_print(data, size, false);
+#endif
+
+    return ESP_LOADER_SUCCESS;
+}
+
+
+// Set GPIO0 LOW, then assert reset pin for 50 milliseconds.
+void loader_port_enter_bootloader(void)
+{
+    gpioWrite(s_gpio0_trigger_pin, 0);
+    loader_port_reset_target();
+    loader_port_delay_ms(SERIAL_FLASHER_BOOT_HOLD_TIME_MS);
+    gpioWrite(s_gpio0_trigger_pin, 1);
+}
+
+
+void loader_port_reset_target(void)
+{
+    gpioWrite(s_reset_trigger_pin, 0);
+    loader_port_delay_ms(SERIAL_FLASHER_RESET_HOLD_TIME_MS);
+    gpioWrite(s_reset_trigger_pin, 1);
+}
+
+
+void loader_port_delay_ms(uint32_t ms)
+{
+    usleep(ms * 1000);
+}
+
+
+void loader_port_start_timer(uint32_t ms)
+{
+    s_time_end = clock() + (ms * (CLOCKS_PER_SEC / 1000));
+}
+
+
+uint32_t loader_port_remaining_time(void)
+{
+    int64_t remaining = (s_time_end - clock()) / 1000;
+    return (remaining > 0) ? (uint32_t)remaining : 0;
+}
+
+
+void loader_port_debug_print(const char *str)
+{
+    printf("DEBUG: %s\n", str);
+}
+
+esp_loader_error_t loader_port_change_transmission_rate(uint32_t baudrate)
+{
+    return change_baudrate(serial, baudrate);
+}

+ 36 - 0
esp_flasher/lib/esp-serial-flasher/port/raspberry_port.h

@@ -0,0 +1,36 @@
+/* Copyright 2020-2023 Espressif Systems (Shanghai) CO LTD
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <stdint.h>
+#include "esp_loader_io.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct {
+    const char *device;
+    uint32_t baudrate;
+    uint32_t reset_trigger_pin;
+    uint32_t gpio0_trigger_pin;
+} loader_raspberry_config_t;
+
+esp_loader_error_t loader_port_raspberry_init(const loader_raspberry_config_t *config);
+
+#ifdef __cplusplus
+}
+#endif

Неке датотеке нису приказане због велике количине промена