I'm using the UART and have set up an UART receive interrupt that reads the received byte value and puts it in a circular buffer.
But when I try higher baud rates I sometimes get over run errors.
Is it possible to use the DMA in some way together with my circular buffer?
Or is it only possible to receive a determined number of bytes with the DMA?
Now I have tested some code.
I think I must link two DMA channels. But now I don't know how to do that. I need some examples.
已解决! 转到解答。
Hi,
I apologize for the delay. I have attached some code that shows how to create a continuous circular buffer using DMA. If you have any questions, please let me know. This code was developed in IAR from Freescale Sample Code for KL25.
Best regards,
Martyn
EDIT: Modified source files for a two DMA channel solution.
Hello all,
I've implemented in a KL05 the solution to this problem provided by Martyn, but I get a configuration error (CE) when the linked DMA channel 2 tries to clear the DONE bit in the register BCR of the DMA channel 0. Has someone else had this problem?
Thanks in advance.
Best,
Francisco
Thanks Santiago and Mark,
Finally I managed to get the code to work as it is. The problem was that I've configured a breakpoint in the IRQ handler of DMA2, and this somehow generated the problem. It seems as if the DMA2 gets a second request before clearing the DONE bit while the CPU is suspended because of the breakpoint, and this generates the Configuration Error in DMA2. I don't have time to dig deeper into the matter, but it would be interesting.
Thanks again.
Best,
Francisco
Hi
I don't see any reason why the linked DMA channel 2 operation should fail: Are you sure that the failure is not due to channel 0 because in the case of circular buffer operation the circular buffer must have a vaid length and also be aligned on an address that is divisible by the buffer length. If the buffer alignment is incorrect it will fail.
The probem with linking DMA to do this is that the DMA channels are ineffciently consumed (there are only 4, so each is valuable) - in many case it is more efficient to not link like this but instead just have a timer interrupt or a task regularly writing DMA channel 0's transfer count to its maximum value again so that it never completes.
It is a shame that the KL DMA doesn't have a free-run mode (like the DMA in the K parts) - eg. to just stop counting down the transfer count value - the designers made quite a boner in this instance because they made doing something that should be as easy as pie into a silly excercise to overcome its annoying behaviour.
Regards
Mark
Hi
The uTasker Kinetis project includes UART DMA reception support on one or more UARTs (up to 6 at one time).
- Each UART can be configured to inform the application when a full circular buffer content is ready (not often useful since the reception is blocked until the buffer is read)
- Alternatively the circular buffer can operate in half-buffer mode, meaning that there will be a notification when the buffer is half-full so that the application has a half-buffer time to clear the buffer for re-use (ping-pong operation)
- Finally a free-running DMA mode is configable where the DMA continuously fills the circular buffer. The application should regularly check the state of the buffer and clear content before the DMA overwrites the buffer again. There are no interrupts ever needed for this mode.
The free-running DMA Rx has proven very useful for high speed UART operation with it being used successfully in a design with 6 UARTs operating in parallel at over 3 MBaud.
Regards
Mark
Hi,
I apologize for the delay. I have attached some code that shows how to create a continuous circular buffer using DMA. If you have any questions, please let me know. This code was developed in IAR from Freescale Sample Code for KL25.
Best regards,
Martyn
EDIT: Modified source files for a two DMA channel solution.