Cumulus Firware Compilation

This is the right place to discuss on how to implement hardware vsync, adding a VIA or AY chipset, puting multiple roms, or how to design a new flash expansion card.
Godzil
Squad Leader
Posts: 733
Joined: Sat May 21, 2011 7:21 pm
Location: Between UK and France
Contact:

Re: Cumulus Firware Compilation

Post by Godzil » Fri Jan 30, 2015 4:43 pm

Chema: I recommend you to dump your SD card and analyse the output in a hexeditor.

FAT16 structure are quite well documented, I suspect that the code/your code try to use some value hardcoded when the fat formating is not "reliable" on where things are.

(On a previous project, there were some code that was searching for the first FAT block in a partition to use it, which was absolutely false because due to the way FAT is formated, the FAT sector could be at multiple places, due to this the code was using an invalid FAT sector and was listing file that does not exist.

FS like FAT are generally simple to implement, but it's also really easy to do a simple mistake that broke everything. You should double check your changes, and looking at a dump in a hexeditor generally helps a lot. You could also test the FAT reading code by making a PC application that open the dump file. it may help to debug your code, as I suspect you don't have the tool to debug on the PIC chip

User avatar
Chema
Game master
Posts: 1934
Joined: Tue Jan 17, 2006 10:55 am
Location: Gijón, SPAIN
Contact:

Re: Cumulus Firware Compilation

Post by Chema » Fri Jan 30, 2015 7:25 pm

Indeed, Godzil. You're right about this. And that is what I tried to do. However at some places I still had to hack a bit (could not manage to follow the official ways).

I dumped the card into a file and wrote a test program, there is where I make my tests. However I forgot about trying to read more than one sector :( When I saw it readed the first bytes correctly I thought it as working.

On the good side, I did not break anything in the process and my FAT32 SDHC card still works perfectly...

What puzzles me is why Microsoft formatted cards do not work. There must be some field I am not interpreting correctly. It keeps on saying the card has 6000+ reserved sectors and FAT size is something above 700 bytes... But that is another story. I would be happy if it supported FAT16 SD cards under normal formats and conditions. And in the meantime made sure the problem is in the FAT code. All this will be useful for the future firmware :)

Godzil
Squad Leader
Posts: 733
Joined: Sat May 21, 2011 7:21 pm
Location: Between UK and France
Contact:

Re: Cumulus Firware Compilation

Post by Godzil » Sat Jan 31, 2015 11:51 am

How do you search for the FAT block? it may move, I think the bootblock give an hint on where to search it.

I strongly suspect that the Windows formater and the other one you used does not use the same parameter for formating, or block size and this led to some important structure not beeing at the same place.

Just to try, do a zeroing of your card (write zero everywhere) before trying to format with the windows one, I think that a non quick format will do something similar, but I'm not sure. The reason is that an old FAT block entry could be left, and you may not use the correct one...

User avatar
Chema
Game master
Posts: 1934
Joined: Tue Jan 17, 2006 10:55 am
Location: Gijón, SPAIN
Contact:

Re: Cumulus Firware Compilation

Post by Chema » Mon Feb 02, 2015 11:08 am

Yep Godzil. The FAT driver in Cumulus is really not complete and does not seem to handle all cases, though it seems to try by looking at the code.

I reached a point where my modified FAT code works reading files on an SD card with FAT16 and MBR as well as SDHC FAT32 with MBR cards (using images), but Cumulus fails. Probably I am not replicating the sequence of calls correctly, but I really fear this is not the problem now.

More testing is needed, again trying to follow the sequence of actions and errors, which is something not easy when the code you want to test is the one interfacing with the SD card using the SPI interface. This requires using the cumulus itself and is a bit tedious and time-consuming.

Not sure if I will go further or not. I have learned a lot of things in the process but I am not sure if it is worth the effort, to be honest.

I strongly suggest that for the future Cumulus rewrite firmware we switch to a decent fat driver. Have a look at this:
http://elm-chan.org/fsw/ff/00index_e.html

It is source code which can be adapted to any microcontroller using SPI interface with an SD/MMC card and seems to support well any type of FAT or card.

But it is not a simple patch of the firmware. It needs a lot of code rewrite.

Godzil
Squad Leader
Posts: 733
Joined: Sat May 21, 2011 7:21 pm
Location: Between UK and France
Contact:

Re: Cumulus Firware Compilation

Post by Godzil » Mon Feb 02, 2015 1:10 pm

Chema: Nice find :)

For the current uC the cumulus use the "Petit" version seems more appropriate:

http://elm-chan.org/fsw/ff/00index_p.html

Godzil
Squad Leader
Posts: 733
Joined: Sat May 21, 2011 7:21 pm
Location: Between UK and France
Contact:

Re: Cumulus Firware Compilation

Post by Godzil » Tue Feb 03, 2015 5:43 pm

Chema: you should try to test the Petit version of FatFS, the few needed function to make should already exist in the cumulus in a similar form.

It should work with partitioned and non partitioned SD card (taking only the first one) and FAT16/32 filesystem.
The "disk_initialize" function should just reply if the SD card is inserted or not, it is not to do a format on the SDcard ;)

The read function is made to read part of one or multiple sectors, the "sector" parameter is simply the same as the SD card sector (the 512 block)

If the Petit version work correctly, we may evaluate the need to use the complete version, I'm not sure this is really needed because the only function that could be useful is the file create, but I'm not really certain that this would be a really interesting feature..

What we need is all the 4 commandm read, dir, lseek and write, and we should at least support FAT16 and FAT32.

Tell me if you need help, or you don't have time to test this, you can make a simple layer between currently used fat functions and the Petit FatFS function for managing the FAT so that you won't have too much change to do.

User avatar
Chema
Game master
Posts: 1934
Joined: Tue Jan 17, 2006 10:55 am
Location: Gijón, SPAIN
Contact:

Re: Cumulus Firware Compilation

Post by Chema » Wed Feb 04, 2015 12:09 pm

I saw the Petit version but I am not sure it is easy (or even possible) to adapt it, because I think the firmware expects to be able to keep several files open at the same time (not as the PetitFS version).

I will try to dig in a bit more on this, but to be honest I am not sure if I will have the time and if it is of any interest. After all people are using SDHC cards without problems and it seems there is not a real demand for SD card support anymore.

Godzil
Squad Leader
Posts: 733
Joined: Sat May 21, 2011 7:21 pm
Location: Between UK and France
Contact:

Re: Cumulus Firware Compilation

Post by Godzil » Wed Feb 04, 2015 12:44 pm

Oh! I forgot that we had to support 4 floppy at the same time..

You're right, the Petit version can't fit for the final version unless constantely open/close file :(

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest