FR_DISK_ERR mientras se interconecta una tarjeta SDHC de 8GB con FATFS + SPI + STM32L0

0

Estoy intentando conectar una tarjeta SDHC de 8 GB con STM32L0 (SPI + FSTFS).

Estoy usando la biblioteca de chan v0.11 con la biblioteca de Adafruit Shield donde el código de E / S SPI de nivel inferior es manejado por el controlador de Nucleo.

He cambiado los respectivos números de PIN para SPI y CS en el controlador Nucleo y he podido enviar la tarjeta SD al estado IDLE mediante el envío manual de 0x40 (CMD0) a través de SPI (lo que significa que NO HAY ERRORES DE HARDWARE).

Cuando trato de usar esta configuración con todas las bibliotecas anteriores, obtengo FR_DISK_ERR cuando llamo f_open ().

He formateado la tarjeta SD como FAT32 y la he etiquetado como '0'.

He adjuntado mi main.c y diskio.c.

¿Este es el problema en el software o FATFS no es compatible con la tarjeta SDHC de 8 GB?

main.c

    const Diskio_drvTypeDef  USER_Driver =
{
  SD_initialize,
  SD_status,
  SD_read, 
#if  _USE_WRITE == 1
  SD_write,
#endif /* _USE_WRITE == 1 */

#if  _USE_IOCTL == 1
  SD_ioctl,
#endif /* _USE_IOCTL == 1 */
};
/*##-1- Link the micro SD disk I/O driver ##################################*/
  if(FATFS_LinkDriver(&USER_Driver, USERPath) == 0)
  {
        DemoState = 3;
    /*##-2- Register the file system object to the FatFs module ##############*/
    if(f_mount(&USERFatFS, (TCHAR const*)USERPath, 0) != FR_OK)
    {
            DemoState = 4;
      /* FatFs Initialization Error */
      Error_Handler();
    }
    else
    {
                DemoState = 5;
      /*##-3- Create and Open a new text file object with write access #######*/
      res = f_open(&USERFile, "STM32.TXT", FA_CREATE_ALWAYS | FA_WRITE);
      if(res != FR_OK)
      {
        /* 'STM32.TXT' file Open for write Error */
        Error_Handler();
      }
      else
      {
                DemoState = 6;
        /*##-4- Write data to the text file ##################################*/
        res = f_write(&USERFile, wtext, sizeof(wtext), (void *)&byteswritten);

        if((byteswritten == 0) || (res != FR_OK))
        {
          /* 'STM32.TXT' file Write or EOF Error */
          Error_Handler();
        }
        else
        {
                    DemoState = 7;
          /*##-5- Close the open text file ###################################*/
          f_close(&USERFile);

          /*##-6- Open the text file object with read access #################*/
          if(f_open(&USERFile, "STM32.TXT", FA_READ) != FR_OK)
          {
            /* 'STM32.TXT' file Open for read Error */
            Error_Handler();
          }
          else
          {
            /*##-7- Read data from the text file #############################*/
            res = f_read(&USERFile, rtext, sizeof(rtext), (UINT*)&bytesread);

            if((bytesread == 0) || (res != FR_OK))
            {
              /* 'STM32.TXT' file Read or EOF Error */
              Error_Handler();
            }
            else
            {
              /*##-8- Close the open text file ###############################*/
              f_close(&USERFile);

              /*##-9- Compare read data with the expected data ###############*/
              if((bytesread != byteswritten))
              {                
                /* Read data is different from the expected data */
                Error_Handler();
              }
              else
              {
                /* Success of the demo: no error occurrence */
                DemoState = DEMO_OK;
              }
            }
          }
        }
      }
    }
  }

  /*##-10- Unlink the SD disk I/O driver #####################################*/
  FATFS_UnLinkDriver(USERPath);

diskio.c

DSTATUS SD_initialize(BYTE lun)
{
  Stat = STA_NOINIT;

  /* Configure the uSD device */
  if(BSP_SD_Init() == MSD_OK)
  {
    Stat &= ~STA_NOINIT;
  }

  return Stat;
}

/**
  * @brief  Gets Disk Status
  * @param  lun : not used
  * @retval DSTATUS: Operation status
  */
DSTATUS SD_status(BYTE lun)
{
  Stat = STA_NOINIT;

  if(BSP_SD_GetStatus() == MSD_OK)
  {
    Stat &= ~STA_NOINIT;
  }

  return Stat;
}

/**
  * @brief  Reads Sector(s)
  * @param  lun : not used
  * @param  *buff: Data buffer to store read data
  * @param  sector: Sector address (LBA)
  * @param  count: Number of sectors to read (1..128)
  * @retval DRESULT: Operation result
  */
DRESULT SD_read(BYTE lun, BYTE *buff, DWORD sector, UINT count)
{
  DRESULT res = RES_OK;

  if(BSP_SD_ReadBlocks((uint32_t*)buff, 
                       (uint64_t) (sector * BLOCK_SIZE), 
                       BLOCK_SIZE, 
                       count) != MSD_OK)
  {
    res = RES_ERROR;
  }

  return res;
}

/**
  * @brief  Writes Sector(s)
  * @param  lun : not used
  * @param  *buff: Data to be written
  * @param  sector: Sector address (LBA)
  * @param  count: Number of sectors to write (1..128)
  * @retval DRESULT: Operation result
  */
#if _USE_WRITE == 1
DRESULT SD_write(BYTE lun, const BYTE *buff, DWORD sector, UINT count)
{
  DRESULT res = RES_OK;

  if(BSP_SD_WriteBlocks((uint32_t*)buff, 
                        (uint64_t)(sector * BLOCK_SIZE), 
                        BLOCK_SIZE, count) != MSD_OK)
  {
    res = RES_ERROR;
  }

  return res;
}
#endif /* _USE_WRITE == 1 */

/**
  * @brief  I/O control operation
  * @param  lun : not used
  * @param  cmd: Control code
  * @param  *buff: Buffer to send/receive control data
  * @retval DRESULT: Operation result
  */
#if _USE_IOCTL == 1
DRESULT SD_ioctl(BYTE lun, BYTE cmd, void *buff)
{
  DRESULT res = RES_ERROR;
  SD_CardInfo CardInfo;

  if (Stat & STA_NOINIT) return RES_NOTRDY;

  switch (cmd)
  {
  /* Make sure that no pending write process */
  case CTRL_SYNC :
    res = RES_OK;
    break;

  /* Get number of sectors on the disk (DWORD) */
  case GET_SECTOR_COUNT :
    BSP_SD_GetCardInfo(&CardInfo);
    *(DWORD*)buff = CardInfo.CardCapacity / BLOCK_SIZE;
    res = RES_OK;
    break;

  /* Get R/W sector size (WORD) */
  case GET_SECTOR_SIZE :
    *(WORD*)buff = BLOCK_SIZE;
    res = RES_OK;
    break;

  /* Get erase block size in unit of sector (DWORD) */
  case GET_BLOCK_SIZE :
    *(DWORD*)buff = BLOCK_SIZE;
    break;

  default:
    res = RES_PARERR;
  }

  return res;
}
#endif /* _USE_IOCTL == 1 */
    

1 respuesta

0

intente con otra tarjeta SD.eg: tarjeta sd 2GB. Estoy teniendo el mismo problema

    
respondido por el MyDoping2611

Lea otras preguntas en las etiquetas