Due to high demand expect some shipping delays at this time, orders may not ship for 1-2 business days.
0

Why does using Serial before enabling TinyUSB usb_msc preven
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Why does using Serial before enabling TinyUSB usb_msc preven

by keylevel on Mon May 03, 2021 6:46 pm

Looking at the code within setup() for msc_ramdisk.ino:

Code: Select all | TOGGLE FULL SIZE
// the setup function runs once when you press reset or power the board
void setup()
{
  // Set disk vendor id, product id and revision with string up to 8, 16, 4 characters respectively
  usb_msc.setID("Adafruit", "Mass Storage", "1.0");
 
  // Set disk size
  usb_msc.setCapacity(DISK_BLOCK_NUM, DISK_BLOCK_SIZE);

  // Set callback
  usb_msc.setReadWriteCallback(msc_read_cb, msc_write_cb, msc_flush_cb);

  // Set Lun ready (RAM disk is always ready)
  usb_msc.setUnitReady(true);
 
  usb_msc.begin();

  Serial.begin(115200);
  while ( !Serial ) delay(10);   // wait for native usb

  Serial.println("Adafruit TinyUSB Mass Storage RAM Disk example");
}
Why does the MSC device not work (as in, it does not show on the host PC) if the serial commands are moved to the start of the function?

Code: Select all | TOGGLE FULL SIZE
// the setup function runs once when you press reset or power the board
void setup()
{
  Serial.begin(115200);
  while ( !Serial ) delay(10);   // wait for native usb

  Serial.println("Adafruit TinyUSB Mass Storage RAM Disk example");

  // Set disk vendor id, product id and revision with string up to 8, 16, 4 characters respectively
  usb_msc.setID("Adafruit", "Mass Storage", "1.0");
 
  // Set disk size
  usb_msc.setCapacity(DISK_BLOCK_NUM, DISK_BLOCK_SIZE);

  // Set callback
  usb_msc.setReadWriteCallback(msc_read_cb, msc_write_cb, msc_flush_cb);

  // Set Lun ready (RAM disk is always ready)
  usb_msc.setUnitReady(true);
 
  usb_msc.begin();
}
I want to be able to do this so that I can use Serial before the MSC device is initialised.

I suspect this is a startup sequencing issue, but I'm not sure where to look to try and work out what's going on. Any pointers would be appreciated.

keylevel
 
Posts: 2
Joined: Mon May 03, 2021 6:40 pm

Re: Why does using Serial before enabling TinyUSB usb_msc pr

by blnkjns on Tue May 04, 2021 1:22 am

Why is having serial active first important?

blnkjns
 
Posts: 455
Joined: Fri Oct 02, 2020 3:33 am

Re: Why does using Serial before enabling TinyUSB usb_msc pr

by keylevel on Tue May 04, 2021 4:07 am

blnkjns wrote:Why is having serial active first important?


Because it is being used to allow a FLASH image that will be used as the USB disk to be checked, verified and repaired.

keylevel
 
Posts: 2
Joined: Mon May 03, 2021 6:40 pm

Please be positive and constructive with your questions and comments.