FatFs not able to write to the mmc card

Go To Last Post
10 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have downloaded the latest version of the fatfs fsample zip file.

I have added code to use the SPI peripheral, and also make sure the mmc is powered.

Disk initialization goes ok,

Mounting of the volume is working

I can read the directory contents and even open a file and spit its contents to the terminal.

So that does indicate that all communication is working

 

The problem I now have is that I can not write to the mmc card all write commands seem to be crashing, as in the sample system seems to be just stopping to execute code.

when I do a "fo 6 mtst.txt" being open a file with FA_WRITE and FA_CREATE_NEW (file name does not exist when doing a directory read with the fl command) I do get a FR_OK so that indicates that the file has been created.

after this it no longer matters what I do.

I tried a "fw 1 48" so just writing the H to the file ( a fw 1 h does not work is aborted and the cursor returns to the next line with the ready indicator '>' )

I also tried a "fc" to immediately close the file again, effectively creating an empty file, that gives the same result.

the cursor goes to the next line to confirm that it has got the line entered, but the ready indicator never returns.

Also I am not able to put in new commands, like a fl or fo

 

I use a 2Gb mmc card have tried a number of things and I am not in read only mode FF_FS_READONLY = 0

Note that I started with the sample code that was added at the end of the FatFs tutorial and that behaves the same on my board so that was why I went back to the fullblown sample code to see what I could do with the result that I can read but not write to the mmc

 

I hope someone can give a clue on what might be happening.

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Do you own a debugger?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Did you configure your setup to handle writing to files?

 

Can you create new files (e.g. empty file with no writes) ?

 

Is the SD card write-protected?

 

 

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I do not have a debugger unfortunately.

 

to my knowledge having "FF_FS_READONLY = 0" should be enough to be able to write to a file.

I can not do any "write" action. as stated opening a new file and then saving it already is causing the program to stop responding.

 

As far as I am aware a mmc (micro sd card) can not be write protected

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes an SD/MMC can be write protected, they have a little slider on the side. HOWEVER this is only observed if the socket you have has a write protect (WP) sensor and your timer interrupt has the code to sense the state of it. 

 

Of course if you don't have the sensor you have to be pretty sure that the stuff that runs on the 10ms interrupt has a fixed answer to say "always writable". If you have that fixed the wrong way it would explain why no write operations work.

 

When using SD/MMC it's best to always use sockets that have both the Card Present and Write Protect sensors so FatFs can be used "properly"

 

AFAIK microSD do not have a write protect capability except when they are plugged into an SD/MMC carrier.

 

EDIT this picture says it all really...

 

Last Edited: Sun. Apr 15, 2018 - 01:19 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ok, sorry for the confusion, I am using a microsd card in a microsd card slot. So no write protection. Also in the file "mmc_avr_SPI.c" I ahve done :

 

#define MMC_WP            0//Never write protected To be filled    /* Test if write protected. yes:true, no:false, default:false */

 

I just tried with this define at 1 and then you get a nice error saying : rc=10 FR_WRITE_PROTECTED

when I have the define at 0 I get : rc=0 FR_OK

which is what I expect for a file to have been created/opened succesfull.

 

In the mean time I have found another thing that seems interesting:

in the file "diskio.h" there is the following define:
#define _USE_WRITE    1    /* 1: Enable disk_write function */

so there are 2 defines for using read only vs read-write functionality. one in the ff-config file and the other in the diskio file.....

 

I also just noticed that after opening a file to write to the fl function does no longer work too.

I have added the project as I have it now. Hopefully someone can spot the problem.

 

 

 

 

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

little update.

I have been successful in getting code I wrote in 2009 to actually work on the hardware I use.

So I can at least say that the hardware seems to be OK.

But as that code is using FatFs0.07e version the changes are so many and all the renaming that is done just gives me almost nothing identical between the 2 versions of the files so that does not give me a single clue as to what is going wrong :(

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'd consider investing in a JTAG - for my money FAT is something too complex to be debugged with printf()s or flashing LEDs alone. It's fine when it works but when it doesn't you need to follow it into the code to find out what's going on. If it really "locks up" (that is enters a while() loop that never exits) it would be very instructive to know where in ff.c that is.

 

Also this could be indicating a problem in the timeout interrupt - most places where Chan does something that could take a while (and possibly timeout) he uses one of the timer variables that is ticked in the regular interrupt. So if it gets infinitely stuck it may indicate an error in the handling / period of that timer interrupt.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Cliff, I will have a try with just directly spitting data to the uart.

I have no way to connect a jtag interface (did not for see the connections and re-used the connections for other parts (nothing to do with micro sd card so JTAG enable (I have it disabled as that was my first worry) is not in my way.

I am glad I found out that with my antique version of FatFs I could write data to the card and as such verify that my HW is not the problem as I initially was worried it could also be a problem.

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Last night I decided to do a compare of the ffsample project and the official fat013b fatFs download.

they are worlds apart a lot of things are changed from the official download to the sample project (FF.c diskio.c diskio.h).

I had not expected that to be the case or atleast only minimal changes between the two.

 

So for now I think I will stick to the old fat version. I do know the newer version should be better, but getting this all sorted seems to become a real challenge for me and might be going to take a lot of time.