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.
jali
Level 4
Level 4
25 replies posted 10 questions asked 50 sign-ins

Hello,

I'm debuging the USB MSC on the CYUSB3014 board, I check the demo code(USBMassStorageDemo), it define the buffer on the ram, I want to write all data into spi flash,  so I change the buffer to 32KB, and modify the CY_FX_MSC_CARD_CAPACITY  to 4*1024*1024, and handle the write and read operations as below, spilt the data into many slice of 4096, but it doesn't work, I attach the code, can you give some suggestions, thanks a lot.

case CY_FX_MSC_SCSI_READ_10:
{
startAddr = (((uint32_t)glMscCbwBuffer[17] << 24) | ((uint32_t)glMscCbwBuffer[18] << 16) |
((uint32_t)glMscCbwBuffer[19] << 😎 | ((uint32_t)glMscCbwBuffer[20]));
numBlks = (((uint16_t)glMscCbwBuffer[22] << 😎 | ((uint16_t)glMscCbwBuffer[23]));

if (!CyFxMscApplnCheckCbwParams (lun, CyTrue, CyTrue, CyTrue, (numBlks * glLunBlkSize),
&dataLength))
break;

glMscState = CY_FX_MSC_STATE_DATA;
for(int i=0;i<numBlks;i++)
{
CyFxSpiTransfer ((startAddr) * glLunBlkSize,glLunBlkSize, glMscStorageDeviceMemory,1);
status = CyFxMscApplnSendDataToHost ((glMscStorageDeviceMemory),
(glLunBlkSize));
startAddr++;
CyU3PDmaChannelWaitForCompletion (&glChHandleMscIn, CYU3P_WAIT_FOREVER);
}
if (status != CY_U3P_SUCCESS)
{
glMscCmdStatus = 1;
glSensePtr = CY_FX_MSC_SENSE_CRC_ERROR;
CyU3PEventSet (&glMscAppEvent, CY_FX_MSC_SIBCB_EVENT_FLAG, CYU3P_EVENT_OR);
}
else
glMscResidue = 0;
}

case CY_FX_MSC_SCSI_WRITE_10:
{
startAddr = (((uint32_t)glMscCbwBuffer[17] << 24) | ((uint32_t)glMscCbwBuffer[18] << 16) |
((uint32_t)glMscCbwBuffer[19] << 😎 | ((uint32_t)glMscCbwBuffer[20]));
numBlks = (((uint16_t)glMscCbwBuffer[22] << 😎 | ((uint16_t)glMscCbwBuffer[23]));

if (!CyFxMscApplnCheckCbwParams (lun, CyTrue, CyFalse, CyTrue, (numBlks * glLunBlkSize),
&dataLength))
break;

glMscState = CY_FX_MSC_STATE_DATA;
for(int i=0;i<numBlks;i++)
{
status = CyFxMscApplnReceiveUsbData (glMscStorageDeviceMemory,(glLunBlkSize));

CyU3PDmaChannelWaitForCompletion (&glChHandleMscOut, CYU3P_WAIT_FOREVER);

W25QXX_SectorErase4KB(startAddr);
CyFxSpiTransfer ((startAddr) * glLunBlkSize,glLunBlkSize,glMscStorageDeviceMemory,0);
W25QXX_Wait_Busy();
startAddr++;
//CyU3PDebugPrint (4, "ReceiveUsbData num = %d\r\n", i);

}
CyU3PDebugPrint (4, "MSC_SCSI_WRITE startAddr %X\n", startAddr);

if (status != CY_U3P_SUCCESS)
{
glMscCmdStatus = 1;
glSensePtr = CY_FX_MSC_SENSE_CRC_ERROR;
CyU3PEventSet (&glMscAppEvent, CY_FX_MSC_SIBCB_EVENT_FLAG, CYU3P_EVENT_OR);
}
else
glMscResidue = 0;
}

glMscStorageDeviceMemory = (uint8_t *)CyU3PDmaBufferAlloc (32*1024);

#define CY_FX_MSC_CARD_CAPACITY (4*1024*1024)

CyFxMscAppInitVars (
void)
{
glLunState = CyTrue;
glLunBlkSize = 4096;
glLunNumBlks = ((CY_FX_MSC_CARD_CAPACITY / 4096) - 1);
glSensePtr = CY_FX_MSC_SENSE_DEVICE_RESET;
glLunStopped = CyFalse;
}

0 Likes
1 Solution

Hi Ajeeth,

I have have fixed the issue, the flash write function have a bug, the addr is wrong, now it works well, and the next step,  I want combine the uvc and msc in one project as a composite device, cam you provide the demo code, thanks.

View solution in original post

0 Likes
3 Replies
Ajeethkumar_P
Moderator
Moderator
Moderator
50 likes received 500 replies posted 100 solutions authored

Hi,

Can you explain the issue you face in detail?

Which board are you using for this application?

If possible, can you share the UART debug logs with us?

Can you check if the SPI transfer happens as expected using Analyzer?

Regards,
Ajeeth

0 Likes

Hi Ajeeth,

I have have fixed the issue, the flash write function have a bug, the addr is wrong, now it works well, and the next step,  I want combine the uvc and msc in one project as a composite device, cam you provide the demo code, thanks.

0 Likes
Ajeethkumar_P
Moderator
Moderator
Moderator
50 likes received 500 replies posted 100 solutions authored

Hi,

For UVC, you can get the Code example here. To understand this code example application, you can refer to Appnote AN75779.

Regards,
Ajeeth

0 Likes