This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

FATFS BMP f_read

Hi All,

I use the TM4C123G sd-demo to complete my project,I want to read bmp photo information through FATFS,a problem is occured:

  char buffer[6000];

  res = f_open(&file,"ceo.bmp", FA_OPEN_ALWAYS | FA_READ);  
  if(res==FR_OK)
  {
    res = f_read(&file, buffer, sizeof(char), &br);

}

when I add the  f_read function to read BMP information, the progrm can not work normally, program will run away after the f_open, I don't know why,

  • It is not clear where buffer is being declared, but the code snippet does not exclude it being in the same function as the open and read. In that case, buffer is on the stack, and that could be the problem. Without the read, buffer isn't used, so it doesn't cause any problem; with the read, the next function call after the buffer allocation causes the program to run away. Solution would be declaring buffer as static or outside the function as a global.

    Also, the third parameter of read is the number of bytes to read. By definition, sizeof(char) is 1, so your read will get at most 1 byte. Probably you want to use sizeof(buffer) instead.