Using data from the SD card on hardware, important!

Hello all

Just a quick heads-up. I just helped @trelemar to get his little “Pocket Wargame” to load a map from SD and I noticed I had dropped an important function from the library by accident.

So, if you need to read data from a file on hardware call

pokInitSD();

before you try to fileOpen a file. pokInitSD is a low level call that initializes the GPIO needed to read the SD. It can be called many times, but the main thing is it needs to be called at least once before reading the SD card. I will make it automatic in the future library updates, but for the time being you can add it to your code - there is no harm.

Also, be aware of the following PetitFatFS limitations (PetitFatFS is used because its memory footprint is very small):

  1. PetitFatFS can not create files. They need to exist on the SD card
  2. PetitFatFS can not change the file size. So if you need 1mb of data for you game, make a 1mb file on the SD beforehand
  3. PetitFatFS can not rename/delete files

Good news is that @trelemar’s game is now reading the data from the SD card and it looks absolutely yummy. We’re getting the first AAA release on Pokitto soon!

4 Likes

I also encountered that problem with initializing the SD library when I started using it:

Huh, I probably could’ve saved some time if I found your post about it @wuuff. Then again I wasn’t too sure what was going on. Going to invest in a debugger to potentially avoid another headache.

Jonne thanks for the kind words about the project! It’s super motivating. I want to make a game that can be enjoyed for a significant amount of time and fixing this SD card problem lets me easily add more content without taking up memory.

1 Like