@@ -41,6 +41,7 @@ static int64_t s_time_end;
4141static int32_t s_uart_port ;
4242static int32_t s_reset_trigger_pin ;
4343static int32_t s_gpio0_trigger_pin ;
44+ static bool s_peripheral_needs_deinit ;
4445
4546esp_loader_error_t loader_port_esp32_init (const loader_esp32_config_t * config )
4647{
@@ -49,30 +50,34 @@ esp_loader_error_t loader_port_esp32_init(const loader_esp32_config_t *config)
4950 s_gpio0_trigger_pin = config -> gpio0_trigger_pin ;
5051
5152 // Initialize UART
52- uart_config_t uart_config = {
53- .baud_rate = config -> baud_rate ,
54- .data_bits = UART_DATA_8_BITS ,
55- .parity = UART_PARITY_DISABLE ,
56- .stop_bits = UART_STOP_BITS_1 ,
57- .flow_ctrl = UART_HW_FLOWCTRL_DISABLE ,
53+ if (!config -> dont_initialize_peripheral ) {
54+ uart_config_t uart_config = {
55+ .baud_rate = config -> baud_rate ,
56+ .data_bits = UART_DATA_8_BITS ,
57+ .parity = UART_PARITY_DISABLE ,
58+ .stop_bits = UART_STOP_BITS_1 ,
59+ .flow_ctrl = UART_HW_FLOWCTRL_DISABLE ,
5860#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL (5 , 0 , 0 )
59- .source_clk = UART_SCLK_DEFAULT ,
61+ .source_clk = UART_SCLK_DEFAULT ,
6062#endif
61- };
62-
63- int rx_buffer_size = config -> rx_buffer_size ? config -> rx_buffer_size : 400 ;
64- int tx_buffer_size = config -> tx_buffer_size ? config -> tx_buffer_size : 400 ;
65- QueueHandle_t * uart_queue = config -> uart_queue ? config -> uart_queue : NULL ;
66- int queue_size = config -> queue_size ? config -> queue_size : 0 ;
67-
68- if ( uart_param_config (s_uart_port , & uart_config ) != ESP_OK ) {
69- return ESP_LOADER_ERROR_FAIL ;
70- }
71- if ( uart_set_pin (s_uart_port , config -> uart_tx_pin , config -> uart_rx_pin , UART_PIN_NO_CHANGE , UART_PIN_NO_CHANGE ) != ESP_OK ) {
72- return ESP_LOADER_ERROR_FAIL ;
73- }
74- if ( uart_driver_install (s_uart_port , rx_buffer_size , tx_buffer_size , queue_size , uart_queue , 0 ) != ESP_OK ) {
75- return ESP_LOADER_ERROR_FAIL ;
63+ };
64+
65+ int rx_buffer_size = config -> rx_buffer_size ? config -> rx_buffer_size : 400 ;
66+ int tx_buffer_size = config -> tx_buffer_size ? config -> tx_buffer_size : 400 ;
67+ QueueHandle_t * uart_queue = config -> uart_queue ? config -> uart_queue : NULL ;
68+ int queue_size = config -> queue_size ? config -> queue_size : 0 ;
69+
70+ if ( uart_param_config (s_uart_port , & uart_config ) != ESP_OK ) {
71+ return ESP_LOADER_ERROR_FAIL ;
72+ }
73+ if ( uart_set_pin (s_uart_port , config -> uart_tx_pin , config -> uart_rx_pin , UART_PIN_NO_CHANGE , UART_PIN_NO_CHANGE ) != ESP_OK ) {
74+ return ESP_LOADER_ERROR_FAIL ;
75+ }
76+ if ( uart_driver_install (s_uart_port , rx_buffer_size , tx_buffer_size , queue_size , uart_queue , 0 ) != ESP_OK ) {
77+ return ESP_LOADER_ERROR_FAIL ;
78+ }
79+
80+ s_peripheral_needs_deinit = true;
7681 }
7782
7883 // Initialize boot pin selection pins
@@ -89,7 +94,9 @@ esp_loader_error_t loader_port_esp32_init(const loader_esp32_config_t *config)
8994
9095void loader_port_esp32_deinit (void )
9196{
92- uart_driver_delete (s_uart_port );
97+ if (s_peripheral_needs_deinit ) {
98+ uart_driver_delete (s_uart_port );
99+ }
93100}
94101
95102
0 commit comments