cancel
Showing results for 
Search instead for 
Did you mean: 

USB Superspeed Peripherals

FuBe_4381791
New Contributor II

Hello Cypress!

This is a continuation of an issue from: FX3 emmc unreachable after format in manual 

The FX3 does not allow the drive to be formatted when set to manual, this is a big issue since we want to encrypt data as it is passed through. The drive becomes unrecognizable after this process, after trying it once, failing, then trying again, the drive does appear as "raw" in device manager, but it is still not format-able. Is there an additional call back that must be added? Please note when firmware is written and the drive is formatted under auto, then reset back to manual, files can be written and read like normal, it is just when trying to format the drive in manual that this fails.

I apologize I can't seem to post a reply to the previous thread so creating a new one. I have tested this on a different FX3 with a different flash chip and the issue persists. Please see the attached project file which is a very slightly modified version of the MSC example and these videos, to find the places where changes were made in the zip, search for the define "Manual_MSC". It is used in 3 places.

Video of failure to format to FAT with explorer, succeeding when switched back to auto mode, then failing again when trying to format in NTFS, and explorer crashed at the end too...

https://drive.google.com/file/d/10jToAssyamGRbILLY7TkheYB-1YNGdFD/view?usp=sharing

Video of formatting drive with device manager, FX3 just stopped working at the end, it was still connected.

https://drive.google.com/file/d/1dZg9Mp7ySYX7QscVTuNORb6bXTlYEx4C/view?usp=sharing

I have also tried other formatting tools and this still fails.

Is there a call back that is missing in: CyFxMscApplnDmaCb? Or is there a response that is meant to be added to CyFxMscApplnUSBSetupCB? 

Regards!

Fujimi

0 Likes
24 Replies
Rashi_Vatsa
Moderator
Moderator

Hello Fujimi,

To understand the requests received by the FX3S when the format is done. Please add the below debug print in the CyFxMscApplnUSBSetupCB function of firmware and enable LOG_ENABLE macro to get the UART prints.

CyBool_t
CyFxMscApplnUSBSetupCB (
        uint32_t setupdat0, /* SETUP Data 0 */
        uint32_t setupdat1  /* SETUP Data 1 */
    )
{
    CyBool_t isHandled = CyFalse;
    uint8_t  ep0Buf[2];

    uint8_t  bRequest, bReqType;
    uint8_t  bType, bTarget;
    uint16_t wValue, wIndex, wLength;

    /* Decode the fields from the setup request. */
    bReqType = (setupdat0 & CY_U3P_USB_REQUEST_TYPE_MASK);
    bType    = (bReqType & CY_U3P_USB_TYPE_MASK);
    bTarget  = (bReqType & CY_U3P_USB_TARGET_MASK);
    bRequest = ((setupdat0 & CY_U3P_USB_REQUEST_MASK) >> CY_U3P_USB_REQUEST_POS);
    wValue   = ((setupdat0 & CY_U3P_USB_VALUE_MASK)   >> CY_U3P_USB_VALUE_POS);
    wIndex   = ((setupdat1 & CY_U3P_USB_INDEX_MASK)   >> CY_U3P_USB_INDEX_POS);
    wLength  = ((setupdat1 & CY_U3P_USB_LENGTH_MASK)  >> CY_U3P_USB_LENGTH_POS);
 
    
    AppDebugPrint(4, "\n\r bType = 0x%x, bRequest = 0x%x, wValue = 0x%x, wIndex = 0x%x, wLength= 0x%x",
    		bType, bRequest, wValue, wIndex, wLength);
    /* Some setup requests have to be handled in a non-standard way for this device. */
    if (bType == CY_U3P_USB_STANDARD_RQT)
    {.....

 

Please share the UART prints for both the tests 1) AUTO and 2) MANUAL

Also, please let me know if the data transfers (read/write) to the card is done successfully with MANUAL channel i.e. without formatting the card.

Regards,
Rashi
0 Likes
FuBe_4381791
New Contributor II

Hello Rashi!

Thanks for the fast reply!

I do not have UART, this is a custom board. I will investigate the call backs in CyFxMscApplnUSBSetupCB

For this question: Also, please let me know if the data transfers (read/write) to the card is done successfully with MANUAL channel i.e. without formatting the card.

