FX3S storage write in override mode

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

cross mob
SaMe_4645651
Level 1
Level 1

Hi everyone,

I'm developing an application based on the MSC example for the FX3S. In some cases, I need to manually read/write data to the storage.

This is the DMA configuration:

CyU3PDmaChannelConfig_t dmaConfig;

dmaConfig.size = 512;

dmaConfig.count = CY_FX_MSC_DMA_BUF_COUNT;

dmaConfig.prodSckId = (CyU3PDmaSocketId_t) (CY_U3P_UIB_SOCKET_PROD_0 | CY_FX_MSC_EP_BULK_OUT_SOCKET);

dmaConfig.consSckId = CY_U3P_SIB_SOCKET_0;

dmaConfig.dmaMode = CY_U3P_DMA_MODE_BYTE;

dmaConfig.notification = CY_U3P_DMA_CB_RECV_CPLT | CY_U3P_DMA_CB_SEND_CPLT | CY_U3P_DMA_CB_PROD_EVENT | CY_U3P_DMA_CB_CONS_EVENT;

dmaConfig.cb = UsbStorage_DmaStorageWriteCb;

dmaConfig.prodHeader = 0;

dmaConfig.prodFooter = 0;

dmaConfig.consHeader = 0;

dmaConfig.prodAvailCount = 0;

status = CyU3PDmaChannelCreate(&glChHandleMscOut, CY_U3P_DMA_TYPE_MANUAL, &dmaConfig);

dmaConfig.prodSckId = CY_U3P_SIB_SOCKET_1;

dmaConfig.consSckId = (CyU3PDmaSocketId_t) (CY_U3P_UIB_SOCKET_CONS_0 | CY_FX_MSC_EP_BULK_IN_SOCKET);

dmaConfig.notification = CY_U3P_DMA_CB_RECV_CPLT | CY_U3P_DMA_CB_SEND_CPLT | CY_U3P_DMA_CB_PROD_EVENT | CY_U3P_DMA_CB_CONS_EVENT;

dmaConfig.cb = UsbStorage_DmaStorageReadCb;

status = CyU3PDmaChannelCreate(&glChHandleMscIn, CY_U3P_DMA_TYPE_MANUAL, &dmaConfig);

I am using the following command sequence to initiate a read/write request. (Each return status check here is omitted for brevity: every call returns SUCCESS until WaitForCompletion).

// Prepare the DMA Buffer

CyU3PDmaBuffer_t dmaBuf;

dmaBuf.buffer = buf;

dmaBuf.status = 0;

dmaBuf.size = (len + 15) & 0xFFF0; // Round up to a multiple of 16.

dmaBuf.count = len;

CyU3PDmaChannel *handle = (isRead) ? &glChHandleMscIn : &glChHandleMscOut;

if(isRead)

    CyU3PDmaChannelSetupRecvBuffer(handle, &dmaBuf);

else

    CyU3PDmaChannelSetupSendBuffer(handle, &dmaBuf);

CyU3PSibReadWriteRequest(isRead, ((lun >= CY_FX_SIB_PARTITIONS) ? 1 : 0), glLunUnit[lun], len / CY_FX_SIB_MAX_BLOCK_SIZE, startAddr, 1);

ret = CyU3PDmaChannelWaitForCompletion(handle, CYU3P_WAIT_FOREVER); // ret == "ABORTED" when trying to write!

Reads are successful. When trying to WRITE, the DmaStorageWriteCb callback is not called and the WaitForCompletion function returns ABORTED.

I've checked the docs and the forums and couldn't find an answer. Can you help me?

Thanks,
Salvatore

0 Likes
1 Solution
SaMe_4645651
Level 1
Level 1

Hello everyone,

I've solved it. I've added a check before the CyU3PDmaChannelSetupRecvBuffer()/CyU3PDmaChannelSetupSendBuffer() calls:

CyU3PDmaState_t state; uint32_t prodCount, consCount;

CyU3PDmaChannelGetStatus(handle, &state, &prodCount, &consCount);

while(state != CY_U3P_DMA_CONFIGURED && state != CY_U3P_DMA_RECV_COMPLETED && state != CY_U3P_DMA_SEND_COMPLETED)

{

    CyU3PThreadSleep(10);

    CyU3PDmaChannelGetStatus(handle, &state, &prodCount, &consCount);

}

Thanks for the help.

Regards,
Salvatore.

View solution in original post

0 Likes
3 Replies