Jump to content

  • Log In with Google      Sign In   
  • Create Account

Photo

[Energia Library] Petit FatFS SD Card Library


  • Please log in to reply
80 replies to this topic

#1 calinp

calinp

    Member

  • Members
  • PipPip
  • 27 posts
  • LocationBucharest, RO

Posted 14 January 2013 - 07:11 PM

Hello,

 

This is a port of ChaN Petit FatFS SD library targeted to low RAM microcontrollers and offers a minimal FAT implementation, with limited write support. For more details see http://elm-chan.org/.../00index_p.html

 

A lot of credits goes to the main contributors to this topic http://forum.43oh.co...card-usci-code/

 

 

Because this library makes use of the SPI library included in Energia it  works for both MSP430 and Stellaris launchpads.

 

With MSP430 I noticed some interference with Serial.print so before every call to the fat library I had to add a small delay. On Stellaris board these are not necessary. 

 

 

Unzip and copy in Energia\hardware\msp430\libraries or Energia\hardware\lm4f\libraries .

 

[UPDATE] See post #15 http://forum.43oh.co...ary/#entry30031

 

[DOWNLOAD LINK] http://forum.43oh.co...&attach_id=3019


  • Rickta59, larsie, xv4y and 2 others like this

#2 OzGrant

OzGrant

    Level 1

  • Members
  • 120 posts
  • LocationAustralia

Posted 29 January 2013 - 10:24 PM

Calin,

Thanks for your reply regarding my SD card read problem. Thought it best to discuss it in this forum as it could help others that might have this problem.

 

Following your suggestion I lowered the SPI speed, by  two changes in diskio.c function DSTATUS disk_initialze() where the first occurrence of SPI_SET_DIVIDER edited from 64 to 128, and the second occurrence 2 to 4.

 

But still unable the read the two new micro SD cards. As the original SD card works ok  I think it is how I format the two new SD cards.

I formatted under Windows 7 and selecting FAT. When I compared properties  of the readable SD card with the other two, the only difference  is that the good SD does not support ReadyBoost, whereas the other two can. Hence Windows 7 has detected a difference, that may be a clue to the problem. All three SD 4GB cards are from the same manufacturer.

 

Will dig up my old XP notebook and see if a non Windows 7 FAT format fixes the problem.

 

Grant  

 

 



#3 OzGrant

OzGrant

    Level 1

  • Members
  • 120 posts
  • LocationAustralia

Posted 30 January 2013 - 08:53 PM

G'day Calin,

Well using XP windows was disappointing, it only allows FAT32 formatting. Anyway have at least one Micro SD card working OK and that solves my immediate problem.

 

On another point, as you can only write to a preexisting file (created in Windows) it makes datalogging csv files a bit of a problem.

Ideally its nice to create a new file each time you start datalogging. Again I have been pampered by the Arduio libs that allow this.

Let me know if you are working on this, if not, I will have a go at modifying your library to include this feature.

 

Grant

 

 



#4 calinp

calinp

    Member

  • Members
  • PipPip
  • 27 posts
  • LocationBucharest, RO

Posted 31 January 2013 - 06:01 AM

Hi Grant,

 

Try to format the cards that are not working with HP USB Disk Storage Format Tool : http://www.softpedia...rmat-Tool.shtml

 

The write function has some limitations :

  • Cannot create file. Only existing file can be written.
  • Cannot expand file size.
  • Cannot update time stamp of the file.
  • Write operation can start/stop on the sector boundary.
  • Read-only attribute of the file cannot block write operation.

See more here: http://elm-chan.org/...f/pf/write.html

 

The FatFS lib does not have these limitations and provides more functions, but will not work with only 512bytes of RAM.

With Petit FatFS you should create one or more empty large files and write until they are full.

 

In case you want to append records to a non empty file you must find the last sector written and start writing on the next one.

 

Below is an update to the library:

- SPI clock divider can be specified in the begin function like FatFs.begin(cs_pin,2); -> 16MHZ / 2 = 8MHz SPI Clock

- added string functions from FatFS:

FatFs.gets - Read a string

FatFs.fputc - Write a character

FatFs.puts - Write a string

FatFs.printf - Write a formatted string

- Inherits from print class so you can use :

FatFS.print()

FatFS.println()

[EDIT] Forgot  about FatFs.close(). It only does pf_write(0, 0, &bw) but is easier to use.

 

Important! Apply these patches:

http://forum.43oh.co...orrupts-spi-io/

http://forum.43oh.co...-byte-not-read/

 

I hope these will make the lib easier to use.

 

Calin 

Attached Files


  • bluehash likes this

#5 OzGrant

OzGrant

    Level 1

  • Members
  • 120 posts
  • LocationAustralia

Posted 01 February 2013 - 02:36 AM

Calin,

As I've moved over to the Stellaris, RAM memory no longer a problem. So it looks like I'll leave Petit FatFS, and start using FatFS.

Can't see an energia type FatFS library anywhere, so will try to convert it over. Then again, it took me three weeks to do the same thing with OneWire, so this might take a while.

 

Tks for your past help.

 

Grant 



#6 calinp

calinp

    Member

  • Members
  • PipPip
  • 27 posts
  • LocationBucharest, RO

Posted 01 February 2013 - 04:53 AM

I made port for Stellaris  http://forum.stellar...nergia-library/ .

Maybe instead of starting from scratch, use this one and improve it :)

 

Regards,

Calin



#7 OzGrant

OzGrant

    Level 1

  • Members
  • 120 posts
  • LocationAustralia

Posted 02 February 2013 - 11:11 PM

Calin,

Yup the stellaris SD Lib looks good, I originally thought it was a Petit one. Have done a few changes and should be finished soon.

