calinp 24 Posted January 14, 2013 Share Posted January 14, 2013 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§ion=attach&attach_id=3019 qwertyu, larsie, PTB and 3 others 6 Quote Link to post Share on other sites
OzGrant 22 Posted January 29, 2013 Share Posted January 29, 2013 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 Quote Link to post Share on other sites
OzGrant 22 Posted January 30, 2013 Share Posted January 30, 2013 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 Quote Link to post Share on other sites
calinp 24 Posted January 31, 2013 Author Share Posted January 31, 2013 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 bluehash 1 Quote Link to post Share on other sites
OzGrant 22 Posted February 1, 2013 Share Posted February 1, 2013 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 Quote Link to post Share on other sites
calinp 24 Posted February 1, 2013 Author Share Posted February 1, 2013 I made port for Stellaris http://forum.stellarisiti.com/topic/442-energia-library-stellaris-launchpad-fatfs-energia-library/ . Maybe instead of starting from scratch, use this one and improve it Regards, Calin Quote Link to post Share on other sites
OzGrant 22 Posted February 2, 2013 Share Posted February 2, 2013 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. Quote Link to post Share on other sites
larsie 121 Posted February 8, 2013 Share Posted February 8, 2013 Would the larger FatFS work on larger MSP430s? Like the F5510, with 4096 KB RAM? sirri 1 Quote Link to post Share on other sites
calinp 24 Posted February 9, 2013 Author Share Posted February 9, 2013 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 Quote Link to post Share on other sites
OzGrant 22 Posted February 14, 2013 Share Posted February 14, 2013 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 Quote Link to post Share on other sites
calinp 24 Posted February 15, 2013 Author Share Posted February 15, 2013 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. Quote Link to post Share on other sites
OzGrant 22 Posted February 15, 2013 Share Posted February 15, 2013 Calin, Where is it hard coded in the CPP file, had a look around and can not see where it is done. Grant Quote Link to post Share on other sites
calinp 24 Posted February 15, 2013 Author Share Posted February 15, 2013 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 Quote Link to post Share on other sites
OzGrant 22 Posted February 15, 2013 Share Posted February 15, 2013 Calin, Hum did not look there will give it a shot Tks Grant Quote Link to post Share on other sites
calinp 24 Posted February 21, 2013 Author Share Posted February 21, 2013 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 bluehash, pivden, sirri and 2 others 5 Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.