Просмотр исходного кода

Merge branch 'feature/support_esp32s3' into 'master'

Added support for ESP32-S3 and ESP32-C3

See merge request espressif/esp-serial-flasher!31
Martin Válik 4 лет назад
Родитель
Сommit
0d4aa086a1
6 измененных файлов с 71 добавлено и 11 удалено
  1. 2 1
      .gitlab-ci.yml
  2. 4 2
      include/esp_loader.h
  3. 40 5
      src/esp_targets.c
  4. 10 3
      src/serial_comm.c
  5. 1 0
      test/run_test.sh
  6. 14 0
      test/test.cpp

+ 2 - 1
.gitlab-ci.yml

@@ -33,11 +33,12 @@ before_script:
 
 build_with_idf:
   stage: build
-  image: ${CI_DOCKER_REGISTRY}/esp32-ci-env
+  image: $CI_DOCKER_REGISTRY/esp-env:v4.4-1
   tags:
     - build
     - internet
   script:
+    - source /opt/pyenv/activate && pyenv global 3.6.13
     - *clone_and_setup_idf
     - cd $CI_PROJECT_DIR/examples/esp32_example
     # Build for all supported targets

+ 4 - 2
include/esp_loader.h

@@ -56,8 +56,10 @@ typedef enum {
     ESP8266_CHIP = 0,
     ESP32_CHIP   = 1,
     ESP32S2_CHIP = 2,
-    ESP_MAX_CHIP = 3,
-    ESP_UNKNOWN_CHIP = 3 
+    ESP32C3_CHIP = 3,
+    ESP32S3_CHIP = 4,
+    ESP_MAX_CHIP = 5,
+    ESP_UNKNOWN_CHIP = 5
 } target_chip_t;
 
 /**

+ 40 - 5
src/esp_targets.c

@@ -30,10 +30,12 @@ typedef struct {
 
 #define ESP8266_SPI_REG_BASE 0x60000200
 #define ESP32S2_SPI_REG_BASE 0x3f402000
+#define ESP32C3_SPI_REG_BASE 0x60002000
+#define ESP32S3_SPI_REG_BASE 0x60002000
 #define ESP32_SPI_REG_BASE   0x3ff42000
 
 static esp_loader_error_t spi_config_esp32(uint32_t efuse_base, uint32_t *spi_config);
-static esp_loader_error_t spi_config_esp32s2(uint32_t efuse_base, uint32_t *spi_config);
+static esp_loader_error_t spi_config_esp32xx(uint32_t efuse_base, uint32_t *spi_config);
 
 static const esp_target_t esp_target[ESP_MAX_CHIP] = {
 
@@ -82,8 +84,40 @@ static const esp_target_t esp_target[ESP_MAX_CHIP] = {
         },
         .efuse_base = 0x3f41A000,
         .chip_magic_value  = 0x000007c6,
-        .read_spi_config = spi_config_esp32s2,
-    }
+        .read_spi_config = spi_config_esp32xx,
+    },
+
+    // ESP32C3
+    {
+        .regs = {
+            .cmd  = ESP32C3_SPI_REG_BASE + 0x00,
+            .usr  = ESP32C3_SPI_REG_BASE + 0x18,
+            .usr1 = ESP32C3_SPI_REG_BASE + 0x1c,
+            .usr2 = ESP32C3_SPI_REG_BASE + 0x20,
+            .w0   = ESP32C3_SPI_REG_BASE + 0x58,
+            .mosi_dlen = ESP32C3_SPI_REG_BASE + 0x24,
+            .miso_dlen = ESP32C3_SPI_REG_BASE + 0x28,
+        },
+        .efuse_base = 0x60008800,
+        .chip_magic_value = 0x6921506f,
+        .read_spi_config = spi_config_esp32xx,
+    },
+
+    // ESP32S3
+    {
+        .regs = {
+            .cmd  = ESP32C3_SPI_REG_BASE + 0x00,
+            .usr  = ESP32C3_SPI_REG_BASE + 0x18,
+            .usr1 = ESP32C3_SPI_REG_BASE + 0x1c,
+            .usr2 = ESP32C3_SPI_REG_BASE + 0x20,
+            .w0   = ESP32C3_SPI_REG_BASE + 0x58,
+            .mosi_dlen = ESP32C3_SPI_REG_BASE + 0x24,
+            .miso_dlen = ESP32C3_SPI_REG_BASE + 0x28,
+        },
+        .efuse_base = 0x60007000,
+        .chip_magic_value = 0x00000009,
+        .read_spi_config = spi_config_esp32xx, // !
+    },
 };
 
 const target_registers_t *get_esp_target_data(target_chip_t chip)
@@ -99,7 +133,7 @@ esp_loader_error_t loader_detect_chip(target_chip_t *target_chip, const target_r
     for (int chip = 0; chip < ESP_MAX_CHIP; chip++) {
         if (magic_value == esp_target[chip].chip_magic_value) {
             *target_chip = (target_chip_t)chip;
-            *target_data = (target_registers_t*)&esp_target[chip];
+            *target_data = (target_registers_t *)&esp_target[chip];
             return ESP_LOADER_SUCCESS;
         }
     }
@@ -154,7 +188,8 @@ static esp_loader_error_t spi_config_esp32(uint32_t efuse_base, uint32_t *spi_co
     return ESP_LOADER_SUCCESS;
 }
 
-static esp_loader_error_t spi_config_esp32s2(uint32_t efuse_base, uint32_t *spi_config)
+// Applies for esp32s2, esp32c3 and esp32c3
+static esp_loader_error_t spi_config_esp32xx(uint32_t efuse_base, uint32_t *spi_config)
 {
     *spi_config = 0;
 

+ 10 - 3
src/serial_comm.c

@@ -236,6 +236,13 @@ static esp_loader_error_t check_response(command_t cmd, uint32_t *reg_value, voi
     return ESP_LOADER_SUCCESS;
 }
 
+static inline uint32_t encryption_field_size(target_chip_t target)
+{
+    return (target == ESP32S2_CHIP || 
+            target == ESP32C3_CHIP || 
+            target == ESP32S3_CHIP) ? 0 : sizeof(uint32_t);
+}
+
 
 esp_loader_error_t loader_flash_begin_cmd(uint32_t offset,
                                           uint32_t erase_size,
@@ -243,13 +250,13 @@ esp_loader_error_t loader_flash_begin_cmd(uint32_t offset,
                                           uint32_t blocks_to_write,
                                           target_chip_t target)
 {
-    size_t removeEncryption = target == ESP32S2_CHIP ? 0 : sizeof(uint32_t);
+    uint32_t encryption_size = encryption_field_size(target);
 
     begin_command_t begin_cmd = {
         .common = {
             .direction = WRITE_DIRECTION,
             .command = FLASH_BEGIN,
-            .size = CMD_SIZE(begin_cmd) - removeEncryption,
+            .size = CMD_SIZE(begin_cmd) - encryption_size,
             .checksum = 0
         },
         .erase_size = erase_size,
@@ -261,7 +268,7 @@ esp_loader_error_t loader_flash_begin_cmd(uint32_t offset,
 
     s_sequence_number = 0;
 
-    return send_cmd(&begin_cmd.common, sizeof(begin_cmd) - removeEncryption, NULL);
+    return send_cmd(&begin_cmd, sizeof(begin_cmd) - encryption_size, NULL);
 }
 
 

+ 1 - 0
test/run_test.sh

@@ -1,5 +1,6 @@
 #!/bin/bash
 
+set -e
 mkdir -p build && cd build
 
 if [ "$1" = "host" ]; then

+ 14 - 0
test/test.cpp

@@ -115,6 +115,8 @@ map<target_chip_t, uint32_t> chip_magic_value = {
     {ESP8266_CHIP,  0xfff0c101},
     {ESP32_CHIP,    0x00f01d83},
     {ESP32S2_CHIP,  0x000007c6},
+    {ESP32C3_CHIP,  0x6921506f},
+    {ESP32S3_CHIP,  0x00000009},
 };
 
 void queue_connect_response(target_chip_t target = ESP32_CHIP)
@@ -193,6 +195,18 @@ TEST_CASE( "Can detect attached target" )
         REQUIRE( esp_loader_get_target() == ESP32S2_CHIP );
     }
 
+    SECTION( "Can detect ESP32C3" ) {
+        queue_connect_response(ESP32C3_CHIP);
+        REQUIRE_SUCCESS( esp_loader_connect(&connect_config) );
+        REQUIRE( esp_loader_get_target() == ESP32C3_CHIP );
+    }
+
+    SECTION( "Can detect ESP32S3" ) {
+        queue_connect_response(ESP32S3_CHIP);
+        REQUIRE_SUCCESS( esp_loader_connect(&connect_config) );
+        REQUIRE( esp_loader_get_target() == ESP32S3_CHIP );
+    }
+
     SECTION( "Can detect ESP8266" ) {
         queue_connect_response(ESP8266_CHIP);
         REQUIRE_SUCCESS( esp_loader_connect(&connect_config) );