Jump to content
calinp

[Energia Library] Stellaris Launchpad FatFs Energia library

Recommended Posts

This is a port to Energia of the Arduino library from this page: http://pressplay.pbworks.com/w/page/25687375/FatFs

 

The diskio.c driver is from Stellarisware example for lm4f232 with some changes:

- use digitalWrite for CS control

- use delays instead of timers for timeouts

 

The card must be connected to SSI0 (hardcoded in driver) but CS signal is defined in sketch and can be any pin.

 

I checked the FileWriteToSerial example and it is working with uSD and uSDHC cards (2GB and 8GB). I connected the uSD cards with and adapter to SD using the first method presented here: http://www.43oh.com/2011/02/five-cheap-breadboard-prototyping-tips-and-tricks-list-2/

 

Also, I'm not a good programmer (I had first hands-on experience with C when I discovered Energia) so some parts of the code might be optimised further for Stellaris.

 

Extract the archive in Energia\hardware\lm4f\libraries\ and enjoy!

 

[uPDATE] See post #7 http://forum.stellarisiti.com/topic/442-energia-library-stellaris-launchpad-fatfs-energia-library/#entry2553

[DOWNLOAD LINK] http://forum.stellarisiti.com/index.php?app=core&module=attach&section=attach&attach_id=335

 

The file attached to this post is the first version. For the updated library please use the link above.

FatFs_03.zip

Share this post


Link to post
Share on other sites

G'day Calin,

Having a wee bit of trouble with the this Fat library. I do not get the SPI  CLK.

Am sure my sd hardware is ok as I can get the CLK when running with the Petit Lib.

Will have a deeper look today.

 

Grant

 

 

 

Share this post


Link to post
Share on other sites

G'day Cain,

Got the lib to work at last. The problem was not with the lib, but with using an arduino shield, that only takes a micro SD's.

After getting a sparkfun SD and wiring up the signals, all worked great.

I think I spent more time on decoding the SPI signals (mainly MISO) on my Cro  then anything else.

Makes one want to spend a few $$'s on a SPI to Hex display.

Anyway, will get on and have a good play with the lib's other functions.

Tks for your help once again.

Grant

Share this post


Link to post
Share on other sites

Hi Grant,

Try to add a pull-up resitor of 1K to MISO pin. The original driver enables the weak pull-up for MISO, but in the the Energia SPI lib it is not enabled. You can also try to set the MISO pin with pinMode(MISO, INPUT_PULLUP) before SPI.begin.

 

Regards,

Calin

Share this post


Link to post
Share on other sites

G'Day Calin,

Yup will give try out your suggestions, when I get back into town.

One thing I have added is a 1000MFD capacitor across the 3v3 supply at the SD card holder.

I found that each time I plugged in a SD card it would reset the processor. Also noted that a 470 MDF was not large enough.

 

Grant

Share this post


Link to post
Share on other sites

Update to support the SPI driver and different SSI modules:

- FatFs.begin(cs_pin) -> defaults to SSI2 and maximum SPI clock

- FatFs.begin(cs_pin, clock_divider) -> SSI2 and SPI clock is divided by clock_divider.

- FatFs.begin(cs_pin, clock_divider, module) -> SPI clock is divided by clock_divider, new SSI module selection

- inherited print functions ( can be enabled in ffconf.h )

 

Pin 9 is used as CS inside the SPI library and it is toggled at each byte transferred so it can't be used by FatFs.

I made some tests with CS control disabled inside the SPI lib and the transfer speed increases by ~50%.

 

If the card can't be initialized, a possible solution is a 1K pull-up resitor from MISO to VDD.

 

Because this library doesn't use low level access to hardware it shoul be compatible with further boards supportded by Energia (with enough RAM).

 

Calin

 

[EDIT]  corrected the speed test example

FatFs_SpeedTest.txt

FatFs05.zip

Share this post


Link to post
Share on other sites
Hi Calin,

 

I tested the example "FileWriteToSerial" and it worked perfectly. I tryed to run the "FatFsSpeedTest" but the program remains hanged-up just after PUSH2 release detection, have you experimented something like this? I suspect it happens at FatFs.open calling function just after key release detection.

 

Rgds,

 

Samuel

Share this post


Link to post
Share on other sites

Hi Samuel,

 

I found  an error in that example. Please change char buffer[2048]; to char buffer[16384]; .

I updated the zip file with this change.

 

Thanks,

Calin

Share this post


Link to post
Share on other sites

Hi Calin,

 

I updated the size of the buffer and now the example is running OK. By the way, this example is an excelent tool to verify writing/reading speeds as well as ratio of block size versus speed.

 

Thanks,

 

Samuel

Share this post


Link to post
Share on other sites

Hi,

I have a problem. When I open file a write message to it and then write something to serial (even other serial ( i mean Serial1.writeln() ) ) it apears in the file.  Even after calling the "FatFs.close()". Could anyone help me with this?

Share this post


Link to post
Share on other sites

Hello,

I will do some check on this.

Try to use the printf function for writing in files (needs to be enabled in ffconf.h, _USE_STRFUNC 1). Also disable the print support ( _USE_PRINT 0)

Share this post


Link to post
Share on other sites

Hello,

I will do some check on this.

Try to use the printf function for writing in files (needs to be enabled in ffconf.h, _USE_STRFUNC 1). Also disable the print support ( _USE_PRINT 0)

I was trying this but always end with FR_NOT_ENABLED error .. and I must say that i do not know what this error mean... maybe I am doing something wrong...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×