Page 1 of 1

Dual mode serial port driver

Posted: Wed Apr 05, 2017 1:24 pm
by steved
I have a requirement to use a (STM32) serial port with either the serial or the UART drivers, dependent on a startup configuration option.

The main requirement not handled by the serial driver is the ability to process received data on a character-by character basis. On some devices its also necessary to know when the transmit buffer is empty.

I was able to add these features to the serial driver quite easily, as attached. The extra code is small enough that it could be left permanently enabled; adding a #define to enable it would also be straightforward.

Use in 'UART' mode is very similar to that of the existing UART driver - I've added four callbacks for the important events. If these are non-NULL, they are used; otherwise the normal serial driver processing takes place. I've assumed 'all or nothing' on the callbacks, although it may be possible to use just those which are wanted without confusing the queue routines. It should even be possible to swap modes on the fly, by simply updating the callbacks.

The serial driver is interrupt driven, which is fine for me - I mostly use the UART driver interrupt-driven anyway, due to DMA conflicts. Plus using DMA to receive single characters is probably less efficient than direct reception using interrupts.

Re: Dual mode serial port driver

Posted: Mon Apr 10, 2017 5:58 pm
by steved
I've done the same thing with the 32F4 serial driver; and also added the 'advanced' buffer allocation mechanism.

Re: Dual mode serial port driver

Posted: Wed Sep 25, 2019 8:30 am
by steved
Here's the version I'm currently using for Chibi 19. (I'm unlikely to update the v1 files)