#include "boot_serial/boot_serial.h" #include "bootutil/bootutil_log.h" #include "port/boot_serial_port.h" #include #include "soc/rtc.h" #include "soc/gpio_periph.h" #include "soc/dport_reg.h" #include "soc/uart_struct.h" #include "soc/gpio_struct.h" #include "esp32/rom/uart.h" #include "esp32/rom/gpio.h" #include "esp_rom_sys.h" #include "esp_rom_uart.h" #include "esp_rom_gpio.h" #include "gpio_hal.h" #include "gpio_ll.h" #include "uart_ll.h" #include #define BOOT_SERIAL_UART ( 1 ) #define BOOT_SERIAL_UART_RX_PIN ( GPIO_NUM_27 ) #define BOOT_SERIAL_UART_TX_PIN ( GPIO_NUM_26 ) #define BOOT_SERIAL_UART_BAUDRATE ( 115200 ) #define BOOT_SERIAL_TRIGGER_BUTTON ( GPIO_NUM_5 ) #define BOOT_SERIAL_BUFF_SIZE ( 512 ) /***************************************************************************/ static int boot_port_serial_read( char * str, int cnt, int *newline ); static void boot_port_serial_write( const char *prt, int cnt ); static const struct boot_uart_funcs xUartFunctions = { .read = boot_port_serial_read, .write = boot_port_serial_write }; const uint32_t GPIO_PIN_MUX_REG[SOC_GPIO_PIN_COUNT] = { IO_MUX_GPIO0_REG, IO_MUX_GPIO1_REG, IO_MUX_GPIO2_REG, IO_MUX_GPIO3_REG, IO_MUX_GPIO4_REG, IO_MUX_GPIO5_REG, IO_MUX_GPIO6_REG, IO_MUX_GPIO7_REG, IO_MUX_GPIO8_REG, IO_MUX_GPIO9_REG, IO_MUX_GPIO10_REG, IO_MUX_GPIO11_REG, IO_MUX_GPIO12_REG, IO_MUX_GPIO13_REG, IO_MUX_GPIO14_REG, IO_MUX_GPIO15_REG, IO_MUX_GPIO16_REG, IO_MUX_GPIO17_REG, IO_MUX_GPIO18_REG, IO_MUX_GPIO19_REG, 0, IO_MUX_GPIO21_REG, IO_MUX_GPIO22_REG, IO_MUX_GPIO23_REG, 0, IO_MUX_GPIO25_REG, IO_MUX_GPIO26_REG, IO_MUX_GPIO27_REG, 0, 0, 0, 0, IO_MUX_GPIO32_REG, IO_MUX_GPIO33_REG, IO_MUX_GPIO34_REG, IO_MUX_GPIO35_REG, IO_MUX_GPIO36_REG, IO_MUX_GPIO37_REG, IO_MUX_GPIO38_REG, IO_MUX_GPIO39_REG, }; /***************************************************************************/ /* TODO: Should use the esp_rom api, but couldn't get it working */ static uint32_t readline( uint8_t * buf, uint32_t cap ) { volatile uint32_t len = 0; volatile uint32_t n_read = 0; volatile bool stop = false; static uart_dev_t * pxUART = &UART1; do { len = uart_ll_get_rxfifo_len( pxUART ); for( uint32_t i=0; i space ) { BOOT_LOG_ERR("Unable to send full message. TX fifo would overflow"); } /* TODO: Should wait for available space, or continuously chunk */ uart_ll_write_txfifo( &UART1, (const uint8_t *)prt, cnt ); BOOT_LOG_DBG("Response[%d]: %s", cnt, prt); }