EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

Writing on SD/MMC card with GCC on MCB2300

Started by rd2...@wavetel.fr August 20, 2007
Hello,
I am trying to port a sample code from NPX
to GCC compiler.

The sample is called MCI. It's based on Keil
compiler. It's just supposed to write some
consecutive blocks on the flash card trough
the MCI port.

The sample works perfectly with Keil evaluation
compiler, but it does not work with GCC.
The compilation of the source code is not
a problem. I adapted a very few part of the
code.

__irq => __attribute__((interrupt("IRQ"))
I am using a startup code written by Martin Thomas.
This code seems to initialize the card as do the
Keil project configuration.
In fact, the initialization of the MCI is a success.
My SD card is found, but i can't write anything on
the card.

Does anyone succeed to write anything on a SD card
in the MCB2300 board trough the MCI port ?
Best regards.

Pascal.

An Engineer's Guide to the LPC2100 Series

r...@wavetel.fr wrote:

> I am trying to port a sample code from NPX
> to GCC compiler.

> The sample works perfectly with Keil evaluation
> compiler, but it does not work with GCC.

> __irq => __attribute__((interrupt("IRQ"))

I don't have much experience with the GCC on ARM, but as far as I read,
there are quite some problems especially with the interrupt code
generated by the GCC.

> I am using a startup code written by Martin Thomas.
> This code seems to initialize the card as do the
> Keil project configuration.

Have a look at the clock configuration in both projects - do they match
(at least for the MCI part)?

> In fact, the initialization of the MCI is a success.
> My SD card is found, but i can't write anything on
> the card.
>
> Does anyone succeed to write anything on a SD card
> in the MCB2300 board trough the MCI port ?

Yes, but I wrote my own "driver". You can find it at the patches section
of the EFSL project (sf.net/projects/efsl/).

Cheers,
Juri
Hello,

> Have a look at the clock configuration in both projects - do they match
> (at least for the MCI part)?

The source code is identical in both projects. The configuration of
the clock appears in one of the files.

In fact, the only differences in the source code is the startup code and
the asm routine which writes into the mci fifo.

I study the startup codes and I did not see lot of differences.
Gcc startup code seems to be a simple port of NPX startup code for
Gcc compiler.

The other difference is the __irq macro, I change it to gcc equivalent :
__attribute__((interrupt("IRQ"))
The execution of the code is very strange. The LPC2378 seems to be
lost in his interruptions. It loops for a long, long while.

> Yes, but I wrote my own "driver". You can find it at the patches
> section of the EFSL project (sf.net/projects/efsl/).

I download EFSL and I patch the library with your contribution this
morning.

You said that GCC seems to have troubles with interruption code, so
I try the library with the Keil compiler.
(the same I use for the MCI sample)

I did not forget to copy the config-sample-lpc23x8.h in the inc directory.

The code compiles great, but the board do not write anything on the
SD card. Moreover, the card seems so be in a infinite loop just after
the call of efs_init.
There is my test code :
--><--
#include "LPC23xx.h" /* LPC23xx/24xx definitions */

#include
#include

#define FILESYSTEM_OK 1
#define FILESYSTEM_INIT_FAILS 2
#define FILESYSTEM_FOPEN_FAILS 3

int main (void)
{
EmbeddedFileSystem efs;

euint8 buf[50];
int len;
int i;

File file;
eint8 res;

FIO2DIR = 0xFF;
FIO2CLR = 0xFF;

FIO2SET = 0x80;

res = efs_init(&efs, 0);
if (res != 0) {
FIO2CLR = 0xFF;
FIO2SET = 0x01;
return FILESYSTEM_INIT_FAILS;
}

res = file_fopen(&file, &efs.myFs, "TEST.TXT", 'w');
if (res != 0) {
FIO2CLR = 0xFF;
FIO2SET = 0x03;
return FILESYSTEM_FOPEN_FAILS;
}

// for (i=1 ; i<0 ; i++) {
// len = sprintf((char*)buf, "writing line %i\n", i);
// file_write(&file, len, buf);
// }

/* Close the file and the filesystem */
file_fclose(&file);
fs_umount(&efs.myFs);

FIO2SET = 0xAA;

return FILESYSTEM_OK;
}
--><----------------------

I think your patch of EFSL should works with Keil compiler.
Does anyone see where I am wrong ?

Best regards.

Pascal.
r...@wavetel.fr wrote:

> The code compiles great, but the board do not write anything on the
> SD card. Moreover, the card seems so be in a infinite loop just after
> the call of efs_init.

If you use the Keil IDE check where the code got stuck - maybe it's
stuck in the data abort handler due to a too small stack (or something
like this).
You could also enable the debugging output of EFSL (though you need to
initialize the serial interface for this to work).

Hope this helps a bit.

Cheers,
Juri
Juri,

I am working on an MCI driver for the LPC2378. I downloaded the
latest EFSL project, but your patch was not a part of it. How do I go
about getting your patch?

Jeff
--- In l..., Juri Haberland wrote:
>
> rd2@... wrote:
>
> > The code compiles great, but the board do not write anything on
the
> > SD card. Moreover, the card seems so be in a infinite loop just
after
> > the call of efs_init.
>
> If you use the Keil IDE check where the code got stuck - maybe it's
> stuck in the data abort handler due to a too small stack (or
something
> like this).
> You could also enable the debugging output of EFSL (though you need
to
> initialize the serial interface for this to work).
>
> Hope this helps a bit.
>
> Cheers,
> Juri
>
> I am working on an MCI driver for the LPC2378. I downloaded the
> latest EFSL project, but your patch was not a part of it. How do I go
> about getting your patch?

Please follow the link 'Patches' on the SourceForge project page
http://sourceforge.net/projects/efsl/

You will find the patch here:
http://sourceforge.net/tracker/?atidr2593&group_id1895&func=browse

Best regards.

Pascal.
ksdoubleshooter wrote:
> Juri,
>
> I am working on an MCI driver for the LPC2378. I downloaded the
> latest EFSL project, but your patch was not a part of it. How do I go
> about getting your patch?

See the patches section at the Sourceforge site.

http://sourceforge.net/tracker/index.php?funcail&aid74563&group_id1895&atidr2593

Cheers,
Juri
Thanks for help.

My problem is resolved. I was looking at the wrong
place.

Looking at the mailing list, I read this :

> Thank you Pete,
> I have just solved the problem. See Ed messege:
> "Try reducing clock speed to 48 or 60MHz, disabling
> MAM and try again.
>
> If that solves your problem, welcome to the
> "NXP really botched the 2368" club!
> -Ed
So, I disable the MAM.

It works great now.
For people who wants to write data on a SD/MMC,
I recommend TinyFS :

http://elm-chan.org/fsw/ff/00index_e.html
Best regards.

Pascal.

The 2024 Embedded Online Conference