Yes, when firmware is written and the drive is formatted under auto, then reset back to manual, files can be written and read like normal, it is just when trying to format the drive in manual that this fails.

Regards!

Fujimi

0 Likes
Rashi_Vatsa
Moderator
Moderator

Hello Fujimi,

You can try capturing USB traces using software analyzer like Wireshark to check the USB requests sent by the host when the disk format is done on the host.

Regards,
Rashi
0 Likes
FuBe_4381791
New Contributor II

Hello Rashi!

I have attached the output from wireshark USB capture, I tried to limit it only to the formatting operation.

So I clicked on "start capturing" then "ok to format", then waited until windows reported failure, then stopped capturing. I can make a video if it would help?

Out of curiosity, are you able to replicate this issue with the firmware project sent above?

Regards! I did notice that it seems to go through read and write of the hash table.

Fujimi

0 Likes
FuBe_4381791
New Contributor II

Hello again Rashi!

I repeated this over USB2, there is WAY less in the capture file so I think would be much easier to go through.

Strongly recommend checking this USB2 file instead of the previous one.....

Regards!

Fujimi

0 Likes
Rashi_Vatsa
Moderator
Moderator

Hello Fujimi,

Thank you for the Wireshark traces.

Can you please share the Wireshark traces for the working case (i.e. AUTO DMA channel)?

In the traces shared, I could see multiple class specific requests sent by the host. I noticed that Mode sense (6) requests fails every time. To confirm the USB request sequence from the host, please help me by sharing the USB traces (Wireshark) for the working case.

Also, let me know reason of using CyU3PUsbEpEvtControl without calling CyU3PUsbRegisterEpEvtCallback

Regards,
Rashi
0 Likes
FuBe_4381791
New Contributor II

Hello Rashi!

Please see the attached wireshark output from successful format using Auto. I tried to limit the period of capture to the format operation, but it still came out pretty big.

Please disregard those calls to CyU3PUsbEpEvtControl, they are left over from trying a bunch of different things in the main project which I can't share. I had copy pasted the relevant changes to the original MSC example to demonstrate the format issue.

What is Mode sense 6?

Regards!

Fujimi

0 Likes
Rashi_Vatsa
Moderator
Moderator

Hello Fujimi,

Thank you for the traces.

After comparing the traces, I could see that CY_FX_MSC_SCSI_WRITE_10 fails as the  CSW returns data residue as 512 bytes (which is equal to the bytes written by the host). It means that data is not written to card.

From the firmware, I understand that for both the channels glChHandleMscOut and glChHandleMscIn same DMA callback is used. Can you try using different DMA callback for both the channels and handle the events appropriately. Please check if CY_U3P_DMA_CB_PROD_EVENT event is seen for glChHandleMscOut channel when data format is done. It seems that the data received from the host is not committed to SIB

Kindly, check if the data is received by FX3S when CY_FX_MSC_SCSI_WRITE_10 command is issued during card formatting or can you check the return status of returned by CyFxMscApplnSibCB when CY_FX_MSC_SCSI_WRITE_10 fails.

 

Regards,
Rashi
0 Likes
FuBe_4381791
New Contributor II

Hello Rashi!

I have tried separating the DMA callbacks which did not resolve the issue. I don't see anything failing with the SIB call back... But it is difficult without UART debugger.

 

I will keep investigating but I am curious if you are able to replicate this? If this is an issue with our PCB as it is a custom board, I would like to confirm it as soon as possible.

My main confusion is that this operation for write is used in normal read and write which does work if the drive is formatted in Auto... The part that it seems to be failing on is writing the start of the drive?

Regards!

Fujimi

0 Likes
Rashi_Vatsa
Moderator
Moderator

Hello Fujimi,

Reproducing the problem is currently not possible at my end, due to hardware constraints. We are trying to get the hardware to reproduce the problem.

The part that it seems to be failing on is writing the start of the drive?

>> From the USB traces, I could see that 

Please let me know if the problem is seen in USB 3.0 as well CY_FX_MSC_SCSI_WRITE_10 where  CSW is sent with failure code. From the firmware, this could happen when CyFxMscApplnSibCB returns  failure. Please check if CyFxMscApplnSibCB returns failure when format is done when channel is MANUAL. 

