cancel
Showing results for 
Search instead for 
Did you mean: 

Proper way to Delay / Pause in the middle of USB MSC transaction.

TinLethax
Associate II

Hello. I'm currently implementing USB Drag and Drop Bitstream loader for FPGA using STM32F103CBTB and latest CubeIDE (1.10.0). The implementation uses STM32 in USB Mass storage class and virtual file system based on FAT12. The part of Drag and drop is working fine. But If I add 200ms delay into the code (line 354) which is under STORAGE_Write_FS() in usbd_storage_if.c , This cause USB to halt. So, my question is there any way to pause USB transaction for 200ms delay and continue transaction? I attached the source of usbd_storage_if.c down below for who want to take a look at. Thank in advance!

1 ACCEPTED SOLUTION

Accepted Solutions
TinLethax
Associate II

I solved the problem. I was able to add delay by using while loop decrement.

uint32_t cnt = 0x1FFFF; // This seems to give me ~200ms delay at 48MHz clock
 
STORAGE_Write_FS(){
 
// Stuffs before delay
while(cnt--); // the delay
// Stuffs after delay
 
}

One thing I discovered is the code optimization affect this delay. By set to non or optimize for debug doesn't break the delay. But other optimization break the delay.

View solution in original post

3 REPLIES 3
TinLethax
Associate II

Thanks for the reply. It's quite similar to my code but the answer still not so clear. I might try something else.

TinLethax
Associate II

I solved the problem. I was able to add delay by using while loop decrement.

uint32_t cnt = 0x1FFFF; // This seems to give me ~200ms delay at 48MHz clock
 
STORAGE_Write_FS(){
 
// Stuffs before delay
while(cnt--); // the delay
// Stuffs after delay
 
}

One thing I discovered is the code optimization affect this delay. By set to non or optimize for debug doesn't break the delay. But other optimization break the delay.