attempting to list the files using SAM21D USB host

Go To Last Post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Greetings: I am trying to list the files in a USB drive and search for a specific file using strstr();

It is opening the drive but it keeps listing the file name as " SYSTEM~1" and this file does not exist on the drive. I need to find "FILE1" instead. It is on the drive and spelled correctly . Can someone tell me where I am going wrong? Thank you

	WatchDog_Reset();
	WatchDog_Disable();
	
	/* Check if a MSC device and its LUN are configured. */
 
	   
	   
		/* The USB management is entirely managed by interrupts */
	while (true) 
	   {
		   
	   /* Check if a MSC device and its LUN are configured */
	   if (!lun_connected) 
	      {
		  if((rTimer_1ms_Flag % 1000) == 0) /*every 1s*/
		     {
					
		       UpdateCompleteScreen();	     		  
		     }	  
		  continue;
		  }
	   /* Adding a small delay to ensure that the MSC device is ready */
	   while (main_usb_host_sof_counter  < MSC_DELAY_SOF_COUNT);

	   /* Go through the different LUN and check for the file. */
	   for (lun = 0; (lun < uhi_msc_mem_get_lun()) && (lun < 8); lun++) 
	      {			 
    
			   
		  root_directory[0] = '0' + lun;

		  /* Initialize the file system object */
		  memset(&fs, 0, sizeof(FATFS));

		  /* 
		   * Set and mount the currently selected LUN as a drive
		   * in Navigator
		   */
		  
		  FRESULT res = f_mount(lun, &fs);
		  /* Check the return status */
		  if (res != FR_OK) 
		     {
		     if((rTimer_1ms_Flag % 1000) == 0) /*every 1s*/
		        {

			    
			    UpdateCompleteScreen();
				}
			 continue;
		     }

		  /* Open the root directory */
		  res = f_opendir(&file_dir, root_directory);
		  /* Check the return status */
		  if (res != FR_OK) 
		     {
		     if((rTimer_1ms_Flag % 1000) == 0) /*every 1s*/
			    {
			    /* Check the next LUN */
			    
			    UpdateCompleteScreen();
			    }
			 continue;
			 }
			 
		  for(;;)
		     {	 
				 
	         res = f_readdir(&file_dir, &f_info); /*reads directory items, informations about file and directory, in sequence*/

	         if((res != FR_OK) || (f_info.fname[0] == 0)) /*if there is a read directory error or the end of dir*/
	            {
				if((rTimer_1ms_Flag % 1000) == 0) /*every 1s*/
				   {
			       
			       UpdateCompleteScreen();
					  break;
				   }
		        continue;
	            }	
		
		
			/* If the long file name is null but a shorter filename exists than the shorter one becomes the name */
			 if((f_info.lfname == NULL) && (f_info.fname != NULL))
			    f_info.lfname = f_info.fname;
		
				
			/* Try and find the new file names. If they exist open them */	
			 if(strstr(f_info.lfname, "FILE1") !=NULL) 
			    {
					if(gCB_Version == 24)
					{
						res = f_open(&file_object,f_info.lfname, FA_READ);
					}
				}
			else if(strstr(f_info.lfname, "FILE2") !=NULL)
				{
					if(gCB_Version == 12)
					{
						res = f_open(&file_object,f_info.lfname, FA_READ);
					}
				}
				
			/* Catch all for older equipment */	
			else if(strstr(f_info.lfname, "FILE3B.hex") !=NULL)	
				{
				res = f_open(&file_object,f_info.lfname, FA_READ);	     		  
				} 

 

Last Edited: Fri. Dec 8, 2017 - 12:39 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

An why or why do you post a SAM D21 question on an UC3 forum?? Moving.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly