KL25 using UART2 and DMA

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

KL25 using UART2 and DMA

1,689 Views
neilhancock
Contributor IV

Hi

I'm using UART2/baud=115K+ with a DMA channel(2&3) as interrupts can be turned off for some period of time ~1mS.

I'm expecting an async packet in over UART2, variable size say 60-512bytes,

Is there a way of creating a packet timeout - no characters have arrived on UART2 for 50char timings.?

KL25P80M48SF0RM describes 4 standard DMAs and looking to see if I can possibly connect a timer in parallel and generate an INT when no char received,

Are there any AppNotes for connecting KL25  UART to DMA?

thanks

Labels (1)
6 Replies

892 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Neil Hancock,

    About the document of KL25 UART to DMA,  acutally, in our quick reference, the chapter 7, Direct Memory Access controller, there has an example interpretation about it.

  the quick reference link is:

http://cache.freescale.com/files/32bit/doc/quick_ref_guide/KLQRUG.pdf?fpsp=1&WT_TYPE=Users Guides&WT_VENDOR=FREESCALE&WT_FILE_FORMAT=pdf&WT_ASSET=Documentation

  You can refer it!

  Wish it helps you!

Jing

892 Views
neilhancock
Contributor IV

Hello Jing

Thankyou for the pointers to the KLQRUG and also I pulled in the "KL25 Sample Code" and following

"KL25 Sample Code\kl25_sc_rev10\klxx-sc-baremetal\src\projects\low_power_dma_uart_demo"

and it gives me the sequence of DMA init as a reference.

I don't have the "Freedom board" to try it,  I'm using a custom board that has the UART already working in simple polled mode.

The second part of my question was how to detect if there is a UART Rx char timeout?

Seems like a standard requirement for the real world - async characters arrive, and when there are no characters arriving for 'X' mSecs, an async timeout interrupt is generated in some fashion.

So I'm curious if anybody sees a solution?

If I could route the UART Rx arrival/dma request to a Timer this might work - that is the first UART Rx received initializes a count down timer and starts a countdown.

For every UART Rx after that it intializes the timer again. When the timer reaches 0, indicating no UART Rx in time period, it generates INT and wakes up the cpu.

The low_power_dma_uart_demo example has a poll of the uart, which seems to contradict the idea of being low power by having the cpu running and monitoring for a full buffer from the UART Rx. For a UART Rx its not usual to know the size of the Rx packet before it starts, so possibly not a real world example.

    // Wait for the DMA buffer to become full.

    while (dma_done == 0)    {

      if((DMA_DSR_BCR0 & DMA_DSR_BCR_DONE_MASK) == DMA_DSR_BCR_DONE_MASK)       {

          // Set DMA semaphore and write DMA Done bit when buffer is full. 

        DMA_DSR_BCR0 |= DMA_DSR_BCR_DONE_MASK;

        dma_done = 1;

      }

    }

thanks

0 Kudos

892 Views
mjbcswitzerland
Specialist V

Hi Neil

I have used the Kinetis in some projects requiring idle line detection and have always used a HW timer triggered by Rx interrupt to do it (up to 115kBaud). This has meant that I haven't used the UARTs in DMA mode for such an application - although I have had some others channels running parallel in DMA reception mode (around 1.5MBaud), which didn't need the timing.

As far as I am aware the UARTs in the Kinetis miss an idle line timer - I have used the same code on ATMEL SAMs (USARTs) which do have an in-built idle timer which is very comfortable since it gives an interrupt when there has been x idle bit periods (1..255 or so programmable).

If UART interrupt mode is not an alternative I would try one of the following:

- have a periodic timer interrupt set up that looks at the Rx DMA counter and flags when it hasn't changed for a certain amount of samples (the processor could also sleep between timer interrupts)

- your idea of retriggering a timer from UART dma is also very good and is probably possible

- the other possibility would be to attach the UART Rx input to another pin (HW change) to allow falling edges to retrigger a HW timer which fires (and wakes the processor) when there is no activity for the programmed period.

Regards

Mark

892 Views
neilhancock
Contributor IV

Hi Mark

Many thanks - appreciate the insight, and suggested options. I can make the periodic timer work till I get another option

I was hoping a tech support guy would comment on how to route the UART Rx  signal to a Timer.

If nothing else I will look at the pin map for the next hw turn to allocate a 2nd physical pin to the Uart Rx to monitor it

thanks

0 Kudos

892 Views
mjbcswitzerland
Specialist V

Neil

To retrigger the timer I would configure a DMA channel to write one word (muxed) from memory to a timer control register each time it is triggered by the UART Rx. The content of the single word can be defined so that it performs a retrigger (the value that SW would write to do the same).

I only started working with the KL family a few days ago and have seen that some of the peripherals are slightly different, or have reduced functionality (compared to the K series) so I don't know where the KL DMA limitations are at the moment.

Regards

Mark

892 Views
neilhancock
Contributor IV

Mark, thanks. I'm exploring the KL family as well, and tripping over the differences with the K series.

Will let you know what I make work.

Cheers

Neil

0 Kudos