cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with two consecutive _SdRead()

colsman
Associate II
Posted on September 03, 2012 at 18:08

Hi,

I am using the software example 'MassStorage' , the IAR compiler and the STM32F103ZE kickstart board for development. I wanted to add some functionality which requires consecutives reads from the SD card. For simplicity, this example illustrates the problem: file: sd_card_mode.c , line function SdDiskIO

.... 
... 
case
DiskRead: 
{
// Test Code which breaks the SdRead function 
#pragma data_alignment=4 
Int8U read_disk[512]; 
unsigned 
int
n; 
_SdRead(&read_disk[0], 0 ,1); 
for
(n = 0 ; n < 0xfff; n++){ 
// This pause is necessary - 
n++; 
// otherwise there are read errors 
n--; 
// DMA not ready ? 
} 
// end test code 
} 
switch
(_SdRead(pData, 
_bHC?BlockStart:BlockStart*_SdDskCtrlBlk.BlockSize, 
BlockNum)) 
{ 
case
SdOk: 
.... 
....

When I take out the for/next loop delay, the second read fails. Problem seems to be, that the second read is not completed. The 512 buffer is filled only half with correct data. It looks like the DMA is still going on.

Anybody seen similar issues with this example or in general with the SDIO example ? - Thanks, Cols
4 REPLIES 4
Posted on September 03, 2012 at 21:33

Anybody seen similar issues with this example or in general with the SDIO example

Well the STM32xxX-EVAL board examples do actually wait for the DMA to complete rather than spin for an arbitrary period. This would definitely be the recommended method as cards vary in speed and responsiveness. Not sure how well the demo apps would port to the IAR boards, but they are typically fairly similar.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
colsman
Associate II
Posted on September 05, 2012 at 10:24

I looked into the issue a bit deeper:

When things start to fail, the

    SDIO_FLAG_RXACT

    SDIO_FLAG_RXFIFOHF

    SDIO_FLAG_RXDAVLFlags

are set, when everything is fine, the 

    SDIO_FLAG_CMDREND

    SDIO_FLAG_RXACT

    SDIO_FLAG_CEATAEND

are set when the _SdSendCmd function is ready.

Any idea ?

- Matt

Posted on September 05, 2012 at 19:03

Seems to be some specific IAR code. ST has there own code, that might be worth some review.

Suspect it has more to do with how the first command completes, or how it leaves the flash device. Behaviour might relate to the specific card, or how it waits for DMA to complete, or reinitializes DMA.

The cards should permit multiple sector reading, the non-SDHC cards do seem to require the block size be programmed.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
colsman
Associate II
Posted on September 06, 2012 at 09:08

Thanks for your replies.

Problem solved. The _SdRead function had code to wait for the DMA to finish - but didn't had the proper flags included. Solution: just add the flags mentioned above.

- Cols