Jump to content
43oh

PetiteFS FATfs SDCard USCI code


Recommended Posts

  • Replies 144
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular Posts

Edit: July 6th, 2014 Please also note that Pabigot maintains BSP430 which has an example for the msp430. He also tracks any changes done to the ElmChan library with patches made to the example. Refer

I went ahead and tested the booster pack and added the write support in the attached zip file. You should take a look at the Petit FatFS documentation regarding the write limitations. PetiteFS only

I took a look at the software serial code - I'm not seeing any issues with gutting it and using hardware UART unless I'm missing something obvious.  I'm not seeing anything that sets anything affectin

Posted Images

  • 2 months later...

Hello,

i found a crittical bug, 

 

i am trying to read each time a diffrencet part from a file, by using    "pf_lseek( ofs)"  and then using " pf_read(Line, sizeof(Line), &s1)" .

each time i am incriminating the ofs.

eveything working great until im trying to read ofs>32768 .

after a long recerch i found that this number means  32768/512 = 64  with means the   "Allocation unit size" of the sdcard.

when i tried to change the  "Allocation unit size" to 64k. i got that the boundery is 65536/512 =128 , so now i could read much more.. but still with limit.

 

i think that there is a problem with reading next block. but i dont know where to change it?

 

 

Thank you all!!

:)

Link to post
Share on other sites

hi, bluehash, I'am trying use a SDCARD only to regist data. Only to write, I noticed that there is already a SDPetit-fat library, my question is I' will have to use all the files? and what are the files that need only to write to the SD. I'm new to microcontrollers, can you recommend me a documentation of easy understanding the workings of SDCARD

Link to post
Share on other sites

The "working" of an SDcard is different from the FatFS layer that sits on top of it.

I'm not thoroughly understanding your question. If you are using the Petite FatFs library, you will have to pre-create the file on your PC, then insert the cart into your embedded system and write/read from the file.

 

Have you seen this - http://43oh.com/2013/12/interfacing-the-launchpad-to-an-sd-card-a-walkthrough/'>Interfacing An SD-Card To The Launchpad

Link to post
Share on other sites

Hey Bluehash,

 

can you help me with my questions?

when using  pf_lseek( ofs) ,  ofs must be from 0 and up to the block size.

My questions is what i should do ,to continue read from the next block? 

I was trying to get you an answer, but got distracted. I think you are hitting a data type boundary on ofs. What data type is ofs.. does it match  pf_lseek declaration?

 

I'm trying to register for multiple values ??in a sdcard, that's I'm trying  do

 

You are trying to write to the SD card?

Link to post
Share on other sites

Thank you for your help!

 

OFS is DWORD

 

Im only trying to read from a file, each time from diffrent place ( at the same file).

 

size of the file is 2 MB.  so each time im setting the ofs , and calling  pf_lseek( ofs) . but the ofs is limited from 0 to 32768 .

everything working great when 0< ofs <32768  . but when im trying to read more , i got error :(

Link to post
Share on other sites

If you are trying to write to the SD-Card in a log fashion, you need to open the file, seek and write to it.

Energia has an example here.

 

Or from the ElmChan site:

http://elm-chan.org/fsw/ff/pf/write.html

 

File write operation must be done in following sequence.

  1. pf_lseek(ofs); read/write pointer must be moved to sector bundary prior to initiate write operation or it will be rounded-down to the sector boundary.
  2. pf_write(buff, btw, &bw); Initiate write operation. Write first data to the file.
  3. pf_write(buff, btw, &bw); Write next data. Any other file function cannot be used while a write operation is in progress.
  4. pf_write(0, 0, &bw); Finalize the write operation. If read/write pointer is not on the sector boundary, left bytes in the sector will be filled with zero.
Link to post
Share on other sites

http://elm-chan.org/fsw/ff/pf/lseek.html

 

pf_lseek takes a 32 bit offset. This is how you move around. The comment about rounding down to a sector size is because that is how it accesses the data, a sector at a time. You can seek to locations that are multiples of the sector size. To move to an odd offset you must seek to the beginning of the sector and then read and throw out data until you reach the odd offset byte.

 

pf_lseek(1024L); // move to the offset of 1024 bytes in the file.

 

pf_lseek(512UL*1000UL); // move really far into the file.

 

One "feature" people often overlook with the petite file system, you must pre-create and allocate the file to the maximum size you want to use. If you try to seek or write past the end of the pre allocated size, it is going to fail.

 

-rick

Link to post
Share on other sites

1233png.png

 

As i understand , each file saved in the sd-card in a lot of blocks. each block is 32 bit size.( as in the picture)

 

 

so if i will do this: 

 

long x=0;

while(1)

{

 

pf_lseek(X++);

pf_read(Line, sizeof(Line), &s1);

 

 

}

 

i will go over all the file?

 

i tried to do so.. and after i reach the  "111111..11" of the first block, i got error

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...