Skip to content

Commit

Permalink
add ESP32C3-DevKitM support to ESP32 all-clusters-app
Browse files Browse the repository at this point in the history
  • Loading branch information
wqx6 committed May 26, 2021
1 parent 3bdeaf6 commit 4d947e8
Show file tree
Hide file tree
Showing 11 changed files with 124 additions and 26 deletions.
3 changes: 3 additions & 0 deletions config/esp32/components/chip/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ if(NOT CONFIG_USE_MINIMAL_MDNS)
list(APPEND chip_libraries $<TARGET_FILE:${mdns_lib}>)
endif()

idf_component_get_property(main_lib main COMPONENT_LIB)
list(APPEND chip_libraries $<TARGET_FILE:${main_lib}>)

target_link_libraries(${COMPONENT_LIB} INTERFACE -Wl,--start-group
${chip_libraries}
$<TARGET_FILE:mbedcrypto> $<TARGET_FILE:${esp32_mbedtls_lib}>
Expand Down
10 changes: 8 additions & 2 deletions examples/all-clusters-app/esp32/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,17 @@ include($ENV{IDF_PATH}/tools/cmake/project.cmake)
# The list of extra component dirs must be in sync with that in all-clusters-app/esp32/Makefile
set(EXTRA_COMPONENT_DIRS
"${CMAKE_CURRENT_LIST_DIR}/third_party/connectedhomeip/config/esp32/components"
"${CMAKE_CURRENT_LIST_DIR}/../../common/m5stack-tft/repo/components"
"${CMAKE_CURRENT_LIST_DIR}/../../common/QRCode"
)
if(${IDF_TARGET} STREQUAL "esp32")
set(EXTRA_COMPONENT_DIRS
${EXTRA_COMPONENT_DIRS}
"${CMAKE_CURRENT_LIST_DIR}/../../common/m5stack-tft/repo/components/tft"
"${CMAKE_CURRENT_LIST_DIR}/../../common/m5stack-tft/repo/components/spidriver"
"${CMAKE_CURRENT_LIST_DIR}/../../common/screen-framework"
)
endif()

project(chip-all-clusters-app)
idf_build_set_property(CXX_COMPILE_OPTIONS "-std=c++14;-Os;-DLWIP_IPV6_SCOPES=0;-DCHIP_HAVE_CONFIG_H" APPEND)
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)
14 changes: 8 additions & 6 deletions examples/all-clusters-app/esp32/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@
PROJECT_NAME := chip-all-clusters-app

# The list of extra component dirs must be in sync with that in all-clusters-app/esp32/CMakeLists.txt
EXTRA_COMPONENT_DIRS += $(PROJECT_PATH)/third_party/connectedhomeip/config/esp32/components \
$(PROJECT_PATH)/../../common/m5stack-tft/repo/components \
$(PROJECT_PATH)/../../common/QRCode \
$(PROJECT_PATH)/../../common/screen-framework \

CXXFLAGS += -std=c++14 -Os -DLWIP_IPV6_SCOPES=0
EXTRA_COMPONENT_DIRS += $(PROJECT_PATH)/third_party/connectedhomeip/config/esp32/components \
$(PROJECT_PATH)/../../common/QRCode \
ifeq($(IDF_TARGET),'esp32')
EXTRA_COMPONENT_DIRS += $(PROJECT_PATH)/../../common/m5stack-tft/repo/components/tft \
$(PROJECT_PATH)/../../common/m5stack-tft/repo/components/spidriver \
$(PROJECT_PATH)/../../common/screen-framework \
endif
CXXFLAGS += -std=gnu++14 -Os -DLWIP_IPV6_SCOPES=0
CPPFLAGS += -Os -DLWIP_IPV6_SCOPES=0 -DCHIP_HAVE_CONFIG_H
CFLAGS += -Os -DLWIP_IPV6_SCOPES=0

Expand Down
36 changes: 24 additions & 12 deletions examples/all-clusters-app/esp32/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# CHIP All Clusters Example

