AnsweredAssumed Answered

New SDK fsl_usb_device_msd_class problem in USB_MSC_DEVICE_WRITE_REQUEST

Question asked by Daniele Cortellazzi on Mar 30, 2015
Latest reply on Apr 3, 2015 by Mark Butcher

Hi all,

 

i'm using the new SDK library with le MSD library. My problem is in the function:

 

uint8_t msd1_class_specific_callback(uint8_t event_type, uint16_t value, uint8_t ** data, uint32_t * size, void * arg)

{

 

...................................................

 

    /* Prepare the storage device buffer for USB transfer */

  case USB_MSC_DEVICE_WRITE_REQUEST:

#ifdef msd1_RAM_DISK_DEMO              /* USB RAM disk PEx demo project (This code is possible to enable by 'USB RAM disk demo' property). */

  lba_data_ptr = (lba_app_struct_t *)size;

  if(data != NULL) {

  *data = (uint8_t *)&msd1_StorageDisk[lba_data_ptr->offset];

  }

#else

  /* copy data from USb buffer to Storage device

  (Called before after recv_data on BULK OUT endpoints)*/

  lba_data_ptr = (lba_app_struct_t*) size;

  *data = (uint8_t *) &buffer_out;

 

  //printf("offset=0x%08X,offset>>9=0x%08X\r\n",lba_data_ptr->offset,lba_data_ptr->offset>>9);

 

  if ((lba_data_ptr->offset >> 9) == FATTable0Sec0) { /* write new file */

  new_file = TRUE;

  printf("new_file=TRUE\r\n");

  } /* EndIf */

 

  if (((lba_data_ptr->offset >> 9) == FATRootDirSec0)

  && (new_file == TRUE)) {

  /* read file size of the file was received */

  /* search for the file entry was received */

  /* each file entry contain 32 bytes */

  for (i = lba_data_ptr->size - 32; i > 0; i -= 32) {

  if (*(lba_data_ptr->buff_ptr + i) != 0) {

  break;

  } /* EndIf */

  } /* Endfor */

 

  /* the file size field is offet 28 of file entry */

#if (defined MCU_MK60N512VMD100)

  file_size = *(uint_32*)( lba_data_ptr->buff_ptr + i + 28);

#else

  file_size = BYTESWAP32( *(uint_32* )(lba_data_ptr->buff_ptr + i + 28));

  printf("file_size=0x%08X\r\n", file_size);

#endif

  new_file = FALSE;

  } /* EndIf */

 

  if ((lba_data_ptr->offset >> 9) == FATDataSec0) {

  erase_flash();

  filetype = UNKNOWN;

  printf("\n\tOpen Image File");

  } /* EndIf */

 

  if ((lba_data_ptr->offset >> 9) >= FATDataSec0) {

  /* parse and flash an array to flash memory */

  if (FLASH_IMAGE_SUCCESS == error) {

  printf("\r\nbufsize=%d\r\n", lba_data_ptr->size);

  printf("bufaddr=0x%08X\r\n", lba_data_ptr->buff_ptr);

  //dumpBuf(lba_data_ptr->buff_ptr, lba_data_ptr->size, 16);

  error = FlashApplication(lba_data_ptr->buff_ptr, lba_data_ptr->size);

  }

  } /* EndIf */

 

  /* rest of file */

  //printf("Rest of file\r\n");

  if (((lba_data_ptr->offset >> 9) - FATDataSec0)

  == ((file_size - 1) / 512)) {

  boot_complete = TRUE;     //tranfer file done

 

  if (BootloaderStatus == BootloaderReady) {

  BootloaderStatus = BootloaderSuccess;

  }

 

  /* print flashing status */

  if (BootloaderStatus != BootloaderSuccess) {

  printf("\nFlash image file fail!");

  } else {

  printf("\nFlash image file complete!");

  printf("\nPress RESET button to enter application mode.");

  } /* EndIf */

  } /* EndIf */

#endif

      break;

.................................................

 

}

 

where the USB_MSC_DEVICE_WRITE_REQUEST is called. This call is done by the :

  • USB_MSC_LBA_Transfer function with msc_obj_ptr->class_specific_callback.callback(USB_MSC_DEVICE_WRITE_REQUEST,  USB_REQ_VAL_INVALID,&msc_obj_ptr->msd_buff.msc_bulk_out_ptr,(uint32_t *)&lba_data, msc_obj_ptr->class_specific_callback.arg);
  • USB_Service_Bulk_Out function with msc_obj_ptr->class_specific_callback.callback(USB_MSC_DEVICE_WRITE_REQUEST,  USB_REQ_VAL_INVALID,&msc_obj_ptr->msd_buff.msc_bulk_out_ptr, NULL, msc_obj_ptr->class_specific_callback.arg);

function in usb_msc.c. As visible the call is different and in USB_Service_Bulk_Out the parameter of size and offset are declare as NULL. Why this? my problem is than that i can't write correctly the data.

 

Thanks

 

Daniele

Outcomes