EmbDev.net

Forum: ARM programming with GCC/GNU tools Olimex sam7-x256 and SD card


von Michal K. (newaxx)


Rate this post
useful
not useful
Hello

I tryed to reconfigure files from ARM MP3/AAC Player for SD support (
reading and writing ) from fatfs to fit for my Olimex sam7-ex256, and
coz i`m complete noob even in programming i didn`t managed to do it. I`d
like to ask if some1 managed to run
http://elm-chan.org/fsw/ff/00index_e.html module at SAM7-ex256 or might
help me with doing this?

Also if there is other library which i can use with that board i`d be
very thankfull if u would tell me which i should use, or if some1 could
guide me in how i can write/read from SD connected to that board. I use
Keil as programming software.

von Clifford S. (clifford)


Rate this post
useful
not useful
I would suggest using EFSL http://efsl.be/. The software you used
describes itself as "experimental" - well the FAT filesystem has been
around for over 30 years now, so there is no need to be 'experimental'!
;-) EFSL just works.

There are examples for AT91SAM7 targets using WinARM at
http://www.siwawi.arubi.uni-kl.de/avr_projects/arm_projects/efsl_arm/index.html,
thy can presumably be adapted for use with Kiel (or just use WinARM at
least to get you going to prove it out before migrating to Keil). There
should not be much if any code adaptation necessary.

Clifford

von Michal K. (newaxx)


Rate this post
useful
not useful
Can i open a file, read 512 Bytes then seek 1024 Bytes and read
1536-2024Bytes from opened file with this library?

von Clifford S. (clifford)


Rate this post
useful
not useful
Michal Kruczek wrote:
> Can i open a file, read 512 Bytes then seek 1024 Bytes and read
> 1536-2024Bytes from opened file with this library?


The manual is available for download. The API is minimal. To do what you
suggest I think would require you to read and discard a number
characters sequentially; not particularly hard, but I suggest that you
create your own wrapper functions to implement fseek/lseek like
functionality.

It would not take much to implement the relevant Newlib syscall stubs so
that the library could be used through stdio, lseek is one of the stubs
you would need to implement. File descriptors 0,1, and 2 are reserved
for stdin, stdout, and stderr, (typically mapped to a UART).

Clifford

von Michal K. (newaxx)


Rate this post
useful
not useful
Could u mail me at new.axx2@gmail.com with info how to contact u? I
think i`ll need a bit more chit-chatting about it. I`ll explain u my
situation and then we can come up with solution.

von Clifford S. (clifford)


Rate this post
useful
not useful
Michal Kruczek wrote:
> Could u mail me at new.axx2@gmail.com with info how to contact u? I
> think i`ll need a bit more chit-chatting about it. I`ll explain u my
> situation and then we can come up with solution.

What starts on forum stays on forum! ;-) For the benefit of all the
community. Besides that the forum does have a private messaging
facility, you just have to click on a user name to contact that user.

I access the forum when I am able, the rest of my time does not come for
free. Besides by discussing your development issues here you will get
more eyes looking at it, and possibly a better solution.

I suggest that you first simply get the file system running.
Synthesising a seek function is a simple programming exercise. If you
are not able to do that, you are not going to get very far in any case.

Clifford

von Michal K. (newaxx)


Attached files:

Rate this post
useful
not useful
hey it`s me back again.

I have some strange things going on with my evolution set. I`m still
trying to write the code for supporting that elm-chan.org lib with my
Olimex sam7-ex256.(EFSL is not an option for me ) I set SPI as following
:

>static
>void power_on (void)
>{
>  //enable pheripery control to: PA16, PA17, PA18
>  s_pPio->PIO_PDR= AT91C_PA13_SPI0_NPCS1 | AT91C_PA16_SPI0_MISO 
|AT91C_PA17_SPI0_MOSI | AT91C_PA18_SPI0_SPCK;
>  s_pPio->PIO_ASR=AT91C_PA13_SPI0_NPCS1 | AT91C_PA16_SPI0_MISO | 
AT91C_PA17_SPI0_MOSI | AT91C_PA18_SPI0_SPCK;
>  s_pPio->PIO_BSR=0;

>  //enable clock for SPI
>  s_pPMC->PMC_PCER=1<<AT91C_ID_SPI0;

>  //reset SPI and enable
>  s_pSpi->SPI_CR=AT91C_SPI_SPIEN | AT91C_SPI_SWRST ;
>  s_pSpi->SPI_CR=AT91C_SPI_SPIEN;

>  //config SPI
>  s_pSpi->SPI_MR=AT91C_SPI_MSTR | AT91C_SPI_PS_FIXED | AT91C_SPI_MODFDIS; 
//master mode,fixed peripheral,disable decoder,disable fault detection

>  s_pSpi->SPI_CSR[1]=AT91C_SPI_NCPHA | AT91C_SPI_BITS_8 | 0xC<<8;  //CPOL=0 
clockphase=1, 8bits,SPCK=47923200/192=249,6kHz,DLYBCT = 0
>  s_pSpi->SPI_MR &= 0xFFF0FFFF; //reset PCS
>  s_pSpi->SPI_MR |= 0xD0000;   //PCS=1101

>}

Then i wrote the functions to receve and send 1 byte (BYTE is equal to
unsigned char) by SPI_TDR and SPI_RDR as following:

