cancel
Showing results for 
Search instead for 
Did you mean: 

SD driver for STM3210C eval using FatFs

lemeclyonnais
Associate
Posted on January 17, 2013 at 10:23

Hi guys,

I'm working for the first time on a STM3210C eval. I have to store files on the SD card included in the STM card.

So I added FatFs to my project. As FatFs is platform independant, I have to find a compatible SD driver which can provide several functions : disk_ioctl(), disk_read(), etc...

I've searched on the Internet and tried to add many drivers, without success. Has someone a SD card driver for STM3210C eval which is compatible with FatFs, and a short ''how to do'' would be great :)

thanks,

Nicolas

#stm3210c-eval-fatfs-sd-driver
6 REPLIES 6
amin23
Associate II
Posted on January 18, 2013 at 10:25

The attached file may help you. also on the following an example based on STM32F2 and STM32F4.

STM32F2 and STM32F4 demonstration builder platform:

http://www.st.com/internet/mcu/product/252jsp

________________

Attachments :

diskio.c : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I0tK&d=%2Fa%2F0X0000000bgu%2FhRMSD1bC2TDMV6ATzYZyDF3utsyZo85baXvpfSyDPSw&asPdf=false
lemeclyonnais
Associate
Posted on January 21, 2013 at 11:44

Thank you for your answers.

@mclean.mark : ''global.h'' in the c files is not recognized by my compiler.

I managed to compilate by replacing ''global.h by :

#include ''stm32f10x_sdio.h''

#include ''stm32f10x_dma.h''

#include ''stm32f10x_rcc.h''

#define NULL    ((void *)0)

I modified SDIO_configuration in sdcard.c :

static void SDIO_Configuration(void)

{

    GPIO_InitTypeDef  GPIO_InitStructureA;

    GPIO_InitTypeDef  GPIO_InitStructureC;

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOC, ENABLE);

  GPIO_InitStructureC.GPIO_Pin =  GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12;

  GPIO_InitStructureC.GPIO_Speed = GPIO_Speed_50MHz;

  GPIO_InitStructureC.GPIO_Mode = GPIO_Mode_AF_PP;

  GPIO_Init(GPIOC, &GPIO_InitStructureC);

  /* Configure PD.02 CMD line */

  GPIO_InitStructureA.GPIO_Pin = GPIO_Pin_4;

    GPIO_InitStructureA.GPIO_Speed = GPIO_Speed_50MHz;

  GPIO_InitStructureA.GPIO_Mode = GPIO_Mode_Out_PP;

  GPIO_Init(GPIOA, &GPIO_InitStructureA);

}

But it still doesn't work when I do in the main :

    FIL fil_obj;

    FATFS fs[1];

    FRESULT FRes;

    disk_initialize(0);

    f_mount(0, &fs[0]);

    f_open(&fil_obj, ''0:whatever.txt'', FA_OPEN_ALWAYS | FA_READ);

    f_close(&fil_obj);

    f_mount(0, NULL);

Note : I use the firmware 3.3.0, and the processor is a STM3210f107VC

Some ideas ?

lee_trueman
Associate II
Posted on January 21, 2013 at 11:51

your SDIO init is not correct it should be more like this

void SD_LowLevel_Init(void)

{

  GPIO_InitTypeDef  GPIO_InitStructure;

  /*!< 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; // Pull up on board

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;

  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);

}

lee_trueman
Associate II
Posted on January 21, 2013 at 12:14

ignore my last post your not using SDIO interface.

Posted on January 21, 2013 at 13:48

Some ideas ?

 

disk_initialize() is called internally by FatFs.

FatFs returns errors, examine them and don't continue to plough forward if it fails.

Use a debugger and scope if you need to understand what's happening.

Debug and test the SD read/write routines outside of FatFs, if they don't work standalone, they aren't going to work when integrated, and debugging is harder.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..