FTDI Community

General Category => Discussion - Software => Topic started by: LOstrander on April 22, 2019, 04:27:41 PM

Title: Manipulating SD Files with ESD
Post by: LOstrander on April 22, 2019, 04:27:41 PM
I have been trying to incorporate a couple of functions into my ESD program to read and write a few text files from an SD card.

First I tried using the fopen() functions native to C.  The program compiled and ran, but when I went to check the SD card's contents, the files were nowhere to be found.

Next I tired using the FatF header included in the SD card example in the Ft9XX Toolchain.  I changed the functions over to the FatF commands, and included all of the files required in my ESD project.

For some reason, however, it refuses to recognize the typedefs for the various functions within the header (specifically the DSTATUS and DRESULT types in diskio.h), and claims a few variables/enums were undeclared because of this.

So my question is kind of two-fold:  Is there an easy way to communicate with the SD card on the FT900 through ESD for non-bitmap files, and if it involves the ff.h header, what do I change to make it function?

For reference, I'm using the ME812A WH50R and MM900EV-LITE in ESD 4.5.
Title: Re: Manipulating SD Files with ESD
Post by: FTDI Community on April 23, 2019, 10:20:05 AM
Hello,

The main EVE Sample Application does include a section where it interfaces the SD card, although this only completes a read of data from the card:
Code: [Select]
#ifdef SAMAPP_ENABLE_APIS_SET13
#if defined (ARDUINO_PLATFORM) || defined (FT900_PLATFORM) || defined (FT93X_PLATFORM)
void set13_fontBufferToRAMG(uint8_t *filePath, uint32_t address) {
int chunk_size = 1024;
uint8_t buff[1024];
FIL pFile;
long int curPos = 0;
long int filesz = 0;
UINT bytesread = 0;
FRESULT fResult;

fResult = f_open(&pFile, filePath, FA_READ | FA_OPEN_EXISTING);
if (fResult != FR_OK) {
printf("Cannot open %s, please check SD card, error: %d \n", filePath, fResult);
return;
}
filesz = f_size(&pFile);
printf("Opened %s, file size: %ld\n", filePath, filesz);

while (curPos < filesz) {
bytesread = (filesz - curPos)>chunk_size?chunk_size:(filesz - curPos);

fResult = f_read(&pFile, buff, chunk_size, &bytesread);
if (fResult != FR_OK) {
printf("Error on f_read\n");
return;
}
Gpu_Hal_WrMem(phost, address + curPos, buff, bytesread);
curPos += bytesread;
}
}
#endif

The SD card example from the FT9XX toolchain (section 3.17) is the best SD card interfacing example for the FT9XX:
https://brtchip.com/wp-content/uploads/Support/Documentation/Application_Notes/ICs/MCU/AN-360-FT9xx-Example-Applications.pdf (https://brtchip.com/wp-content/uploads/Support/Documentation/Application_Notes/ICs/MCU/AN-360-FT9xx-Example-Applications.pdf)

What exact errors are being thrown?

ESD 4.5 will look for an SD card to be mounted to your development board, however we don't have any examples of writing non bitmap/font data to this.

Best Regards,
FTDI Community
Title: Re: Manipulating SD Files with ESD
Post by: LOstrander on April 23, 2019, 06:02:49 PM
I seem to have it working now.  It looks like the emulator's C compiler doesn't like me using the ff.h header in anything besides the ESD specific functions, but when I upload the program to my FT900, it works perfectly.