Regards,
Rashi
0 Likes
FuBe_4381791
New Contributor II

Hello Rashi!

I am still investigating the issue, I have found that in CY_FX_MSC_SCSI_WRITE_10, the operation: status = CyU3PSibReadWriteRequest (CY_FX_SIB_WRITE, ((lun >= CY_FX_SIB_PARTITIONS) ? 1 : 0), glLunUnit[lun], numBlks, startAddr, 0);

Throws the status: "CY_U3P_ERROR_INVALID_DEV"

From checking the variables passed in: lun == 0, glLunUnit[lun] == 3. Both of these variables seem ok so I am confused about why it would say device is invalid, perhaps an operation before it is resetting the drive?

I am still trying to a few bandaid ways around this since it only seems to occur on formatting.

Regards!

Fujimi

0 Likes
Rashi_Vatsa
Moderator
Moderator

Hello Fujimi,

Thank you for the details.

CY_U3P_ERROR_INVALID_DEV status is seen when  port with no connected storage device is accessed.

I have modified the firmware you had shared to debug the reason failure of CyU3PSibReadWriteRequest. I have added CyU3PSibIsAddrValid_check function before CyU3PSibReadWriteRequest in CY_FX_MSC_SCSI_WRITE_10, which is similar to the implementation done in CyU3PSibReadWriteRequest API. Please let me know the return status of CyU3PSibIsAddrValid_check

 

Regards,
Rashi
0 Likes
FuBe_4381791
New Contributor II

Hello Rashi!

I had to modify it slightly since it stopped the format process entirely, this is the code I used:

uint32_t startAddr2;
startAddr2 = startAddr;
startAddr2 += CyU3PSibLunGetStartAddr (((lun >= CY_FX_SIB_PARTITIONS) ? 1 : 0), glLunUnit[lun]);
status = CyU3PSibIsAddrValid_check (((lun >= CY_FX_SIB_PARTITIONS) ? 1 : 0), glLunUnit[lun], numBlks, startAddr2);
if (status != CY_U3P_SUCCESS)
{
if (status == CY_U3P_ERROR_INVALID_ADDR){
CyFxAppErrorHandler(1);
}
if (status == CY_U3P_ERROR_INVALID_UNIT){
CyFxAppErrorHandler(2);
}
if (status == CY_U3P_ERROR_INVALID_DEV){
CyFxAppErrorHandler(3);
}
}

The result is: status == CY_U3P_ERROR_INVALID_DEV

I think a previous operation is causing the drive to stop working? I'm not seeing any instances of de-init of the drive though. Please note I can get feedback from the error handler.

Regards!

Fujimi

0 Likes
Rashi_Vatsa
Moderator
Moderator

Hello Fujimi,

CY_U3P_ERROR_INVALID_DEV is returned when the address is not valid or the card is not detected.

I have compared the USB traces that you had shared earlier when the card format is done for MANUAL and AUTO channels. I could see the failure happens when WRITE (10) command is received. Please confirm if only Card format was performed while capturing the USB traces with AUTO and MANUAL mode.

I could see following commands from host before WRITE (10) command

- Mode Sense (6) -  Manual /Auto channel not used as the channel is used in Override mode i.e. using CyFxMscApplnSendDataToHost

- Read Capacity -  Manual /Auto channel not used as the channel is used in Override mode i.e. using CyFxMscApplnSendDataToHost

- Inquiry LUN -  Manual /Auto channel not used as the channel is used in Override mode i.e. using CyFxMscApplnSendDataToHost

The changes that are done in the firmware i.e. AUTO to MANUAL applies when WRITE (10) command is received. The MANUAL DMA channel (glChHandleMscOut)will be enabled when CyU3PDmaChannelSetXfer is called. 

From the test, we could see that CyU3PSibReadWriteRequest returns CY_U3P_ERROR_INVALID_DEV which happens when the card is not accessible. 

To check if the data is read from the SD card when WRITE (10) is received, please check if CY_U3P_DMA_CB_PROD_EVENT is received for glChHandleMscOut . Please modify the DMA callback as follows and let me know the value of data_read_from_SD (global variable)

