mirror of
https://github.com/espressif/esp-idf.git
synced 2025-07-30 10:47:19 +02:00
Merge branch 'bugfix/fix_the_bluedroid_hci_crash_on_esp32c2' into 'release/v5.0'
Fixed the bluedroid hci crash due to insufficient memory on ESP32C2 See merge request espressif/esp-idf!22056
This commit is contained in:
@ -207,7 +207,7 @@ menu "Memory Settings"
|
|||||||
|
|
||||||
config BT_LE_ACL_BUF_COUNT
|
config BT_LE_ACL_BUF_COUNT
|
||||||
int "ACL Buffer count"
|
int "ACL Buffer count"
|
||||||
default 24
|
default 10
|
||||||
help
|
help
|
||||||
The number of ACL data buffers.
|
The number of ACL data buffers.
|
||||||
|
|
||||||
@ -387,3 +387,10 @@ choice BT_LE_WAKEUP_SOURCE
|
|||||||
help
|
help
|
||||||
Use BLE rtc timer to wakeup CPU
|
Use BLE rtc timer to wakeup CPU
|
||||||
endchoice
|
endchoice
|
||||||
|
|
||||||
|
config BT_LE_USE_ESP_TIMER
|
||||||
|
bool "Use Esp Timer for callout"
|
||||||
|
depends on !BT_NIMBLE_ENABLED
|
||||||
|
default y
|
||||||
|
help
|
||||||
|
Set this option to use Esp Timer which has higher priority timer instead of FreeRTOS timer
|
||||||
|
@ -207,7 +207,7 @@ menu "Memory Settings"
|
|||||||
|
|
||||||
config BT_LE_ACL_BUF_COUNT
|
config BT_LE_ACL_BUF_COUNT
|
||||||
int "ACL Buffer count"
|
int "ACL Buffer count"
|
||||||
default 24
|
default 10
|
||||||
help
|
help
|
||||||
The number of ACL data buffers.
|
The number of ACL data buffers.
|
||||||
|
|
||||||
@ -381,5 +381,11 @@ choice BT_LE_WAKEUP_SOURCE
|
|||||||
bool "Use ESP timer to wakeup CPU"
|
bool "Use ESP timer to wakeup CPU"
|
||||||
help
|
help
|
||||||
Use esp timer to wakeup CPU
|
Use esp timer to wakeup CPU
|
||||||
|
|
||||||
endchoice
|
endchoice
|
||||||
|
|
||||||
|
config BT_LE_USE_ESP_TIMER
|
||||||
|
bool "Use Esp Timer for callout"
|
||||||
|
depends on !BT_NIMBLE_ENABLED
|
||||||
|
default y
|
||||||
|
help
|
||||||
|
Set this option to use Esp Timer which has higher priority timer instead of FreeRTOS timer
|
||||||
|
@ -64,10 +64,10 @@ config BT_NIMBLE_LOG_LEVEL
|
|||||||
|
|
||||||
config BT_NIMBLE_MAX_CONNECTIONS
|
config BT_NIMBLE_MAX_CONNECTIONS
|
||||||
int "Maximum number of concurrent connections"
|
int "Maximum number of concurrent connections"
|
||||||
range 1 8 if IDF_TARGET_ESP32H4
|
range 1 8 if IDF_TARGET_ESP32H2
|
||||||
range 1 2 if IDF_TARGET_ESP32C2
|
range 1 2 if IDF_TARGET_ESP32C2
|
||||||
range 1 9 if !SOC_ESP_NIMBLE_CONTROLLER
|
range 1 9 if !SOC_ESP_NIMBLE_CONTROLLER
|
||||||
default 3 if (IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32S3 || IDF_TARGET_ESP32H4)
|
default 3 if (IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32S3 || IDF_TARGET_ESP32H2)
|
||||||
default 2 if IDF_TARGET_ESP32C2
|
default 2 if IDF_TARGET_ESP32C2
|
||||||
depends on BT_NIMBLE_ENABLED
|
depends on BT_NIMBLE_ENABLED
|
||||||
help
|
help
|
||||||
|
@ -12,6 +12,15 @@
|
|||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
#include "sdkconfig.h"
|
||||||
|
|
||||||
|
#if ((defined(CONFIG_BT_NIMBLE_USE_ESP_TIMER) && CONFIG_BT_NIMBLE_USE_ESP_TIMER) || \
|
||||||
|
(defined(CONFIG_BT_LE_USE_ESP_TIMER) && CONFIG_BT_LE_USE_ESP_TIMER))
|
||||||
|
/* Use esp timer instead of FreeRTOS timer to implement the callout. */
|
||||||
|
#define BLE_NPL_USE_ESP_TIMER (1)
|
||||||
|
#else
|
||||||
|
#define BLE_NPL_USE_ESP_TIMER (0)
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef void ble_npl_event_fn(struct ble_npl_event *ev);
|
typedef void ble_npl_event_fn(struct ble_npl_event *ev);
|
||||||
|
|
||||||
@ -26,7 +35,7 @@ struct ble_npl_eventq_freertos {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct ble_npl_callout_freertos {
|
struct ble_npl_callout_freertos {
|
||||||
#if CONFIG_BT_NIMBLE_USE_ESP_TIMER
|
#if BLE_NPL_USE_ESP_TIMER
|
||||||
esp_timer_handle_t handle;
|
esp_timer_handle_t handle;
|
||||||
#else
|
#else
|
||||||
TimerHandle_t handle;
|
TimerHandle_t handle;
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
|
|
||||||
portMUX_TYPE ble_port_mutex = portMUX_INITIALIZER_UNLOCKED;
|
portMUX_TYPE ble_port_mutex = portMUX_INITIALIZER_UNLOCKED;
|
||||||
|
|
||||||
#if CONFIG_BT_NIMBLE_USE_ESP_TIMER
|
#if BLE_NPL_USE_ESP_TIMER
|
||||||
static const char *TAG = "Timer";
|
static const char *TAG = "Timer";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -540,7 +540,7 @@ IRAM_ATTR npl_freertos_sem_release(struct ble_npl_sem *sem)
|
|||||||
return BLE_NPL_OK;
|
return BLE_NPL_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if CONFIG_BT_NIMBLE_USE_ESP_TIMER
|
#if BLE_NPL_USE_ESP_TIMER
|
||||||
static void
|
static void
|
||||||
IRAM_ATTR ble_npl_event_fn_wrapper(void *arg)
|
IRAM_ATTR ble_npl_event_fn_wrapper(void *arg)
|
||||||
{
|
{
|
||||||
@ -606,7 +606,7 @@ npl_freertos_callout_init(struct ble_npl_callout *co, struct ble_npl_eventq *evq
|
|||||||
memset(callout, 0, sizeof(*callout));
|
memset(callout, 0, sizeof(*callout));
|
||||||
ble_npl_event_init(&callout->ev, ev_cb, ev_arg);
|
ble_npl_event_init(&callout->ev, ev_cb, ev_arg);
|
||||||
|
|
||||||
#if CONFIG_BT_NIMBLE_USE_ESP_TIMER
|
#if BLE_NPL_USE_ESP_TIMER
|
||||||
callout->evq = evq;
|
callout->evq = evq;
|
||||||
|
|
||||||
esp_timer_create_args_t create_args = {
|
esp_timer_create_args_t create_args = {
|
||||||
@ -630,7 +630,7 @@ npl_freertos_callout_init(struct ble_npl_callout *co, struct ble_npl_eventq *evq
|
|||||||
co->co = NULL;
|
co->co = NULL;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#endif // CONFIG_BT_NIMBLE_USE_ESP_TIMER
|
#endif // BLE_NPL_USE_ESP_TIMER
|
||||||
} else {
|
} else {
|
||||||
callout = (struct ble_npl_callout_freertos *)co->co;
|
callout = (struct ble_npl_callout_freertos *)co->co;
|
||||||
BLE_LL_ASSERT(callout);
|
BLE_LL_ASSERT(callout);
|
||||||
@ -649,7 +649,7 @@ npl_freertos_callout_init(struct ble_npl_callout *co, struct ble_npl_eventq *evq
|
|||||||
memset(callout, 0, sizeof(*callout));
|
memset(callout, 0, sizeof(*callout));
|
||||||
ble_npl_event_init(&callout->ev, ev_cb, ev_arg);
|
ble_npl_event_init(&callout->ev, ev_cb, ev_arg);
|
||||||
|
|
||||||
#if CONFIG_BT_NIMBLE_USE_ESP_TIMER
|
#if BLE_NPL_USE_ESP_TIMER
|
||||||
callout->evq = evq;
|
callout->evq = evq;
|
||||||
|
|
||||||
esp_timer_create_args_t create_args = {
|
esp_timer_create_args_t create_args = {
|
||||||
@ -673,7 +673,7 @@ npl_freertos_callout_init(struct ble_npl_callout *co, struct ble_npl_eventq *evq
|
|||||||
co->co = NULL;
|
co->co = NULL;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#endif // CONFIG_BT_NIMBLE_USE_ESP_TIMER
|
#endif // BLE_NPL_USE_ESP_TIMER
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
callout = (struct ble_npl_callout_freertos *)co->co;
|
callout = (struct ble_npl_callout_freertos *)co->co;
|
||||||
@ -700,7 +700,7 @@ npl_freertos_callout_deinit(struct ble_npl_callout *co)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ble_npl_event_deinit(&callout->ev);
|
ble_npl_event_deinit(&callout->ev);
|
||||||
#if CONFIG_BT_NIMBLE_USE_ESP_TIMER
|
#if BLE_NPL_USE_ESP_TIMER
|
||||||
esp_err_t err = esp_timer_stop(callout->handle);
|
esp_err_t err = esp_timer_stop(callout->handle);
|
||||||
if(err != ESP_OK) {
|
if(err != ESP_OK) {
|
||||||
if (err != ESP_ERR_INVALID_STATE) { // ESP_ERR_INVALID_STATE is expected when timer is already stopped
|
if (err != ESP_ERR_INVALID_STATE) { // ESP_ERR_INVALID_STATE is expected when timer is already stopped
|
||||||
@ -718,7 +718,7 @@ npl_freertos_callout_deinit(struct ble_npl_callout *co)
|
|||||||
#else
|
#else
|
||||||
free((void *)callout);
|
free((void *)callout);
|
||||||
#endif // OS_MEM_ALLOC
|
#endif // OS_MEM_ALLOC
|
||||||
#endif // CONFIG_BT_NIMBLE_USE_ESP_TIMER
|
#endif // BLE_NPL_USE_ESP_TIMER
|
||||||
co->co = NULL;
|
co->co = NULL;
|
||||||
memset(co, 0, sizeof(struct ble_npl_callout));
|
memset(co, 0, sizeof(struct ble_npl_callout));
|
||||||
}
|
}
|
||||||
@ -735,7 +735,7 @@ ble_npl_error_t
|
|||||||
IRAM_ATTR npl_freertos_callout_reset(struct ble_npl_callout *co, ble_npl_time_t ticks)
|
IRAM_ATTR npl_freertos_callout_reset(struct ble_npl_callout *co, ble_npl_time_t ticks)
|
||||||
{
|
{
|
||||||
struct ble_npl_callout_freertos *callout = (struct ble_npl_callout_freertos *)co->co;
|
struct ble_npl_callout_freertos *callout = (struct ble_npl_callout_freertos *)co->co;
|
||||||
#if CONFIG_BT_NIMBLE_USE_ESP_TIMER
|
#if BLE_NPL_USE_ESP_TIMER
|
||||||
esp_timer_stop(callout->handle);
|
esp_timer_stop(callout->handle);
|
||||||
|
|
||||||
return esp_err_to_npl_error(esp_timer_start_once(callout->handle, ticks*1000));
|
return esp_err_to_npl_error(esp_timer_start_once(callout->handle, ticks*1000));
|
||||||
@ -773,7 +773,7 @@ IRAM_ATTR npl_freertos_callout_stop(struct ble_npl_callout *co)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if CONFIG_BT_NIMBLE_USE_ESP_TIMER
|
#if BLE_NPL_USE_ESP_TIMER
|
||||||
esp_timer_stop(callout->handle);
|
esp_timer_stop(callout->handle);
|
||||||
#else
|
#else
|
||||||
xTimerStop(callout->handle, portMAX_DELAY);
|
xTimerStop(callout->handle, portMAX_DELAY);
|
||||||
@ -784,7 +784,7 @@ bool
|
|||||||
IRAM_ATTR npl_freertos_callout_is_active(struct ble_npl_callout *co)
|
IRAM_ATTR npl_freertos_callout_is_active(struct ble_npl_callout *co)
|
||||||
{
|
{
|
||||||
struct ble_npl_callout_freertos *callout = (struct ble_npl_callout_freertos *)co->co;
|
struct ble_npl_callout_freertos *callout = (struct ble_npl_callout_freertos *)co->co;
|
||||||
#if CONFIG_BT_NIMBLE_USE_ESP_TIMER
|
#if BLE_NPL_USE_ESP_TIMER
|
||||||
return esp_timer_is_active(callout->handle);
|
return esp_timer_is_active(callout->handle);
|
||||||
#else
|
#else
|
||||||
return xTimerIsTimerActive(callout->handle) == pdTRUE;
|
return xTimerIsTimerActive(callout->handle) == pdTRUE;
|
||||||
@ -794,7 +794,7 @@ IRAM_ATTR npl_freertos_callout_is_active(struct ble_npl_callout *co)
|
|||||||
ble_npl_time_t
|
ble_npl_time_t
|
||||||
IRAM_ATTR npl_freertos_callout_get_ticks(struct ble_npl_callout *co)
|
IRAM_ATTR npl_freertos_callout_get_ticks(struct ble_npl_callout *co)
|
||||||
{
|
{
|
||||||
#if CONFIG_BT_NIMBLE_USE_ESP_TIMER
|
#if BLE_NPL_USE_ESP_TIMER
|
||||||
/* Currently, esp_timer does not support an API which gets the expiry time for
|
/* Currently, esp_timer does not support an API which gets the expiry time for
|
||||||
* current timer.
|
* current timer.
|
||||||
* Returning 0 from here should not cause any effect.
|
* Returning 0 from here should not cause any effect.
|
||||||
@ -819,7 +819,7 @@ IRAM_ATTR npl_freertos_callout_remaining_ticks(struct ble_npl_callout *co,
|
|||||||
|
|
||||||
struct ble_npl_callout_freertos *callout = (struct ble_npl_callout_freertos *)co->co;
|
struct ble_npl_callout_freertos *callout = (struct ble_npl_callout_freertos *)co->co;
|
||||||
|
|
||||||
#if CONFIG_BT_NIMBLE_USE_ESP_TIMER
|
#if BLE_NPL_USE_ESP_TIMER
|
||||||
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
|
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
|
||||||
uint64_t expiry = 0;
|
uint64_t expiry = 0;
|
||||||
esp_err_t err;
|
esp_err_t err;
|
||||||
@ -862,7 +862,7 @@ IRAM_ATTR npl_freertos_callout_set_arg(struct ble_npl_callout *co, void *arg)
|
|||||||
uint32_t
|
uint32_t
|
||||||
IRAM_ATTR npl_freertos_time_get(void)
|
IRAM_ATTR npl_freertos_time_get(void)
|
||||||
{
|
{
|
||||||
#if CONFIG_BT_NIMBLE_USE_ESP_TIMER
|
#if BLE_NPL_USE_ESP_TIMER
|
||||||
return esp_timer_get_time() / 1000;
|
return esp_timer_get_time() / 1000;
|
||||||
#else
|
#else
|
||||||
return xTaskGetTickCountFromISR();
|
return xTaskGetTickCountFromISR();
|
||||||
@ -873,7 +873,7 @@ ble_npl_error_t
|
|||||||
IRAM_ATTR npl_freertos_time_ms_to_ticks(uint32_t ms, ble_npl_time_t *out_ticks)
|
IRAM_ATTR npl_freertos_time_ms_to_ticks(uint32_t ms, ble_npl_time_t *out_ticks)
|
||||||
{
|
{
|
||||||
uint64_t ticks;
|
uint64_t ticks;
|
||||||
#if CONFIG_BT_NIMBLE_USE_ESP_TIMER
|
#if BLE_NPL_USE_ESP_TIMER
|
||||||
ticks = (uint64_t)ms;
|
ticks = (uint64_t)ms;
|
||||||
#else
|
#else
|
||||||
ticks = ((uint64_t)ms * configTICK_RATE_HZ) / 1000;
|
ticks = ((uint64_t)ms * configTICK_RATE_HZ) / 1000;
|
||||||
@ -891,7 +891,7 @@ ble_npl_error_t
|
|||||||
IRAM_ATTR npl_freertos_time_ticks_to_ms(ble_npl_time_t ticks, uint32_t *out_ms)
|
IRAM_ATTR npl_freertos_time_ticks_to_ms(ble_npl_time_t ticks, uint32_t *out_ms)
|
||||||
{
|
{
|
||||||
uint64_t ms;
|
uint64_t ms;
|
||||||
#if CONFIG_BT_NIMBLE_USE_ESP_TIMER
|
#if BLE_NPL_USE_ESP_TIMER
|
||||||
ms = ((uint64_t)ticks);
|
ms = ((uint64_t)ticks);
|
||||||
#else
|
#else
|
||||||
ms = ((uint64_t)ticks * 1000) / configTICK_RATE_HZ;
|
ms = ((uint64_t)ticks * 1000) / configTICK_RATE_HZ;
|
||||||
@ -908,7 +908,7 @@ IRAM_ATTR npl_freertos_time_ticks_to_ms(ble_npl_time_t ticks, uint32_t *out_ms)
|
|||||||
ble_npl_time_t
|
ble_npl_time_t
|
||||||
IRAM_ATTR npl_freertos_time_ms_to_ticks32(uint32_t ms)
|
IRAM_ATTR npl_freertos_time_ms_to_ticks32(uint32_t ms)
|
||||||
{
|
{
|
||||||
#if CONFIG_BT_NIMBLE_USE_ESP_TIMER
|
#if BLE_NPL_USE_ESP_TIMER
|
||||||
return ms;
|
return ms;
|
||||||
#else
|
#else
|
||||||
return ms * configTICK_RATE_HZ / 1000;
|
return ms * configTICK_RATE_HZ / 1000;
|
||||||
@ -918,7 +918,7 @@ IRAM_ATTR npl_freertos_time_ms_to_ticks32(uint32_t ms)
|
|||||||
uint32_t
|
uint32_t
|
||||||
IRAM_ATTR npl_freertos_time_ticks_to_ms32(ble_npl_time_t ticks)
|
IRAM_ATTR npl_freertos_time_ticks_to_ms32(ble_npl_time_t ticks)
|
||||||
{
|
{
|
||||||
#if CONFIG_BT_NIMBLE_USE_ESP_TIMER
|
#if BLE_NPL_USE_ESP_TIMER
|
||||||
return ticks;
|
return ticks;
|
||||||
#else
|
#else
|
||||||
return ticks * 1000 / configTICK_RATE_HZ;
|
return ticks * 1000 / configTICK_RATE_HZ;
|
||||||
@ -928,7 +928,7 @@ IRAM_ATTR npl_freertos_time_ticks_to_ms32(ble_npl_time_t ticks)
|
|||||||
void
|
void
|
||||||
IRAM_ATTR npl_freertos_time_delay(ble_npl_time_t ticks)
|
IRAM_ATTR npl_freertos_time_delay(ble_npl_time_t ticks)
|
||||||
{
|
{
|
||||||
#if CONFIG_BT_NIMBLE_USE_ESP_TIMER
|
#if BLE_NPL_USE_ESP_TIMER
|
||||||
vTaskDelay(ticks / portTICK_PERIOD_MS);
|
vTaskDelay(ticks / portTICK_PERIOD_MS);
|
||||||
#else
|
#else
|
||||||
vTaskDelay(ticks);
|
vTaskDelay(ticks);
|
||||||
|
Reference in New Issue
Block a user