• AVR Freaks

FatFS Microchip MMC driver bug

Starting Member
  • Total Posts : 45
  • Reward points : 0
  • Joined: 2006/05/11 20:41:17
  • Location: Vietnam
  • Status: offline
2009/05/15 09:56:31 (permalink)

FatFS Microchip MMC driver bug

There is a serious bug in microchip SD/MMC driver come with PIC32 FATFS library
In function SDBufferReceive, the code to read 1 datablock from SPI is:

if (size) {
      do {
          data.Val = getcSPI();   
          buffer[0] = data.v[3];
          buffer[1] = data.v[2];
          buffer[2] = data.v[1];
          buffer[3] = data.v[0];
          buffer += 4;
      } while (size--);

This cause the do loop execute (size+1) times and will overwrite 4 byte after buffer area.
This may cause the multiple block read command failed because SDBufferReceive may not receive the DATA TOKEN
reply (0xFE) in subsequent calls.

To fix the bug just change to while (--size);

At first, I found the "problem" that I posted here:
I though I have "fixed" it.

But then a new problem came that something has changed my FIL variable when f_read called so that the fs field point to an invalid address, and the MCU throws an exception.

post edited by bien_van_khat - 2009/05/15 10:10:22

1 Reply Related Threads

    Kiwi Mike AZ
    Super Member
    • Total Posts : 2056
    • Reward points : 0
    • Status: offline
    RE: FatFS Microchip MMC driver bug 2009/05/15 14:35:45 (permalink)
    Thanks for the info....
    If you can raise a support ticket at
    That way it will be officially registered and might actually get fixed in the next release as it will be officially in the system.
    Jump to:
    © 2020 APG vNext Commercial Version 4.5