How to Detect uTasker USB to SD Card has Completed Mounting to PC?

Showing results for 
Search instead for 
Did you mean: 

How to Detect uTasker USB to SD Card has Completed Mounting to PC?

Contributor III

How to Detect uTasker USB to SD Card has Completed Mounting to PC?

Because when I plugged in the Teensy 3.5 with uTasker MSD enabled it took 10 seconds to mount when the SD Card's allocation unit size is big like 4096 for faster copy speed. 

Is there an event handler in uTasker USB to SD Card  that can handle when SD card has completed mounting to PC?

2 Replies

Contributor III

Thanks for the advise Sir Mark :smileyhappy: I really appreciate your response :smileyhappy: :smileyhappy: :smileywink:

0 Kudos

Specialist V


USB-MSD operation is an independent process and so there is generally no/little interaction.

1. The mass storage task will check whether the SD card is detected, formatted or not, which takes a fraction of a second at start up. It will signal whether a disk is present and formatted by flags in the disk objects, which the MSD class uses to check the state when returning class responses the the host (eg.):

if ((ptrDiskInfo[ucActiveLUN]->usDiskFlags & (DISK_MOUNTED | DISK_UNFORMATTED)) != 0)

2. This means that usually the host (MSD host PC) will see that there is either a formatted or an un-formatted disk immediately when it connects.

3. The MSD host will however also mount the disk, which means that it reads certain information from it to detect its file system type and it reads its FAT (to have a local copy of it for speed purposes). On larger disks with larger FATs this may require reading MBytes of data that can take a short time. After the PC is happy that the disk is OK (it may also do additional checks and can detect some forms of corruption in the process) it will display the disk as being mounted.

4. The USB-MSD device is not involved with file system details - it only reads and writes blocks of data as commanded by the PC. This means that it also doesn't have any information about when the PC has completed mounting a disk.

It is important to note that the application should not modify data on the SD card when the PC host is connected! It should generally also not access the disk for reads either. This is due to the fact that the PC may be writing data to its local cache and not to the SD card via MSD and so the SD card content is not synchronised to the PC - if the application were to write changes they could be overwritten by the PC (since it doesn't know that FAT changes were made between reading its content it its cache and writing it back, which can lead to FAT corruption or loss of data).

Therefore, applications should use the SD card to do things like data logging in normal operation. Then it should allow the PC to use the card to retrieve this data (or the opposite direction may be true) in a different mode. This is like a photo camera - one uses it to take photos that are saved to the SD card and later one connects to a PC as USB-MSD to retrieve the data - the two are not performed at the same time!

Therefore my question is what is your requirement to know when the PC host has mounted the disk? Generally, if the application needs to avoid accessing the SD card when the host is connected, the USB enumeration events would be the safest method.


On the events

you could block accesses.
On the event


you could allow access again.