2024-07-30 01:30 AM - edited 2024-07-30 09:37 AM
If you enable Transmission Complete (TC) interrupt flag TCIE in the UART_CR1 register before enabling UART itself, the interrupt will still be be generated.
It is not possible to clear TC flag using USART_ICR TCCF in such state. The interrupt handler will be invoked infinitely, unless interrupt is disabled back in the CR1 register.
Steps to reproduce:
1. Write USART_CR1=0x20000048; Uart is disabled here (UE=0).
2. Enable UARTx_IRQ in NVIC; At this point interrupt handler will be invoked.
3. Inside Interrupt Handler, Try to reset TC flag by writing USART_ICR=0x40; It will fail. TC flag will stay active, application will hang because interrupt handler will be called infinitely.