EmbeddedRelated.com
Forums

SD/MMC card on an sam7-ex256

Started by axl_dudu March 2, 2008
The initial clock setting was for 48khz. I moved all SD card init
code from inside the task(I am using the FreeRTOS) in the init part
and I got it going(after a lot of playing with the clock speed - got
it at 8Mhz)! I will now have to see if I can read the file from a
task.
Still, I am very happy to see that is working. Thanks a lot for your
help! The only explanation that I have is that it is not working from
inside a task, even though it is obvious that the code I use was
adapted for FreeRTOS - it has some specific functions like
vPortEnterCritical() .
I will see what I can do to make it work and post what I will find in
case anyone encounters the same problems.

I am using a 1GB A-DATA microSD card with SD adapter, FAT32, 8bit
transfer, CPOL=0, ClockPhase=1, SCLK = 48Mhz/32*31 = 48kHz (initial
clock).

Once again thanks for pointing the directions where I had to look and
if you got any ideea why the file_fopen() function is not working
from inside a task, please let me know.

Tudor
--- In A..., "microbit" wrote:
>
> The first thing to do is to check if your low level disk interface
is properly working.
> Now, of course if you just simply write somewhere and read it back
(as a test) it might still
> 'appear' to be OK, but actually be writing wrong (and read back
wrong, so it looks OK).
>
> Having a 'sanity check' PC formatted card is your ticket out....
>
> It actually does sound like your low level isn't running right.
I'll have to dig up what your card
> could be reading at offset 510 & 511 (where the signature is).
AFAIK it *should* read 0x55AA
> there, SFD or FDISK.
>
> The best probably is to first check if your low level reads card
size properly.
> You need to read the CSD (Card Specific Data). If your Card Size
makes sense, then you're on your
> way, else this is where you should concentrate first.
>
> In answer to your earlier question, you should first do the SPI
operations (like putting into bit
> mode etc.) at low clock (I used SPI at 2 MHz first on SAM7 and that
worked fine on many SD cards).
> Once init properly then you can go to full speed (I switched to 24
MHz SPI).
>
> Perhaps this might get you started.
>
> It might help if you tell which :
> - Card you're using
> - What FAT you have on it, 16/32
> (bear in mind that XP now can format as FAT32 from 64 MB onwards)
> - SPI settings you use
>
> Best Regards,
> Kris
>
> -----Original Message-----
> From: A... [mailto:A...] On
Behalf Of axl_dudu
> Sent: Wednesday, 5 March 2008 5:39 AM
> To: A...
> Subject: [AT91SAM] Re: SD/MMC card on an sam7-ex256
>
> I've just checked to see if it reads the MBR and WHAT it reads from
> there. First, the EFSL checks the Boot sector signature (that must
be
> 0x55AA) but mine reads 0xABB0. Then it checks other stuff that I
> haven't got the time to dig up.
> I have checked the signature on the pc and it is just fine. So
there
> might be a problem when reading this address. Maybe it is a problem
> with the device speed, as Eric suggested. If you have any other
> suggestions, please post them.
> Regards,
> Tudor
>
> --- In A..., "microbit" wrote:
> >
> > I'm not familiar with EFSL, but it sounds like it might be
looking
> for the MBR (Master Boot
> > Record) in the wrong place.
> > There are primarily 2 ways of format & set up partition, it can't
> just look in sector (LBA) #0.
> > I would check the procedure and see if it supports :
> > 1. FDISK method
> > 2. Allows enough offset to go fetching the MBR in 2nd case.
> >
> > Best Regards,
> > Kris
> >
> > -----Original Message-----
> > From: A... [mailto:A...] On
> Behalf Of axl_dudu
> > Sent: Wednesday, 5 March 2008 4:11 AM
> > To: A...
> > Subject: [AT91SAM] Re: SD/MMC card on an sam7-ex256
> >
> > Yes. It is what I was looking for. I got an example made for this
> > board but it doesn't work properly. I have a microSD with an
> adapter
> > for the SD slot. The problem, as far as I went until now, is that
> > even thought the interface can read from the card, it detects
> invalid
> > FAT during the startup sequence of the EFSL. The card is just
fine,
> I
> > checked it on the pc. I even installed a program that reads the
> Disk
> > Parameter Block and everything seems ok.
> >
> > The person that gave me the example said he tried it with a 512MB
> > SANDISK SD card. I am using a 1GB A-DATA microSD with the
available
> > adapter. Could this be a problem?
> >
> > Tudor
> >
> >
> > --- In A..., Bernd Walter wrote:
> > >
> > > On Tue, Mar 04, 2008 at 08:09:42AM -0000, axl_dudu wrote:
> > > > Thanks Eric.
> > > > I haven't tried yet the NutOS. I have been using FreeRTOS and
> I'd
> > > > like to continue with it(at least for the moment). But I will
> > > > consider migrating to the NutOS, if it includes FTP.
> > >
> > > You might want to consider efsl.
> > > http://www.efsl.be/
> > > It has some limitations on FAT with long filenames though.
> > > But maybe you are just searching for the block functions and
not
> for
> > > filesystem support.
> > >
> > > > --- In A..., "Eric Haver"
> wrote:
> > > > >
> > > > > Hi Tudor,
> > > > >
> > > > > NutOS does this right out of the box.
> > > > > Includes FTP.
> > > > >
> > > > > I am now working to get it to format the card.
> > > > >
> > > > > *E
> > > > >
> > > > >
> > > > >
> > > > > On Sun, Mar 2, 2008 at 12:39 PM, axl_dudu wrote:
> > > > >
> > > > > > Hello,
> > > > > > does anyone has a working example for controlling the
> SD/MMC
> > card
> > > > on an
> > > > > > at91sam7 (preferably with the olimex's board sam7-ex256)?
I
> > have
> > > > been
> > > > > > struggling to get working an example that someone gave me
> but
> > it
> > > > gets
> > > > > > stuck somewhere in the init part.
> > > > > >
> > > > > > Thanks,
> > > > > > Tudor
> > > > > >
> > > > > >
> > >
> > > --
> > > B.Walter http://www.bwct.de
> http://www.fizon.de
> > > bernd@ info@ support@
> > >
> >
> >
> >
> >
> >
> >
It would be great to see the format function you have made. If you
can, try the system together with FreeRTOS and tell me if it works
for you.

Tudor

--- In A..., "microbit" wrote:
>
> I was curious and ended up having a look at EFSL.
> It seems to be in an 'in between' state 0.2.8 -> 0.3/4 , but
overall I quite like it - the ioman
> has some nice caching features. There's a few silly things too, but
it seems that's WIP.
>
> So, I got interested in fiddling and decided to set it up for my
SAM7S256-EK which I added an
> SD/MMC socket to quite some time ago.
>
> To be able to work faster I've first set up a project under
CrossWorks MSP430 with Simulator.
> I simulate a 30 KB FAT12 drive there (which I first "force" format
of course, as it's in simulated
> RAM..)
> This way I can familiarise myself way faster with the guts of it,
as the code is little
> documented.
>
> I've written a formatting function so you can fmt from EFSL in
FAT12/16/32, to be tested better.
>
> I've actually had fun doing that, next I'll port my existing
interface code from SAM7-EK that I
> have under CrossWorks for ARM.
>
> So, after I do this I can help you much better with EFSL if you
want to.
>
> Best Regards,
> Kris
>
> -----Original Message-----
> From: A... [mailto:A...] On
Behalf Of axl_dudu
> Sent: Wednesday, 5 March 2008 5:39 AM
> To: A...
> Subject: [AT91SAM] Re: SD/MMC card on an sam7-ex256
>
> I've just checked to see if it reads the MBR and WHAT it reads from
> there. First, the EFSL checks the Boot sector signature (that must
be
> 0x55AA) but mine reads 0xABB0. Then it checks other stuff that I
> haven't got the time to dig up.
> I have checked the signature on the pc and it is just fine. So
there
> might be a problem when reading this address. Maybe it is a problem
> with the device speed, as Eric suggested. If you have any other
> suggestions, please post them.
> Regards,
> Tudor
>
Hi Tudor,

You limit the speed by setting your SPI clock to about 100KHz during init phase :

Command 0 : GO_IDLE_STATE
Command 1 : SEND_OP_COND

After receiving the last response, you can then change the SPI clock up to 25MHz max (check manufacturer specifications and CSD register).

I am sucessfully using an ScanDisk 2Gb card at 8MHz.

Eric.

----- Original Message -----
From: axl_dudu
To: A...
Sent: Tuesday, March 04, 2008 7:40 PM
Subject: [AT91SAM] Re: SD/MMC card on an sam7-ex256
Hello Eric!
How did you limit the speed? If you remember what changes you made to
do that, please post them (at least from what you remember).

Thanks,
Tudor

--- In A..., "Eric Pasquier" wrote:
>
> Hi,
>
> I am using a 2GB card with SPI protocol.
> I remember that I had to limit transfert rate during initialisation
phase.
>
> I hope this help.
>
> Eric Pasquier
>
>
> ----- Original Message -----
> From: axl_dudu
> To: A...
> Sent: Tuesday, March 04, 2008 6:10 PM
> Subject: [AT91SAM] Re: SD/MMC card on an sam7-ex256
>
>
> Yes. It is what I was looking for. I got an example made for this
> board but it doesn't work properly. I have a microSD with an
adapter
> for the SD slot. The problem, as far as I went until now, is that
> even thought the interface can read from the card, it detects
invalid
> FAT during the startup sequence of the EFSL. The card is just
fine, I
> checked it on the pc. I even installed a program that reads the
Disk
> Parameter Block and everything seems ok.
>
> The person that gave me the example said he tried it with a 512MB
> SANDISK SD card. I am using a 1GB A-DATA microSD with the
available
> adapter. Could this be a problem?
>
> Tudor
>
> --- In A..., Bernd Walter wrote:
> >
> > On Tue, Mar 04, 2008 at 08:09:42AM -0000, axl_dudu wrote:
> > > Thanks Eric.
> > > I haven't tried yet the NutOS. I have been using FreeRTOS and
I'd
> > > like to continue with it(at least for the moment). But I will
> > > consider migrating to the NutOS, if it includes FTP.
> >
> > You might want to consider efsl.
> > http://www.efsl.be/
> > It has some limitations on FAT with long filenames though.
> > But maybe you are just searching for the block functions and
not for
> > filesystem support.
> >
> > > --- In A..., "Eric Haver"
wrote:
> > > >
> > > > Hi Tudor,
> > > >
> > > > NutOS does this right out of the box.
> > > > Includes FTP.
> > > >
> > > > I am now working to get it to format the card.
> > > >
> > > > *E
> > > >
> > > >
> > > >
> > > > On Sun, Mar 2, 2008 at 12:39 PM, axl_dudu wrote:
> > > >
> > > > > Hello,
> > > > > does anyone has a working example for controlling the
SD/MMC
> card
> > > on an
> > > > > at91sam7 (preferably with the olimex's board sam7-ex256)?
I
> have
> > > been
> > > > > struggling to get working an example that someone gave me
but
> it
> > > gets
> > > > > stuck somewhere in the init part.
> > > > >
> > > > > Thanks,
> > > > > Tudor
> > > > >
> > > > >
> >
> > --
> > B.Walter http://www.bwct.de http://www.fizon.de
> > bernd@ info@ support@
> >
>
Hi Tudor,

I've only had time in bits 'n pieces, but everything is working quite OK now.
The formatting is working fine for FAT12/16 with a choice to create partitioned or not
cards. I need to find a gap to finalise testing FAT32, there's a small snag there somewhere.
One of the problems is that EFSL assumes a FAT32 card by default *and* assumes that it is
partitioned. Format an SD card from XP through a reader and you'll see they're never partitioned,
they're just SFD.
EFSL just loads the 4 partition tables and happily chugs away. (it should check for the 'magic'
number on MBR and then make a decision whether there is a partition table present or not) I
presume the authors are working on that. I looked at it, but there's no simple way to fix that
without changing the actual code under the \src\ directory.
The main contention is with function loadMBR().

In any case, when the format function is all tested and cleaned up I'll send it to you and/or
upload it here in Files.

Oh, I don't use FreeRTOS, If I need RTOS I use CTL (which is CrossWorks included RTOS).

Best Regards,
Kris

-----Original Message-----
From: A... [mailto:A...] On Behalf Of axl_dudu
Sent: Thursday, 6 March 2008 12:33 AM
To: A...
Subject: [AT91SAM] Re: SD/MMC card on an sam7-ex256

It would be great to see the format function you have made. If you
can, try the system together with FreeRTOS and tell me if it works
for you.

Tudor
Hi all,

For completeness in the formatting stuff I've written for EFSL, I'm writing ability to partition
large SD cards. Now, I've noticed that XP doesn't/won't access the extra partitions.
I'm assuming it's because they're registering as 'Removable' media.

I always thought that RBC deals in RAW LBAs, so I don't see why XP shouldn't be able to do it.
(but it doesn't it seems)

So, the question is :

Q : Does anyone know of a utility or some such that 'stops' or 'filters' XP from ignoring active
partitions #2-#4 on SD cards (through a Card Reader) ?

FWIW, when I format from AT91SAM7S-EK and test with eg. 2 partitions, then Disk Manager shows the
2 partitions :
It shows the first partition as 'FAT' - healthy
and the 2nd partition as 'Healthy' but doesn't recognise FAT.

PS : Changing the Media Descriptor to 'Fixed' in boot record in my code doesn't help either.

Best Regards,
Kris
Hi,

> For completeness in the formatting stuff I've written for EFSL, I'm
> writing ability to partition
> large SD cards. Now, I've noticed that XP doesn't/won't access the
> extra partitions.
> I'm assuming it's because they're registering as 'Removable' media.

Whatever it's doing, the partitions don't show up. I don't think anybody
has been able to do this on Windows.

> I always thought that RBC deals in RAW LBAs, so I don't see why XP
> shouldn't be able to do it. (but it doesn't it seems)

Again, I do not know of a reason not to, but I suspect that Microsoft have a
good reason.

> So, the question is :
>
> Q : Does anyone know of a utility or some such that 'stops' or
> 'filters' XP from ignoring active
> partitions #2-#4 on SD cards (through a Card Reader) ?

Not that I know of.

> FWIW, when I format from AT91SAM7S-EK and test with eg. 2 partitions,
> then Disk Manager shows the 2 partitions :
> It shows the first partition as 'FAT' - healthy
> and the 2nd partition as 'Healthy' but doesn't recognise FAT.
>
> PS : Changing the Media Descriptor to 'Fixed' in boot record in my code
> doesn't help either.

I use Mac OS X with my SD card library; Mac OS seems to do a much better job
of it than Windows.

--
Paul Curtis, Rowley Associates Ltd http://www.rowley.co.uk
CrossWorks for ARM, MSP430, AVR, MAXQ, and now Cortex-M3 processors
Hi Kris,
Good ideea to use more partitions on a single SD card. I don't see
any reason for Windows to not recognize them.
If you find anything, please let me know.

Tudor

--- In A..., "microbit" wrote:
>
> Hi all,
>
> For completeness in the formatting stuff I've written for EFSL, I'm
writing ability to partition
> large SD cards. Now, I've noticed that XP doesn't/won't access the
extra partitions.
> I'm assuming it's because they're registering as 'Removable' media.
>
> I always thought that RBC deals in RAW LBAs, so I don't see why XP
shouldn't be able to do it.
> (but it doesn't it seems)
>
> So, the question is :
>
> Q : Does anyone know of a utility or some such that 'stops'
or 'filters' XP from ignoring active
> partitions #2-#4 on SD cards (through a Card Reader) ?
>
> FWIW, when I format from AT91SAM7S-EK and test with eg. 2
partitions, then Disk Manager shows the
> 2 partitions :
> It shows the first partition as 'FAT' - healthy
> and the 2nd partition as 'Healthy' but doesn't recognise FAT.
>
> PS : Changing the Media Descriptor to 'Fixed' in boot record in my
code doesn't help either.
>
> Best Regards,
> Kris
>
Hello Paul,
sorry for asking, but I didn't understood one thing from what you
wrote. Is MAC OS able to recognize different partitions on a sigle SD
card?

Regards,
Tudor

--- In A..., "Paul Curtis" wrote:
>
> Hi,
>
> > For completeness in the formatting stuff I've written for EFSL,
I'm
> > writing ability to partition
> > large SD cards. Now, I've noticed that XP doesn't/won't access the
> > extra partitions.
> > I'm assuming it's because they're registering as 'Removable'
media.
>
> Whatever it's doing, the partitions don't show up. I don't think
anybody
> has been able to do this on Windows.
>
> > I always thought that RBC deals in RAW LBAs, so I don't see why XP
> > shouldn't be able to do it. (but it doesn't it seems)
>
> Again, I do not know of a reason not to, but I suspect that
Microsoft have a
> good reason.
>
> > So, the question is :
> >
> > Q : Does anyone know of a utility or some such that 'stops' or
> > 'filters' XP from ignoring active
> > partitions #2-#4 on SD cards (through a Card Reader) ?
>
> Not that I know of.
>
> > FWIW, when I format from AT91SAM7S-EK and test with eg. 2
partitions,
> > then Disk Manager shows the 2 partitions :
> > It shows the first partition as 'FAT' - healthy
> > and the 2nd partition as 'Healthy' but doesn't recognise FAT.
> >
> > PS : Changing the Media Descriptor to 'Fixed' in boot record in
my code
> > doesn't help either.
>
> I use Mac OS X with my SD card library; Mac OS seems to do a much
better job
> of it than Windows.
>
> --
> Paul Curtis, Rowley Associates Ltd http://www.rowley.co.uk
> CrossWorks for ARM, MSP430, AVR, MAXQ, and now Cortex-M3 processors
>
Hi Tudor,

> Hello Paul,
> sorry for asking, but I didn't understood one thing from what you
> wrote. Is MAC OS able to recognize different partitions on a sigle SD
> card?

Yes, and it's able to partition them too.

--
Paul Curtis, Rowley Associates Ltd http://www.rowley.co.uk
CrossWorks for ARM, MSP430, AVR, MAXQ, and now Cortex-M3 processors
Hi Paul,

Thanks for clarifying, that confirms my observations :-)

> Whatever it's doing, the partitions don't show up. I don't think anybody
> has been able to do this on Windows.

Can you define 'partitions don't show up' better ?
Disk Management does show my (extra) partitions, but it doesn't see the FAT I put on it.

While on this subject, can you confirm that each boot record for a partition does _indeed_ reside
at LBA start of partition + the CHS sector offset of 63 ?
IOW I mean, let's say an SD card is partitioned exactly in 2 equal parts (SD card size/2).
If I have this correct, the Boot record for partition #2 would be at LBA (SD card size/2) + 63
and its LBA sector size (at [0x1CE].sectorsize in MBR) would be LBA ((SD card size/2) - 63).
Correct ?

In any case, it's still handy to partition. One of my test cards is a Transcend 512 MB and it's
woefully slow. For quicker testing I just allocate like say 1/4 of that etc.

Best Regards,
Kris

-----Original Message-----
From: A... [mailto:A...] On Behalf Of Paul Curtis
Sent: Sunday, 9 March 2008 10:11 PM
To: A...
Subject: RE: [AT91SAM] Reading extra partitions on SD Cards as Volumes on XP

Hi,

> For completeness in the formatting stuff I've written for EFSL, I'm
> writing ability to partition
> large SD cards. Now, I've noticed that XP doesn't/won't access the
> extra partitions.
> I'm assuming it's because they're registering as 'Removable' media.

Whatever it's doing, the partitions don't show up. I don't think anybody
has been able to do this on Windows.

> I always thought that RBC deals in RAW LBAs, so I don't see why XP
> shouldn't be able to do it. (but it doesn't it seems)

Again, I do not know of a reason not to, but I suspect that Microsoft have a
good reason.

> So, the question is :
>
> Q : Does anyone know of a utility or some such that 'stops' or
> 'filters' XP from ignoring active
> partitions #2-#4 on SD cards (through a Card Reader) ?

Not that I know of.

> FWIW, when I format from AT91SAM7S-EK and test with eg. 2 partitions,
> then Disk Manager shows the 2 partitions :
> It shows the first partition as 'FAT' - healthy
> and the 2nd partition as 'Healthy' but doesn't recognise FAT.
>
> PS : Changing the Media Descriptor to 'Fixed' in boot record in my code
> doesn't help either.

I use Mac OS X with my SD card library; Mac OS seems to do a much better job
of it than Windows.

--
Paul Curtis, Rowley Associates Ltd http://www.rowley.co.uk
CrossWorks for ARM, MSP430, AVR, MAXQ, and now Cortex-M3 processors