Skip to content

Commit

Permalink
Merge branch 'feature/add_configurate_console_uart_v3.0' into 'releas…
Browse files Browse the repository at this point in the history
…e/v3.0'

Add configration for output console UART

See merge request sdk/ESP8266_RTOS_SDK!462
  • Loading branch information
donghengqaz committed Sep 7, 2018
2 parents 44a2b2d + e4808fe commit 7679495
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
PROVIDE ( ets_memcpy = 0x400018b4 );
PROVIDE ( ets_printf = 0x400024cc );

PROVIDE ( SPIRead = 0x40004b1c );

PROVIDE ( xthal_get_ccount = 0x4000dd38 );
PROVIDE ( xthal_get_ccount = 0x4000dd38 );
PROVIDE ( uart_div_modify = 0x400039d8 );
PROVIDE ( ets_io_vprintf = 0x40001f00 );
33 changes: 33 additions & 0 deletions components/bootloader_support/src/bootloader_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,15 @@ void __assert_func(const char *file, int line, const char *func, const char *exp
#include "esp_flash_partitions.h"
#include "bootloader_flash.h"

#include "esp8266/uart_register.h"
#include "esp8266/eagle_soc.h"
#include "esp8266/gpio_register.h"
#include "esp8266/pin_mux_register.h"
#include "esp8266/rom_functions.h"

#define CONFIG_CONSOLE_UART_BAUDRATE 74880
#define BOOTLOADER_CONSOLE_CLK_FREQ 52 * 1000 * 1000

extern int _bss_start;
extern int _bss_end;
extern int _data_start;
Expand All @@ -558,6 +567,28 @@ static esp_err_t bootloader_main();
static void print_flash_info(const esp_image_header_t* pfhdr);
static void update_flash_config(const esp_image_header_t* pfhdr);

static void uart_console_configure(void)
{
#if CONFIG_CONSOLE_UART_NUM == 1
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_U1TXD_BK);

CLEAR_PERI_REG_MASK(UART_CONF1(CONFIG_CONSOLE_UART_NUM), UART_RX_FLOW_EN);
CLEAR_PERI_REG_MASK(UART_CONF0(CONFIG_CONSOLE_UART_NUM), UART_TX_FLOW_EN);

uart_div_modify(CONFIG_CONSOLE_UART_NUM, BOOTLOADER_CONSOLE_CLK_FREQ / CONFIG_CONSOLE_UART_BAUDRATE);

WRITE_PERI_REG(UART_CONF0(CONFIG_CONSOLE_UART_NUM),
0 // None parity
| (1 << 4) // 1-bit stop
| (3 << 2) // 8-bit data
| 0 // None flow control
| 0); // None Inverse

SET_PERI_REG_MASK(UART_CONF0(CONFIG_CONSOLE_UART_NUM), UART_RXFIFO_RST | UART_TXFIFO_RST);
CLEAR_PERI_REG_MASK(UART_CONF0(CONFIG_CONSOLE_UART_NUM), UART_RXFIFO_RST | UART_TXFIFO_RST);
#endif
}

esp_err_t bootloader_init()
{
//Clear bss
Expand All @@ -571,6 +602,8 @@ esp_err_t bootloader_init()

static esp_err_t bootloader_main()
{
uart_console_configure();

esp_image_header_t fhdr;
if (bootloader_flash_read(ESP_BOOTLOADER_OFFSET, &fhdr, sizeof(esp_image_header_t), true) != ESP_OK) {
ESP_LOGE(TAG, "failed to load bootloader header!");
Expand Down
17 changes: 17 additions & 0 deletions components/esp8266/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,23 @@ config SOC_FULL_ICACHE

endmenu

choice CONSOLE_UART_NUM
prompt "UART peripheral to use for console output (0-1)"
default CONSOLE_UART_CUSTOM_NUM_0
help
Configrate output console UART for "ets_printf", "printf", "ESP_LOGX" and so on.

config CONSOLE_UART_CUSTOM_NUM_0
bool "UART0"
config CONSOLE_UART_CUSTOM_NUM_1
bool "UART1"
endchoice

config CONSOLE_UART_NUM
int
default 0 if CONSOLE_UART_CUSTOM_NUM_0
default 1 if CONSOLE_UART_CUSTOM_NUM_1

menu WIFI

config SCAN_AP_MAX
Expand Down
10 changes: 4 additions & 6 deletions components/esp8266/source/ets_printf.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,24 @@

#include <stdint.h>

#include "sdkconfig.h"

#include "esp_attr.h"

#include "esp8266/eagle_soc.h"
#include "esp8266/uart_register.h"
#include "esp8266/rom_functions.h"

#ifndef CONFIG_ETS_PUTC_UART
#define CONFIG_ETS_PUTC_UART 0
#endif

int IRAM_ATTR ets_putc(int c)
{
while (1) {
uint32_t fifo_cnt = READ_PERI_REG(UART_STATUS(CONFIG_ETS_PUTC_UART)) & (UART_TXFIFO_CNT << UART_TXFIFO_CNT_S);
uint32_t fifo_cnt = READ_PERI_REG(UART_STATUS(CONFIG_CONSOLE_UART_NUM)) & (UART_TXFIFO_CNT << UART_TXFIFO_CNT_S);

if ((fifo_cnt >> UART_TXFIFO_CNT_S & UART_TXFIFO_CNT) < 126)
break;
}

WRITE_PERI_REG(UART_FIFO(CONFIG_ETS_PUTC_UART) , c);
WRITE_PERI_REG(UART_FIFO(CONFIG_CONSOLE_UART_NUM) , c);

return c;
}
Expand Down

0 comments on commit 7679495

Please sign in to comment.