Kaynağa Gözat

Added spi pin config support

Martin Valik 5 yıl önce
ebeveyn
işleme
4a48ce1114

+ 12 - 3
CMakeLists.txt

@@ -3,8 +3,13 @@ cmake_minimum_required(VERSION 3.5)
 if (DEFINED ESP_PLATFORM)
 if (DEFINED ESP_PLATFORM)
 
 
     # Register component to esp-idf build system
     # Register component to esp-idf build system
-    set(COMPONENT_SRCS src/esp_loader.c src/serial_comm.c src/md5_hash.c port/esp32_port.c)
-    set(COMPONENT_ADD_INCLUDEDIRS "include" "port")
+    set(COMPONENT_SRCS
+        src/esp_loader.c
+        src/esp_targets.c
+        src/serial_comm.c
+        src/md5_hash.c
+        port/esp32_port.c)
+    set(COMPONENT_ADD_INCLUDEDIRS "include port")
     set(COMPONENT_PRIV_INCLUDEDIRS "private_include" )
     set(COMPONENT_PRIV_INCLUDEDIRS "private_include" )
     register_component()
     register_component()
     component_compile_options(-Wstrict-prototypes)
     component_compile_options(-Wstrict-prototypes)
@@ -13,7 +18,11 @@ if (DEFINED ESP_PLATFORM)
 else()
 else()
 
 
     # Create traditional CMake target
     # Create traditional CMake target
-    add_library(flasher src/esp_loader.c src/serial_comm.c src/md5_hash.c)
+    add_library(flasher 
+        src/esp_loader.c
+        src/esp_targets.c
+        src/serial_comm.c
+        src/md5_hash.c)
 
 
     target_include_directories(flasher PUBLIC include port PRIVATE private_include)
     target_include_directories(flasher PUBLIC include port PRIVATE private_include)
 
 

+ 11 - 14
include/esp_loader.h

@@ -22,6 +22,17 @@
 extern "C" {
 extern "C" {
 #endif
 #endif
 
 
+/**
+ * Macro which can be used to check the error code,
+ * and return in case the code is not ESP_LOADER_SUCCESS.
+ */
+#define RETURN_ON_ERROR(x) do {         \
+    esp_loader_error_t _err_ = (x);     \
+    if (_err_ != ESP_LOADER_SUCCESS) {  \
+        return _err_;                   \
+    }                                   \
+} while(0)
+
 /**
 /**
  * @brief Error codes
  * @brief Error codes
  */
  */
@@ -71,25 +82,11 @@ typedef struct {
     uint32_t sync_timeout;  /*!< Maximum time to wait for response from serial interface. */
     uint32_t sync_timeout;  /*!< Maximum time to wait for response from serial interface. */
     int32_t trials;         /*!< Number of trials to connect to target. If greater than 1,
     int32_t trials;         /*!< Number of trials to connect to target. If greater than 1,
                                100 millisecond delay is inserted after each try. */
                                100 millisecond delay is inserted after each try. */
-    esp_loader_spi_config_t spi_pin_config;  /*!< Determine which SPI peripheral and pins should be used to
-                                                connect to SPI flash. By setting spi_pin_config.val to zero,
-                                                default configuration will be used. For more detailed
-                                                information refer to serial protocol of esptool */
 } esp_loader_connect_args_t;
 } esp_loader_connect_args_t;
 
 
 #define ESP_LOADER_CONNECT_DEFAULT() { \
 #define ESP_LOADER_CONNECT_DEFAULT() { \
   .sync_timeout = 100, \
   .sync_timeout = 100, \
   .trials = 10, \
   .trials = 10, \
