FX3 UART DMA ISR

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
E_521156
Level 4
Level 4
100 sign-ins 50 replies posted 50 sign-ins

Hi,
I used cyfxuartlpdmamode example and modified the channel to UART-> CPU ( MANUAL IN) and another channel CPU ->UART (MANUAL OUT). I attached my new firmware.  I used the UART event(UartIsr). I send data from Teraterm, I got ISR after sending 16-bytes(DMA size). I put a fixed buffer, when I got the ISR, I send that data to Teraterm. Up to here, everything is ok. But I have 2 problems:
1- I don't get another ISR. I mean I sent 16 bytes first time, I got letters A to Q (fixed buffer) in Teraterm, but again I entered another 16 bytes and I expected to get another ISR, but I don't get. I think the previous event hasn't had clear, and I don't know how I should do that.(SendDebugMessage(buf, len))

2- When I try to replace the fixed buffer with the input buffer, I got nothing. (SendDebugMessage(buf_p.buffer, len))

Could you please help me on this matter?

Thanks

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.

Hello,

Please refer to the attached firmware.

I have tested this at my end and it is working as expected. Please check this at your end and let me know if it works.

I tried sending "1234567891234567" and received the same. I could do this multiple times.

uart_test.PNG

Regards,
Rashi

View solution in original post

0 Likes
20 Replies
Rashi_Vatsa
Moderator
Moderator
Moderator
5 likes given 500 solutions authored 1000 replies posted

Hello,

The Rx transfer size is set to 16 which means CY_U3P_UART_EVENT_RX_DONE will be triggered when 16 bytes are received by UART RX of FX3.

Please set UART rx transfer size (CyU3PUartRxSetBlockXfer) every time 16 bytes are received (CY_U3P_UART_EVENT_RX_DONE triggered)

Also, let me know why CyU3PDmaChannelSetWrapUp and CyU3PDmaChannelReset are called in UartIsr as full buffers are received.

Regards,
Rashi
0 Likes
lock attach
Attachments are accessible only for community members.

Hi,
I did that changes but not works with previous structure.
I change my code as follows:

void UartIsr (
CyU3PUartEvt_t evt, 
CyU3PUartError_t error )
{    if (evt == CY_U3P_UART_EVENT_RX_DONE)
     {
          UART_ready = CyTrue;
           CyU3PUartRxSetBlockXfer(16);
     }

}

and added the following code in UartLpAppThread_Entry:

for (;;)
{
     if(UART_ready)
    {   uint8_t buf[len];
        int i;
        for( i = 0; i < len; i++)
              buf[i] = i+65;
       SendDebugMessage(buf, len);
      UART_ready = CyFalse;
}
}

I put a gpio in SendDebugMessage which set and reset. so I can see that after every 16-bytes  ISR happens and it goes to SendDebugMessage . but only the first time the fixed buffer values comes out.

when I tested the below code to get whatever I sent, again based on GPIO (that I looked at it on oscilloscope), I can see the ISR happens, but nothing comes out on Teraterm.

