Dual mode serial port driver

Use this forum for requesting small changes in ChibiOS. Large changes should be discussed in the development forum. This forum is NOT for support.
steved
Posts: 825
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 12 times
Been thanked: 135 times

Dual mode serial port driver

Postby steved » Wed Apr 05, 2017 1:24 pm

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.
Attachments
USARTv2_serial.zip
serial driver with callbacks on key events
(7.58 KiB) Downloaded 236 times

steved
Posts: 825
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 12 times
Been thanked: 135 times

Re: Dual mode serial port driver

Postby steved » Mon Apr 10, 2017 5:58 pm

I've done the same thing with the 32F4 serial driver; and also added the 'advanced' buffer allocation mechanism.
Attachments
USARTv1.zip
Serial driver with callback-driven option, advanced buffer handling capability
(6.64 KiB) Downloaded 238 times

steved
Posts: 825
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 12 times
Been thanked: 135 times

Re: Dual mode serial port driver

Postby steved » Wed Sep 25, 2019 8:30 am

Here's the version I'm currently using for Chibi 19. (I'm unlikely to update the v1 files)
Attachments
USARTv2.7z
(6.26 KiB) Downloaded 209 times


Return to “Small Change Requests”

Who is online

Users browsing this forum: No registered users and 23 guests