cancel
Showing results for 
Search instead for 
Did you mean: 

SDIO/DMA and Filesystem

lee_trueman
Associate II
Posted on March 29, 2012 at 21:49

Hi all, i'm sorry if this has been discuss before, but from reading posts i'm still some what unclear, thus my post.

Right here goes :)

Has anyone implemented reliably SDIO using DMA along with say FatFS file system ? 

There seems to be alot of comments around interrupts and delays when setting DMA, and thus creating a race/lockout.

8 REPLIES 8
infoinfo989
Associate III
Posted on March 30, 2012 at 05:48

Yes, it's been done, I've done it, as have others. (No I cannot post my code).

The Chan FatFS code works well and is very easy to port over to the STM32. You only need edit one file.

The challenge lies with the ST-supplied SDIO code. It's useful as example code, but not very useful as ''production'' code. You'll spend a lot of time cleaning it up. Take a look through this forum for posts, and there's also some useful info here:

http://www.frankvh.com/stm32-information.html

lee_trueman
Associate II
Posted on April 03, 2012 at 21:18

Right dont seem to be getting very far with this. Code is just loop forever in the FindSCR function. 

 while (!(SDIO->STA & (SDIO_FLAG_RXOVERR | SDIO_FLAG_DCRCFAIL | SDIO_FLAG_DTIMEOUT | SDIO_FLAG_DBCKEND | SDIO_FLAG_STBITERR)))

  {

    if (SDIO_GetFlagStatus(SDIO_FLAG_RXDAVL) != RESET)

    {

      *(tempscr + index) = SDIO_ReadData();

      index++;

    }

  }

Can any offer some light on this ?

lee_trueman
Associate II
Posted on April 04, 2012 at 18:55

right went back to basics and just tried raw readblock and writeblock, using stm32_eval_sdio_sd.c MCD Ver4.6.0 and this works fine. 

If i add the read/write single blocks to the fatfs code it just ends up loop around in SD_GetStatus()

status = SD_ReadBlock( (uint8_t *)buff,

Memory_Offset,

Transfer_Length);

       /* Check if the Transfer is finished */

       status =  SD_WaitReadOperation();

       while(SD_GetStatus() != SD_TRANSFER_OK);

lee_trueman
Associate II
Posted on April 10, 2012 at 09:36

more feedback, changed the stm32_eval_sdio_sd.c to version 4.6.1 and now i can get a file to write to the sd-card but only if i add a break point on f_close().

  if( f_mount( 0, &fs ) != FR_OK)

  {

  }

  else

  {

 if( f_open( &file, ''test.dat'',

   FA_CREATE_ALWAYS | FA_WRITE ) != FR_OK )

 {

 }

 else

 {

 f_write( &file, buffer, 7, &result );

 f_close( &file );

 }

  }

My thinking is that f_write() is not waiting correctly for the sd-card and thus me adding a break point on f_close() adds some delay which enables the sd-card to finish its process.

Can anyone add to this and help me out ? 

rosarium
Associate II
Posted on April 10, 2012 at 10:00

just to confirm can you check the optimisation level in your workspace.Try once minimising teh optimisation level.

And also one imp point: after closing teh file are you unmounting the drive.

f_close(&file);

f_mount(0, NULL);

Regards,

Rosarium

lee_trueman
Associate II
Posted on April 10, 2012 at 17:31

I'm using Atollic Free IDE/Compiler thus opimisation is not Selectable, but it is currently set to None (-O0).

 

What is the lastest version of stm32_eval_sdio_sd.c from MCD team ?  

lee_trueman
Associate II
Posted on April 10, 2012 at 18:34

There seems to be a bug in this function with regards to the STM3210e evalkit.

When SD-Card is present the signal on PF.11 is LOW. Thus this function returns SD_NOT_PRESENT when the SD-Card is fitted !!!!!

uint8_t SD_Detect(void)

{

  __IO uint8_t status = SD_PRESENT;

  /*!< Check GPIO to detect SD */

  if (GPIO_ReadInputDataBit(SD_DETECT_GPIO_PORT, SD_DETECT_PIN) == Bit_RESET)

  {

    status = SD_NOT_PRESENT;

  }

  return status;

}

lee_trueman
Associate II
Posted on April 10, 2012 at 18:37

Strange thing is in 4.5.0 version it is correct !!!!! 

uint8_t SD_Detect(void)

{

  __IO uint8_t status = SD_PRESENT;

  /*!< Check GPIO to detect SD */

  if (GPIO_ReadInputDataBit(SD_DETECT_GPIO_PORT, SD_DETECT_PIN) != Bit_RESET)

  {

    status = SD_NOT_PRESENT;

  }

  return status;

}