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

Merge branch 'feature/debug_print' into 'master'

feature: Transfer debug tracing

Closes ESF-47

See merge request espressif/esp-serial-flasher!67
Roland Dobai 2 лет назад
Родитель
Сommit
0fcb9b5557
11 измененных файлов с 98 добавлено и 82 удалено
  1. 1 1
      .github/ISSUE_TEMPLATE/bug_report.yml
  2. 4 0
      CMakeLists.txt
  3. 4 0
      Kconfig
  4. 1 1
      idf_component.yml
  5. 14 31
      port/esp32_port.c
  6. 11 14
      port/raspberry_port.c
  7. 11 33
      port/stm32_port.c
  8. 22 0
      port/zephyr_port.c
  9. 5 1
      test/CMakeLists.txt
  10. 2 1
      test/qemu_test.cpp
  11. 23 0
      test/serial_io_tcp.cpp

+ 1 - 1
.github/ISSUE_TEMPLATE/bug_report.yml

@@ -36,7 +36,7 @@ body:
   - type: textarea
   - type: textarea
     attributes:
     attributes:
       label: Log output
       label: Log output
-      description: Provide the full output log.
+      description: Enable tracing with SERIAL_FLASHER_DEBUG_TRACE and provide the full log.
       render: plain
       render: plain
     validations:
     validations:
       required: true
       required: true

+ 4 - 0
CMakeLists.txt

@@ -93,6 +93,10 @@ elseif (DEFINED SERIAL_FLASHER_INTERFACE_SPI OR CONFIG_SERIAL_FLASHER_INTERFACE_
     )
     )
 endif()
 endif()
 
 
