- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Don't you need to get address from EP0 and send to SPI for read?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Maybe in this specific case they don't need it since there is an pageAddress pass to CyFxSpiTransfer(). My bad. Thx
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The SPI internal address and read length are passed in the SETUP packet in the wIndex and wLength fields.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hey milkfish, you might want to change this question to "Answered" so people don't spend time on a resolved issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sure. ! !