#ifdef Manual_MSC
        case CY_U3P_DMA_CB_PROD_EVENT:

        	if(handle == &glChHandleMscOut)
        	{
        		data_read_from_SD++;
        		CyU3PDmaChannelCommitBuffer (handle, input->buffer_p.count, 0);
        		
        	}
        	else
               CyU3PDmaChannelCommitBuffer (handle, input->buffer_p.count, 0);
break;
#endif

 

Regards,
Rashi
0 Likes
Rashi_Vatsa
Moderator
Moderator

Hello Fujimi,

Apologies for the confusion.

To check if the data is read from the SD card when WRITE (10) is received, please check if CY_U3P_DMA_CB_PROD_EVENT is received for glChHandleMscIN . Please modify the DMA callback as follows and let me know the value of data_written_from_USB (global variable)

#ifdef Manual_MSC
        case CY_U3P_DMA_CB_PROD_EVENT:

        	if(handle == &glChHandleMscOut)
        	{
        		data_read_from_SD++;
        		CyU3PDmaChannelCommitBuffer (handle, input->buffer_p.count, 0);
        		
        	}
        	else
{
               data_written_from_USB++
               CyU3PDmaChannelCommitBuffer (handle, input->buffer_p.count, 0);
}
break;
#endif

 

Regards,
Rashi
0 Likes
FuBe_4381791
New Contributor II

Hello Rashi!

To answer this question: "Please confirm if only Card format was performed while capturing the USB traces with AUTO and MANUAL mode."

Yes, only card format was performed in the trace, I first programmed the fx3, after waiting a few seconds for drivers, started the trace, then immediately formatted the drive, after the failure pop up appeared, stop tracing.

The results I get is: 

global variable from taking both sides after format
BOTH
data_read_from_SD 39
data_written_from_USB 76

CyFxMscApplnDmaCbout only
data_read_from_SD 39
data_written_from_USB 0

CyFxMscApplnDmaCbin only
data_read_from_SD 0
data_written_from_USB 73

I tried separating the in and out callback just to double check, and the output seems consistent.... I do not know what this shows? I did get a slight difference with: data_written_from_USB , but I think that's with how fast I performed the format after programming the fx3.

Regards!

Fujimi

0 Likes
Rashi_Vatsa
Moderator
Moderator

Hello Fujimi,

I tried separating the in and out callback just to double check, and the output seems consistent.... I do not know what this shows?

>> Can you please share the latest modified firmware. This will help me to understand the values better.

Also, please confirm if the following value is for AUTO channel  and the other CyFxMscApplnDmaCbout only  and CyFxMscApplnDmaCbin only is for manual channel. Is that correct?

global variable from taking both sides after format
BOTH
data_read_from_SD 39
data_written_from_USB 76

If not, please let me know the values for AUTO channel also.

Regards,
Rashi
0 Likes
FuBe_4381791
New Contributor II

Hello Rashi!

I have attached the modified project, values when run in AUTO are 0 and 0. This makes sense since the event listener for: CY_U3P_DMA_CB_PROD_EVENT is not used in the callback.....

The method used to output values is to flash LED's, I have another project which I can not share that sends values over HID so they have been confirmed.

Q: "Also, please confirm if the following value is for AUTO channel  and the other CyFxMscApplnDmaCbout only  and CyFxMscApplnDmaCbin only is for manual channel. Is that correct?"

A: No it's all manual, AUTO produced 0 values only. I realize now that: 

"if(handle == &glChHandleMscOut) { " in your code had the same effect as separating the call back channels, hence:

BOTH (manual mode, using the same callback)
data_read_from_SD 39
data_written_from_USB 76

CyFxMscApplnDmaCbout only  (manual mode, separated callbacks)
data_read_from_SD 39
data_written_from_USB 0

CyFxMscApplnDmaCbin only  (manual mode, separated callbacks)
data_read_from_SD 0
data_written_from_USB 73

Is unnecessary information and didn't do anything but confuse sorry....

To help you look through the code, in cyfx3s_msc.c:

1.value output via LED's lines 50 to 193
2.CyU3PSibIsAddrValid_check code line 508
3.Write_10 is at line 1294, this includes the point where the output is LED flashed on line 1330
4.remove the comment on line 1336 when trying to force the LED to output using auto during a format, as it does not throw errors normally
5.global variables usage lines: 1910 and 1964 in the separated callbacks

