Example #1
0
/**
  * @brief  Initializes the SD Card and put it into StandBy State (Ready for 
  *         data transfer).
  * @param  None
  * @retval None
  */
void SD_LowLevel_Init(void)
{
  GPIO_InitTypeDef  GPIO_InitStructure;

  SD_NVIC_Configuration();

  /*!< GPIOC and GPIOD Periph clock enable */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD | SD_DETECT_GPIO_CLK, ENABLE);

  /*!< Configure PC.08, PC.09, PC.10, PC.11, PC.12 pin: D0, D1, D2, D3, CLK pin */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  GPIO_Init(GPIOC, &GPIO_InitStructure);

  /*!< Configure PD.02 CMD line */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
  GPIO_Init(GPIOD, &GPIO_InitStructure);

  /*!< Configure SD_SPI_DETECT_PIN pin: SD Card detect pin */
  GPIO_InitStructure.GPIO_Pin = SD_DETECT_PIN;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  GPIO_Init(SD_DETECT_GPIO_PORT, &GPIO_InitStructure);
  
  /*!< Enable the SDIO AHB Clock */
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_SDIO, ENABLE);

  /*!< Enable the DMA2 Clock */
  RCC_AHBPeriphClockCmd(SD_SDIO_DMA_CLK, ENABLE);
}
Example #2
0
FRESULT ff_test(void)
{
    printf("test fatfs begin\n\r");
    SD_NVIC_Configuration();

    res = f_mount(&fatfs, "", 0);
    if(res != FR_OK) printf("mount failed: %d\n\r", res);
    
    res = f_open(&file, "test.txt", FA_CREATE_ALWAYS | FA_WRITE | FA_READ);
    res = f_open(&file2, "var.txt", FA_CREATE_ALWAYS | FA_WRITE | FA_READ);
    if(res != FR_OK) printf("open failed: %d\n\r", res);
    
    res = f_write(&file, buff, 12 * sizeof(char), &bw);
    res = f_printf(&file, "test-");
    res = f_printf(&file, "speed:%d,%d\n\r",speed[0],speed[1]--);
    res = f_puts("end of file\n\r", &file);

    speed[0] = 65;
    speed[1] = 1;
    res = f_write(&file2, speed, sizeof(speed), &bw);
    if(res != FR_OK) printf("fwrite failed: %d\n\r", res);
    
    res = f_close(&file);
    res = f_close(&file2);
    if(res != FR_OK) printf("fclose failled: %d\n\r", res);

    res = f_mount(NULL,"", 0);
    if(res != FR_OK) printf("umonut failed: %d\n\r", res);
    
    if(res == FR_OK) printf("test fatfs success\n\r");
}
Example #3
0
void SDIO_test(void)
{
    SD_Error error;
    // interrupt config
    SD_NVIC_Configuration();
    //SD init
    error = SD_Init();
    printf("test SDIO without FS\n\r");

    if(error == SD_OK) printf("SD_Init Success.\n\r");
    else{
	printf("SD_Init fail.\n\r");
	printf("status:\t%d\n\r",error);
    }

    printf("CardType:\t%d\n\r",SDCardInfo.CardType);
    printf("CardCapacity:\t%d\n\r",SDCardInfo.CardCapacity);
    printf("CardBlockSize:\t%d\n\r",SDCardInfo.CardBlockSize);
    printf("ManufactureID:\t%d\n\r",SDCardInfo.SD_cid.ManufacturerID);
    printf("RCA:\t%d\n\r",SDCardInfo.RCA);


    while((error == SD_OK) && (uwSDCardOperation != SD_OPERATION_END))
    {
	switch(uwSDCardOperation)
	{
	    /* -------------------SD single block test--------------------- */
	    case(SD_OPERATION_BLOCK):
	    {
		SD_SingleBlockTest();
		uwSDCardOperation = SD_OPERATION_ERASE;
		break;
	    }
	    /* -------------------SD Erase test--------------------- */
	    case(SD_OPERATION_ERASE):
	    {
		SD_EraseTest();
		uwSDCardOperation = SD_OPERATION_MULTI_BLOCK;
		break;
	    }
	    /* -------------------SD single block test--------------------- */
	    case(SD_OPERATION_MULTI_BLOCK):
	    {
		SD_MultiBlockTest();
		uwSDCardOperation = SD_OPERATION_END;
		break;
	    }
	}
    }
}
Example #4
0
void start_record(){
    SD_NVIC_Configuration();

    /* mount file system */
    res = f_mount(&fatfs, "", 0);
    if(res != FR_OK) printf("mount failed: %d\n\r", res);

    /* open file to write data */
    res = f_open(&file, "data.txt", FA_CREATE_ALWAYS | FA_WRITE | FA_READ);
    res = f_open(&f_value, "fncp.txt", FA_CREATE_ALWAYS | FA_WRITE | FA_READ);

    if(res != FR_OK) printf("open file failed: %d\n\r", res);

    if(res == FR_OK) printf("file is ready to write data!\n\r");
}
Example #5
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
	SD_GPIO_Configuration();
	SD_NVIC_Configuration();
	LCD_Init();
	LCD_Clear(0, 0, 240, 320, BACKGROUND);
	res = f_mount(&fs, "0:", 1);			//挂载SD卡
	if(res == FR_OK)
	{
		LCD_DisplayMultiCH(0, 0, (uint8_t *)"“王献”你好啊!Welcome Mr.Wang! 666", BLUE, SIZE_12);
		LCD_DisplayMultiCH(0, 16, (uint8_t *)"王献你是最棒的!you are the best!", GREEN, SIZE_16);
	}
	while (1)
	{

	}
}
/**
  * @brief  Initializes the SD Card and put it into StandBy State (Ready for
  *         data transfer).
  * @param  None
  * @retval None
  */
void SD_LowLevel_Init(void)
{
    GPIO_InitTypeDef  GPIO_InitStructure;

    /* GPIOC and GPIOD Periph clock enable */
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOD, ENABLE);

    #ifdef SD_DMA_MODE
    SD_NVIC_Configuration();
    #endif
    
    GPIO_PinAFConfig(GPIOC, GPIO_PinSource8, GPIO_AF_SDIO);
    GPIO_PinAFConfig(GPIOC, GPIO_PinSource9, GPIO_AF_SDIO);
    GPIO_PinAFConfig(GPIOC, GPIO_PinSource10, GPIO_AF_SDIO);
    GPIO_PinAFConfig(GPIOC, GPIO_PinSource11, GPIO_AF_SDIO);
    GPIO_PinAFConfig(GPIOC, GPIO_PinSource12, GPIO_AF_SDIO);
    GPIO_PinAFConfig(GPIOD, GPIO_PinSource2, GPIO_AF_SDIO);

    /* Configure PC.08, PC.09, PC.10, PC.11 pins: D0, D1, D2, D3 pins */
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_25MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
    GPIO_Init(GPIOC, &GPIO_InitStructure);

    /* Configure PD.02 CMD line */
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
    GPIO_Init(GPIOD, &GPIO_InitStructure);

    /* Configure PC.12 pin: CLK pin */
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
    GPIO_Init(GPIOC, &GPIO_InitStructure);

    /* Enable the SDIO APB2 Clock */
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_SDIO, ENABLE);

    /* Enable the DMA2 Clock */
    RCC_AHB1PeriphClockCmd(SD_SDIO_DMA_CLK, ENABLE);
}