Bruno
The behavior/control has nothing to do with FreeRTOS - I can do the same with existing FreeRTOS projects - but it is the USB MSD class/file system that actually influences it.
Do you use an SD card together with the MSD? In this case you will need to understand how the FAT and MSD interact together - since I can't help with the NXP stack or fsFAT you will need to either study the details to work it out or request support from the individual sources.
In the uTasker case (which is a complete integrated solution and not a collection of libraries from different sources) [it is also free and open source] it is done by controlling the MSD class responses to various UFI requests - for example, the host will usually be polling the state of the disk and so one place to make it dependent is there (although the host will also request some other card details at enumeration, such as format capacity, where similar "unusable" states need to be returned).
Eg. this is the response to the sense request:
case UFI_REQUEST_SENSE:
{
CBW_RETURN_SENSE_DATA present_sense_data;
uMemcpy(&present_sense_data, &sense_data_OK, sizeof(sense_data_OK)); // prepare positive response
if ((ptrDiskInfo[ucActiveLUN]->usDiskFlags & (DISK_MOUNTED | DISK_UNFORMATTED)) == 0) { // if the disk is not present
present_sense_data.ucValid_ErrorCode = (CURRENT_ERRORS); // set that the disk is presently in a non-usable state
present_sense_data.ucSenseKey = SENSE_NOT_READY;
present_sense_data.ucAdditionalSenseCode = DESC_MEDIUM_NOT_PRESENT;
}
fnWrite(USBPortID_MSD, (unsigned char *)&present_sense_data, sizeof(present_sense_data)); // return the response
}
break;
so if one can control the LUN's disk state one can make MSD think that the disk is not inserted, and then one can set the state back to an inserted/formatted disk when one wants MSD to start working with the disk.
I just manipulated the ptrDiskInfo[ucActiveLUN]->usDiskFlags by adding a controllable mask to do it.
if (((ptrDiskInfo[ucActiveLUN]->usDiskFlags & usLocalMask) & (DISK_MOUNTED | DISK_UNFORMATTED)) == 0) { // if the disk is not present
so I can control it by changing usLocalMask between 0 and (DISK_MOUNTED | DISK_UNFORMATTED).
I assume that your MSD class has basic support for correctly handling disk state information, otherwise you will first need to expand it before you can start controlling it.
Regards
Mark