Skip to content

Commit 608f05b

Browse files
committed
Merge branch 'nw_split_linux_wip5' into 'master'
fix(nw_split): Disable Network split for ESP32-C2 and ESP32-C3 See merge request app-frameworks/esp_hosted!577
2 parents c273b00 + e8f76bb commit 608f05b

File tree

20 files changed

+145
-268
lines changed

20 files changed

+145
-268
lines changed

esp_hosted_fg/docs/Linux_based_host/UART_setup.md

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
| Supported Chipsets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-S3 | ESP32-C6 | ESP32-C5 | ESP32-S2 |
44
| ------------------ | :---: | :------: | :------: | :------: | :------: | :------: | :------: |
5-
| 4 line UART | Y | N | Y | Y | N | N | Y |
6-
| 2 line UART | N | Y | N | N | Y | Y | N |
5+
| 4 line UART | T | NT | T | T | NT | NT | T |
6+
| 2 line UART | NT | T | NT | NT | T | T | NT |
77

8-
Y - **Tested**, N - **Not Tested**
8+
T - **Tested**, NT - **Not Tested**
99

1010
In this section, ESP chipset provides a way to run Bluetooth/BLE over UART interface.
1111
Please connect ESP peripheral to Raspberry-Pi with jumper cables (preferably PCB) as mentioned below.
@@ -28,6 +28,12 @@ Raspberry-Pi pinout can be found [here!](https://pinout.xyz/pinout/uart)
2828

2929
#### Four Line UART setup
3030

31+
> [!NOTE]
32+
>
33+
> For UART protocol
34+
> - Host TX is to be connected to slave RX & vice versa.
35+
> - Host CTS is to be connected to slave RTS & vice versa.
36+
3137
| Raspberry-Pi Pin Function | Raspberry-Pi Pin | ESP32 | ESP32-S3 | ESP32-C3 | ESP32 Pin Function |
3238
|:-------:|:--------:|:---------:|:--------:|:--------:|:--------:|
3339
| RX | 10 | IO5 | IO17 | IO5 | TX |
@@ -41,15 +47,21 @@ Sample SPI+UART setup image looks like:
4147

4248
#### Two Line UART setup
4349

50+
> [!NOTE]
51+
>
52+
> For UART protocol, Host TX is connected to slave RX & vice versa.
4453
4554
| Raspberry-Pi Pin Function | Raspberry-Pi Pin | ESP32-C2 | ESP32-C5 | ESP32-C6 | ESP Function |
4655
|:-------:|:--------:|:---------:|:--------:|:--------:|:--------:|
47-
| TX | 8 | IO5 | IO5 | IO5 | TX |
48-
| RX | 10 | IO18 | IO23 | IO12 | RX |
49-
50-
Note:
51-
- ESP32-C2 only
52-
- Although, `HCI with UART` is supported on `ESP32-C2`, `Wi-Fi + Bluetooth` (together) when used with `SPI+UART` setup, Bluetooth on UART works fine but Wi-Fi on SPI faces low throughput problem. By the time this is rectified, please use 'SPI only' i.e. `HCI over SPI` and `Wi-Fi over SPI` transport combination. In `SPI only` setup, there is no such limitation.
56+
| RX | 10 | IO5 | IO5 | IO5 | TX |
57+
| TX | 8 | IO1 | IO23 | IO12 | RX |
58+
59+
> [ !CAUTION ]
60+
> - ESP32-C2 only
61+
> - ESP32-C2 has much less IRAM, without PSRAM support.
62+
> - With `SPI+UART` mode, i.e. Wi-Fi on SPI & BLE over UART mode, Wi-Fi on SPI faces low throughput problem when uart is loaded.
63+
> - With `SPI only` mode, i.e. Wi-Fi & BLE, both, running over SPI, both, Wi-Fi and Bluetooth work smooth.
64+
> - Conclusion, For `ESP32-C2`, prefer using `SPI only` mode.
5365
5466

5567
### 1.2 Raspberry-Pi Software Setup

esp_hosted_fg/esp/esp_driver/network_adapter/CMakeLists.txt

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,18 @@ include($ENV{IDF_PATH}/tools/cmake/project.cmake)
2727
project(network_adapter)
2828
idf_build_set_property(COMPILE_OPTIONS "-fdiagnostics-color=always" APPEND)
2929

30-
31-
idf_component_get_property(lwip lwip COMPONENT_LIB)
32-
target_compile_options(${lwip} PRIVATE "-I${PROJECT_DIR}/main")
33-
target_compile_definitions(${lwip} PRIVATE "-DESP_IDF_LWIP_HOOK_FILENAME=\"esp_hosted_lwip_src_port_hook.h\"")
30+
if(NOT CONFIG_IDF_TARGET_ESP32C2 AND NOT CONFIG_IDF_TARGET_ESP32C3)
31+
idf_component_get_property(lwip lwip COMPONENT_LIB)
32+
if(TARGET ${lwip})
33+
# Use generator expressions to only apply to non-INTERFACE targets
34+
get_target_property(lwip_type ${lwip} TYPE)
35+
if(NOT lwip_type STREQUAL "INTERFACE_LIBRARY")
36+
message(STATUS "********** Configuring LWIP for network split mode with custom hook **********")
37+
target_include_directories(${lwip} PRIVATE "${PROJECT_DIR}/main")
38+
target_compile_definitions(${lwip} PRIVATE "-DESP_IDF_LWIP_HOOK_FILENAME=\"esp_hosted_lwip_src_port_hook.h\"")
39+
endif()
40+
endif()
41+
else()
42+
message(STATUS "********** Skipping LWIP for network split mode with custom hook **********")
43+
# Do not reference esp_http_client for esp32c2 and esp32c3
44+
endif()

esp_hosted_fg/esp/esp_driver/network_adapter/main/CMakeLists.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,17 @@ set(COMPONENT_SRCS
1111
"stats.c"
1212
"mempool_ll.c"
1313
"host_power_save.c"
14-
"mqtt_example.c"
15-
"http_req.c"
1614
"lwip_filter.c"
1715
)
1816

17+
if(CONFIG_ESP_HOSTED_COPROCESSOR_EXAMPLE_MQTT)
18+
list(APPEND COMPONENT_SRCS mqtt_example.c)
19+
endif()
20+
21+
if(CONFIG_ESP_HOSTED_COPROCESSOR_EXAMPLE_HTTP_CLIENT)
22+
list(APPEND COMPONENT_SRCS http_req.c)
23+
endif()
24+
1925
set(COMPONENT_ADD_INCLUDEDIRS
2026
"."
2127
"${common_dir}/include"

esp_hosted_fg/esp/esp_driver/network_adapter/main/Kconfig.projbuild

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,7 @@ menu "Example Configuration"
480480
endmenu
481481

482482
config NETWORK_SPLIT_ENABLED
483+
depends on !IDF_TARGET_ESP32C2 && !IDF_TARGET_ESP32C3
483484
bool "Allow Network Split using packet port number"
484485
default y
485486
help
@@ -631,6 +632,7 @@ menu "Example Configuration"
631632
endmenu
632633

633634
config ESP_HOSTED_CLI_ENABLED
635+
depends on !IDF_TARGET_ESP32C2 && !IDF_TARGET_ESP32C3
634636
bool "Start CLI at slave"
635637
default y
636638

@@ -738,6 +740,8 @@ menu "Example Configuration"
738740

739741

740742
menu "Example to run"
743+
depends on NETWORK_SPLIT_ENABLED
744+
741745
config ESP_HOSTED_COPROCESSOR_EXAMPLE_MQTT
742746
bool "MQTT client example"
743747
default y

esp_hosted_fg/esp/esp_driver/network_adapter/main/http_req.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
CONDITIONS OF ANY KIND, either express or implied.
88
*/
99
#include <string.h>
10+
#include "sdkconfig.h"
11+
12+
#ifdef CONFIG_ESP_HOSTED_COPROCESSOR_EXAMPLE_HTTP_CLIENT
1013
#include "freertos/FreeRTOS.h"
1114
#include "freertos/task.h"
1215
#include "esp_system.h"
@@ -17,9 +20,9 @@
1720
#include "lwip/sys.h"
1821
#include "lwip/netdb.h"
1922
#include "lwip/dns.h"
20-
#include "sdkconfig.h"
2123

22-
#ifdef ESP_HOSTED_COPROCESSOR_EXAMPLE_HTTP_CLIENT
24+
25+
2326
extern volatile uint8_t station_connected;
2427
/* Constants that aren't configurable in menuconfig */
2528
#define WEB_SERVER CONFIG_HTTP_WEBSERVER
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
dependencies:
22
cmd_system:
33
path: ${IDF_PATH}/examples/system/console/advanced/components/cmd_system
4+
rules:
5+
- if: target not in ["esp32c2", "esp32c3"]
46
espressif/iperf:
57
version: "*"
8+
rules:
9+
- if: target not in ["esp32c2", "esp32c3"]
610
espressif/iperf-cmd:
711
version: "~0.1.1"
12+
rules:
13+
- if: target not in ["esp32c2", "esp32c3"]
814
esp-qa/wifi-cmd:
915
version: "~0.1.0"
16+
rules:
17+
- if: target not in ["esp32c2", "esp32c3"]
1018
esp-qa/ping-cmd:
1119
version: "~0.0.1"
20+
rules:
21+
- if: target not in ["esp32c2", "esp32c3"]

esp_hosted_fg/esp/esp_driver/network_adapter/main/lwip_filter.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include "host_power_save.h"
1010
#include "lwip_filter.h"
1111

12-
#ifdef CONFIG_NETWORK_SPLIT_ENABLED
12+
#if defined(CONFIG_NETWORK_SPLIT_ENABLED) && defined(CONFIG_LWIP_ENABLE)
1313
#include "lwip/opt.h"
1414
#include "lwip/err.h"
1515
#include "lwip/sys.h"
@@ -522,4 +522,4 @@ hosted_l2_bridge filter_and_route_packet(void *frame_data, uint16_t frame_length
522522
int configure_host_static_port_forwarding_rules(const char *ports_str_tcp_src, const char *ports_str_tcp_dst, const char *ports_str_udp_src, const char *ports_str_udp_dst) {
523523
return punch_hole_for_host_ports_from_config(ports_str_tcp_src, ports_str_tcp_dst, ports_str_udp_src, ports_str_udp_dst);
524524
}
525-
#endif
525+
#endif

esp_hosted_fg/esp/esp_driver/network_adapter/main/lwip_filter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ typedef enum {
1111
INVALID_BRIDGE,
1212
} hosted_l2_bridge;
1313

14-
#ifdef CONFIG_NETWORK_SPLIT_ENABLED
14+
#if defined(CONFIG_NETWORK_SPLIT_ENABLED) && defined(CONFIG_LWIP_ENABLE)
1515
#include "esp_hosted_lwip_src_port_hook.h"
1616

1717
hosted_l2_bridge filter_and_route_packet(void *frame_data, uint16_t frame_length);
1818

1919
int configure_host_static_port_forwarding_rules(const char *ports_str_tcp_src, const char *ports_str_tcp_dst,
2020
const char *ports_str_udp_src, const char *ports_str_udp_dst);
21-
#endif
21+
#endif

esp_hosted_fg/esp/esp_driver/network_adapter/main/mqtt_example.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
#include <stdint.h>
1212
#include <stddef.h>
1313
#include <string.h>
14+
#include "sdkconfig.h"
15+
16+
#ifdef CONFIG_ESP_HOSTED_COPROCESSOR_EXAMPLE_MQTT
17+
1418
#include "esp_wifi.h"
1519
#include "esp_system.h"
1620
#include "nvs_flash.h"
@@ -23,15 +27,15 @@
2327
#include "freertos/semphr.h"
2428
#include "freertos/queue.h"
2529

26-
#include "lwip/sockets.h"
27-
#include "lwip/dns.h"
28-
#include "lwip/netdb.h"
2930

3031
#include "esp_log.h"
3132
#include "mqtt_client.h"
3233
#include "host_power_save.h"
3334

34-
#ifdef CONFIG_ESP_HOSTED_COPROCESSOR_EXAMPLE_MQTT
35+
#include "lwip/sockets.h"
36+
#include "lwip/dns.h"
37+
#include "lwip/netdb.h"
38+
3539
static const char *TAG = "mqtt_example";
3640
static esp_mqtt_client_handle_t client;
3741
static uint8_t client_started;

esp_hosted_fg/esp/esp_driver/network_adapter/main/slave_bt.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -413,9 +413,7 @@ static void init_uart_c2_c6_c5(void)
413413
{
414414
ESP_LOGD(TAG, "Set-up BLE for ESP32-C2/C6/C5");
415415

416-
#if defined(CONFIG_IDF_TARGET_ESP32C2)
417-
ESP_LOGI(TAG, "UART Pins: Tx:%u Rx:%u", BT_TX_PIN, BT_RX_PIN);
418-
#elif defined(CONFIG_IDF_TARGET_ESP32C6) || defined(CONFIG_IDF_TARGET_ESP32C5)
416+
#if defined(CONFIG_IDF_TARGET_ESP32C2) || defined(CONFIG_IDF_TARGET_ESP32C6) || defined(CONFIG_IDF_TARGET_ESP32C5)
419417
//ESP_ERROR_CHECK( uart_set_pin(BLUETOOTH_UART, BT_TX_PIN,
420418
// BT_RX_PIN, BT_RTS_PIN, BT_CTS_PIN) );
421419
ESP_LOGI(TAG, "UART Pins: Tx:%u Rx:%u", BT_TX_PIN, BT_RX_PIN);

esp_hosted_fg/esp/esp_driver/network_adapter/main/slave_bt.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,7 @@
8989
#define BT_RTS_PIN 19
9090
#define BT_CTS_PIN 23
9191

92-
#elif defined(CONFIG_IDF_TARGET_ESP32C2)
93-
94-
#define BT_TX_PIN 5
95-
#define BT_RX_PIN 18
96-
//#define BT_RTS_PIN 9
97-
//#define BT_CTS_PIN 8
98-
99-
#elif defined(CONFIG_IDF_TARGET_ESP32C6) || defined(CONFIG_IDF_TARGET_ESP32C5)
92+
#elif defined(CONFIG_IDF_TARGET_ESP32C2) || defined(CONFIG_IDF_TARGET_ESP32C6) || defined(CONFIG_IDF_TARGET_ESP32C5)
10093

10194
#define BT_TX_PIN CONFIG_BT_LE_HCI_UART_TX_PIN
10295
#define BT_RX_PIN CONFIG_BT_LE_HCI_UART_RX_PIN

esp_hosted_fg/esp/esp_driver/network_adapter/main/slave_control.c

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,7 @@ void vTimerCallback( TimerHandle_t xTimer )
145145

146146
static void send_wifi_event_data_to_host(int event, void *event_data, int event_size)
147147
{
148-
#ifndef CONFIG_SLAVE_MANAGES_WIFI
149-
send_event_data_to_host(event, event_data, event_size);
150-
#endif
148+
send_event_data_to_host(event, event_data, event_size);
151149
}
152150

153151
static bool wifi_is_provisioned(wifi_config_t *wifi_cfg)
@@ -407,15 +405,13 @@ static void station_event_handler(void *arg, esp_event_base_t event_base,
407405
station_got_ip = 0;
408406
#endif
409407

410-
#ifndef CONFIG_SLAVE_MANAGES_WIFI
411-
wifi_event_sta_disconnected_t * disconnected_event =
412-
(wifi_event_sta_disconnected_t *) event_data;
408+
wifi_event_sta_disconnected_t * disconnected_event =
409+
(wifi_event_sta_disconnected_t *) event_data;
413410

414-
send_wifi_event_data_to_host(CTRL_MSG_ID__Event_StationDisconnectFromAP,
415-
disconnected_event, sizeof(wifi_event_sta_disconnected_t));
416-
ESP_LOGI(TAG, "Station disconnected, reason[%u]",
417-
disconnected_event->reason);
418-
#endif
411+
send_wifi_event_data_to_host(CTRL_MSG_ID__Event_StationDisconnectFromAP,
412+
disconnected_event, sizeof(wifi_event_sta_disconnected_t));
413+
ESP_LOGI(TAG, "Station disconnected, reason[%u]",
414+
disconnected_event->reason);
419415

420416
#ifdef CONFIG_NETWORK_SPLIT_ENABLED
421417
send_dhcp_dns_info_to_host(0, 0);
@@ -464,13 +460,12 @@ static void station_event_handler(void *arg, esp_event_base_t event_base,
464460
}
465461
sta_connect_retry = 0;
466462
prev_wifi_config_valid = true;
467-
#ifndef CONFIG_SLAVE_MANAGES_WIFI
468-
/* Event should not be triggered if event handler is
469-
* called as part of host triggered procedure like sta_disconnect etc
470-
**/
471-
send_wifi_event_data_to_host(CTRL_MSG_ID__Event_StationConnectedToAP,
472-
connected_event, sizeof(wifi_event_sta_connected_t));
473-
#endif
463+
464+
/* Event should not be triggered if event handler is
465+
* called as part of host triggered procedure like sta_disconnect etc
466+
**/
467+
send_wifi_event_data_to_host(CTRL_MSG_ID__Event_StationConnectedToAP,
468+
connected_event, sizeof(wifi_event_sta_connected_t));
474469

475470
memcpy(&lkg_sta_connected_event, connected_event, sizeof(wifi_event_sta_connected_t));
476471

0 commit comments

Comments
 (0)