cancel
Showing results for 
Search instead for 
Did you mean: 

USB Superspeed Peripherals

New Contributor II

I would like to use UART on an FX3 in DMA mode, but I have variable sized packets.

The DMA architecture refers to producers sockets being able to signal End of Packet (EOP) to cause partially filled DMA buffers to be committed.

Is there a method to specify a bit pattern e.g. ASCII ETX (0x03) in the received data so that the UART or DMA adapter can signal EOP.

I have variable length packets using an ASCII protocol in the format as follows: -

<STX><variable length data converted to ASCII HEX><16 bit CRC converted to ASCII HEX><ETX>

I have used register mode transfers which works but appears to consume lots of CPU time.

I am hoping that changing to DMA mode will be more efficient but I cannot see how to cope with variable sized packets.

0 Likes
Reply
1 Solution
New Contributor II

Hi Jayakrishna,

Thank you for your suggestion.

Unfortunately I cannot change to Auto mode as I have to to do some processing of the packets in the FX3 code.

I have found a solution.

I set the receive block size to 18,

CyU3PUartRxSetBlockXfer(18)

I can change the code transmitting the packets to pad the longer packets to a multiple of 18.

So 524 packet is transmitted as a 540 packet.

The end of the longer packets is padded with ETX characters.

The receiving code if it detects a longer packet (which I know from the starting bytes) the FX3 code just adds it to a local buffer and discards the DMA buffer until it gets a DMA buffer that ends with ETX is received.

It then processes the buffered complete packet.

It seems to work...

Best Regards

Keith

View solution in original post

0 Likes
Reply
7 Replies
Moderator
Moderator

Hello,

According to my understanding, UART is the producer socket and USB is the consumer socket. Please correct me if Iam wrong.

Also, can you please elaborate your requirement as I did not understand it properly.

Best Regards,

Jayakrishna

Best Regards,
Jayakrishna
0 Likes
Reply
New Contributor II

Hello

Thank you for replying.

The USB connection is used for upgrading the firmware only.

In normal operation all communications is through the UART serial interface using optical modems.

This is because the FX3 electronics is next to some high Voltage supplies and the PC needs to be electrically separated from the FX3.

So the UART is the producer and consumer for the DMA channel

I am creating a DMA channel in manual mode with a call back function as below

//

// EstablishDMAChannelForUART()

//

// Create a DMA Manual channel between UART producer

// and UART consumer sockets

//

CyU3PReturnStatus_t EstablishDMAChannelForUART()

{

CyU3PDmaChannelConfig_t dmaConfig;

CyU3PMemSet((uint8_t *)&dmaConfig, 0, sizeof(dmaConfig));

dmaConfig.size = 524;

dmaConfig.count = 4;

dmaConfig.dmaMode = CY_U3P_DMA_MODE_BYTE;

dmaConfig.prodHeader = 0;

dmaConfig.prodFooter = 0;

dmaConfig.consHeader = 0;

dmaConfig.prodAvailCount = 0;

dmaConfig.notification = CY_U3P_DMA_CB_PROD_EVENT;

dmaConfig.cb = CyFxUARTProducerDMACallback;

dmaConfig.prodSckId = CY_U3P_LPP_SOCKET_UART_PROD;

dmaConfig.consSckId = CY_U3P_LPP_SOCKET_UART_CONS;

// Create the channel

if (CyU3PDmaChannelCreate(&glChHandleUART_prod_cons, CY_U3P_DMA_TYPE_MANUAL, &dmaConfig) != CY_U3P_SUCCESS)

g_iWhileFail = 7;

if (CyU3PDmaChannelSetXfer(&glChHandleUART_prod_cons, 0) != CY_U3P_SUCCESS)

g_iWhileFail = 8;

return CY_U3P_SUCCESS;

}

The problem is some packets will be 18 bytes long and some up to 524 bytes long.

If all packets are the same size then there is no problem.

If short packets are received then I wanted to use ASCII ETX ( 0x03) to denote the end of a packet and commit the buffer

similar the calling

     CyU3PDmaChannelSetWrapUp(&glChHandleUART_prod_cons);

Otherwise the DMA buffer waits for 524 byte to arrive before calling the call back.

Is there a way of configuring UART or DMA to recognise ETX  character and to perform End Of Packet EOP.

Regards

Keith

0 Likes
Reply
Moderator
Moderator

Hello,

Please let me know if the incoming data to FX3 is of a regular pattern or not. That is, if it has a pattern as shown below:

<524 bytes> <524 bytes> .... <18 bytes>

Also, are these 524 bytes and 18 bytes are the only packet sizes or is it just an example and you see variable length packet always in such a way that the maximum size can never exceed 524 bytes?

Best Regards,

Jayakrishna

Best Regards,
Jayakrishna
0 Likes
Reply
New Contributor II

Hi Jayakrishna.

Again thank you for replying.

Most of the time the packets are <18 byte> and only occasionally <524 bytes>.

There is no pattern as to when the longer packets are needed.

There are only two packet sizes used at present, 18 and 524.

It would be nice to have more flexibility, if possible, but not essential at present.

If you have any suggestions then they are welcome.

Best regards

Keith

0 Likes
Reply
Moderator
Moderator

Hello,

Please try the following:

1. Change the channel type from MANUAL to AUTO.

2. DMA buffer size should be a multiple of 16 bytes. So, you can use 528 as DMA buffer size.

3. Now, add the break sequence at the end of the 18 byte and 524 byte packets. FX3 will recognize this and automatically commit the received data from producer to consumer socket.

I tested this using teraterm by sending the break signal. This is done by pressing alt+B in teraterm.

Best Regards,

Jayakrishna

Best Regards,
Jayakrishna
0 Likes
Reply
New Contributor II

Hi Jayakrishna,

Thank you for your suggestion.

Unfortunately I cannot change to Auto mode as I have to to do some processing of the packets in the FX3 code.

I have found a solution.

I set the receive block size to 18,

CyU3PUartRxSetBlockXfer(18)

I can change the code transmitting the packets to pad the longer packets to a multiple of 18.

So 524 packet is transmitted as a 540 packet.

The end of the longer packets is padded with ETX characters.

The receiving code if it detects a longer packet (which I know from the starting bytes) the FX3 code just adds it to a local buffer and discards the DMA buffer until it gets a DMA buffer that ends with ETX is received.

It then processes the buffered complete packet.

It seems to work...

Best Regards

Keith

View solution in original post

0 Likes
Reply
Moderator
Moderator

Hello Keith,

Glad to hear that you found a way and the issue is resolved!

Best Regards,

Jayakrishna

Best Regards,
Jayakrishna
0 Likes
Reply