From e979e9701f276b03c3335cd20967ba04386e00e4 Mon Sep 17 00:00:00 2001 From: zhangyanjiao Date: Tue, 21 Dec 2021 15:16:20 +0800 Subject: [PATCH 01/14] esp_wifi: bringup esp32c2 wifi --- components/esp_phy/CMakeLists.txt | 7 +- .../esp_phy/esp32c2/include/phy_init_data.h | 182 ++++ .../esp32c2/phy_multiple_init_data.bin | Bin 0 -> 1072 bytes components/esp_phy/src/phy_init.c | 10 +- components/esp_wifi/CMakeLists.txt | 6 +- components/esp_wifi/Kconfig | 1 - components/esp_wifi/esp32c2/esp_adapter.c | 783 ++++++++++++++++++ .../include/esp_private/wifi_os_adapter.h | 2 +- components/esp_wifi/include/esp_wifi_types.h | 10 +- components/soc/esp32c2/include/soc/soc_caps.h | 6 + 10 files changed, 991 insertions(+), 16 deletions(-) create mode 100644 components/esp_phy/esp32c2/include/phy_init_data.h create mode 100644 components/esp_phy/esp32c2/phy_multiple_init_data.bin create mode 100644 components/esp_wifi/esp32c2/esp_adapter.c diff --git a/components/esp_phy/CMakeLists.txt b/components/esp_phy/CMakeLists.txt index 43b3ddfbf2..db0807413d 100644 --- a/components/esp_phy/CMakeLists.txt +++ b/components/esp_phy/CMakeLists.txt @@ -1,10 +1,5 @@ idf_build_get_property(idf_target IDF_TARGET) -if(IDF_TARGET STREQUAL "esp32c2") - # TODO : IDF-3906 - return() -endif() - set(srcs "src/phy_override.c" "src/lib_printf.c") if(CONFIG_APP_NO_BLOBS) @@ -72,7 +67,7 @@ if(link_binary_libs) $) endif() - if(CONFIG_IDF_TARGET_ESP32C3 OR CONFIG_IDF_TARGET_ESP32S3 OR CONFIG_IDF_TARGET_ESP32H2) + if(CONFIG_IDF_TARGET_ESP32C3 OR CONFIG_IDF_TARGET_ESP32S3 OR CONFIG_IDF_TARGET_ESP32H2 OR CONFIG_IDF_TARGET_ESP32C2) target_link_libraries(${COMPONENT_LIB} PUBLIC btbb) target_link_libraries(${COMPONENT_LIB} INTERFACE $ libphy.a libbtbb.a $) diff --git a/components/esp_phy/esp32c2/include/phy_init_data.h b/components/esp_phy/esp32c2/include/phy_init_data.h new file mode 100644 index 0000000000..7e458c4311 --- /dev/null +++ b/components/esp_phy/esp32c2/include/phy_init_data.h @@ -0,0 +1,182 @@ +/* + * SPDX-FileCopyrightText: 2016-2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef PHY_INIT_DATA_H +#define PHY_INIT_DATA_H /* don't use #pragma once here, we compile this file sometimes */ +#include "esp_phy_init.h" +#include "sdkconfig.h" + +#ifdef __cplusplus +extern "C" { +#endif + +// constrain a value between 'low' and 'high', inclusive +#define LIMIT(val, low, high) ((val < low) ? low : (val > high) ? high : val) + +#define PHY_INIT_MAGIC "PHYINIT" + +// define the lowest tx power as LOWEST_PHY_TX_POWER +#define PHY_TX_POWER_LOWEST LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 52) +#define PHY_TX_POWER_OFFSET 44 +#define PHY_TX_POWER_NUM 5 + +#if CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN +#define PHY_CRC_ALGORITHM 1 +#define PHY_COUNTRY_CODE_LEN 2 +#define PHY_INIT_DATA_TYPE_OFFSET 126 +#define PHY_SUPPORT_MULTIPLE_BIN_OFFSET 125 +#endif + +static const char __attribute__((section(".rodata"))) phy_init_magic_pre[] = PHY_INIT_MAGIC; + +/** + * @brief Structure containing default recommended PHY initialization parameters. + */ +static const esp_phy_init_data_t phy_init_data= { { + 0x00, + 0x00, + LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 0x50), + LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 0x50), + LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 0x50), + LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 0x4c), + LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 0x4c), + LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 0x48), + LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 0x4c), + LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 0x48), + LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 0x48), + LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 0x44), + LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 0x4a), + LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 0x46), + LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 0x46), + LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 0x42), + 0x00, + 0x00, + 0x00, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0x74 +} }; + +static const char __attribute__((section(".rodata"))) phy_init_magic_post[] = PHY_INIT_MAGIC; + +#if CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN +/** + * @brief PHY init data control infomation structure + */ +typedef struct { + uint8_t control_info_checksum[4]; /*!< 4-byte control infomation checksum */ + uint8_t multiple_bin_checksum[4]; /*!< 4-byte multiple bin checksum */ + uint8_t check_algorithm; /*!< check algorithm */ + uint8_t version; /*!< PHY init data bin version */ + uint8_t number; /*!< PHY init data bin number */ + uint8_t length[2]; /*!< Length of each PHY init data bin */ + uint8_t reserved[19]; /*!< 19-byte reserved */ +} __attribute__ ((packed)) phy_control_info_data_t; + +/** + * @brief Country corresponds to PHY init data type structure + */ +typedef struct { + char cc[PHY_COUNTRY_CODE_LEN]; + uint8_t type; +} phy_country_to_bin_type_t; +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* PHY_INIT_DATA_H */ diff --git a/components/esp_phy/esp32c2/phy_multiple_init_data.bin b/components/esp_phy/esp32c2/phy_multiple_init_data.bin new file mode 100644 index 0000000000000000000000000000000000000000..0f754a2c496b5cf7b712c49b15e83a02082692f4 GIT binary patch literal 1072 zcmWIWi1hUH3}Ikk2nY!9@$vBS@Nn^Rb8}+&PdZ>A7cep`gSlh6%ptaIvLd;R4D1XI zSj|IsC!-rO`0s!WaPhDjOjwYSF%~nN7;SuDz{bYrzljG7n3$NL^ISl{#KeTKRajLp zGJVBnzYP-jj~p0oxOiAiCoIUwY>3T%nD>2X?tc~yEcPQuxC1U9gMtN-8VGw8s|rTe k1z79{#VH))wO +#include +#include +#include +#include +#include + +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "freertos/queue.h" +#include "freertos/semphr.h" +#include "freertos/event_groups.h" +#include "freertos/portmacro.h" +#include "riscv/interrupt.h" +#include "riscv/riscv_interrupts.h" +#include "esp_types.h" +#include "esp_random.h" +#include "esp_mac.h" +#include "esp_task.h" +#include "esp_intr_alloc.h" +#include "esp_attr.h" +#include "esp_log.h" +#include "esp_event.h" +#include "esp_heap_caps.h" +#include "esp_timer.h" +#include "esp_private/wifi_os_adapter.h" +#include "esp_private/wifi.h" +#include "esp_phy_init.h" +#include "soc/rtc_cntl_reg.h" +#include "soc/rtc.h" +#include "soc/syscon_reg.h" +#include "phy_init_data.h" +#include "esp_private/periph_ctrl.h" +#include "esp_private/esp_clk.h" +#include "nvs.h" +#include "os.h" +#include "esp_smartconfig.h" +#include "esp_coexist_internal.h" +#include "esp_coexist_adapter.h" +#include "esp32c2/rom/ets_sys.h" + +#define TAG "esp_adapter" + +#ifdef CONFIG_PM_ENABLE +extern void wifi_apb80m_request(void); +extern void wifi_apb80m_release(void); +#endif + +IRAM_ATTR void *wifi_malloc( size_t size ) +{ + return malloc(size); +} + +IRAM_ATTR void *wifi_realloc( void *ptr, size_t size ) +{ + return realloc(ptr, size); +} + +IRAM_ATTR void *wifi_calloc( size_t n, size_t size ) +{ + return calloc(n, size); +} + +static void * IRAM_ATTR wifi_zalloc_wrapper(size_t size) +{ + void *ptr = wifi_calloc(1, size); + return ptr; +} + +wifi_static_queue_t* wifi_create_queue( int queue_len, int item_size) +{ + wifi_static_queue_t *queue = NULL; + + queue = (wifi_static_queue_t*)heap_caps_malloc(sizeof(wifi_static_queue_t), MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); + if (!queue) { + return NULL; + } + + queue->handle = xQueueCreate( queue_len, item_size); + return queue; +} + +void wifi_delete_queue(wifi_static_queue_t *queue) +{ + if (queue) { + vQueueDelete(queue->handle); + free(queue); + } +} + +static void * wifi_create_queue_wrapper(int queue_len, int item_size) +{ + return wifi_create_queue(queue_len, item_size); +} + +static void wifi_delete_queue_wrapper(void *queue) +{ + wifi_delete_queue(queue); +} + +static bool IRAM_ATTR env_is_chip_wrapper(void) +{ +#ifdef CONFIG_IDF_ENV_FPGA + return false; +#else + return true; +#endif +} + +static void set_intr_wrapper(int32_t cpu_no, uint32_t intr_source, uint32_t intr_num, int32_t intr_prio) +{ + intr_matrix_route(intr_source, intr_num); + esprv_intc_int_set_priority(intr_num, intr_prio); + esprv_intc_int_set_type(intr_num, INTR_TYPE_LEVEL); +} + +static void clear_intr_wrapper(uint32_t intr_source, uint32_t intr_num) +{ + +} + +static void set_isr_wrapper(int32_t n, void *f, void *arg) +{ + intr_handler_set(n, (intr_handler_t)f, arg); +} + +static void enable_intr_wrapper(uint32_t intr_mask) +{ + esprv_intc_int_enable(intr_mask); +} + +static void disable_intr_wrapper(uint32_t intr_mask) +{ + esprv_intc_int_disable(intr_mask); +} + +static void * spin_lock_create_wrapper(void) +{ + portMUX_TYPE tmp = portMUX_INITIALIZER_UNLOCKED; + void *mux = malloc(sizeof(portMUX_TYPE)); + + if (mux) { + memcpy(mux,&tmp,sizeof(portMUX_TYPE)); + return mux; + } + return NULL; +} + +static uint32_t IRAM_ATTR wifi_int_disable_wrapper(void *wifi_int_mux) +{ + if (xPortInIsrContext()) { + portENTER_CRITICAL_ISR(wifi_int_mux); + } else { + portENTER_CRITICAL(wifi_int_mux); + } + + return 0; +} + +static void IRAM_ATTR wifi_int_restore_wrapper(void *wifi_int_mux, uint32_t tmp) +{ + if (xPortInIsrContext()) { + portEXIT_CRITICAL_ISR(wifi_int_mux); + } else { + portEXIT_CRITICAL(wifi_int_mux); + } +} + +static bool IRAM_ATTR is_from_isr_wrapper(void) +{ + return !xPortCanYield(); +} + +static void IRAM_ATTR task_yield_from_isr_wrapper(void) +{ + portYIELD_FROM_ISR(); +} + +static void * semphr_create_wrapper(uint32_t max, uint32_t init) +{ + return (void *)xSemaphoreCreateCounting(max, init); +} + +static void semphr_delete_wrapper(void *semphr) +{ + vSemaphoreDelete(semphr); +} + +static void wifi_thread_semphr_free(void* data) +{ + SemaphoreHandle_t *sem = (SemaphoreHandle_t*)(data); + + if (sem) { + vSemaphoreDelete(sem); + } +} + +static void * wifi_thread_semphr_get_wrapper(void) +{ + static bool s_wifi_thread_sem_key_init = false; + static pthread_key_t s_wifi_thread_sem_key; + SemaphoreHandle_t sem = NULL; + + if (s_wifi_thread_sem_key_init == false) { + if (0 != pthread_key_create(&s_wifi_thread_sem_key, wifi_thread_semphr_free)) { + return NULL; + } + s_wifi_thread_sem_key_init = true; + } + + sem = pthread_getspecific(s_wifi_thread_sem_key); + if (!sem) { + sem = xSemaphoreCreateCounting(1, 0); + if (sem) { + pthread_setspecific(s_wifi_thread_sem_key, sem); + ESP_LOGV(TAG, "thread sem create: sem=%p", sem); + } + } + + ESP_LOGV(TAG, "thread sem get: sem=%p", sem); + return (void*)sem; +} + +static int32_t IRAM_ATTR semphr_take_from_isr_wrapper(void *semphr, void *hptw) +{ + return (int32_t)xSemaphoreTakeFromISR(semphr, hptw); +} + +static int32_t IRAM_ATTR semphr_give_from_isr_wrapper(void *semphr, void *hptw) +{ + return (int32_t)xSemaphoreGiveFromISR(semphr, hptw); +} + +static int32_t semphr_take_wrapper(void *semphr, uint32_t block_time_tick) +{ + if (block_time_tick == OSI_FUNCS_TIME_BLOCKING) { + return (int32_t)xSemaphoreTake(semphr, portMAX_DELAY); + } else { + return (int32_t)xSemaphoreTake(semphr, block_time_tick); + } +} + +static int32_t semphr_give_wrapper(void *semphr) +{ + return (int32_t)xSemaphoreGive(semphr); +} + +static void * recursive_mutex_create_wrapper(void) +{ + return (void *)xSemaphoreCreateRecursiveMutex(); +} + +static void * mutex_create_wrapper(void) +{ + return (void *)xSemaphoreCreateMutex(); +} + +static void mutex_delete_wrapper(void *mutex) +{ + vSemaphoreDelete(mutex); +} + +static int32_t IRAM_ATTR mutex_lock_wrapper(void *mutex) +{ + return (int32_t)xSemaphoreTakeRecursive(mutex, portMAX_DELAY); +} + +static int32_t IRAM_ATTR mutex_unlock_wrapper(void *mutex) +{ + return (int32_t)xSemaphoreGiveRecursive(mutex); +} + +static void * queue_create_wrapper(uint32_t queue_len, uint32_t item_size) +{ + return (void *)xQueueCreate(queue_len, item_size); +} + +static int32_t queue_send_wrapper(void *queue, void *item, uint32_t block_time_tick) +{ + if (block_time_tick == OSI_FUNCS_TIME_BLOCKING) { + return (int32_t)xQueueSend(queue, item, portMAX_DELAY); + } else { + return (int32_t)xQueueSend(queue, item, block_time_tick); + } +} + +static int32_t IRAM_ATTR queue_send_from_isr_wrapper(void *queue, void *item, void *hptw) +{ + return (int32_t)xQueueSendFromISR(queue, item, hptw); +} + +static int32_t queue_send_to_back_wrapper(void *queue, void *item, uint32_t block_time_tick) +{ + return (int32_t)xQueueGenericSend(queue, item, block_time_tick, queueSEND_TO_BACK); +} + +static int32_t queue_send_to_front_wrapper(void *queue, void *item, uint32_t block_time_tick) +{ + return (int32_t)xQueueGenericSend(queue, item, block_time_tick, queueSEND_TO_FRONT); +} + +static int32_t queue_recv_wrapper(void *queue, void *item, uint32_t block_time_tick) +{ + if (block_time_tick == OSI_FUNCS_TIME_BLOCKING) { + return (int32_t)xQueueReceive(queue, item, portMAX_DELAY); + } else { + return (int32_t)xQueueReceive(queue, item, block_time_tick); + } +} + +static uint32_t event_group_wait_bits_wrapper(void *event, uint32_t bits_to_wait_for, int clear_on_exit, int wait_for_all_bits, uint32_t block_time_tick) +{ + if (block_time_tick == OSI_FUNCS_TIME_BLOCKING) { + return (uint32_t)xEventGroupWaitBits(event, bits_to_wait_for, clear_on_exit, wait_for_all_bits, portMAX_DELAY); + } else { + return (uint32_t)xEventGroupWaitBits(event, bits_to_wait_for, clear_on_exit, wait_for_all_bits, block_time_tick); + } +} + +static int32_t task_create_pinned_to_core_wrapper(void *task_func, const char *name, uint32_t stack_depth, void *param, uint32_t prio, void *task_handle, uint32_t core_id) +{ + return (uint32_t)xTaskCreatePinnedToCore(task_func, name, stack_depth, param, prio, task_handle, (core_id < portNUM_PROCESSORS ? core_id : tskNO_AFFINITY)); +} + +static int32_t task_create_wrapper(void *task_func, const char *name, uint32_t stack_depth, void *param, uint32_t prio, void *task_handle) +{ + return (uint32_t)xTaskCreate(task_func, name, stack_depth, param, prio, task_handle); +} + +static int32_t IRAM_ATTR task_ms_to_tick_wrapper(uint32_t ms) +{ + return (int32_t)(ms / portTICK_PERIOD_MS); +} + +static int32_t task_get_max_priority_wrapper(void) +{ + return (int32_t)(configMAX_PRIORITIES); +} + +static int32_t esp_event_post_wrapper(const char* event_base, int32_t event_id, void* event_data, size_t event_data_size, uint32_t ticks_to_wait) +{ + if (ticks_to_wait == OSI_FUNCS_TIME_BLOCKING) { + return (int32_t)esp_event_post(event_base, event_id, event_data, event_data_size, portMAX_DELAY); + } else { + return (int32_t)esp_event_post(event_base, event_id, event_data, event_data_size, ticks_to_wait); + } +} + +static void IRAM_ATTR wifi_apb80m_request_wrapper(void) +{ +#ifdef CONFIG_PM_ENABLE + wifi_apb80m_request(); +#endif +} + +static void IRAM_ATTR wifi_apb80m_release_wrapper(void) +{ +#ifdef CONFIG_PM_ENABLE + wifi_apb80m_release(); +#endif +} + +static void IRAM_ATTR timer_arm_wrapper(void *timer, uint32_t tmout, bool repeat) +{ + ets_timer_arm(timer, tmout, repeat); +} + +static void IRAM_ATTR timer_disarm_wrapper(void *timer) +{ + ets_timer_disarm(timer); +} + +static void timer_done_wrapper(void *ptimer) +{ + ets_timer_done(ptimer); +} + +static void timer_setfn_wrapper(void *ptimer, void *pfunction, void *parg) +{ + ets_timer_setfn(ptimer, pfunction, parg); +} + +static void IRAM_ATTR timer_arm_us_wrapper(void *ptimer, uint32_t us, bool repeat) +{ + ets_timer_arm_us(ptimer, us, repeat); +} + +static void wifi_reset_mac_wrapper(void) +{ + SET_PERI_REG_MASK(SYSCON_WIFI_RST_EN_REG, SYSTEM_MAC_RST); + CLEAR_PERI_REG_MASK(SYSCON_WIFI_RST_EN_REG, SYSTEM_MAC_RST); +} + +static void IRAM_ATTR wifi_rtc_enable_iso_wrapper(void) +{ +#if CONFIG_MAC_BB_PD + esp_mac_bb_power_down(); + SET_PERI_REG_MASK(SYSCON_WIFI_RST_EN_REG, SYSTEM_MAC_RST); +#endif +} + +static void IRAM_ATTR wifi_rtc_disable_iso_wrapper(void) +{ +#if CONFIG_MAC_BB_PD + esp_mac_bb_power_up(); + SET_PERI_REG_MASK(SYSCON_WIFI_RST_EN_REG, SYSTEM_MAC_RST); + CLEAR_PERI_REG_MASK(SYSCON_WIFI_RST_EN_REG, SYSTEM_MAC_RST); +#endif +} + +static void wifi_clock_enable_wrapper(void) +{ + wifi_module_enable(); +} + +static void wifi_clock_disable_wrapper(void) +{ + wifi_module_disable(); +} + +static int get_time_wrapper(void *t) +{ + return os_get_time(t); +} + +static uint32_t esp_clk_slowclk_cal_get_wrapper(void) +{ + /* The bit width of WiFi light sleep clock calibration is 12 while the one of + * system is 19. It should shift 19 - 12 = 7. + */ + return (esp_clk_slowclk_cal_get() >> (RTC_CLK_CAL_FRACT - SOC_WIFI_LIGHT_SLEEP_CLK_WIDTH)); +} + +static void * IRAM_ATTR malloc_internal_wrapper(size_t size) +{ + return heap_caps_malloc(size, MALLOC_CAP_8BIT|MALLOC_CAP_DMA|MALLOC_CAP_INTERNAL); +} + +static void * IRAM_ATTR realloc_internal_wrapper(void *ptr, size_t size) +{ + return heap_caps_realloc(ptr, size, MALLOC_CAP_8BIT|MALLOC_CAP_DMA|MALLOC_CAP_INTERNAL); +} + +static void * IRAM_ATTR calloc_internal_wrapper(size_t n, size_t size) +{ + return heap_caps_calloc(n, size, MALLOC_CAP_8BIT|MALLOC_CAP_DMA|MALLOC_CAP_INTERNAL); +} + +static void * IRAM_ATTR zalloc_internal_wrapper(size_t size) +{ + void *ptr = heap_caps_calloc(1, size, MALLOC_CAP_8BIT|MALLOC_CAP_DMA|MALLOC_CAP_INTERNAL); + return ptr; +} + +static esp_err_t nvs_open_wrapper(const char* name, uint32_t open_mode, nvs_handle_t *out_handle) +{ + return nvs_open(name,(nvs_open_mode_t)open_mode, out_handle); +} + +static void esp_log_writev_wrapper(uint32_t level, const char *tag, const char *format, va_list args) +{ + return esp_log_writev((esp_log_level_t)level,tag,format,args); +} + +static void esp_log_write_wrapper(uint32_t level,const char *tag,const char *format, ...) +{ + va_list list; + va_start(list, format); + esp_log_writev((esp_log_level_t)level, tag, format, list); + va_end(list); +} + +static esp_err_t esp_read_mac_wrapper(uint8_t* mac, uint32_t type) +{ + return esp_read_mac(mac, (esp_mac_type_t)type); +} + +static int coex_init_wrapper(void) +{ +#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE + return coex_init(); +#else + return 0; +#endif +} + +static void coex_deinit_wrapper(void) +{ +#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE + coex_deinit(); +#endif +} + +static int coex_enable_wrapper(void) +{ +#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE + return coex_enable(); +#else + return 0; +#endif +} + +static void coex_disable_wrapper(void) +{ +#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE + coex_disable(); +#endif +} + +static IRAM_ATTR uint32_t coex_status_get_wrapper(void) +{ +#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE + return coex_status_get(); +#else + return 0; +#endif +} + +static void coex_condition_set_wrapper(uint32_t type, bool dissatisfy) +{ +#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE + coex_condition_set(type, dissatisfy); +#endif +} + +static int coex_wifi_request_wrapper(uint32_t event, uint32_t latency, uint32_t duration) +{ +#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE + return coex_wifi_request(event, latency, duration); +#else + return 0; +#endif +} + +static IRAM_ATTR int coex_wifi_release_wrapper(uint32_t event) +{ +#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE + return coex_wifi_release(event); +#else + return 0; +#endif +} + +static int coex_wifi_channel_set_wrapper(uint8_t primary, uint8_t secondary) +{ +#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE + return coex_wifi_channel_set(primary, secondary); +#else + return 0; +#endif +} + +static IRAM_ATTR int coex_event_duration_get_wrapper(uint32_t event, uint32_t *duration) +{ +#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE + return coex_event_duration_get(event, duration); +#else + return 0; +#endif +} + +static int coex_pti_get_wrapper(uint32_t event, uint8_t *pti) +{ +#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE + return coex_pti_get(event, pti); +#else + return 0; +#endif +} + +static void coex_schm_status_bit_clear_wrapper(uint32_t type, uint32_t status) +{ +#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE + coex_schm_status_bit_clear(type, status); +#endif +} + +static void coex_schm_status_bit_set_wrapper(uint32_t type, uint32_t status) +{ +#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE + coex_schm_status_bit_set(type, status); +#endif +} + +static IRAM_ATTR int coex_schm_interval_set_wrapper(uint32_t interval) +{ +#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE + return coex_schm_interval_set(interval); +#else + return 0; +#endif +} + +static uint32_t coex_schm_interval_get_wrapper(void) +{ +#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE + return coex_schm_interval_get(); +#else + return 0; +#endif +} + +static uint8_t coex_schm_curr_period_get_wrapper(void) +{ +#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE + return coex_schm_curr_period_get(); +#else + return 0; +#endif +} + +static void * coex_schm_curr_phase_get_wrapper(void) +{ +#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE + return coex_schm_curr_phase_get(); +#else + return NULL; +#endif +} + +static int coex_schm_curr_phase_idx_set_wrapper(int idx) +{ +#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE + return coex_schm_curr_phase_idx_set(idx); +#else + return 0; +#endif +} + +static int coex_schm_curr_phase_idx_get_wrapper(void) +{ +#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE + return coex_schm_curr_phase_idx_get(); +#else + return 0; +#endif +} + +static void IRAM_ATTR esp_empty_wrapper(void) +{ + +} + +wifi_osi_funcs_t g_wifi_osi_funcs = { + ._version = ESP_WIFI_OS_ADAPTER_VERSION, + ._env_is_chip = env_is_chip_wrapper, + ._set_intr = set_intr_wrapper, + ._clear_intr = clear_intr_wrapper, + ._set_isr = set_isr_wrapper, + ._ints_on = enable_intr_wrapper, + ._ints_off = disable_intr_wrapper, + ._is_from_isr = is_from_isr_wrapper, + ._spin_lock_create = spin_lock_create_wrapper, + ._spin_lock_delete = free, + ._wifi_int_disable = wifi_int_disable_wrapper, + ._wifi_int_restore = wifi_int_restore_wrapper, + ._task_yield_from_isr = task_yield_from_isr_wrapper, + ._semphr_create = semphr_create_wrapper, + ._semphr_delete = semphr_delete_wrapper, + ._semphr_take = semphr_take_wrapper, + ._semphr_give = semphr_give_wrapper, + ._wifi_thread_semphr_get = wifi_thread_semphr_get_wrapper, + ._mutex_create = mutex_create_wrapper, + ._recursive_mutex_create = recursive_mutex_create_wrapper, + ._mutex_delete = mutex_delete_wrapper, + ._mutex_lock = mutex_lock_wrapper, + ._mutex_unlock = mutex_unlock_wrapper, + ._queue_create = queue_create_wrapper, + ._queue_delete = (void(*)(void *))vQueueDelete, + ._queue_send = queue_send_wrapper, + ._queue_send_from_isr = queue_send_from_isr_wrapper, + ._queue_send_to_back = queue_send_to_back_wrapper, + ._queue_send_to_front = queue_send_to_front_wrapper, + ._queue_recv = queue_recv_wrapper, + ._queue_msg_waiting = (uint32_t(*)(void *))uxQueueMessagesWaiting, + ._event_group_create = (void *(*)(void))xEventGroupCreate, + ._event_group_delete = (void(*)(void *))vEventGroupDelete, + ._event_group_set_bits = (uint32_t(*)(void *,uint32_t))xEventGroupSetBits, + ._event_group_clear_bits = (uint32_t(*)(void *,uint32_t))xEventGroupClearBits, + ._event_group_wait_bits = event_group_wait_bits_wrapper, + ._task_create_pinned_to_core = task_create_pinned_to_core_wrapper, + ._task_create = task_create_wrapper, + ._task_delete = (void(*)(void *))vTaskDelete, + ._task_delay = vTaskDelay, + ._task_ms_to_tick = task_ms_to_tick_wrapper, + ._task_get_current_task = (void *(*)(void))xTaskGetCurrentTaskHandle, + ._task_get_max_priority = task_get_max_priority_wrapper, + ._malloc = malloc, + ._free = free, + ._event_post = esp_event_post_wrapper, + ._get_free_heap_size = esp_get_free_internal_heap_size, + ._rand = esp_random, + ._dport_access_stall_other_cpu_start_wrap = esp_empty_wrapper, + ._dport_access_stall_other_cpu_end_wrap = esp_empty_wrapper, + ._wifi_apb80m_request = wifi_apb80m_request_wrapper, + ._wifi_apb80m_release = wifi_apb80m_release_wrapper, + ._phy_disable = esp_phy_disable, + ._phy_enable = esp_phy_enable, + ._phy_update_country_info = esp_phy_update_country_info, + ._read_mac = esp_read_mac_wrapper, + ._timer_arm = timer_arm_wrapper, + ._timer_disarm = timer_disarm_wrapper, + ._timer_done = timer_done_wrapper, + ._timer_setfn = timer_setfn_wrapper, + ._timer_arm_us = timer_arm_us_wrapper, + ._wifi_reset_mac = wifi_reset_mac_wrapper, + ._wifi_clock_enable = wifi_clock_enable_wrapper, + ._wifi_clock_disable = wifi_clock_disable_wrapper, + ._wifi_rtc_enable_iso = wifi_rtc_enable_iso_wrapper, + ._wifi_rtc_disable_iso = wifi_rtc_disable_iso_wrapper, + ._esp_timer_get_time = esp_timer_get_time, + ._nvs_set_i8 = nvs_set_i8, + ._nvs_get_i8 = nvs_get_i8, + ._nvs_set_u8 = nvs_set_u8, + ._nvs_get_u8 = nvs_get_u8, + ._nvs_set_u16 = nvs_set_u16, + ._nvs_get_u16 = nvs_get_u16, + ._nvs_open = nvs_open_wrapper, + ._nvs_close = nvs_close, + ._nvs_commit = nvs_commit, + ._nvs_set_blob = nvs_set_blob, + ._nvs_get_blob = nvs_get_blob, + ._nvs_erase_key = nvs_erase_key, + ._get_random = os_get_random, + ._get_time = get_time_wrapper, + ._random = os_random, + ._slowclk_cal_get = esp_clk_slowclk_cal_get_wrapper, + ._log_write = esp_log_write_wrapper, + ._log_writev = esp_log_writev_wrapper, + ._log_timestamp = esp_log_timestamp, + ._malloc_internal = malloc_internal_wrapper, + ._realloc_internal = realloc_internal_wrapper, + ._calloc_internal = calloc_internal_wrapper, + ._zalloc_internal = zalloc_internal_wrapper, + ._wifi_malloc = wifi_malloc, + ._wifi_realloc = wifi_realloc, + ._wifi_calloc = wifi_calloc, + ._wifi_zalloc = wifi_zalloc_wrapper, + ._wifi_create_queue = wifi_create_queue_wrapper, + ._wifi_delete_queue = wifi_delete_queue_wrapper, + ._coex_init = coex_init_wrapper, + ._coex_deinit = coex_deinit_wrapper, + ._coex_enable = coex_enable_wrapper, + ._coex_disable = coex_disable_wrapper, + ._coex_status_get = coex_status_get_wrapper, + ._coex_condition_set = coex_condition_set_wrapper, + ._coex_wifi_request = coex_wifi_request_wrapper, + ._coex_wifi_release = coex_wifi_release_wrapper, + ._coex_wifi_channel_set = coex_wifi_channel_set_wrapper, + ._coex_event_duration_get = coex_event_duration_get_wrapper, + ._coex_pti_get = coex_pti_get_wrapper, + ._coex_schm_status_bit_clear = coex_schm_status_bit_clear_wrapper, + ._coex_schm_status_bit_set = coex_schm_status_bit_set_wrapper, + ._coex_schm_interval_set = coex_schm_interval_set_wrapper, + ._coex_schm_interval_get = coex_schm_interval_get_wrapper, + ._coex_schm_curr_period_get = coex_schm_curr_period_get_wrapper, + ._coex_schm_curr_phase_get = coex_schm_curr_phase_get_wrapper, + ._coex_schm_curr_phase_idx_set = coex_schm_curr_phase_idx_set_wrapper, + ._coex_schm_curr_phase_idx_get = coex_schm_curr_phase_idx_get_wrapper, + ._magic = ESP_WIFI_OS_ADAPTER_MAGIC, +}; + +coex_adapter_funcs_t g_coex_adapter_funcs = { + ._version = COEX_ADAPTER_VERSION, + ._task_yield_from_isr = task_yield_from_isr_wrapper, + ._semphr_create = semphr_create_wrapper, + ._semphr_delete = semphr_delete_wrapper, + ._semphr_take_from_isr = semphr_take_from_isr_wrapper, + ._semphr_give_from_isr = semphr_give_from_isr_wrapper, + ._semphr_take = semphr_take_wrapper, + ._semphr_give = semphr_give_wrapper, + ._is_in_isr = xPortInIsrContext, + ._malloc_internal = malloc_internal_wrapper, + ._free = free, + ._esp_timer_get_time = esp_timer_get_time, + ._magic = COEX_ADAPTER_MAGIC, +}; diff --git a/components/esp_wifi/include/esp_private/wifi_os_adapter.h b/components/esp_wifi/include/esp_private/wifi_os_adapter.h index 88d0ee5402..d05cb7b66a 100644 --- a/components/esp_wifi/include/esp_private/wifi_os_adapter.h +++ b/components/esp_wifi/include/esp_private/wifi_os_adapter.h @@ -109,7 +109,7 @@ typedef struct { int (* _get_random)(uint8_t *buf, size_t len); int (* _get_time)(void *t); unsigned long (* _random)(void); -#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C2 uint32_t (* _slowclk_cal_get)(void); #endif void (* _log_write)(uint32_t level, const char* tag, const char* format, ...); diff --git a/components/esp_wifi/include/esp_wifi_types.h b/components/esp_wifi/include/esp_wifi_types.h index c1c5da08a5..edd9068a7f 100644 --- a/components/esp_wifi/include/esp_wifi_types.h +++ b/components/esp_wifi/include/esp_wifi_types.h @@ -276,7 +276,11 @@ typedef struct { uint32_t reserved:27; /**< bit: 5..31 reserved */ } wifi_sta_info_t; +#if CONFIG_IDF_TARGET_ESP32C2 +#define ESP_WIFI_MAX_CONN_NUM (4) /**< max number of stations which can connect to ESP32C2 soft-AP */ +#else #define ESP_WIFI_MAX_CONN_NUM (10) /**< max number of stations which can connect to ESP32 soft-AP */ +#endif /** @brief List of stations associated with the ESP32 Soft-AP */ typedef struct { @@ -346,7 +350,7 @@ typedef struct { unsigned sgi:1; /**< Short Guide Interval(SGI). 0: Long GI; 1: Short GI */ #if CONFIG_IDF_TARGET_ESP32 signed noise_floor:8; /**< noise floor of Radio Frequency Module(RF). unit: dBm*/ -#elif CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 +#elif CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C2 unsigned :8; /**< reserved */ #endif unsigned ampdu_cnt:8; /**< ampdu cnt */ @@ -357,7 +361,7 @@ typedef struct { unsigned :32; /**< reserved */ #if CONFIG_IDF_TARGET_ESP32S2 unsigned :32; /**< reserved */ -#elif CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 +#elif CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C2 signed noise_floor:8; /**< noise floor of Radio Frequency Module(RF). unit: dBm*/ unsigned :24; /**< reserved */ unsigned :32; /**< reserved */ @@ -367,7 +371,7 @@ typedef struct { #if CONFIG_IDF_TARGET_ESP32S2 signed noise_floor:8; /**< noise floor of Radio Frequency Module(RF). unit: dBm*/ unsigned :24; /**< reserved */ -#elif CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 +#elif CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C2 unsigned :32; /**< reserved */ unsigned :32; /**< reserved */ unsigned :32; /**< reserved */ diff --git a/components/soc/esp32c2/include/soc/soc_caps.h b/components/soc/esp32c2/include/soc/soc_caps.h index 2350c6e882..7f58821b0c 100644 --- a/components/soc/esp32c2/include/soc/soc_caps.h +++ b/components/soc/esp32c2/include/soc/soc_caps.h @@ -268,3 +268,9 @@ #define SOC_PM_SUPPORT_WIFI_WAKEUP (1) #define SOC_PM_SUPPORT_BT_WAKEUP (1) + +#define SOC_PM_SUPPORT_CPU_PD (0) + +#define SOC_PM_SUPPORT_WIFI_PD (0) + +#define SOC_PM_SUPPORT_BT_PD (0) From 58d04eb20328744fa37b206e63b5f409a479c2bc Mon Sep 17 00:00:00 2001 From: Jack Date: Sat, 7 May 2022 18:19:55 +0800 Subject: [PATCH 02/14] esp_wifi: update esp32c2 wifi rom & lib --- components/esp_phy/lib | 2 +- components/esp_wifi/esp32c2/esp_adapter.c | 10 ++++++++++ components/esp_wifi/include/esp_coexist_internal.h | 6 ++++++ .../esp_wifi/include/esp_private/wifi_os_adapter.h | 3 +++ components/esp_wifi/include/esp_wifi.h | 2 +- components/esp_wifi/include/esp_wifi_types.h | 2 ++ components/esp_wifi/lib | 2 +- 7 files changed, 24 insertions(+), 3 deletions(-) diff --git a/components/esp_phy/lib b/components/esp_phy/lib index c0491ee7cc..d8ee8f776a 160000 --- a/components/esp_phy/lib +++ b/components/esp_phy/lib @@ -1 +1 @@ -Subproject commit c0491ee7cc60288244268b04b523637a6e297739 +Subproject commit d8ee8f776acd1aafdfc3046f526db024b175b094 diff --git a/components/esp_wifi/esp32c2/esp_adapter.c b/components/esp_wifi/esp32c2/esp_adapter.c index bd31d94f60..ee3dc062ee 100644 --- a/components/esp_wifi/esp32c2/esp_adapter.c +++ b/components/esp_wifi/esp32c2/esp_adapter.c @@ -642,6 +642,15 @@ static int coex_schm_curr_phase_idx_get_wrapper(void) #endif } +static int coex_register_start_cb_wrapper(int (* cb)(void)) +{ +#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE + return coex_register_start_cb(cb); +#else + return 0; +#endif +} + static void IRAM_ATTR esp_empty_wrapper(void) { @@ -763,6 +772,7 @@ wifi_osi_funcs_t g_wifi_osi_funcs = { ._coex_schm_curr_phase_get = coex_schm_curr_phase_get_wrapper, ._coex_schm_curr_phase_idx_set = coex_schm_curr_phase_idx_set_wrapper, ._coex_schm_curr_phase_idx_get = coex_schm_curr_phase_idx_get_wrapper, + ._coex_register_start_cb = coex_register_start_cb_wrapper, ._magic = ESP_WIFI_OS_ADAPTER_MAGIC, }; diff --git a/components/esp_wifi/include/esp_coexist_internal.h b/components/esp_wifi/include/esp_coexist_internal.h index 7ba06d4c69..1e0e5d0a27 100644 --- a/components/esp_wifi/include/esp_coexist_internal.h +++ b/components/esp_wifi/include/esp_coexist_internal.h @@ -195,6 +195,12 @@ int coex_schm_curr_phase_idx_set(int idx); */ int coex_schm_curr_phase_idx_get(void); +/** + * @brief TODO + * + */ +int coex_register_start_cb(int (* cb)(void)); + /** * @brief Register coexistence adapter functions. * diff --git a/components/esp_wifi/include/esp_private/wifi_os_adapter.h b/components/esp_wifi/include/esp_private/wifi_os_adapter.h index d05cb7b66a..adf95ea7b5 100644 --- a/components/esp_wifi/include/esp_private/wifi_os_adapter.h +++ b/components/esp_wifi/include/esp_private/wifi_os_adapter.h @@ -22,6 +22,8 @@ extern "C" { #define OSI_QUEUE_SEND_BACK 1 #define OSI_QUEUE_SEND_OVERWRITE 2 +typedef int(* coex_start_wifi_cb_t)(void); + typedef struct { int32_t _version; bool (* _env_is_chip)(void); @@ -144,6 +146,7 @@ typedef struct { void * (* _coex_schm_curr_phase_get)(void); int (* _coex_schm_curr_phase_idx_set)(int idx); int (* _coex_schm_curr_phase_idx_get)(void); + int (* _coex_register_start_cb)(coex_start_wifi_cb_t cb); int32_t _magic; } wifi_osi_funcs_t; diff --git a/components/esp_wifi/include/esp_wifi.h b/components/esp_wifi/include/esp_wifi.h index 89bf70fcb7..5692c066fe 100644 --- a/components/esp_wifi/include/esp_wifi.h +++ b/components/esp_wifi/include/esp_wifi.h @@ -1218,7 +1218,7 @@ esp_err_t esp_wifi_config_11b_rate(wifi_interface_t ifx, bool disable); * * @param interval how much micriosecond would the chip wake up, from 1 to 65535. */ -esp_err_t esp_wifi_set_connectionless_wake_interval(uint16_t interval); +esp_err_t esp_wifi_connectionless_module_set_wake_interval(uint16_t interval); /** * @brief configure country diff --git a/components/esp_wifi/include/esp_wifi_types.h b/components/esp_wifi/include/esp_wifi_types.h index edd9068a7f..8c3c0f5aca 100644 --- a/components/esp_wifi/include/esp_wifi_types.h +++ b/components/esp_wifi/include/esp_wifi_types.h @@ -607,6 +607,8 @@ typedef enum { WIFI_EVENT_STA_BEACON_TIMEOUT, /**< ESP32 station beacon timeout */ + WIFI_EVENT_CONNECTIONLESS_MODULE_WAKE_INTERVAL_START, /**< ESP32 connectionless module wake interval start */ + WIFI_EVENT_MAX, /**< Invalid WiFi event ID */ } wifi_event_t; diff --git a/components/esp_wifi/lib b/components/esp_wifi/lib index 59e16e7cd3..aea6411b4c 160000 --- a/components/esp_wifi/lib +++ b/components/esp_wifi/lib @@ -1 +1 @@ -Subproject commit 59e16e7cd3a7d5b3b9daa2b4f54f617f51b34014 +Subproject commit aea6411b4cd90bc00524db58855bd6478a0e2475 From 84628ba883717015401366c3f123d604cbf15607 Mon Sep 17 00:00:00 2001 From: jingli Date: Thu, 6 Jan 2022 14:17:22 +0800 Subject: [PATCH 03/14] fix rtc attr for esp32c2 --- components/esp_common/include/esp_attr.h | 68 +++++++++++++++--------- 1 file changed, 43 insertions(+), 25 deletions(-) diff --git a/components/esp_common/include/esp_attr.h b/components/esp_common/include/esp_attr.h index 91fe654014..c02c54faed 100644 --- a/components/esp_common/include/esp_attr.h +++ b/components/esp_common/include/esp_attr.h @@ -12,6 +12,7 @@ extern "C" { #endif #include "sdkconfig.h" +#include "soc/soc_caps.h" #define ROMFN_ATTR @@ -61,9 +62,51 @@ extern "C" { // Use as esp_rom_printf(DRAM_STR("Hello world!\n")); #define DRAM_STR(str) (__extension__({static const DRAM_ATTR char __c[] = (str); (const char *)&__c;})) +#if SOC_RTC_FAST_MEM_SUPPORTED // Forces code into RTC fast memory. See "docs/deep-sleep-stub.rst" #define RTC_IRAM_ATTR _SECTION_ATTR_IMPL(".rtc.text", __COUNTER__) +// Allows to place data into RTC_FAST memory. +#define RTC_FAST_ATTR _SECTION_ATTR_IMPL(".rtc.force_fast", __COUNTER__) + +// Allows to place data into RTC_FAST memory and map it to coredump +#define COREDUMP_RTC_FAST_ATTR _SECTION_ATTR_IMPL(".rtc.fast.coredump", __COUNTER__) +#else +#define RTC_IRAM_ATTR +#define RTC_FAST_ATTR +#define COREDUMP_RTC_FAST_ATTR +#endif + +#if SOC_RTC_SLOW_MEM_SUPPORTED +// Forces data into RTC slow memory. See "docs/deep-sleep-stub.rst" +// Any variable marked with this attribute will keep its value +// during a deep sleep / wake cycle. +#define RTC_DATA_ATTR _SECTION_ATTR_IMPL(".rtc.data", __COUNTER__) + +// Allows to place data into RTC_SLOW memory. +#define RTC_SLOW_ATTR _SECTION_ATTR_IMPL(".rtc.force_slow", __COUNTER__) + +// Forces data into RTC slow memory of .noinit section. +// Any variable marked with this attribute will keep its value +// after restart or during a deep sleep / wake cycle. +#define RTC_NOINIT_ATTR _SECTION_ATTR_IMPL(".rtc_noinit", __COUNTER__) +#else +#define RTC_DATA_ATTR +#define RTC_SLOW_ATTR +#define RTC_NOINIT_ATTR +#endif + +#if SOC_RTC_FAST_MEM_SUPPORTED || SOC_RTC_SLOW_MEM_SUPPORTED +// Forces read-only data into RTC memory. See "docs/deep-sleep-stub.rst" +#define RTC_RODATA_ATTR _SECTION_ATTR_IMPL(".rtc.rodata", __COUNTER__) + +// Forces data into RTC memory and map it to coredump +#define COREDUMP_RTC_DATA_ATTR _SECTION_ATTR_IMPL(".rtc.coredump", __COUNTER__) +#else +#define RTC_RODATA_ATTR +#define COREDUMP_RTC_DATA_ATTR +#endif + #if CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY // Forces bss variable into external memory. " #define EXT_RAM_BSS_ATTR _SECTION_ATTR_IMPL(".ext_ram.bss", __COUNTER__) @@ -81,20 +124,6 @@ extern "C" { #define EXT_RAM_ATTR _Pragma ("GCC warning \"'EXT_RAM_ATTR' macro is deprecated, please use `EXT_RAM_BSS_ATTR`\"") #endif -// Forces data into RTC slow memory. See "docs/deep-sleep-stub.rst" -// Any variable marked with this attribute will keep its value -// during a deep sleep / wake cycle. -#define RTC_DATA_ATTR _SECTION_ATTR_IMPL(".rtc.data", __COUNTER__) - -// Forces read-only data into RTC memory. See "docs/deep-sleep-stub.rst" -#define RTC_RODATA_ATTR _SECTION_ATTR_IMPL(".rtc.rodata", __COUNTER__) - -// Allows to place data into RTC_SLOW memory. -#define RTC_SLOW_ATTR _SECTION_ATTR_IMPL(".rtc.force_slow", __COUNTER__) - -// Allows to place data into RTC_FAST memory. -#define RTC_FAST_ATTR _SECTION_ATTR_IMPL(".rtc.force_fast", __COUNTER__) - // Forces data into noinit section to avoid initialization after restart. #define __NOINIT_ATTR _SECTION_ATTR_IMPL(".noinit", __COUNTER__) @@ -106,22 +135,11 @@ extern "C" { #define EXT_RAM_NOINIT_ATTR __NOINIT_ATTR #endif -// Forces data into RTC slow memory of .noinit section. -// Any variable marked with this attribute will keep its value -// after restart or during a deep sleep / wake cycle. -#define RTC_NOINIT_ATTR _SECTION_ATTR_IMPL(".rtc_noinit", __COUNTER__) - // Forces code into DRAM instead of flash and map it to coredump // Use dram2 instead of dram1 to make sure this section will not be included // by dram1 section in the linker script #define COREDUMP_DRAM_ATTR _SECTION_ATTR_IMPL(".dram2.coredump", __COUNTER__) -// Forces data into RTC memory and map it to coredump -#define COREDUMP_RTC_DATA_ATTR _SECTION_ATTR_IMPL(".rtc.coredump", __COUNTER__) - -// Allows to place data into RTC_FAST memory and map it to coredump -#define COREDUMP_RTC_FAST_ATTR _SECTION_ATTR_IMPL(".rtc.fast.coredump", __COUNTER__) - // Forces to not inline function #define NOINLINE_ATTR __attribute__((noinline)) From 4302e28698f5f617e4dd8e92ed54d68ccd600b07 Mon Sep 17 00:00:00 2001 From: jiangguangming Date: Wed, 12 Jan 2022 17:29:57 +0800 Subject: [PATCH 04/14] newlib: use newlib nano format default --- components/newlib/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/newlib/Kconfig b/components/newlib/Kconfig index 564ea88895..9e6cefdc27 100644 --- a/components/newlib/Kconfig +++ b/components/newlib/Kconfig @@ -50,7 +50,7 @@ menu "Newlib" config NEWLIB_NANO_FORMAT bool "Enable 'nano' formatting options for printf/scanf family" - default n + default y if IDF_TARGET_ESP32C2 help ESP32 ROM contains parts of newlib C library, including printf/scanf family of functions. These functions have been compiled with so-called "nano" From c7beae1d6a9f2b396581395813a291465a42bd41 Mon Sep 17 00:00:00 2001 From: jiangguangming Date: Mon, 17 Jan 2022 20:00:15 +0800 Subject: [PATCH 05/14] newlib: 64-bits time_t test pass please keep in mind that don't use nano-foramt printf for 64-bits --- components/newlib/test/test_time.c | 1 + 1 file changed, 1 insertion(+) diff --git a/components/newlib/test/test_time.c b/components/newlib/test/test_time.c index d833de37d8..4a2966d209 100644 --- a/components/newlib/test/test_time.c +++ b/components/newlib/test/test_time.c @@ -35,6 +35,7 @@ #elif CONFIG_IDF_TARGET_ESP32H2 #include "esp32h2/rtc.h" #elif CONFIG_IDF_TARGET_ESP32C2 +#include "esp32c2/rtc.h" #endif #if portNUM_PROCESSORS == 2 From fcf8c84ad51f18b2fcf2dc2e37334c8876982edb Mon Sep 17 00:00:00 2001 From: Zhang Jun Hao Date: Tue, 16 Nov 2021 10:19:26 +0800 Subject: [PATCH 06/14] fix potential leak of memory check error --- .../wpa_supplicant/esp_supplicant/src/crypto/crypto_mbedtls.c | 1 + 1 file changed, 1 insertion(+) diff --git a/components/wpa_supplicant/esp_supplicant/src/crypto/crypto_mbedtls.c b/components/wpa_supplicant/esp_supplicant/src/crypto/crypto_mbedtls.c index 577b50d202..f82d44980a 100644 --- a/components/wpa_supplicant/esp_supplicant/src/crypto/crypto_mbedtls.c +++ b/components/wpa_supplicant/esp_supplicant/src/crypto/crypto_mbedtls.c @@ -894,6 +894,7 @@ int rc4_skip(const u8 *key, size_t keylen, size_t skip, if ((ret = mbedtls_arc4_crypt(&ctx, len, skip_buf_in, skip_buf_out)) != 0) { wpa_printf(MSG_ERROR, "rc4 encryption failed"); + os_free(obuf); return -1; } os_memcpy(skip_buf_in, skip_buf_out, 16); From 31f9292f90e48c4418b41d2d1382d87c00169a72 Mon Sep 17 00:00:00 2001 From: Zhang Junhao Date: Tue, 10 May 2022 17:09:06 +0800 Subject: [PATCH 07/14] feat: disable mbedtls rom code on master --- .../esp_rom/esp32c2/ld/esp32c2.rom.mbedtls.ld | 388 ------------------ 1 file changed, 388 deletions(-) diff --git a/components/esp_rom/esp32c2/ld/esp32c2.rom.mbedtls.ld b/components/esp_rom/esp32c2/ld/esp32c2.rom.mbedtls.ld index de54ca21ba..bc0f7b24b1 100644 --- a/components/esp_rom/esp32c2/ld/esp32c2.rom.mbedtls.ld +++ b/components/esp_rom/esp32c2/ld/esp32c2.rom.mbedtls.ld @@ -19,395 +19,7 @@ ***************************************/ /* Functions */ -mbedtls_aes_init = 0x40002664; -ssl_write_client_hello = 0x40002668; -ssl_parse_server_hello = 0x4000266c; -ssl_parse_server_key_exchange = 0x40002670; -ssl_parse_certificate_request = 0x40002674; -ssl_parse_server_hello_done = 0x40002678; -ssl_write_client_key_exchange = 0x4000267c; -ssl_write_certificate_verify = 0x40002680; -ssl_parse_new_session_ticket = 0x40002684; -mbedtls_aes_free = 0x40002688; -mbedtls_aes_setkey_enc = 0x4000268c; -mbedtls_aes_setkey_dec = 0x40002690; -mbedtls_aes_crypt_ecb = 0x40002694; -mbedtls_aes_crypt_cbc = 0x40002698; -mbedtls_internal_aes_encrypt = 0x4000269c; -mbedtls_internal_aes_decrypt = 0x400026a0; -mbedtls_asn1_get_len = 0x400026a4; -mbedtls_asn1_get_tag = 0x400026a8; -mbedtls_asn1_get_bool = 0x400026ac; -mbedtls_asn1_get_int = 0x400026b0; -mbedtls_asn1_get_bitstring = 0x400026b4; -mbedtls_asn1_get_bitstring_null = 0x400026b8; -mbedtls_asn1_get_sequence_of = 0x400026bc; -mbedtls_asn1_get_mpi = 0x400026c0; -mbedtls_asn1_get_alg = 0x400026c4; -mbedtls_asn1_get_alg_null = 0x400026c8; -mbedtls_asn1_write_len = 0x400026cc; -mbedtls_asn1_write_tag = 0x400026d0; -mbedtls_asn1_write_mpi = 0x400026d4; -mbedtls_base64_decode = 0x400026d8; -mbedtls_mpi_init = 0x400026dc; -mbedtls_mpi_free = 0x400026e0; -mbedtls_mpi_grow = 0x400026e4; -mbedtls_mpi_shrink = 0x400026e8; -mbedtls_mpi_copy = 0x400026ec; -mbedtls_mpi_safe_cond_assign = 0x400026f0; -mbedtls_mpi_safe_cond_swap = 0x400026f4; -mbedtls_mpi_lset = 0x400026f8; -mbedtls_mpi_get_bit = 0x400026fc; -mbedtls_mpi_set_bit = 0x40002700; -mbedtls_mpi_lsb = 0x40002704; -mbedtls_mpi_bitlen = 0x40002708; -mbedtls_mpi_size = 0x4000270c; -mbedtls_mpi_read_binary = 0x40002710; -mbedtls_mpi_write_binary = 0x40002714; -mbedtls_mpi_shift_l = 0x40002718; -mbedtls_mpi_shift_r = 0x4000271c; -mbedtls_mpi_cmp_abs = 0x40002720; -mbedtls_mpi_cmp_mpi = 0x40002724; -mbedtls_mpi_lt_mpi_ct = 0x40002728; -mbedtls_mpi_cmp_int = 0x4000272c; -mbedtls_mpi_add_abs = 0x40002730; -mbedtls_mpi_sub_abs = 0x40002734; -mbedtls_mpi_add_mpi = 0x40002738; -mbedtls_mpi_sub_mpi = 0x4000273c; -mbedtls_mpi_add_int = 0x40002740; -mbedtls_mpi_sub_int = 0x40002744; -mbedtls_mpi_mul_mpi = 0x40002748; -mbedtls_mpi_mul_int = 0x4000274c; -mbedtls_mpi_div_mpi = 0x40002750; -mbedtls_mpi_div_int = 0x40002754; -mbedtls_mpi_mod_mpi = 0x40002758; -mbedtls_mpi_mod_int = 0x4000275c; -mbedtls_mpi_exp_mod = 0x40002760; -mbedtls_mpi_fill_random = 0x40002764; -mbedtls_mpi_gcd = 0x40002768; -mbedtls_mpi_inv_mod = 0x4000276c; -mbedtls_mpi_is_prime_ext = 0x40002770; -mbedtls_ccm_star_encrypt_and_tag = 0x40002774; -mbedtls_ccm_star_auth_decrypt = 0x40002778; -mbedtls_cipher_init = 0x4000277c; -mbedtls_cipher_set_padding_mode = 0x40002780; -mbedtls_cipher_reset = 0x40002784; -mbedtls_cipher_finish = 0x40002788; -mbedtls_cipher_crypt = 0x4000278c; -mbedtls_cipher_cmac_starts = 0x40002790; -mbedtls_cipher_cmac_update = 0x40002794; -mbedtls_cipher_cmac_finish = 0x40002798; -mbedtls_ctr_drbg_init = 0x4000279c; -mbedtls_ctr_drbg_seed = 0x400027a0; -mbedtls_ctr_drbg_free = 0x400027a4; -mbedtls_ctr_drbg_reseed = 0x400027a8; -mbedtls_ctr_drbg_random_with_add = 0x400027ac; -mbedtls_ctr_drbg_random = 0x400027b0; -mbedtls_dhm_init = 0x400027b4; -mbedtls_dhm_read_params = 0x400027b8; -mbedtls_dhm_make_public = 0x400027bc; -mbedtls_dhm_calc_secret = 0x400027c0; -mbedtls_dhm_free = 0x400027c4; -mbedtls_ecdh_init = 0x400027c8; -mbedtls_ecdh_setup = 0x400027cc; -mbedtls_ecdh_free = 0x400027d0; -mbedtls_ecdh_read_params = 0x400027d4; -mbedtls_ecdh_get_params = 0x400027d8; -mbedtls_ecdh_make_public = 0x400027dc; -mbedtls_ecdh_calc_secret = 0x400027e0; -mbedtls_ecdh_enable_restart = 0x400027e4; -mbedtls_ecdsa_write_signature = 0x400027e8; -mbedtls_ecdsa_write_signature_restartable = 0x400027ec; -mbedtls_ecdsa_read_signature = 0x400027f0; -mbedtls_ecdsa_read_signature_restartable = 0x400027f4; -mbedtls_ecdsa_from_keypair = 0x400027f8; -mbedtls_ecdsa_init = 0x400027fc; -mbedtls_ecdsa_free = 0x40002800; -mbedtls_ecdsa_restart_init = 0x40002804; -mbedtls_ecdsa_restart_free = 0x40002808; -mbedtls_ecjpake_init = 0x4000280c; -mbedtls_ecjpake_check = 0x40002810; -mbedtls_ecjpake_write_round_one = 0x40002814; -mbedtls_ecjpake_read_round_one = 0x40002818; -mbedtls_ecjpake_write_round_two = 0x4000281c; -mbedtls_ecjpake_read_round_two = 0x40002820; -mbedtls_ecjpake_derive_secret = 0x40002824; -mbedtls_ecjpake_free = 0x40002828; -mbedtls_ecp_check_budget = 0x4000282c; -mbedtls_ecp_restart_is_enabled = 0x40002830; -mbedtls_ecp_curve_list = 0x40002834; -mbedtls_ecp_grp_id_list = 0x40002838; -mbedtls_ecp_curve_info_from_grp_id = 0x4000283c; -mbedtls_ecp_curve_info_from_tls_id = 0x40002840; -mbedtls_ecp_point_init = 0x40002844; -mbedtls_ecp_group_init = 0x40002848; -mbedtls_ecp_keypair_init = 0x4000284c; -mbedtls_ecp_point_free = 0x40002850; -mbedtls_ecp_group_free = 0x40002854; -mbedtls_ecp_keypair_free = 0x40002858; -mbedtls_ecp_restart_init = 0x4000285c; -mbedtls_ecp_restart_free = 0x40002860; -mbedtls_ecp_copy = 0x40002864; -mbedtls_ecp_group_copy = 0x40002868; -mbedtls_ecp_set_zero = 0x4000286c; -mbedtls_ecp_is_zero = 0x40002870; -mbedtls_ecp_point_cmp = 0x40002874; -mbedtls_ecp_point_write_binary = 0x40002878; -mbedtls_ecp_point_read_binary = 0x4000287c; -mbedtls_ecp_tls_read_point = 0x40002880; -mbedtls_ecp_tls_write_point = 0x40002884; -mbedtls_ecp_group_load = 0x40002888; -mbedtls_ecp_tls_read_group = 0x4000288c; -mbedtls_ecp_tls_read_group_id = 0x40002890; -mbedtls_ecp_tls_write_group = 0x40002894; -mbedtls_ecp_mul = 0x40002898; -mbedtls_ecp_mul_restartable = 0x4000289c; -mbedtls_ecp_muladd = 0x400028a0; -mbedtls_ecp_muladd_restartable = 0x400028a4; -mbedtls_ecp_check_pubkey = 0x400028a8; -mbedtls_ecp_check_privkey = 0x400028ac; -mbedtls_ecp_gen_privkey = 0x400028b0; -mbedtls_ecp_gen_keypair_base = 0x400028b4; -mbedtls_ecp_check_pub_priv = 0x400028b8; -mbedtls_entropy_add_source = 0x400028bc; -mbedtls_entropy_func = 0x400028c0; -mbedtls_gcm_crypt_and_tag = 0x400028c4; -mbedtls_gcm_starts = 0x400028c8; -mbedtls_gcm_update = 0x400028cc; -mbedtls_gcm_finish = 0x400028d0; -mbedtls_hmac_drbg_init = 0x400028d4; -mbedtls_hmac_drbg_seed_buf = 0x400028d8; -mbedtls_hmac_drbg_update_ret = 0x400028dc; -mbedtls_hmac_drbg_reseed = 0x400028e0; -mbedtls_hmac_drbg_random_with_add = 0x400028e4; -mbedtls_hmac_drbg_random = 0x400028e8; -mbedtls_hmac_drbg_free = 0x400028ec; -mbedtls_md_list = 0x400028f0; -mbedtls_md_init = 0x400028f4; -mbedtls_md_free = 0x400028f8; -mbedtls_md_setup = 0x400028fc; -mbedtls_md_clone = 0x40002900; -mbedtls_md_get_size = 0x40002904; -mbedtls_md_get_type = 0x40002908; -mbedtls_md_starts = 0x4000290c; -mbedtls_md_update = 0x40002910; -mbedtls_md_finish = 0x40002914; -mbedtls_md = 0x40002918; -mbedtls_md_hmac_starts = 0x4000291c; -mbedtls_md_hmac_update = 0x40002920; -mbedtls_md_hmac_finish = 0x40002924; -mbedtls_md_hmac_reset = 0x40002928; -mbedtls_oid_get_x509_ext_type = 0x4000292c; -mbedtls_oid_get_pk_alg = 0x40002930; -mbedtls_oid_get_ec_grp = 0x40002934; -mbedtls_oid_get_sig_alg = 0x40002938; -mbedtls_oid_get_md_alg = 0x4000293c; -mbedtls_oid_get_md_hmac = 0x40002940; -mbedtls_oid_get_oid_by_md = 0x40002944; -mbedtls_oid_get_cipher_alg = 0x40002948; -mbedtls_oid_get_pkcs12_pbe_alg = 0x4000294c; -mbedtls_pem_init = 0x40002950; -mbedtls_pem_free = 0x40002954; -mbedtls_pkcs12_pbe_sha1_rc4_128 = 0x40002958; -mbedtls_pkcs12_pbe = 0x4000295c; -mbedtls_pkcs12_derivation = 0x40002960; -mbedtls_pkcs5_pbes2 = 0x40002964; -mbedtls_pkcs5_pbkdf2_hmac = 0x40002968; -mbedtls_pk_info_from_type = 0x4000296c; -mbedtls_pk_init = 0x40002970; -mbedtls_pk_free = 0x40002974; -mbedtls_pk_restart_init = 0x40002978; -mbedtls_pk_restart_free = 0x4000297c; -mbedtls_pk_setup = 0x40002980; -mbedtls_pk_can_do = 0x40002984; -mbedtls_pk_verify = 0x40002988; -mbedtls_pk_verify_restartable = 0x4000298c; -mbedtls_pk_verify_ext = 0x40002990; -mbedtls_pk_sign_restartable = 0x40002994; -mbedtls_pk_encrypt = 0x40002998; -mbedtls_pk_get_type = 0x4000299c; -mbedtls_pk_parse_subpubkey = 0x400029a0; -mbedtls_rsa_init = 0x400029a4; -mbedtls_rsa_import = 0x400029a8; -mbedtls_rsa_import_raw = 0x400029ac; -mbedtls_rsa_complete = 0x400029b0; -mbedtls_rsa_set_padding = 0x400029b4; -mbedtls_rsa_get_len = 0x400029b8; -mbedtls_rsa_check_pubkey = 0x400029bc; -mbedtls_rsa_check_privkey = 0x400029c0; -mbedtls_rsa_check_pub_priv = 0x400029c4; -mbedtls_rsa_public = 0x400029c8; -mbedtls_rsa_private = 0x400029cc; -mbedtls_rsa_pkcs1_encrypt = 0x400029d0; -mbedtls_rsa_rsaes_pkcs1_v15_encrypt = 0x400029d4; -mbedtls_rsa_rsaes_oaep_encrypt = 0x400029d8; -mbedtls_rsa_pkcs1_decrypt = 0x400029dc; -mbedtls_rsa_rsaes_pkcs1_v15_decrypt = 0x400029e0; -mbedtls_rsa_rsaes_oaep_decrypt = 0x400029e4; -mbedtls_rsa_pkcs1_sign = 0x400029e8; -mbedtls_rsa_rsassa_pkcs1_v15_sign = 0x400029ec; -mbedtls_rsa_rsassa_pss_sign = 0x400029f0; -mbedtls_rsa_pkcs1_verify = 0x400029f4; -mbedtls_rsa_rsassa_pkcs1_v15_verify = 0x400029f8; -mbedtls_rsa_rsassa_pss_verify = 0x400029fc; -mbedtls_rsa_rsassa_pss_verify_ext = 0x40002a00; -mbedtls_rsa_free = 0x40002a04; -mbedtls_rsa_deduce_primes = 0x40002a08; -mbedtls_rsa_deduce_private_exponent = 0x40002a0c; -mbedtls_rsa_deduce_crt = 0x40002a10; -mbedtls_rsa_validate_params = 0x40002a14; -mbedtls_rsa_validate_crt = 0x40002a18; -mbedtls_sha1_init = 0x40002a1c; -mbedtls_sha1_free = 0x40002a20; -mbedtls_sha1_clone = 0x40002a24; -mbedtls_sha1_starts_ret = 0x40002a28; -mbedtls_sha1_finish_ret = 0x40002a2c; -mbedtls_sha256_init = 0x40002a30; -mbedtls_sha256_free = 0x40002a34; -mbedtls_sha256_clone = 0x40002a38; -mbedtls_sha256_starts_ret = 0x40002a3c; -mbedtls_sha256_finish_ret = 0x40002a40; -mbedtls_sha256_ret = 0x40002a44; -mbedtls_sha512_init = 0x40002a48; -mbedtls_sha512_free = 0x40002a4c; -mbedtls_sha512_clone = 0x40002a50; -mbedtls_sha512_starts_ret = 0x40002a54; -mbedtls_sha512_update_ret = 0x40002a58; -mbedtls_sha512_finish_ret = 0x40002a5c; -mbedtls_internal_sha512_process = 0x40002a60; -mbedtls_sha512_ret = 0x40002a64; -mbedtls_ssl_conf_endpoint = 0x40002a68; -mbedtls_ssl_conf_transport = 0x40002a6c; -mbedtls_ssl_set_bio = 0x40002a70; -mbedtls_ssl_conf_dh_param_bin = 0x40002a74; -mbedtls_ssl_get_max_frag_len = 0x40002a78; -mbedtls_ssl_get_max_out_record_payload = 0x40002a7c; -mbedtls_ssl_handshake = 0x40002a80; -mbedtls_ssl_handshake_step = 0x40002a84; -mbedtls_ssl_renegotiate = 0x40002a88; -mbedtls_ssl_send_alert_message = 0x40002a8c; -mbedtls_ssl_config_defaults = 0x40002a90; -mbedtls_ssl_session_init = 0x40002a94; -mbedtls_ssl_session_free = 0x40002a98; -mbedtls_ssl_transform_free = 0x40002a9c; -mbedtls_ssl_handshake_free = 0x40002aa0; -mbedtls_ssl_handshake_client_step = 0x40002aa4; -mbedtls_ssl_handshake_wrapup = 0x40002aa8; -mbedtls_ssl_derive_keys = 0x40002aac; -mbedtls_ssl_handle_message_type = 0x40002ab0; -mbedtls_ssl_prepare_handshake_record = 0x40002ab4; -mbedtls_ssl_update_handshake_status = 0x40002ab8; -mbedtls_ssl_read_record = 0x40002abc; -mbedtls_ssl_fetch_input = 0x40002ac0; -mbedtls_ssl_write_handshake_msg = 0x40002ac4; -mbedtls_ssl_write_record = 0x40002ac8; -mbedtls_ssl_flush_output = 0x40002acc; -mbedtls_ssl_parse_certificate = 0x40002ad0; -mbedtls_ssl_write_certificate = 0x40002ad4; -mbedtls_ssl_parse_change_cipher_spec = 0x40002ad8; -mbedtls_ssl_write_change_cipher_spec = 0x40002adc; -mbedtls_ssl_parse_finished = 0x40002ae0; -mbedtls_ssl_write_finished = 0x40002ae4; -mbedtls_ssl_optimize_checksum = 0x40002ae8; -mbedtls_ssl_psk_derive_premaster = 0x40002aec; -mbedtls_ssl_sig_from_pk = 0x40002af0; -mbedtls_ssl_pk_alg_from_sig = 0x40002af4; -mbedtls_ssl_md_alg_from_hash = 0x40002af8; -mbedtls_ssl_hash_from_md_alg = 0x40002afc; -mbedtls_ssl_check_curve = 0x40002b00; -mbedtls_ssl_check_sig_hash = 0x40002b04; -mbedtls_ssl_write_version = 0x40002b08; -mbedtls_ssl_read_version = 0x40002b0c; -mbedtls_ssl_get_key_exchange_md_ssl_tls = 0x40002b10; -mbedtls_ssl_get_key_exchange_md_tls1_2 = 0x40002b14; -mbedtls_ssl_cf_hmac = 0x40002b18; -mbedtls_ssl_cf_memcpy_offset = 0x40002b1c; -mbedtls_x509_crt_parse_der = 0x40002b20; -mbedtls_x509_crt_verify_restartable = 0x40002b24; -mbedtls_x509_crt_check_key_usage = 0x40002b28; -mbedtls_x509_crt_check_extended_key_usage = 0x40002b2c; -mbedtls_x509_crt_is_revoked = 0x40002b30; -mbedtls_x509_crt_init = 0x40002b34; -mbedtls_x509_crt_free = 0x40002b38; -mbedtls_x509_crt_restart_init = 0x40002b3c; -mbedtls_x509_crt_restart_free = 0x40002b40; -mbedtls_x509_get_name = 0x40002b44; -mbedtls_x509_get_alg_null = 0x40002b48; -mbedtls_x509_get_alg = 0x40002b4c; -mbedtls_x509_get_rsassa_pss_params = 0x40002b50; -mbedtls_x509_get_sig = 0x40002b54; -mbedtls_x509_get_sig_alg = 0x40002b58; -mbedtls_x509_get_time = 0x40002b5c; -mbedtls_x509_get_serial = 0x40002b60; -mbedtls_x509_get_ext = 0x40002b64; -mbedtls_aes_xts_init = 0x40002b68; -mbedtls_aes_xts_free = 0x40002b6c; -mbedtls_aes_xts_setkey_enc = 0x40002b70; -mbedtls_aes_xts_setkey_dec = 0x40002b74; -mbedtls_aes_crypt_xts = 0x40002b78; -mbedtls_aes_crypt_cfb128 = 0x40002b7c; -mbedtls_aes_crypt_ofb = 0x40002b80; -mbedtls_aes_crypt_ctr = 0x40002b84; -mbedtls_arc4_init = 0x40002b88; -mbedtls_arc4_free = 0x40002b8c; -mbedtls_arc4_setup = 0x40002b90; -mbedtls_arc4_crypt = 0x40002b94; -mbedtls_ccm_init = 0x40002b98; -mbedtls_ccm_setkey = 0x40002b9c; -mbedtls_ccm_free = 0x40002ba0; -mbedtls_ccm_encrypt_and_tag = 0x40002ba4; -mbedtls_ccm_auth_decrypt = 0x40002ba8; -mbedtls_dhm_make_params = 0x40002bac; -mbedtls_dhm_set_group = 0x40002bb0; -mbedtls_dhm_read_public = 0x40002bb4; -mbedtls_ecdh_make_params = 0x40002bb8; -mbedtls_ecdh_read_public = 0x40002bbc; -mbedtls_entropy_init = 0x40002bc0; -mbedtls_entropy_free = 0x40002bc4; -mbedtls_gcm_init = 0x40002bc8; -mbedtls_gcm_setkey = 0x40002bcc; -mbedtls_gcm_auth_decrypt = 0x40002bd0; -mbedtls_gcm_free = 0x40002bd4; -mbedtls_md5_init = 0x40002bd8; -mbedtls_md5_free = 0x40002bdc; -mbedtls_md5_clone = 0x40002be0; mbedtls_md5_starts_ret = 0x40002be4; mbedtls_md5_update_ret = 0x40002be8; mbedtls_md5_finish_ret = 0x40002bec; -mbedtls_internal_md5_process = 0x40002bf0; -mbedtls_md5_ret = 0x40002bf4; -mbedtls_pk_get_bitlen = 0x40002bf8; -mbedtls_pk_sign = 0x40002bfc; -mbedtls_pk_decrypt = 0x40002c00; -mbedtls_pk_parse_key = 0x40002c04; -mbedtls_sha1_ret = 0x40002c08; -mbedtls_ssl_init = 0x40002c0c; -mbedtls_ssl_setup = 0x40002c10; -mbedtls_ssl_conf_authmode = 0x40002c14; -mbedtls_ssl_conf_rng = 0x40002c18; -mbedtls_ssl_conf_ca_chain = 0x40002c1c; -mbedtls_ssl_conf_own_cert = 0x40002c20; -mbedtls_ssl_read = 0x40002c24; -mbedtls_ssl_write = 0x40002c28; -mbedtls_ssl_config_init = 0x40002c2c; -mbedtls_ssl_sig_hash_set_find = 0x40002c30; -mbedtls_ssl_sig_hash_set_add = 0x40002c34; -mbedtls_ssl_sig_hash_set_const_hash = 0x40002c38; -mbedtls_ssl_sig_from_pk_alg = 0x40002c3c; -mbedtls_ssl_set_calc_verify_md = 0x40002c40; -mbedtls_x509_crt_parse = 0x40002c44; /* Data (.data, .bss, .rodata) */ -p_osi_mbedtls_rom_funcs = 0x3fcdfaa0; -mbedtls_x509_crt_profile_default = 0x3ff4fba4; -mbedtls_x509_crt_profile_suiteb = 0x3ff4fb94; -aes_FSb_ptr = 0x3fcdfa9c; -AES_RT0_ptr = 0x3fcdfa98; -AES_RT1_ptr = 0x3fcdfa94; -AES_RT2_ptr = 0x3fcdfa90; -AES_RT3_ptr = 0x3fcdfa8c; -AES_FT0_ptr = 0x3fcdfa88; -AES_FT1_ptr = 0x3fcdfa84; -AES_FT2_ptr = 0x3fcdfa80; -AES_FT3_ptr = 0x3fcdfa7c; -bignum_small_prime_ptr = 0x3fcdfa78; -sha512_K_ptr = 0x3fcdfa74; From 60cbbffc748af12a62f322db37524122c4757894 Mon Sep 17 00:00:00 2001 From: Jessy Chen Date: Mon, 9 May 2022 07:57:01 -0400 Subject: [PATCH 08/14] esp_phy: optimize esp32c2 tx power control --- components/esp_phy/esp32c2/include/phy_init_data.h | 4 ++-- components/esp_rom/esp32c2/ld/esp32c2.rom.ld | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/components/esp_phy/esp32c2/include/phy_init_data.h b/components/esp_phy/esp32c2/include/phy_init_data.h index 7e458c4311..212cd582de 100644 --- a/components/esp_phy/esp32c2/include/phy_init_data.h +++ b/components/esp_phy/esp32c2/include/phy_init_data.h @@ -20,8 +20,8 @@ extern "C" { // define the lowest tx power as LOWEST_PHY_TX_POWER #define PHY_TX_POWER_LOWEST LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 52) -#define PHY_TX_POWER_OFFSET 44 -#define PHY_TX_POWER_NUM 5 +#define PHY_TX_POWER_OFFSET 2 +#define PHY_TX_POWER_NUM 14 #if CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN #define PHY_CRC_ALGORITHM 1 diff --git a/components/esp_rom/esp32c2/ld/esp32c2.rom.ld b/components/esp_rom/esp32c2/ld/esp32c2.rom.ld index 4ab6b49245..c3f3e2e7d3 100644 --- a/components/esp_rom/esp32c2/ld/esp32c2.rom.ld +++ b/components/esp_rom/esp32c2/ld/esp32c2.rom.ld @@ -2448,7 +2448,7 @@ rfpll_cap_track = 0x40002538; phy_param_track = 0x4000253c; txpwr_correct = 0x40002540; txpwr_cal_track = 0x40002544; -tx_pwctrl_background = 0x40002548; +/* tx_pwctrl_background = 0x40002548;*/ bt_track_tx_power = 0x4000254c; wifi_track_tx_power = 0x40002550; rom_code_to_temp = 0x40002554; From 0ae391ef078a6eafa717b034de47a886fd9fce8e Mon Sep 17 00:00:00 2001 From: Jessy Chen Date: Tue, 10 May 2022 04:00:01 -0400 Subject: [PATCH 09/14] esp_wifi: enable FTM for esp32c2 & fix pre-commit check --- components/esp_phy/CMakeLists.txt | 3 ++- components/esp_phy/src/phy_init.c | 14 ++++++++++---- components/esp_wifi/Kconfig | 4 ++-- components/esp_wifi/include/esp_coexist_internal.h | 2 +- components/esp_wifi/lib | 2 +- .../soc/esp32c2/include/soc/Kconfig.soc_caps.in | 14 +++++++++++++- components/soc/esp32c2/include/soc/soc_caps.h | 2 +- 7 files changed, 30 insertions(+), 11 deletions(-) diff --git a/components/esp_phy/CMakeLists.txt b/components/esp_phy/CMakeLists.txt index db0807413d..c5219d8ffc 100644 --- a/components/esp_phy/CMakeLists.txt +++ b/components/esp_phy/CMakeLists.txt @@ -67,7 +67,8 @@ if(link_binary_libs) $) endif() - if(CONFIG_IDF_TARGET_ESP32C3 OR CONFIG_IDF_TARGET_ESP32S3 OR CONFIG_IDF_TARGET_ESP32H2 OR CONFIG_IDF_TARGET_ESP32C2) + if(CONFIG_IDF_TARGET_ESP32C3 OR CONFIG_IDF_TARGET_ESP32S3 + OR CONFIG_IDF_TARGET_ESP32H2 OR CONFIG_IDF_TARGET_ESP32C2) target_link_libraries(${COMPONENT_LIB} PUBLIC btbb) target_link_libraries(${COMPONENT_LIB} INTERFACE $ libphy.a libbtbb.a $) diff --git a/components/esp_phy/src/phy_init.c b/components/esp_phy/src/phy_init.c index ee7da2f0e0..fcfb4cd68c 100644 --- a/components/esp_phy/src/phy_init.c +++ b/components/esp_phy/src/phy_init.c @@ -48,10 +48,12 @@ static const char* TAG = "phy_init"; static _lock_t s_phy_access_lock; +#if !CONFIG_IDF_TARGET_ESP32C2 // TODO - WIFI-4424 static DRAM_ATTR struct { int count; /* power on count of wifi and bt power domain */ _lock_t lock; } s_wifi_bt_pd_controller = { .count = 0 }; +#endif /* Indicate PHY is calibrated or not */ static bool s_is_phy_calibrated = false; @@ -284,26 +286,30 @@ void esp_phy_disable(void) void IRAM_ATTR esp_wifi_bt_power_domain_on(void) { +#if !CONFIG_IDF_TARGET_ESP32C2 // TODO - WIFI-4424 _lock_acquire(&s_wifi_bt_pd_controller.lock); if (s_wifi_bt_pd_controller.count++ == 0) { -// CLEAR_PERI_REG_MASK(RTC_CNTL_DIG_PWC_REG, RTC_CNTL_WIFI_FORCE_PD); + CLEAR_PERI_REG_MASK(RTC_CNTL_DIG_PWC_REG, RTC_CNTL_WIFI_FORCE_PD); #if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 SET_PERI_REG_MASK(SYSCON_WIFI_RST_EN_REG, SYSTEM_BB_RST | SYSTEM_FE_RST); CLEAR_PERI_REG_MASK(SYSCON_WIFI_RST_EN_REG, SYSTEM_BB_RST | SYSTEM_FE_RST); #endif - // CLEAR_PERI_REG_MASK(RTC_CNTL_DIG_ISO_REG, RTC_CNTL_WIFI_FORCE_ISO); + CLEAR_PERI_REG_MASK(RTC_CNTL_DIG_ISO_REG, RTC_CNTL_WIFI_FORCE_ISO); } _lock_release(&s_wifi_bt_pd_controller.lock); +#endif } void esp_wifi_bt_power_domain_off(void) { +#if !CONFIG_IDF_TARGET_ESP32C2 // TODO - WIFI-4424 _lock_acquire(&s_wifi_bt_pd_controller.lock); if (--s_wifi_bt_pd_controller.count == 0) { - // SET_PERI_REG_MASK(RTC_CNTL_DIG_ISO_REG, RTC_CNTL_WIFI_FORCE_ISO); - // SET_PERI_REG_MASK(RTC_CNTL_DIG_PWC_REG, RTC_CNTL_WIFI_FORCE_PD); + SET_PERI_REG_MASK(RTC_CNTL_DIG_ISO_REG, RTC_CNTL_WIFI_FORCE_ISO); + SET_PERI_REG_MASK(RTC_CNTL_DIG_PWC_REG, RTC_CNTL_WIFI_FORCE_PD); } _lock_release(&s_wifi_bt_pd_controller.lock); +#endif } #if CONFIG_MAC_BB_PD diff --git a/components/esp_wifi/Kconfig b/components/esp_wifi/Kconfig index 106dee8150..8362ee2ac4 100644 --- a/components/esp_wifi/Kconfig +++ b/components/esp_wifi/Kconfig @@ -4,7 +4,7 @@ menu "Wi-Fi" config ESP32_WIFI_ENABLED bool - default "y" if !IDF_TARGET_ESP32H2 + default y if SOC_WIFI_SUPPORTED config ESP32_WIFI_SW_COEXIST_ENABLE bool "Software controls WiFi/Bluetooth coexistence" @@ -281,7 +281,7 @@ menu "Wi-Fi" config ESP_WIFI_FTM_ENABLE bool "WiFi FTM" default n - depends on (IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32S3) + depends on (IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32S3 || IDF_TARGET_ESP32C2) help Enable feature Fine Timing Measurement for calculating WiFi Round-Trip-Time (RTT). diff --git a/components/esp_wifi/include/esp_coexist_internal.h b/components/esp_wifi/include/esp_coexist_internal.h index 1e0e5d0a27..1011ee50fd 100644 --- a/components/esp_wifi/include/esp_coexist_internal.h +++ b/components/esp_wifi/include/esp_coexist_internal.h @@ -196,7 +196,7 @@ int coex_schm_curr_phase_idx_set(int idx); int coex_schm_curr_phase_idx_get(void); /** - * @brief TODO + * @brief TODO - WIFI-4423 * */ int coex_register_start_cb(int (* cb)(void)); diff --git a/components/esp_wifi/lib b/components/esp_wifi/lib index aea6411b4c..a0b316b22a 160000 --- a/components/esp_wifi/lib +++ b/components/esp_wifi/lib @@ -1 +1 @@ -Subproject commit aea6411b4cd90bc00524db58855bd6478a0e2475 +Subproject commit a0b316b22acb6fbc6001f8dc7da8d26cd564cc05 diff --git a/components/soc/esp32c2/include/soc/Kconfig.soc_caps.in b/components/soc/esp32c2/include/soc/Kconfig.soc_caps.in index 4e06c8853f..2db8618cc7 100644 --- a/components/soc/esp32c2/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32c2/include/soc/Kconfig.soc_caps.in @@ -25,7 +25,7 @@ config SOC_BT_SUPPORTED config SOC_WIFI_SUPPORTED bool - default n + default y config SOC_ASYNC_MEMCPY_SUPPORTED bool @@ -526,3 +526,15 @@ config SOC_PM_SUPPORT_WIFI_WAKEUP config SOC_PM_SUPPORT_BT_WAKEUP bool default y + +config SOC_PM_SUPPORT_CPU_PD + bool + default n + +config SOC_PM_SUPPORT_WIFI_PD + bool + default n + +config SOC_PM_SUPPORT_BT_PD + bool + default n diff --git a/components/soc/esp32c2/include/soc/soc_caps.h b/components/soc/esp32c2/include/soc/soc_caps.h index 7f58821b0c..7fddf89b06 100644 --- a/components/soc/esp32c2/include/soc/soc_caps.h +++ b/components/soc/esp32c2/include/soc/soc_caps.h @@ -30,7 +30,7 @@ #define SOC_DEDICATED_GPIO_SUPPORTED 1 #define SOC_GDMA_SUPPORTED 1 #define SOC_BT_SUPPORTED 0 // Enable during bringup, IDF-4357 -#define SOC_WIFI_SUPPORTED 0 // Enable during bringup, IDF-3905 +#define SOC_WIFI_SUPPORTED 1 #define SOC_ASYNC_MEMCPY_SUPPORTED 1 #define SOC_SUPPORTS_SECURE_DL_MODE 1 #define SOC_EFUSE_KEY_PURPOSE_FIELD 0 From e0decf4839521534439a858aad47d71959074247 Mon Sep 17 00:00:00 2001 From: liuning Date: Tue, 15 Mar 2022 17:08:12 +0800 Subject: [PATCH 10/14] esp_wifi: fully support connectionless traffic with ps and coex --- components/esp_rom/esp32c3/ld/esp32c3.rom.eco3.ld | 4 ++-- components/esp_rom/esp32c3/ld/esp32c3.rom.ld | 6 +++--- components/esp_rom/esp32s3/ld/esp32s3.rom.ld | 10 +++++----- components/esp_wifi/esp32/esp_adapter.c | 10 ++++++++++ components/esp_wifi/esp32c3/esp_adapter.c | 10 ++++++++++ components/esp_wifi/esp32s2/esp_adapter.c | 10 ++++++++++ components/esp_wifi/esp32s3/esp_adapter.c | 10 ++++++++++ .../esp_wifi/include/esp_coexist_internal.h | 4 +++- components/esp_wifi/include/esp_now.h | 12 +++++------- .../include/esp_private/wifi_os_adapter.h | 4 +--- components/esp_wifi/include/esp_wifi.h | 15 ++++++++------- components/esp_wifi/lib | 2 +- 12 files changed, 68 insertions(+), 29 deletions(-) diff --git a/components/esp_rom/esp32c3/ld/esp32c3.rom.eco3.ld b/components/esp_rom/esp32c3/ld/esp32c3.rom.eco3.ld index 461f70694d..c7b882576b 100644 --- a/components/esp_rom/esp32c3/ld/esp32c3.rom.eco3.ld +++ b/components/esp_rom/esp32c3/ld/esp32c3.rom.eco3.ld @@ -6,10 +6,10 @@ Version 3 API's imported from the ROM esf_buf_alloc_dynamic = 0x400015c0; esf_buf_recycle = 0x400015c4; /*lmacTxDone = 0x4000162c;*/ -ppMapTxQueue = 0x400016d8; +/*ppMapTxQueue = 0x400016d8;*/ rcGetSched = 0x40001764; wDevCheckBlockError = 0x400017b4; -ppProcTxDone = 0x40001804; +/*ppProcTxDone = 0x40001804;*/ sta_input = rom_sta_input; /*************************************** diff --git a/components/esp_rom/esp32c3/ld/esp32c3.rom.ld b/components/esp_rom/esp32c3/ld/esp32c3.rom.ld index 73d510c2d0..f1394b3242 100644 --- a/components/esp_rom/esp32c3/ld/esp32c3.rom.ld +++ b/components/esp_rom/esp32c3/ld/esp32c3.rom.ld @@ -1525,7 +1525,7 @@ lmacReachShortLimit = 0x4000161c; lmacRecycleMPDU = 0x40001620; lmacRxDone = 0x40001624; lmacSetTxFrame = 0x40001628; -lmacTxFrame = 0x40001630; +/*lmacTxFrame = 0x40001630;*/ mac_tx_set_duration = 0x40001634; /* mac_tx_set_htsig = 0x40001638;*/ mac_tx_set_plcp0 = 0x4000163c; @@ -1553,7 +1553,7 @@ pm_rx_beacon_process = 0x40001690; pm_rx_data_process = 0x40001694; /*pm_sleep = 0x40001698;*/ pm_sleep_for = 0x4000169c; -pm_tbtt_process = 0x400016a0; +/*pm_tbtt_process = 0x400016a0;*/ ppAMPDU2Normal = 0x400016a4; ppAssembleAMPDU = 0x400016a8; ppCalFrameTimes = 0x400016ac; @@ -1761,7 +1761,7 @@ coex_core_pti_get = 0x400018c0; coex_core_release = 0x400018c4; coex_core_request = 0x400018c8; coex_core_status_get = 0x400018cc; -coex_core_timer_idx_get = 0x400018d0; +/*coex_core_timer_idx_get = 0x400018d0;*/ coex_event_duration_get = 0x400018d4; coex_hw_timer_disable = 0x400018d8; coex_hw_timer_enable = 0x400018dc; diff --git a/components/esp_rom/esp32s3/ld/esp32s3.rom.ld b/components/esp_rom/esp32s3/ld/esp32s3.rom.ld index 712fdd8ec2..24aba6277a 100644 --- a/components/esp_rom/esp32s3/ld/esp32s3.rom.ld +++ b/components/esp_rom/esp32s3/ld/esp32s3.rom.ld @@ -1830,7 +1830,7 @@ lmacRecycleMPDU = 0x400053a0; lmacRxDone = 0x400053ac; lmacSetTxFrame = 0x400053b8; lmacTxDone = 0x400053c4; -lmacTxFrame = 0x400053d0; +/*lmacTxFrame = 0x400053d0;*/ mac_tx_set_duration = 0x400053dc; /* mac_tx_set_htsig = 0x400053e8;*/ mac_tx_set_plcp0 = 0x400053f4; @@ -1858,7 +1858,7 @@ pm_rx_beacon_process = 0x400054f0; pm_rx_data_process = 0x400054fc; /*pm_sleep = 0x40005508;*/ pm_sleep_for = 0x40005514; -pm_tbtt_process = 0x40005520; +/*pm_tbtt_process = 0x40005520;*/ ppAMPDU2Normal = 0x4000552c; ppAssembleAMPDU = 0x40005538; ppCalFrameTimes = 0x40005544; @@ -1872,7 +1872,7 @@ ppEnqueueRxq = 0x40005598; ppEnqueueTxDone = 0x400055a4; ppGetTxQFirstAvail_Locked = 0x400055b0; ppGetTxframe = 0x400055bc; -ppMapTxQueue = 0x400055c8; +/*ppMapTxQueue = 0x400055c8;*/ ppProcessRxPktHdr = 0x400055e0; ppProcessTxQ = 0x400055ec; ppRecordBarRRC = 0x400055f8; @@ -1946,7 +1946,7 @@ wDev_ProcessRxSucData = 0x4000591c; wdevProcessRxSucDataAll = 0x40005928; wdev_csi_len_align = 0x40005934; ppDequeueTxDone_Locked = 0x40005940; -ppProcTxDone = 0x4000594c; +/*ppProcTxDone = 0x4000594c;*/ /*pm_tx_data_done_process = 0x40005958;*/ config_is_cache_tx_buf_enabled = 0x40005964; ppMapWaitTxq = 0x40005970; @@ -2073,7 +2073,7 @@ coex_core_pti_get = 0x40005ba4; coex_core_release = 0x40005bb0; coex_core_request = 0x40005bbc; coex_core_status_get = 0x40005bc8; -coex_core_timer_idx_get = 0x40005bd4; +/*coex_core_timer_idx_get = 0x40005bd4;*/ coex_event_duration_get = 0x40005be0; coex_hw_timer_disable = 0x40005bec; coex_hw_timer_enable = 0x40005bf8; diff --git a/components/esp_wifi/esp32/esp_adapter.c b/components/esp_wifi/esp32/esp_adapter.c index 315e39fb48..1309509e2f 100644 --- a/components/esp_wifi/esp32/esp_adapter.c +++ b/components/esp_wifi/esp32/esp_adapter.c @@ -646,6 +646,15 @@ static int coex_schm_curr_phase_idx_get_wrapper(void) #endif } +static int coex_register_start_cb_wrapper(int (* cb)(void)) +{ +#if CONFIG_SW_COEXIST_ENABLE + return coex_register_start_cb(cb); +#else + return 0; +#endif +} + static void IRAM_ATTR esp_empty_wrapper(void) { @@ -773,6 +782,7 @@ wifi_osi_funcs_t g_wifi_osi_funcs = { ._coex_schm_curr_phase_get = coex_schm_curr_phase_get_wrapper, ._coex_schm_curr_phase_idx_set = coex_schm_curr_phase_idx_set_wrapper, ._coex_schm_curr_phase_idx_get = coex_schm_curr_phase_idx_get_wrapper, + ._coex_register_start_cb = coex_register_start_cb_wrapper, ._magic = ESP_WIFI_OS_ADAPTER_MAGIC, }; diff --git a/components/esp_wifi/esp32c3/esp_adapter.c b/components/esp_wifi/esp32c3/esp_adapter.c index a5e52a62b9..6ad5db4aff 100644 --- a/components/esp_wifi/esp32c3/esp_adapter.c +++ b/components/esp_wifi/esp32c3/esp_adapter.c @@ -642,6 +642,15 @@ static int coex_schm_curr_phase_idx_get_wrapper(void) #endif } +static int coex_register_start_cb_wrapper(int (* cb)(void)) +{ +#if CONFIG_SW_COEXIST_ENABLE + return coex_register_start_cb(cb); +#else + return 0; +#endif +} + static void IRAM_ATTR esp_empty_wrapper(void) { @@ -763,6 +772,7 @@ wifi_osi_funcs_t g_wifi_osi_funcs = { ._coex_schm_curr_phase_get = coex_schm_curr_phase_get_wrapper, ._coex_schm_curr_phase_idx_set = coex_schm_curr_phase_idx_set_wrapper, ._coex_schm_curr_phase_idx_get = coex_schm_curr_phase_idx_get_wrapper, + ._coex_register_start_cb = coex_register_start_cb_wrapper, ._magic = ESP_WIFI_OS_ADAPTER_MAGIC, }; diff --git a/components/esp_wifi/esp32s2/esp_adapter.c b/components/esp_wifi/esp32s2/esp_adapter.c index 8d5ac5f2cf..f953aa80ed 100644 --- a/components/esp_wifi/esp32s2/esp_adapter.c +++ b/components/esp_wifi/esp32s2/esp_adapter.c @@ -649,6 +649,15 @@ static int coex_schm_curr_phase_idx_get_wrapper(void) #endif } +static int coex_register_start_cb_wrapper(int (* cb)(void)) +{ +#if CONFIG_SW_COEXIST_ENABLE + return coex_register_start_cb(cb); +#else + return 0; +#endif +} + static void IRAM_ATTR esp_empty_wrapper(void) { @@ -775,6 +784,7 @@ wifi_osi_funcs_t g_wifi_osi_funcs = { ._coex_schm_curr_phase_get = coex_schm_curr_phase_get_wrapper, ._coex_schm_curr_phase_idx_set = coex_schm_curr_phase_idx_set_wrapper, ._coex_schm_curr_phase_idx_get = coex_schm_curr_phase_idx_get_wrapper, + ._coex_register_start_cb = coex_register_start_cb_wrapper, ._magic = ESP_WIFI_OS_ADAPTER_MAGIC, }; diff --git a/components/esp_wifi/esp32s3/esp_adapter.c b/components/esp_wifi/esp32s3/esp_adapter.c index f2ce2614bd..bec1ab0265 100644 --- a/components/esp_wifi/esp32s3/esp_adapter.c +++ b/components/esp_wifi/esp32s3/esp_adapter.c @@ -666,6 +666,15 @@ static int coex_schm_curr_phase_idx_get_wrapper(void) #endif } +static int coex_register_start_cb_wrapper(int (* cb)(void)) +{ +#if CONFIG_SW_COEXIST_ENABLE + return coex_register_start_cb(cb); +#else + return 0; +#endif +} + static void IRAM_ATTR esp_empty_wrapper(void) { @@ -792,6 +801,7 @@ wifi_osi_funcs_t g_wifi_osi_funcs = { ._coex_schm_curr_phase_get = coex_schm_curr_phase_get_wrapper, ._coex_schm_curr_phase_idx_set = coex_schm_curr_phase_idx_set_wrapper, ._coex_schm_curr_phase_idx_get = coex_schm_curr_phase_idx_get_wrapper, + ._coex_register_start_cb = coex_register_start_cb_wrapper, ._magic = ESP_WIFI_OS_ADAPTER_MAGIC, }; diff --git a/components/esp_wifi/include/esp_coexist_internal.h b/components/esp_wifi/include/esp_coexist_internal.h index 1011ee50fd..b4137785d8 100644 --- a/components/esp_wifi/include/esp_coexist_internal.h +++ b/components/esp_wifi/include/esp_coexist_internal.h @@ -196,8 +196,10 @@ int coex_schm_curr_phase_idx_set(int idx); int coex_schm_curr_phase_idx_get(void); /** - * @brief TODO - WIFI-4423 + * @brief Register WiFi callback for coexistence starts. * + * @param cb : WiFi callback + * @return : 0 - success, other - failed */ int coex_register_start_cb(int (* cb)(void)); diff --git a/components/esp_wifi/include/esp_now.h b/components/esp_wifi/include/esp_now.h index 191d1d1cce..f3e2a88145 100644 --- a/components/esp_wifi/include/esp_now.h +++ b/components/esp_wifi/include/esp_now.h @@ -309,15 +309,13 @@ esp_err_t esp_now_get_peer_num(esp_now_peer_num_t *num); esp_err_t esp_now_set_pmk(const uint8_t *pmk); /** - * @brief Set esp_now wake window for sta_disconnected power management + * @brief Set wake window for esp_now to wake up in interval unit * - * @param window how much microsecond would the chip keep waked each interval, vary from 0 to 65535 + * @param window Milliseconds would the chip keep waked each interval, from 0 to 65535. * - * @attention 1. Only when ESP_WIFI_STA_DISCONNECTED_PM_ENABLE is enabled, this configuration could work - * @attention 2. This configuration only work for station mode and disconnected status - * @attention 3. If more than one module has configured its wake_window, chip would choose the largest one to stay waked - * @attention 4. If the gap between interval and window is smaller than 5ms, the chip would keep waked all the time - * @attention 5. If never configured wake_window, the chip would keep waked at disconnected once it uses esp_now + * @attention 1. This configuration could work at connected status. + * When ESP_WIFI_STA_DISCONNECTED_PM_ENABLE is enabled, this configuration could work at disconnected status. + * @attention 2. Default value is the maximum. * * @return * - ESP_OK : succeed diff --git a/components/esp_wifi/include/esp_private/wifi_os_adapter.h b/components/esp_wifi/include/esp_private/wifi_os_adapter.h index adf95ea7b5..fa0f152936 100644 --- a/components/esp_wifi/include/esp_private/wifi_os_adapter.h +++ b/components/esp_wifi/include/esp_private/wifi_os_adapter.h @@ -22,8 +22,6 @@ extern "C" { #define OSI_QUEUE_SEND_BACK 1 #define OSI_QUEUE_SEND_OVERWRITE 2 -typedef int(* coex_start_wifi_cb_t)(void); - typedef struct { int32_t _version; bool (* _env_is_chip)(void); @@ -146,7 +144,7 @@ typedef struct { void * (* _coex_schm_curr_phase_get)(void); int (* _coex_schm_curr_phase_idx_set)(int idx); int (* _coex_schm_curr_phase_idx_get)(void); - int (* _coex_register_start_cb)(coex_start_wifi_cb_t cb); + int (* _coex_register_start_cb)(int (* cb)(void)); int32_t _magic; } wifi_osi_funcs_t; diff --git a/components/esp_wifi/include/esp_wifi.h b/components/esp_wifi/include/esp_wifi.h index 5692c066fe..7c7a2319ac 100644 --- a/components/esp_wifi/include/esp_wifi.h +++ b/components/esp_wifi/include/esp_wifi.h @@ -1209,16 +1209,17 @@ esp_err_t esp_wifi_ftm_resp_set_offset(int16_t offset_cm); esp_err_t esp_wifi_config_11b_rate(wifi_interface_t ifx, bool disable); /** - * @brief Set interval for station to wake up periodically at disconnected. + * @brief Set wake interval for connectionless modules to wake up periodically. * - * @attention 1. Only when ESP_WIFI_STA_DISCONNECTED_PM_ENABLE is enabled, this configuration could work - * @attention 2. This configuration only work for station mode and disconnected status - * @attention 3. This configuration would influence nothing until some module configure wake_window - * @attention 4. A sensible interval which is not too small is recommended (e.g. 100ms) + * @attention 1. Only one wake interval for all connectionless modules. + * @attention 2. This configuration could work at connected status. + * When ESP_WIFI_STA_DISCONNECTED_PM_ENABLE is enabled, this configuration could work at disconnected status. + * @attention 3. Event WIFI_EVENT_CONNECTIONLESS_MODULE_WAKE_INTERVAL_START would be posted each time wake interval starts. + * @attention 4. Recommend to configure interval in multiples of hundred. (e.g. 100ms) * - * @param interval how much micriosecond would the chip wake up, from 1 to 65535. + * @param wake_interval Milliseconds after would the chip wake up, from 1 to 65535. */ -esp_err_t esp_wifi_connectionless_module_set_wake_interval(uint16_t interval); +esp_err_t esp_wifi_connectionless_module_set_wake_interval(uint16_t wake_interval); /** * @brief configure country diff --git a/components/esp_wifi/lib b/components/esp_wifi/lib index a0b316b22a..05794b1c88 160000 --- a/components/esp_wifi/lib +++ b/components/esp_wifi/lib @@ -1 +1 @@ -Subproject commit a0b316b22acb6fbc6001f8dc7da8d26cd564cc05 +Subproject commit 05794b1c8898c9b43bd8c1b3418dea0f140ec303 From 7b9b4480411b3fb18c2c0a31cff73ea82d0068fa Mon Sep 17 00:00:00 2001 From: Jessy Chen Date: Tue, 10 May 2022 04:00:01 -0400 Subject: [PATCH 11/14] esp_wifi: optimize wifi kconfig --- components/esp_netif/test_apps/README.md | 6 ++---- components/esp_wifi/Kconfig | 4 ++-- .../soc/esp32/include/soc/Kconfig.soc_caps.in | 12 ++++++++++++ components/soc/esp32/include/soc/soc_caps.h | 5 +++++ .../soc/esp32c2/include/soc/Kconfig.soc_caps.in | 16 ++++++++++++---- components/soc/esp32c2/include/soc/soc_caps.h | 8 +++++--- .../soc/esp32c3/include/soc/Kconfig.soc_caps.in | 16 ++++++++++++---- components/soc/esp32c3/include/soc/soc_caps.h | 8 +++++--- .../soc/esp32s2/include/soc/Kconfig.soc_caps.in | 16 ++++++++++++---- components/soc/esp32s2/include/soc/soc_caps.h | 8 +++++--- .../soc/esp32s3/include/soc/Kconfig.soc_caps.in | 16 ++++++++++++---- components/soc/esp32s3/include/soc/soc_caps.h | 8 +++++--- .../phy/phy_multi_init_data_test/README.md | 6 ++---- .../protocols/mqtt/build_test/README.md | 6 ++---- 14 files changed, 93 insertions(+), 42 deletions(-) diff --git a/components/esp_netif/test_apps/README.md b/components/esp_netif/test_apps/README.md index 3efcd3efae..57433de18a 100644 --- a/components/esp_netif/test_apps/README.md +++ b/components/esp_netif/test_apps/README.md @@ -1,4 +1,2 @@ -| Supported Targets | ESP32 | ESP32-S2 | ESP32-S3 | ESP32-C3 | -| ----------------- | ----- | -------- | -------- | -------- | - -Not support on ESP32-C2 yet, waiting esp_wifi supported. TODO: IDF-3905 +| Supported Targets | ESP32 | ESP32-S2 | ESP32-S3 | ESP32-C3 | ESP32-C2 | +| ----------------- | ----- | -------- | -------- | -------- | -------- | diff --git a/components/esp_wifi/Kconfig b/components/esp_wifi/Kconfig index 8362ee2ac4..90ad2b4c14 100644 --- a/components/esp_wifi/Kconfig +++ b/components/esp_wifi/Kconfig @@ -281,7 +281,7 @@ menu "Wi-Fi" config ESP_WIFI_FTM_ENABLE bool "WiFi FTM" default n - depends on (IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32S3 || IDF_TARGET_ESP32C2) + depends on SOC_WIFI_FTM_SUPPORT help Enable feature Fine Timing Measurement for calculating WiFi Round-Trip-Time (RTT). @@ -316,7 +316,7 @@ menu "Wi-Fi" config ESP_WIFI_GCMP_SUPPORT bool "WiFi GCMP Support(GCMP128 and GCMP256)" default n - depends on (IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32S3) + depends on SOC_WIFI_GCMP_SUPPORT help Select this option to enable GCMP support. GCMP support is compulsory for WiFi Suite-B support. diff --git a/components/soc/esp32/include/soc/Kconfig.soc_caps.in b/components/soc/esp32/include/soc/Kconfig.soc_caps.in index 7340e5b2dd..ff4c037c10 100644 --- a/components/soc/esp32/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32/include/soc/Kconfig.soc_caps.in @@ -654,3 +654,15 @@ config SOC_SDMMC_NUM_SLOTS config SOC_BLE_DONT_UPDATE_OWN_RPA bool default y + +config SOC_WIFI_HW_TSF + bool + default n + +config SOC_WIFI_FTM_SUPPORT + bool + default n + +config SOC_WIFI_GCMP_SUPPORT + bool + default n diff --git a/components/soc/esp32/include/soc/soc_caps.h b/components/soc/esp32/include/soc/soc_caps.h index ae2ecb89be..b67980489e 100644 --- a/components/soc/esp32/include/soc/soc_caps.h +++ b/components/soc/esp32/include/soc/soc_caps.h @@ -370,3 +370,8 @@ /*------------------------------ BLE --------------------------------------------*/ #define SOC_BLE_DONT_UPDATE_OWN_RPA (1) + +/*-------------------------- WI-FI HARDWARE CAPS -------------------------------*/ +#define SOC_WIFI_HW_TSF (0) /*!< Support hardware TSF */ +#define SOC_WIFI_FTM_SUPPORT (0) /*!< FTM Support */ +#define SOC_WIFI_GCMP_SUPPORT (0) /*!< GCMP Support(GCMP128 and GCMP256) */ diff --git a/components/soc/esp32c2/include/soc/Kconfig.soc_caps.in b/components/soc/esp32c2/include/soc/Kconfig.soc_caps.in index 2db8618cc7..ef61f89c88 100644 --- a/components/soc/esp32c2/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32c2/include/soc/Kconfig.soc_caps.in @@ -499,10 +499,6 @@ config SOC_UART_SUPPORT_FSM_TX_WAIT_SEND bool default y -config SOC_WIFI_HW_TSF - bool - default y - config SOC_COEX_HW_PTI bool default y @@ -538,3 +534,15 @@ config SOC_PM_SUPPORT_WIFI_PD config SOC_PM_SUPPORT_BT_PD bool default n + +config SOC_WIFI_HW_TSF + bool + default y + +config SOC_WIFI_FTM_SUPPORT + bool + default y + +config SOC_WIFI_GCMP_SUPPORT + bool + default n diff --git a/components/soc/esp32c2/include/soc/soc_caps.h b/components/soc/esp32c2/include/soc/soc_caps.h index 7fddf89b06..f9daef65d5 100644 --- a/components/soc/esp32c2/include/soc/soc_caps.h +++ b/components/soc/esp32c2/include/soc/soc_caps.h @@ -251,9 +251,6 @@ // UART has an extra TX_WAIT_SEND state when the FIFO is not empty and XOFF is enabled #define SOC_UART_SUPPORT_FSM_TX_WAIT_SEND (1) -/*-------------------------- WI-FI HARDWARE TSF CAPS -------------------------------*/ -#define SOC_WIFI_HW_TSF (1) - /*-------------------------- COEXISTENCE HARDWARE PTI CAPS -------------------------------*/ #define SOC_COEX_HW_PTI (1) @@ -274,3 +271,8 @@ #define SOC_PM_SUPPORT_WIFI_PD (0) #define SOC_PM_SUPPORT_BT_PD (0) + +/*------------------------------------ WI-FI CAPS ------------------------------------*/ +#define SOC_WIFI_HW_TSF (1) /*!< Support hardware TSF */ +#define SOC_WIFI_FTM_SUPPORT (1) /*!< FTM Support */ +#define SOC_WIFI_GCMP_SUPPORT (0) /*!< GCMP Support(GCMP128 and GCMP256) */ diff --git a/components/soc/esp32c3/include/soc/Kconfig.soc_caps.in b/components/soc/esp32c3/include/soc/Kconfig.soc_caps.in index e234e9f6dd..5f03225a3d 100644 --- a/components/soc/esp32c3/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32c3/include/soc/Kconfig.soc_caps.in @@ -699,10 +699,6 @@ config SOC_UART_SUPPORT_FSM_TX_WAIT_SEND bool default y -config SOC_WIFI_HW_TSF - bool - default y - config SOC_COEX_HW_PTI bool default y @@ -746,3 +742,15 @@ config SOC_TEMPERATURE_SENSOR_SUPPORT_FAST_RC config SOC_TEMPERATURE_SENSOR_SUPPORT_XTAL bool default y + +config SOC_WIFI_HW_TSF + bool + default y + +config SOC_WIFI_FTM_SUPPORT + bool + default y + +config SOC_WIFI_GCMP_SUPPORT + bool + default y diff --git a/components/soc/esp32c3/include/soc/soc_caps.h b/components/soc/esp32c3/include/soc/soc_caps.h index 5f29f7e4b0..e57c61cdd9 100644 --- a/components/soc/esp32c3/include/soc/soc_caps.h +++ b/components/soc/esp32c3/include/soc/soc_caps.h @@ -329,9 +329,6 @@ // UART has an extra TX_WAIT_SEND state when the FIFO is not empty and XOFF is enabled #define SOC_UART_SUPPORT_FSM_TX_WAIT_SEND (1) -/*-------------------------- WI-FI HARDWARE TSF CAPS -------------------------------*/ -#define SOC_WIFI_HW_TSF (1) - /*-------------------------- COEXISTENCE HARDWARE PTI CAPS -------------------------------*/ #define SOC_COEX_HW_PTI (1) @@ -356,3 +353,8 @@ /*-------------------------- Temperature Sensor CAPS -------------------------------------*/ #define SOC_TEMPERATURE_SENSOR_SUPPORT_FAST_RC (1) #define SOC_TEMPERATURE_SENSOR_SUPPORT_XTAL (1) + +/*------------------------------------ WI-FI CAPS ------------------------------------*/ +#define SOC_WIFI_HW_TSF (1) /*!< Support hardware TSF */ +#define SOC_WIFI_FTM_SUPPORT (1) /*!< FTM Support */ +#define SOC_WIFI_GCMP_SUPPORT (1) /*!< GCMP Support(GCMP128 and GCMP256) */ diff --git a/components/soc/esp32s2/include/soc/Kconfig.soc_caps.in b/components/soc/esp32s2/include/soc/Kconfig.soc_caps.in index 63c44b589f..984ddd72a9 100644 --- a/components/soc/esp32s2/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32s2/include/soc/Kconfig.soc_caps.in @@ -783,10 +783,6 @@ config SOC_AES_SUPPORT_AES_256 bool default y -config SOC_WIFI_HW_TSF - bool - default y - config SOC_PHY_DIG_REGS_MEM_SIZE int default 21 @@ -834,3 +830,15 @@ config SOC_COEX_HW_PTI config SOC_TEMPERATURE_SENSOR_SUPPORT_FAST_RC bool default y + +config SOC_WIFI_HW_TSF + bool + default y + +config SOC_WIFI_FTM_SUPPORT + bool + default y + +config SOC_WIFI_GCMP_SUPPORT + bool + default n diff --git a/components/soc/esp32s2/include/soc/soc_caps.h b/components/soc/esp32s2/include/soc/soc_caps.h index a56d50a693..694857de18 100644 --- a/components/soc/esp32s2/include/soc/soc_caps.h +++ b/components/soc/esp32s2/include/soc/soc_caps.h @@ -359,9 +359,6 @@ #define SOC_AES_SUPPORT_AES_192 (1) #define SOC_AES_SUPPORT_AES_256 (1) -/*-------------------------- WI-FI HARDWARE TSF CAPS -------------------------------*/ -#define SOC_WIFI_HW_TSF (1) - /*--------------- PHY REGISTER AND MEMORY SIZE CAPS --------------------------*/ #define SOC_PHY_DIG_REGS_MEM_SIZE (21*4) @@ -390,3 +387,8 @@ /*-------------------------- Temperature Sensor CAPS -------------------------------------*/ #define SOC_TEMPERATURE_SENSOR_SUPPORT_FAST_RC (1) + +/*------------------------------------ WI-FI CAPS ------------------------------------*/ +#define SOC_WIFI_HW_TSF (1) /*!< Support hardware TSF */ +#define SOC_WIFI_FTM_SUPPORT (1) /*!< FTM Support */ +#define SOC_WIFI_GCMP_SUPPORT (0) /*!< GCMP Support(GCMP128 and GCMP256) */ diff --git a/components/soc/esp32s3/include/soc/Kconfig.soc_caps.in b/components/soc/esp32s3/include/soc/Kconfig.soc_caps.in index 7ab39fabc4..d09ff1fb9c 100644 --- a/components/soc/esp32s3/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32s3/include/soc/Kconfig.soc_caps.in @@ -907,10 +907,6 @@ config SOC_FLASH_ENCRYPTION_XTS_AES_256 bool default y -config SOC_WIFI_HW_TSF - bool - default y - config SOC_PHY_DIG_REGS_MEM_SIZE int default 21 @@ -967,6 +963,18 @@ config SOC_TEMPERATURE_SENSOR_SUPPORT_FAST_RC bool default y +config SOC_WIFI_HW_TSF + bool + default y + +config SOC_WIFI_FTM_SUPPORT + bool + default y + +config SOC_WIFI_GCMP_SUPPORT + bool + default y + config SOC_TWAI_BRP_MIN int default 2 diff --git a/components/soc/esp32s3/include/soc/soc_caps.h b/components/soc/esp32s3/include/soc/soc_caps.h index ec2838ac4a..00106aa897 100644 --- a/components/soc/esp32s3/include/soc/soc_caps.h +++ b/components/soc/esp32s3/include/soc/soc_caps.h @@ -386,9 +386,6 @@ #define SOC_FLASH_ENCRYPTION_XTS_AES_128 1 #define SOC_FLASH_ENCRYPTION_XTS_AES_256 1 -/*-------------------------- WI-FI HARDWARE TSF CAPS -------------------------------*/ -#define SOC_WIFI_HW_TSF (1) - /*--------------- PHY REGISTER AND MEMORY SIZE CAPS --------------------------*/ #define SOC_PHY_DIG_REGS_MEM_SIZE (21*4) #define SOC_MAC_BB_PD_MEM_SIZE (192*4) @@ -419,3 +416,8 @@ /*-------------------------- Temperature Sensor CAPS -------------------------------------*/ #define SOC_TEMPERATURE_SENSOR_SUPPORT_FAST_RC (1) + +/*------------------------------------ WI-FI CAPS ------------------------------------*/ +#define SOC_WIFI_HW_TSF (1) /*!< Support hardware TSF */ +#define SOC_WIFI_FTM_SUPPORT (1) /*!< FTM Support */ +#define SOC_WIFI_GCMP_SUPPORT (1) /*!< GCMP Support(GCMP128 and GCMP256) */ diff --git a/tools/test_apps/phy/phy_multi_init_data_test/README.md b/tools/test_apps/phy/phy_multi_init_data_test/README.md index 3efcd3efae..57433de18a 100644 --- a/tools/test_apps/phy/phy_multi_init_data_test/README.md +++ b/tools/test_apps/phy/phy_multi_init_data_test/README.md @@ -1,4 +1,2 @@ -| Supported Targets | ESP32 | ESP32-S2 | ESP32-S3 | ESP32-C3 | -| ----------------- | ----- | -------- | -------- | -------- | - -Not support on ESP32-C2 yet, waiting esp_wifi supported. TODO: IDF-3905 +| Supported Targets | ESP32 | ESP32-S2 | ESP32-S3 | ESP32-C3 | ESP32-C2 | +| ----------------- | ----- | -------- | -------- | -------- | -------- | diff --git a/tools/test_apps/protocols/mqtt/build_test/README.md b/tools/test_apps/protocols/mqtt/build_test/README.md index f698cdff43..0f6c3a99bd 100644 --- a/tools/test_apps/protocols/mqtt/build_test/README.md +++ b/tools/test_apps/protocols/mqtt/build_test/README.md @@ -1,7 +1,5 @@ -| Supported Targets | ESP32 | ESP32-S2 | ESP32-S3 | ESP32-C3 | -| ----------------- | ----- | -------- | -------- | -------- | - -Not support on ESP32-C2 yet, waiting esp_wifi supported. TODO: IDF-3905 +| Supported Targets | ESP32 | ESP32-S2 | ESP32-S3 | ESP32-C3 | ESP32-C2 | +| ----------------- | ----- | -------- | -------- | -------- | -------- | # Build only test for C++ From 1781ce3b987a0e83fa3af388dd225250a3839a2f Mon Sep 17 00:00:00 2001 From: jingli Date: Fri, 27 May 2022 15:36:43 +0800 Subject: [PATCH 12/14] further fix rtc attr for esp32c2 --- components/esp_common/include/esp_attr.h | 57 +++++++++++------------- 1 file changed, 25 insertions(+), 32 deletions(-) diff --git a/components/esp_common/include/esp_attr.h b/components/esp_common/include/esp_attr.h index c02c54faed..d49f76141c 100644 --- a/components/esp_common/include/esp_attr.h +++ b/components/esp_common/include/esp_attr.h @@ -12,7 +12,6 @@ extern "C" { #endif #include "sdkconfig.h" -#include "soc/soc_caps.h" #define ROMFN_ATTR @@ -62,7 +61,26 @@ extern "C" { // Use as esp_rom_printf(DRAM_STR("Hello world!\n")); #define DRAM_STR(str) (__extension__({static const DRAM_ATTR char __c[] = (str); (const char *)&__c;})) -#if SOC_RTC_FAST_MEM_SUPPORTED +#if CONFIG_SOC_RTC_FAST_MEM_SUPPORTED || CONFIG_SOC_RTC_SLOW_MEM_SUPPORTED +// Forces data into RTC memory. See "docs/deep-sleep-stub.rst" +// Any variable marked with this attribute will keep its value +// during a deep sleep / wake cycle. +#define RTC_DATA_ATTR _SECTION_ATTR_IMPL(".rtc.data", __COUNTER__) + +// Forces data into RTC memory of .noinit section. +// Any variable marked with this attribute will keep its value +// after restart or during a deep sleep / wake cycle. +#define RTC_NOINIT_ATTR _SECTION_ATTR_IMPL(".rtc_noinit", __COUNTER__) + +// Forces read-only data into RTC memory. See "docs/deep-sleep-stub.rst" +#define RTC_RODATA_ATTR _SECTION_ATTR_IMPL(".rtc.rodata", __COUNTER__) + +// Forces data into RTC memory and map it to coredump +#define COREDUMP_RTC_DATA_ATTR _SECTION_ATTR_IMPL(".rtc.coredump", __COUNTER__) + +// Allows to place data into RTC_SLOW memory. +#define RTC_SLOW_ATTR _SECTION_ATTR_IMPL(".rtc.force_slow", __COUNTER__) + // Forces code into RTC fast memory. See "docs/deep-sleep-stub.rst" #define RTC_IRAM_ATTR _SECTION_ATTR_IMPL(".rtc.text", __COUNTER__) @@ -72,41 +90,16 @@ extern "C" { // Allows to place data into RTC_FAST memory and map it to coredump #define COREDUMP_RTC_FAST_ATTR _SECTION_ATTR_IMPL(".rtc.fast.coredump", __COUNTER__) #else +#define RTC_DATA_ATTR +#define RTC_NOINIT_ATTR +#define RTC_RODATA_ATTR +#define COREDUMP_RTC_DATA_ATTR +#define RTC_SLOW_ATTR #define RTC_IRAM_ATTR #define RTC_FAST_ATTR #define COREDUMP_RTC_FAST_ATTR #endif -#if SOC_RTC_SLOW_MEM_SUPPORTED -// Forces data into RTC slow memory. See "docs/deep-sleep-stub.rst" -// Any variable marked with this attribute will keep its value -// during a deep sleep / wake cycle. -#define RTC_DATA_ATTR _SECTION_ATTR_IMPL(".rtc.data", __COUNTER__) - -// Allows to place data into RTC_SLOW memory. -#define RTC_SLOW_ATTR _SECTION_ATTR_IMPL(".rtc.force_slow", __COUNTER__) - -// Forces data into RTC slow memory of .noinit section. -// Any variable marked with this attribute will keep its value -// after restart or during a deep sleep / wake cycle. -#define RTC_NOINIT_ATTR _SECTION_ATTR_IMPL(".rtc_noinit", __COUNTER__) -#else -#define RTC_DATA_ATTR -#define RTC_SLOW_ATTR -#define RTC_NOINIT_ATTR -#endif - -#if SOC_RTC_FAST_MEM_SUPPORTED || SOC_RTC_SLOW_MEM_SUPPORTED -// Forces read-only data into RTC memory. See "docs/deep-sleep-stub.rst" -#define RTC_RODATA_ATTR _SECTION_ATTR_IMPL(".rtc.rodata", __COUNTER__) - -// Forces data into RTC memory and map it to coredump -#define COREDUMP_RTC_DATA_ATTR _SECTION_ATTR_IMPL(".rtc.coredump", __COUNTER__) -#else -#define RTC_RODATA_ATTR -#define COREDUMP_RTC_DATA_ATTR -#endif - #if CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY // Forces bss variable into external memory. " #define EXT_RAM_BSS_ATTR _SECTION_ATTR_IMPL(".ext_ram.bss", __COUNTER__) From 7a8b63869ff2f10cf32b23d68e57e7a7b5d008b9 Mon Sep 17 00:00:00 2001 From: Jack Date: Sun, 29 May 2022 00:13:32 +0800 Subject: [PATCH 13/14] deinit BB MAC back memory when they are not used --- components/bt/controller/esp32c3/bt.c | 3 +++ components/esp_phy/include/esp_phy_init.h | 5 +++++ components/esp_phy/src/phy_init.c | 16 ++++++++++++++++ components/esp_wifi/src/wifi_init.c | 3 +++ 4 files changed, 27 insertions(+) diff --git a/components/bt/controller/esp32c3/bt.c b/components/bt/controller/esp32c3/bt.c index 9296b86ec4..f757fac3c7 100644 --- a/components/bt/controller/esp32c3/bt.c +++ b/components/bt/controller/esp32c3/bt.c @@ -1244,6 +1244,9 @@ esp_err_t esp_bt_controller_deinit(void) phy_init_flag(); esp_bt_power_domain_off(); +#if CONFIG_MAC_BB_PD + esp_mac_bb_pd_mem_deinit(); +#endif free(osi_funcs_p); osi_funcs_p = NULL; diff --git a/components/esp_phy/include/esp_phy_init.h b/components/esp_phy/include/esp_phy_init.h index b2562ef11e..56054d82cd 100644 --- a/components/esp_phy/include/esp_phy_init.h +++ b/components/esp_phy/include/esp_phy_init.h @@ -181,6 +181,11 @@ void esp_phy_load_cal_and_init(void); */ void esp_mac_bb_pd_mem_init(void); +/** + * @brief Deinitialize backup memory for MAC and Baseband power up/down + */ +void esp_mac_bb_pd_mem_deinit(void); + /** * @brief Power up MAC and Baseband */ diff --git a/components/esp_phy/src/phy_init.c b/components/esp_phy/src/phy_init.c index fcfb4cd68c..0be0acd881 100644 --- a/components/esp_phy/src/phy_init.c +++ b/components/esp_phy/src/phy_init.c @@ -79,6 +79,8 @@ static uint32_t* s_phy_digital_regs_mem = NULL; #if CONFIG_MAC_BB_PD uint32_t* s_mac_bb_pd_mem = NULL; +/* Reference count of MAC BB backup memory */ +static uint8_t s_backup_mem_ref = 0; #endif #if CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN @@ -317,6 +319,7 @@ void esp_mac_bb_pd_mem_init(void) { _lock_acquire(&s_phy_access_lock); + s_backup_mem_ref++; if (s_mac_bb_pd_mem == NULL) { s_mac_bb_pd_mem = (uint32_t *)heap_caps_malloc(SOC_MAC_BB_PD_MEM_SIZE, MALLOC_CAP_DMA|MALLOC_CAP_INTERNAL); } @@ -324,6 +327,19 @@ void esp_mac_bb_pd_mem_init(void) _lock_release(&s_phy_access_lock); } +void esp_mac_bb_pd_mem_deinit(void) +{ + _lock_acquire(&s_phy_access_lock); + + s_backup_mem_ref--; + if (s_backup_mem_ref == 0) { + free(s_mac_bb_pd_mem); + s_mac_bb_pd_mem = NULL; + } + + _lock_release(&s_phy_access_lock); +} + IRAM_ATTR void esp_mac_bb_power_up(void) { if (s_mac_bb_pd_mem == NULL) { diff --git a/components/esp_wifi/src/wifi_init.c b/components/esp_wifi/src/wifi_init.c index 351f8a5600..eb6d4945c6 100644 --- a/components/esp_wifi/src/wifi_init.c +++ b/components/esp_wifi/src/wifi_init.c @@ -129,6 +129,9 @@ esp_err_t esp_wifi_deinit(void) phy_init_flag(); #endif esp_wifi_power_domain_off(); +#if CONFIG_MAC_BB_PD + esp_mac_bb_pd_mem_deinit(); +#endif return err; } From 74e00964727b7fe0837ce8739f7dd157b794a95a Mon Sep 17 00:00:00 2001 From: Jack Date: Sun, 29 May 2022 01:22:19 +0800 Subject: [PATCH 14/14] relax memory leak threshold for some wifi test case --- components/esp_wifi/test/test_wifi_init.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/components/esp_wifi/test/test_wifi_init.c b/components/esp_wifi/test/test_wifi_init.c index 660a817ac4..ff4875d1a2 100644 --- a/components/esp_wifi/test/test_wifi_init.c +++ b/components/esp_wifi/test/test_wifi_init.c @@ -104,6 +104,7 @@ static void wifi_driver_can_start_on_APP_CPU_task(void* arg) TEST_CASE("wifi driver can start on APP CPU", "[wifi_init]") { + test_case_uses_tcpip(); TaskHandle_t th = NULL; SemaphoreHandle_t sema = xSemaphoreCreateBinary(); TEST_ASSERT_NOT_NULL(sema); @@ -206,6 +207,7 @@ static void wifi_stop_task(void* arg) TEST_CASE("Calling esp_wifi_stop() without start", "[wifi_init]") { + test_case_uses_tcpip(); TaskHandle_t th = NULL; SemaphoreHandle_t sema = xSemaphoreCreateBinary(); TEST_ASSERT_NOT_NULL(sema);