Fat16 - Numerous Minor Bug Fixes and FAT32 Support v4.3
Moderator: Benj
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Fat16 - Numerous Minor Bug Fixes and FAT32 Support v4.3
Hello,
For anyone using the FAT16 component in Flowcode you may have noticed some strange effects when using the component with certain types of cards.
I have been looking into this for a while and have finally discovered that the problem lies with how many sectors make up a disk cluster.
In the C code the number of sectors per cluster is read from the card's disk info section, however the value is not used in the code and instead the value of 32 is assumed.
Eg any cards with 32 sectors (16284 bytes) per cluster will work fine and any cards with a different cluster size will not work correctly causing dissapearing or missing files and FAT corruption etc.
I have recently aquired 3 new SD cards and they all have 64 sectors (32768 bytes) as a minimum per cluster so none of them worked with the current FAT16 component (v4.3).
Working Card - Minimum allocation size 16K Non Working Card - Minimum allocation size 32K Thankfully once I realised the route of the problem the fix was relativly simple.
Attached is an updated component for v4.3 of Flowcode which solves the problems described above by using the sector size value read from the card rather then using the assumed hard coded value.
To update the old FAT16 component simply save the file into your "Flowcode v4/Components" directory and restart Flowcode. You may want to make a backup of the file first just incase you want to go back to it for any reason at a later date.
FAT16 can only have a maximum partition size of 2GB so cards larger then 2GB will have to be formatted into the FAT16 (FAT) format to work correctly with the Flowcode component. The Flowcode component will only be able to access the first valid partition it see's on the card so multi-partition cards larger then 2GB should probably be avoided.
Fingers crossed now all types of SD and MMC cards sized 2GB and under will be fully compatible with the component This should also include the new types of MMC and SD card which are supposed to be supporting the embedded SPI protocol that is currently used on the earlier cards. One small note about this is that while most cards will adopt the standard there are some that have a sector size that is not equal to 512 bytes. Any such cards will cause the Flowcode init macro to return an error code indicating the problem.
Any feedback or comments from anyone using my updated version of the FAT16 component would be appreciated.
Thanks.
For anyone using the FAT16 component in Flowcode you may have noticed some strange effects when using the component with certain types of cards.
I have been looking into this for a while and have finally discovered that the problem lies with how many sectors make up a disk cluster.
In the C code the number of sectors per cluster is read from the card's disk info section, however the value is not used in the code and instead the value of 32 is assumed.
Eg any cards with 32 sectors (16284 bytes) per cluster will work fine and any cards with a different cluster size will not work correctly causing dissapearing or missing files and FAT corruption etc.
I have recently aquired 3 new SD cards and they all have 64 sectors (32768 bytes) as a minimum per cluster so none of them worked with the current FAT16 component (v4.3).
Working Card - Minimum allocation size 16K Non Working Card - Minimum allocation size 32K Thankfully once I realised the route of the problem the fix was relativly simple.
Attached is an updated component for v4.3 of Flowcode which solves the problems described above by using the sector size value read from the card rather then using the assumed hard coded value.
To update the old FAT16 component simply save the file into your "Flowcode v4/Components" directory and restart Flowcode. You may want to make a backup of the file first just incase you want to go back to it for any reason at a later date.
FAT16 can only have a maximum partition size of 2GB so cards larger then 2GB will have to be formatted into the FAT16 (FAT) format to work correctly with the Flowcode component. The Flowcode component will only be able to access the first valid partition it see's on the card so multi-partition cards larger then 2GB should probably be avoided.
Fingers crossed now all types of SD and MMC cards sized 2GB and under will be fully compatible with the component This should also include the new types of MMC and SD card which are supposed to be supporting the embedded SPI protocol that is currently used on the earlier cards. One small note about this is that while most cards will adopt the standard there are some that have a sector size that is not equal to 512 bytes. Any such cards will cause the Flowcode init macro to return an error code indicating the problem.
Any feedback or comments from anyone using my updated version of the FAT16 component would be appreciated.
Thanks.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Fat16 - Dissapearing or Missing Files, Disk corruption
As a side note FAT32 would not be a massive stretch to add to the functionality. This would allow for card partitions much larger then 2GB to work with the component. Would anyone like to see this functionality available as an option within the component?
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: Fat16 - Dissapearing or Missing Files, Disk corruption
Hi Benj,
I have started to use the SD Card quite a lot and would really like to see you implement the 32 bit option, Thus giving more scope to what can be placed on the card.
Regards
JAW
I have started to use the SD Card quite a lot and would really like to see you implement the 32 bit option, Thus giving more scope to what can be placed on the card.
Regards
JAW
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Fat16 - Dissapearing or Missing Files, Disk corruption
Hello again,
FAT32 is nearly working correctly I just have a few minor issues left to iron out and then i'll post up the updated component.
In the mean time I have spotted another minor bug with the FAT16 component where if you are writing to the card using the high speed manual method then the file size sticks at the cluster size and will not increase any further in size.
To fix this problem simply comment out this line in the "Move_To_Next_File_Sector" function.
This causes the file to increase correctly past the limitations of a single file sector.
FAT32 is nearly working correctly I just have a few minor issues left to iron out and then i'll post up the updated component.
In the mean time I have spotted another minor bug with the FAT16 component where if you are writing to the card using the high speed manual method then the file size sticks at the cluster size and will not increase any further in size.
To fix this problem simply comment out this line in the "Move_To_Next_File_Sector" function.
Code: Select all
//mx_file_sector = mx_file_sector + 1; //Increment file sector //BR 06/10 Not Needed - Causes fixed file size of 1 cluster
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Fat16 - Dissapearing or Missing Files, Disk corruption
Hello,
As promised here is the FAT16 / FAT32 capable component code file including the fixes mentioned above.
To enable the FAT32 functionality simply go into the custom code option of the component and find the following line in the Defines function.
Change the number to the FAT type required.
Alternatively you can edit the file directly to hard code the setting.
I'm afraid its one type of FAT or the other at the moment but i'm hoping to take this further and make a combined driver that can detect and make allowances for either standard on the fly.
As promised here is the FAT16 / FAT32 capable component code file including the fixes mentioned above.
To enable the FAT32 functionality simply go into the custom code option of the component and find the following line in the Defines function.
Code: Select all
#define MX_FAT_TYPE 0//%l //0-FAT16(FAT) / 1-FAT32
Alternatively you can edit the file directly to hard code the setting.
I'm afraid its one type of FAT or the other at the moment but i'm hoping to take this further and make a combined driver that can detect and make allowances for either standard on the fly.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Fat16 - Dissapearing or Missing Files, Disk corruption
Hello again,
Right I've finally cracked it!!
Here is a v4 FAT16 component code file that will allow 3 modes of operation.
0 - Minimal memory and ram - FAT16 only
1 - Medium memory and ram - FAT32 only
2 - Maximal memory and ram - FAT16 and FAT32
For mode 2 the type of card is determined automatically every time you run the Init_Card function.
Here is the line in the defines code section that will need to be edited to switch between modes.
Default is currently set to mode 0.
The good news is that the definition modification is the only modification you will have to make. Your existing Flowcode FAT16 program should work flawlessly in any of the modes as long as there is enough memory space to allow for the larger modes.
This file is in beta testing so if anyone wants to try it and see if there are any problems then that would be much appreciated.
Here are the results of compiling a small logging program for an ECIO40
RAM
Mode 0 - RAM available:2048 bytes, used:698 bytes (34.1%), free:1350 bytes (65.9%),
Mode 1 - RAM available:2048 bytes, used:704 bytes (34.4%), free:1344 bytes (65.6%),
Mode 2 - RAM available:2048 bytes, used:727 bytes (35.5%), free:1321 bytes (64.5%),
ROM
Mode 0 - ROM available:22528 bytes, used:9726 bytes (43.2%), free:12802 bytes (56.8%)
Mode 1 - ROM available:22528 bytes, used:11160 bytes (49.6%), free:11368 bytes (50.4%)
Mode 2 - ROM available:22528 bytes, used:11916 bytes (52.9%), free:10612 bytes (47.1%)
Right I've finally cracked it!!
Here is a v4 FAT16 component code file that will allow 3 modes of operation.
0 - Minimal memory and ram - FAT16 only
1 - Medium memory and ram - FAT32 only
2 - Maximal memory and ram - FAT16 and FAT32
For mode 2 the type of card is determined automatically every time you run the Init_Card function.
Here is the line in the defines code section that will need to be edited to switch between modes.
Code: Select all
#define MX_FAT_TYPE 0//%l //0-FAT16(FAT) / 1-FAT32 / 2-FAT16&32
The good news is that the definition modification is the only modification you will have to make. Your existing Flowcode FAT16 program should work flawlessly in any of the modes as long as there is enough memory space to allow for the larger modes.
This file is in beta testing so if anyone wants to try it and see if there are any problems then that would be much appreciated.
Here are the results of compiling a small logging program for an ECIO40
RAM
Mode 0 - RAM available:2048 bytes, used:698 bytes (34.1%), free:1350 bytes (65.9%),
Mode 1 - RAM available:2048 bytes, used:704 bytes (34.4%), free:1344 bytes (65.6%),
Mode 2 - RAM available:2048 bytes, used:727 bytes (35.5%), free:1321 bytes (64.5%),
ROM
Mode 0 - ROM available:22528 bytes, used:9726 bytes (43.2%), free:12802 bytes (56.8%)
Mode 1 - ROM available:22528 bytes, used:11160 bytes (49.6%), free:11368 bytes (50.4%)
Mode 2 - ROM available:22528 bytes, used:11916 bytes (52.9%), free:10612 bytes (47.1%)
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Fat16 - Numerous Minor Bug Fixes and FAT32 Support v4.3
If there is any demand for any of the following functions then let me know and I will try and get them into future revisions of the component.
//char Modify_File_Access_Stats(char Day, char Month, short Year, char Hours, char Minutes, char Seconds)
//char Erase_Disk(void)
//char Format_Disk(void)
//char Rename_File(char* Filename, char* New_Filename){}
//char Move_File(char* Filename, char* New_Folder){}
//char Copy_File(char* Filename, char* New_Filename){}
//char Delete_Current_Folder(){}
//char Create_Folder(char* Folder_Name){}
//char Modify_File_Properties(char properties){}
//char Modify_File_Access_Stats(char Day, char Month, short Year, char Hours, char Minutes, char Seconds)
//char Erase_Disk(void)
//char Format_Disk(void)
//char Rename_File(char* Filename, char* New_Filename){}
//char Move_File(char* Filename, char* New_Folder){}
//char Copy_File(char* Filename, char* New_Filename){}
//char Delete_Current_Folder(){}
//char Create_Folder(char* Folder_Name){}
//char Modify_File_Properties(char properties){}
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: Fat16 - Numerous Minor Bug Fixes and FAT32 Support v4.3
Hi Benj,
I could really use the following :-
//char Erase_Disk(void)
//char Format_Disk(void)
Regards
JAW
I could really use the following :-
//char Erase_Disk(void)
//char Format_Disk(void)
Regards
JAW
Re: Fat16 - Numerous Minor Bug Fixes and FAT32 Support v4.3
//char Copy_File(char* Filename, char* New_Filename){}
//char Create_Folder(char* Folder_Name){}
could also be useful
//char Create_Folder(char* Folder_Name){}
could also be useful
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Fat16 - Numerous Minor Bug Fixes and FAT32 Support v4.3
Great thanks I will try and rattle off these functions when I get time.
Any feedback from using the updated component?
Any feedback from using the updated component?
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: Fat16 - Numerous Minor Bug Fixes and FAT32 Support v4.3
Hi Benj,
I have not had time to test yet but as soon as I do I'll let you know.
Thanks
JAW
I have not had time to test yet but as soon as I do I'll let you know.
Thanks
JAW