FX3 Spi reference code

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

cross mob
dilic_2635671
Level 4
Level 4

I am recently starting working on FX3 SPI code. This is a function in all of SPI code (UsbSpiDmaMode, UsbSpiGpioMode and UsbSpiRegMode). Basically this CyFxUSBSetupCB() function is a call back routine to process control end point 0 data and process. Following code is switching the vendor command.

In the READ command, the code zero out the glEp0Buffer then pass to CySpiTransfer for SPI transfer. Instead of zero out the buffer, the code should get data from EP0 then pass for passing.

I am just wondering how Cypress QA the code before publish.

CyBool_t

CyFxUSBSetupCB (

        uint32_t setupdat0,

        uint32_t setupdat1)

{

...

            case CY_FX_RQT_SPI_FLASH_WRITE:

                status = CyU3PUsbGetEP0Data (wLength, glEp0Buffer, NULL);

                if (status == CY_U3P_SUCCESS)

                {

                    status = CyFxSpiTransfer (wIndex, wLength,  glEp0Buffer, CyFalse);

                }

                break;

            case CY_FX_RQT_SPI_FLASH_READ:

                CyU3PMemSet (glEp0Buffer, 0, sizeof (glEp0Buffer));

               status = CyU3PUsbGetEP0Data (wLength, glEp0Buffer, NULL);

                status = CyFxSpiTransfer (wIndex, wLength,  glEp0Buffer, CyTrue);

                if (status == CY_U3P_SUCCESS)

                {

                    status = CyU3PUsbSendEP0Data (wLength, glEp0Buffer);

                }

                break;

Thanks,

Dick

0 Likes
1 Solution
KandlaguntaR_36
Moderator
Moderator
Moderator
25 solutions authored 10 solutions authored 5 solutions authored

While Writing to SPI - you have to send the SPI internal address and length of data and data over the Control end point. This data will be copied to glEp0Buffer through   status = CyU3PUsbGetEP0Data (wLength, glEp0Buffer, NULL); then this buffer will be send to SPI using CyFxSpiTransfer (wIndex, wLength,  glEp0Buffer, CyFalse);

Similarly for reading from SPI - you have to send the SPI Internal address and length of data to be read from the SPI.

In the CY_FX_RQT_SPI_FLASH_READ case, you are allocating a Buffer (glEp0Buffer) to receive the data.

Then you are receiving the data to the buffer using CyFxSpiTransfer (wIndex, wLength,  glEp0Buffer, CyTrue);

Then you are sending it to Control Endpoint using CyU3PUsbSendEP0Data (wLength, glEp0Buffer);

View solution in original post

0 Likes
7 Replies
Anonymous
Not applicable

The purpose of the READ command is to get data from the SPI and put it into the EP0 buffer to send it to the host.  Why would you want to get data from EP0 on an IN transaction?  While zeroing the EP0 buffer might not be strictly necessary, it think it's a reasonable practice.

Right?

0 Likes

Don't you need to get address from EP0 and send to  SPI for read?

0 Likes

Maybe in this specific case they don't need it since there is an  pageAddress pass to CyFxSpiTransfer(). My bad. Thx

0 Likes
Anonymous
Not applicable

The SPI internal address and read length are passed in the SETUP packet in the wIndex and wLength fields.

0 Likes
Anonymous
Not applicable

Hey milkfish, you might want to change this question to "Answered" so people don't spend time on a resolved issue.

0 Likes
KandlaguntaR_36
Moderator
Moderator
Moderator
25 solutions authored 10 solutions authored 5 solutions authored

While Writing to SPI - you have to send the SPI internal address and length of data and data over the Control end point. This data will be copied to glEp0Buffer through   status = CyU3PUsbGetEP0Data (wLength, glEp0Buffer, NULL); then this buffer will be send to SPI using CyFxSpiTransfer (wIndex, wLength,  glEp0Buffer, CyFalse);

Similarly for reading from SPI - you have to send the SPI Internal address and length of data to be read from the SPI.

In the CY_FX_RQT_SPI_FLASH_READ case, you are allocating a Buffer (glEp0Buffer) to receive the data.

Then you are receiving the data to the buffer using CyFxSpiTransfer (wIndex, wLength,  glEp0Buffer, CyTrue);

Then you are sending it to Control Endpoint using CyU3PUsbSendEP0Data (wLength, glEp0Buffer);

0 Likes
dilic_2635671
Level 4
Level 4

Sure. ! !

0 Likes