Skip to content

Commit cd295b9

Browse files
committed
Merge branch 'feat/enable_port_c_for_m5stack' into 'main'
feat: add support for Unit Gateway H2 in the M5Stack example See merge request espressif/esp-thread-br!173
2 parents ab57a81 + 8ecde3b commit cd295b9

File tree

9 files changed

+128
-10
lines changed

9 files changed

+128
-10
lines changed
Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,38 @@
11
menu "ESP Thread Border Router M5Stack Example"
22

3-
config OPENTHREAD_EPHEMERALKEY_LIFE_TIME
4-
int "The life time (seconds) of openthread ephemeral key"
5-
default 100
3+
choice RADIO_CO_PROCESSOR_MODE
4+
prompt "IEEE 802.15.4 Radio Co-Processor Mode"
5+
default RADIO_CO_PROCESSOR_MODULE_H2
66
help
7-
Set the lifetime of the OpenThread ephemeral key in seconds.
7+
Select the target hardware configuration for the IEEE 802.15.4 Radio Co-Processor.
88

9-
config OPENTHREAD_EPHEMERALKEY_PORT
10-
int "The UDP port to use with the ephemeral key"
11-
default 49180
12-
help
13-
Set the UDP port to use with the ephemeral key.
9+
config RADIO_CO_PROCESSOR_MODULE_H2
10+
bool "Module Gateway H2"
11+
help
12+
Select this if you are using a Module Gateway H2.
13+
14+
config RADIO_CO_PROCESSOR_UNIT_H2
15+
bool "Unit Gateway H2"
16+
help
17+
Select this if you are using a Unit Gateway H2, the following must be ensured:
18+
1. Connect the CoreS3 and Module Gateway H2 via PORT C.
19+
2. Disable the AUTO_UPDATE_RCP feature.
20+
3. Set PIN_TO_RCP_TX to 18 and PIN_TO_RCP_RX to 17.
21+
endchoice # RADIO_CO_PROCESSOR_MODE
22+
23+
menu "Thread Ephemeral Key Configurations"
24+
config OPENTHREAD_EPHEMERALKEY_LIFE_TIME
25+
int "The life time (seconds) of openthread ephemeral key"
26+
default 100
27+
help
28+
Set the lifetime of the OpenThread ephemeral key in seconds.
29+
30+
config OPENTHREAD_EPHEMERALKEY_PORT
31+
int "The UDP port to use with the ephemeral key"
32+
default 49180
33+
help
34+
Set the UDP port to use with the ephemeral key.
35+
36+
endmenu
1437

1538
endmenu
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: CC0-1.0
5+
*
6+
*/
7+
8+
#pragma once
9+
10+
#include "esp_err.h"
11+
12+
#define BSP_AW9523_ADDR 0x58
13+
#define CORE_S3_BUS_OUT_EN BIT(1)
14+
#define CORE_S3_BOOST_EN BIT(7)
15+
16+
#ifdef __cplusplus
17+
extern "C" {
18+
#endif
19+
20+
esp_err_t br_m5stack_enable_port_c_power(void);
21+
22+
#ifdef __cplusplus
23+
} /* extern "C" */
24+
#endif

examples/common/thread_border_router_m5stack/src/border_router_m5stack.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,17 @@
99

1010
#include "br_m5stack_animation.h"
1111
#include "br_m5stack_layout.h"
12+
#include "br_m5stack_power.h"
1213

1314
#include "esp_err.h"
1415
#include "bsp/esp-bsp.h"
1516