Will talk to you on the stellaris forum, as it's of no use for the 430, due to ram limitations

Grant.

 



#8 larsie

larsie

    Level 2

  • Members
  • 272 posts


Posted 08 February 2013 - 09:53 PM

Would the larger FatFS work on larger MSP430s? Like the F5510, with 4096 KB RAM?


  • sirri likes this

#9 calinp

calinp

    Member

  • Members
  • PipPip
  • 27 posts
  • LocationBucharest, RO

Posted 09 February 2013 - 05:27 AM

Of course. As a starting point you can grab the Stellaris Fatfs lib and adapt the diskio driver from Petit Fatfs (based on Energia SPI library).The Petit lib is more "Arduino style" and it works both on MSP430 and Stellaris Launchpads without any change.

 

I plan to make these changes to the Fatfs lib in the next weeks.

 

Calin



#10 OzGrant

OzGrant

    Level 1

  • Members
  • 120 posts
  • LocationAustralia

Posted 14 February 2013 - 11:15 PM

Calin,

Am a bit naught here asking this stellaris type question (but the site is down at the moment) plus its to do with your other FatFS lib.

The Petit used SPI(2) where the FatFS uses SPI(0). Is there a command that can force Petit to useSPI(0) or to force FatFs to use SPI(2).

I want to allow the booster card I'm making to suit both Petie on the 430 and FatFs on stellaris.

Grant



#11 calinp

calinp

    Member

  • Members
  • PipPip
  • 27 posts
  • LocationBucharest, RO

Posted 15 February 2013 - 05:18 AM

Hi,

Now you can't select a different port for FatFS, but I plan to implement this so existing shields can be used on both Launchpads. 



#12 OzGrant

OzGrant

    Level 1

  • Members
  • 120 posts
  • LocationAustralia

Posted 15 February 2013 - 06:32 AM

Calin,

Where is it hard coded in the CPP file, had a look around and can not see where it is done.

Grant



#13 calinp

calinp

    Member

  • Members
  • PipPip
  • 27 posts
  • LocationBucharest, RO

Posted 15 February 2013 - 08:31 AM

In diskio.c that was taken from StellarisWare. I think you have to change SSI0 with SSI2 and make sure the GPIO are initialized properly



#14 OzGrant

OzGrant

    Level 1

  • Members
  • 120 posts
  • LocationAustralia

Posted 15 February 2013 - 11:37 AM

Calin,

Hum did not look there will give it a shot Tks

Grant



#15 calinp

calinp

    Member

  • Members
  • PipPip
  • 27 posts
  • LocationBucharest, RO

Posted 21 February 2013 - 08:55 PM

A small update:

- all config settings in one file - pffconf.h

- a soft SPI driver ( shuftIn/shiftOut ) that can be enabled in pffconf.h. It defaults on HW SPI pins, but these can be changed using FatFs.begin(cs_pin, sclk_pin, mosi_pin, miso_pin); . The speed is very low, but it frees 3 pins that can be used as analog inputs or I2C.

- added a small benchmarking example

 

Tested on MSP430G2553 and Stellaris Launchpads. A minimal program should work also on MSP430G2452. 

On fraunchpad the examples compile without errors but I don't have the board to test it.

 

Calin

 

 

Attached Files


  • bluehash, energia, pivden and 1 other like this

#16 bluehash

bluehash

    Site Admin

  • Administrators
  • 5,468 posts

Posted 03 March 2013 - 01:06 PM

Thanks Calinp. Could you update the first post of this thread with a link to the latest version post. Makes it easier for members to find.


  • sirri likes this

Stellarisiti - Join the new Tiva-C/Stellaris ARM Forums discussing Tiva-C(Stellaris) Microcontrollers.

C2kCentral - C2000 News, Projects and Forums
43oh - MSP430 Discussion, News, Projects and Hacks
MachineGrid - Robots, Hacks and Technology!


#17 sirri

sirri

    Level 2

  • Members
  • 163 posts
  • Locationturkey

Posted 18 March 2013 - 05:53 PM

Can you please give a simple "writing" example for this library?

Thanks,

Sirri



#18 bluehash

bluehash

    Site Admin

  • Administrators
  • 5,468 posts

Posted 18 March 2013 - 06:23 PM

Can you please give a simple "writing" example for this library?

Thanks,

Sirri

See Calinp post above mine. There is an example in the package.


  • sirri likes this

Stellarisiti - Join the new Tiva-C/Stellaris ARM Forums discussing Tiva-C(Stellaris) Microcontrollers.

C2kCentral - C2000 News, Projects and Forums
43oh - MSP430 Discussion, News, Projects and Hacks
MachineGrid - Robots, Hacks and Technology!


#19 sirri

sirri

    Level 2

  • Members
  • 163 posts
  • Locationturkey

Posted 18 March 2013 - 08:35 PM

See Calinp post above mine. There is an example in the package.

Thanks, i have seen the sample but it looks quite complicated :/  I will try it soon though.



#20 sirri

sirri

    Level 2

  • Members
  • 163 posts
  • Locationturkey

Posted 19 March 2013 - 07:25 PM

 
I have formatted my SD Card to FAT file system 
My pin connections are as below (checked in the petit fatfs libray)
(and 10 for the CS)
I have pasted t_read and t_write .txt files into the sd card..
P.S. My 16MHz Crystal is not soldered is this an issue for this task?
 
  uint8_t data;
  uint8_t _SCLK = 7;
  uint8_t _MOSI = 15;
  uint8_t _MISO = 14;  //defaults on HW SPI pins
 
I am getting this message on serial monitor and so when i check my sd card i see that t_write is still blank..
 
Press button to start...
 
Open a test file (t_read.txt).
 
Failed with rc=6

Attached Files






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users