Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions components/bt/common/ble_log/Kconfig.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions components/bt/common/ble_log/ble_log_spi_out.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
8 changes: 4 additions & 4 deletions components/bt/controller/esp32c3/Kconfig.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
62 changes: 32 additions & 30 deletions components/bt/controller/esp32c3/bt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -663,14 +660,19 @@ 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:
assert(0);
}

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;
}
Expand Down
6 changes: 1 addition & 5 deletions components/bt/include/esp32c3/include/esp_bt.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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, \
}

Expand Down Expand Up @@ -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;

Expand Down
3 changes: 2 additions & 1 deletion components/esp_driver_spi/src/gpspi/spi_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 1 addition & 3 deletions components/esp_driver_spi/src/gpspi/spi_master.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 7 additions & 1 deletion components/esp_driver_spi/src/gpspi/spi_slave.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions components/hal/esp32/include/hal/spi_ll.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions components/hal/esp32p4/include/hal/spi_ll.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
Loading