EZ-USB FX3 raid1 buffer data modification before storage?

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

cross mob
taahc_4008171
Level 1
Level 1

hello everyone, i am using EZ-USB F3 raid1 and raid0 firmware for storage. i am trying to modify the buffer data (coming from host) before storing the data on storage, unfortunately could not get any success to isolate the buffer. Is it possible to modify buffer before storing on storage? Any help will much appreciated.

0 Likes
11 Replies
SrinathS_16
Moderator
Moderator
Moderator
1000 replies posted 750 replies posted 500 replies posted

Hello,

- In case you are using MANUAL channel, the PROD event callback can be used to modify the buffer contents before storing it in the device.

- In case you are using AUTO channel, the CyU3PDmaChannelSetupSendBuffer() API can be used to obtain handle to the DMA channel and a custom buffer can be sent to the storage port. But, using this would result in the loss of the actual data that came from the producer socket.

Best regards,

Srinath S

0 Likes

hello Srinath,

Thank you for reply.

i am using   CyU3PDmaMultiChannelCreate and mode is CY_U3P_DMA_TYPE_MULTICAST.

CyU3PDmaMultiChannelCreate (&glChHandleUSBOut, CY_U3P_DMA_TYPE_MULTICAST, &dmaMultiConfig);

configuration:

dmaMultiConfig.size           = 1024 * CY_FX_MSC_EP_BURST_SIZE;     
dmaMultiConfig.count          = CY_FX_MSC_DMA_BUF_COUNT;    
dmaMultiConfig.validSckCount  = 2;    
dmaMultiConfig.prodSckId[0]   = (CyU3PDmaSocketId_t)(CY_U3P_UIB_SOCKET_PROD_0 | CY_FX_MSC_EP_BULK_OUT_SOCKET);    
dmaMultiConfig.consSckId[0]   = CY_U3P_SIB_SOCKET_0;    
dmaMultiConfig.consSckId[1]   = CY_U3P_SIB_SOCKET_1;    
dmaMultiConfig.dmaMode        = CY_U3P_DMA_MODE_BYTE;    
dmaMultiConfig.notification   = CY_U3P_DMA_CB_PROD_EVENT | CY_U3P_DMA_CB_RECV_CPLT;    
dmaMultiConfig.cb             = CyFxMscApplnMultiDmaCb;    
dmaMultiConfig.prodHeader     = 0;    
dmaMultiConfig.prodFooter     = 0;    
dmaMultiConfig.consHeader     = 0;    
dmaMultiConfig.prodAvailCount = 0;

- Should i change CY_U3P_DMA_TYPE_MULTICAST  mode to manual mode?

- About prod callback, can you be more specific to this. I have gone through dma callback as you can see in configuration or dma and PROD callback both are same. where this PROD callback is registered?

- Auto mode, i will try your solution but first i need to clear things about this multicast one.

i am new to this firmware so please don't mind my lot of question.

Thank you.

0 Likes

Hello,

- MULTICAST mode is by default in MANUAL and AUTO mode is not supported for MULTICAST.

- The statement dmaMultiConfig.notification  = CY_U3P_DMA_CB_PROD_EVENT | CY_U3P_DMA_CB_RECV_CPLT; registers the events for which the callback is to be triggered and the statement dmaMultiConfig.cb = CyFxMscApplnMultiDmaCb; defines the callback function to be executed when the mentioned event occurs.

- In the callback function, the event notified can be checked and the buffer can be modified to add custom data. Please look for the CyFxMscApplnMultiDmaCb callback function definition in the AN89661 firmware example.

Best regards,

Srinath S

0 Likes

Hello Srinath,

Thank you for response.

- In CyFxMscApplnMultiDmaCb(), i have implemented small logic to overwrite the buffer data before committing it.

if (type == CY_U3P_DMA_CB_PROD_EVENT) 

{       

     int i = 0

     while( i!= input->buffer_p.count

     { 

           input->buffer_p.buffer[i++] = '1'

      }

}     

- when i loaded the firmware and tried to copy a file from host system to USB, it stuck while writing. File is .txt and containing only hello data. I am unable to figure out why it get stuck while writing.

- i have one more doubt, does the memory of buffer allocated at the time callback?

Thanks and regards,

Taufeeq

0 Likes

Hello,

- The callback function is similar to an interrupt block and it should not be a blocking function. It is essential that the callback function is processed quickly. I find that you are trying to modify the entire buffer data in the callback function which is not advisable.

- The DMA buffer space is allocated at the time of DMA channel creation.

Best regards,

Srinath S

0 Likes

Hello Srinath,

Thanks for your suggestion, but my requirement is to modify entire buffer. As i have mentioned size(5 bytes) of file is very small, so i don't think it should affect callback.

- Is there any terminating character at the end of buffer?

Thanks and regards,

Taufeeq

0 Likes

Hello Taufeeq,

- Please let me know how the data transfer is performed from the host application. Is it just copy/paste of the file into the memory device or are you using a custom application with the SCSI commands to write data to the memory device.

- Where do you find the hang - On the host side or on the FX3 firmware?

- In the firmware code snippet that you have attached, please check if the firmware control comes out of the while block by having a debug print after the loop. Also, ensure that you have used the EDIT: CyU3PDmaChannelCommitBuffer() CyU3PDmaMultiChannelCommitBuffer() API to commit the data onto the consumer socket in the PROD event handler.

Best regards,

Srinath S

0 Likes

Hello Srinath,

Thank you for response.

- I am using Pactron FX3 raid on chip, which does not support debug. When i talked to vendor, they told me short some pin which is possible for me because this chip machine soldiered and also they mentioned if i do so, i may not able to flash, because same pin has been used for SPI and serial. Due to lack of debug its becoming quite complicated for me to understand the things.

-  As for data transmission from Host, i am just using copy paste on windows machine.

- After changing Data in while loop, CyU3PDmaChannelCommitBuffer() is getting called at the end of DMA callback.

- If i am doing something wrong, please suggest me some example for modifying buffer data before storing it.

- Is there any other way to modify buffer data?

0 Likes

Hello Taufeeq,

- Firstly, please let me know why do you need to modify the entire buffer contents in the FX3S firmware.

- When the data is copy-pasted on the PC host, the data transfer length will not be the same size as the number of bytes of text in the file (in your case, not just 5 bytes of data will be sent). This is because, the storage device stores data in clusters and hence the USB host sends data in terms of these clusters. Please view the below image which was captured when I copied a text file containing the text "Hello" into the storage device. So, in the callback, you are actually trying to modify the entire 4096 bytes of data which is not advisable.

pastedImage_0.png

- Also, the data that is sent as part of the BULK OUT transfer contains additional information relating to the File System implementations on the storage device. Hence, it is essential that these data are not modified inappropriately.

Best regards,

Srinath S

Hello Srinath,

Thanks for your reply and making things more clear to me.

- I am trying to encrypt data before writing on SD card and decrypt before reading it from SD card.

- There should be some way to modify only particular data not all other file system information.

- What should i do to modify only data not entire buffer? if it is possible please let me know.

Thanks and regards,

Taufeeq.

0 Likes

Hello Taufeeq,

Please perform the encryption/decryption of data on the host before sending/receiving to/from the device. The FX3S is unaware of the file system implementation from the host. It acts as a pass-through for the data from the host.

When the encryption of the data is done in the FX3S firmware, the data can still be sniffed when transmitting between host and FX3S. Please let me know if there is any special use case of yours why the data needs to be encrypted in FX3S firmware.


Best regards,

Srinath S

0 Likes