Author Topic: ATSAMS70 Inconsistent USB connection  (Read 1106 times)

0 Members and 1 Guest are viewing this topic.

Offline MBarkerTopic starter

  • Newbie
  • Posts: 1
  • Country: ca
ATSAMS70 Inconsistent USB connection
« on: April 02, 2019, 03:46:31 am »

We are using an ATSAMS70N21B on a PCB that we designed and had built. We are trying to connect the board to a USB 3.1 memory stick and run the USB in high speed mode. However, we are having trouble getting the USB to work consistently. One time we’ll run the code and it will work fine then another time we run the same code and the microcontroller doesn’t connect to the USB. We used a similar code on a SAM E70 Xplained development board and it worked fine. The code and the errors we are getting are given below. Are there any suggestions on code/libraries that we should look at modifying to get the USB to work consistently?
We are using the ASF 3.40 version on atmel studio. The library used for accessing the usb is the usb host mass storage and for opening/reading the files is fatfs.


int main(void)
{
#if SAMD21 || SAML21
       //system_init();
#else
       sysclk_init();
       board_init();
#endif
       irq_initialize_vectors();
       cpu_irq_enable();

       // Initialize the sleep manager
       sleepmgr_init();

       ui_init();

       // Start USB host stack
       uhc_start();
             
       
       
       while (main_usb_sof_counter <= 2000) {
             }
             main_usb_sof_counter = 0;
             volatile uint8_t lun;
             FRESULT res;

                    // Mount drive
                    memset(&fs, 0, sizeof(FATFS));
                    res = f_mount(lun, &fs);////This command occasionally returns   
                                                 FR_INVALID_DRIVE
                    if (FR_INVALID_DRIVE == res) {
                           // LUN is not present
                           lun_states[lun] = TEST_NO_PRESENT;
                           continue;
                    }
                   
                    // Create a test file on the disk
                    test_file_name[0] = lun + '0';
             
                    res = f_open(&file_object,
                    (char const *)test_file_name,
                    FA_CREATE_ALWAYS | FA_WRITE);////This returns FR_NOT_READY OR
                                                  FR_DISK_ERROR
                    if (res == FR_NOT_READY) {
                           // LUN not ready
                           lun_states[lun] = TEST_NO_PRESENT;
                           f_close(&file_object);
                           continue;
                    }
                    if (res != FR_OK) {
                           // LUN test error
                           lun_states[lun] = TEST_ERROR;
                           f_close(&file_object);
                           continue;
                    }
                    f_close(&file_object);
                   
       }
When the power is reset on the device the above program usually behaves in three different ways:
1)   It works at times ,executes all the statements ,returns FR_OK and creates a text file on the usb
2)   It returns FR_OK for f_mount but returns FR_not_ready for f_open statement or at times it just skips the statement
3)   It returns FR_INVALID_DRIVE after the F_mount statement is executed and then it just skips the rest of the program. When this happens, the LUN obtained is usually a random number.
Whenever 2 or 3 happens STA_NOINT is not cleared in the disk_initialize statement which needs to be cleared for the drive to be initialized.

 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11261
  • Country: us
    • Personal site
Re: ATSAMS70 Inconsistent USB connection
« Reply #1 on: April 02, 2019, 04:39:26 am »
I don't think you can avoid debugging this thing and actually tracing what causes those error codes.

If I remember correctly, there are some issues with debouncing, so if this error only happens when you insert the drive while device is already running, then it might be it. If it happens even after reset when the drive is already connected, then it is something else.
Alex
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf