Browse Source

Merge branch 'feature/add_spi_pin_config' into 'master'

Added spi_pin_config

See merge request espressif/esp-serial-flasher!16
Martin Válik 5 years ago
parent
commit
50efabff0c
3 changed files with 36 additions and 2 deletions
  1. 6 0
      examples/esp32_example/README.md
  2. 29 0
      include/esp_loader.h
  3. 1 2
      src/esp_loader.c

+ 6 - 0
examples/esp32_example/README.md

@@ -15,6 +15,12 @@ Following steps are performed in order to re-program target's memory:
 
 
 Note: In addition, to steps mentioned above, `esp_loader_change_baudrate`  is called after connection is established in order to increase flashing speed. This does not apply for ESP8266, as its bootloader does not support this command. However, ESP8266 is capable of detecting baud rate during connection phase, and can be changed before calling `esp_loader_connect`, if necessary.
 Note: In addition, to steps mentioned above, `esp_loader_change_baudrate`  is called after connection is established in order to increase flashing speed. This does not apply for ESP8266, as its bootloader does not support this command. However, ESP8266 is capable of detecting baud rate during connection phase, and can be changed before calling `esp_loader_connect`, if necessary.
 
 
+## SPI pin initialization
+
+In majority of cases `ESP_LOADER_CONNECT_DEFAULT` helper macro is used in order to initialize `loader_connect_args_t` data structure passed to `esp_loader_connect`. Helper macro sets `spi_pin_config` field of the data structure to zero, thus, default SPI pins are used to connect to FLASH memory. In special cases, such as custom design in which FLASH is connected to different pins, `spi_pin_config` field has to be set accordingly. For more detailed information refer to [serial protocol](https://github.com/espressif/esptool/wiki/Serial-Protocol).
+
+When programming ESP32-PICO-V4 (SiP), `ESP_LOADER_SPI_CONFIG_ESP32PICOD4` macro can be used to initialize `spi_pin_config`, due to special connection between ESP32 and SPI FLASH chip.
+
 ## Hardware Required
 ## Hardware Required
 
 
 * Two development boards with ESP32 SoC (e.g., ESP32-DevKitC, ESP-WROVER-KIT, etc.).
 * Two development boards with ESP32 SoC (e.g., ESP32-DevKitC, ESP-WROVER-KIT, etc.).

+ 29 - 0
include/esp_loader.h

@@ -39,6 +39,21 @@ typedef enum
     ESP_LOADER_ERROR_INVALID_RESPONSE  /*!< Internal error */
     ESP_LOADER_ERROR_INVALID_RESPONSE  /*!< Internal error */
 } esp_loader_error_t;
 } esp_loader_error_t;
 
 
+/**
+ * @brief SPI pin configuration arguments
+ */
+typedef union {
+    struct {
+        uint32_t pin_clk: 6;
+        uint32_t pin_q:   6;
+        uint32_t pin_d:   6;
+        uint32_t pin_cs:  6;
+        uint32_t pin_hd:  6;
+        uint32_t zero:    2;
+    };
+    uint32_t val;
+} esp_loader_spi_config_t;
+
 /**
 /**
  * @brief Connection arguments
  * @brief Connection arguments
  */
  */
@@ -47,13 +62,27 @@ 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() { \
+  .spi_pin_config.val = 0,  \
   .sync_timeout = 100,  \
   .sync_timeout = 100,  \
   .trials = 10  \
   .trials = 10  \
 }
 }
 
 
+#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     \
+}
+
 /**
 /**
   * @brief Connects to the target
   * @brief Connects to the target
   *
   *

+ 1 - 2
src/esp_loader.c

@@ -179,9 +179,8 @@ esp_loader_error_t esp_loader_connect(esp_loader_connect_args_t *connect_args)
     RETURN_ON_ERROR( detect_chip() );
     RETURN_ON_ERROR( detect_chip() );
 
 
 #ifndef TARGET_ESP8266
 #ifndef TARGET_ESP8266
-    uint32_t SPI_PIN_CONFIG_DEFAULT = 0;
     loader_port_start_timer(DEFAULT_TIMEOUT);
     loader_port_start_timer(DEFAULT_TIMEOUT);
-    err = loader_spi_attach_cmd(SPI_PIN_CONFIG_DEFAULT);
+    err = loader_spi_attach_cmd(connect_args->spi_pin_config.val);
 #endif
 #endif
 
 
     return err;
     return err;