A prototype application that uses CHIP to setup WiFi on the ESP32 and runs an
Echo Server. This example will evolve as more complex messaging is supported in
CHIP.
A prototype application that uses CHIP to setup WiFi on the ESP32&ESP32C3 and
runs an Echo Server. This example will evolve as more complex messaging is
supported in CHIP.

---

Expand All @@ -18,28 +18,30 @@ CHIP.

## Supported Devices

The CHIP demo application is intended to work on two categories of ESP32
devices: the
The CHIP demo application is intended to work on two categories of ESP32 devices
and one categories ESP32C3 device: the
[ESP32-DevKitC](https://www.espressif.com/en/products/hardware/esp32-devkitc/overview),
and the [M5Stack](http://m5stack.com). On the [M5Stack](http://m5stack.com) this
example displays a CHIP QRCode with the device's Soft-AP SSID encoded in the TLV
section.
the [M5Stack](http://m5stack.com) and the
[ESP32C3-DevKitM](https://docs.espressif.com/projects/esp-idf/en/latest/esp32c3/hw-reference/esp32c3/user-guide-devkitm-1.html).
On the [M5Stack](http://m5stack.com) this example displays a CHIP QRCode with
the device's Soft-AP SSID encoded in the TLV section.

## Building the Example Application

Building the example application requires the use of the Espressif ESP32 IoT
Development Framework and the xtensa-esp32-elf toolchain.
Development Framework and the xtensa-esp32-elf toolchain for ESP32 or the
riscv-esp32-elf toolchain for ESP32C3.

The VSCode devcontainer has these components pre-installed, so you can skip this
step. To install these components manually, follow these steps:

- Clone the Espressif ESP-IDF and checkout release/v4.2 branch
- Clone the Espressif ESP-IDF and checkout release/v4.3 branch

$ mkdir ${HOME}/tools
$ cd ${HOME}/tools
$ git clone https://github.com/espressif/esp-idf.git
$ cd esp-idf
$ git checkout release/v4.2
$ git checkout release/v4.3
$ git submodule update --init
$ export IDF_PATH=${HOME}/tools/esp-idf
$ ./install.sh
Expand Down Expand Up @@ -76,18 +78,28 @@ If packages are already installed then simply activate it.

- Configuration Options

To choose the module, run set-target

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

To choose from the different configuration options, run menuconfig

$ idf.py menuconfig

Select ESP32 based `Device Type` through `Demo`->`Device Type`.
The device types that are currently supported include `ESP32-DevKitC` (default),
`ESP32-WROVER-KIT_V4.1` and `M5Stack`
`ESP32-WROVER-KIT_V4.1`, `M5Stack` and `ESP32C3-DevKitM`

If you are using `standalone chip-tool` to communicate with the ESP32, bypass the
Rendezvous mode so that the device can communicate over an insecure channel.
This can be done through `Demo`->`Rendezvous Mode`->`Bypass`

If you are using `ESP32C3-DevKitM` and need BLEAdvertising, please enable host based
privacy for random address through `Component config`->`Bluetooth`->'NimBLE Options'->
`enable host based privacy form random address`.

To connect the ESP32 to your network, configure the Wi-Fi SSID and Passphrase through
`Component config`->`CHIP Device Layer`->`WiFi Station Options`->`Default WiFi SSID` and
`Default WiFi Password` respectively.
Expand Down
31 changes: 28 additions & 3 deletions examples/all-clusters-app/esp32/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@

# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)
# The list of src and include dirs must be in sync with that in all-clusters-app/esp32/main/component.mk
idf_component_register(PRIV_INCLUDE_DIRS
set(PRIV_INCLUDE_DIRS_GROUPS
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/all-clusters-app/all-clusters-common"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/third_party/nlio/repo/include"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src"
"${CMAKE_CURRENT_LIST_DIR}/include"
SRC_DIRS
)
set(SRC_DIRS_GROUPS
"${CMAKE_CURRENT_LIST_DIR}"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/all-clusters-app/all-clusters-common/gen"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/server"
Expand Down Expand Up @@ -51,7 +52,31 @@ idf_component_register(PRIV_INCLUDE_DIRS
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/door-lock-server"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/ias-zone-server"
#${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/ias-zone-client
PRIV_REQUIRES chip QRCode tft spidriver bt screen-framework)
)

if(${CONFIG_DEVICE_TYPE_ESP32_C3_DEVKITM})
set(PRIV_INCLUDE_DIRS_GROUPS ${PRIV_INCLUDE_DIRS_GROUPS}
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/common/screen-framework/include")
set(PRIV_REQUIRES_GROUPS chip QRCode bt)
endif()

if(${CONFIG_DEVICE_TYPE_ESP32_DEVKITC})
set(PRIV_INCLUDE_DIRS_GROUPS ${PRIV_INCLUDE_DIRS_GROUPS}
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/common/screen-framework/include")
set(PRIV_REQUIRES_GROUPS chip QRCode bt)
endif()

if(${CONFIG_DEVICE_TYPE_ESP32_WROVER_KIT})
set(PRIV_REQUIRES_GROUPS chip QRCode bt tft spidrier screen-framework)
endif()

if(${CONFIG_DEVICE_TYPE_M5STACK})
set(PRIV_REQUIRES_GROUPS chip QRCode bt tft spidrier screen-framework)
endif()

idf_component_register(PRIV_INCLUDE_DIRS ${PRIV_INCLUDE_DIRS_GROUPS}
SRC_DIRS ${SRC_DIRS_GROUPS}
PRIV_REQUIRES ${PRIV_REQUIRES_GROUPS})

set_property(TARGET ${COMPONENT_LIB} PROPERTY CXX_STANDARD 14)
target_compile_options(${COMPONENT_LIB} PRIVATE "-DLWIP_IPV6_SCOPES=0" "-DCHIP_HAVE_CONFIG_H")
3 changes: 3 additions & 0 deletions examples/all-clusters-app/esp32/main/Kconfig.projbuild
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ menu "Demo"
bool "ESP32-WROVER-KIT_V4.1"
config DEVICE_TYPE_M5STACK
bool "M5Stack"
config DEVICE_TYPE_ESP32_C3_DEVKITM
bool "EXP32C3-DevKitM"
endchoice

choice
Expand Down Expand Up @@ -71,6 +73,7 @@ menu "Demo"
int
range 0 5
default 0 if DEVICE_TYPE_ESP32_DEVKITC
default 0 if DEVICE_TYPE_ESP32_C3_DEVKITM
default 3 if DEVICE_TYPE_M5STACK
default 4 if DEVICE_TYPE_ESP32_WROVER_KIT

Expand Down
23 changes: 21 additions & 2 deletions examples/all-clusters-app/esp32/main/component.mk
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@
#
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)

COMPONENT_DEPENDS := chip QRCode tft spidriver
COMPONENT_DEPENDS := chip QRCode

ifdef $(CONFIG_DEVICE_TYPE_M5STACK)
COMPONENT_DEPENDS += spidriver tft
endif

ifdef $(CONFIG_DEVICE_TYPE_ESP32_WROVER_KIT)
COMPONENT_DEPENDS += spidriver tft
endif

# The list of src and include dirs must be in sync with that in all-clusters-app/esp32/main/CMakeLists.txt
COMPONENT_SRCDIRS := \
Expand Down Expand Up @@ -64,7 +72,18 @@ COMPONENT_EXTRA_INCLUDES := $(PROJECT_PATH)/third_party/connectedhomeip/src/app/
$(PROJECT_PATH)/third_party/connectedhomeip/src/app/server \
$(PROJECT_PATH)/third_party/connectedhomeip/examples/all-clusters-app/all-clusters-common \
$(PROJECT_PATH)/third_party/connectedhomeip/third_party/nlio/repo/include \
$(PROJECT_PATH)/third_party/connectedhomeip/src
$(PROJECT_PATH)/third_party/connectedhomeip/src \

ifdef $(CONFIG_DEVICE_TYPE_ESP32_C3_DEVKITM)
COMPONENT_EXTRA_INCLUDES += $(PROJECT_PATH)/third_party/connectedhomeip/examples/common/screen-framework/include \

endif

ifdef $(CONFIG_DEVICE_TYPE_ESP32_DEVKITC)
COMPONENT_EXTRA_INCLUDES += $(PROJECT_PATH)/third_party/connectedhomeip/examples/common/screen-framework/include \

endif


# So "gen/*" files are found by the src/app bits.
COMPONENT_PRIV_INCLUDEDIRS := .
4 changes: 4 additions & 0 deletions examples/all-clusters-app/esp32/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ using namespace ::chip::DeviceLayer;

#define STATUS_LED_GPIO_NUM GPIO_NUM_2 // Use LED1 (blue LED) as status LED on DevKitC

#elif CONFIG_DEVICE_TYPE_ESP32_C3_DEVKITM

#define STATUS_LED_GPIO_NUM GPIO_NUM_2

#else // !CONFIG_DEVICE_TYPE_ESP32_DEVKITC

#error "Unsupported device type selected"
Expand Down
22 changes: 22 additions & 0 deletions src/lib/core/CHIPTLV.h
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,17 @@ class DLL_EXPORT TLVWriter
*/
CHIP_ERROR Put(uint64_t tag, int32_t v);

/*
* @overload CHIP_ERROR TLVWriter::Put(uint64_t tag, int8_t v)
* riscv toolchain of esp-idf defines int32_t from long int instead of int
*/
#ifdef __riscv
CHIP_ERROR Put(uint64_t tag, int v)
{
return Put(tag, static_cast<int32_t>(v));
};
#endif

/**
* @overload CHIP_ERROR TLVWriter::Put(uint64_t tag, int8_t v, bool preserveSize)
*/
Expand Down Expand Up @@ -1032,6 +1043,17 @@ class DLL_EXPORT TLVWriter
*/
CHIP_ERROR Put(uint64_t tag, uint32_t v);

/*
* @overload CHIP_ERROR TLVWriter::Put(uint64_t tag, int8_t v)
* riscv toolchain of esp-idf defines int32_t from long int instead of int
*/
#ifdef __riscv
CHIP_ERROR Put(uint64_t tag, unsigned int v)
{
return Put(tag, static_cast<uint32_t>(v));
};
#endif

/**
* @overload CHIP_ERROR TLVWriter::Put(uint64_t tag, uint8_t v, bool preserveSize)
*/
Expand Down
2 changes: 1 addition & 1 deletion src/platform/ESP32/PlatformManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack(void)
esp_fill_random(ap_mac, sizeof(ap_mac));
/* Bit 0 of the first octet of MAC Address should always be 0 */
ap_mac[0] &= (uint8_t) ~0x01;
err = esp_wifi_set_mac(ESP_IF_WIFI_AP, ap_mac);
err = esp_wifi_set_mac(WIFI_IF_AP, ap_mac);
SuccessOrExit(err);
}

Expand Down
2 changes: 2 additions & 0 deletions src/platform/ESP32/nimble/BLEManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1117,6 +1117,7 @@ CHIP_ERROR BLEManagerImpl::StartAdvertising(void)
return err;
}
}
#if CONFIG_BT_NIMBLE_HOST_BASED_PRIVACY
else
{
err = MapBLEError(ble_hs_pvcy_rpa_config(NIMBLE_HOST_ENABLE_RPA));
Expand All @@ -1126,6 +1127,7 @@ CHIP_ERROR BLEManagerImpl::StartAdvertising(void)
return err;
}
}
#endif
err = MapBLEError(ble_gap_adv_start(own_addr_type, NULL, BLE_HS_FOREVER, &adv_params, ble_svr_gap_event, NULL));
if (err == CHIP_NO_ERROR)
{
Expand Down

0 comments on commit 4d947e8

Please sign in to comment.