fix(esp8266): fix UART output error when start up

Add UART system API to flush UART and wait until all characters are sent.
This commit is contained in:
dongheng
2019-09-16 13:59:38 +08:00
parent 0769fb46dc
commit 96e5df4ebd
6 changed files with 54 additions and 49 deletions

View File

@ -17,6 +17,7 @@
#include <string.h>
#include "rom/ets_sys.h"
#include "rom/uart.h"
#include "esp_err.h"
#include "esp_phy_init.h"
@ -69,6 +70,11 @@ esp_err_t esp_phy_rf_init(const esp_phy_init_data_t* init_data, esp_phy_calibrat
esp_err_t status = ESP_OK;
uint8_t sta_mac[6];
uint8_t *local_init_data = calloc(1, 256);
#ifdef CONFIG_CONSOLE_UART_BAUDRATE
const uint32_t uart_baudrate = CONFIG_CONSOLE_UART_BAUDRATE;
#else
const uint32_t uart_baudrate = 74880; // ROM default baudrate
#endif
memcpy(local_init_data, init_data->params, 128);
@ -85,6 +91,16 @@ esp_err_t esp_phy_rf_init(const esp_phy_init_data_t* init_data, esp_phy_calibrat
esp_efuse_mac_get_default(sta_mac);
/**
* The API "register_chipv6_phy" will modify the APB frequency to 80MHz,
* so UARTs must be flush here, then reconfigurate the UART frequency dividor
*/
uart_tx_wait_idle(0);
uart_div_modify(0, UART_CLK_FREQ / uart_baudrate);
uart_tx_wait_idle(1);
uart_div_modify(1, UART_CLK_FREQ / uart_baudrate);
int ret = register_chipv6_phy(local_init_data);
if (ret) {
ESP_LOGI(TAG, "phy register error, ret:%d", ret);