+if(DEFINED SERIAL_FLASHER_DEBUG_TRACE OR CONFIG_SERIAL_FLASHER_DEBUG_TRACE)
+    target_compile_definitions(${target} PUBLIC SERIAL_FLASHER_DEBUG_TRACE)
+endif()
+
 if(DEFINED CONFIG_SERIAL_FLASHER_RESET_HOLD_TIME_MS AND DEFINED CONFIG_SERIAL_FLASHER_BOOT_HOLD_TIME_MS)
 if(DEFINED CONFIG_SERIAL_FLASHER_RESET_HOLD_TIME_MS AND DEFINED CONFIG_SERIAL_FLASHER_BOOT_HOLD_TIME_MS)
     target_compile_definitions(${target}
     target_compile_definitions(${target}
     PUBLIC
     PUBLIC

+ 4 - 0
Kconfig

@@ -27,4 +27,8 @@ menu "ESP serial flasher"
         int "Time for which the boot pin is asserted when doing a hard reset"
         int "Time for which the boot pin is asserted when doing a hard reset"
         default 50
         default 50
 
 
+    config SERIAL_FLASHER_DEBUG_TRACE
+        bool "Enable debug tracing output (only transfer data tracing is supported at the time)"
+        default n
+
 endmenu
 endmenu

+ 1 - 1
idf_component.yml

@@ -1,3 +1,3 @@
-version: "0.1.0"
+version: "0.2.0"
 description: Serial flasher component provides portable library for flashing or loading ram loadble app to Espressif SoCs from other host microcontroller
 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
 url: https://github.com/espressif/esp-serial-flasher

+ 14 - 31
port/esp32_port.c

@@ -21,42 +21,20 @@
 #include "esp_idf_version.h"
 #include "esp_idf_version.h"
 #include <unistd.h>
 #include <unistd.h>
 
 
-// #define SERIAL_DEBUG_ENABLE
-
-#ifdef SERIAL_DEBUG_ENABLE
-
-static void dec_to_hex_str(const uint8_t dec, uint8_t hex_str[3])
-{
-    static const uint8_t dec_to_hex[] = {
-        '0', '1', '2', '3', '4', '5', '6', '7',
-        '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
-    };
-
-    hex_str[0] = dec_to_hex[dec >> 4];
-    hex_str[1] = dec_to_hex[dec & 0xF];
-    hex_str[2] = '\0';
-}
-
-static void serial_debug_print(const uint8_t *data, uint16_t size, bool write)
+#ifdef SERIAL_FLASHER_DEBUG_TRACE
+static void transfer_debug_print(const uint8_t *data, uint16_t size, bool write)
 {
 {
     static bool write_prev = false;
     static bool write_prev = false;
-    uint8_t hex_str[3];
 
 
-    if(write_prev != write) {
+    if (write_prev != write) {
         write_prev = write;
         write_prev = write;
         printf("\n--- %s ---\n", write ? "WRITE" : "READ");
         printf("\n--- %s ---\n", write ? "WRITE" : "READ");
     }
     }
 
 
-    for(uint32_t i = 0; i < size; i++) {
-        dec_to_hex_str(data[i], hex_str);
-        printf("%s ", hex_str);
+    for (uint32_t i = 0; i < size; i++) {
+        printf("%02x ", data[i]);
     }
     }
 }
 }
-
-#else
-
-static void serial_debug_print(const uint8_t *data, uint16_t size, bool write) { }
-
 #endif
 #endif
 
 
 static int64_t s_time_end;
 static int64_t s_time_end;
@@ -117,12 +95,13 @@ void loader_port_esp32_deinit(void)
 
 
 esp_loader_error_t loader_port_write(const uint8_t *data, uint16_t size, uint32_t timeout)
 esp_loader_error_t loader_port_write(const uint8_t *data, uint16_t size, uint32_t timeout)
 {
 {
-    serial_debug_print(data, size, true);
-
     uart_write_bytes(s_uart_port, (const char *)data, size);
     uart_write_bytes(s_uart_port, (const char *)data, size);
     esp_err_t err = uart_wait_tx_done(s_uart_port, pdMS_TO_TICKS(timeout));
     esp_err_t err = uart_wait_tx_done(s_uart_port, pdMS_TO_TICKS(timeout));
 
 
     if (err == ESP_OK) {
     if (err == ESP_OK) {
+#ifdef SERIAL_FLASHER_DEBUG_TRACE
+        transfer_debug_print(data, size, true);
+#endif
         return ESP_LOADER_SUCCESS;
         return ESP_LOADER_SUCCESS;
     } else if (err == ESP_ERR_TIMEOUT) {
     } else if (err == ESP_ERR_TIMEOUT) {
         return ESP_LOADER_ERROR_TIMEOUT;
         return ESP_LOADER_ERROR_TIMEOUT;
@@ -136,13 +115,17 @@ esp_loader_error_t loader_port_read(uint8_t *data, uint16_t size, uint32_t timeo
 {
 {
     int read = uart_read_bytes(s_uart_port, data, size, pdMS_TO_TICKS(timeout));
     int read = uart_read_bytes(s_uart_port, data, size, pdMS_TO_TICKS(timeout));
 
 
-    serial_debug_print(data, read, false);
-
     if (read < 0) {
     if (read < 0) {
         return ESP_LOADER_ERROR_FAIL;
         return ESP_LOADER_ERROR_FAIL;
     } else if (read < size) {
     } else if (read < size) {
+#ifdef SERIAL_FLASHER_DEBUG_TRACE
+        transfer_debug_print(data, read, false);
+#endif
         return ESP_LOADER_ERROR_TIMEOUT;
         return ESP_LOADER_ERROR_TIMEOUT;
     } else {
     } else {
+#ifdef SERIAL_FLASHER_DEBUG_TRACE
+        transfer_debug_print(data, read, false);
+#endif
         return ESP_LOADER_SUCCESS;
         return ESP_LOADER_SUCCESS;
     }
     }
 }
 }

+ 11 - 14
port/raspberry_port.c

@@ -33,14 +33,10 @@
 #include <sys/stat.h>
 #include <sys/stat.h>
 #include <sys/param.h>
 #include <sys/param.h>
 
 
-// #define SERIAL_DEBUG_ENABLE
-
-#ifdef SERIAL_DEBUG_ENABLE
-
-static void serial_debug_print(const uint8_t *data, uint16_t size, bool write)
+#ifdef SERIAL_FLASHER_DEBUG_TRACE
+static void transfer_debug_print(const uint8_t *data, uint16_t size, bool write)
 {
 {
     static bool write_prev = false;
     static bool write_prev = false;
-    uint8_t hex_str[3];
 
 
     if (write_prev != write) {
     if (write_prev != write) {
         write_prev = write;
         write_prev = write;
@@ -51,11 +47,6 @@ static void serial_debug_print(const uint8_t *data, uint16_t size, bool write)
         printf("%02x ", data[i]);
         printf("%02x ", data[i]);
     }
     }
 }
 }
-
-#else
-
-static void serial_debug_print(const uint8_t *data, uint16_t size, bool write) { }
-
 #endif
 #endif
 
 
 static int serial;
 static int serial;
@@ -233,15 +224,19 @@ esp_loader_error_t loader_port_raspberry_init(const loader_raspberry_config_t *c
 
 
 esp_loader_error_t loader_port_write(const uint8_t *data, uint16_t size, uint32_t timeout)
 esp_loader_error_t loader_port_write(const uint8_t *data, uint16_t size, uint32_t timeout)
 {
 {
-    serial_debug_print(data, size, true);
-
     int written = write(serial, data, size);
     int written = write(serial, data, size);
 
 
     if (written < 0) {
     if (written < 0) {
         return ESP_LOADER_ERROR_FAIL;
         return ESP_LOADER_ERROR_FAIL;
     } else if (written < size) {
     } else if (written < size) {
+#ifdef SERIAL_FLASHER_DEBUG_TRACE
+        transfer_debug_print(data, written, true);
+#endif
         return ESP_LOADER_ERROR_TIMEOUT;
         return ESP_LOADER_ERROR_TIMEOUT;
     } else {
     } else {
+#ifdef SERIAL_FLASHER_DEBUG_TRACE
+        transfer_debug_print(data, written, true);
+#endif
         return ESP_LOADER_SUCCESS;
         return ESP_LOADER_SUCCESS;
     }
     }
 }
 }
@@ -251,7 +246,9 @@ esp_loader_error_t loader_port_read(uint8_t *data, uint16_t size, uint32_t timeo
 {
 {
     RETURN_ON_ERROR( read_data(data, size) );
     RETURN_ON_ERROR( read_data(data, size) );
 
 
-    serial_debug_print(data, size, false);
+#ifdef SERIAL_FLASHER_DEBUG_TRACE
+    transfer_debug_print(data, size, false);
+#endif
 
 
     return ESP_LOADER_SUCCESS;
     return ESP_LOADER_SUCCESS;
 }
 }

+ 11 - 33
port/stm32_port.c

@@ -20,57 +20,36 @@
 #include <stdio.h>
 #include <stdio.h>
 #include "stm32_port.h"
 #include "stm32_port.h"
 
 
-// #define SERIAL_DEBUG_ENABLE
-
 static UART_HandleTypeDef *uart;
 static UART_HandleTypeDef *uart;
 static GPIO_TypeDef* gpio_port_io0, *gpio_port_rst;
 static GPIO_TypeDef* gpio_port_io0, *gpio_port_rst;
 static uint16_t gpio_num_io0, gpio_num_rst;
 static uint16_t gpio_num_io0, gpio_num_rst;
 
 
-#ifdef SERIAL_DEBUG_ENABLE
-
-static void dec_to_hex_str(const uint8_t dec, uint8_t hex_str[3])
-{
-    static const uint8_t dec_to_hex[] = {
-        '0', '1', '2', '3', '4', '5', '6', '7',
-        '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
-    };
-
-    hex_str[0] = dec_to_hex[(dec >> 4)];
-    hex_str[1] = dec_to_hex[(dec & 0xF)];
-    hex_str[2] = '\0';
-}
-
-static void serial_debug_print(const uint8_t *data, uint16_t size, bool write)
+#ifdef SERIAL_FLASHER_DEBUG_TRACE
+static void transfer_debug_print(const uint8_t *data, uint16_t size, bool write)
 {
 {
     static bool write_prev = false;
     static bool write_prev = false;
-    uint8_t hex_str[3];
 
 
-    if(write_prev != write) {
+    if (write_prev != write) {
         write_prev = write;
         write_prev = write;
         printf("\n--- %s ---\n", write ? "WRITE" : "READ");
         printf("\n--- %s ---\n", write ? "WRITE" : "READ");
     }
     }
 
 
-    for(uint32_t i = 0; i < size; i++) {
-        dec_to_hex_str(data[i], hex_str);
-        printf("%s ", hex_str);
+    for (uint32_t i = 0; i < size; i++) {
+        printf("%02x ", data[i]);
     }
     }
 }
 }
-
-#else
-
-static void serial_debug_print(const uint8_t *data, uint16_t size, bool write) { }
-
 #endif
 #endif
 
 
 static uint32_t s_time_end;
 static uint32_t s_time_end;
 
 
 esp_loader_error_t loader_port_write(const uint8_t *data, uint16_t size, uint32_t timeout)
 esp_loader_error_t loader_port_write(const uint8_t *data, uint16_t size, uint32_t timeout)
 {
 {
-    serial_debug_print(data, size, true);
-
     HAL_StatusTypeDef err = HAL_UART_Transmit(uart, (uint8_t *)data, size, timeout);
     HAL_StatusTypeDef err = HAL_UART_Transmit(uart, (uint8_t *)data, size, timeout);
 
 
     if (err == HAL_OK) {
     if (err == HAL_OK) {
+#ifdef SERIAL_FLASHER_DEBUG_TRACE
+        transfer_debug_print(data, size, true);
+#endif
         return ESP_LOADER_SUCCESS;
         return ESP_LOADER_SUCCESS;
     } else if (err == HAL_TIMEOUT) {
     } else if (err == HAL_TIMEOUT) {
         return ESP_LOADER_ERROR_TIMEOUT;
         return ESP_LOADER_ERROR_TIMEOUT;
@@ -82,13 +61,12 @@ esp_loader_error_t loader_port_write(const uint8_t *data, uint16_t size, uint32_
 
 
 esp_loader_error_t loader_port_read(uint8_t *data, uint16_t size, uint32_t timeout)
 esp_loader_error_t loader_port_read(uint8_t *data, uint16_t size, uint32_t timeout)
 {
 {
-    memset(data, 0x22, size);
-
     HAL_StatusTypeDef err = HAL_UART_Receive(uart, data, size, timeout);
     HAL_StatusTypeDef err = HAL_UART_Receive(uart, data, size, timeout);
 
 
-    serial_debug_print(data, size, false);
-
     if (err == HAL_OK) {
     if (err == HAL_OK) {
+#ifdef SERIAL_FLASHER_DEBUG_TRACE
+        transfer_debug_print(data, size, false);
+#endif
         return ESP_LOADER_SUCCESS;
         return ESP_LOADER_SUCCESS;
     } else if (err == HAL_TIMEOUT) {
     } else if (err == HAL_TIMEOUT) {
         return ESP_LOADER_ERROR_TIMEOUT;
         return ESP_LOADER_ERROR_TIMEOUT;

+ 22 - 0
port/zephyr_port.c

@@ -26,6 +26,22 @@ static struct tty_serial tty;
 static char tty_rx_buf[CONFIG_ESP_SERIAL_FLASHER_UART_BUFSIZE];
 static char tty_rx_buf[CONFIG_ESP_SERIAL_FLASHER_UART_BUFSIZE];
 static char tty_tx_buf[CONFIG_ESP_SERIAL_FLASHER_UART_BUFSIZE];
 static char tty_tx_buf[CONFIG_ESP_SERIAL_FLASHER_UART_BUFSIZE];
 
 
+#ifdef SERIAL_FLASHER_DEBUG_TRACE
+static void transfer_debug_print(const uint8_t *data, uint16_t size, bool write)
+{
+    static bool write_prev = false;
+
+    if (write_prev != write) {
+        write_prev = write;
+        printk("\n--- %s ---\n", write ? "WRITE" : "READ");
+    }
+
+    for (uint32_t i = 0; i < size; i++) {
+        printk("%02x ", data[i]);
+    }
+}
+#endif
+
 esp_loader_error_t configure_tty()
 esp_loader_error_t configure_tty()
 {
 {
     if (tty_init(&tty, uart_dev) < 0 ||
     if (tty_init(&tty, uart_dev) < 0 ||
@@ -54,6 +70,9 @@ esp_loader_error_t loader_port_read(uint8_t *data, const uint16_t size, const ui
         if (read < 0) {
         if (read < 0) {
             return ESP_LOADER_ERROR_TIMEOUT;
             return ESP_LOADER_ERROR_TIMEOUT;
         }
         }
+#ifdef SERIAL_FLASHER_DEBUG_TRACE
+        transfer_debug_print(data, read, false);
+#endif
         total_read += read;
         total_read += read;
         remaining -= read;
         remaining -= read;
     }
     }
@@ -78,6 +97,9 @@ esp_loader_error_t loader_port_write(const uint8_t *data, const uint16_t size, c
         if (written < 0) {
         if (written < 0) {
             return ESP_LOADER_ERROR_TIMEOUT;
             return ESP_LOADER_ERROR_TIMEOUT;
         }
         }
+#ifdef SERIAL_FLASHER_DEBUG_TRACE
+        transfer_debug_print(data, written, true);
+#endif
         total_written += written;
         total_written += written;
         remaining -= written;
         remaining -= written;
     }
     }

+ 5 - 1
test/CMakeLists.txt

@@ -22,4 +22,8 @@ else()
     target_sources(${PROJECT_NAME} PRIVATE serial_io_mock.cpp test.cpp)
     target_sources(${PROJECT_NAME} PRIVATE serial_io_mock.cpp test.cpp)
 endif()
 endif()
 
 
-target_compile_definitions(${PROJECT_NAME} PRIVATE MD5_ENABLED=1 SERIAL_FLASHER_INTERFACE_UART)
+target_compile_definitions(${PROJECT_NAME} PRIVATE
+	MD5_ENABLED=1
+	SERIAL_FLASHER_INTERFACE_UART
+	SERIAL_FLASHER_DEBUG_TRACE
+)

+ 2 - 1
test/qemu_test.cpp

@@ -64,7 +64,8 @@ void flash_application(ifstream& image)
 
 
         ESP_ERR_CHECK( esp_loader_flash_write(payload, to_read) );
         ESP_ERR_CHECK( esp_loader_flash_write(payload, to_read) );
 
 
-        cout << "packet: " << count++ <<  " written: " << to_read << endl;
+        cout << endl << "--- FLASH DATA PACKET: " << count++
+             <<  " DATA WRITTEN: " << to_read << " ---" << endl;
 
 
         image_size -= to_read;
         image_size -= to_read;
     };
     };

+ 23 - 0
test/serial_io_tcp.cpp

@@ -33,6 +33,22 @@ const uint32_t PORT = 5555;
 static int sock = 0;
 static int sock = 0;
 ofstream file;
 ofstream file;
 
 
+#ifdef SERIAL_FLASHER_DEBUG_TRACE
+static void transfer_debug_print(const uint8_t *data, uint16_t size, bool write)
+{
+    static bool write_prev = false;
+
+    if (write_prev != write) {
+        write_prev = write;
+        cout << endl << "--- " << (write ? "WRITE" : "READ") << " ---" << endl;
+    }
+
+    for (uint32_t i = 0; i < size; i++) {
+        cout << hex << static_cast<unsigned int>(data[i]) << dec << ' ';
+    }
+}
+#endif
+
 esp_loader_error_t loader_port_mock_init(const loader_serial_config_t *config)
 esp_loader_error_t loader_port_mock_init(const loader_serial_config_t *config)
 {
 {
     struct sockaddr_in serv_addr;
     struct sockaddr_in serv_addr;
@@ -89,6 +105,9 @@ esp_loader_error_t loader_port_write(const uint8_t *data, uint16_t size, uint32_
             cout << "Socket send failed\n";
             cout << "Socket send failed\n";
             return ESP_LOADER_ERROR_FAIL;
             return ESP_LOADER_ERROR_FAIL;
         }
         }
+#ifdef SERIAL_FLASHER_DEBUG_TRACE
+        transfer_debug_print(data, bytes_written, true);
+#endif
         written += bytes_written;
         written += bytes_written;
     } while (written != size);
     } while (written != size);
     return ESP_LOADER_SUCCESS;
     return ESP_LOADER_SUCCESS;
@@ -106,6 +125,10 @@ esp_loader_error_t loader_port_read(uint8_t *data, uint16_t size, uint32_t timeo
             return ESP_LOADER_ERROR_FAIL;
             return ESP_LOADER_ERROR_FAIL;
         }
         }
 
 
+#ifdef SERIAL_FLASHER_DEBUG_TRACE
+        transfer_debug_print(data, bytes_read, false);
+#endif
+
         file.write((const char*)&data[written], bytes_read);
         file.write((const char*)&data[written], bytes_read);
         file.flush();
         file.flush();