diff --git a/components/esp32/CMakeLists.txt b/components/esp32/CMakeLists.txt index 2b6a82a07..135e822e4 100644 --- a/components/esp32/CMakeLists.txt +++ b/components/esp32/CMakeLists.txt @@ -72,6 +72,14 @@ else() register_component() target_link_libraries(esp32 "-L ${CMAKE_CURRENT_SOURCE_DIR}/lib") + + # Add a different linker search path depending on WiFi optimisations + if (CONFIG_ESP32_WIFI_IRAM_OPT) + target_link_libraries(esp32 "-L ${CMAKE_CURRENT_SOURCE_DIR}/ld/wifi_iram_opt") + else() + target_link_libraries(esp32 "-L ${CMAKE_CURRENT_SOURCE_DIR}/ld/wifi_iram_noopt") + endif() + if(NOT CONFIG_NO_BLOBS) target_link_libraries(esp32 coexist core espnow mesh net80211 phy pp rtc smartconfig wpa2 wpa wps) endif() diff --git a/components/esp32/Kconfig b/components/esp32/Kconfig index 0d095da08..7eb44cc2f 100644 --- a/components/esp32/Kconfig +++ b/components/esp32/Kconfig @@ -1152,7 +1152,14 @@ config ESP32_WIFI_SOFTAP_BEACON_MAX_LEN 932 (752+36*5). Setting a longer beacon length also assists with debugging as the conflicting root nodes can be identified more quickly. - + +config ESP32_WIFI_IRAM_OPT + bool "WiFi IRAM speed optimization" + default y + help + Select this option to place frequently called Wi-Fi library functions in IRAM. When this option is disabled, + more than 10Kbytes of IRAM memory will be saved but Wi-Fi throughput will be reduced. + endmenu # Wi-Fi menu PHY diff --git a/components/esp32/component.mk b/components/esp32/component.mk index 605bb5637..74c2466bc 100644 --- a/components/esp32/component.mk +++ b/components/esp32/component.mk @@ -18,6 +18,13 @@ endif #specifies its own scripts. LINKER_SCRIPTS += esp32.common.ld esp32.rom.ld esp32.peripherals.ld +# Add a different linker search path depending on WiFi optimisations +ifdef CONFIG_ESP32_WIFI_IRAM_OPT +COMPONENT_ADD_LDFLAGS += -L $(COMPONENT_PATH)/ld/wifi_iram_opt +else +COMPONENT_ADD_LDFLAGS += -L $(COMPONENT_PATH)/ld/wifi_iram_noopt +endif + #Force pure functions from libgcc.a to be linked from ROM LINKER_SCRIPTS += esp32.rom.libgcc.ld diff --git a/components/esp32/ld/esp32.common.ld b/components/esp32/ld/esp32.common.ld index 744fbc211..179b1abdc 100644 --- a/components/esp32/ld/esp32.common.ld +++ b/components/esp32/ld/esp32.common.ld @@ -159,6 +159,7 @@ SECTIONS *libheap.a:multi_heap_poisoning.*(.literal .text .literal.* .text.*) *libesp32.a:panic.*(.literal .text .literal.* .text.*) *libesp32.a:core_dump.*(.literal .text .literal.* .text.*) + INCLUDE wifi_iram.ld *libapp_trace.a:(.literal .text .literal.* .text.*) *libxtensa-debug-module.a:eri.*(.literal .text .literal.* .text.*) *librtc.a:(.literal .text .literal.* .text.*) @@ -326,6 +327,7 @@ SECTIONS _text_start = ABSOLUTE(.); *(.literal .text .literal.* .text.* .stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*) *(.irom0.text) /* catch stray ICACHE_RODATA_ATTR */ + *(.wifi0iram .wifi0iram.*) /* catch stray WIFI_IRAM_ATTR */ *(.fini.literal) *(.fini) *(.gnu.version) diff --git a/components/esp32/ld/wifi_iram_noopt/wifi_iram.ld b/components/esp32/ld/wifi_iram_noopt/wifi_iram.ld new file mode 100644 index 000000000..d414e4d76 --- /dev/null +++ b/components/esp32/ld/wifi_iram_noopt/wifi_iram.ld @@ -0,0 +1,2 @@ +/* This snippet does nothing, if WiFi IRAM optimisations + are disabled. */ diff --git a/components/esp32/ld/wifi_iram_opt/wifi_iram.ld b/components/esp32/ld/wifi_iram_opt/wifi_iram.ld new file mode 100644 index 000000000..f8cd6dbeb --- /dev/null +++ b/components/esp32/ld/wifi_iram_opt/wifi_iram.ld @@ -0,0 +1,4 @@ +/* Link WiFi library .wifi0iram sections to IRAM + if this snippet is included */ +*libnet80211.a:( .wifi0iram .wifi0iram.*) +*libpp.a:( .wifi0iram .wifi0iram.*) diff --git a/components/esp32/lib b/components/esp32/lib index eb53491cf..4a4b8089b 160000 --- a/components/esp32/lib +++ b/components/esp32/lib @@ -1 +1 @@ -Subproject commit eb53491cf6eb18d6cfd98f7b3bb4e09fb241733c +Subproject commit 4a4b8089b3ec47b7d59f69d39ccd0d82402b2597