Skip to content

Commit

Permalink
Merge branch 'feature/esp32c2_support_single_ble' into 'master'
Browse files Browse the repository at this point in the history
feat(ESPAT-1932): Added single ble module configuration for esp32-c2

See merge request application/esp-at!1522
  • Loading branch information
xcguang committed Feb 21, 2024
2 parents 5bc838f + 5ae4022 commit 50b25ce
Show file tree
Hide file tree
Showing 26 changed files with 689 additions and 31 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ jobs:
artifacts_name: esp32c2-2MB-at
secrets: inherit

build-esp32c2-ble-2mb-at:
uses: ./.github/workflows/build_template_esp32c2.yml
with:
module_name: ESP32C2-BLE-2MB
artifacts_name: esp32c2-ble-2mb-at
secrets: inherit

build-esp32c6-4mb-at:
uses: ./.github/workflows/build_template_esp32c6.yml
with:
Expand Down
11 changes: 5 additions & 6 deletions .gitlab/ci/build_esp32c2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,17 @@ esp32c2_4mb_at:
variables:
MODULE_NAME: "ESP32C2-4MB"

esp32c2_4mb_at_xtal_40mhz_test:
esp32c2_ble_2mb_at:
extends:
- .build_template_esp32c2
- .before_script_esp32c2_enable_40mhz_xtal
- .rules:build:build_project_on_protected
- .rules:build:build_project
variables:
MODULE_NAME: "ESP32C2-4MB"
MODULE_NAME: "ESP32C2-BLE-2MB"

esp32c2_at_ble_function_test:
esp32c2_4mb_at_xtal_40mhz_test:
extends:
- .build_template_esp32c2
- .before_script_esp32c2_enable_ble_cmds
- .before_script_esp32c2_enable_40mhz_xtal
- .rules:build:build_project_on_protected
variables:
MODULE_NAME: "ESP32C2-4MB"
Expand Down
15 changes: 0 additions & 15 deletions .gitlab/ci/build_template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,6 @@
- echo -e "CONFIG_AT_BLUFI_COMMAND_SUPPORT=n" >> module_config/${module_cfg_dir}/sdkconfig.defaults
- echo -e "CONFIG_AT_BT_COMMAND_SUPPORT=n" >> module_config/${module_cfg_dir}/sdkconfig.defaults

.enable_ble_cmd_esp32c2: &enable_ble_cmd_esp32c2
- sed -i '/CONFIG_BT_NIMBLE_50_FEATURE_SUPPORT=n/,/CONFIG_BT_NIMBLE_HCI_EVT_LO_BUF_COUNT=3/d' module_config/module_esp32c2_default/sdkconfig.defaults
- echo -e "CONFIG_AT_BLE_COMMAND_SUPPORT=y" >> module_config/module_esp32c2_default/sdkconfig.defaults
- echo -e "CONFIG_BT_NIMBLE_EXT_ADV=y" >> module_config/module_esp32c2_default/sdkconfig.defaults
- echo -e "CONFIG_BT_NIMBLE_MAX_PERIODIC_SYNCS=1" >> module_config/module_esp32c2_default/sdkconfig.defaults
- echo -e "CONFIG_BT_NIMBLE_GAP_DEVICE_NAME_MAX_LEN=32" >> module_config/module_esp32c2_default/sdkconfig.defaults
- echo -e "CONFIG_BT_NIMBLE_ATT_PREFERRED_MTU=203" >> module_config/module_esp32c2_default/sdkconfig.defaults

.enable_40mhz_xtal: &enable_40mhz_xtal
- echo -e "CONFIG_XTAL_FREQ_40=y" >> module_config/module_esp32c2_default/sdkconfig.defaults

Expand Down Expand Up @@ -220,13 +212,6 @@
- *enable_ethernet_cmds
- *enlarge_app_partition

.before_script_esp32c2_enable_ble_cmds:
before_script:
- source ${CI_PROJECT_DIR}/.gitlab/ci/utils.sh
- add_gitlab_ssh_keys
- *setup_tokens_esp32c2
- *enable_ble_cmd_esp32c2

.before_script_esp32c2_enable_40mhz_xtal:
before_script:
- source ${CI_PROJECT_DIR}/.gitlab/ci/utils.sh
Expand Down
5 changes: 2 additions & 3 deletions components/at/include/esp_at_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,11 @@ typedef enum {
} esp_at_result_code_string_index;

/**
* @brief This function should be called only once, before any other AT functions are called.
* @brief This function should be called only once.
*
* @param netconn_max the maximum number of the link in the at module
* @param custom_version version information by custom
*/
void esp_at_module_init(uint32_t netconn_max, const uint8_t *custom_version);
void esp_at_module_init(const uint8_t *custom_version);

