Ejemplo n.º 1
0
/**
  * @brief  Initializes the SD/SD communication.
  * @param  None
  * @retval The SD Response: 
  *         - MSD_ERROR : Sequence failed
  *         - MSD_OK    : Sequence succeed
  */
uint8_t BSP_SD_Init(void)
{ 
  /* Configure IO functionalities for SD pin */
  SD_IO_Init();

  /* Check SD card detect pin */
  if(BSP_SD_IsDetected()==SD_NOT_PRESENT) 
  {
    SdStatus = SD_NOT_PRESENT;
    return MSD_ERROR;
  }
  else
  {
    SdStatus = SD_PRESENT;
  }
  
  /* SD initialized and set to SPI mode properly */
  return (SD_GoIdleState());
}
Ejemplo n.º 2
0
/**
  * @brief  Initializes the SD/SD communication.
  * @param  None
  * @retval The SD Response: 
  *         - SD_RESPONSE_FAILURE: Sequence failed
  *         - SD_RESPONSE_NO_ERROR: Sequence succeed
  */
SD_Error SD_Init(void)
{
  uint32_t i = 0;

  /*!< Initialize SD_SPI */
  SD_LowLevel_Init(); 

  /*!< SD chip select high */
  SD_CS_HIGH();

  /*!< Send dummy byte 0xFF, 10 times with CS high */
  /*!< Rise CS and MOSI for 80 clocks cycles */
  for (i = 0; i <= 9; i++)
  {
    /*!< Send dummy byte 0xFF */
    SD_WriteByte(SD_DUMMY_BYTE);
  }
  /*------------Put SD in SPI mode--------------*/
  /*!< SD initialized and set to SPI mode properly */
  return (SD_GoIdleState());
}
/**
  * @brief  Initializes the SD/SD communication.
  * @param  None
  * @retval The SD Response: 
  *         - MSD_ERROR: Sequence failed
  *         - MSD_OK: Sequence succeed
  */
uint8_t BSP_SD_Init(void)
{ 
  uint8_t status = MSD_ERROR;
  
  /* Configure IO functionalities for SD pin */
  SD_IO_Init();

  /* SD detection pin is not physically mapped on the Adafruit shield */
  SdStatus = SD_PRESENT;
  
  /* SD initialized and set to SPI mode properly */
  status = SD_GoIdleState();
  
  if (status == SD_RESPONSE_NO_ERROR)
  {
    return MSD_OK;
  }
  else
  {
    return MSD_ERROR;
  }
}
/**
  * @brief  Initializes the SD/SD communication.
  * @param  None
  * @retval The SD Response: 
  *         - SD_RESPONSE_FAILURE: Sequence failed
  *         - SD_RESPONSE_NO_ERROR: Sequence succeed
  */
SD_Error SD_Init(void)
{
  uint32_t TimeOut, i = 0;
  SD_Error Status = SD_RESPONSE_NO_ERROR;

  /*!< Initialize SD_SPI 初始化SPI相应管脚与处理器的SPI接口 */
  //printf("(SD Init in SPI mode)");
  SD_LowLevel_Init(); 
  SD_SPI_SetSpeedLow();
  //rt_kprintf("sd_init 0\n");
  /*------------Put SD in SPI mode--------------*/
  /*!< SD initialized and set to SPI mode properly */
  TimeOut = 0;
  do
  {
    /*!< SD chip select high */
    SD_CS_HIGH();
  
    /*!< Send dummy byte 0xFF, 10 times with CS high */
    /*!< Rise CS and MOSI for 80 clocks cycles */
    for (i = 0; i <= 9; i++)
    {
      /*!< Send dummy byte 0xFF */
      SD_WriteByte(SD_DUMMY_BYTE);
    }    
    
	Status = SD_GoIdleState();
	//rt_kprintf("sd_init 1 %d\n",(uint32_t)Status);
    if(TimeOut > 6)
    {
      break;
    }
    TimeOut++;
  }while(Status);

  SD_SPI_SetSpeedHi();
  
  return (Status);
}