From d44cb80bc59681259f14d4d9c768edf40f892304 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Redon?= Date: Sat, 7 Jul 2018 14:41:11 +0200 Subject: [PATCH] DFU: disable configured console UART before starting main app The DFU uses the UART peripheral (with IRQ/ISR) for the debug output console. Before starting the main application we should make sure this configuration is reset to avoid interference (particularly the IRQ/ISR). This is not too important though since the main application reconfigures the UART for console output. Other peripheral could also be disabled (e.g. all other PIO used by DFU), but most of them also get configured by the main application. Change-Id: I8234d1b85938ad6393094c08183f613ad09ee01b --- firmware/libboard/common/include/uart_console.h | 1 + .../libboard/common/source/board_cstartup_gnu.c | 2 ++ firmware/libboard/common/source/uart_console.c | 16 ++++++++++++++++ 3 files changed, 19 insertions(+) diff --git a/firmware/libboard/common/include/uart_console.h b/firmware/libboard/common/include/uart_console.h index c48c2c1a..0e49bfd0 100644 --- a/firmware/libboard/common/include/uart_console.h +++ b/firmware/libboard/common/include/uart_console.h @@ -34,6 +34,7 @@ #include extern void UART_Configure( uint32_t dwBaudrate, uint32_t dwMasterClock ) ; +extern void UART_Exit(void) ; extern void UART_PutChar( uint8_t uc ) ; extern uint32_t UART_GetChar( void ) ; extern uint32_t UART_IsRxReady( void ) ; diff --git a/firmware/libboard/common/source/board_cstartup_gnu.c b/firmware/libboard/common/source/board_cstartup_gnu.c index 4b561ec5..42231fb2 100644 --- a/firmware/libboard/common/source/board_cstartup_gnu.c +++ b/firmware/libboard/common/source/board_cstartup_gnu.c @@ -173,6 +173,8 @@ void ResetException( void ) * the second entry in the vector table is the reset address, corresponding to the application start */ if (((*((uint32_t*)(IFLASH_ADDR+BOARD_DFU_BOOT_SIZE)))&0xFFFF0000)==0x20000000) { + UART_Exit(); + __disable_irq(); BootIntoApp(); /* Infinite loop */ while ( 1 ) ; diff --git a/firmware/libboard/common/source/uart_console.c b/firmware/libboard/common/source/uart_console.c index a47ba0cc..fe649229 100644 --- a/firmware/libboard/common/source/uart_console.c +++ b/firmware/libboard/common/source/uart_console.c @@ -103,6 +103,22 @@ extern void UART_Configure( uint32_t baudrate, uint32_t masterClock) _ucIsConsoleInitialized=1 ; } +/** + * \brief Disables the USART peripheral and related IRQ + */ +void UART_Exit(void) +{ + if (!_ucIsConsoleInitialized) { + return; + } + + Uart *pUart = CONSOLE_UART; + pUart->UART_IDR = UART_IDR_TXRDY; + pUart->UART_CR = UART_CR_RSTRX | UART_CR_RSTTX | UART_CR_RXDIS | UART_CR_TXDIS | UART_CR_RSTSTA; + PMC->PMC_PCDR0 = 1 << CONSOLE_ID; + NVIC_DisableIRQ(CONSOLE_IRQ); +} + /** Interrupt Service routine to transmit queued data */ void CONSOLE_ISR(void) {