Regards!

Fujimi

0 Likes
Rashi_Vatsa
Moderator
Moderator

Hi Fujimi,

Please use the attached firmware and let me know the values of  global variables used in separated callbacks for both AUTO_SIGNAL and MANUAL channel. To get the callbacks for AUTO channel, I have changed the channel to AUTO_SIGNAL.

Regards,

Rashi

Regards,
Rashi
0 Likes
FuBe_4381791
New Contributor II

Hello Rashi!

AUTO_SIGNAL:

data_read_from_SD = 49, data_read_from_USB = 0

Manual: 

data_read_from_SD = 98, data_read_from_USB = 0

Regards!

Fujimi

0 Likes
Rashi_Vatsa
Moderator
Moderator

Hello Fujimi,

Please let me know the values of following variables also

- data_written_to_USB and data_written_to_SD

Please comment out the CyU3PSibIsAddrValid_check from all the instances in the firmware.

Also, let me know if it is possible to access the UART on your board. Without the debug prints it is a bit difficult to debug the issue as currently we are not able to reproduce the issue at our end.

In addition to this, please let me know if the device always comes up as USB 3.0 and the problem is seen when connected as  USB 3.0. 

From the values of data_read_from_SD for both channel, the value is double for MANUAL case. Please check if for both cases the connection is USB 3.0. 

Also, I have noticed that GPIO are used to control LEDs when error is seen. Please let me know which API fails when the LED blinks.

Regards,
Rashi
0 Likes
FuBe_4381791
New Contributor II

Hello Rashi!

We've been making a new debug board with a CY7C65215 chip to give more useful feedback. Hopefully done this or next week.

To answer the question: Please let me know which API fails when the LED blinks.

This occurs in write_10 whenever any drive operation is attempted, as the drive is "CY_U3P_ERROR_INVALID_DEV". I forced this when trying to get feedback on the global variables in auto mode.

For questions about variables, I will wait for the UART dev board.

I just discovered that adding the manual flag breaks when trying to copy a file using USB2 and writing, for some reason write works on USB 3 though, to replicate, on the original MSC sample in the SDK, with either the FX3 on a USB2 cable or on a USB3 cable with CyU3PConnectState (CyTrue, CyFalse); in both cases I can not write to mass storage when  CY_U3P_DMA_TYPE_MANUAL is used.

With a USB3 cable and CyU3PConnectState (CyTrue, CyTrue); and CY_U3P_DMA_TYPE_MANUAL, I can write to the drive... 

To summarize cause this is really weird to me:

1. USB2 and USB3 in auto DMA and Mass storage read/write/format works

2. USB2 mode, manual DMA and mass storage can read, not write/format

3. USB3 mode, manual DMA and mass storage can read and write, not format

I do not know what could cause this... Perhaps a callback or another operation is missing? Apart from CY_U3P_DMA_CB_PROD_EVENT and CyU3PDmaChannelCommitBuffer (handle, input->buffer_p.count, 0);

Is there a way to encrypt data before it is sent to the mass storage in auto mode? What exactly does auto do that manual does not?

Regards!

Fujimi

0 Likes
Rashi_Vatsa
Moderator
Moderator

Hello Fujimi,

Thank you for the details

I do not know what could cause this... Perhaps a callback or another operation is missing? Apart from CY_U3P_DMA_CB_PROD_EVENT and CyU3PDmaChannelCommitBuffer (handle, input->buffer_p.count, 0);

>> Please do the the following changes in the CyFxMscApplnDmaCbout and let me know values of  data_read_from_USB and data_written_to_SD when write to the drive is done. Also let me know if write fails with USB 2.0/USB 3.0 for MANUAL(enable Manual_MSC)

 case CY_U3P_DMA_CB_PROD_EVENT:
            {
        		data_read_from_USB++;
			}

        break;
        case CY_U3P_DMA_CB_CONS_EVENT:
        {
        	data_written_to_SD++;
        }
        break;

 

Regards,
Rashi
0 Likes
FuBe_4381791
New Contributor II

Hello Rashi!

I am abit more confused, the CY_FX_MSC_SCSI_MODE_SENSE_6 has handle for 0x1A, from what I can find, 1A is for power...

Regards!

Fujimi

0 Likes