FAT32 format function not compiling

General discussion on Libstock website & codes posted on this website.
Post Reply
Author
Message
kenstoc
Posts: 5
Joined: 31 Dec 2012 20:32

FAT32 format function not compiling

#1 Post by kenstoc » 18 Apr 2014 23:24

Hi,
I am running into an issue getting the FAT32_Format to work on the MIkroBasic Compiler for AVR. I downloaded and installed the package fine. I added a #define AVR line to the example code and changed the MMC chip select line in the code. The directory test works fine and creates the directories and text files just fine on a SD card. But when I un-comment the err = FAT32_format("dev0") line, the compiler gives a 411 327 Incompatible types ("complex type" to "simple type") main.mbas error. If I put less than 2 characters in the "dev0" field, I get a 0 360 Unresolved extern 'FAT32_Dev_SectorCount' __Lib_FAT32_lte.c error. All of the tick marks are present in the Library Manager under FAT32. Can someone help me here with what I may be doing wrong?
Thanks,
Ken

Update: I noticed while looking at the _lib_Fat32_Driver_lte.mbas file in the FAT32 Uses directory that the sub function FAT32_Dev_SectorCount is NOT called out in the declarations above the Implements. Is there a reason for this?

dmtulsa
Posts: 114
Joined: 04 Jun 2010 14:08
Location: Tulsa,Ok
Contact:

Re: FAT32 format function not compiling

#2 Post by dmtulsa » 17 Jun 2014 17:04

Did you ever figure this out I'm getting the same error with format, makeDir ect....anything that needs a string passed in the FAT32 lib.

Thanks
Doug
Doug
KD5NWK

User avatar
dejan.odabasic
mikroElektronika team
Posts: 2649
Joined: 30 Apr 2012 14:20

Re: FAT32 format function not compiling

#3 Post by dejan.odabasic » 18 Jun 2014 15:37

Hello,

Please take a look at this modified example.
SD_MMC_Demo.7z
(28.93 KiB) Downloaded 271 times
This is how you can pass string to functions:

Code: Select all

dim drive_name as string[4]
main:
  drive_name = "dev0"
...
  err = FAT32_Init()
  err = FAT32_format(@drive_name)
FAT32 Libray example project will be updated as soon as possible.

Best regards.

dmtulsa
Posts: 114
Joined: 04 Jun 2010 14:08
Location: Tulsa,Ok
Contact:

Re: FAT32 format function not compiling

#4 Post by dmtulsa » 24 Jun 2014 17:14

Still get the same sector error using @device_Name

mbasic pro 6.4.0

Doug
Doug
KD5NWK

ywjn001
Posts: 12
Joined: 02 Apr 2014 08:16

Re: FAT32 format function not compiling

#5 Post by ywjn001 » 18 Aug 2014 11:02

I also met the same problem.

User avatar
dejan.odabasic
mikroElektronika team
Posts: 2649
Joined: 30 Apr 2012 14:20

Re: FAT32 format function not compiling

#6 Post by dejan.odabasic » 19 Aug 2014 11:10

Hello,

Have you tested the attached example project?
Are you able to compile it without problems?

Best regards.

mhicleoid
Posts: 4
Joined: 04 Feb 2013 16:32

Re: FAT32 format function not compiling

#7 Post by mhicleoid » 05 Sep 2014 15:49

Hi

I found the FAT32 Format function disabled as told above (Basic for Arm, latest FAT32 lib), so I reactivated it. It made some problems clear wich I found on this odyssee.

First a big problem on SD Cards:
On a new card I can write as much files and folders I want in every folder or even root.

If I use Format_Fat32, the SD Card looks quite good at first sight, but no more than 126 files and/or directories are allowed on the card (not in folder, on the whole card). Looks like a bug in FAT. This problems occurs in several threads.

If I use Windows formatting, quick or full, the SD card will NOT come back to life, problem stays, so something significant has to be corrupted.

If I use SD Formatter V4.0 from Panasonic/Trendy the SD-Card is restored. This program deletes ALL sectors.

So please check the Format function, I broke the program down to a few lines. Works fine if format is off, is corrupted when formatted before use.

Some corrections to the help file:
If you use Format_FAT32, you have to use a vector instead a string or char variable.
Only Capitals are accepted (This also for MakeDir) or function will not execute

Dim Vol_Name as char[11]
...
Vol_name="ABCDEFGHIJK"
SDerror = FAT32_Format(@Vol_Name)

Best regs

mhicleoid
Posts: 4
Joined: 04 Feb 2013 16:32

Re: FAT32 format function not compiling

#8 Post by mhicleoid » 05 Sep 2014 16:26

Addition to my last Post

On a correct formatted SD card:

If you write more than 1024 Files in Root directory, the SD Card gets corrupted the same way as above.

If you write mor than 1023 Files in a subfolder, the SD Card stays OK but the complete folder content is gone.

Thats a limitation I guess you can live with but it should be told for it does not comply to FAT 32 rules.

Best regs

Frank

mhicleoid
Posts: 4
Joined: 04 Feb 2013 16:32

Re: FAT32 format function not compiling

#9 Post by mhicleoid » 10 Sep 2014 17:53

Hello again

It just took me 2 days to figure out the problem:

I monitored the FAT entries and tried to force the errors:

Format function is working properly, ignore above post, accidently worked this way, the problem ist:
Making a new directory and new files when the 4096byte limit (SD 4Gbyte, 8 Sec/Cluster) is reached.

1.) i.e. Format Disk, Windows or FAT32_Format
You are now able to write 128 root directory entries, program goes on hold on
fhandle = FAT32_Open(@File_Name, FILE_WRITE_F32)
no chance to lookup up for error in fhandle, program stuck
SD Card with Hex editor
FAT table has the correct update and references Cluster 2 (root) to Cluster 131 as next root cluster (128Files Cluster3-130), absolutely correct.
All data from Cluster 2 up is lost and set to 0x00, maybe because of stuck open command, I don't know

2.) i.e. Format Disk, Windows or FAT32_Format
FAT32_makeDir(@DIR_name)
FAT32_ChangeDir(@DIR_name)
You are now able to write 126 directory entries, program goes on hold on
fhandle = FAT32_Open(@File_Name, FILE_WRITE_F32), again no chance to lookup up for error in fhandle, program stuck
SD Card with Hex editor
FAT table has the correct update and references Cluster 3 (New directory) to Cluster 130 as next root cluster (126Files Cluster4-129), absolutely correct.
Root still intact, Sub directory lost it's dot and dotdot entry and all data from Cluster 3 (new Directory) up is lost and set to 0x00

3.) Use SD Formatter from http://www.sdcard.org the SD will be formatted with 64 Secs/cluster.
You will get exactly the same behaviour as above when you reach 1024 Files and / or directories > 32kbyte in one folder entry.

This effect only takes place when you are creating files or directories which exceed the limit of the directory cluster. It looks like you are updating the FAT with reference as it should be but do not use the new sector or maybe use a wrong sector for these two commands, maybe also make_swap, have not tested it until now. Fat is working absolutely fine when writing to files, FAT referencing works, clusters correctly addressed.

It would be great if you can release the FAT32_Format, Makedir, Makeswap and File_write commands as .mbas so we have a chance to look this up and maybe change it.

Thanks

Post Reply

Return to “Libstock Discussion”