/var/www/restricted/ssh/stm32/www/stm32circle/ STM CircleOS forum / SD card DMA operation failing

Username:     
Password:     
             

Forum

# 1   2009-05-26 10:42:57 SD card DMA operation failing

kubark42
Member
Registered: 2009-02-13
Posts: 46

SD card DMA operation failing

I'm using STM's sdcard.c in dma mode (pretty much pulled straight from the circleOS code) and noticing that the DMA isn't writing to the right spot! To be exact, it's writing the SD data exactly one byte to the left. That is to say that if I ask it to write sector data from 0x01 to 0x20, it starts at 0x00 and finishes at 0x1F.

I've not modified the STM code in any way, so this is either A) a catastrophic code bug so big that STM would have caught it, as *nothing* works right like this, or some kind of weird bug that I've uncovered in certain situations.

Any ideas? It's driving me crazy and is keeping my program from working.

EDIT 1:

I'm starting to figure it out. It seems that it has something to do with 32-bit address space. I'm not sure quite how, but I'm guessing that DMA can only write to the beginning of a 32-bit word. Now, why this is and how I've gotten into this problem kind of escape me, as I'm used to 8-bit uC and am not necessarily aware of all the "gotchas" when programming in 32-bits. Can anyone explain (or give me a link, I'm not too lazy to read a good article!) what's going on?

EDIT 2:

I found a work-around. According to http://infocenter.arm.com/help/index.js … 1144.html, I can force the char array `sector`, as defined in fs.c, to a 32-bit boundary. This solved the problem. Note that this is a bug in fs.c and it should be fixed in CircleOS!

Last edited by kubark42 (2009-05-26 11:10:07)

Offline

 

# 2   2009-05-26 11:50:50 SD card DMA operation failing

repzak
Member
Registered: 2008-03-05
Posts: 170

Re: SD card DMA operation failing

Hi,

Try to give a litle more information to your problem, i have the same issue for read..

Kasper

Offline

 

# 3   2009-05-26 15:43:10 SD card DMA operation failing

kubark42
Member
Registered: 2009-02-13
Posts: 46

Re: SD card DMA operation failing

I'm not sure I understand what you mean. In any case, if you look at my last EDIT, you'll see that I solved the problem by editing fs.c

I replace

Code:

u8 sector[SECTOR_SIZE];

with

Code:

static union array {
  u8 sector[SECTOR_SIZE];    // the char array
  unsigned int  i;          // force 32-bit int alignment
} u;

and then replace all instances of

Code:

sector

with

Code:

u.sector

Offline

 

# 4   2009-05-26 17:04:31 SD card DMA operation failing

repzak
Member
Registered: 2008-03-05
Posts: 170

Re: SD card DMA operation failing

Hey,

I think that is not enough sad

I have most been looking on read, but the sector is only used when it is a partial sector to read, maybe also write...

else it is written directly to the buffer from the "application"

I think it is the same for write...

Kasper

Offline

 

Board footer