cancel
Showing results for 
Search instead for 
Did you mean: 

How to debug properly UART interrupts?

BHowa
Associate

My UART works well in normal mode, but when I want to analyze callbacks for Rx in debug mode it doesn't work properly. I mean when I set breakpoint at HAL_UART_RxCpltCallback and I'will send bytes from terminal, debugger stops at this callback and doesn't perform appropriate amount of calls. This is my code:

#define BUFF_SIZE 255
 
char BUFF_RX[BUFF_SIZE];
 
__IO uint8_t BUSY_RX = 0;
__IO uint8_t EMPTY_RX = 0;
 
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) {
	if(huart == &huart2) {
		EMPTY_RX++;
		if(EMPTY_RX >= BUFF_SIZE)
			EMPTY_RX = 0;
		HAL_UART_Receive_IT(&huart2, (uint8_t *)&BUFF_RX[EMPTY_RX], 1);
	}
}
 
int main() {
   /* CubeMX initializations etc */
   HAL_UART_Receive_IT(&huart2, (uint8_t *)&BUFF_RX[0], 1);
}

Steps:

  1. Set breakpoint at Rx callback
  2. Run debugger and press "Resume"
  3. Send bytes from terminal
  4. Debugger stops at callback and in BUFF_RX[0] is first byte
  5. Press resume for another receive
  6. Debugger stops at callback and in BUFF_RX[1] is second char
  7. Press resume for another receive
  8. Debugger stops showing next calls <---- [PROBLEM]

For this operation i send 4 bytes.

2 REPLIES 2

Real time systems don't function well when stopped.

Make sure the USART isn't flagging errors (overrun, etc) as a result of you stopping things.

The debugger will damage the USART state if you inspect it. ie showing you DR clears SR.RXNE.

Try to debug in ways that doesn't require human interaction.

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

I think even running with a debugger is slower than running free. So I miss bytes.

Try Arduino mode debugging. Use flags and print " I am here at #12775"