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

Merge branch 'feature/add_C3_rev3_support' into 'master'

Added support for ESP32-C3 Rev3

See merge request espressif/esp-serial-flasher!34
Martin Válik 4 лет назад
Родитель
Сommit
40ce22efee
2 измененных файлов с 23 добавлено и 14 удалено
  1. 14 10
      src/esp_targets.c
  2. 9 4
      test/test.cpp

+ 14 - 10
src/esp_targets.c

@@ -16,12 +16,14 @@
 #include "esp_targets.h"
 #include <stddef.h>
 
+#define MAX_MAGIC_VALUES 2
+
 typedef esp_loader_error_t (*read_spi_config_t)(uint32_t efuse_base, uint32_t *spi_config);
 
 typedef struct {
     target_registers_t regs;
     uint32_t efuse_base;
-    uint32_t chip_magic_value;
+    uint32_t chip_magic_value[MAX_MAGIC_VALUES];
     read_spi_config_t read_spi_config;
 } esp_target_t;
 
@@ -51,7 +53,7 @@ static const esp_target_t esp_target[ESP_MAX_CHIP] = {
             .miso_dlen  = 0,
         },
         .efuse_base = 0,            // Not used
-        .chip_magic_value  = 0xfff0c101,
+        .chip_magic_value  = { 0xfff0c101, 0 },
         .read_spi_config = NULL,    // Not used
     },
 
@@ -67,7 +69,7 @@ static const esp_target_t esp_target[ESP_MAX_CHIP] = {
             .miso_dlen = ESP32_SPI_REG_BASE + 0x2c,
         },
         .efuse_base = 0x3ff5A000,
-        .chip_magic_value  = 0x00f01d83,
+        .chip_magic_value  = { 0x00f01d83, 0 },
         .read_spi_config = spi_config_esp32,
     },
 
@@ -83,7 +85,7 @@ static const esp_target_t esp_target[ESP_MAX_CHIP] = {
             .miso_dlen = ESP32S2_SPI_REG_BASE + 0x28,
         },
         .efuse_base = 0x3f41A000,
-        .chip_magic_value  = 0x000007c6,
+        .chip_magic_value  = { 0x000007c6, 0 },
         .read_spi_config = spi_config_esp32xx,
     },
 
@@ -99,7 +101,7 @@ static const esp_target_t esp_target[ESP_MAX_CHIP] = {
             .miso_dlen = ESP32C3_SPI_REG_BASE + 0x28,
         },
         .efuse_base = 0x60008800,
-        .chip_magic_value = 0x6921506f,
+        .chip_magic_value = { 0x6921506f, 0x1b31506f },
         .read_spi_config = spi_config_esp32xx,
     },
 
@@ -115,7 +117,7 @@ static const esp_target_t esp_target[ESP_MAX_CHIP] = {
             .miso_dlen = ESP32C3_SPI_REG_BASE + 0x28,
         },
         .efuse_base = 0x60007000,
-        .chip_magic_value = 0x00000009,
+        .chip_magic_value = { 0x00000009, 0 },
         .read_spi_config = spi_config_esp32xx, // !
     },
 };
@@ -131,10 +133,12 @@ esp_loader_error_t loader_detect_chip(target_chip_t *target_chip, const target_r
     RETURN_ON_ERROR( esp_loader_read_register(CHIP_DETECT_MAGIC_REG_ADDR,  &magic_value) );
 
     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];
-            return ESP_LOADER_SUCCESS;
+        for(int index = 0; index < MAX_MAGIC_VALUES; index++) {
+            if (magic_value == esp_target[chip].chip_magic_value[index]) {
+                *target_chip = (target_chip_t)chip;
+                *target_data = (target_registers_t *)&esp_target[chip];
+                return ESP_LOADER_SUCCESS;
+            }
         }
     }
 

+ 9 - 4
test/test.cpp

@@ -119,12 +119,11 @@ map<target_chip_t, uint32_t> chip_magic_value = {
     {ESP32S3_CHIP,  0x00000009},
 };
 
-void queue_connect_response(target_chip_t target = ESP32_CHIP)
+void queue_connect_response(target_chip_t target = ESP32_CHIP, uint32_t magic_value = 0)
 {
     // Set magic value register used for detection of attached chip
     auto magic_value_response = read_reg_response;
-    magic_value_response.data.common.value = chip_magic_value[target];
-
+    magic_value_response.data.common.value = magic_value ? magic_value : chip_magic_value[target];
     clear_buffers();
     queue_response(sync_response);
     queue_response(magic_value_response);
@@ -201,6 +200,12 @@ TEST_CASE( "Can detect attached target" )
         REQUIRE( esp_loader_get_target() == ESP32C3_CHIP );
     }
 
+    SECTION( "Can detect ESP32C3 rev3" ) {
+        queue_connect_response(ESP32C3_CHIP, 0x1b31506f);
+        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) );
@@ -214,7 +219,7 @@ TEST_CASE( "Can detect attached target" )
     }
 
     SECTION( "Can detect unknown chip" ) {
-        queue_connect_response(ESP_UNKNOWN_CHIP);
+        queue_connect_response(ESP_UNKNOWN_CHIP, 0xaaaaaaaa);
         REQUIRE( esp_loader_connect(&connect_config) == ESP_LOADER_ERROR_INVALID_TARGET);
     }
 }