From a4b6ac5299dd6fabf0c0d1610c58226c1b7fddb9 Mon Sep 17 00:00:00 2001 From: Th3maz1ng Date: Sat, 7 Jan 2023 23:15:53 +0100 Subject: [PATCH] Moved uart TX for debug to PB_02 pin, letting the PB_19 pin free for the I2C SDA line --- src/W800 SDK v1.00.08/include/wm_config.h | 4 +- .../platform/arch/xt804/bsp/board_init.c | 24 +++++++- .../platform/arch/xt804/libc/libc_port.c | 59 +++++++++++-------- src/W800 SDK v1.00.08/platform/inc/utils.h | 1 + src/W800 SDK v1.00.08/platform/sys/wm_main.c | 8 ++- 5 files changed, 66 insertions(+), 30 deletions(-) diff --git a/src/W800 SDK v1.00.08/include/wm_config.h b/src/W800 SDK v1.00.08/include/wm_config.h index c8946c3..803102d 100644 --- a/src/W800 SDK v1.00.08/include/wm_config.h +++ b/src/W800 SDK v1.00.08/include/wm_config.h @@ -16,8 +16,8 @@ #define WM_CONFIG_DEBUG_UART1 CFG_OFF/*PRINTF PORT USE UART1*/ /**Driver Support**/ -#define TLS_CONFIG_HS_SPI CFG_ON /*High Speed SPI*/ -#define TLS_CONFIG_LS_SPI CFG_ON /*Low Speed SPI*/ +#define TLS_CONFIG_HS_SPI CFG_OFF /*High Speed SPI*/ +#define TLS_CONFIG_LS_SPI CFG_OFF /*Low Speed SPI*/ #define TLS_CONFIG_UART CFG_ON /*UART*/ /**Only Factory Test At Command**/ diff --git a/src/W800 SDK v1.00.08/platform/arch/xt804/bsp/board_init.c b/src/W800 SDK v1.00.08/platform/arch/xt804/bsp/board_init.c index 7f965b5..017f8bd 100644 --- a/src/W800 SDK v1.00.08/platform/arch/xt804/bsp/board_init.c +++ b/src/W800 SDK v1.00.08/platform/arch/xt804/bsp/board_init.c @@ -33,7 +33,7 @@ #define UART_BITSTOP_VAL (0x03) /// 1 stop-bit; no crc; 8 data-bits extern void set_printf_port(unsigned char port); -static void uart0Init (int bandrate) +static void uart0Init(int bandrate) { unsigned int bd; @@ -48,8 +48,25 @@ static void uart0Init (int bandrate) tls_reg_write32(HR_UART0_DMA_CTRL, 0x00); /* Disable DMA */ tls_reg_write32(HR_UART0_FIFO_CTRL, 0x00); /* one byte TX/RX */ // tls_reg_write32(HR_UART0_INT_MASK, 0x00); /* Disable INT */ - } + +static void uart2Init(int bandrate) +{ + unsigned int bd; + + NVIC_DisableIRQ(UART24_IRQn); + NVIC_ClearPendingIRQ(UART24_IRQn); + + bd = (APB_CLK/(16*bandrate) - 1)|(((APB_CLK%(bandrate*16))*16/(bandrate*16))<<16); + tls_reg_write32(HR_UART2_BAUD_RATE_CTRL, bd); + + tls_reg_write32(HR_UART2_LINE_CTRL, UART_BITSTOP_VAL | UART_TXEN_BIT | UART_RXEN_BIT); + tls_reg_write32(HR_UART2_FLOW_CTRL, 0x00); /* Disable afc */ + tls_reg_write32(HR_UART2_DMA_CTRL, 0x00); /* Disable DMA */ + tls_reg_write32(HR_UART2_FIFO_CTRL, 0x00); /* one byte TX/RX */ +// tls_reg_write32(HR_UART2_INT_MASK, 0x00); /* Disable INT */ +} + #if 0 static void uart1_io_init(void) { @@ -97,7 +114,8 @@ void board_init(void) #if USE_UART0_PRINT /* use uart0 as log output io */ - uart0Init(115200); + //uart0Init(115200); + uart2Init(115200); set_printf_port(0); #else uart1_io_init(); diff --git a/src/W800 SDK v1.00.08/platform/arch/xt804/libc/libc_port.c b/src/W800 SDK v1.00.08/platform/arch/xt804/libc/libc_port.c index b971db7..4787b65 100644 --- a/src/W800 SDK v1.00.08/platform/arch/xt804/libc/libc_port.c +++ b/src/W800 SDK v1.00.08/platform/arch/xt804/libc/libc_port.c @@ -57,35 +57,48 @@ void set_printf_port(unsigned char port) int sendchar(int ch) { - //tls_reg_write32(HR_UART0_INT_MASK, 0x3); - if (printf_port == 0) - { - if(ch == '\n') - { - while (tls_reg_read32(HR_UART0_FIFO_STATUS) & 0x3F); - tls_reg_write32(HR_UART0_TX_WIN, '\r'); - } - while(tls_reg_read32(HR_UART0_FIFO_STATUS) & 0x3F); - tls_reg_write32(HR_UART0_TX_WIN, (char)ch); - } - else if (printf_port == 1) - { - if(ch == '\n') - { - while (tls_reg_read32(HR_UART1_FIFO_STATUS) & 0x3F); - tls_reg_write32(HR_UART1_TX_WIN, '\r'); - } - while(tls_reg_read32(HR_UART1_FIFO_STATUS) & 0x3F); - tls_reg_write32(HR_UART1_TX_WIN, (char)ch); - } - //tls_reg_write32(HR_UART0_INT_MASK, 0x0); + // tls_reg_write32(HR_UART0_INT_MASK, 0x3); + if (printf_port == 0) + { + if (ch == '\n') + { + while (tls_reg_read32(HR_UART0_FIFO_STATUS) & 0x3F); + tls_reg_write32(HR_UART0_TX_WIN, '\r'); + } + while (tls_reg_read32(HR_UART0_FIFO_STATUS) & 0x3F); + tls_reg_write32(HR_UART0_TX_WIN, (char)ch); + } + else if (printf_port == 1) + { + if (ch == '\n') + { + while (tls_reg_read32(HR_UART1_FIFO_STATUS) & 0x3F); + tls_reg_write32(HR_UART1_TX_WIN, '\r'); + } + while (tls_reg_read32(HR_UART1_FIFO_STATUS) & 0x3F); + tls_reg_write32(HR_UART1_TX_WIN, (char)ch); + } + // tls_reg_write32(HR_UART0_INT_MASK, 0x0); + return ch; +} + +int sendchar_debug_uart(int ch) +{ + if (ch == '\n') + { + while (tls_reg_read32(HR_UART2_FIFO_STATUS) & 0x3F); + tls_reg_write32(HR_UART2_TX_WIN, '\r'); + } + while (tls_reg_read32(HR_UART2_FIFO_STATUS) & 0x3F); + tls_reg_write32(HR_UART2_TX_WIN, (char)ch); return ch; } int fputc(int ch, FILE *stream) { (void)stream; - sendchar(ch); + //sendchar(ch); + sendchar_debug_uart(ch); return 0; } diff --git a/src/W800 SDK v1.00.08/platform/inc/utils.h b/src/W800 SDK v1.00.08/platform/inc/utils.h index 6894390..1a26802 100644 --- a/src/W800 SDK v1.00.08/platform/inc/utils.h +++ b/src/W800 SDK v1.00.08/platform/inc/utils.h @@ -35,5 +35,6 @@ char * strdup(const char *s); char * strndup(const char *s, size_t len); int sendchar(int ch); +int sendchar_debug_uart(int ch); #endif /* UTILS_H */ diff --git a/src/W800 SDK v1.00.08/platform/sys/wm_main.c b/src/W800 SDK v1.00.08/platform/sys/wm_main.c index 187c583..379563a 100644 --- a/src/W800 SDK v1.00.08/platform/sys/wm_main.c +++ b/src/W800 SDK v1.00.08/platform/sys/wm_main.c @@ -151,8 +151,11 @@ void wm_gpio_config() /* must call first */ wm_gpio_af_disable(); - wm_uart0_tx_config(WM_IO_PB_19); - wm_uart0_rx_config(WM_IO_PB_20); + /*wm_uart0_tx_config(WM_IO_PB_19); + wm_uart0_rx_config(WM_IO_PB_20);*/ + + /* used for the debug uart */ + wm_uart2_tx_scio_config(WM_IO_PB_02); /*Please Attention, only one IO's multiplex can be used at one times' configuration. */ @@ -233,6 +236,7 @@ int main(void) tls_reg_write32(HR_PMU_BK_REG, value); value = tls_reg_read32(HR_PMU_PS_CR); value &= ~(BIT(5)); + value &= ~(BIT(6)); //Set wakeup pin to trigger immediatly by clearing pin 6, needed for the touch panel fast interrupt tls_reg_write32(HR_PMU_PS_CR, value); /*Close those not initialized clk except touchsensor/trng, uart0,sdadc,gpio,rfcfg*/