cancel
Showing results for 
Search instead for 
Did you mean: 

How to have more than one access to a USB pendrive using STM32L496ZG as USB host

HABIJ.1
Associate III

Hello,

I am trying to write data in .txt file on a USB pendrive at a certain frequency (in the while 1 loop) using STM32L496ZG as the USB host in the Mass Storage Class (MSC) configuration.

I succeded writing to the .txt file in the first iteration, but after I can't access the USB pendrive anymore. I investigated the matter and I found out that when accessing the USB pendrive in the first iteration, the MSC_Handle->State is put to MSC_IDLE (see code below).

static USBH_StatusTypeDef USBH_MSC_Process(USBH_HandleTypeDef *phost)
{
  MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData;
  USBH_StatusTypeDef error = USBH_BUSY;
  USBH_StatusTypeDef scsi_status = USBH_BUSY;
  USBH_StatusTypeDef ready_status = USBH_BUSY;
 
  switch (MSC_Handle->state)
  {
    case MSC_INIT:
 
      if (MSC_Handle->current_lun < MSC_Handle->max_lun)
      {
          ....  // initialization of the MSC
       }
 
      //MSC initialization finished
      else   // if (MSC_Handle->current_lun >= MSC_Handle->max_lun) where max_lun =1
      {
        MSC_Handle->current_lun = 0U;
        MSC_Handle->state = MSC_IDLE;                                   //MSC put to IDLE
        phost->pUser(phost, HOST_USER_CLASS_ACTIVE);    //access to the USB
      }
      break;
 
 

In the MSC_IDLE state, we can't access anymore the USB pendrive.

    case MSC_IDLE:
      error = USBH_OK;
      break;

I tried finding where to put the MSC_Handle->State back to MSC_INIT but with no success.

May anyone has a clue to share?

Tell me if more details, on what I did, is needed.

Thanks in advance for your help

0 REPLIES 0