<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>LPC MicrocontrollersのトピックRe: Implementing a mass storage device, reading an external Image file</title>
    <link>https://community.nxp.com/t5/LPC-Microcontrollers/Implementing-a-mass-storage-device-reading-an-external-Image/m-p/1320311#M46105</link>
    <description>&lt;P&gt;After some digging, seems that the problem is with the cdc that received the bulk data.&lt;/P&gt;&lt;P&gt;Since this have nothing to do with MSC, I will create a new post with the CDC issue.&lt;/P&gt;</description>
    <pubDate>Tue, 10 Aug 2021 07:11:47 GMT</pubDate>
    <dc:creator>embedded_eng_</dc:creator>
    <dc:date>2021-08-10T07:11:47Z</dc:date>
    <item>
      <title>Implementing a mass storage device, reading an external Image file</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/Implementing-a-mass-storage-device-reading-an-external-Image/m-p/1319970#M46091</link>
      <description>&lt;P&gt;Hi, I'm using&amp;nbsp;&lt;SPAN&gt;lpcxpresso55s16_dev_composite_cdc_msc_bm&amp;nbsp;&lt;/SPAN&gt;with a&amp;nbsp;&lt;SPAN&gt;LPC55S16-EVK board.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;USB HS is connected to PC A and exposes a CDC interface and a HID interface, and USB FB is connected to PC B and exposes a MSC interface.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The general purpose is that PC B will be able to mount an img file that exist in PC A.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Every&amp;nbsp;read request received from PC B is read by the MCU, then the MCU issues a HID command to PC A, asking the specific block, which is sent through a CDC channel.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Since the image size is&amp;nbsp;209715200 Bytes (409600 512 blocks), the&amp;nbsp;capacityInformation-&amp;gt;totalLbaNumberSupports parameter is set to be&amp;nbsp;409600.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;usb_status_t USB_DeviceMscCallback(class_handle_t handle, uint32_t event, void *param)
{
    usb_status_t error = kStatus_USB_Success;
    usb_device_lba_information_struct_t *lbaInformationStructure;
    usb_device_lba_app_struct_t *lbaData;
    usb_device_ufi_app_struct_t *ufi;
    usb_device_capacity_information_struct_t *capacityInformation;

    switch (event)
    {
        case kUSB_DeviceMscEventReadResponse:
            lbaData = (usb_device_lba_app_struct_t *)param;
            break;
        case kUSB_DeviceMscEventWriteResponse:
            lbaData = (usb_device_lba_app_struct_t *)param;
            break;
        case kUSB_DeviceMscEventWriteRequest:
            lbaData = (usb_device_lba_app_struct_t *)param;
            /*offset is the write start address get from write command, refer to class driver*/
            lbaData-&amp;gt;buffer = g_deviceComposite_fs-&amp;gt;mscDisk.storageDisk + lbaData-&amp;gt;offset * LENGTH_OF_EACH_LBA;
            break;
        case kUSB_DeviceMscEventReadRequest:
            lbaData = (usb_device_lba_app_struct_t *)param;
            /*offset is the read start address get from read command, refer to class driver*/
            send_hid(lbaData-&amp;gt;offset); //asks for the block in this offset
            lbaData-&amp;gt;buffer = get_bulk();//get block from cdc
            break;
        case kUSB_DeviceMscEventGetLbaInformation:
            lbaInformationStructure                             = (usb_device_lba_information_struct_t *)param;
            lbaInformationStructure-&amp;gt;logicalUnitNumberSupported = LOGICAL_UNIT_SUPPORTED;

            lbaInformationStructure-&amp;gt;logicalUnitInformations[0].lengthOfEachLba = LENGTH_OF_EACH_LBA;
            lbaInformationStructure-&amp;gt;logicalUnitInformations[0].totalLbaNumberSupports = 409600;
            lbaInformationStructure-&amp;gt;logicalUnitInformations[0].bulkInBufferSize  = 512;
            lbaInformationStructure-&amp;gt;logicalUnitInformations[0].bulkOutBufferSize = 512;
            break;
        case kUSB_DeviceMscEventTestUnitReady:
            /*change the test unit ready command's sense data if need, be careful to modify*/
            ufi = (usb_device_ufi_app_struct_t *)param;
            break;
        case kUSB_DeviceMscEventInquiry:
            ufi         = (usb_device_ufi_app_struct_t *)param;
            ufi-&amp;gt;size   = sizeof(usb_device_inquiry_data_fromat_struct_t);
            ufi-&amp;gt;buffer = (uint8_t *)&amp;amp;g_InquiryInfo;
            break;
        case kUSB_DeviceMscEventModeSense:
            ufi         = (usb_device_ufi_app_struct_t *)param;
            ufi-&amp;gt;size   = sizeof(usb_device_mode_parameters_header_struct_t);
            ufi-&amp;gt;buffer = (uint8_t *)&amp;amp;g_ModeParametersHeader;
            break;
        case kUSB_DeviceMscEventModeSelect:
        	usb_echo("kUSB_DeviceMscEventModeSelect\r\n");
            break;
        case kUSB_DeviceMscEventModeSelectResponse:
            ufi = (usb_device_ufi_app_struct_t *)param;
            break;
        case kUSB_DeviceMscEventFormatComplete:
            break;
        case kUSB_DeviceMscEventRemovalRequest:
            break;
        case kUSB_DeviceMscEventRequestSense:
            break;
        case kUSB_DeviceMscEventReadCapacity:
            capacityInformation                         = (usb_device_capacity_information_struct_t *)param;
            capacityInformation-&amp;gt;lengthOfEachLba        = LENGTH_OF_EACH_LBA;
            capacityInformation-&amp;gt;totalLbaNumberSupports = 409600;
            break;
        case kUSB_DeviceMscEventReadFormatCapacity:
            capacityInformation                         = (usb_device_capacity_information_struct_t *)param;
            capacityInformation-&amp;gt;lengthOfEachLba        = LENGTH_OF_EACH_LBA;
            capacityInformation-&amp;gt;totalLbaNumberSupports = 409600;
            break;
        default:
            break;
    }
    return error;
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I wrote a script for PC A that listens to the relevant /dev/hidraw port, and sends the blocks through the relevant /dev/ttyACM port.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Now, the only issue I have seems to be with the offsets.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;When the USB FS&amp;nbsp; is connected to PC B, after the following events:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;kUSB_DeviceMscEventGetLbaInformation&lt;BR /&gt;kUSB_DeviceMscEventGetLbaInformation&lt;BR /&gt;kUSB_DeviceMscEventInquiry&lt;BR /&gt;kUSB_DeviceMscEventTestUnitReady&lt;BR /&gt;kUSB_DeviceMscEventReadCapacity&lt;BR /&gt;kUSB_DeviceMscEventModeSense&lt;BR /&gt;kUSB_DeviceMscEventModeSense&lt;BR /&gt;kUSB_DeviceMscEventTestUnitReady&lt;BR /&gt;kUSB_DeviceMscEventRemovalRequest&lt;BR /&gt;kUSB_DeviceMscEventTestUnitReady&lt;BR /&gt;kUSB_DeviceMscEventReadCapacity&lt;BR /&gt;kUSB_DeviceMscEventModeSense&lt;BR /&gt;kUSB_DeviceMscEventModeSense&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;4168 read events are received, with o&lt;/SPAN&gt;&lt;SPAN&gt;ffsets:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;0, 512, 1024, 1536, 2048, 2560, 3072, 3584&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Then:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;209649664,&amp;nbsp;209650176,&amp;nbsp;209650688,&amp;nbsp;209651200,&amp;nbsp;209651712, ,209652224 ,&amp;nbsp;209652736...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Then:&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;0, 512, 1024, 1536, 2048, 2560, 3072, 3584..&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;It goes like this until&amp;nbsp;4168 request were made.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;It asks for the same blocks several&amp;nbsp;times.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;After these events, a /dev/sdX1 partition appears on PC B.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Now, If I'm trying to mount the partition I get a filesystem error.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;When I try to look at the content using&amp;nbsp; hexdump command, PC B issues some more read commands, and I see: "This is not a bootable disk. please insert a bootable floopy and..."&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Maybe someone can help with that?&lt;/P&gt;</description>
      <pubDate>Sun, 08 Aug 2021 15:13:07 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/Implementing-a-mass-storage-device-reading-an-external-Image/m-p/1319970#M46091</guid>
      <dc:creator>embedded_eng_</dc:creator>
      <dc:date>2021-08-08T15:13:07Z</dc:date>
    </item>
    <item>
      <title>Re: Implementing a mass storage device, reading an external Image file</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/Implementing-a-mass-storage-device-reading-an-external-Image/m-p/1320311#M46105</link>
      <description>&lt;P&gt;After some digging, seems that the problem is with the cdc that received the bulk data.&lt;/P&gt;&lt;P&gt;Since this have nothing to do with MSC, I will create a new post with the CDC issue.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Aug 2021 07:11:47 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/Implementing-a-mass-storage-device-reading-an-external-Image/m-p/1320311#M46105</guid>
      <dc:creator>embedded_eng_</dc:creator>
      <dc:date>2021-08-10T07:11:47Z</dc:date>
    </item>
  </channel>
</rss>

