Autor Tema: Creación Escritura Archivos tarjeta SD XC32 PIC32 HARMONY  (Leído 2502 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado mayk888

  • PIC10
  • *
  • Mensajes: 6
Creación Escritura Archivos tarjeta SD XC32 PIC32 HARMONY
« en: 21 de Octubre de 2016, 06:15:13 »
Buenas a todos foreros,

resulta que me hallo embarcado en un proyecto en el que necesito almacenar un conjunto de datos en una tarjeta SD.
Estoy utilizando la herramienta HARMONY de microchip pero no consigo hacer arrancar a la susodicha. En la primera instrucción que se supone
monta el sistema de gestión de archivos en la tarjeta ya salta al error como si no la encontrara.

Aquí os dejo la instrucción con su definición de la librería.

//******************************************************************************
/*Function:
    SYS_FS_RESULT SYS_FS_Mount(const char *devName, const char *mountName,
   SYS_FS_FILE_SYSTEM_TYPE filesystemtype, unsigned long mountflags, const void *data);

    Summary:
        Mount filesystems

    Description:
        Attaches the filesystem specified by source to a specified media.

    Precondition:
        The "devName" for the media has to be known. The convention that is
      followed in Harmony file system is: -

      For NVM         - "nvm"<media number><volume number>
      For SD card      - "mmcblk"<media number><volume number>
      For MSD         - "sd"<media number><volume number>

      <media number>    - a, b, c... depending upon number of media of certain type
                    connected.
       <volume number>   - 1, 2, 3... depending upon number of partitions in that
                    media.

    Parameters:
        devName       - The device name (name of media) which needs to be mounted
        mountName       - Mount name for the device to be mounted
        filesystemtype    - native file system type
        mountflags       - mounting control flags. This parameter is kept for future
                    expansion. Hence, always pass zero.
        data          - The data argument is interpreted by the different file systems.
                     This parameter is kept for future expansion. Hence, always
                    pass NULL.

    Returns:
        If Success: SYS_FS_RES_SUCCESS
        If Failure: SYS_FS_RES_FAILURE
            Sets error code which can be retrieved with SYS_FS_Error
***************************************************************************/
SYS_FS_RESULT SYS_FS_Mount
(
    const char *devName,
    const char *mountName,
    SYS_FS_FILE_SYSTEM_TYPE filesystemtype,
    unsigned long mountflags,
    const void *data
 )
{
    int fileStatus = -1;
    SYS_FS_MOUNT_POINT *disk = NULL;
    uint8_t mountPoint;
    SYS_FS_VOLUME_PROPERTY volProperty;
    uint8_t index;

    /* First check if the media is attached or not */
    if(SYS_FS_MEDIA_MANAGER_MediaStatusGet(devName) != true)
           
    {
        errorValue = SYS_FS_ERROR_NOT_READY;
        /* The media name specified is not attached */       
            Lcd_envia(1,1);
            Lcd_Out(2,1,"ERROR NOT READY");
            delay_ms(500);
        return SYS_FS_RES_FAILURE;
    }
    /* Clear the error value when mount is sucessful */
    errorValue = SYS_FS_ERROR_OK;
        /* Verify if the requested file system is supported by SYS_FS */
    for( index = 0; index != SYS_FS_MAX_FILE_SYSTEM_TYPE; index++ )
    {
        if(gSYSFSObj[index].nativeFileSystemType == filesystemtype)
            break;  /* Now, index, holds the element number for the requested file system */
    }

    /* If the requested file system type is not supported by SYS_FS */
    if(index >= SYS_FS_MAX_FILE_SYSTEM_TYPE)
    {
        errorValue = SYS_FS_ERROR_FS_NOT_SUPPORTED;
        Lcd_envia(1,1);
        Lcd_Out(2,1,"ERROR NOT SUPPORTED");
        delay_ms(500);
        return SYS_FS_RES_FAILURE;
    }
    // Start with 0th disk and find a disk which is available (not in use)
    for(mountPoint = 0; mountPoint != SYS_FS_VOLUME_NUMBER; mountPoint++)
    {
        if(!gSYSFSMountPoint[mountPoint].inUse) // not in use, hence this is available
        {
            if(true == SYS_FS_MEDIA_MANAGER_VolumePropertyGet(devName, &volProperty))
            {
                if(volProperty.fsType != filesystemtype)
                {
                     errorValue = SYS_FS_ERROR_FS_NOT_MATCH_WITH_VOLUME;
                     Lcd_envia(1,1);
                     Lcd_Out(2,1,"ERROR NOT SUPPORTED");
                     delay_ms(500);
                     return SYS_FS_RES_FAILURE;
                }
            }
            else
            {
                 errorValue = SYS_FS_ERROR_DISK_ERR;
                 Lcd_envia(1,1);
                 Lcd_Out(2,1,"ERROR DISK ERR");
                 delay_ms(500);
                 return SYS_FS_RES_FAILURE;
            }
            disk = &gSYSFSMountPoint[mountPoint];

            disk->inUse = true;
            disk->fsType = filesystemtype;
            disk->fsFunctions = gSYSFSObj[index].nativeFileSystemFunctions;
            disk->mountName = (mountName + 5);  // Save only mountName. Do not save "/mnt/"
            disk->diskNumber = volProperty.volNumber;
          /* Create mutex for this Mount/volume */
            if(OSAL_MUTEX_Create(&(disk->mutexDiskVolume)) != OSAL_RESULT_TRUE)
            {
                Lcd_envia(1,1);
                Lcd_Out(2,1,"ERROR RES FAILURE");
                delay_ms(500);
                return SYS_FS_RES_FAILURE;
            }
            break;
        }
    }

    if(mountPoint >= SYS_FS_VOLUME_NUMBER)
    {
        SYS_ASSERT(false, "Invalid Disk");
        errorValue = SYS_FS_ERROR_NOT_ENOUGH_FREE_VOLUME;
        return SYS_FS_RES_FAILURE;
    }
    /* Put the recently assigned disk as the current disk */
    gSYSFSCurrentMountPoint.inUse = true;
    gSYSFSCurrentMountPoint.currentDisk = disk;

    if(disk->fsType == FAT)
    {
        disk->fsFunctions->chdrive(disk->diskNumber);
    }

    /* Check, if the mount function in native FS is NULL or not */
    if(disk->fsFunctions->mount == NULL)
    {
        errorValue = SYS_FS_ERROR_NOT_SUPPORTED_IN_NATIVE_FS;
        return SYS_FS_RES_FAILURE;
    }

    fileStatus = disk->fsFunctions->mount(disk->diskNumber);

    if(fileStatus == 0)
    {
        return SYS_FS_RES_SUCCESS;
    }
    else
    {
        errorValue = fileStatus;
        return SYS_FS_RES_FAILURE;
    }
}

La llamada la realizo de la siguiente manera:

if(SYS_FS_Mount("/dev/mmcblka1","/mnt/MYDRIVE", FAT, 0, NULL) != 0)
//            {

dentro de la función introduje una salida por el LCD que me permite ver que falla nada mas entrar y realizar la primera comprobación.

En los proyectos que tiene de ejemplos el HARMONY encontre la instrucción que utilizo y en este mismo ejemplo no encontre ninguna asignación
de nombre a la SD o algo que se le parezca. Por aquello que dice en la explicación de que el nombre del device debe ser conocido.
No se estoy bastante perdido, si alguien tiene aunque se a alguna directriz me sería de mucha ayuda.
Utilizo el puerto SPI2 y adjunto imagen con la configuración del HARMONY.

Un saludo a todos y gracias de antebrazo.  :-)

« Última modificación: 21 de Octubre de 2016, 06:23:22 por mayk888 »


 

anything