>static
>BYTE rcvr_spi (void)
>{

>  BYTE dat;
>  AT91PS_SPI s_pSpi      = AT91C_BASE_SPI0;


>  while(!( s_pSpi->SPI_SR & AT91C_SPI_TDRE ) ); // transfer compl. wait
>  s_pSpi->SPI_TDR = 0xFF;



>  while( !( s_pSpi->SPI_SR & AT91C_SPI_RDRF ) ); // wait for char
>  dat = (BYTE)( s_pSpi->SPI_RDR );




>  return dat;
>}

and

>static
>BYTE xmit_spi(BYTE dat)
>{
>  BYTE data;
>  AT91PS_SPI s_pSpi = AT91C_BASE_SPI0;
>    while( !( s_pSpi->SPI_SR & AT91C_SPI_TDRE ) ); // transfer compl. wait
>  s_pSpi->SPI_TDR = dat;

>  while(!(s_pSpi->SPI_SR & AT91C_SPI_RDRF) );
>  data=(BYTE) ((s_pSpi->SPI_RDR) & 0xFF);        //read value
>  return data;
>}

After i called one of those functions in my disk init function those
seems to be loop forever, so i checked the state of TDRE and RDRF after
SPI enable command and guess what, both were 0 after reset. In datasheet
it is written that those bits after SPI enable command should be 1. Does
this mean that i have some data contantly applied to those registers, or
maybe there`s inverted way of working of those registers compering that
in datasheet. Also i include my source files, so some1 could look at
them and help me implementing this lib for writing to SD card. After i
changed while functions to while((s_pSpi->SPI_SR & AT91C_SPI_RDRF) )
they are no longer loops forever,  And the hole initialization process
stops after
>if (send_cmd(CMD8, 0x1AA) == 1)
function, to be more exact it stops at
>if (wait_ready() != 0xFF) return 0xFF;
function of send_cmd(), my debug function(zaswiec() i wrote more about
it later) doesn`t work after this even if this function suceede or it
won`t. It`s strange coz wait_ready() function always ends up but without
0xFF value. Also i tryed to set Chip select wire to be controled by PIO
and SPI, in both cases initialization function stoped at same point as
said few lines above. Oh also i`ve made my debug fuction ( which is lame
one, but it is helpfull for me, since i have no other way to debug
what`s going on with my program in Olimex evolution board ) this fuction
lights up LCD, so i use it to see in other fuctions succeded, by this
way i managed to know everything what i typed. That`s it, i hope some1
will be able to help me.

von Michal K. (newaxx)


Rate this post
useful
not useful
Ok this things seems to be fixed. But i have 1 more question, does the
SD card should respond with idle bit set to 1 ( in R1 command respons)
to CMD16 ( set block length ) ?

von Lite R. (lite)


Rate this post
useful
not useful
Michal Kruczek wrote:
> Ok this things seems to be fixed. But i have 1 more question, does the
> SD card should respond with idle bit set to 1 ( in R1 command respons)
> to CMD16 ( set block length ) ?

i'm also starting with an Olimex sam7-x256, so i'm new at this. i'm
trying to write/read from a file on a SD card. Could use some help ....
how did you fix those problems? could ou attach the code?

von Clifford S. (clifford)


Rate this post
useful
not useful
Lite Red wrote:
> Michal Kruczek wrote:
> i'm also starting with an Olimex sam7-x256, so i'm new at this. i'm
> trying to write/read from a file on a SD card. Could use some help ....
> how did you fix those problems? could ou attach the code?

How have you got on so far with the links and answers already provided
in this thread?

von Michal K. (newaxx)


Attached files:

Rate this post
useful
not useful
So, at first. Clifford thx for your help, but i decided to use ChaN`s
file system for my project. Thought your advices didn`t help alot, but I
would like to thank u very much for your time. I did made this file
system work, but i didn`t have enought time to finish my students
project, so i only wrote and read from file, not completing the
recording data to file from microphone and playing data from file by the
speaker, but i was very close.

At secound. Lite Red I attach the final project file. The thing is that
ChaN`s fs made a file at sd card but it was still 0byte. When i tryed it
create buffer for keeping data read/to be written do sd card, the
program hanged and didn`t wrok at all. I don`t know until now what was
the problem, but i did managed to store data and read data from the file
at sd disk. I figured out that when i made array or structure not
defined in ChaN`s release the program crashed, but when i used defined
arrays, everything worked. So becouse i didn`t use FILINFO structure as
my data holing array, U can re-edit that structure and change it the way
u want. Anyway it worked for me. this way I was able to read/write to
file 272bytes blok. Don`t bother interrupt.c I haven`t use it at all.

von Clifford S. (clifford)


Rate this post
useful
not useful
Michal Kruczek wrote:
> So, at first. Clifford thx for your help, but i decided to use ChaN`s
> file system for my project.

When I wrote "How have you got on so far with the links and answers
already provided in this thread?" the comment was directed at Lite Red
who appeared to be jumping in with a possibly unrelated problem or one
that was already answered in the thread, without any indication of how
far he'd got. He seemed to be saying, "give me your code because I am
too lazy to figure it out for my self". You did not need to write the
update on your work, but thanks.

I have looked more closely at ChaN's FS and I think you did the right
thing. It is nice an simple.


> Thought your advices didn`t help alot, but I
> would like to thank u very much for your time.
Ouch! Harsh putdown! ;-)

von Michal K. (newaxx)


Rate this post
useful
not useful
hehe, ok. I thought it was a question to me :) and sorry for beeing so
harsh :P

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.