-  .spi_pin_config = { .val = 0 } \
-}
-
-#define ESP_LOADER_SPI_CONFIG_ESP32PICOD4() (esp_loader_spi_config_t) { \
-  .pin_hd = 11, \
-  .pin_cs = 16, \
-  .pin_d = 8,   \
-  .pin_q = 17,  \
-  .pin_clk = 6, \
-  .zero = 0     \
 }
 }
 
 
 /**
 /**

+ 32 - 0
private_include/esp_targets.h

@@ -0,0 +1,32 @@
+/* Copyright 2020 Espressif Systems (Shanghai) PTE LTD
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <stdint.h>
+#include "esp_loader.h"
+
+typedef struct {
+    uint32_t cmd;
+    uint32_t usr;
+    uint32_t usr1;
+    uint32_t usr2;
+    uint32_t w0;
+    uint32_t mosi_dlen;
+    uint32_t miso_dlen;
+} target_registers_t;
+
+esp_loader_error_t loader_detect_chip(target_chip_t *target, const target_registers_t **regs);
+esp_loader_error_t loader_read_spi_config(target_chip_t target_chip, uint32_t *spi_config);

+ 0 - 11
private_include/serial_comm.h

@@ -23,17 +23,6 @@
 extern "C" {
 extern "C" {
 #endif
 #endif
 
 
-/**
- * Macro which can be used to check the error code,
- * and return in case the code is not ESP_LOADER_SUCCESS.
- */
-#define RETURN_ON_ERROR(x) do {         \
-    esp_loader_error_t _err_ = (x);     \
-    if (_err_ != ESP_LOADER_SUCCESS) {  \
-        return _err_;                   \
-    }                                   \
-} while(0)
-
 esp_loader_error_t loader_flash_begin_cmd(uint32_t offset, uint32_t erase_size, uint32_t block_size, uint32_t blocks_to_write, target_chip_t target);
 esp_loader_error_t loader_flash_begin_cmd(uint32_t offset, uint32_t erase_size, uint32_t block_size, uint32_t blocks_to_write, target_chip_t target);
 
 
 esp_loader_error_t loader_flash_data_cmd(const uint8_t *data, uint32_t size);
 esp_loader_error_t loader_flash_data_cmd(const uint8_t *data, uint32_t size);

+ 6 - 98
src/esp_loader.c

@@ -17,6 +17,7 @@
 #include "serial_comm.h"
 #include "serial_comm.h"
 #include "serial_io.h"
 #include "serial_io.h"
 #include "esp_loader.h"
 #include "esp_loader.h"
+#include "esp_targets.h"
 #include "md5_hash.h"
 #include "md5_hash.h"
 #include <string.h>
 #include <string.h>
 #include <assert.h>
 #include <assert.h>
@@ -50,83 +51,9 @@ typedef enum {
     SPI_FLASH_READ_ID = 0x9F
     SPI_FLASH_READ_ID = 0x9F
 } spi_flash_cmd_t;
 } spi_flash_cmd_t;
 
 
-typedef struct {
-    uint32_t cmd;
-    uint32_t usr;
-    uint32_t usr1;
-    uint32_t usr2;
-    uint32_t w0;
-    uint32_t mosi_dlen;
-    uint32_t miso_dlen;
-} target_registers_t;
-
-typedef struct {
-    uint32_t reg_1;
-    uint32_t reg_2;
-} date_registers_t;
-
-
-static const uint32_t UART_DATE_REG_ADDR  = 0x60000078;   // used to differentiate ESP8266 vs ESP32*
-static const uint32_t UART_DATE_REG2_ADDR = 0x3f400074;   // used to differentiate ESP32-S2 vs other models
-
-#define ESP8266_SPI_REG_BASE 0x60000200
-#define ESP32S2_SPI_REG_BASE 0x3f402000
-#define ESP32_SPI_REG_BASE   0x60002000
-
-static const target_registers_t registers[ESP_MAX_CHIP] = {
-    // ESP8266
-    {
-        .cmd  = ESP8266_SPI_REG_BASE + 0x00,
-        .usr  = ESP8266_SPI_REG_BASE + 0x1c,
-        .usr1 = ESP8266_SPI_REG_BASE + 0x20,
-        .usr2 = ESP8266_SPI_REG_BASE + 0x24,
-        .w0   = ESP8266_SPI_REG_BASE + 0x40,
-        .mosi_dlen = 0,
-        .miso_dlen = 0,
-    },
-    // ESP32
-    {
-        .cmd  = ESP32_SPI_REG_BASE + 0x00,
-        .usr  = ESP32_SPI_REG_BASE + 0x1c,
-        .usr1 = ESP32_SPI_REG_BASE + 0x20,
-        .usr2 = ESP32_SPI_REG_BASE + 0x24,
-        .w0   = ESP32_SPI_REG_BASE + 0x80,
-        .mosi_dlen = ESP32_SPI_REG_BASE + 0x28,
-        .miso_dlen = ESP32_SPI_REG_BASE + 0x2c,
-    },
-    // ESP32S2
-    {
-        .cmd  = ESP32S2_SPI_REG_BASE + 0x00,
-        .usr  = ESP32S2_SPI_REG_BASE + 0x18,
-        .usr1 = ESP32S2_SPI_REG_BASE + 0x1c,
-        .usr2 = ESP32S2_SPI_REG_BASE + 0x20,
-        .w0   = ESP32S2_SPI_REG_BASE + 0x58,
-        .mosi_dlen = ESP32S2_SPI_REG_BASE + 0x24,
-        .miso_dlen = ESP32S2_SPI_REG_BASE + 0x28,
-    }
-};
-
 static uint32_t s_flash_write_size = 0;
 static uint32_t s_flash_write_size = 0;
+static const target_registers_t *s_reg = NULL;
 static target_chip_t s_target = ESP_UNKNOWN_CHIP;
 static target_chip_t s_target = ESP_UNKNOWN_CHIP;
-static const target_registers_t *s_reg = &registers[ESP32S2_CHIP];
-
-static const date_registers_t s_date_regs[ESP_MAX_CHIP] = {
-    // ESP8266
-    {
-        .reg_1 = 0x00062000,
-        .reg_2 = 0,
-    },
-    // ESP32
-    {
-        .reg_1 = 0x15122500,
-        .reg_2 = 0,
-    },
-    // ESP32S2
-    {
-        .reg_1 = 0x00000500,
-        .reg_2 = 0x19031400,
-    }
-};
 
 
 #if MD5_ENABLED
 #if MD5_ENABLED
 
 
@@ -167,27 +94,9 @@ static uint32_t timeout_per_mb(uint32_t size_bytes, uint32_t time_per_mb)
     return MAX(timeout, DEFAULT_FLASH_TIMEOUT);
     return MAX(timeout, DEFAULT_FLASH_TIMEOUT);
 }
 }
 
 
-static esp_loader_error_t detect_chip(target_chip_t *target)
-{
-    uint32_t reg_1, reg_2;
-
-    RETURN_ON_ERROR( esp_loader_read_register(UART_DATE_REG_ADDR,  &reg_1) );
-    RETURN_ON_ERROR( esp_loader_read_register(UART_DATE_REG2_ADDR, &reg_2) );
-
-    for (int chip = 0; chip < ESP_MAX_CHIP; chip++) {
-        const date_registers_t *r = &s_date_regs[chip];
-        if (r->reg_1 == reg_1 && (r->reg_2 == 0 || r->reg_2 == reg_2)) {
-            *target = (target_chip_t)chip;
-            return ESP_LOADER_SUCCESS;
-        }
-    }
-
-    return ESP_LOADER_ERROR_INVALID_TARGET;
-}
-
-
 esp_loader_error_t esp_loader_connect(esp_loader_connect_args_t *connect_args)
 esp_loader_error_t esp_loader_connect(esp_loader_connect_args_t *connect_args)
 {
 {
+    uint32_t spi_config;
     esp_loader_error_t err;
     esp_loader_error_t err;
     int32_t trials = connect_args->trials;
     int32_t trials = connect_args->trials;
 
 
@@ -206,15 +115,14 @@ esp_loader_error_t esp_loader_connect(esp_loader_connect_args_t *connect_args)
         }
         }
     } while (err != ESP_LOADER_SUCCESS);
     } while (err != ESP_LOADER_SUCCESS);
 
 
-    RETURN_ON_ERROR( detect_chip(&s_target) );
-
-    s_reg = &registers[s_target];
+    RETURN_ON_ERROR( loader_detect_chip(&s_target, &s_reg) );
 
 
     if (s_target == ESP8266_CHIP) {
     if (s_target == ESP8266_CHIP) {
         err = loader_flash_begin_cmd(0, 0, 0, 0, s_target);
         err = loader_flash_begin_cmd(0, 0, 0, 0, s_target);
     } else {
     } else {
+        RETURN_ON_ERROR( loader_read_spi_config(s_target, &spi_config) );
         loader_port_start_timer(DEFAULT_TIMEOUT);
         loader_port_start_timer(DEFAULT_TIMEOUT);
-        err = loader_spi_attach_cmd(connect_args->spi_pin_config.val);
+        err = loader_spi_attach_cmd(spi_config);
     }
     }
 
 
     return err;
     return err;

