Early TC event with 1 byte using serial STM32 USARTv1 driver

Report here problems in any of ChibiOS components. This forum is NOT for support.
psyco
Posts: 21
Joined: Fri May 22, 2020 1:40 am
Been thanked: 11 times

Early TC event with 1 byte using serial STM32 USARTv1 driver

Postby psyco » Sun Dec 20, 2020 1:07 am

My friend ran into an issue with an RS485 based serial interface where it seemed to drop bytes when receiving, but only when he was manually typing out data to it. Bulk transfers using a program were fine. What I found and believe to be the issue was actually in the transmit code from the STM32.

Effectively, the transmit complete interrupt was triggering before the 1 byte made it out. Writing to DR clears the TC interrupt, but USARTv1 didn't reread SR or clear out the TC flag. Since the queue was now empty (the one byte was sent), the TC event was fired.

Logic analyzer capture of the problem:

STM32F407_USARTv1_Current.png


And after the proposed fix:

STM32F407_USARTv1_Patched.png


The zip contains the patch along with a demo of how I tested this on the F407-Disco board demo. The patch just yanks the TX looping code from USARTv2. There is also the small benefit of skipping an interrupt when starting to send more than 1 byte.

USARTv2 isn't affected because of the loop while transmitting.
Attachments
usartv1_early_tc_fix.zip
(6.29 KiB) Downloaded 143 times

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: Early TC event with 1 byte using serial STM32 USARTv1 driver

Postby Giovanni » Sat Feb 13, 2021 10:19 am

bump


Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 20 guests