Skip to content

Commit dbdacdf

Browse files
committed
Merge branch 'feature/add_configurate_console_uart' into 'master'
Add configration for output console UART See merge request sdk/ESP8266_RTOS_SDK!460
2 parents dabbbb2 + 964e027 commit dbdacdf

File tree

4 files changed

+57
-8
lines changed

4 files changed

+57
-8
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
PROVIDE ( ets_memcpy = 0x400018b4 );
2-
PROVIDE ( ets_printf = 0x400024cc );
32

43
PROVIDE ( SPIRead = 0x40004b1c );
54

6-
PROVIDE ( xthal_get_ccount = 0x4000dd38 );
5+
PROVIDE ( xthal_get_ccount = 0x4000dd38 );
6+
PROVIDE ( uart_div_modify = 0x400039d8 );
7+
PROVIDE ( ets_io_vprintf = 0x40001f00 );

components/bootloader_support/src/bootloader_init.c

+33
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,15 @@ void __assert_func(const char *file, int line, const char *func, const char *exp
547547
#include "esp_flash_partitions.h"
548548
#include "bootloader_flash.h"
549549

550+
#include "esp8266/uart_register.h"
551+
#include "esp8266/eagle_soc.h"
552+
#include "esp8266/gpio_register.h"
553+
#include "esp8266/pin_mux_register.h"
554+
#include "esp8266/rom_functions.h"
555+
556+
#define CONFIG_CONSOLE_UART_BAUDRATE 74880
557+
#define BOOTLOADER_CONSOLE_CLK_FREQ 52 * 1000 * 1000
558+
550559
extern int _bss_start;
551560
extern int _bss_end;
552561
extern int _data_start;
@@ -558,6 +567,28 @@ static esp_err_t bootloader_main();
558567
static void print_flash_info(const esp_image_header_t* pfhdr);
559568
static void update_flash_config(const esp_image_header_t* pfhdr);
560569

570+
static void uart_console_configure(void)
571+
{
572+
#if CONFIG_CONSOLE_UART_NUM == 1
573+
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_U1TXD_BK);
574+
575+
CLEAR_PERI_REG_MASK(UART_CONF1(CONFIG_CONSOLE_UART_NUM), UART_RX_FLOW_EN);
576+
CLEAR_PERI_REG_MASK(UART_CONF0(CONFIG_CONSOLE_UART_NUM), UART_TX_FLOW_EN);
577+
578+
uart_div_modify(CONFIG_CONSOLE_UART_NUM, BOOTLOADER_CONSOLE_CLK_FREQ / CONFIG_CONSOLE_UART_BAUDRATE);
579+
580+
WRITE_PERI_REG(UART_CONF0(CONFIG_CONSOLE_UART_NUM),
581+
0 // None parity
582+
| (1 << 4) // 1-bit stop
583+
| (3 << 2) // 8-bit data
584+
| 0 // None flow control
585+
| 0); // None Inverse
586+
587+
SET_PERI_REG_MASK(UART_CONF0(CONFIG_CONSOLE_UART_NUM), UART_RXFIFO_RST | UART_TXFIFO_RST);
588+
CLEAR_PERI_REG_MASK(UART_CONF0(CONFIG_CONSOLE_UART_NUM), UART_RXFIFO_RST | UART_TXFIFO_RST);
589+
#endif
590+
}
591+
561592
esp_err_t bootloader_init()
562593
{
563594
//Clear bss
@@ -571,6 +602,8 @@ esp_err_t bootloader_init()
571602

572603
static esp_err_t bootloader_main()
573604
{
605+
uart_console_configure();
606+
574607
esp_image_header_t fhdr;
575608
if (bootloader_flash_read(ESP_BOOTLOADER_OFFSET, &fhdr, sizeof(esp_image_header_t), true) != ESP_OK) {
576609
ESP_LOGE(TAG, "failed to load bootloader header!");

components/esp8266/Kconfig

+17
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,23 @@ config SOC_FULL_ICACHE
3535
Enable this option, full 32 KB iram instead of 16 KB iram will be used as icache, so the heap use can use
3636
may reduce a lot.
3737

38+
choice CONSOLE_UART_NUM
39+
prompt "UART peripheral to use for console output (0-1)"
40+
default CONSOLE_UART_CUSTOM_NUM_0
41+
help
42+
Configrate output console UART for "ets_printf", "printf", "ESP_LOGX" and so on.
43+
44+
config CONSOLE_UART_CUSTOM_NUM_0
45+
bool "UART0"
46+
config CONSOLE_UART_CUSTOM_NUM_1
47+
bool "UART1"
48+
endchoice
49+
50+
config CONSOLE_UART_NUM
51+
int
52+
default 0 if CONSOLE_UART_CUSTOM_NUM_0
53+
default 1 if CONSOLE_UART_CUSTOM_NUM_1
54+
3855
endmenu
3956

4057
menu WIFI

components/esp8266/source/ets_printf.c

+4-6
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,24 @@
1414

1515
#include <stdint.h>
1616

17+
#include "sdkconfig.h"
18+
1719
#include "esp_attr.h"
1820

1921
#include "esp8266/eagle_soc.h"
2022
#include "esp8266/uart_register.h"
2123
#include "esp8266/rom_functions.h"
2224

23-
#ifndef CONFIG_ETS_PUTC_UART
24-
#define CONFIG_ETS_PUTC_UART 0
25-
#endif
26-
2725
int IRAM_ATTR ets_putc(int c)
2826
{
2927
while (1) {
30-
uint32_t fifo_cnt = READ_PERI_REG(UART_STATUS(CONFIG_ETS_PUTC_UART)) & (UART_TXFIFO_CNT << UART_TXFIFO_CNT_S);
28+
uint32_t fifo_cnt = READ_PERI_REG(UART_STATUS(CONFIG_CONSOLE_UART_NUM)) & (UART_TXFIFO_CNT << UART_TXFIFO_CNT_S);
3129

3230
if ((fifo_cnt >> UART_TXFIFO_CNT_S & UART_TXFIFO_CNT) < 126)
3331
break;
3432
}
3533

36-
WRITE_PERI_REG(UART_FIFO(CONFIG_ETS_PUTC_UART) , c);
34+
WRITE_PERI_REG(UART_FIFO(CONFIG_CONSOLE_UART_NUM) , c);
3735

3836
return c;
3937
}

0 commit comments

Comments
 (0)