/**
* @brief Parse digit parameter from command string.
Expand Down
8 changes: 4 additions & 4 deletions components/at/lib/VERSION
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 modified components/at/lib/libesp32_at_core.a
Binary file not shown.
Binary file modified components/at/lib/libesp32_at_core_silence.a
Binary file not shown.
Binary file modified components/at/lib/libesp32c2_at_core.a
Binary file not shown.
Binary file modified components/at/lib/libesp32c2_at_core_silence.a
Binary file not shown.
Binary file modified components/at/lib/libesp32c3_at_core.a
Binary file not shown.
Binary file modified components/at/lib/libesp32c3_at_core_silence.a
Binary file not shown.
Binary file modified components/at/lib/libesp32c6_at_core.a
Binary file not shown.
Binary file modified components/at/lib/libesp32c6_at_core_silence.a
Binary file not shown.
8 changes: 8 additions & 0 deletions components/at/src/at_default_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ static const esp_at_module_info_t esp_at_module_info[] = {
#if defined(CONFIG_IDF_TARGET_ESP32C2)
{"ESP32C2-2MB", CONFIG_ESP_AT_OTA_TOKEN_ESP32C2_2MB, CONFIG_ESP_AT_OTA_SSL_TOKEN_ESP32C2_2MB},
{"ESP32C2-4MB", CONFIG_ESP_AT_OTA_TOKEN_ESP32C2_4MB, CONFIG_ESP_AT_OTA_SSL_TOKEN_ESP32C2_4MB},
{"ESP32C2-BLE-2MB", NULL, NULL},
#endif

#if defined(CONFIG_IDF_TARGET_ESP32C6)
Expand Down Expand Up @@ -79,6 +80,13 @@ uint32_t esp_at_get_socket_task_stack_size(void)
return CONFIG_AT_SOCKET_TASK_STACK_SIZE;
}

#ifdef CONFIG_AT_NET_COMMAND_SUPPORT
uint32_t esp_at_get_netconn_count(void)
{
return CONFIG_AT_SOCKET_MAX_CONN_NUM;
}
#endif

#ifdef CONFIG_AT_OTA_SUPPORT
const char* esp_at_get_ota_token_by_id(uint32_t id, at_ota_mode_t ota_mode)
{
Expand Down
2 changes: 1 addition & 1 deletion components/at/src/at_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ static void at_module_init(void)
"Bin version:%s(%s)\r\n", CONFIG_ESP_AT_FW_VERSION, esp_at_get_current_module_name());
#endif

esp_at_module_init(CONFIG_AT_SOCKET_MAX_CONN_NUM, version);
esp_at_module_init(version);
free(version);

ESP_LOGD(TAG, "at module init done");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ PLATFORM_ESP32,ESP32-D2WD,"2MB flash, No OTA",4,78,1,1,13,CN,115200,22,19,15,14
PLATFORM_ESP32C3,MINI-1,TX:7 RX:6,4,78,1,1,13,CN,115200,7,6,5,4
PLATFORM_ESP32C3,ESP32C3-SPI,,4,78,-1,1,13,CN,-1,-1,-1,-1,-1
PLATFORM_ESP32C3,ESP32C3_RAINMAKER,TX:7 RX:6,4,78,1,1,13,CN,115200,7,6,5,4
PLATFORM_ESP32C2,ESP32C2-2MB,"ESP32C2 (ESP8684) series with 2MB flash, TX:7 RX:6",4,78,1,1,13,CN,115200,7,6,19,20
PLATFORM_ESP32C2,ESP32C2-4MB,"ESP32C2 (ESP8684) series with 4MB flash, TX:7 RX:6",4,78,1,1,13,CN,115200,7,6,5,4
PLATFORM_ESP32C2,ESP32C2-2MB,"Single Wi-Fi, 2MB, TX:7 RX:6",4,78,1,1,13,CN,115200,7,6,19,20
PLATFORM_ESP32C2,ESP32C2-4MB,"Wi-Fi + BluFi, 4MB, TX:7 RX:6",4,78,1,1,13,CN,115200,7,6,5,4
PLATFORM_ESP32C2,ESP32C2-BLE-2MB,"Single BLE, 2MB, TX:7 RX:6",4,78,1,1,13,CN,115200,7,6,5,4
PLATFORM_ESP32C6,ESP32C6-4MB,"TX:7 RX:6",4,78,1,1,13,CN,115200,7,6,5,4
3 changes: 3 additions & 0 deletions module_config/module_esp32c2-ble-2mb/IDF_VERSION
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
2 changes: 2 additions & 0 deletions module_config/module_esp32c2-ble-2mb/at_customize.csv
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
7 changes: 7 additions & 0 deletions module_config/module_esp32c2-ble-2mb/partitions_at.csv
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 module_config/module_esp32c2-ble-2mb/patch/bbpll_calibration.patch
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 module_config/module_esp32c2-ble-2mb/patch/blufi-adv.patch
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 (&params, 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, &params, 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
Loading

0 comments on commit 50b25ce

Please sign in to comment.