From da32729e823393899e7b31c68803bbd73d807069 Mon Sep 17 00:00:00 2001 From: wanckl Date: Mon, 1 Sep 2025 16:58:35 +0800 Subject: [PATCH 1/4] feat(driver_spi): update p4 eco5 spi support on real chip --- components/esp_driver_spi/src/gpspi/spi_common.c | 3 ++- components/esp_driver_spi/src/gpspi/spi_master.c | 4 +--- components/esp_driver_spi/src/gpspi/spi_slave.c | 8 +++++++- components/hal/esp32/include/hal/spi_ll.h | 6 ++++++ components/hal/esp32p4/include/hal/spi_ll.h | 5 +++++ 5 files changed, 21 insertions(+), 5 deletions(-) diff --git a/components/esp_driver_spi/src/gpspi/spi_common.c b/components/esp_driver_spi/src/gpspi/spi_common.c index a8b310a5dbe4..3efbea764223 100644 --- a/components/esp_driver_spi/src/gpspi/spi_common.c +++ b/components/esp_driver_spi/src/gpspi/spi_common.c @@ -591,7 +591,8 @@ esp_err_t spicommon_bus_initialize_io(spi_host_device_t host, const spi_bus_conf } //set flags for DUAL mode according to output-capability of MOSI and MISO pins. if ((bus_config->mosi_io_num < 0 || GPIO_IS_VALID_OUTPUT_GPIO(bus_config->mosi_io_num)) && - (bus_config->miso_io_num < 0 || GPIO_IS_VALID_OUTPUT_GPIO(bus_config->miso_io_num))) { + (bus_config->miso_io_num < 0 || GPIO_IS_VALID_OUTPUT_GPIO(bus_config->miso_io_num)) && + (bus_config->miso_io_num != bus_config->mosi_io_num)) { temp_flag |= SPICOMMON_BUSFLAG_DUAL; } diff --git a/components/esp_driver_spi/src/gpspi/spi_master.c b/components/esp_driver_spi/src/gpspi/spi_master.c index 5869d8522da5..c29605e4cbee 100644 --- a/components/esp_driver_spi/src/gpspi/spi_master.c +++ b/components/esp_driver_spi/src/gpspi/spi_master.c @@ -620,9 +620,7 @@ esp_err_t spi_bus_remove_device(spi_device_handle_t handle) esp_err_t spi_device_get_actual_freq(spi_device_handle_t handle, int* freq_khz) { - if ((spi_device_t *)handle == NULL || freq_khz == NULL) { - return ESP_ERR_INVALID_ARG; - } + SPI_CHECK(handle && freq_khz, "invalid arg", ESP_ERR_INVALID_ARG); *freq_khz = handle->hal_dev.timing_conf.real_freq / 1000; return ESP_OK; diff --git a/components/esp_driver_spi/src/gpspi/spi_slave.c b/components/esp_driver_spi/src/gpspi/spi_slave.c index 749245ad2280..debaf742238a 100644 --- a/components/esp_driver_spi/src/gpspi/spi_slave.c +++ b/components/esp_driver_spi/src/gpspi/spi_slave.c @@ -100,20 +100,26 @@ static inline bool SPI_SLAVE_ISR_ATTR bus_is_iomux(spi_slave_t *host) return host->flags & SPICOMMON_BUSFLAG_IOMUX_PINS; } -static void SPI_SLAVE_ISR_ATTR freeze_cs(spi_slave_t *host) +static inline void SPI_SLAVE_ISR_ATTR freeze_cs(spi_slave_t *host) { +#if SPI_LL_SLAVE_NEEDS_CS_WORKAROUND + // This workaround only for ESP32 due to old hardware design, see MR !3207 esp_rom_gpio_connect_in_signal(GPIO_MATRIX_CONST_ONE_INPUT, host->cs_in_signal, false); +#endif } // Use this function instead of cs_initial to avoid overwrite the output config // This is used in test by internal gpio matrix connections static inline void SPI_SLAVE_ISR_ATTR restore_cs(spi_slave_t *host) { +#if SPI_LL_SLAVE_NEEDS_CS_WORKAROUND + // This workaround only for ESP32 due to old hardware design, see MR !3207 if (host->cs_iomux) { gpio_ll_iomux_in(GPIO_HAL_GET_HW(GPIO_PORT_0), host->cfg.spics_io_num, host->cs_in_signal); } else { esp_rom_gpio_connect_in_signal(host->cfg.spics_io_num, host->cs_in_signal, false); } +#endif } #if (SOC_CPU_CORES_NUM > 1) && (!CONFIG_FREERTOS_UNICORE) diff --git a/components/hal/esp32/include/hal/spi_ll.h b/components/hal/esp32/include/hal/spi_ll.h index 84113565176e..b7f907877c1c 100644 --- a/components/hal/esp32/include/hal/spi_ll.h +++ b/components/hal/esp32/include/hal/spi_ll.h @@ -44,6 +44,12 @@ extern "C" { #define SPI_LL_CPU_MAX_BIT_LEN (16 * 32) //Fifo len: 16 words #define SPI_LL_MOSI_FREE_LEVEL 0 //Default level after bus initialized +// CS_WORKAROUND: SPI slave with using DMA, the rx dma suffers from unexpected transactions +// before slave is ready, need disconnect CS before and after each transaction +#define SPI_LL_SLAVE_NEEDS_CS_WORKAROUND 1 +#define SPI_LL_SLAVE_NEEDS_RESET_WORKAROUND 1 +#define SPI_LL_SUPPORT_TIME_TUNING 1 + /** * The data structure holding calculated clock configuration. Since the * calculation needs long time, it should be calculated during initialization and diff --git a/components/hal/esp32p4/include/hal/spi_ll.h b/components/hal/esp32p4/include/hal/spi_ll.h index 8e0d75cab9c7..c056fad8955c 100644 --- a/components/hal/esp32p4/include/hal/spi_ll.h +++ b/components/hal/esp32p4/include/hal/spi_ll.h @@ -247,6 +247,10 @@ static inline void spi_ll_master_init(spi_dev_t *hw) hw->slave.val = 0; hw->user.val = 0; + //Disable unused error_end condition + hw->user1.mst_wfull_err_end_en = 0; + hw->user2.mst_rempty_err_end_en = 0; + hw->dma_conf.val = 0; hw->dma_conf.slv_tx_seg_trans_clr_en = 1; hw->dma_conf.slv_rx_seg_trans_clr_en = 1; @@ -748,6 +752,7 @@ static inline void spi_ll_master_keep_cs(spi_dev_t *hw, int keep_active) *----------------------------------------------------------------------------*/ /** * Set the standard clock mode for master. + * This config take effect only when SPI_CLK (pre-div before periph) div >=2 * * @param hw Beginning address of the peripheral registers. * @param enable_std True for std timing, False for half cycle delay sampling. From 7371064f8aae454a45ef2327e92e28ebd98d5992 Mon Sep 17 00:00:00 2001 From: Chen Jian Hua Date: Wed, 5 Nov 2025 13:33:19 +0800 Subject: [PATCH 2/4] feat(bt): Update bt lib for ESP32-C3 and ESP32-S3(0871069) - Added more log for BLE - Support BLE log filter and simeple output - Support BLE log compression (cherry picked from commit 03758ba550d1eec11b3f00ecc00341e2f53cd2e3) Co-authored-by: chenjianhua --- components/bt/controller/esp32c3/Kconfig.in | 8 +-- components/bt/controller/esp32c3/bt.c | 62 ++++++++++--------- components/bt/controller/lib_esp32c3_family | 2 +- .../bt/include/esp32c3/include/esp_bt.h | 6 +- 4 files changed, 38 insertions(+), 40 deletions(-) diff --git a/components/bt/controller/esp32c3/Kconfig.in b/components/bt/controller/esp32c3/Kconfig.in index 98581e269c00..006114d432f3 100644 --- a/components/bt/controller/esp32c3/Kconfig.in +++ b/components/bt/controller/esp32c3/Kconfig.in @@ -614,15 +614,15 @@ menu "Controller debug log Options (Experimental)" config BT_CTRL_LE_LOG_MODE_EN depends on BT_CTRL_LE_LOG_EN - int "Enable log for specified BLE mode" - range 0 4095 - default 4093 + hex "Enable log for specified BLE mode" + range 0 0xFFFF + default 0xDB7F config BT_CTRL_LE_LOG_LEVEL depends on BT_CTRL_LE_LOG_EN int "The level of BLE log" range 0 5 - default 2 + default 1 config BT_CTRL_LE_LOG_BUF1_SIZE depends on BT_CTRL_LE_LOG_EN diff --git a/components/bt/controller/esp32c3/bt.c b/components/bt/controller/esp32c3/bt.c index 38c091f77ac2..03cb10e1cc16 100644 --- a/components/bt/controller/esp32c3/bt.c +++ b/components/bt/controller/esp32c3/bt.c @@ -240,7 +240,12 @@ struct osi_funcs_t { }; #if CONFIG_BT_CTRL_LE_LOG_EN -typedef void (*interface_func_t) (uint32_t len, const uint8_t*addr, bool end); +typedef void (*interface_func_t) (uint32_t len, const uint8_t *addr, uint32_t len_append, const uint8_t *addr_append, uint32_t flag); + +enum { + BLE_LOG_INTERFACE_FLAG_CONTINUE = 0, + BLE_LOG_INTERFACE_FLAG_END, +}; #endif // CONFIG_BT_CTRL_LE_LOG_EN /* External functions or values @@ -303,11 +308,14 @@ extern void btdm_aa_check_enhance_enable(void); /* BLE Log module */ #if CONFIG_BT_CTRL_LE_LOG_EN +extern int r_ble_log_init_simple(interface_func_t interface, void *handler); +extern void r_ble_log_deinit_simple(void); extern int r_ble_log_init_async(interface_func_t bt_controller_log_interface, bool task_create, uint8_t buffers, uint32_t *bufs_size); extern int r_ble_log_deinit_async(void); extern void r_ble_log_async_select_dump_buffers(uint8_t buffers); extern void r_ble_log_async_output_dump_all(bool output); extern void esp_panic_handler_feed_wdts(void); +extern int r_ble_log_ctrl_level_and_mod(uint8_t level, uint32_t mod_en); #endif // CONFIG_BT_CTRL_LE_LOG_EN #if (CONFIG_BT_BLUEDROID_ENABLED || CONFIG_BT_NIMBLE_ENABLED) extern void scan_stack_enableAdvFlowCtrlVsCmd(bool en); @@ -398,12 +406,13 @@ static esp_err_t try_heap_caps_add_region(intptr_t start, intptr_t end); static void bt_controller_deinit_internal(void); #if CONFIG_BT_CTRL_LE_LOG_EN -static void esp_bt_controller_log_interface(uint32_t len, const uint8_t *addr, bool end); +#if !CONFIG_BT_CTRL_LE_LOG_MODE_BLE_LOG_V2 #if CONFIG_BT_CTRL_LE_LOG_STORAGE_EN void esp_bt_read_ctrl_log_from_flash(bool output); static int esp_bt_controller_log_storage(uint32_t len, const uint8_t *addr, bool end); static void esp_bt_ctrl_log_partition_get_and_erase_first_block(void); -#endif // #if CONFIG_BT_CTRL_LE_LOG_STORAGE_EN +#endif // CONFIG_BT_CTRL_LE_LOG_STORAGE_EN +#endif // !CONFIG_BT_CTRL_LE_LOG_MODE_BLE_LOG_V2 #endif // CONFIG_BT_CTRL_LE_LOG_EN /* Local variable definition @@ -537,18 +546,14 @@ static bool is_filled = false; #endif // CONFIG_BT_CTRL_LE_LOG_STORAGE_EN #if CONFIG_BT_CTRL_LE_LOG_MODE_BLE_LOG_V2 -static IRAM_ATTR void esp_bt_controller_log_interface(uint32_t len, const uint8_t *addr, bool end) -{ - ble_log_write_hex_ll(len, addr, 0, NULL, 0); -} - void esp_ble_controller_log_dump_all(bool output) { ble_log_dump_to_console(); } #else /* !CONFIG_BT_CTRL_LE_LOG_MODE_BLE_LOG_V2 */ -static void esp_bt_controller_log_interface(uint32_t len, const uint8_t *addr, bool end) +static void esp_bt_controller_log_interface(uint32_t len, const uint8_t *addr, uint32_t len_append, const uint8_t *addr_append, uint32_t flag) { + bool end = (flag & BIT(BLE_LOG_INTERFACE_FLAG_END)); if (log_output_mode == LOG_STORAGE_TO_FLASH) { #if CONFIG_BT_CTRL_LE_LOG_STORAGE_EN esp_bt_controller_log_storage(len, addr, end); @@ -557,24 +562,19 @@ static void esp_bt_controller_log_interface(uint32_t len, const uint8_t *addr, b portMUX_TYPE spinlock = portMUX_INITIALIZER_UNLOCKED; portENTER_CRITICAL_SAFE(&spinlock); esp_panic_handler_feed_wdts(); - for (int i = 0; i < len; i++) { - esp_rom_printf("%02x ", addr[i]); - } - if (end) { - esp_rom_printf("\n"); + if (len && addr) { + for (int i = 0; i < len; i++) { esp_rom_printf("%02x ", addr[i]); } + } + if (len_append && addr_append) { + for (int i = 0; i < len_append; i++) { esp_rom_printf("%02x ", addr_append[i]); } } + if (end) { esp_rom_printf("\n"); } + portEXIT_CRITICAL_SAFE(&spinlock); } } -#if CONFIG_BT_CTRL_LE_LOG_SPI_OUT_EN -static IRAM_ATTR void esp_bt_controller_spi_log_interface(uint32_t len, const uint8_t *addr, bool end) -{ - ble_log_spi_out_ll_write(len, addr, 0, NULL, 0); -} -#endif // CONFIG_BT_CTRL_LE_LOG_SPI_OUT_EN - void esp_ble_controller_log_dump_all(bool output) { if (log_output_mode == LOG_STORAGE_TO_FLASH) { @@ -611,16 +611,13 @@ esp_err_t esp_bt_controller_log_init(uint8_t log_output_mode) } esp_err_t ret = ESP_OK; - uint8_t buffers = 0; -#if CONFIG_BT_CTRL_LE_LOG_EN - buffers |= ESP_BLE_LOG_BUF_CONTROLLER; -#endif // CONFIG_BT_CTRL_LE_LOG_EN -#if CONFIG_BT_CTRL_LE_HCI_LOG_EN - buffers |= ESP_BLE_LOG_BUF_HCI; -#endif // CONFIG_BT_CTRL_LE_HCI_LOG_EN + ret = r_ble_log_init_simple(ble_log_write_hex_ll, NULL); + if (ret != ESP_OK) { + return ret; + } - ret = r_ble_log_init_async(esp_bt_controller_log_interface, true, buffers, (uint32_t *)log_bufs_size); + ret = r_ble_log_ctrl_level_and_mod(BLE_LOG_LEVEL, BLE_LOG_MODE_EN); if (ret == ESP_OK) { log_is_inited = true; } @@ -663,7 +660,7 @@ esp_err_t esp_bt_controller_log_init(uint8_t log_output_mode) case LOG_SPI_OUT: task_create = true; #if CONFIG_BT_CTRL_LE_LOG_SPI_OUT_EN - bt_controller_log_interface = esp_bt_controller_spi_log_interface; + bt_controller_log_interface = ble_log_spi_out_ll_write; #endif // CONFIG_BT_CTRL_LE_LOG_SPI_OUT_EN break; default: @@ -671,6 +668,11 @@ esp_err_t esp_bt_controller_log_init(uint8_t log_output_mode) } ret = r_ble_log_init_async(bt_controller_log_interface, task_create, buffers, (uint32_t *)log_bufs_size); + if (ret != ESP_OK) { + return ret; + } + + ret = r_ble_log_ctrl_level_and_mod(BLE_LOG_LEVEL, BLE_LOG_MODE_EN); if (ret == ESP_OK) { log_is_inited = true; } diff --git a/components/bt/controller/lib_esp32c3_family b/components/bt/controller/lib_esp32c3_family index 42c965137ecc..099a7e1ab87d 160000 --- a/components/bt/controller/lib_esp32c3_family +++ b/components/bt/controller/lib_esp32c3_family @@ -1 +1 @@ -Subproject commit 42c965137ecc3c6cf3d38ecece7ce71ffc461353 +Subproject commit 099a7e1ab87dd977754fc4ad35678ab7ebf2f2a2 diff --git a/components/bt/include/esp32c3/include/esp_bt.h b/components/bt/include/esp32c3/include/esp_bt.h index 0688b7fb9d83..1d45571559ec 100644 --- a/components/bt/include/esp32c3/include/esp_bt.h +++ b/components/bt/include/esp32c3/include/esp_bt.h @@ -30,7 +30,7 @@ extern "C" { * * @note Please do not modify this value */ -#define ESP_BT_CTRL_CONFIG_VERSION 0x02505080 +#define ESP_BT_CTRL_CONFIG_VERSION 0x02509280 /** * @brief Internal use only @@ -376,8 +376,6 @@ typedef void (* esp_bt_hci_tl_callback_t) (void *arg, uint8_t status); .connect_en = BT_CTRL_BLE_MASTER, \ .scan_en = BT_CTRL_BLE_SCAN, \ .ble_aa_check = BLE_CTRL_CHECK_CONNECT_IND_ACCESS_ADDRESS_ENABLED, \ - .ble_log_mode_en = BLE_LOG_MODE_EN, \ - .ble_log_level = BLE_LOG_LEVEL, \ .adv_en = BT_CTRL_BLE_ADV, \ } @@ -504,8 +502,6 @@ typedef struct { bool connect_en; /*!< True if the connection feature is enabled (default); false otherwise. Configurable in menuconfig.*/ bool scan_en; /*!< True if the scan feature is enabled (default); false otherwise. Configurable in menuconfig.*/ bool ble_aa_check; /*!< True if adds a verification step for the Access Address within the CONNECT_IND PDU; false otherwise. Configurable in menuconfig */ - uint32_t ble_log_mode_en; /*!< BLE log mode enable */ - uint8_t ble_log_level; /*!< BLE log level */ bool adv_en; /*!< True if the ADV feature is enabled (default); false otherwise. Configurable in menuconfig.*/ } esp_bt_controller_config_t; From 2eae1532e65ae9626a77bb33a8d3c4aae2a8c6e2 Mon Sep 17 00:00:00 2001 From: Chen Jian Hua Date: Wed, 5 Nov 2025 13:33:20 +0800 Subject: [PATCH 3/4] feat(ble): Enable get bt ts for ESP32-C3 and ESP32-S3 (cherry picked from commit b870a8fb5afb278ea29bbf70744589e41cdfe26a) Co-authored-by: chenjianhua --- components/bt/common/ble_log/ble_log_spi_out.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/components/bt/common/ble_log/ble_log_spi_out.c b/components/bt/common/ble_log/ble_log_spi_out.c index 2a96fec6a3c0..79c0087226a8 100644 --- a/components/bt/common/ble_log/ble_log_spi_out.c +++ b/components/bt/common/ble_log/ble_log_spi_out.c @@ -247,9 +247,9 @@ extern uint32_t r_ble_lll_timer_current_tick_get(void); #elif defined(CONFIG_IDF_TARGET_ESP32C2) extern uint32_t r_os_cputime_get32(void); #define SPI_OUT_GET_LC_TIME r_os_cputime_get32() -// #elif defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32S3) -// extern uint32_t lld_read_clock_us(void); -// #define SPI_OUT_GET_LC_TIME lld_read_clock_us() +#elif defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32S3) +extern uint32_t lld_read_clock_us(void); +#define SPI_OUT_GET_LC_TIME lld_read_clock_us() #else #define SPI_OUT_GET_LC_TIME esp_timer_get_time() #endif From b5ad158e27cc4895b0038421c3e3f7349983fe15 Mon Sep 17 00:00:00 2001 From: Chen Jian Hua Date: Wed, 5 Nov 2025 13:33:20 +0800 Subject: [PATCH 4/4] feat(ble): make ble log task stack size configurable (cherry picked from commit b525e6555b153deff11d9dc5365036eee3a5f9ee) Co-authored-by: Zhou Xiao --- components/bt/common/ble_log/Kconfig.in | 6 ++++++ .../bt/common/ble_log/src/internal_include/ble_log_rt.h | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/components/bt/common/ble_log/Kconfig.in b/components/bt/common/ble_log/Kconfig.in index dfbd47117831..f3a5e5348a72 100644 --- a/components/bt/common/ble_log/Kconfig.in +++ b/components/bt/common/ble_log/Kconfig.in @@ -5,6 +5,12 @@ config BLE_LOG_ENABLED Enable BLE Log Module if BLE_LOG_ENABLED + config BLE_LOG_TASK_STACK_SIZE + int "Stack size for BLE Log Task" + default 1024 + help + Stack size for BLE Log Task + config BLE_LOG_LBM_TRANS_SIZE int "Buffer size for each peripheral transport" default 512 diff --git a/components/bt/common/ble_log/src/internal_include/ble_log_rt.h b/components/bt/common/ble_log/src/internal_include/ble_log_rt.h index f053049339fc..ae8b4b05a37a 100644 --- a/components/bt/common/ble_log/src/internal_include/ble_log_rt.h +++ b/components/bt/common/ble_log/src/internal_include/ble_log_rt.h @@ -21,7 +21,7 @@ /* MACRO */ #define BLE_LOG_TASK_PRIO (ESP_TASK_PRIO_MAX - 1) -#define BLE_LOG_TASK_STACK_SIZE (1024) +#define BLE_LOG_TASK_STACK_SIZE CONFIG_BLE_LOG_TASK_STACK_SIZE #define BLE_LOG_TASK_HOOK_TIMEOUT_MS (1000) /* INTERFACE */