Troubleshooting
Something not working? Make sure your Pokitto’s battery is charged. Some cards can be picky about voltage.
Still not working? Try another card. FAT is brittle.
Available APIs
There are three ways to access the SD card from your code. Each has its pros and cons:
- PokittoDisk
Based on PetitFatFs (PFFS).
Pros: The smallest of the three libs.
Cons: Limited to one file at a time, 8-char filenames only.
#include <Pokitto.h>
void readExample(char *buffer, int length){
pokInitSD();
if(fileOpen("filename", FILE_MODE_READONLY) == 0)
fileReadBytes(buffer, length);
fileClose();
}
- SDFileSystem (SDFS)
Based on FatFs.
Pros: The most feature-complete.
Cons: The slowest, largest of the three. API is problematic. Not available in simulator.
Notes:
- Use of the C
fopen
function results in a memory leak. Use the SDFS directly, like in the example below.
#include <SDFileSystem.h>
...
void readExample(char *buffer, int amount){
auto sdfs = new SDFileSystem(P0_9, P0_8, P0_6, P0_7, "sd", NC, SDFileSystem::SWITCH_NONE, 24000000 );
auto file = sdfs->open("filename", O_RDONLY);
if(file){
file->read(buffer, amount);
file->close();
}
}
- File
Also based on FatFs.
Pros: Faster than the other two. Simple API. Works in simulator, hardware and emulator.
#include <File>
void readExample(char *buffer, int amount){
File file;
if(file.openRO("filename"))
file.read(buffer, amount);
}
You can use the File API together with SDFS by using the following in your My_settings.h:
#define PROJ_SDFS_STREAMING
It will initialize SDFS automatically, just create a File
and use it. Always include File. You shouldn’t include the implementation headers (SIMFile/YAPFSFile/SDFSFile) directly.