How to configure DMA to extract values from UART in PE?

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

How to configure DMA to extract values from UART in PE?

1,875 Views
Amit_Kumar1
Senior Contributor II

Hi

I am using K60 uc and receiving data over UART in continuous form, beside the data I am doing other processing but due to UART my program is getting delayed so I wanted to use DMA so that both the process works simultaneously. Do we have any document regarding this to make it work?

Thanks

Amit Kumar

9 Replies

1,064 Views
Petr_H
NXP Employee
NXP Employee

Hi,

The component DMA_Channel can be used for receiving the data via DMA.

I attach a simple project that trasmits 8 characters (normally) and receives 8 characters via DMA. You can see the components configuration there and a basic code in the main function.

Best regards

Petr Hradsky

Processor Expert Support Team

0 Kudos

1,064 Views
Amit_Kumar1
Senior Contributor II

Hi Petr

Thanks for the code.I will have a look on the code and let you know if I find any problems. One more thing I wanted to ask regarding UART is  when we use the receive function in UART ie      AS1_ReceiveBlock(serial, rbuff, sizeof(rbuff));    in this case if the size of rbuff is 10 char, and the data transmitted is 4 char, and we try to read it , it is not readable .i.e when the next command is received and the buffer is full i.e it contains 10 char then only we are able to read the buffer. Is there any solution for this ? If I want to read the data buffer which is not yet full than how do we do that ??

Thanks and Regards

Amit Kumar

0 Kudos

1,064 Views
Petr_H
NXP Employee
NXP Employee

