Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 2 of 2

Thread: MSC race condition during initialization

  1. #1
    Senior Member wwatson's Avatar
    Join Date
    Aug 2017
    Posts
    777

    MSC race condition during initialization

    @Paul @KurtE - Using Arduino 1.8.19, TD1.58 Beta3 I am seeing a intermittent situation with MSC where during uploading and sometimes powering up using the "DriveInfo.ino" sketch for testing results in the msDriveInfo struct is blank:
    Code:
    Waiting for Drive to initialize...
    Device Info:
           connected: 1
         initialized: 0
       USB Vendor ID: 0000
      USB Product ID: 0000
          HUB Number: 0
            HUB Port: 0
      Device Address: 0
    Removable Device: NO
            VendorID:         
           ProductID:                 
          RevisionID:     
             Version: 0
        Sector Count: 0
         Sector size: 0
       Disk Capacity: 0 Bytes
    
    Volume name: 32GFAT32
    Volume type: FAT32
    Cluster Size: 16384 bytes
    Volume size: 30927306752 bytes
     Space used: 375930880 bytes  (922 ms to compute)
    
    Files:
    2021-10-03 16:29   56863276 armaged.wav
    2019-01-01 08:14   40900890 Daddy's_Little_Man.wav
    2021-09-12 23:48   43025728 DeffLepardAnimal.wav
    2021-09-12 23:46   60148898 StatusQuoWhateverYouWant.wav
    2021-09-12 23:44   35639166 ThePaperboysMolinos.wav
    2019-01-01 08:01   36381082 ThePaperboysMolinosI'veJustSeenaFace.wav
    2021-09-12 23:47  102878882 YoureLazyJimmyBarnesJoeBonamassa.wav
    It shows the device is connected but everything else is 0 including 'initialized'. This is from 'printDriveInfo(myDrive)'. The drive info is filled in by the 'mscInit()' function.

    Other times the output is correct:
    Code:
    Waiting for Drive to initialize...
    Device Info:
           connected: 1
         initialized: 1
       USB Vendor ID: 0951
      USB Product ID: 1666
          HUB Number: 0
            HUB Port: 0
      Device Address: 1
    Removable Device: YES
            VendorID: Kingston
           ProductID: DataTraveler 3.0
          RevisionID:     
             Version: 6
        Sector Count: 60437491
         Sector size: 512
       Disk Capacity: 30943995392 Bytes
    
    Partition Table
    	part,boot,bgnCHS[3],type,endCHS[3],start,length
    FAT32:	1,0,0x4,0x1,0x4,0xB,0xFE,0xC2,0xFF,2048,60434432
    pt_#0:	2,0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0,0
    pt_#0:	3,0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0,0
    pt_#0:	4,0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0,0
    	 < unused area starting at: 60436480 length 1011 >
    
    Volume name: 32GFAT32
    Volume type: FAT32
    Cluster Size: 16384 bytes
    Volume size: 30927306752 bytes
     Space used: 375930880 bytes  (922 ms to compute)
    
    Files:
    2021-10-03 16:29   56863276 armaged.wav
    2019-01-01 08:14   40900890 Daddy's_Little_Man.wav
    2021-09-12 23:48   43025728 DeffLepardAnimal.wav
    2021-09-12 23:46   60148898 StatusQuoWhateverYouWant.wav
    2021-09-12 23:44   35639166 ThePaperboysMolinos.wav
    2019-01-01 08:01   36381082 ThePaperboysMolinosI'veJustSeenaFace.wav
    2021-09-12 23:47  102878882 YoureLazyJimmyBarnesJoeBonamassa.wav
    I added a 'Serial.printf()' in:
    Code:
    bool USBDrive::begin() {
    	m_errorCode = MS_CBW_PASS;
    Serial.printf("mscInit()\n");
    	mscInit(); // Do initial init of each instance of a MSC object.
    	m_errorCode = checkConnectedInitialized();
    	if (m_errorCode) { // Check for Connected USB drive.
    		m_initDone = false;
    	} else {
    		m_initDone = true;
    	}
    	return m_initDone;
    }
    And the result when failing is:
    Code:
    Waiting for Drive to initialize...
    Device Info:
           connected: 1
         initialized: 0
       USB Vendor ID: 0000
      USB Product ID: 0000
          HUB Number: 0
            HUB Port: 0
      Device Address: 0
    Removable Device: NO                                                                   
            VendorID:                                                                      
           ProductID:                                                                      
          RevisionID:                                                                      
             Version: 0                                                                    
        Sector Count: 0
         Sector size: 0
       Disk Capacity: 0 Bytes
    
    mscInit() <------ mscInit() called after printDriveInfo().
    Volume name: 128GEXFAT
    Volume type: FAT64
    Cluster Size: 131072 bytes
    Volume size: 123723579392 bytes
     Space used: 159121408 bytes  (91 ms to compute)
    
    Files:
    2011-09-07 16:39     74002706 rom-hackerboard-3320.zip
    2022-04-04 15:07     74901978 rom-falconwing.img.zip
    2011-10-30 12:07       978134 IOMux.v2.0.27.zip
    2011-10-30 12:07       754815 IMX23REFSCH.zip
    2022-04-04 17:51      4273249 falconwing_chb3_all.zip
    2011-09-07 16:39         7368 chumby-user-group-pages.zip
    2011-09-07 16:39       115691 chumby-user-group-files.zip
    2011-09-07 16:39       470245 chumbyone_gerbers.zip
    2011-09-07 16:39       664812 chumby_hackerboard_gerbers.zip
    2011-09-07 16:39      1748436 chumby_hackerboard.zip
    2011-10-30 12:06        18247 Debian_on_a_Chumby.html
    When not failing results are:
    Code:
    Waiting for Drive to initialize...
    mscInit() <------ mscInit() called before printDriveInfo().
    Device Info:
           connected: 1
         initialized: 1
       USB Vendor ID: 0951
      USB Product ID: 1666
          HUB Number: 0
            HUB Port: 0
      Device Address: 1
    Removable Device: YES
            VendorID: Kingston
           ProductID: DataTraveler 3.0
          RevisionID:     
             Version: 6
        Sector Count: 241660915
         Sector size: 512
       Disk Capacity: 123730388480 Bytes
    
    Partition Table
            part,boot,bgnCHS[3],type,endCHS[3],start,length
    exFAT:  1,0,0x4,0x1,0x4,0x7,0xFE,0xC2,0xFF,2048,241657856
    pt_#0:  2,0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0,0
    pt_#0:  3,0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0,0
    pt_#0:  4,0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0,0
             < unused area starting at: 241659904 length 1011 >
    
    Volume name: 128GEXFAT
    Volume type: FAT64
    Cluster Size: 131072 bytes
    Volume size: 123723579392 bytes
     Space used: 159121408 bytes  (90 ms to compute)
    
    Files:
    2011-09-07 16:39     74002706 rom-hackerboard-3320.zip
    2022-04-04 15:07     74901978 rom-falconwing.img.zip
    2011-10-30 12:07       978134 IOMux.v2.0.27.zip
    2011-10-30 12:07       754815 IMX23REFSCH.zip
    2022-04-04 17:51      4273249 falconwing_chb3_all.zip
    2011-09-07 16:39         7368 chumby-user-group-pages.zip
    2011-09-07 16:39       115691 chumby-user-group-files.zip
    2011-09-07 16:39       470245 chumbyone_gerbers.zip
    2011-09-07 16:39       664812 chumby_hackerboard_gerbers.zip
    2011-09-07 16:39      1748436 chumby_hackerboard.zip
    2011-10-30 12:06        18247 Debian_on_a_Chumby.html
    This may or may not be a problem but can be misleading and/or misinterpreted as a failure. 'mscInit()' is eventually called after 'printDriveInfo'.

    If I add a manual call to 'myDrive.begin()'in the sketch the results are:
    Code:
    Waiting for Drive to initialize...
    mscInit() <----- Manual call to myDrive.begin().
    Device Info:
           connected: 1
         initialized: 1
       USB Vendor ID: 0951
      USB Product ID: 1666
          HUB Number: 0
            HUB Port: 0
      Device Address: 1
    Removable Device: YES
            VendorID: Kingston
           ProductID: DataTraveler 3.0
          RevisionID:     
             Version: 6
        Sector Count: 241660915
         Sector size: 512
       Disk Capacity: 123730388480 Bytes
    
    Partition Table
            part,boot,bgnCHS[3],type,endCHS[3],start,length
    exFAT:  1,0,0x4,0x1,0x4,0x7,0xFE,0xC2,0xFF,2048,241657856
    pt_#0:  2,0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0,0
    pt_#0:  3,0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0,0
    pt_#0:  4,0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0,0
             < unused area starting at: 241659904 length 1011 >
    
    mscInit() <----- startFileSystems() call to USBDrive::begin().
    Volume name: 128GEXFAT
    Volume type: FAT64
    Cluster Size: 131072 bytes
    Volume size: 123723579392 bytes
     Space used: 159121408 bytes  (90 ms to compute)
    
    Files:
    2011-09-07 16:39     74002706 rom-hackerboard-3320.zip
    2022-04-04 15:07     74901978 rom-falconwing.img.zip
    2011-10-30 12:07       978134 IOMux.v2.0.27.zip
    2011-10-30 12:07       754815 IMX23REFSCH.zip
    2022-04-04 17:51      4273249 falconwing_chb3_all.zip
    2011-09-07 16:39         7368 chumby-user-group-pages.zip
    2011-09-07 16:39       115691 chumby-user-group-files.zip
    2011-09-07 16:39       470245 chumbyone_gerbers.zip
    2011-09-07 16:39       664812 chumby_hackerboard_gerbers.zip
    2011-09-07 16:39      1748436 chumby_hackerboard.zip
    2011-10-30 12:06        18247 Debian_on_a_Chumby.html
    Successful initialization consistently. Will have to experiment more to try and fix it. Any help is welcome

    Edit: Tested with 4 different USB thumb drives and a SSD drive. Same results.
    Last edited by wwatson; 01-21-2023 at 10:23 PM. Reason: More Info...

  2. #2
    Senior Member wwatson's Avatar
    Join Date
    Aug 2017
    Posts
    777
    Turns out the issue is with 'DriveInfo.ino' itself. Here is the changed section of the sketch.

    Code:
      // Wait for the drive to start.
      while (!myDrive) {
    //    myusb.Task();
      }
      myusb.Task();
    This works consistently with all my USB drives.
    Ran out of time tonight check it out further...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •