Преглед изворни кода

fix(protocol): Fix SYNC packet response reception

This fixes an issue where the SYNC packet response was only received
once instead of 8 times. This issue was masked by buffering on ESP32,
Zephyr and Raspberry ports where subsequent packets were delayed,
however on ports without buffering like the STM32 port, this resulted in
communication errors.
Djordje Nedic пре 2 година
родитељ
комит
22a6a8a092
3 измењених фајлова са 17 додато и 4 уклоњено
  1. 1 1
      idf_component.yml
  2. 7 1
      src/protocol_uart.c
  3. 9 2
      test/test.cpp

+ 1 - 1
idf_component.yml

@@ -1,3 +1,3 @@
-version: "0.4.2"
+version: "0.4.3"
 description: Serial flasher component provides portable library for flashing or loading ram loadble app to Espressif SoCs from other host microcontroller
 url: https://github.com/espressif/esp-serial-flasher

+ 7 - 1
src/protocol_uart.c

@@ -51,7 +51,13 @@ esp_loader_error_t send_cmd(const void *cmd_data, uint32_t size, uint32_t *reg_v
     RETURN_ON_ERROR( SLIP_send((const uint8_t *)cmd_data, size) );
     RETURN_ON_ERROR( SLIP_send_delimiter() );
 
-    return check_response(command, reg_value, &response, sizeof(response));
+    const uint8_t response_cnt = command == SYNC ? 8 : 1;
+    
+    for (uint8_t recv_cnt = 0; recv_cnt < response_cnt; recv_cnt++) {
+        RETURN_ON_ERROR(check_response(command, reg_value, &response, sizeof(response)));
+    }
+
+    return ESP_LOADER_SUCCESS;
 }
 
 

+ 9 - 2
test/test.cpp

@@ -128,7 +128,11 @@ void queue_connect_response(target_chip_t target = ESP32_CHIP, uint32_t magic_va
     auto magic_value_response = read_reg_response;
     magic_value_response.data.common.value = magic_value ? magic_value : chip_magic_value[target];
     clear_buffers();
-    queue_response(sync_response);
+
+    for (uint8_t resp = 0; resp < 8; resp++) {
+        queue_response(sync_response);
+    }
+    
     queue_response(magic_value_response);
 
     if (target == ESP8266_CHIP) {
@@ -323,7 +327,10 @@ TEST_CASE( "Sync command is constructed correctly" )
     };
 
     clear_buffers();
-    queue_response(sync_response);
+    
+    for (uint8_t resp = 0; resp < 8; resp++) {
+        queue_response(sync_response);
+    }
 
     REQUIRE_SUCCESS( loader_sync_cmd() );