Hi all,
I am a newbie in Keil MDK. I am trying to run some file operations from a USB mass storage connected to my STM32429-i evaluation board. I am using CMSIS RTOS and CMSIS compliant peripheral drivers. Referring the following link: http://www.keil.com/pack/doc/mw/USB/html/index.html, I have written a test application in which there are two threads. One thread is performing some file operation (file open, write, read, copy continuously) and one thread is checking the mass storage connection status periodically.
I need to recover from a usb mass storage disconnect/connect gracefully in this situation. But my observation is, while I am accessing the file over USB (eg: fread() API in FS stack), if a USB disconnect happens, the internal USB core thread created by the USB stack is going to some WAIT state. And all my threads, USB file operation thread and USB connection monitoring thread are also going to some WAIT state. Somewhat like a deadlock.
Please share your valuable thoughts on how can I recover from this situation. Is the USB stack provide any support to know the USB_DISCONNECT event and gracefully handle it.
I understood from the link www.keil.com/.../group___u_s_b_h__port__events.html CMSIS driver is signalling some event like ARM_USBH_EVENT_DISCONNECT. But how do I know it from USB stack or from my application while I am performing fread()?
Thank you, Honey S
Generally, you should check return values of file system functions for example Keil's standard USB Host with File System example \Middleware\USB\Host\MassStorage\ example uses fgetc function for reading file and this function specifies that if an error (such as no media because of disconnect) occurred it returns EOF. Also, this example terminates the file read when EOF is returned and if USB stick is reconnected file can be accessed again.
Hi, Thank you for your response. I understood the point. But in my test application, I have checked for return values and error status for most of the file system related calls like fopen(), fread() except for fseek() and fclose(). Even at one instant, I got my debug log for ferror(FP) check after fread() when USB is disconnected. But all the other times, it is hung when USB disconnected while fread() happens [Verifying this via debug logs only]. One thing is my fread is for 32Kb bytes read every-time. Do you think is there any known issue of things like this while fread is going on and the device underneath is disconnected, how fread() will behave? Under all cases, does it recover instantly?
Hi, Same problem, the thread deadlock when I unplug my usb during fread() or fwrite() any solution ?
Hi, can you provide more info:
- which microcontroller and board are you using (board custom or commercial evaluation board)? - which MDK version? - which middleware version? - which device pack and which version?