r2axz / bluepill-serial-monster

USB to 3 Port Serial (UART) adapter firmware for STM32 Blue Pill.
MIT License
323 stars 76 forks source link

Use DMA polling instead of TC/HT and USART IDLE interrupts for RX buffer updates #44

Closed r2axz closed 2 years ago

r2axz commented 3 years ago

It seems that using DMA TC/HC interrupts in conjunction with the USART IDLE interrupt for updating RX buffers head positions is a wrong strategy in the case of a USB to UART bridge.

Consider the following scenario: a low-speed device (say 2400, 9600 baud) connected to UART sends a steady stream of bytes. There are no gaps in transmission, so that the USART IDLE interrupt never triggers. On the other hand, since the RX buffers on bluepill-serial-monster are relatively large, the firmware will not send the content of the RX buffer to the host until DMA TC/HC triggers. While it does not lead to data loss, it creates a noticeable delay which can be critical for applications that rely on RX timing.

On the other hand, the firmware can only send the data to the host in the USB polling loop, so it makes perfect sense to update circular buffers there as well.

As a side effect, this change introduces a slight delay in the RTS signal handling. It looks like it should not be a problem, however this requires some additional testing.

r2axz commented 2 years ago

Also, it has been reported that ser2net freezes occasionally with the main firmware while works just fine with this modification.