Jump to content
43oh

[Energia Library] Petit FatFS SD Card Library


Recommended Posts

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/fsw/ff/00index_p.html

 

A lot of credits goes to the main contributors to this topic http://forum.43oh.com/topic/1427-petitefs-fatfs-sdcard-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.com/topic/3209-energia-library-petit-fatfs-sd-card-library/#entry30031

 

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

Link to post
Share on other sites
  • 3 weeks later...
  • Replies 148
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular Posts

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.

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 Fa

Hi, i just wanted to report that the library won't compile with Energia release 0101E0011 and the F5529 Launchpad because "DIR" is already defined in \energia-0101E0011\hardware\tools\msp430\msp430\in

Posted Images

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  

 

 

Link to post
Share on other sites

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

 

 

Link to post
Share on other sites

Hi Grant,

 

Try to format the cards that are not working with HP USB Disk Storage Format Tool : http://www.softpedia.com/get/System/Hard-Disk-Utils/HP-USB-Disk-Storage-Format-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/fsw/ff/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.com/topic/3272-msp430g2553-issue-hardwareserial-io-corrupts-spi-io/

http://forum.43oh.com/topic/3163-fixed-%E2%80%94-msp430g2553-spi-issue-first-byte-not-read/''>http://forum.43oh.com/topic/3163-fixed-%E2%80%94-msp430g2553-spi-issue-first-byte-not-read/'>http://forum.43oh.com/topic/3163-fixed-

PFatFs07.zip

Link to post
Share on other sites

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 

Link to post
Share on other sites

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

Link to post
Share on other sites

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

Link to post
Share on other sites

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

 

 

PFatFs10.zip

PFatFs_SpeedTest.txt

PFatFs_SpeedTest430.txt

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...