Skip to content

Commit

Permalink
Add support for WiFi to ESP32-P4 (#10463)
Browse files Browse the repository at this point in the history
* feat(p4): Add support for WiFi to ESP32-P4

Implements support for external MCU connected through SDIO

* fix(p4): Init SDIO host properly on Network boot

esp-hosted has one function marked as "constructor" that did not run in the boot phase of the chip. This calls the function when network is started
  • Loading branch information
me-no-dev authored Oct 15, 2024
1 parent 3733c87 commit 3edf518
Show file tree
Hide file tree
Showing 19 changed files with 58 additions and 28 deletions.
20 changes: 14 additions & 6 deletions idf_component.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,35 +56,43 @@ dependencies:
espressif/esp-zboss-lib:
version: "^1.0.1"
rules:
- if: "target != esp32c2"
- if: "target not in [esp32c2, esp32p4]"
espressif/esp-zigbee-lib:
version: "^1.0.1"
rules:
- if: "target != esp32c2"
- if: "target not in [esp32c2, esp32p4]"
espressif/esp-dsp:
version: "^1.3.4"
rules:
- if: "target != esp32c2"
espressif/esp_rainmaker:
version: "^1.0.0"
rules:
- if: "target != esp32c2"
- if: "target not in [esp32c2, esp32p4]"
espressif/rmaker_common:
version: "^1.4.6"
rules:
- if: "target != esp32c2"
- if: "target not in [esp32c2, esp32p4]"
espressif/esp_insights:
version: "^1.0.1"
rules:
- if: "target != esp32c2"
- if: "target not in [esp32c2, esp32p4]"
espressif/qrcode:
version: "^0.1.0~1"
rules:
- if: "target != esp32c2"
- if: "target not in [esp32c2, esp32p4]"
espressif/esp-sr:
version: "^1.4.2"
rules:
- if: "target in [esp32s3]"
espressif/esp_hosted:
version: "^0.0.22"
rules:
- if: "target == esp32p4"
espressif/esp_wifi_remote:
version: "^0.4.1"
rules:
- if: "target == esp32p4"
espressif/libsodium:
version: "^1.0.20~1"
require: public
Expand Down
2 changes: 1 addition & 1 deletion libraries/Network/src/NetworkEvents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ const char *NetworkEvents::eventName(arduino_event_id_t id) {
case ARDUINO_EVENT_PPP_GOT_IP: return "PPP_GOT_IP";
case ARDUINO_EVENT_PPP_LOST_IP: return "PPP_LOST_IP";
case ARDUINO_EVENT_PPP_GOT_IP6: return "PPP_GOT_IP6";
#if SOC_WIFI_SUPPORTED
#if SOC_WIFI_SUPPORTED || CONFIG_ESP_WIFI_REMOTE_ENABLED
case ARDUINO_EVENT_WIFI_OFF: return "WIFI_OFF";
case ARDUINO_EVENT_WIFI_READY: return "WIFI_READY";
case ARDUINO_EVENT_WIFI_SCAN_DONE: return "SCAN_DONE";
Expand Down
13 changes: 8 additions & 5 deletions libraries/Network/src/NetworkEvents.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
#include "freertos/queue.h"
#include "freertos/semphr.h"
#include "freertos/event_groups.h"
#include "sdkconfig.h"

#if SOC_WIFI_SUPPORTED
#if SOC_WIFI_SUPPORTED || CONFIG_ESP_WIFI_REMOTE_ENABLED
#include "esp_wifi_types.h"
#include "esp_smartconfig.h"
#include "network_provisioning/network_config.h"
#endif

#if SOC_WIFI_SUPPORTED
#if SOC_WIFI_SUPPORTED || CONFIG_ESP_WIFI_REMOTE_ENABLED
static const int WIFI_SCANNING_BIT = BIT0;
static const int WIFI_SCAN_DONE_BIT = BIT1;
#endif
Expand All @@ -41,7 +42,7 @@ typedef enum {
ARDUINO_EVENT_ETH_GOT_IP,
ARDUINO_EVENT_ETH_LOST_IP,
ARDUINO_EVENT_ETH_GOT_IP6,
#if SOC_WIFI_SUPPORTED
#if SOC_WIFI_SUPPORTED || CONFIG_ESP_WIFI_REMOTE_ENABLED
ARDUINO_EVENT_WIFI_OFF,
ARDUINO_EVENT_WIFI_READY,
ARDUINO_EVENT_WIFI_SCAN_DONE,
Expand Down Expand Up @@ -93,7 +94,7 @@ typedef union {
ip_event_got_ip_t got_ip;
ip_event_got_ip6_t got_ip6;
esp_eth_handle_t eth_connected;
#if SOC_WIFI_SUPPORTED
#if SOC_WIFI_SUPPORTED || CONFIG_ESP_WIFI_REMOTE_ENABLED
wifi_event_sta_scan_done_t wifi_scan_done;
wifi_event_sta_authmode_change_t wifi_sta_authmode_change;
wifi_event_sta_connected_t wifi_sta_connected;
Expand All @@ -104,6 +105,8 @@ typedef union {
wifi_event_ap_staconnected_t wifi_ap_staconnected;
wifi_event_ap_stadisconnected_t wifi_ap_stadisconnected;
wifi_event_ftm_report_t wifi_ftm_report;
#endif
#if SOC_WIFI_SUPPORTED
wifi_sta_config_t prov_cred_recv;
network_prov_wifi_sta_fail_reason_t prov_fail_reason;
smartconfig_event_got_ssid_pswd_t sc_got_ssid_pswd;
Expand Down Expand Up @@ -147,7 +150,7 @@ class NetworkEvents {
friend class ESP_NetworkInterface;
friend class ETHClass;
friend class PPPClass;
#if SOC_WIFI_SUPPORTED
#if SOC_WIFI_SUPPORTED || CONFIG_ESP_WIFI_REMOTE_ENABLED
friend class STAClass;
friend class APClass;
friend class WiFiGenericClass;
Expand Down
7 changes: 7 additions & 0 deletions libraries/Network/src/NetworkManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
#include "esp_mac.h"
#include "netdb.h"

#if CONFIG_ESP_WIFI_REMOTE_ENABLED
extern "C" esp_err_t esp_hosted_init(void *);
#endif

NetworkManager::NetworkManager() {}

NetworkInterface *getNetifByID(Network_Interface_ID id);
Expand All @@ -18,6 +22,9 @@ bool NetworkManager::begin() {
static bool initialized = false;
if (!initialized) {
initialized = true;
#if CONFIG_ESP_WIFI_REMOTE_ENABLED
esp_hosted_init(NULL);
#endif
#if CONFIG_IDF_TARGET_ESP32
uint8_t mac[8];
if (esp_efuse_mac_get_default(mac) == ESP_OK) {
Expand Down
2 changes: 1 addition & 1 deletion libraries/WiFi/src/AP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "WiFi.h"
#include "WiFiGeneric.h"
#include "WiFiAP.h"
#if SOC_WIFI_SUPPORTED
#if SOC_WIFI_SUPPORTED || CONFIG_ESP_WIFI_REMOTE_ENABLED
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
Expand Down
2 changes: 1 addition & 1 deletion libraries/WiFi/src/STA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "WiFi.h"
#include "WiFiGeneric.h"
#include "WiFiSTA.h"
#if SOC_WIFI_SUPPORTED
#if SOC_WIFI_SUPPORTED || CONFIG_ESP_WIFI_REMOTE_ENABLED
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
Expand Down
2 changes: 1 addition & 1 deletion libraries/WiFi/src/WiFi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/
#include "WiFi.h"
#if SOC_WIFI_SUPPORTED
#if SOC_WIFI_SUPPORTED || CONFIG_ESP_WIFI_REMOTE_ENABLED

extern "C" {
#include <stdint.h>
Expand Down
3 changes: 2 additions & 1 deletion libraries/WiFi/src/WiFi.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
#pragma once

#include "soc/soc_caps.h"
#if SOC_WIFI_SUPPORTED
#include "sdkconfig.h"
#if SOC_WIFI_SUPPORTED || CONFIG_ESP_WIFI_REMOTE_ENABLED

#include <stdint.h>

Expand Down
2 changes: 1 addition & 1 deletion libraries/WiFi/src/WiFiAP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include "WiFi.h"
#include "WiFiGeneric.h"
#include "WiFiAP.h"
#if SOC_WIFI_SUPPORTED
#if SOC_WIFI_SUPPORTED || CONFIG_ESP_WIFI_REMOTE_ENABLED

#include <stdint.h>
#include <stdbool.h>
Expand Down
2 changes: 1 addition & 1 deletion libraries/WiFi/src/WiFiAP.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#pragma once

#include "soc/soc_caps.h"
#if SOC_WIFI_SUPPORTED
#if SOC_WIFI_SUPPORTED || CONFIG_ESP_WIFI_REMOTE_ENABLED

#include "esp_wifi_types.h"
#include "WiFiType.h"
Expand Down
15 changes: 13 additions & 2 deletions libraries/WiFi/src/WiFiGeneric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

#include "WiFi.h"
#include "WiFiGeneric.h"
#if SOC_WIFI_SUPPORTED
#if SOC_WIFI_SUPPORTED || CONFIG_ESP_WIFI_REMOTE_ENABLED

extern "C" {
#include <stdint.h>
Expand All @@ -39,7 +39,9 @@ extern "C" {
#include <esp_event.h>
#include <esp_mac.h>
#include <esp_netif.h>
#if SOC_WIFI_SUPPORTED
#include <esp_phy.h>
#endif
#include "lwip/ip_addr.h"
#include "lwip/opt.h"
#include "lwip/err.h"
Expand Down Expand Up @@ -103,6 +105,7 @@ static void _arduino_event_cb(void *arg, esp_event_base_t event_base, int32_t ev
arduino_event.event_id = ARDUINO_EVENT_WIFI_FTM_REPORT;
memcpy(&arduino_event.event_info.wifi_ftm_report, event_data, sizeof(wifi_event_ftm_report_t));

#if !CONFIG_ESP_WIFI_REMOTE_ENABLED
/*
* SMART CONFIG
* */
Expand Down Expand Up @@ -157,6 +160,7 @@ static void _arduino_event_cb(void *arg, esp_event_base_t event_base, int32_t ev
} else if (event_base == NETWORK_PROV_EVENT && event_id == NETWORK_PROV_WIFI_CRED_SUCCESS) {
log_v("Provisioning Success!");
arduino_event.event_id = ARDUINO_EVENT_PROV_CRED_SUCCESS;
#endif
}

if (arduino_event.event_id < ARDUINO_EVENT_MAX) {
Expand All @@ -170,6 +174,7 @@ static bool initWiFiEvents() {
return false;
}

#if !CONFIG_ESP_WIFI_REMOTE_ENABLED
if (esp_event_handler_instance_register(SC_EVENT, ESP_EVENT_ANY_ID, &_arduino_event_cb, NULL, NULL)) {
log_e("event_handler_instance_register for SC_EVENT Failed!");
return false;
Expand All @@ -179,6 +184,7 @@ static bool initWiFiEvents() {
log_e("event_handler_instance_register for NETWORK_PROV_EVENT Failed!");
return false;
}
#endif

return true;
}
Expand All @@ -189,6 +195,7 @@ static bool deinitWiFiEvents() {
return false;
}

#if !CONFIG_ESP_WIFI_REMOTE_ENABLED
if (esp_event_handler_unregister(SC_EVENT, ESP_EVENT_ANY_ID, &_arduino_event_cb)) {
log_e("esp_event_handler_unregister for SC_EVENT Failed!");
return false;
Expand All @@ -198,6 +205,7 @@ static bool deinitWiFiEvents() {
log_e("esp_event_handler_unregister for NETWORK_PROV_EVENT Failed!");
return false;
}
#endif

return true;
}
Expand Down Expand Up @@ -370,6 +378,7 @@ void WiFiGenericClass::_eventCallback(arduino_event_t *event) {
// log_d("Arduino Event: %d - %s", event->event_id, WiFi.eventName(event->event_id));
if (event->event_id == ARDUINO_EVENT_WIFI_SCAN_DONE) {
WiFiScanClass::_scanDone();
#if !CONFIG_ESP_WIFI_REMOTE_ENABLED
} else if (event->event_id == ARDUINO_EVENT_SC_GOT_SSID_PSWD) {
WiFi.begin(
(const char *)event->event_info.sc_got_ssid_pswd.ssid, (const char *)event->event_info.sc_got_ssid_pswd.password, 0,
Expand All @@ -378,6 +387,7 @@ void WiFiGenericClass::_eventCallback(arduino_event_t *event) {
} else if (event->event_id == ARDUINO_EVENT_SC_SEND_ACK_DONE) {
esp_smartconfig_stop();
WiFiSTAClass::_smartConfigDone = true;
#endif
}
}

Expand Down Expand Up @@ -693,6 +703,7 @@ bool WiFiGenericClass::initiateFTM(uint8_t frm_count, uint16_t burst_period, uin
* @return true on success
*/
bool WiFiGenericClass::setDualAntennaConfig(uint8_t gpio_ant1, uint8_t gpio_ant2, wifi_rx_ant_t rx_mode, wifi_tx_ant_t tx_mode) {
#if !CONFIG_ESP_WIFI_REMOTE_ENABLED

esp_phy_ant_gpio_config_t wifi_ant_io;

Expand Down Expand Up @@ -759,7 +770,7 @@ bool WiFiGenericClass::setDualAntennaConfig(uint8_t gpio_ant1, uint8_t gpio_ant2
log_e("Failed to set antenna configuration");
return false;
}

#endif
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion libraries/WiFi/src/WiFiGeneric.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#pragma once

#include "soc/soc_caps.h"
#if SOC_WIFI_SUPPORTED
#if SOC_WIFI_SUPPORTED || CONFIG_ESP_WIFI_REMOTE_ENABLED

#include "esp_err.h"
#include "esp_event.h"
Expand Down
2 changes: 1 addition & 1 deletion libraries/WiFi/src/WiFiMulti.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/

#include "WiFiMulti.h"
#if SOC_WIFI_SUPPORTED
#if SOC_WIFI_SUPPORTED || CONFIG_ESP_WIFI_REMOTE_ENABLED
#include <limits.h>
#include <string.h>
#include <esp32-hal.h>
Expand Down
2 changes: 1 addition & 1 deletion libraries/WiFi/src/WiFiMulti.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#pragma once

#include "soc/soc_caps.h"
#if SOC_WIFI_SUPPORTED
#if SOC_WIFI_SUPPORTED || CONFIG_ESP_WIFI_REMOTE_ENABLED

#include "WiFi.h"
#include <vector>
Expand Down
2 changes: 1 addition & 1 deletion libraries/WiFi/src/WiFiSTA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include "WiFi.h"
#include "WiFiGeneric.h"
#include "WiFiSTA.h"
#if SOC_WIFI_SUPPORTED
#if SOC_WIFI_SUPPORTED || CONFIG_ESP_WIFI_REMOTE_ENABLED

#include <stdint.h>
#include <stdbool.h>
Expand Down
2 changes: 1 addition & 1 deletion libraries/WiFi/src/WiFiSTA.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#pragma once

#include "soc/soc_caps.h"
#if SOC_WIFI_SUPPORTED
#if SOC_WIFI_SUPPORTED || CONFIG_ESP_WIFI_REMOTE_ENABLED

#include "WiFiType.h"
#include "WiFiGeneric.h"
Expand Down
2 changes: 1 addition & 1 deletion libraries/WiFi/src/WiFiScan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include "WiFi.h"
#include "WiFiGeneric.h"
#include "WiFiScan.h"
#if SOC_WIFI_SUPPORTED
#if SOC_WIFI_SUPPORTED || CONFIG_ESP_WIFI_REMOTE_ENABLED

extern "C" {
#include <stdint.h>
Expand Down
2 changes: 1 addition & 1 deletion libraries/WiFi/src/WiFiScan.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#pragma once

#include "soc/soc_caps.h"
#if SOC_WIFI_SUPPORTED
#if SOC_WIFI_SUPPORTED || CONFIG_ESP_WIFI_REMOTE_ENABLED

#include "WiFiType.h"
#include "WiFiGeneric.h"
Expand Down
2 changes: 1 addition & 1 deletion libraries/WiFi/src/WiFiType.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#pragma once

#include "soc/soc_caps.h"
#if SOC_WIFI_SUPPORTED
#if SOC_WIFI_SUPPORTED || CONFIG_ESP_WIFI_REMOTE_ENABLED

#include "esp_wifi_types.h"

Expand Down

0 comments on commit 3edf518

Please sign in to comment.