From cc468797b34eddb3938720a57df00c78055541ec Mon Sep 17 00:00:00 2001 From: Anatole SCHRAMM Date: Wed, 8 Mar 2023 14:04:01 +0100 Subject: [PATCH] Now also outputting SDK logs to UART1 pins, corrected an issue raising an error when using the nano_shell and added a workaround to be able to really stop the BT modem. Probably a bug in the SDK or in the chip ? --- app/nano_shell_command.c | 6 ++++-- app/nano_shell_port.c | 4 ++++ platform/arch/xt804/bsp/board_init.c | 24 ++++++++++++++++++++++-- platform/arch/xt804/libc/libc_port.c | 17 +++++++++++++++-- platform/inc/utils.h | 1 + 5 files changed, 46 insertions(+), 6 deletions(-) diff --git a/app/nano_shell_command.c b/app/nano_shell_command.c index a68e6cf..9a51894 100644 --- a/app/nano_shell_command.c +++ b/app/nano_shell_command.c @@ -60,6 +60,8 @@ void wifi_scan_result_cb(void) } tls_mem_free(buf); + + tls_wifi_scan_result_cb_register(NULL); } void tls_wifi_data_ext_recv_cb(u8* data, u32 data_len, struct tls_wifi_ext_t *ext) @@ -508,12 +510,12 @@ int _bluetooth(const shell_cmd_t *pcmd, int argc, char *const argv[]) if(strcmp(argv[1], "enable") == 0) { shell_printf("Enabling bluetooth : %d"NEW_LINE, demo_bt_enable()); - //shell_printf("Enabling bluetooth test"NEW_LINE); } else if(strcmp(argv[1], "disable") == 0) { shell_printf("Disabling bluetooth : %d"NEW_LINE, demo_bt_destroy()); - //shell_printf("Disabling bluetooth test"NEW_LINE); + //Starting a wifi scan really stops the BT modem ?? Why ? I don't know + tls_wifi_scan(); } else if(strcmp(argv[1], "start_demo") == 0) { diff --git a/app/nano_shell_port.c b/app/nano_shell_port.c index a983e75..8def246 100644 --- a/app/nano_shell_port.c +++ b/app/nano_shell_port.c @@ -77,9 +77,13 @@ int shell_printf(const char *format, ...) length = vsnprintf(shell_printf_buffer, CONFIG_SHELL_PRINTF_BUFFER_SIZE, format, ap); va_end(ap); + //No need to write anything in this case + if(!length) return 0; + (void)tls_uart_write(TLS_UART_0, shell_printf_buffer, length); (void)tls_uart_write(TLS_UART_1, shell_printf_buffer, length); (void)network_write_string(shell_printf_buffer, length); + return length; } diff --git a/platform/arch/xt804/bsp/board_init.c b/platform/arch/xt804/bsp/board_init.c index 7f965b5..6da8a83 100644 --- a/platform/arch/xt804/bsp/board_init.c +++ b/platform/arch/xt804/bsp/board_init.c @@ -49,6 +49,25 @@ static void uart0Init (int bandrate) tls_reg_write32(HR_UART0_FIFO_CTRL, 0x00); /* one byte TX/RX */ // tls_reg_write32(HR_UART0_INT_MASK, 0x00); /* Disable INT */ +} + +/*Not present in official SDK, added to spit the traces on the UART1 on startup */ +static void uart1Init (int bandrate) +{ + unsigned int bd; + + NVIC_DisableIRQ(UART1_IRQn); + NVIC_ClearPendingIRQ(UART1_IRQn); + + bd = (APB_CLK/(16*bandrate) - 1)|(((APB_CLK%(bandrate*16))*16/(bandrate*16))<<16); + tls_reg_write32(HR_UART1_BAUD_RATE_CTRL, bd); + + tls_reg_write32(HR_UART1_LINE_CTRL, UART_BITSTOP_VAL | UART_TXEN_BIT | UART_RXEN_BIT); + tls_reg_write32(HR_UART1_FLOW_CTRL, 0x00); /* Disable afc */ + tls_reg_write32(HR_UART1_DMA_CTRL, 0x00); /* Disable DMA */ + tls_reg_write32(HR_UART1_FIFO_CTRL, 0x00); /* one byte TX/RX */ +// tls_reg_write32(HR_UART1_INT_MASK, 0x00); /* Disable INT */ + } #if 0 static void uart1_io_init(void) @@ -96,8 +115,9 @@ void board_init(void) { #if USE_UART0_PRINT - /* use uart0 as log output io */ - uart0Init(115200); + /* use uart1 as log output io */ + //uart0Init(115200); + uart1Init(115200); set_printf_port(0); #else uart1_io_init(); diff --git a/platform/arch/xt804/libc/libc_port.c b/platform/arch/xt804/libc/libc_port.c index b971db7..7151644 100644 --- a/platform/arch/xt804/libc/libc_port.c +++ b/platform/arch/xt804/libc/libc_port.c @@ -78,14 +78,27 @@ int sendchar(int ch) 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; + //tls_reg_write32(HR_UART0_INT_MASK, 0x0); + return ch; +} + +int sendchar_debug_uart(int ch) +{ + 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); + return ch; } int fputc(int ch, FILE *stream) { (void)stream; sendchar(ch); + sendchar_debug_uart(ch); return 0; } diff --git a/platform/inc/utils.h b/platform/inc/utils.h index eb5a47d..b4fe054 100644 --- a/platform/inc/utils.h +++ b/platform/inc/utils.h @@ -35,6 +35,7 @@ char * strdup(const char *s); char * strndup(const char *s, size_t len); int sendchar(int ch); +int sendchar_debug_uart(int ch); void dumpBuffer(char *name, char* buffer, int len); void dumpUint32(char *name, u32* buffer, int len);