Proper way to Delay / Pause in the middle of USB MSC transaction.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-07-05 2:42 AM
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!
Solved! Go to Solution.
- Labels:
-
STM32F1 Series
-
USB
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-07-10 7:13 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-07-05 4:43 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-07-05 5:54 AM
Thanks for the reply. It's quite similar to my code but the answer still not so clear. I might try something else.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-07-10 7:13 PM
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.
