Skip to content

Commit

Permalink
ESP32: Add support for flashing using .flash.py (project-chip#7947)
Browse files Browse the repository at this point in the history
  • Loading branch information
sweetymhaiske authored and Nikita committed Sep 23, 2021
1 parent 1c62898 commit 445d404
Show file tree
Hide file tree
Showing 9 changed files with 231 additions and 1 deletion.
35 changes: 35 additions & 0 deletions examples/all-clusters-app/esp32/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,38 @@ endif()
project(chip-all-clusters-app)
idf_build_set_property(CXX_COMPILE_OPTIONS "-std=gnu++14;-Os;-DLWIP_IPV6_SCOPES=0;-DCHIP_HAVE_CONFIG_H" APPEND)
idf_build_set_property(C_COMPILE_OPTIONS "-Os;-DLWIP_IPV6_SCOPES=0" APPEND)

idf_build_get_property(build_dir BUILD_DIR)
idf_build_get_property(project_path PROJECT_DIR)
idf_build_get_property(sdkconfig SDKCONFIG)
idf_build_get_property(idf_path IDF_PATH)

add_custom_command(OUTPUT "${build_dir}/firmware_utils.py"
COMMAND ${CMAKE_COMMAND} ARGS -E copy "${project_path}/third_party/connectedhomeip/scripts/flashing/firmware_utils.py" "${build_dir}/"
WORKING_DIRECTORY ${build_dir}
VERBATIM)

add_custom_command(OUTPUT "${build_dir}/esp32_firmware_utils.py"
COMMAND ${CMAKE_COMMAND} ARGS -E copy "${project_path}/third_party/connectedhomeip/scripts/flashing/esp32_firmware_utils.py" "${build_dir}/"
WORKING_DIRECTORY ${build_dir}
VERBATIM)

add_custom_command(OUTPUT "${build_dir}/${CMAKE_PROJECT_NAME}.flash.py"
COMMAND ${python}
"${project_path}/../../../scripts/flashing/gen_flashing_script.py" esp32
--output "${build_dir}/${CMAKE_PROJECT_NAME}.flash.py"
--port "$ENV{ESPPORT}"
--baud "$ENV{ESPBAUD}"
--before ${CONFIG_ESPTOOLPY_BEFORE}
--after ${CONFIG_ESPTOOLPY_AFTER}
--application "${CMAKE_PROJECT_NAME}.bin"
--bootloader "bootloader/bootloader.bin"
--partition "partition_table/partition-table.bin"
--use-partition-file "${build_dir}/partition_table/partition-table.bin"
--use-parttool ${idf_path}/components/partition_table/parttool.py
--use-sdkconfig ${project_path}/sdkconfig
WORKING_DIRECTORY ${build_dir}
COMMENT "To flash ${build_dir}/${CMAKE_PROJECT_NAME}.bin run ./build/${CMAKE_PROJECT_NAME}.flash.py"
VERBATIM)

add_custom_target(flashing_script DEPENDS "${build_dir}/${CMAKE_PROJECT_NAME}.bin" "${build_dir}/${CMAKE_PROJECT_NAME}.flash.py" "${build_dir}/esp32_firmware_utils.py" "${build_dir}/firmware_utils.py")
20 changes: 20 additions & 0 deletions examples/all-clusters-app/esp32/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ control.
- [Setting up Python Controller](#setting-up-python-controller)
- [Commissioning over BLE](#commissioning-over-ble)
- [Cluster control](#cluster-control)
- [Flashing app using script](#flashing-app-using-script)
- [Note](#note)

---
Expand Down Expand Up @@ -214,6 +215,25 @@ commissioning and cluster control.

`chip-device-ctrl > zcl OnOff Off 135246 1 0`

### Flashing app using script

- Follow these steps to use `${app_name}.flash.py`.

- First set IDF target, run set-target with one of the commands.

$ idf.py set-target esp32
$ idf.py set-target esp32c3

- Execute below sequence of commands

```
$ export ESPPORT=/dev/tty.SLAB_USBtoUART
$ export ESPBAUD=${baud_value}
$ idf.py build
$ idf.py flashing_script
$ python ${app_name}.flash.py
```

### Note

This demo app illustrates controlling OnOff cluster (Server) attributes of an
Expand Down
35 changes: 35 additions & 0 deletions examples/persistent-storage/esp32/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,38 @@ set(EXTRA_COMPONENT_DIRS
project(persistent-storage)
idf_build_set_property(CXX_COMPILE_OPTIONS "-std=gnu++14;-Os;-DLWIP_IPV6_SCOPES=0;-DCHIP_HAVE_CONFIG_H" APPEND)
idf_build_set_property(C_COMPILE_OPTIONS "-Os;-DLWIP_IPV6_SCOPES=0" APPEND)

idf_build_get_property(build_dir BUILD_DIR)
idf_build_get_property(project_path PROJECT_DIR)
idf_build_get_property(sdkconfig SDKCONFIG)
idf_build_get_property(idf_path IDF_PATH)

add_custom_command(OUTPUT "${build_dir}/firmware_utils.py"
COMMAND ${CMAKE_COMMAND} ARGS -E copy "${project_path}/third_party/connectedhomeip/scripts/flashing/firmware_utils.py" "${build_dir}/"
WORKING_DIRECTORY ${build_dir}
VERBATIM)

add_custom_command(OUTPUT "${build_dir}/esp32_firmware_utils.py"
COMMAND ${CMAKE_COMMAND} ARGS -E copy "${project_path}/third_party/connectedhomeip/scripts/flashing/esp32_firmware_utils.py" "${build_dir}/"
WORKING_DIRECTORY ${build_dir}
VERBATIM)

add_custom_command(OUTPUT "${build_dir}/${CMAKE_PROJECT_NAME}.flash.py"
COMMAND ${python}
"${project_path}/../../../scripts/flashing/gen_flashing_script.py" esp32
--output "${build_dir}/${CMAKE_PROJECT_NAME}.flash.py"
--port "$ENV{ESPPORT}"
--baud "$ENV{ESPBAUD}"
--before ${CONFIG_ESPTOOLPY_BEFORE}
--after ${CONFIG_ESPTOOLPY_AFTER}
--application "${CMAKE_PROJECT_NAME}.bin"
--bootloader "bootloader/bootloader.bin"
--partition "partition_table/partition-table.bin"
--use-partition-file "${build_dir}/partition_table/partition-table.bin"
--use-parttool ${idf_path}/components/partition_table/parttool.py
--use-sdkconfig ${project_path}/sdkconfig
WORKING_DIRECTORY ${build_dir}
COMMENT "To flash ${build_dir}/${CMAKE_PROJECT_NAME}.bin run ./build/${CMAKE_PROJECT_NAME}.flash.py"
VERBATIM)

add_custom_target(flashing_script DEPENDS "${build_dir}/${CMAKE_PROJECT_NAME}.bin" "${build_dir}/${CMAKE_PROJECT_NAME}.flash.py" "${build_dir}/esp32_firmware_utils.py" "${build_dir}/firmware_utils.py")
20 changes: 20 additions & 0 deletions examples/persistent-storage/esp32/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ An example testing and demonstrating the key value storage API.
- [Building](#building)
- [Flashing the Application](#flashing-the-application)
- [Viewing Logging Output](#viewing-logging-output)
- [Flashing app using script](#flashing-app-using-script)

<hr>

Expand Down Expand Up @@ -106,6 +107,25 @@ make sure the IDF_PATH has been exported(See the manual setup steps above).

<a name="view-logging"></a>

### Flashing app using script

- Follow these steps to use `${app_name}.flash.py`.

- First set IDF target, run set-target with one of the commands.

$ idf.py set-target esp32
$ idf.py set-target esp32c3

- Execute below sequence of commands

```
$ export ESPPORT=/dev/tty.SLAB_USBtoUART
$ export ESPBAUD=${baud_value}
$ idf.py build
$ idf.py flashing_script
$ python ${app_name}.flash.py
```

### Viewing Logging Output

The output of the test will be streamed out of the UART and can be observed with
Expand Down
45 changes: 45 additions & 0 deletions examples/pigweed-app/esp32/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,48 @@ set(EXTRA_COMPONENT_DIRS
project(chip-pigweed-app)
idf_build_set_property(CXX_COMPILE_OPTIONS "-std=gnu++17;-Os;-DLWIP_IPV6_SCOPES=0;-DCHIP_HAVE_CONFIG_H" APPEND)
idf_build_set_property(C_COMPILE_OPTIONS "-Os;-DLWIP_IPV6_SCOPES=0" APPEND)

idf_build_get_property(build_dir BUILD_DIR)
idf_build_get_property(project_path PROJECT_DIR)
idf_build_get_property(sdkconfig SDKCONFIG)
idf_build_get_property(idf_path IDF_PATH)

add_custom_command(OUTPUT "${build_dir}/firmware_utils.py"
COMMAND ${CMAKE_COMMAND} ARGS -E copy "${project_path}/third_party/connectedhomeip/scripts/flashing/firmware_utils.py" "${build_dir}/"
WORKING_DIRECTORY ${build_dir}
VERBATIM)

add_custom_command(OUTPUT "${build_dir}/esp32_firmware_utils.py"
COMMAND ${CMAKE_COMMAND} ARGS -E copy "${project_path}/third_party/connectedhomeip/scripts/flashing/esp32_firmware_utils.py" "${build_dir}/"
WORKING_DIRECTORY ${build_dir}
VERBATIM)

add_custom_command(OUTPUT "${build_dir}/echo_test.py"
COMMAND ${CMAKE_COMMAND} ARGS -E copy "${project_path}/../mobly_tests/echo_test.py" "${build_dir}/"
WORKING_DIRECTORY ${build_dir}
VERBATIM)

add_custom_command(OUTPUT "${build_dir}/echo_test_config.yml"
COMMAND ${CMAKE_COMMAND} ARGS -E copy "${project_path}/echo_test_config.yml" "${build_dir}/"
WORKING_DIRECTORY ${build_dir}
VERBATIM)

add_custom_command(OUTPUT "${build_dir}/${CMAKE_PROJECT_NAME}.flash.py"
COMMAND ${python}
"${project_path}/../../../scripts/flashing/gen_flashing_script.py" esp32
--output "${build_dir}/${CMAKE_PROJECT_NAME}.flash.py"
--port "$ENV{ESPPORT}"
--baud "$ENV{ESPBAUD}"
--before ${CONFIG_ESPTOOLPY_BEFORE}
--after ${CONFIG_ESPTOOLPY_AFTER}
--application "${CMAKE_PROJECT_NAME}.bin"
--bootloader "bootloader/bootloader.bin"
--partition "partition_table/partition-table.bin"
--use-partition-file "${build_dir}/partition_table/partition-table.bin"
--use-parttool ${idf_path}/components/partition_table/parttool.py
--use-sdkconfig ${project_path}/sdkconfig
WORKING_DIRECTORY ${build_dir}
COMMENT "To flash ${build_dir}/${CMAKE_PROJECT_NAME}.bin run ./build/${CMAKE_PROJECT_NAME}.flash.py"
VERBATIM)

add_custom_target(flashing_script DEPENDS "${build_dir}/${CMAKE_PROJECT_NAME}.bin" "${build_dir}/${CMAKE_PROJECT_NAME}.flash.py" "${build_dir}/esp32_firmware_utils.py" "${build_dir}/firmware_utils.py" "${build_dir}/echo_test.py" "${build_dir}/echo_test_config.yml")
19 changes: 19 additions & 0 deletions examples/pigweed-app/esp32/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,25 @@ To download and install packages.
[VCP driver](https://www.silabs.com/products/development-tools/software/usb-to-uart-bridge-vcp-drivers)
before the device shows up on `/dev/tty`.

### Flashing app using script

- Follow these steps to use `${app_name}.flash.py`.

- First set IDF target, run set-target with one of the commands.

$ idf.py set-target esp32
$ idf.py set-target esp32c3

- Execute below sequence of commands

```
$ export ESPPORT=/dev/tty.SLAB_USBtoUART
$ export ESPBAUD=${baud_value}
$ idf.py build
$ idf.py flashing_script
$ python ${app_name}.flash.py
```

## Testing the Example Application

Run the following command to start an interactive Python shell, where the Echo
Expand Down
35 changes: 35 additions & 0 deletions examples/temperature-measurement-app/esp32/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,38 @@ set(EXTRA_COMPONENT_DIRS
project(chip-temperature-measurement-app)
idf_build_set_property(CXX_COMPILE_OPTIONS "-std=gnu++14;-Os;-DLWIP_IPV6_SCOPES=0;-DCHIP_HAVE_CONFIG_H" APPEND)
idf_build_set_property(C_COMPILE_OPTIONS "-Os;-DLWIP_IPV6_SCOPES=0" APPEND)

idf_build_get_property(build_dir BUILD_DIR)
idf_build_get_property(project_path PROJECT_DIR)
idf_build_get_property(sdkconfig SDKCONFIG)
idf_build_get_property(idf_path IDF_PATH)

add_custom_command(OUTPUT "${build_dir}/firmware_utils.py"
COMMAND ${CMAKE_COMMAND} ARGS -E copy "${project_path}/third_party/connectedhomeip/scripts/flashing/firmware_utils.py" "${build_dir}/"
WORKING_DIRECTORY ${build_dir}
VERBATIM)

add_custom_command(OUTPUT "${build_dir}/esp32_firmware_utils.py"
COMMAND ${CMAKE_COMMAND} ARGS -E copy "${project_path}/third_party/connectedhomeip/scripts/flashing/esp32_firmware_utils.py" "${build_dir}/"
WORKING_DIRECTORY ${build_dir}
VERBATIM)

add_custom_command(OUTPUT "${build_dir}/${CMAKE_PROJECT_NAME}.flash.py"
COMMAND ${python}
"${project_path}/../../../scripts/flashing/gen_flashing_script.py" esp32
--output "${build_dir}/${CMAKE_PROJECT_NAME}.flash.py"
--port "$ENV{ESPPORT}"
--baud "$ENV{ESPBAUD}"
--before ${CONFIG_ESPTOOLPY_BEFORE}
--after ${CONFIG_ESPTOOLPY_AFTER}
--application "${CMAKE_PROJECT_NAME}.bin"
--bootloader "bootloader/bootloader.bin"
--partition "partition_table/partition-table.bin"
--use-partition-file "${build_dir}/partition_table/partition-table.bin"
--use-parttool ${idf_path}/components/partition_table/parttool.py
--use-sdkconfig ${project_path}/sdkconfig
WORKING_DIRECTORY ${build_dir}
COMMENT "To flash ${build_dir}/${CMAKE_PROJECT_NAME}.bin run ./build/${CMAKE_PROJECT_NAME}.flash.py"
VERBATIM)

add_custom_target(flashing_script DEPENDS "${build_dir}/${CMAKE_PROJECT_NAME}.bin" "${build_dir}/${CMAKE_PROJECT_NAME}.flash.py" "${build_dir}/esp32_firmware_utils.py" "${build_dir}/firmware_utils.py")
20 changes: 20 additions & 0 deletions examples/temperature-measurement-app/esp32/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This example is meant to represent a minimal-sized application.
- [Setting up Python Controller](#setting-up-python-controller)
- [Commissioning over BLE](#commissioning-over-ble)
- [Cluster control](#cluster-control)
- [Flashing app using script](#flashing-app-using-script)
- [Optimization](#optimization)

---
Expand Down Expand Up @@ -185,6 +186,25 @@ commissioning and cluster control.

`chip-device-ctrl > zcl Basic MfgSpecificPing 135246 1 0`

### Flashing app using script

- Follow these steps to use `${app_name}.flash.py`.

- First set IDF target, run set-target with one of the commands.

$ idf.py set-target esp32
$ idf.py set-target esp32c3

- Execute below sequence of commands

```
$ export ESPPORT=/dev/tty.SLAB_USBtoUART
$ export ESPBAUD=${baud_value}
$ idf.py build
$ idf.py flashing_script
$ python ${app_name}.flash.py
```

## Optimization

Optimization related to WiFi, BLuetooth, Asserts etc are the part of this
Expand Down
3 changes: 2 additions & 1 deletion scripts/flashing/esp32_firmware_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,11 @@
},
'bootloader_offset': {
'help': 'Bootloader offset',
'default': '0x1000',
'default': None,
'argparse': {
'metavar': 'OFFSET'
},
'sdkconfig': 'CONFIG_BOOTLOADER_OFFSET_IN_FLASH',
},
'partition': {
'help': 'Partition table image',
Expand Down

0 comments on commit 445d404

Please sign in to comment.