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