Skip to content

Commit

Permalink
ESP32: Add support for ESP32-P4 (#36312) (#36773)
Browse files Browse the repository at this point in the history
* ESP32: Add support for ESP32-P4

* Restyled by clang-format

* Restyled by prettier-yaml

---------

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
wqx6 and restyled-commits authored Dec 10, 2024
1 parent 9b008bc commit 43aa98c
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 18 deletions.
16 changes: 12 additions & 4 deletions config/esp32/components/chip/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,8 @@ if(CONFIG_BT_ENABLED)
idf_component_get_property(bt_dir bt COMPONENT_DIR)
list(APPEND chip_libraries $<TARGET_FILE:${bt_lib}>)
list(APPEND chip_libraries "${bt_dir}/controller/lib_${target_name}/${target_name}-bt-lib/libble_app.a")
elseif(target_name STREQUAL "esp32p4")
list(APPEND chip_libraries $<TARGET_FILE:${bt_lib}>)
else()
list(APPEND chip_libraries $<TARGET_FILE:${bt_lib}> -lbtdm_app)
endif()
Expand Down Expand Up @@ -513,11 +515,12 @@ endif()
idf_component_get_property(lwip_lib lwip COMPONENT_LIB)
list(APPEND chip_libraries $<TARGET_FILE:${lwip_lib}>)


if (CONFIG_ESP32_WIFI_ENABLED)
if (CONFIG_ESP32_WIFI_ENABLED OR CONFIG_IDF_TARGET_ESP32P4)
idf_component_get_property(esp_wifi_lib esp_wifi COMPONENT_LIB)
idf_component_get_property(esp_wifi_dir esp_wifi COMPONENT_DIR)
list(APPEND chip_libraries $<TARGET_FILE:${esp_wifi_lib}>)
endif()
if (CONFIG_ESP32_WIFI_ENABLED)
idf_component_get_property(esp_wifi_dir esp_wifi COMPONENT_DIR)
if (CONFIG_IDF_TARGET_ESP32C2)
set(blobs core net80211 pp)
else()
Expand All @@ -543,6 +546,7 @@ list(APPEND chip_libraries $<TARGET_FILE:${esp_netif_lib}>)
idf_component_get_property(esp_hw_support_lib esp_hw_support COMPONENT_LIB)
list(APPEND chip_libraries $<TARGET_FILE:${esp_hw_support_lib}>)

if (NOT CONFIG_IDF_TARGET_ESP32P4)
idf_component_get_property(esp_phy_lib esp_phy COMPONENT_LIB)
idf_component_get_property(esp_phy_dir esp_phy COMPONENT_DIR)
list(APPEND chip_libraries $<TARGET_FILE:${esp_phy_lib}>)
Expand All @@ -557,8 +561,12 @@ endif()
foreach(phy_blob ${phy_blobs})
list(APPEND chip_libraries "${esp_phy_dir}/lib/${target_name}/lib${phy_blob}.a")
endforeach()
endif()

set(components_to_link esp_event hal esp_system soc efuse vfs driver esp_coex freertos esp_timer)
set(components_to_link esp_event hal esp_system soc efuse vfs driver freertos esp_timer)
if (NOT CONFIG_IDF_TARGET_ESP32P4)
list(APPEND components_to_link esp_coex)
endif()
idf_build_get_property(build_components BUILD_COMPONENTS)
foreach(component ${components_to_link})
# Some of the components are not present in IDF v4.x
Expand Down
5 changes: 5 additions & 0 deletions config/esp32/components/chip/idf_component.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,8 @@ dependencies:
require: public
rules:
- if: "idf_version >=4.3"

espressif/esp_wifi_remote:
version: ">=0.1.12"
rules:
- if: "target in [esp32p4]"
8 changes: 6 additions & 2 deletions examples/all-clusters-app/esp32/main/Kconfig.projbuild
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ menu "Demo"
default DEVICE_TYPE_ESP32_C3_DEVKITM if IDF_TARGET_ESP32C3
default DEVICE_TYPE_ESP32_C2_DEVKITM if IDF_TARGET_ESP32C2
default DEVICE_TYPE_ESP32_C6_DEVKITC if IDF_TARGET_ESP32C6
default DEVICE_TYPE_ESP32_P4_FUNCTION_EV_BOARD if IDF_TARGET_ESP32P4
help
Specifies the type of ESP32 device.

Expand Down Expand Up @@ -57,6 +58,9 @@ menu "Demo"
config DEVICE_TYPE_ESP32_H2_DEVKITM
bool "ESP32H2-DevKitM"
depends on IDF_TARGET_ESP32H2
config DEVICE_TYPE_ESP32_P4_FUNCTION_EV_BOARD
bool "ESP32P4 Function EV Board"
depends on IDF_TARGET_ESP32P4
endchoice

choice
Expand Down Expand Up @@ -87,7 +91,7 @@ menu "Demo"
config TFT_PREDEFINED_DISPLAY_TYPE
int
range 0 5
default 0 if DEVICE_TYPE_ESP32_DEVKITC || DEVICE_TYPE_ESP32_H2_DEVKITM
default 0 if DEVICE_TYPE_ESP32_DEVKITC || DEVICE_TYPE_ESP32_H2_DEVKITM || DEVICE_TYPE_ESP32_P4_FUNCTION_EV_BOARD
default 0 if DEVICE_TYPE_ESP32_C3_DEVKITM || DEVICE_TYPE_ESP32_C2_DEVKITM || DEVICE_TYPE_ESP32_C6_DEVKITC
default 3 if DEVICE_TYPE_M5STACK
default 4 if DEVICE_TYPE_ESP32_WROVER_KIT
Expand Down Expand Up @@ -118,7 +122,7 @@ menu "Demo"
range 0 40
default 2 if DEVICE_TYPE_ESP32_DEVKITC #Use LED1 (blue LED) as status LED on DevKitC
default 2 if DEVICE_TYPE_ESP32_ETHERNET_KIT
default 8 if DEVICE_TYPE_ESP32_C3_DEVKITM || DEVICE_TYPE_ESP32_C2_DEVKITM || DEVICE_TYPE_ESP32_C6_DEVKITC || DEVICE_TYPE_ESP32_H2_DEVKITM
default 8 if DEVICE_TYPE_ESP32_C3_DEVKITM || DEVICE_TYPE_ESP32_C2_DEVKITM || DEVICE_TYPE_ESP32_C6_DEVKITC || DEVICE_TYPE_ESP32_H2_DEVKITM || DEVICE_TYPE_ESP32_P4_FUNCTION_EV_BOARD
default 26 if DEVICE_TYPE_ESP32_WROVER_KIT
default 40 if DEVICE_TYPE_M5STACK
help
Expand Down
37 changes: 37 additions & 0 deletions examples/all-clusters-app/esp32/sdkconfig.defaults.esp32p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
CONFIG_IDF_TARGET="esp32p4"

# Flash size and partition
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
CONFIG_PARTITION_TABLE_CUSTOM=y
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv"

# Enable BLE Host but use remote controller
CONFIG_BT_ENABLED=y
CONFIG_BT_NIMBLE_ENABLED=y
CONFIG_BT_NIMBLE_TRANSPORT_UART=n
CONFIG_ESP_ENABLE_BT=y

# Increase main task stack size
CONFIG_ESP_MAIN_TASK_STACK_SIZE=4096

# Disable Wi-Fi Soft AP
CONFIG_ESP_WIFI_SOFTAP_SUPPORT=n

# LwIP
CONFIG_LWIP_IPV6_AUTOCONFIG=y
CONFIG_LWIP_IPV6_NUM_ADDRESSES=6

# mbedtls
CONFIG_MBEDTLS_HKDF_C=y

# Matter shell
CONFIG_ENABLE_CHIP_SHELL=y

# OTA requestor
CONFIG_ENABLE_OTA_REQUESTOR=y

# Do not deinit BLE after commissioning
CONFIG_USE_BLE_ONLY_FOR_COMMISSIONING=n

# ESP32-P4 Function EV Board use ESP32C6 as slave device
CONFIG_SLAVE_IDF_TARGET_ESP32C6=y
37 changes: 37 additions & 0 deletions examples/lighting-app/esp32/sdkconfig.defaults.esp32p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
CONFIG_IDF_TARGET="esp32p4"

# Flash size and partition
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
CONFIG_PARTITION_TABLE_CUSTOM=y
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv"

# Enable BLE Host but use remote controller
CONFIG_BT_ENABLED=y
CONFIG_BT_NIMBLE_ENABLED=y
CONFIG_BT_NIMBLE_TRANSPORT_UART=n
CONFIG_ESP_ENABLE_BT=y

# Increase main task stack size
CONFIG_ESP_MAIN_TASK_STACK_SIZE=4096

# Disable Wi-Fi Soft AP
CONFIG_ESP_WIFI_SOFTAP_SUPPORT=n

# LwIP
CONFIG_LWIP_IPV6_AUTOCONFIG=y
CONFIG_LWIP_IPV6_NUM_ADDRESSES=6

# mbedtls
CONFIG_MBEDTLS_HKDF_C=y

# Matter shell
CONFIG_ENABLE_CHIP_SHELL=y

# OTA requestor
CONFIG_ENABLE_OTA_REQUESTOR=y

# Do not deinit BLE after commissioning
CONFIG_USE_BLE_ONLY_FOR_COMMISSIONING=n

# ESP32-P4 Function EV Board use ESP32C6 as slave device
CONFIG_SLAVE_IDF_TARGET_ESP32C6=y
12 changes: 0 additions & 12 deletions examples/platform/esp32/common/Esp32AppServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,6 @@
#include <app/clusters/device-energy-management-server/DeviceEnergyManagementTestEventTriggerHandler.h>
#endif

#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
#if CONFIG_BT_ENABLED
#include "esp_bt.h"
#if CONFIG_BT_NIMBLE_ENABLED
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0)
#include "esp_nimble_hci.h"
#endif // ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0)
#include "nimble/nimble_port.h"
#endif // CONFIG_BT_NIMBLE_ENABLED
#endif // CONFIG_BT_ENABLED
#endif // CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE

