• AVR Freaks

Hot!fileio and thumb drive help.

Author
BrunoC
Starting Member
  • Total Posts : 84
  • Reward points : 0
  • Joined: 2010/11/19 04:05:49
  • Location: France
  • Status: offline
2014/05/14 07:02:29 (permalink)
0

fileio and thumb drive help.

Hello,
I try to use fileio with usb host. (PIC24FJ256GB110)
 
In my project I include :
 
-Header
    -Framework
         -fileio
              fileio.h
         -usb
              usb.h
              usb_ch9.h
              usb_common.h
              usb_hal.h
              usb_hal_pic24.h
              usb_hal_pic24f.h
              usb_host.h
              usb_host_msd.h
              usb_host_msd_scsi.h
       sytem_config.h
       usb_config.h
       fileio_config.h
 
- Source Files
     -Framework
         -fileio
              fileio.c
         -usb
              usb_hal_pic24.c
              usb_host.c
              usb_host_msd.c
              usb_host_msd_scsi.c
       usb_config.c
 
**************************************************************************
for init in main :
 
//Initialize the stack
    FILEIO_Initialize();

    FILEIO_RegisterTimestampGet(GetTimestamp);

    //Initialize the stack
    USBHostInit(0);

 
and add task :
 
USBHostTasks();
USBHostMSDTasks();

 
 
IN main.c add :
 
/****************************************************************************
Function:
bool USB_ApplicationEventHandler( uint8_t address, USB_EVENT event,
void *data, uint32_t size )
Summary:
This is the application event handler. It is called when the stack has
an event that needs to be handled by the application layer rather than
by the client driver.
Description:
This is the application event handler. It is called when the stack has
an event that needs to be handled by the application layer rather than
by the client driver. If the application is able to handle the event, it
returns true. Otherwise, it returns false.
Precondition:
None
Parameters:
uint8_t address - Address of device where event occurred
USB_EVENT event - Identifies the event that occured
void *data - Pointer to event-specific data
uint32_t size - Size of the event-specific data
Return Values:
true - The event was handled
false - The event was not handled
Remarks:
The application may also implement an event handling routine if it
requires knowledge of events. To do so, it must implement a routine that
matches this function signature and define the USB_HOST_APP_EVENT_HANDLER
macro as the name of that function.
***************************************************************************/
bool USB_ApplicationEventHandler(uint8_t address, USB_EVENT event, void *data, uint32_t size) {
switch ((int) event) {
case EVENT_VBUS_REQUEST_POWER:
// The data pointer points to a byte that represents the amount of power
// requested in mA, divided by two. If the device wants too much power,
// we reject it.
return true;
case EVENT_VBUS_RELEASE_POWER:
//This means that the device was removed
return true;
break;
/* Here are various other events that a user might want to handle
* or be aware of. In this demo we are not handling them so we
* will just return true to allow the stack to move on from the error.
*/
case EVENT_HUB_ATTACH:
case EVENT_UNSUPPORTED_DEVICE:
case EVENT_CANNOT_ENUMERATE:
case EVENT_CLIENT_INIT_ERROR:
case EVENT_OUT_OF_MEMORY:
case EVENT_UNSPECIFIED_ERROR: // This should never be generated.
return true;
break;
case EVENT_MSD_ATTACH:
//APP_MountDrive (address);
deviceAddress = address;
deviceAttached = true;
break;
default:
break;
}
return false;
}
// Placeholder function to get the timestamp for FILEIO operations
void GetTimestamp(FILEIO_TIMESTAMP * timestamp) {
// Populate the timestamp field with some inaccurate timestamp information
timestamp->date.bitfield.day = 5;
timestamp->date.bitfield.month = 1;
timestamp->date.bitfield.year = 33;
timestamp->time.bitfield.hours = 8;
timestamp->time.bitfield.secondsDiv2 = 20;
timestamp->time.bitfield.minutes = 10;
timestamp->timeMs = 0;
}

 
Declarations in main.c :
 
static uint8_t deviceAddress = 0;
void GetTimestamp(FILEIO_TIMESTAMP * timestamp);
// Placeholder function for the File I/O driver structure's IO Initialize function
void USBDummyIOInitialize(void * mediaParameters);
void USBDummyIOInitialize(void * mediaParameters) {
}
// Declare a FILEIO_DRIVE_CONFIG structure to describe which functions the File I/O library will use to communicate with the media
const FILEIO_DRIVE_CONFIG gUSBDrive = {
(FILEIO_DRIVER_IOInitialize) USBDummyIOInitialize, // Function to initialize the I/O pins used by the driver.
(FILEIO_DRIVER_MediaDetect) USBHostMSDSCSIMediaDetect, // Function to detect that the media is inserted.
(FILEIO_DRIVER_MediaInitialize) USBHostMSDSCSIMediaInitialize, // Function to initialize the media.
(FILEIO_DRIVER_MediaDeinitialize) USBHostMSDSCSIMediaReset, // Function to de-initialize the media.
(FILEIO_DRIVER_SectorRead) USBHostMSDSCSISectorRead, // Function to read a sector from the media.
(FILEIO_DRIVER_SectorWrite) USBHostMSDSCSISectorWrite, // Function to write a sector to the media.
(FILEIO_DRIVER_WriteProtectStateGet) USBHostMSDSCSIWriteProtectState, // Function to determine if the media is write-protected.
};

 
 
