Skip to content

Commit

Permalink
Merge branch 'feature/support_esp32s2' into 'master'
Browse files Browse the repository at this point in the history
feat: Added esp32-s2 support

See merge request application/esp-at!1560
  • Loading branch information
xcguang committed May 10, 2024
2 parents 60cbf45 + ad368e7 commit 63b9986
Show file tree
Hide file tree
Showing 22 changed files with 617 additions and 1 deletion.
59 changes: 59 additions & 0 deletions .github/workflows/build_template_esp32s2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Reusable esp32s2-at workflow template

on:
workflow_call:
# parameters from upstream workflow
inputs:
module_name:
required: true
type: string
artifacts_name:
required: true
type: string
# parameters from upstream inherit
secrets:
ESP32S2_4MB_TOKEN:
required: false

jobs:
build-template-esp32s2:
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- uses: actions/[email protected]
with:
python-version: '3.10'
- name: Configure prerequisites
run: |
# set module information
mkdir build
echo -e "{\"platform\": \"PLATFORM_ESP32S2\", \"module\": \"${{ inputs.module_name }}\", \"silence\": 0}" > build/module_info.json
# update esp32s2 ota token
cd components/at/private_include
rm -f at_ota_token.h
echo -e "#pragma once" >> at_ota_token.h
echo -e "#define CONFIG_ESP_AT_OTA_TOKEN_ESP32S2_4MB \"${{ secrets.ESP32S2_4MB_TOKEN }}\"" >> at_ota_token.h
echo -e "#define CONFIG_ESP_AT_OTA_SSL_TOKEN_ESP32S2_4MB \"${{ secrets.ESP32S2_4MB_TOKEN }}\"" >> at_ota_token.h
cd -
- name: Install ESP-IDF environment variables
run: |
./build.py install
- name: Compile
run: |
./build.py build
- name: Upload artifacts
uses: actions/[email protected]
with:
name: ${{ inputs.artifacts_name }}
path: |
sdkconfig
build/*.bin
build/*.elf
build/*.map
build/bootloader/*.bin
build/partition_table/*.bin
build/customized_partitions/*
build/flasher_args.json
build/download.config
build/factory/*
7 changes: 7 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,10 @@ jobs:
module_name: ESP32C6-4MB
artifacts_name: esp32c6-4MB-at
secrets: inherit

build-esp32s2-4mb-at:
uses: ./.github/workflows/build_template_esp32s2.yml
with:
module_name: ESP32S2-4MB
artifacts_name: esp32s2-4MB-at
secrets: inherit
1 change: 1 addition & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@ include:
- '.gitlab/ci/build_esp32c2.yml'
- '.gitlab/ci/build_esp32c3.yml'
- '.gitlab/ci/build_esp32c6.yml'
- '.gitlab/ci/build_esp32s2.yml'
- '.gitlab/ci/deploy.yml'
- '.gitlab/ci/post_deploy.yml'
16 changes: 16 additions & 0 deletions .gitlab/ci/build_esp32s2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Build ESP32-S2 AT Firmwares

esp32s2_4mb_at:
extends:
- .build_template_esp32s2
- .rules:build:build_project
variables:
MODULE_NAME: "ESP32S2-4MB"

esp32s2_4mb_at_tat_debug:
extends:
- .build_template_esp32s2
- .before_script_enable_at_debugs
- .rules:build:build_project_on_protected
variables:
MODULE_NAME: "ESP32S2-4MB"
21 changes: 21 additions & 0 deletions .gitlab/ci/build_template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@
- echo -e "#define CONFIG_ESP_AT_OTA_SSL_TOKEN_ESP32C6_4MB \"$ESP32C6_4MB_TOKEN\"" >> at_ota_token.h
- cd -

.setup_tokens_esp32s2: &setup_tokens_esp32s2
- cd components/at/private_include
- rm -f at_ota_token.h
- echo -e "#define CONFIG_ESP_AT_OTA_TOKEN_ESP32S2_4MB \"$ESP32S2_4MB_TOKEN\"" >> at_ota_token.h
- echo -e "#define CONFIG_ESP_AT_OTA_SSL_TOKEN_ESP32S2_4MB \"$ESP32S2_4MB_TOKEN\"" >> at_ota_token.h
- cd -

#############################
# Update sdkconfig.defaults #
#############################
Expand Down Expand Up @@ -189,6 +196,12 @@
- add_gitlab_ssh_keys
- *setup_tokens_esp32c6

.before_script_esp32s2:
before_script:
- source ${CI_PROJECT_DIR}/.gitlab/ci/utils.sh
- add_gitlab_ssh_keys
- *setup_tokens_esp32s2

.before_script_enable_at_debugs:
before_script:
- source ${CI_PROJECT_DIR}/.gitlab/ci/utils.sh
Expand Down Expand Up @@ -304,3 +317,11 @@
variables:
PLATFORM: "PLATFORM_ESP32C6"
SILENCE: "0"

.build_template_esp32s2:
extends:
- .build_template
- .before_script_esp32s2
variables:
PLATFORM: "PLATFORM_ESP32S2"
SILENCE: "0"
2 changes: 1 addition & 1 deletion build.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
sys_cmd = 'export'
sys_delimiter = ':'

at_targets = ['esp32', 'esp32c2', 'esp32c3', 'esp32c6']
at_targets = ['esp32', 'esp32c2', 'esp32c3', 'esp32c6', 'esp32s2']
at_macro_pairs = []

def ESP_LOGI(x):
Expand Down
1 change: 1 addition & 0 deletions components/at/lib/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ ESP32: ca45add
ESP32C3: ca45add
ESP32C2: ca45add
ESP32C6: f33f3c8
ESP32S2: ca45add
Binary file added components/at/lib/libesp32s2_at_core.a
Binary file not shown.
Binary file added components/at/lib/libesp32s2_at_core_silence.a
Binary file not shown.
3 changes: 3 additions & 0 deletions components/at/private_include/at_ota_token.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,7 @@
#elif defined(CONFIG_IDF_TARGET_ESP32C6)
#define CONFIG_ESP_AT_OTA_TOKEN_ESP32C6_4MB CONFIG_ESP_AT_OTA_TOKEN_DEFAULT
#define CONFIG_ESP_AT_OTA_SSL_TOKEN_ESP32C6_4MB CONFIG_ESP_AT_OTA_SSL_TOKEN_DEFAULT
#elif defined(CONFIG_IDF_TARGET_ESP32S2)
#define CONFIG_ESP_AT_OTA_TOKEN_ESP32S2_4MB CONFIG_ESP_AT_OTA_TOKEN_DEFAULT
#define CONFIG_ESP_AT_OTA_SSL_TOKEN_ESP32S2_4MB CONFIG_ESP_AT_OTA_SSL_TOKEN_DEFAULT
#endif
4 changes: 4 additions & 0 deletions components/at/src/at_default_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ static const esp_at_module_info_t esp_at_module_info[] = {
#if defined(CONFIG_IDF_TARGET_ESP32C6)
{"ESP32C6-4MB", CONFIG_ESP_AT_OTA_TOKEN_ESP32C6_4MB, CONFIG_ESP_AT_OTA_SSL_TOKEN_ESP32C6_4MB},
#endif

#if defined(CONFIG_IDF_TARGET_ESP32S2)
{"ESP32S2-4MB", CONFIG_ESP_AT_OTA_TOKEN_ESP32S2_4MB, CONFIG_ESP_AT_OTA_SSL_TOKEN_ESP32S2_4MB},
#endif
};

static uint8_t esp_at_module_id = 0x0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ PLATFORM_ESP32C2,ESP32C2-2MB,"single Wi-Fi, 2MB, TX:7 RX:6",4,78,1,1,13,CN,11520
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
PLATFORM_ESP32S2,ESP32S2-4MB,"TX:17 RX:21",4,78,1,1,13,CN,115200,17,21,20,19
9 changes: 9 additions & 0 deletions main/interface/include/at_uart.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include "esp32c2/rom/uart.h"
#elif CONFIG_IDF_TARGET_ESP32C6
#include "esp32c6/rom/uart.h"
#elif CONFIG_IDF_TARGET_ESP32S2
#include "esp32s2/rom/uart.h"
#endif

/*******************************************************
Expand Down Expand Up @@ -80,6 +82,13 @@
#endif
#endif

#if defined(CONFIG_IDF_TARGET_ESP32S2)
#define CONFIG_AT_UART_PORT_TX_PIN_DEFAULT 17
#define CONFIG_AT_UART_PORT_RX_PIN_DEFAULT 21
#define CONFIG_AT_UART_PORT_CTS_PIN_DEFAULT 20
#define CONFIG_AT_UART_PORT_RTS_PIN_DEFAULT 19
#endif

/**
* @brief The uart configuration
*/
Expand Down
3 changes: 3 additions & 0 deletions module_config/module_esp32s2_default/IDF_VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
branch:release/v5.0
commit:bcca689866db3dfda47f77670bf8df2a7ec94721
repository:https://github.com/espressif/esp-idf.git
3 changes: 3 additions & 0 deletions module_config/module_esp32s2_default/at_customize.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Name, Type, SubType, Offset, Size
mfg_nvs, data, nvs, 0x21000, 112K
fatfs, data, fat, 0x70000, 576K
7 changes: 7 additions & 0 deletions module_config/module_esp32s2_default/partitions_at.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Name, Type, SubType, Offset, Size
phy_init, data, phy, 0xf000, 0x1000
otadata, data, ota, 0x10000, 8K
nvs, data, nvs, 0x12000, 56K
at_customize, 0x40, 0, 0x20000, 0xE0000
ota_0, app, ota_0, 0x100000, 0x180000
ota_1, app, ota_1, 0x280000, 0x180000
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
diff --git a/components/esp-tls/esp_tls_mbedtls.c b/components/esp-tls/esp_tls_mbedtls.c
index ce1d832b09..d796463e82 100644
--- a/components/esp-tls/esp_tls_mbedtls.c
+++ b/components/esp-tls/esp_tls_mbedtls.c
@@ -78,6 +78,17 @@ esp_err_t esp_create_mbedtls_handle(const char *hostname, size_t hostlen, const
mbedtls_ssl_config_init(&tls->conf);
mbedtls_entropy_init(&tls->entropy);

+ if ((ret = mbedtls_ctr_drbg_seed(&tls->ctr_drbg,
+ mbedtls_entropy_func, &tls->entropy, NULL, 0)) != 0) {
+ ESP_LOGE(TAG, "mbedtls_ctr_drbg_seed returned -0x%04X", -ret);
+ mbedtls_print_error_msg(ret);
+ ESP_INT_EVENT_TRACKER_CAPTURE(tls->error_handle, ESP_TLS_ERR_TYPE_MBEDTLS, -ret);
+ esp_ret = ESP_ERR_MBEDTLS_CTR_DRBG_SEED_FAILED;
+ goto exit;
+ }
+
+ mbedtls_ssl_conf_rng(&tls->conf, mbedtls_ctr_drbg_random, &tls->ctr_drbg);
+
if (tls->role == ESP_TLS_CLIENT) {
esp_ret = set_client_config(hostname, hostlen, (esp_tls_cfg_t *)cfg, tls);
if (esp_ret != ESP_OK) {
@@ -97,17 +108,6 @@ esp_err_t esp_create_mbedtls_handle(const char *hostname, size_t hostlen, const
#endif
}

- if ((ret = mbedtls_ctr_drbg_seed(&tls->ctr_drbg,
- mbedtls_entropy_func, &tls->entropy, NULL, 0)) != 0) {
- ESP_LOGE(TAG, "mbedtls_ctr_drbg_seed returned -0x%04X", -ret);
- mbedtls_print_error_msg(ret);
- ESP_INT_EVENT_TRACKER_CAPTURE(tls->error_handle, ESP_TLS_ERR_TYPE_MBEDTLS, -ret);
- esp_ret = ESP_ERR_MBEDTLS_CTR_DRBG_SEED_FAILED;
- goto exit;
- }
-
- mbedtls_ssl_conf_rng(&tls->conf, mbedtls_ctr_drbg_random, &tls->ctr_drbg);
-
#ifdef CONFIG_MBEDTLS_DEBUG
mbedtls_esp_enable_debug_log(&tls->conf, CONFIG_MBEDTLS_DEBUG_LEVEL);
#endif
123 changes: 123 additions & 0 deletions module_config/module_esp32s2_default/patch/fatfs_generation.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
diff --git a/components/fatfs/fatfs_utils/utils.py b/components/fatfs/fatfs_utils/utils.py
index e7d2e25a7f..ddc68c9225 100644
--- a/components/fatfs/fatfs_utils/utils.py
+++ b/components/fatfs/fatfs_utils/utils.py
@@ -1,14 +1,17 @@
# SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Apache-2.0
-
import argparse
import binascii
import os
import uuid
from datetime import datetime
-from typing import List, Optional, Tuple
+from typing import List
+from typing import Optional
+from typing import Tuple

-from construct import BitsInteger, BitStruct, Int16ul
+from construct import BitsInteger
+from construct import BitStruct
+from construct import Int16ul

FAT12_MAX_CLUSTERS: int = 4085
FAT16_MAX_CLUSTERS: int = 65525
@@ -200,6 +203,11 @@ def get_args_for_partition_generator(desc: str) -> argparse.Namespace:
Type of fat. Select 12 for fat12, 16 for fat16. Don't set, or set to 0 for automatic
calculation using cluster size and partition size.
""")
+ parser.add_argument('--wl_mode',
+ default=None,
+ type=str,
+ choices=['safe', 'perf'],
+ help='Wear levelling mode to use. Safe or performance. Only for sector size of 512')

args = parser.parse_args()
if args.fat_type == 0:
@@ -207,6 +215,9 @@ def get_args_for_partition_generator(desc: str) -> argparse.Namespace:
args.partition_size = int(str(args.partition_size), 0)
if not os.path.isdir(args.input_directory):
raise NotADirectoryError(f'The target directory `{args.input_directory}` does not exist!')
+ if args.wl_mode is not None:
+ if args.sector_size != 512:
+ raise ValueError('Wear levelling mode can be set only for sector size 512')
return args


diff --git a/components/fatfs/wl_fatfsgen.py b/components/fatfs/wl_fatfsgen.py
index b6c5dd4fe7..8881938f03 100755
--- a/components/fatfs/wl_fatfsgen.py
+++ b/components/fatfs/wl_fatfsgen.py
@@ -1,13 +1,19 @@
#!/usr/bin/env python
-# SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
+# SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Apache-2.0
+from typing import List
+from typing import Optional

-from typing import List, Optional
-
-from construct import Const, Int32ul, Struct
+from construct import Const
+from construct import Int32ul
+from construct import Struct
from fatfs_utils.exceptions import WLNotInitialized
-from fatfs_utils.utils import (FULL_BYTE, UINT32_MAX, FATDefaults, crc32, generate_4bytes_random,
- get_args_for_partition_generator)
+from fatfs_utils.utils import crc32
+from fatfs_utils.utils import FATDefaults
+from fatfs_utils.utils import FULL_BYTE
+from fatfs_utils.utils import generate_4bytes_random
+from fatfs_utils.utils import get_args_for_partition_generator
+from fatfs_utils.utils import UINT32_MAX
from fatfsgen import FATFS


@@ -55,6 +61,7 @@ class WLFATFS:
WL_STATE_HEADER_SIZE = 64
WL_STATE_COPY_COUNT = 2 # always 2 copies for power failure safety
WL_SECTOR_SIZE = 0x1000
+ WL_SAFE_MODE_DUMP_SECTORS = 2

WL_STATE_T_DATA = Struct(
'pos' / Int32ul,
@@ -99,7 +106,8 @@ class WLFATFS:
temp_buff_size: int = FATDefaults.TEMP_BUFFER_SIZE,
device_id: int = None,
root_entry_count: int = FATDefaults.ROOT_ENTRIES_COUNT,
- media_type: int = FATDefaults.MEDIA_TYPE) -> None:
+ media_type: int = FATDefaults.MEDIA_TYPE,
+ wl_mode: Optional[str] = None) -> None:
self._initialized = False
self._version = version
self._temp_buff_size = temp_buff_size
@@ -107,6 +115,7 @@ class WLFATFS:
self.partition_size = size
self.total_sectors = self.partition_size // FATDefaults.WL_SECTOR_SIZE
self.wl_state_size = WLFATFS.WL_STATE_HEADER_SIZE + WLFATFS.WL_STATE_RECORD_SIZE * self.total_sectors
+ self.wl_mode = wl_mode

# determine the number of required sectors (roundup to sector size)
self.wl_state_sectors = (self.wl_state_size + FATDefaults.WL_SECTOR_SIZE - 1) // FATDefaults.WL_SECTOR_SIZE
@@ -116,6 +125,9 @@ class WLFATFS:

wl_sectors = (WLFATFS.WL_DUMMY_SECTORS_COUNT + WLFATFS.WL_CFG_SECTORS_COUNT +
self.wl_state_sectors * WLFATFS.WL_STATE_COPY_COUNT)
+ if self.wl_mode is not None and self.wl_mode == 'safe':
+ wl_sectors += WLFATFS.WL_SAFE_MODE_DUMP_SECTORS
+
self.plain_fat_sectors = self.total_sectors - wl_sectors
self.plain_fatfs = FATFS(
explicit_fat_type=explicit_fat_type,
@@ -226,7 +238,8 @@ if __name__ == '__main__':
root_entry_count=args.root_entry_count,
explicit_fat_type=args.fat_type,
long_names_enabled=args.long_name_support,
- use_default_datetime=args.use_default_datetime)
+ use_default_datetime=args.use_default_datetime,
+ wl_mode=args.wl_mode)

wl_fatfs.wl_generate(args.input_directory)
wl_fatfs.init_wl()
13 changes: 13 additions & 0 deletions module_config/module_esp32s2_default/patch/patch_list.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
; Add your patches to the section below

[esp_tls_parse_ecc_key.patch]
path = esp-idf
note = "Fixed an issue where esp-tls is unable to parse ECC keys"

[fatfs_generation.patch]
path = esp-idf
note = "Fixed an issue where data read after writing fatfs partition more than 63 times might be incorrect"

[support_ext_partition.patch]
path = esp-idf
note = "[IDF-9560] Support to use partition table outside of the project directory"
Loading

0 comments on commit 63b9986

Please sign in to comment.