mirror of
https://github.com/espressif/ESP8266_RTOS_SDK.git
synced 2025-05-21 09:05:59 +08:00
feat(bootloader): Add configration for output console UART
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
PROVIDE ( ets_memcpy = 0x400018b4 );
|
||||
PROVIDE ( ets_printf = 0x400024cc );
|
||||
|
||||
PROVIDE ( SPIRead = 0x40004b1c );
|
||||
|
||||
PROVIDE ( xthal_get_ccount = 0x4000dd38 );
|
||||
PROVIDE ( uart_div_modify = 0x400039d8 );
|
||||
PROVIDE ( ets_io_vprintf = 0x40001f00 );
|
@ -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;
|
||||
@ -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
|
||||
@ -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!");
|
||||
|
@ -35,6 +35,23 @@ config SOC_FULL_ICACHE
|
||||
Enable this option, full 32 KB iram instead of 16 KB iram will be used as icache, so the heap use can use
|
||||
may reduce a lot.
|
||||
|
||||
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
|
||||
|
||||
endmenu
|
||||
|
||||
menu WIFI
|
||||
|
@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user