+ 173 - 0
src/esp_targets.c

@@ -0,0 +1,173 @@
+/* Copyright 2020 Espressif Systems (Shanghai) PTE LTD
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "esp_targets.h"
+#include <stddef.h>
+
+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;
+    read_spi_config_t read_spi_config;
+} esp_target_t;
+
+// This ROM address has a different value on each chip model
+#define CHIP_DETECT_MAGIC_REG_ADDR 0x40001000
+
+#define ESP8266_SPI_REG_BASE 0x60000200
+#define ESP32S2_SPI_REG_BASE 0x3f402000
+#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 const esp_target_t esp_target[ESP_MAX_CHIP] = {
+
+    // ESP8266
+    {
+        .regs = {
+            .cmd  = ESP8266_SPI_REG_BASE + 0x00,
+            .usr  = ESP8266_SPI_REG_BASE + 0x1c,
+            .usr1 = ESP8266_SPI_REG_BASE + 0x20,
+            .usr2 = ESP8266_SPI_REG_BASE + 0x24,
+            .w0   = ESP8266_SPI_REG_BASE + 0x40,
+            .mosi_dlen  = 0,
+            .miso_dlen  = 0,
+        },
+        .efuse_base = 0,            // Not used
+        .chip_magic_value  = 0xfff0c101,
+        .read_spi_config = NULL,    // Not used
+    },
+
+    // ESP32
+    {
+        .regs = {
+            .cmd  = ESP32_SPI_REG_BASE + 0x00,
+            .usr  = ESP32_SPI_REG_BASE + 0x1c,
+            .usr1 = ESP32_SPI_REG_BASE + 0x20,
+            .usr2 = ESP32_SPI_REG_BASE + 0x24,
+            .w0   = ESP32_SPI_REG_BASE + 0x80,
+            .mosi_dlen = ESP32_SPI_REG_BASE + 0x28,
+            .miso_dlen = ESP32_SPI_REG_BASE + 0x2c,
+        },
+        .efuse_base = 0x3ff5A000,
+        .chip_magic_value  = 0x00f01d83,
+        .read_spi_config = spi_config_esp32,
+    },
+
+    // ESP32S2
+    {
+        .regs = {
+            .cmd  = ESP32S2_SPI_REG_BASE + 0x00,
+            .usr  = ESP32S2_SPI_REG_BASE + 0x18,
+            .usr1 = ESP32S2_SPI_REG_BASE + 0x1c,
+            .usr2 = ESP32S2_SPI_REG_BASE + 0x20,
+            .w0   = ESP32S2_SPI_REG_BASE + 0x58,
+            .mosi_dlen = ESP32S2_SPI_REG_BASE + 0x24,
+            .miso_dlen = ESP32S2_SPI_REG_BASE + 0x28,
+        },
+        .efuse_base = 0x3f41A000,
+        .chip_magic_value  = 0x000007c6,
+        .read_spi_config = spi_config_esp32s2,
+    }
+};
+
+const target_registers_t *get_esp_target_data(target_chip_t chip)
+{
+    return (target_registers_t *)&esp_target[chip];
+}
+
+esp_loader_error_t loader_detect_chip(target_chip_t *target_chip, const target_registers_t **target_data)
+{
+    uint32_t magic_value;
+    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;
+        }
+    }
+
+    return ESP_LOADER_ERROR_INVALID_TARGET;
+}
+
+esp_loader_error_t loader_read_spi_config(target_chip_t target_chip, uint32_t *spi_config)
+{
+    const esp_target_t *target = &esp_target[target_chip];
+    return target->read_spi_config(target->efuse_base, spi_config);
+}
+
+static inline uint32_t efuse_word_addr(uint32_t efuse_base, uint32_t n)
+{
+    return efuse_base + (n * 4);
+}
+
+// 30->GPIO32 | 31->GPIO33
+static inline uint8_t adjust_pin_number(uint8_t num)
+{
+    return (num >= 30) ? num + 2 : num;
+}
+
+
+static esp_loader_error_t spi_config_esp32(uint32_t efuse_base, uint32_t *spi_config)
+{
+    *spi_config = 0;
+
+    uint32_t reg5, reg3;
+    RETURN_ON_ERROR( esp_loader_read_register(efuse_word_addr(efuse_base, 5), &reg5) );
+    RETURN_ON_ERROR( esp_loader_read_register(efuse_word_addr(efuse_base, 3), &reg3) );
+
+    uint32_t pins = reg5 & 0xfffff;
+
+    if (pins == 0 || pins == 0xfffff) {
+        return ESP_LOADER_SUCCESS;
+    }
+
+    uint8_t clk = adjust_pin_number( (pins >> 0)  & 0x1f );
+    uint8_t q   = adjust_pin_number( (pins >> 5)  & 0x1f );
+    uint8_t d   = adjust_pin_number( (pins >> 10) & 0x1f );
+    uint8_t cs  = adjust_pin_number( (pins >> 15) & 0x1f );
+    uint8_t hd  = adjust_pin_number( (reg3 >> 4)  & 0x1f );
+
+    if (clk == cs || clk == d || clk == q || q == cs || q == d || q == d) {
+        return ESP_LOADER_SUCCESS;
+    }
+
+    *spi_config = (hd << 24) | (cs << 18) | (d << 12) | (q << 6) | clk;
+
+    return ESP_LOADER_SUCCESS;
+}
+
+static esp_loader_error_t spi_config_esp32s2(uint32_t efuse_base, uint32_t *spi_config)
+{
+    *spi_config = 0;
+
+    uint32_t reg1, reg2;
+    RETURN_ON_ERROR( esp_loader_read_register(efuse_word_addr(efuse_base, 18), &reg1) );
+    RETURN_ON_ERROR( esp_loader_read_register(efuse_word_addr(efuse_base, 19), &reg2) );
+
+    uint32_t pins = ((reg1 >> 16) | ((reg2 & 0xfffff) << 16)) & 0x3fffffff;
+
+    if (pins == 0 || pins == 0xffffffff) {
+        return ESP_LOADER_SUCCESS;
+    }
+
+    *spi_config = pins;
+    return ESP_LOADER_SUCCESS;
+}

+ 6 - 1
test/CMakeLists.txt

@@ -1,7 +1,12 @@
 cmake_minimum_required(VERSION 3.5)
 cmake_minimum_required(VERSION 3.5)
 project(serial_flasher_test)
 project(serial_flasher_test)
 
 
-add_executable( ${PROJECT_NAME} test_main.cpp ../src/serial_comm.c ../src/esp_loader.c ../src/md5_hash.c )
+add_executable( ${PROJECT_NAME}
+	test_main.cpp
+	../src/serial_comm.c
+	../src/esp_loader.c
+	../src/md5_hash.c
+	../src/esp_targets.c )
 
 
 target_include_directories(${PROJECT_NAME} PRIVATE ../include ../private_include ../test ../port)
 target_include_directories(${PROJECT_NAME} PRIVATE ../include ../private_include ../test ../port)
 
 

+ 0 - 1
test/loader_config_user.h

@@ -1 +0,0 @@
-#pragma once

+ 25 - 14
test/test.cpp

@@ -22,6 +22,7 @@
 #include <string.h>
 #include <string.h>
 #include <stdio.h>
 #include <stdio.h>
 #include <array>
 #include <array>
+#include <map>
 #include <iostream>
 #include <iostream>
 #include <algorithm>
 #include <algorithm>
 
 
@@ -110,30 +111,40 @@ struct __attribute__((packed)) write_reg_cmd_response {
     uint8_t delimiter_2 = 0xc0;
     uint8_t delimiter_2 = 0xc0;
 };
 };
 
 
+map<target_chip_t, uint32_t> chip_magic_value = {
+    {ESP8266_CHIP,  0xfff0c101},
+    {ESP32_CHIP,    0x00f01d83},
+    {ESP32S2_CHIP,  0x000007c6},
+};
 
 
-void queue_connect_response(uint32_t date_reg_1 = 0x15122500,
-                            uint32_t date_reg_2 = 0, 
-                            target_chip_t target = ESP32_CHIP)
+void queue_connect_response(target_chip_t target = ESP32_CHIP)
 {
 {
-    // Set date registers used for detection of attached chip
-    auto uart_date_reg_1 = read_reg_response;
-    auto uart_date_reg_2 = read_reg_response;
-    uart_date_reg_1.data.common.value = date_reg_1;
-    uart_date_reg_2.data.common.value = date_reg_2;
+    // 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];
 
 
     clear_buffers();
     clear_buffers();
     queue_response(sync_response);
     queue_response(sync_response);
-    queue_response(uart_date_reg_1);
-    queue_response(uart_date_reg_2);
+    queue_response(magic_value_response);
 
 
     if (target == ESP8266_CHIP) {
     if (target == ESP8266_CHIP) {
         queue_response(flash_begin_response);
         queue_response(flash_begin_response);
     } else {
     } else {
+        auto efuse_pin_config_reg_1 = read_reg_response;
+        auto efuse_pin_config_reg_2 = read_reg_response;
+
+        queue_response(efuse_pin_config_reg_1);
+        queue_response(efuse_pin_config_reg_2);
         queue_response(attach_response);
         queue_response(attach_response);
     }
     }
 
 
 }
 }
 
 
+TEST_CASE( "chip_magic_value contains all supported chips " )
+{
+    REQUIRE( chip_magic_value.size() ==  ESP_MAX_CHIP );
+}
+
 TEST_CASE( "Can connect within specified time " )
 TEST_CASE( "Can connect within specified time " )
 {
 {
     queue_connect_response();
     queue_connect_response();
@@ -171,25 +182,25 @@ TEST_CASE( "Can detect attached target" )
     esp_loader_connect_args_t connect_config = ESP_LOADER_CONNECT_DEFAULT();
     esp_loader_connect_args_t connect_config = ESP_LOADER_CONNECT_DEFAULT();
 
 
     SECTION( "Can detect ESP32" ) {
     SECTION( "Can detect ESP32" ) {
-        queue_connect_response(0x15122500, 0);
+        queue_connect_response(ESP32_CHIP);
         REQUIRE_SUCCESS( esp_loader_connect(&connect_config) );
         REQUIRE_SUCCESS( esp_loader_connect(&connect_config) );
         REQUIRE( esp_loader_get_target() == ESP32_CHIP );
         REQUIRE( esp_loader_get_target() == ESP32_CHIP );
     }
     }
 
 
     SECTION( "Can detect ESP32S2" ) {
     SECTION( "Can detect ESP32S2" ) {
-        queue_connect_response(0x00000500, 0x19031400);
+        queue_connect_response(ESP32S2_CHIP);
         REQUIRE_SUCCESS( esp_loader_connect(&connect_config) );
         REQUIRE_SUCCESS( esp_loader_connect(&connect_config) );
         REQUIRE( esp_loader_get_target() == ESP32S2_CHIP );
         REQUIRE( esp_loader_get_target() == ESP32S2_CHIP );
     }
     }
 
 
     SECTION( "Can detect ESP8266" ) {
     SECTION( "Can detect ESP8266" ) {
-        queue_connect_response(0x00062000, 0, ESP8266_CHIP);
+        queue_connect_response(ESP8266_CHIP);
         REQUIRE_SUCCESS( esp_loader_connect(&connect_config) );
         REQUIRE_SUCCESS( esp_loader_connect(&connect_config) );
         REQUIRE( esp_loader_get_target() == ESP8266_CHIP );
         REQUIRE( esp_loader_get_target() == ESP8266_CHIP );
     }
     }
 
 
     SECTION( "Can detect unknown chip" ) {
     SECTION( "Can detect unknown chip" ) {
-        queue_connect_response(0xaa, 0xbb);
+        queue_connect_response(ESP_UNKNOWN_CHIP);
         REQUIRE( esp_loader_connect(&connect_config) == ESP_LOADER_ERROR_INVALID_TARGET);
         REQUIRE( esp_loader_connect(&connect_config) == ESP_LOADER_ERROR_INVALID_TARGET);
     }
     }
 }
 }