cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F2XX + SDIO + FatFs problem

damien2399
Associate II
Posted on January 09, 2012 at 10:38

Hi,

I've a problem with my STM32. I need to use fat filesystem on SD card to read/write/create files.

I tried to use Chan FatFs module but it didn't working at all ...

I use SD card in SDIO and 4 wires mode.

When I debug, check_fs() function can't retrieve 0x55 0xAA on boot sector, but, when I read sector n�0 in the main(), I can correctly read all datas on boot sector.

If someone can help me with this problem ...

Thanks.

#sdio-fatfs #sdio-chan-fatfs
31 REPLIES 31
Cesar cfg
Associate II
Posted on March 05, 2013 at 15:40

i don't inderstand you.my question is there a fatfs library that i can use it without modification.(standard library).

Posted on March 05, 2013 at 16:00

Perhaps, I'd just port it, embedded sw devs are expected to do that for custom platforms. The FatFs code is cross platform, the bulk of it you leave alone and will compile just fine, the platform specific code to do the sector/block IO is in DISKIO.C

If you have routines to access the card, integration is relatively straight forward.

If you can't find a drop in example via Google/Bing, assume you're going to have to do the port yourself, or contract someone.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Cesar cfg
Associate II
Posted on March 05, 2013 at 16:16

my problem is there is any available exapmle using the stm32F10b and the fatfs library to control the micro sd card   even if it use the SDIO interface.  

Posted on March 05, 2013 at 16:25

Magic 8 Ball says ''ask again later'', I guess you can wait for other responses.

So what is this STM32F10B, are you talking about the STM3210B-EVAL?
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Cesar cfg
Associate II
Posted on March 05, 2013 at 16:53

yes i am using the stm32f10b eval board and it is connected to the micro sd card with spi protocol.

Posted on March 05, 2013 at 18:16

Drop the 'F' when Googling, it's not in the board name, you'll get better results.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Cesar cfg
Associate II
Posted on March 07, 2013 at 09:36

Hi Clive1

I used the exapmle that you have  posted in wich you use the stm32f4 discovery and a micro sd card connected to the STM32 by the SDIO interface.

My question is that we don't have the same functions for example:  SD_ReadMultiBlocksFIXED  i have this function:

uint8_t MSD_ReadBuffer(uint8_t* pBuffer, uint32_t ReadAddr, uint32_t NumByteToRead)

{

  uint32_t i = 0, NbrOfBlock = 0, Offset = 0;

  uint8_t rvalue = MSD_RESPONSE_FAILURE;

  /* Calculate number of blocks to read */

  NbrOfBlock = NumByteToRead / BLOCK_SIZE;

  /* MSD chip select low */

  MSD_CS_LOW();

  /* Data transfer */

  while (NbrOfBlock --)

  {

    /* Send CMD17 (MSD_READ_SINGLE_BLOCK) to read one block */

    MSD_SendCmd (MSD_READ_SINGLE_BLOCK, ReadAddr + Offset, 0xFF);

    /* Check if the MSD acknowledged the read block command: R1 response (0x00: no errors) */

    if (MSD_GetResponse(MSD_RESPONSE_NO_ERROR))

    {

      return  MSD_RESPONSE_FAILURE;

    }

    /* Now look for the data token to signify the start of the data */

    if (!MSD_GetResponse(MSD_START_DATA_SINGLE_BLOCK_READ))

    {

      /* Read the MSD block data : read NumByteToRead data */

      for (i = 0; i < BLOCK_SIZE; i++)

      {

        /* Read the pointed data */

        *pBuffer = MSD_ReadByte();

        /* Point to the next location where the byte read will be saved */

        pBuffer++;

      }

      /* Set next read address*/

      Offset += 512;

      /* get CRC bytes (not really needed by us, but required by MSD) */

      MSD_ReadByte();

      MSD_ReadByte();

      /* Set response value to success */

      rvalue = MSD_RESPONSE_NO_ERROR;

    }

    else

    {

      /* Set response value to failure */

      rvalue = MSD_RESPONSE_FAILURE;

    }

  }

  /* MSD chip select high */

  MSD_CS_HIGH();

  /* Send dummy byte: 8 Clock pulses of delay */

  MSD_WriteByte(DUMMY);

  /* Returns the reponse */

  return rvalue;

}

so i have changed something in the file ff.c when calling the function f_read i put the 4th varaible to 512 to read 512 bytes.

But it returns  FR_NO_FILE 

 

 

Cesar cfg
Associate II
Posted on March 07, 2013 at 09:38

This is my main code

void main(void)

{

  

/*!< At this stage the microcontroller clock setting is already configured, 

       this is done through SystemInit() function which is called from startup

       file (startup_stm32f30x.s) before to branch to application main.

       To reconfigure the default setting of SystemInit() function, refer to

       system_stm32f30x.c file

     */

   /* Configure PC12 pin: CS pin */

  

//  GPIO_InitTypeDef                    GPIO_InitStructure;

 

  

   /* Initializes the SD/SPI communication */

  Status = MSD_Init();

  Get_Medium_Characteristics();

 

  

  memset(&fs32, 0, sizeof(FATFS));

  res1 = f_mount(0, &fs32);

  res2 = f_open(&fil, ''essai1.txt'', FA_WRITE);

  res0 = f_close(&fil); // LENGTH.TXT

  

while (1)

  {

  

 }

}

Posted on March 07, 2013 at 16:01

You should not have to touch FF.C, all you IO abstraction should be in DISKIO.C

  res2 = f_open(&fil, ''essai1.txt'',FA_OPEN_ALWAYS | FA_WRITE); // Surely?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Cesar cfg
Associate II
Posted on March 07, 2013 at 16:27

Thank you Clive1 my problem was resolved.Just i modified the file diskio.c (disk functions).

Once again i want to thank you.