1617
static void ot_br_m5stack_worker(void *ctx)
1718
{
1819
br_m5stack_bsp_init();
20+
#if CONFIG_RADIO_CO_PROCESSOR_UNIT_H2
21+
ESP_ERROR_CHECK(br_m5stack_enable_port_c_power());
22+
#endif
1923
br_m5stack_display_init();
2024
boot_animation_start(br_m5stack_create_ui);
2125

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: CC0-1.0
5+
*
6+
*/
7+
8+
#include "br_m5stack_power.h"
9+
#include "br_m5stack_common.h"
10+
11+
#include "esp_check.h"
12+
#include "esp_err.h"
13+
#include "bsp/esp-bsp.h"
14+
15+
esp_err_t br_m5stack_enable_port_c_power(void)
16+
{
17+
esp_err_t ret = ESP_OK;
18+
uint8_t data[2];
19+
uint8_t val = 0;
20+
21+
data[0] = 0x02;
22+
ESP_GOTO_ON_ERROR(i2c_master_write_read_device(BSP_I2C_NUM, BSP_AW9523_ADDR, data, 1, &val, 1, pdMS_TO_TICKS(1000)),
23+
exit, "", "");
24+
data[1] = val | CORE_S3_BUS_OUT_EN;
25+
ESP_GOTO_ON_ERROR(i2c_master_write_to_device(BSP_I2C_NUM, BSP_AW9523_ADDR, data, sizeof(data), pdMS_TO_TICKS(1000)),
26+
exit, "", "");
27+
28+
data[0] = 0x03;
29+
ESP_GOTO_ON_ERROR(i2c_master_write_read_device(BSP_I2C_NUM, BSP_AW9523_ADDR, data, 1, &val, 1, pdMS_TO_TICKS(1000)),
30+
exit, "", "");
31+
data[1] = val | CORE_S3_BOOST_EN;
32+
ESP_GOTO_ON_ERROR(i2c_master_write_to_device(BSP_I2C_NUM, BSP_AW9523_ADDR, data, sizeof(data), pdMS_TO_TICKS(1000)),
33+
exit, "", "");
34+
35+
data[0] = 0x11;
36+
data[1] = 0x10;
37+
ret = i2c_master_write_to_device(BSP_I2C_NUM, BSP_AW9523_ADDR, data, sizeof(data), pdMS_TO_TICKS(1000));
38+
39+
exit:
40+
if (ret != ESP_OK) {
41+
ESP_LOGE(BR_M5STACK_TAG, "Failed to enable PORT.C for M5Stack.");
42+
}
43+
return ret;
44+
}

examples/m5stack_thread_border_router/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,19 @@ It connects to a pre-configured Wi-Fi network and automatically forms a Thread n
1313
This example requires the M5Stack CoreS3 along with the ESP32-H2 Thread/Zigbee Gateway Module. Please refer to:
1414

1515
- [M5Stack CoreS3](https://shop.m5stack.com/products/m5stack-cores3-esp32s3-lotdevelopment-kit)
16+
<p align="center">
17+
<img src="images/M5Stack-CoreS3.png" alt="M5Stack CoreS3" width="400"/>
18+
</p>
19+
1620
- [ESP32-H2 Thread/Zigbee Gateway Module](https://shop.m5stack.com/products/esp32-h2-thread-zigbee-gateway-module)
21+
<p align="center">
22+
<img src="images/ESP32-H2-Thread-Zigbee-Gateway-Module.png" alt="ESP32-H2 Thread/Zigbee Gateway Module" width="400"/>
23+
</p>
24+
25+
- [ESP32-H2 Thread/Zigbee Gateway Unit](https://shop.m5stack.com/products/esp32-h2-thread-zigbee-gateway-unit)
26+
<p align="center">
27+
<img src="images/ESP32-H2-Thread-Zigbee-Gateway-Unit.png" alt="ESP32-H2 Thread/Zigbee Gateway Unit" width="400"/>
28+
</p>
1729

1830
### IDF Version Required
1931

@@ -56,3 +68,14 @@ Upon startup, the device will connect to the pre-configured Wi-Fi network and jo
5668
4. `Thread`: This button is used to view and configure basic Thread parameters.
5769

5870
This example can be used in conjunction with an external Commissioner such as `ot-commissioner`. The ephemeral key allows the Commissioner to connect to the Thread Border Router over Wi-Fi. Once connected, the Commissioner can retrieve or configure parameters for the Border Router and its child nodes via the same network.
71+
72+
### Adapting to Unit Gateway H2
73+
The above configuration process is intended for use with the [Module Gateway H2](https://docs.m5stack.com/en/module/Module%20Gateway%20H2). If you are using the [Unit Gateway H2](https://docs.m5stack.com/en/unit/Unit%20Gateway%20H2), please follow the steps below:
74+
75+
1. Hardware Setup: Prepare a Unit Gateway H2 flashed with `ot_rcp` and connect it to the M5Stack via `PORT.C`.
76+
2. Build Configuration:
77+
* Enable the `RADIO_CO_PROCESSOR_UNIT_H2` feature via menuconfig.
78+
* Disable the `AUTO_UPDATE_RCP` feature via menuconfig.
79+
* Set `PIN_TO_RCP_TX` to `18` and `PIN_TO_RCP_RX` to `17` via menuconfig.
80+
81+
After that, build and flash as usual. The example will then operate using the Unit Gateway H2.
42.5 KB
Loading
16.4 KB
Loading
28.5 KB
Loading

examples/m5stack_thread_border_router/main/esp_ot_br.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,6 @@ void app_main(void)
121121
esp_br_web_start("/spiffs");
122122
#endif
123123

124-
launch_openthread_border_router(&platform_config, &rcp_update_config);
125124
ESP_ERROR_CHECK(border_router_m5stack_init());
125+
launch_openthread_border_router(&platform_config, &rcp_update_config);
126126
}

0 commit comments

Comments
 (0)