#1

7 Replies Related Threads

    BrunoC
    Starting Member
    • Total Posts : 84
    • Reward points : 0
    • Joined: 2010/11/19 04:05:49
    • Location: France
    • Status: offline
    Re: fileio and thumb drive help. 2014/05/14 07:05:57 (permalink)
    0
    The problem is :
     
    FILEIO_MediaDetect(&gUSBDrive, &deviceAddress) == true

    Is ok
     
    FILEIO_DriveMount('A', &gUSBDrive, &deviceAddress) == FILEIO_ERROR_NONE

    Is ok
     
    FILEIO_Open(&myFile,"es.txt", FILEIO_OPEN_READ) == FILEIO_RESULT_FAILURE

    Result = FAILURE
     
    #2
    BrunoC
    Starting Member
    • Total Posts : 84
    • Reward points : 0
    • Joined: 2010/11/19 04:05:49
    • Location: France
    • Status: offline
    Re: fileio and thumb drive help. 2014/05/14 07:19:36 (permalink)
    0
    In FILEIO_Open :
     

     
    // Check to ensure no errors occured
    if (error != FILEIO_ERROR_NONE)
    {
    directory.drive->error = error;
    return FILEIO_RESULT_FAILURE;
    }

     
    here error = 0xFFFF
     
    Before directory.drive->error = error; error = 0x000F => FILEIO_ERROR_DONE
    post edited by BrunoC - 2014/05/14 07:32:42
    #3
    BrunoC
    Starting Member
    • Total Posts : 84
    • Reward points : 0
    • Joined: 2010/11/19 04:05:49
    • Location: France
    • Status: offline
    Re: fileio and thumb drive help. 2014/05/14 09:25:26 (permalink)
    0
    In FILEIO_DirectoryEntryCache
     
    error= FILEIO_ERROR_DONE here :
     

    case FILEIO_FILE_SYSTEM_TYPE_FAT32:
    if (*currentCluster == FILEIO_CLUSTER_VALUE_FAT32_EOF)
    {
    *error = FILEIO_ERROR_DONE;
    return NULL;
    }
    break;

    #4
    chinzei
    Super Member
    • Total Posts : 2250
    • Reward points : 0
    • Joined: 2003/11/07 12:39:02
    • Location: Tokyo, Japan
    • Status: offline
    Re: fileio and thumb drive help. 2014/05/18 20:42:02 (permalink)
    0
    Maybe, you are working on MLA v2013_12_20
    I tested msd_simple_demo example ( \v2013_12_20\apps\usb\host\msd_simple_demo\ ) on my Explorer16 / PIC24FJ256GB110 PIM. It worked as expected without any change - confirmed on a hardware bus analyzer.

    Try this example, first.
    Copy msd_simple_demo folder at the same place
    - highlight this folder by mouse click, and CTRL-C, CTRL-V)

    Drag the "MPLABX" folder (in this example folder) and drop it to MPLABX IDE icon.
    - MPLABX IDE starts up
    - At the pull-down on the top toolbar, choose "PIC24FJ256GB110_PIM"

    Tsuneo
    #5
    BrunoC
    Starting Member
    • Total Posts : 84
    • Reward points : 0
    • Joined: 2010/11/19 04:05:49
    • Location: France
    • Status: offline
    Re: fileio and thumb drive help. 2014/05/19 02:22:04 (permalink)
    0
    Yes I'm working on MLA v2013_12_20.
    I tried the msd_simple example all are good but this example write a file. I want to read existing files.
    I tried to write a new file in my project all work. Problem is when I read a file.
    #6
    chinzei
    Super Member
    • Total Posts : 2250
    • Reward points : 0
    • Joined: 2003/11/07 12:39:02
    • Location: Tokyo, Japan
    • Status: offline
    Re: fileio and thumb drive help. 2014/05/20 14:58:55 (permalink)
    +2 (2)
    "es.txt"

    help_mla_fileio.pdf (in \v2013_12_20\doc\ folder)
    1.4.3 How the Library Works
    Note that Short File Names can only use upper-case alphanumeric characters,

     
    Tsuneo
    #7
    VBT
    New Member
    • Total Posts : 2
    • Reward points : 0
    • Joined: 2016/03/11 07:48:31
    • Location: 0
    • Status: offline
    Re: fileio and thumb drive help. 2020/12/21 07:51:18 (permalink)
    0
    Hi BrunoC,
     
    Did you solve the problem with reading of the USB drive?
     
    Seems that I am experiencing the same problem. File name is uppercase.
     
    VBT
    #8
    Jump to:
    © 2021 APG vNext Commercial Version 4.5