Bootloader API library with SDHC and FAT32

Topics related to the API, programming discussions & questions, coding tips, bugs, etc. should go here.
User avatar
Jubatian
Posts: 1561
Joined: Thu Oct 01, 2015 9:44 pm
Location: Hungary
Contact:

Re: Bootloader API library with SDHC and FAT32

Post by Jubatian »

CunningFellow wrote: Sun Jan 07, 2018 10:39 pmAfter the file is found the only difference between SDHC and SD should be the byte vs sector address in the "read multi" command.
The API has a translation function for that, too. If you want, you may use its built-in SDC_Command function to produce CMD18, at least if you can afford the slower speed (due to CRC calculation) and possibly a retry on it if the command CRC fails (not essential, but no matter what, data could be totally off then). By this method you could safely start your streaming where you need to, then you may switch over to max speed for the streaming itself.
CunningFellow
Posts: 1445
Joined: Mon Feb 11, 2013 8:08 am
Location: Brisbane, Australia

Re: Bootloader API library with SDHC and FAT32

Post by CunningFellow »

Jubatian wrote: Mon Jan 08, 2018 9:38 pm
CunningFellow wrote: Sun Jan 07, 2018 10:39 pmAfter the file is found the only difference between SDHC and SD should be the byte vs sector address in the "read multi" command.
The API has a translation function for that, too. If you want, you may use its built-in SDC_Command function to produce CMD18, at least if you can afford the slower speed (due to CRC calculation) and possibly a retry on it if the command CRC fails (not essential, but no matter what, data could be totally off then). By this method you could safely start your streaming where you need to, then you may switch over to max speed for the streaming itself.
API sounds excellent. T2K wont be able to do that though as it has to take the base address and multiply it by WEB * Rotation * ZOOM to get the frame of the video to show at any one instant.

Totally awesome it hides the SD/SDHC differences for the normal case though.
User avatar
ry755
Posts: 226
Joined: Mon May 22, 2017 6:01 am

Re: Bootloader API library with SDHC and FAT32

Post by ry755 »

Could you possibly add write support to this? I have an idea for a new game but it needs to write to the SD card, and I'd like to use this library if possible.
User avatar
nicksen782
Posts: 714
Joined: Wed Feb 01, 2012 8:23 pm
Location: Detroit, United States
Contact:

Re: Bootloader API library with SDHC and FAT32

Post by nicksen782 »

I managed to get SD Write working:
viewtopic.php?f=5&t=2446&p=18649&hilit=512#p18649

I just ripped the SD writing stuff out of PetitFS. It does work. But, it depends on being able to get to the first sector of the file you specify. It requires sdCardFindFileFirstSector from sDbase (also known as SD Simple.)

Perhaps this may help?
User avatar
ry755
Posts: 226
Joined: Mon May 22, 2017 6:01 am

Re: Bootloader API library with SDHC and FAT32

Post by ry755 »

That might help. But it looks like that can only write a whole sector at a time? Is there some way I could modify that so it can write individual bytes?
(I could be wrong about this, I don't know everything about how SD cards work internally)
CunningFellow
Posts: 1445
Joined: Mon Feb 11, 2013 8:08 am
Location: Brisbane, Australia

Re: Bootloader API library with SDHC and FAT32

Post by CunningFellow »

From the user interface SD cards can only write a sector at a time.

Internally it is worse than this, but the in built controller hides that from you.

If you need to write less than a sector you have no option than to read the 512 bytes into a buffer. Alter the bits you want to write. Then write the whole 512 bytes out.
User avatar
ry755
Posts: 226
Joined: Mon May 22, 2017 6:01 am

Re: Bootloader API library with SDHC and FAT32

Post by ry755 »

Ok, that's fine. One more question: can I use Nicksen's write code and Jubatian's library together, or does it need to be used with PetitFS or SD Simple?
User avatar
nicksen782
Posts: 714
Joined: Wed Feb 01, 2012 8:23 pm
Location: Detroit, United States
Contact:

Re: Bootloader API library with SDHC and FAT32

Post by nicksen782 »

With my code you will still need to queue the sector of the file that you want to read. My code is translated from the write routines in PetitFS. If you can queue the sector of the file then it shouldn't matter if you use the new API for reads.

So, unless Jubatian says otherwise, my code and his code should work independently.
User avatar
Jubatian
Posts: 1561
Joined: Thu Oct 01, 2015 9:44 pm
Location: Hungary
Contact:

Re: Bootloader API library with SDHC and FAT32

Post by Jubatian »

Stop right now! And check this experimental branch out instead:

https://github.com/Jubatian/uzebox/tree/bootlib_write

It adds the two missing interface functions (SDC_Write_Sector() and FS_Write_Sector()) for write access. Now that I see you actually need it and so would most likely test it, I added them. I did basic tests on it, and it seems like it works all right (SDSC and SDHC cards and CUzeBox).

Don't mix up stuff, especially not for write access, it could end up in a disaster for the data sitting on the card. For example if you carelessly used an SDHC since the new bootloader reads it fine: writing to that using a library designed for SDSC will spit out the data nowhere near where you wanted it to go. Except if the library didn't even have CRC and you didn't turn it off either (as then the card would reject it).
User avatar
ry755
Posts: 226
Joined: Mon May 22, 2017 6:01 am

Re: Bootloader API library with SDHC and FAT32

Post by ry755 »

Thanks, I'll try this out!
Post Reply