Skip to main content
ANguy.1
Associate
December 20, 2019
Question

STM32L476 bus fault escalated hard fault in HAL uart_irq() when spamming USART2

  • December 20, 2019
  • 4 replies
  • 1030 views

Hi all,

Our team is developing on a custom PCB with STM32L476. And we are testing our CLI robustness, we found out that when we spam the CLI which uses USART2 at baud rate 115200, the program goes into hard fault. Upon investigating with a JLINK debugger, and looking at CFSR, we found we have precise bus fault. And the PC and LP both point to the function uart_irq() in serial_device.c. specifically line 0x080331b8:

if (__HAL_UART_GET_FLAG(huart, UART_FLAG_TXE) != RESET) {
0x080331b4 ldr r3, [sp, #16] 
0x080331b6 ldr r3, [r3, #0] 
0x080331b8 ldr r3, [r3, #28] 

  which is accessing USART_TypeDef's ISR attribute. And as the image shown below, R3+#28 is the memory address stored in BFAR.

0690X00000BuqNXQAZ.png

We've also found a post that might be relevant to this problem we are facing, but it happened on STM32F. And upon looking at USART2's register ISR, we found the ORE flag is tripped. And we are also using mbedOS on top of HAL if that matters.

Does anyone know why this is happening? And if this can be fixed? Thank you all.

This topic has been closed for replies.

4 replies

Pavel A.
December 20, 2019

Suspect memory corruption: the huart structure overwritten, thus the bad UART register address.

-- pa

Tesla DeLorean
Guru
December 20, 2019

Something is trashing huart->Instance it is being corrupted, perhaps an unbounded buffer write somewhere else. Perhaps huart is wrong, and thus the chain is broken.

Walk back up the code here, and add sanity checks to see when the pointer(s) get broken.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
ANguy.1
ANguy.1Author
Associate
December 20, 2019

So what I found is before the bus fault and hard fault, the memory map of huart->Instance shows

0690X00000But4nQAB.png

and after the fault, it shows:

0690X00000But4sQAB.png

which according to visualGDB I am running in visual studio, the memory region is not readable.

Tesla DeLorean
Guru
December 20, 2019

So got to unwind the pointers, and array, and index

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..