cancel
Showing results for 
Search instead for 
Did you mean: 

STM3210VE, 8G SD card , SDIO 4bits bus, DMA mode-STOne-32,help me please

linkai1020
Associate II
Posted on September 17, 2010 at 03:07

STM3210VE, 8G SD card , SDIO 4bits bus, DMA mode-STOne-32,help me please

26 REPLIES 26
stst9185
Associate III
Posted on May 17, 2011 at 14:07

I´ve the necessity to implement a SD-card-interface too and could not get the demo-code runnin with my µSD-Cards until now. This week I´m very busy with different things, but next week I want to turn to this issue.

stst9185
Associate III
Posted on May 17, 2011 at 14:07

I´ve the same problem to integrate µSD-support to a project and did not manage to run the demo-code on my system: As soon as the switch to DMA 4-bit-mode takes place the system hangs (reading card-ID etc. works!). This week I´m very busy, but next week I will come back to this issue. Perhaps we can work together on this topic, I think the theme is of interest for many developers, so it should be in ST´s interest to give us some support.

stst9185
Associate III
Posted on May 17, 2011 at 14:07

I´ve the same problem to integrate µSD-support to a project and did not manage to run the demo-code on my system: As soon as the switch to DMA 4-bit-mode takes place the system hangs (reading card-ID etc. works!). This week I´m very busy, but next week I will come back to this issue. Perhaps we can work together on this topic, I think the theme is of interest for many developers, so it should be in ST´s interest to give us some support.

linkai1020
Associate II
Posted on May 17, 2011 at 14:07

I readed the spec again today.

and i found some c

lue

s in the code,I list it to you a

lthough it has no effect.

DRESULT disk_read (

 BYTE drv,   /* Physical drive number (0) */

 BYTE *buff,   /* Pointer to the data buffer to store read data */

 DWORD sector,  /* Start sector number (LBA) */

 BYTE count   /* Sector count (1..255) */

)

{

 uint16_t Transfer_Length;

 uint32_t Memory_Offset;

/*********************************************/ //test

// uint32_t* buff_temp;//test

/*********************************************/

 Transfer_Length =  count * 512;

 Memory_Offset = sector * 512;

// buff_temp = (uint32_t*) malloc (Transfer_Length);//test

// SD_ReadBlock(Memory_Offset, (uint32_t *)buff_temp, Transfer_Length);

// buff = (BYTE *)buff_temp;//test

 SD_ReadBlock(Memory_Offset, (uint32_t *)buff, Transfer_Length);

//free(buff_temp);//test

 //NAND_Read(Memory_Offset, (uint32_t *)buff, Transfer_Length); //

 return RES_OK;

}

I think there is a bug in this f

unction,look at the red words.

Pointer address

may c

ause

 some t

rouble

  because the DMA

Controller

can d

eal with the address which is a

multiple of 4 only

.(BYTE-> uint32_t ),but in some

Compiler

like IAR,it will be lost 2 o

ffset address when(BYTE-> uint32_t).And it will be OK in the MDK.

linkai1020
Associate II
Posted on May 17, 2011 at 14:07

It is a problem in such problems.The code that comes from st is not robust,i am testing it.

THANKS.

daviddavid92
Associate II
Posted on May 17, 2011 at 14:07

Aha, I have exactly the same problem!!!

I added some extra parameters in the while loop:

  else if (DeviceMode == SD_DMA_MODE)

  {

    SDIO_ITConfig(SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT | SDIO_IT_DATAEND | SDIO_IT_RXOVERR | SDIO_IT_STBITERR, ENABLE);

    SDIO_DMACmd(ENABLE);

    DMA_RxConfiguration(readbuff, BlockSize);

    while ((DMA_GetFlagStatus(DMA2_FLAG_TC4) == RESET) && (DMA_GetFlagStatus(DMA2_FLAG_TE4) == RESET) && (TransferError == SD_OK)); // TransferError set by interrupt handler.

       if (DMA_GetFlagStatus(DMA2_FLAG_TE4)==SET) TransferError = SD_ERROR;    //uart_puts(''DMA Transfer error\n'');   

    if (TransferError!=SD_OK) return(TransferError);

  }

  return(errorstatus);

I believe the problem is caused by the DMA being unable to keep up with the data being read from the SD card, and thus you get a buffer overrun. The DMA then stops being fired as all data has been received, but there are not enough bytes to indicate that the transfer is complete. So it hangs for ever..... (not very robust code!!)

I wrap the entire read_block() routine with an error check, and retry if it fails. Sometimes it can fail 6 times before reading successfully........

I believe it is related to CPU load as it only occurs when I have lots of interrupts firing.

Chris.

xacc
Associate II
Posted on May 17, 2011 at 14:07

The last argument is block size, not transfer size.

In most cases block size is 512.  The following works well for me.

DRESULT disk_read (

    BYTE drv,        /* Physical drive nmuber (0..) */

    BYTE *buff,        /* Data buffer to store read data */

    DWORD sector,    /* Sector address (LBA) */

    BYTE count        /* Number of sectors to read (1..255) */

)

{

  SD_Error res=0;

    if (drv || !count)

    {   

        return RES_PARERR;

    }

    if(!SD_Detect())

    {

        return RES_NOTRDY;

    }

    if(count==1)

    {                                               

        res = SD_ReadBlock(buff, sector << 9, 512);

    }                                               

    else

    {                                               

        res = SD_ReadMultiBlocks(buff, sector << 9, 512, count);

    }                                               

    if(res == SD_OK)

    {

        return RES_OK;

    }

    else

    {

        return RES_ERROR;

    }

}

linkai1020
Associate II
Posted on May 17, 2011 at 14:07

All the programs I tested, FATFS + SDIO + DMA +4 bit unstable.

Write data continuously for up to 1M will be caught in DMA wait state.

I am about to test DOSFS.

linkai1020
Associate II
Posted on May 17, 2011 at 14:07

I solved all the problems, I will leave in two days and then come back to talk about this in detail.

aha, Happy Holidays!

write SADDISK-8G-420KB/S

        Kingston-8G-200KB/S.
xacc
Associate II
Posted on May 17, 2011 at 14:07

Looking forward to your findings :)