#ifdef CONFIG_ENABLE_CHIP_SHELL
#include <lib/shell/commands/WiFi.h>
#endif
Expand Down
2 changes: 2 additions & 0 deletions src/platform/ESP32/ConfigurationManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
#include "esp_mac.h"
#endif
#include "esp_ota_ops.h"
#ifndef CONFIG_IDF_TARGET_ESP32P4
#include "esp_phy_init.h"
#endif
#include "esp_wifi.h"
#include "nvs.h"
#include "nvs_flash.h"
Expand Down
7 changes: 7 additions & 0 deletions src/platform/ESP32/nimble/BLEManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@
#include <setup_payload/AdditionalDataPayloadGenerator.h>
#include <system/SystemTimer.h>

#ifndef CONFIG_IDF_TARGET_ESP32P4
#include "esp_bt.h"
#endif
#include "esp_log.h"

#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0)
Expand Down Expand Up @@ -1021,6 +1023,11 @@ CHIP_ERROR BLEManagerImpl::DeinitBLE()
return MapBLEError(err);
}

#ifdef CONFIG_IDF_TARGET_ESP32P4
// Stub function to avoid link error
extern "C" void ble_transport_ll_deinit(void) {}
#endif

CHIP_ERROR BLEManagerImpl::ConfigureAdvertisingData(void)
{
CHIP_ERROR err;
Expand Down

0 comments on commit 43aa98c

Please sign in to comment.