-
Notifications
You must be signed in to change notification settings - Fork 863
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/esp32c2_support_single_ble' into 'master'
feat(ESPAT-1932): Added single ble module configuration for esp32-c2 See merge request application/esp-at!1522
- Loading branch information
Showing
26 changed files
with
689 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
ESP32: f3c1850 | ||
ESP32C3: f3c1850 | ||
ESP32C2: f3c1850 | ||
ESP32C6: f3c1850 | ||
ESP32: 141f8b6 | ||
ESP32C3: 141f8b6 | ||
ESP32C2: 141f8b6 | ||
ESP32C6: 141f8b6 |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
branch:release/v5.0 | ||
commit:8fbf4ba6058bcf736317d8a7aa75d0578563c38b | ||
repository:https://github.com/espressif/esp-idf.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Name, Type, SubType, Offset, Size | ||
mfg_nvs, data, nvs, 0x1b000, 60K |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Name, Type, SubType, Offset, Size | ||
otadata, data, ota, 0x9000, 0x2000 | ||
phy_init, data, phy, 0xb000, 0x1000 | ||
nvs, data, nvs, 0xc000, 0xe000 | ||
at_customize, 0x40, 0, 0x1a000, 0x10000 | ||
storage, data, 0x22, 0x2a000, 0xa6000 | ||
ota_0, app, ota_0, 0xd0000, 0x130000 |
88 changes: 88 additions & 0 deletions
88
module_config/module_esp32c2-ble-2mb/patch/bbpll_calibration.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
diff --git a/components/esp_hw_support/port/esp32c2/rtc_clk.c b/components/esp_hw_support/port/esp32c2/rtc_clk.c | ||
index a0d88be36f..3b293e2fc4 100644 | ||
--- a/components/esp_hw_support/port/esp32c2/rtc_clk.c | ||
+++ b/components/esp_hw_support/port/esp32c2/rtc_clk.c | ||
@@ -128,6 +128,7 @@ static void rtc_clk_bbpll_configure(rtc_xtal_freq_t xtal_freq, int pll_freq) | ||
clk_ll_bbpll_set_config(pll_freq, xtal_freq); | ||
/* WAIT CALIBRATION DONE */ | ||
while(!regi2c_ctrl_ll_bbpll_calibration_is_done()); | ||
+ esp_rom_delay_us(10); | ||
/* BBPLL CALIBRATION STOP */ | ||
regi2c_ctrl_ll_bbpll_calibration_stop(); | ||
|
||
@@ -350,6 +351,22 @@ bool rtc_dig_8m_enabled(void) | ||
return clk_ll_rc_fast_digi_is_enabled(); | ||
} | ||
|
||
+// Workaround for bootloader not calibration well issue. | ||
+// Placed in IRAM because disabling BBPLL may influence the cache | ||
+void rtc_clk_recalib_bbpll(void) | ||
+{ | ||
+ rtc_cpu_freq_config_t old_config; | ||
+ rtc_clk_cpu_freq_get_config(&old_config); | ||
+ | ||
+ rtc_clk_cpu_freq_set_xtal(); | ||
+ | ||
+ rtc_clk_bbpll_disable(); | ||
+ rtc_clk_bbpll_enable(); | ||
+ rtc_clk_bbpll_configure(rtc_clk_xtal_freq_get(), 480); | ||
+ | ||
+ rtc_clk_cpu_freq_set_config(&old_config); | ||
+} | ||
+ | ||
/* Name used in libphy.a:phy_chip_v7.o | ||
* TODO: update the library to use rtc_clk_xtal_freq_get | ||
*/ | ||
diff --git a/components/esp_system/Kconfig b/components/esp_system/Kconfig | ||
index 0abd2abd9d..872434a480 100644 | ||
--- a/components/esp_system/Kconfig | ||
+++ b/components/esp_system/Kconfig | ||
@@ -543,6 +543,15 @@ menu "ESP System Settings" | ||
(2). For special workflow, the chip needs do more things instead of restarting directly. This part | ||
needs to be done in callback function of interrupt. | ||
|
||
+ config ESP_SYSTEM_BBPLL_RECALIB | ||
+ bool "Re-calibration BBPLL at startup" | ||
+ depends on IDF_TARGET_ESP32C2 || IDF_TARGET_ESP32S3 || IDF_TARGET_ESP32C6 || IDF_TARGET_ESP32H2 | ||
+ default y | ||
+ help | ||
+ This configuration helps to address an BBPLL inaccurate issue when boot from certain bootloader version, | ||
+ which may increase about the boot-up time by about 200 us. Disable this when your bootloader is built with | ||
+ ESP-IDF version v5.2 and above. | ||
+ | ||
endmenu # ESP System Settings | ||
|
||
menu "IPC (Inter-Processor Call)" | ||
diff --git a/components/esp_system/port/cpu_start.c b/components/esp_system/port/cpu_start.c | ||
index b6e6b4a2f4..c64361193b 100644 | ||
--- a/components/esp_system/port/cpu_start.c | ||
+++ b/components/esp_system/port/cpu_start.c | ||
@@ -419,6 +419,12 @@ void IRAM_ATTR call_start_cpu0(void) | ||
* In this stage, we re-configure the Flash (and MSPI) to required configuration | ||
*/ | ||
spi_flash_init_chip_state(); | ||
+ | ||
+ // In earlier version of ESP-IDF, the PLL provided by bootloader is not stable enough. | ||
+ // Do calibration again here so that we can use better clock for the timing tuning. | ||
+#if CONFIG_ESP_SYSTEM_BBPLL_RECALIB | ||
+ rtc_clk_recalib_bbpll(); | ||
+#endif | ||
#if CONFIG_IDF_TARGET_ESP32S3 | ||
//On other chips, this feature is not provided by HW, or hasn't been tested yet. | ||
spi_timing_flash_tuning(); | ||
diff --git a/components/soc/esp32c2/include/soc/rtc.h b/components/soc/esp32c2/include/soc/rtc.h | ||
index 131eecadaf..14ce306996 100644 | ||
--- a/components/soc/esp32c2/include/soc/rtc.h | ||
+++ b/components/soc/esp32c2/include/soc/rtc.h | ||
@@ -502,6 +502,11 @@ void rtc_dig_clk8m_disable(void); | ||
*/ | ||
bool rtc_dig_8m_enabled(void); | ||
|
||
+/** | ||
+ * @brief Workaround for C2, S3, C6, H2. Trigger the calibration of PLL. Should be called when the bootloader doesn't provide a good enough PLL accuracy. | ||
+*/ | ||
+void rtc_clk_recalib_bbpll(void); | ||
+ | ||
/** | ||
* @brief Calculate the real clock value after the clock calibration | ||
* |
146 changes: 146 additions & 0 deletions
146
module_config/module_esp32c2-ble-2mb/patch/blufi-adv.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
From 880c46ed4830a561df3dc6ba72dfee9c39b0559a Mon Sep 17 00:00:00 2001 | ||
From: xiewenxiang <[email protected]> | ||
Date: Thu, 13 Jul 2023 19:24:50 +0800 | ||
Subject: [PATCH] feat(blufi): Support ext adv | ||
|
||
--- | ||
.../profile/esp/blufi/nimble_host/esp_blufi.c | 98 ++++++++++++++++++- | ||
1 file changed, 97 insertions(+), 1 deletion(-) | ||
|
||
diff --git a/components/bt/common/btc/profile/esp/blufi/nimble_host/esp_blufi.c b/components/bt/common/btc/profile/esp/blufi/nimble_host/esp_blufi.c | ||
index 5a22773c7a..220a29de81 100644 | ||
--- a/components/bt/common/btc/profile/esp/blufi/nimble_host/esp_blufi.c | ||
+++ b/components/bt/common/btc/profile/esp/blufi/nimble_host/esp_blufi.c | ||
@@ -32,11 +32,22 @@ | ||
|
||
#if (BLUFI_INCLUDED == TRUE) | ||
|
||
+#if !CONFIG_BT_NIMBLE_EXT_ADV | ||
static uint8_t own_addr_type; | ||
+#endif | ||
|
||
struct gatt_value gatt_values[SERVER_MAX_VALUES]; | ||
const static char *TAG = "BLUFI_EXAMPLE"; | ||
|
||
+#if CONFIG_BT_NIMBLE_EXT_ADV | ||
+static uint8_t ext_adv_pattern_1[] = { | ||
+ 0x02, 0x01, 0x06, | ||
+ 0x03, 0x03, 0xFF, 0xFF, | ||
+ 0x0d, 0X09, 'B', 'L', 'U', 'F','I', '_' ,'D','E','V','I','C','E', | ||
+ 0x02, 0x0A, 0x09 | ||
+}; | ||
+#endif | ||
+ | ||
enum { | ||
GATT_VALUE_TYPE_CHR, | ||
GATT_VALUE_TYPE_DSC, | ||
@@ -333,6 +344,79 @@ esp_blufi_gap_event(struct ble_gap_event *event, void *arg) | ||
|
||
void esp_blufi_adv_start(void) | ||
{ | ||
+#if CONFIG_BT_NIMBLE_EXT_ADV //Extended Adv | ||
+ struct ble_gap_ext_adv_params params; | ||
+ struct os_mbuf *data; | ||
+ uint8_t instance = 0; | ||
+ int rc; | ||
+ const char *name; | ||
+ uint8_t adv_data[31] = {0}; | ||
+ | ||
+ /* use defaults for non-set params */ | ||
+ memset (¶ms, 0, sizeof(params)); | ||
+ | ||
+ /* enable connectable advertising */ | ||
+ params.connectable = 1; | ||
+ params.scannable = 1; | ||
+ params.legacy_pdu = 1; | ||
+ | ||
+ /* advertise using public addr */ | ||
+ params.own_addr_type = BLE_OWN_ADDR_PUBLIC; | ||
+ | ||
+ params.primary_phy = BLE_HCI_LE_PHY_1M; | ||
+ params.secondary_phy = BLE_HCI_LE_PHY_1M; | ||
+ params.sid = 1; | ||
+ | ||
+ params.itvl_min = BLE_GAP_ADV_FAST_INTERVAL1_MIN; | ||
+ params.itvl_max = BLE_GAP_ADV_FAST_INTERVAL1_MIN; | ||
+ | ||
+ /* configure instance 0 */ | ||
+ rc = ble_gap_ext_adv_configure(instance, ¶ms, NULL, | ||
+ esp_blufi_gap_event, NULL); | ||
+ if (rc != 0) { | ||
+ ESP_LOGE(TAG, "Configuration failed with reason : %d \n" , rc); | ||
+ return; | ||
+ } | ||
+ | ||
+ name = ble_svc_gap_device_name(); | ||
+ adv_data[0] = 0x02; | ||
+ adv_data[1] = 0x01; | ||
+ adv_data[2] = 0x06; | ||
+ adv_data[3] = 1 + strlen(name); | ||
+ adv_data[4] = 0x09; | ||
+ memcpy(adv_data + 5, name, strlen(name)); | ||
+ | ||
+ /* get mbuf for scan rsp data */ | ||
+ data = os_msys_get_pkthdr(strlen(name) + 5, 0); | ||
+ | ||
+ if (data == NULL) { | ||
+ ESP_LOGE(TAG, "Failed to get mbuf \n"); | ||
+ return; | ||
+ } | ||
+ | ||
+ /* fill mbuf with scan rsp data */ | ||
+ rc = os_mbuf_append(data, adv_data, strlen(name) + 5); | ||
+ | ||
+ if (rc != 0) { | ||
+ ESP_LOGE(TAG, "Failed to fill scan rsp data with reason: %d \n", rc); | ||
+ return; | ||
+ } | ||
+ | ||
+ rc = ble_gap_ext_adv_set_data(instance, data); | ||
+ | ||
+ if (rc != 0) { | ||
+ ESP_LOGE(TAG, "Failed to set adv data with reason: %d \n", rc); | ||
+ return; | ||
+ } | ||
+ | ||
+ /* start advertising */ | ||
+ rc = ble_gap_ext_adv_start(instance, 0, 0); | ||
+ | ||
+ if (rc != 0) { | ||
+ ESP_LOGE(TAG, "Failed to start ext adv with reason: %d \n", rc); | ||
+ return; | ||
+ } | ||
+#else // Legacy ADV | ||
int rc; | ||
|
||
rc = ble_hs_util_ensure_addr(0); | ||
@@ -404,6 +488,7 @@ void esp_blufi_adv_start(void) | ||
ESP_LOGE(TAG, "error enabling advertisement; rc=%d\n", rc); | ||
return; | ||
} | ||
+#endif | ||
} | ||
|
||
uint8_t esp_blufi_init(void) | ||
@@ -447,7 +532,18 @@ void esp_blufi_disconnect(void) | ||
ble_gap_terminate(blufi_env.conn_id, BLE_ERR_REM_USER_CONN_TERM); | ||
} | ||
|
||
-void esp_blufi_adv_stop(void) {} | ||
+void esp_blufi_adv_stop(void) | ||
+{ | ||
+#if CONFIG_BT_NIMBLE_EXT_ADV | ||
+ int i; | ||
+ | ||
+ for (i = 0; i < BLE_ADV_INSTANCES; i++) { | ||
+ ble_gap_ext_adv_stop(i); | ||
+ } | ||
+#else | ||
+ ble_gap_adv_stop(); | ||
+#endif | ||
+} | ||
|
||
void esp_blufi_send_encap(void *arg) | ||
{ | ||
-- | ||
2.25.1 |
Oops, something went wrong.