Is there any reason why are you using AsynchroSerial component ? If not, I recommend to use Serial_LDD component instead (it's also used in my example). With that you are using your own buffer that you pass as a pointer to the receive function. There is also a function that you can use for checking the number of receved/sent characters.

Best regards

Petr Hradsky

Processor Expert Support Team

1,064 Views
Amit_Kumar1
Senior Contributor II

Hi Petr

I am using Serial_LDD only the one which is present in your sample code. It automatically Assigns the name I think . See in the image also in your program , it is named as such.

serial_ldd.jpg

So My issue was if we define the size of the buffer as 100 and only 4 char is received and we want to print that char. I am not able to do so... It Gets printed once all the 100 values are filled by the upcoming data. Is there any way to get access over any incoming data if the buffer is not filled ?

Thanks & Regards

Amit Kumar

0 Kudos

1,063 Views
Petr_H
NXP Employee
NXP Employee

Yes, sorry, you are right, I thought from the name that it's AsynchroSerial.

Regarding the printing of the buffer content, you can enable the method GetTransferredDataSize (switch to 'Advanced' view mode in the inspector) and use it for getting the already received number of characters.

Best regards

Petr Hradsky

Processor Expert Support Team

0 Kudos

1,063 Views
Amit_Kumar1
Senior Contributor II

Hi Petr

I am able to get the size of the received data, but my problem is in the following command, AS1_ReceiveBlock(serial, rbuff, 100); 100 is the size of the receiving buffer  so if the size of received characters is 5 and I try to print that , it is not able to print that characters. It is only printing the characters only if 100 characters will be filled else It will wait for it to get filled. The problem in keeping fixed buffer size is that if my incoming buffer is varying so in that case it can be accessible easily. In datasheet it is mentioned that we can use FIFO but how to configure it I am unable to find.

Thanks & Regards

Amit Kumar

0 Kudos

1,063 Views
Petr_H
NXP Employee
NXP Employee

I don't know how you are using the component, but you're probably not using my example, because it does not use ReceiveBlock, DMA is used instead. I woul'd need to see the code.

Anyway, regarding the ReceiveBlock - it does not wait for receiving the data. There is probably some loop waiting in your code for the result or you are using the event that is invoked after you receive the data. But you do not have to wait, you can enable and call GetReceivedData of AS1 component to check how many characters are already in the buffer.

However, please note that the data are still received into one buffer that you passed to ReceiveBlock so if you will print or process only part of the buffer, new incoming characters are still being added at the end in background.

Regarding FIFO, I think that this is internal hardware buffer that is not accessible by the user.

Best regards

Petr Hradsky

Processor Expert Support Team

1,063 Views
Amit_Kumar1
Senior Contributor II

Hi Petr

I Due to some technical fault in my K60 board I was not able to test your code instead I Copied the settings to a K20D50M- FRDM board but it didn't work Can you please check out what I am doing wrong ? I am getting nothing in the terminal windows even after typing. I have checked the baud rate. I am attaching my K20 board's DMA code which I copied from the one which u send.

Thanks & Regards

Amit Kumar

0 Kudos

1,063 Views
marek_neuzil
NXP Employee
NXP Employee

Hello,

The K20DMA project is OK but the DMA_LDD component (DMAInit function) contain an error in CW MCU 10.5 (the project works in CW MCU 10.6.1 when it is imported, re-generated and builded).

There is an workaround for this issue. Open the file MCU\ProcessorExpert\lib\Kinetis\pdd\inc\SIM_PDD.h in your CW MCU 10.5 installation and do the following modification:

Rename the symbol SIM_PDD_CLOCK_GATE_DMA_MULTIPLEXOR to SIM_PDD_CLOCK_GATE_DMA_MULTIPLEXOR0 for the MCU_MK20D5.

....
#elif ((defined(MCU_MK20D5)) || (defined(MCU_PCK20L4)))
/* Clock gate identifiers */
  #define SIM_PDD_CLOCK_GATE_EWM            0x61U /**< Clock gate identifier for External watchdog */
  #define SIM_PDD_CLOCK_GATE_CMT            0x62U /**< Clock gate identifier for Carrier modulator timer (CMT) */
  #define SIM_PDD_CLOCK_GATE_I2C0            0x66U /**< Clock gate identifier for I2C0 */
  #define SIM_PDD_CLOCK_GATE_UART0          0x6AU /**< Clock gate identifier for UART 0 */
  #define SIM_PDD_CLOCK_GATE_UART1          0x6BU /**< Clock gate identifier for UART 1 */
  #define SIM_PDD_CLOCK_GATE_UART2          0x6CU /**< Clock gate identifier for UART 2 */
  #define SIM_PDD_CLOCK_GATE_USB0            0x72U /**< Clock gate identifier for USB OTG FS/LS */
  #define SIM_PDD_CLOCK_GATE_CMP            0x73U /**< Clock gate identifier for High-speed comparator (CMP)/6-bit digital-to-analog converter (DAC) */
  #define SIM_PDD_CLOCK_GATE_VREF            0x74U /**< Clock gate identifier for Voltage reference (VREF) */
  #define SIM_PDD_CLOCK_GATE_LPTMR0          0x80U /**< Clock gate identifier for Low-power timer (LPTMR) */
  #define SIM_PDD_CLOCK_GATE_TSI0            0x85U /**< Clock gate identifier for Touch sense interface (TSI) */
  #define SIM_PDD_CLOCK_GATE_PORTA          0x89U /**< Clock gate identifier for Port A control */
  #define SIM_PDD_CLOCK_GATE_PORTB          0x8AU /**< Clock gate identifier for Port B control */
  #define SIM_PDD_CLOCK_GATE_PORTC          0x8BU /**< Clock gate identifier for Port C control */
  #define SIM_PDD_CLOCK_GATE_PORTD          0x8CU /**< Clock gate identifier for Port D control */
  #define SIM_PDD_CLOCK_GATE_PORTE          0x8DU /**< Clock gate identifier for Port E control */
  #define SIM_PDD_CLOCK_GATE_FTFL            0xA0U /**< Clock gate identifier for Flash memory */
  #define SIM_PDD_CLOCK_GATE_DMA_MULTIPLEXOR0 0xA1U /**< Clock gate identifier for DMA channel mutiplexor */
...

It is a static file and therefore these changes will not be influenced by generating code in PEx.

Best Regards,

Marek Neuzil