for (;;)
{
if(UART_ready)
{
     status = CyU3PDmaChannelSetupRecvBuffer(&glUartRXChHandle, &buf_p);
      SendDebugMessage(buf_p.buffer, len);
      UART_ready = CyFalse;
}

I attached the firmware.
Thanks

0 Likes
Rashi_Vatsa
Moderator
Moderator
Moderator
5 likes given 500 solutions authored 1000 replies posted

Hello,

The CyU3PUartTxSetBlockXfer also needs to be called after every buffer is transferred back on UART TX similar to CyU3PUartRxSetBlockXfer is called when every buffer is received by UART RX. A counter is set using CyU3PUartTxSetBlockXfer/CyU3PUartRxSetBlockXfer API which will count the data transmitted/received. In your application the API is expected to be called once the data is transferred completely.

Please call CyU3PUartTxSetBlockXfer every time once the data is transferred on the Tera term .

Please let me know if any queries on this

Regards,
Rashi
0 Likes
lock attach
Attachments are accessible only for community members.

Hello,
Thank you Rashi. I add CyU3PUartTxSetBlockXfer to  SendDebugMessage  function. Now the first part of my  last question works fine. Thanks for that again.
But the second part still has problem.

when I tested the below code to receive whatever I sent (not loopback, receive and then transmit), again based on GPIO, I can see the ISR happens, but nothing comes out on Teraterm.

for (;;)
{
if(UART_ready)
{
     status = CyU3PDmaChannelSetupRecvBuffer(&glUartRXChHandle, &buf_p);
     CyU3PDmaChannelWaitForCompletion(&glUartRXChHandle, CYU3P_WAIT_FOREVER);
      SendDebugMessage(buf_p.buffer, len);
      UART_ready = CyFalse;
}

0 Likes
Rashi_Vatsa
Moderator
Moderator
Moderator
5 likes given 500 solutions authored 1000 replies posted

Hello,

Please let me know if GPIO 38 is set to false when the issue happens. This is to check if CyU3PDmaChannelSetupSendBuffer API returns CY_U3P_SUCCESS

Regards,
Rashi
0 Likes

 Hi,
GPIO 38 is low unless the ISR happens(16-byte being received from Teraterm)after that again goes back to low. I can see that after every 16-bytes  ISR happens and it goes to SendDebugMessage and gpio goes high and low(in osciloscope).

To ensure that CyU3PDmaChannelSetupSendBuffer works well, I tested with a fixed buffer and it works fine. but when I used from data in DMA IN (glUartRXChHandle), I received nothing in Teraterm, however it is got the ISR and it goes to SendDebugMessage and back. It seems that something is wrong with DMA IN buffer.
Thanks

0 Likes
Rashi_Vatsa
Moderator
Moderator
Moderator
5 likes given 500 solutions authored 1000 replies posted

Hello,

Thanks for the details

Please let me know if you have checked the buffer received through CyU3PDmaChannelSetupRecvBuffer. Please check the first few bytes to check if the data is received properly.

You can also check if CyU3PDmaChannelWaitForCompletion returns success just to confirm that the buffer is received properly.

If the buffer received properly, the buffer can be check inside SendDebugMessage before calling CyU3PDmaChannelSetupSendBuffer to check if the passing of buffer is as expected.

Regards,
Rashi
0 Likes

Hello,
status of CyU3PDmaChannelSetupRecvBuffer is success.
but for:
 status = CyU3PDmaChannelWaitForCompletion(&glUartRXChHandle, YYYYYY);
 if  I put:  YYYYYY =CYU3P_WAIT_FOREVER or  CYU3P_NO_WAIT  ==> 
       status = CY_U3P_ERROR_BAD_ARGUMENT(0x40)
 if  I put:  YYYYYY = 0x7ffff  ==>    status = CY_U3P_ERROR_NOT_STARTED(0x42)


Thanks


0 Likes
Rashi_Vatsa
Moderator
Moderator
Moderator
5 likes given 500 solutions authored 1000 replies posted

Hello,

Please comment out the CyU3PUartRxSetBlockXfer called in CY_U3P_UART_EVENT_RX_DONE and check if one buffer is received properly i.e. CyU3PDmaChannelWaitForCompletion and CyU3PDmaChannelWaitForCompletion are success

If yes, please call CyU3PUartRxSetBlockXfer after CyU3PDmaChannelWaitForCompletion is success.

Regards,
Rashi
0 Likes
lock attach
Attachments are accessible only for community members.

Hi,
When I comment out the CyU3PUartRxSetBlockXfer,  the problem is same as before.  I also used CyU3PDmaChannelGetBuffer,  but same problem exist.

I change the code again, I used these part of codes in UartIsr, 
- with fixed buffer ==> every thing works fine.
- with Dma buffer, using CyU3PDmaChannelSetupRecvBuffer ==> in debug mode I can see ,it stuck in Main function.
-with DMA buffer, using CyU3PDmaChannelGetBuffer ==> I got ISR and receive some garbage in teraterm after every ISR and uart error is CY_U3P_UART_ERROR_NAK_BYTE_0.
I attached new firmware.

I should mention that I did this test(send and then receive data ) in RegMode and It work fine. I mean it shouldn't be hardware issue.
Thanks

0 Likes
lock attach
Attachments are accessible only for community members.
Rashi_Vatsa
Moderator
Moderator
Moderator
5 likes given 500 solutions authored 1000 replies posted

Hello,

Please find the attached firmware with modifications according to bulklpmaninout firmware of the SDK. This will be enabled only when the macro no_override is enabled.

I have done some modifications to the override mode also.  Please confirm that CY_U3P_UART_EVENT_RX_DONE is not called repeatedly when only 16 bytes are received by Fx3 (i.e. CY_U3P_UART_EVENT_RX_DONE is called once per 16 bytes received)

Please check this firmware for both modes and let me know if the any API fails.

Regards,
Rashi
0 Likes

Hello,
 if not_override enable :  I received the first ISR, I mean after 16-byte, I got whatever I sent. but ISR never happens again.  It is weird that only ISR happens when it was in debug mode.  without debug mode, I didn't get that only ISR even.

 if not_override disable(overide mode) : 
CyU3PDmaChannelSetupRecvBuffer got error CY_U3P_ERROR_BAD_ARGUMENT
Thanks

0 Likes
lock attach
Attachments are accessible only for community members.
Rashi_Vatsa
Moderator
Moderator
Moderator
5 likes given 500 solutions authored 1000 replies posted

Hello,

I understand that if for no_override enabled, the 16 bytes data is received and transmitted as expected. Is that correct?

For no_override enabled the ISR will not be triggered as callback is not registered during Uart configuration

 apiRetStatus = CyU3PUartSetConfig (&uartConfig, NULL);

In this case when 16 bytes of data is sent to FX3 over UART the producer event will be triggered which will enable Uart_ready and copy the data into another buffer which will be sent to UART Tx. It is similar to bulklpmaninout firmware. The CY_U3P_DMA_CB_PROD_EVENT will be triggered only when complete 16 bytes are received by UART RX. 

Please try the following for no_override enabled

- Send 16 bytes data to UART RX

- Check if CY_U3P_DMA_CB_PROD_EVENT is triggered

- Check if the same data is received at UART TX and check for CY_U3P_DMA_CB_CONS_EVENT

- Send the next 16 bytes of data to UART RX

For no_override disabled, I have modified the firmware again. Please let me know if this works.

Regards,
Rashi
0 Likes

Hi,
I really appreciate your support and useful comments.
For no_override enabled,  I follow those steps. Your code works well. But because of my hardware configuration (using half duplex chip), I have to set a gpio to 1 in TX duration to get data in the output of my chip. But when I put CyU3PGpioSetValue (38, CyTrue) before CyU3PDmaChannelCommitBuffer, I can see that when the code reach to this line, it jumps to DMA callback/CY_U3P_DMA_CB_PROD_EVENT.  and stuck there.


For no_override disabled,  the problem with this new firmware  is that it stuck in CyU3PDmaChannelWaitForCompletion with CYU3P_WAIT_FOREVER.
When I changed it to CYU3P_NO_WAIT, it got CY_U3P_ERROR_TIMEOUT.
Thanks

0 Likes
lock attach
Attachments are accessible only for community members.
Rashi_Vatsa
Moderator
Moderator
Moderator
5 likes given 500 solutions authored 1000 replies posted

Hello, 

Please use the firmware in no override enable mode,  try using the GPIO and let me know if this works.

Meanwhile I will check for the other case

Regards,
Rashi
0 Likes

Hi Rashi,
It doesn't work with gpio, however without gpio also it went to  DMA callback  only once.

As I mentioned before, in the previous firmware(with CyU3PDmaChannelSetXfer (&glUartTXChHandle, 0)), it works without gpio not with gpio.
Thanks

0 Likes
lock attach
Attachments are accessible only for community members.
Rashi_Vatsa
Moderator
Moderator
Moderator
5 likes given 500 solutions authored 1000 replies posted

Hello,

Please let me know if the GPIO is set when GPIO set API is called before commit buffer.

I had changed the second parameter of CyU3PDmaChannelSetXfer as you were getting prod event after receiving 16 bytes of data. Calling CyU3PDmaChannelSetXfer with definite bytes will not allow any more transfer once the defines bytes are received. We need to call CyU3PDmaChannelSetXfer again with definite bytes to start the transfer again.

I have now called setxfer (TX) api once the producer event for the RX channel is received and setxfer (RX) is called when data is transmitted over UART i.e. cons event.

Please try setting the GPIO when the data received (inside prod event handler)  so that the remote transmitter is stopped and receiver (remote) is started.

Please follow these steps,

- Send only 16 bytes of data to FX3

- Check if Producer event is triggered, tx channel is initialized (returns success) and gpio is set

- Then the DMA buffer will be copied and committed

- check if the Cons event is triggered, rx channel is initialized (returns success) and set the gpio

- Now, repeat above steps

Please let me know if this works.

Regards,
Rashi
0 Likes
lock attach
Attachments are accessible only for community members.

Hello,

Please refer to the attached firmware.

I have tested this at my end and it is working as expected. Please check this at your end and let me know if it works.

I tried sending "1234567891234567" and received the same. I could do this multiple times.

uart_test.PNG

Regards,
Rashi
0 Likes

Thank you vermuch Rashi,
I changed a few line for my setup, now it works. I write them here if anyone need in future.

CyU3PGpioSetValue (38, CyTrue);
status = CyU3PDmaChannelCommitBuffer (&glUartTXChHandle, inBuf_p.count, 0);
CyU3PBusyWait(86.8*15);// len-1
CyU3PGpioSetValue (38, CyFalse);


Regards,

0 Likes
Rashi_Vatsa
Moderator
Moderator
Moderator
5 likes given 500 solutions authored 1000 replies posted

Hello,

Glad to hear the the firmware worked at your end too!

Regards,
Rashi
0 Likes