I've got an application running on a ATSAML21J8B that gets input from the uart in 6 byte chunks and then returns an ack or nack packet. This works great for the most part if they sending system does what it's supposed to do. However there are situations that can arise that cause issues. For instance, if the sender mistakenly sends an invalid 7 byte packet followed by 2 valid 6 byte packets my application will (correctly) resond with 3 nacks and then be in a situation where it has one leftover byte in it's receive buffer.
Any further valid packets sent will always cause a nack and an extraneous byte in the buffer. My application will then be sitting in the usart_read_buffer_job(). I'd like to use an external interrupt to somehow recover from this error condition, essentially clearing my receive buffer and breaking out of the usart_read_buffer_job() function. Conceptually, I'm not sure how to approach this problem. I have a slash and burn solution which is to just reset the processor, but I'd like to avoid this if possible as there is data in the application I'd like to retain after recovering from this condition. Any thoughts would be appreciated. Thanks.