mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 07:03:55 +00:00 
			
		
		
		
	Fix ESP-IDF uart initialisation sequence to match Espressif docs. (#5838)
This commit is contained in:
		| @@ -84,28 +84,9 @@ void IDFUARTComponent::setup() { | |||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   err = uart_driver_install(this->uart_num_, /* UART RX ring buffer size. */ this->rx_buffer_size_, |  | ||||||
|                             /* UART TX ring buffer size. If set to zero, driver will not use TX buffer, TX function will |  | ||||||
|                                block task until all data have been sent out.*/ |  | ||||||
|                             0, |  | ||||||
|                             /* UART event queue size/depth. */ 20, &(this->uart_event_queue_), |  | ||||||
|                             /* Flags used to allocate the interrupt. */ 0); |  | ||||||
|   if (err != ESP_OK) { |  | ||||||
|     ESP_LOGW(TAG, "uart_driver_install failed: %s", esp_err_to_name(err)); |  | ||||||
|     this->mark_failed(); |  | ||||||
|     return; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   int8_t tx = this->tx_pin_ != nullptr ? this->tx_pin_->get_pin() : -1; |   int8_t tx = this->tx_pin_ != nullptr ? this->tx_pin_->get_pin() : -1; | ||||||
|   int8_t rx = this->rx_pin_ != nullptr ? this->rx_pin_->get_pin() : -1; |   int8_t rx = this->rx_pin_ != nullptr ? this->rx_pin_->get_pin() : -1; | ||||||
|  |  | ||||||
|   err = uart_set_pin(this->uart_num_, tx, rx, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE); |  | ||||||
|   if (err != ESP_OK) { |  | ||||||
|     ESP_LOGW(TAG, "uart_set_pin failed: %s", esp_err_to_name(err)); |  | ||||||
|     this->mark_failed(); |  | ||||||
|     return; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   uint32_t invert = 0; |   uint32_t invert = 0; | ||||||
|   if (this->tx_pin_ != nullptr && this->tx_pin_->is_inverted()) |   if (this->tx_pin_ != nullptr && this->tx_pin_->is_inverted()) | ||||||
|     invert |= UART_SIGNAL_TXD_INV; |     invert |= UART_SIGNAL_TXD_INV; | ||||||
| @@ -119,6 +100,25 @@ void IDFUARTComponent::setup() { | |||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |   err = uart_set_pin(this->uart_num_, tx, rx, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE); | ||||||
|  |   if (err != ESP_OK) { | ||||||
|  |     ESP_LOGW(TAG, "uart_set_pin failed: %s", esp_err_to_name(err)); | ||||||
|  |     this->mark_failed(); | ||||||
|  |     return; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   err = uart_driver_install(this->uart_num_, /* UART RX ring buffer size. */ this->rx_buffer_size_, | ||||||
|  |                             /* UART TX ring buffer size. If set to zero, driver will not use TX buffer, TX function will | ||||||
|  |                                block task until all data have been sent out.*/ | ||||||
|  |                             0, | ||||||
|  |                             /* UART event queue size/depth. */ 20, &(this->uart_event_queue_), | ||||||
|  |                             /* Flags used to allocate the interrupt. */ 0); | ||||||
|  |   if (err != ESP_OK) { | ||||||
|  |     ESP_LOGW(TAG, "uart_driver_install failed: %s", esp_err_to_name(err)); | ||||||
|  |     this->mark_failed(); | ||||||
|  |     return; | ||||||
|  |   } | ||||||
|  |  | ||||||
|   xSemaphoreGive(this->lock_); |   xSemaphoreGive(this->lock_); | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user