Page 1 of 1

Legacy FAT16 library available for PIC24?

Posted: 12 Nov 2014 16:21
by ISL_Dave
Hi, is there a version of the libstock legacy FAT16 library that works on the PIC24?

I previously used the legacy library over the built in library as I could not do with losing 1/8th of my RAM when the library was updated with a compiler update and I just cannot get the FAT16 library that comes with MikroC PRO for dsPIC working reliably (not a hardware issue as the FAT32 library from libstock works perfectly well).

The char Mmc_Fat_Exists(char *name); built in library function is randomly telling me there is no file present and I sometimes have to call it a couple of times before it tells me the truth. :?

Re: Legacy FAT16 library available for PIC24?

Posted: 13 Nov 2014 16:01
by filip
Hi,

Well, I think there is no legacy lib for the dsPIC, but I will consult my colleagues.

Regards,
Filip.

Re: Legacy FAT16 library available for PIC24?

Posted: 13 Nov 2014 16:59
by ISL_Dave
Thanks, fingers crossed but if I can get round some niggling problems, I could at a push use the new library. It would just mean a small minority of customers that use the larger buffer would have to pay for a hardware upgrade if they wanted to run the newer firmware. :roll:

One of the problems I am stuck on is the Mmc_Fat_Init() function as it is causing the micro to reset when it finds a card is formatted with the exFAT file system. The reset is generated because of a MATHERR interrupt.
Strangely it only does it once, then makes the micro re-boot but the 2nd time, it just returns an error as expected.

The function I have used for a long time simply tries to initialize a FAT32 filesystem and if this fails, it tries to initialize a FAT16 filesystem.

Code: Select all

/*******************************************************************************
SD_Determine_FAT - Find out which FAT we can use if any.
Return: 0 = FAT32  ;  1 = FAT16  ;  2 = Error
*******************************************************************************/
unsigned short Fn_SD_Determine_FAT()
{
  unsigned short res = 2;             //Start with error
  
#ifdef USEFAT32
  if (FAT32_Init()   == 0) res = 0;   //Try to initialize with FAT32 library
  else
#endif
  if (Mmc_Fat_Init() == 0) res = 1;   //Try to initialize with FAT16 lib

  return res;                         //return results
}

Re: Legacy FAT16 library available for PIC24?

Posted: 19 Nov 2014 19:14
by ISL_Dave
I have just created a small standalone code that also tries to initialize FAT32 and then FAT16 if unsuccessful and it performs as expected with no crash. :?

I have juggled the order of the initialization in both my code and the small test code to test for FAT16 and then FAT32 initialization and it does not matter what order they are done in.

So Mmc_Fat_Init() causes a MATHERR interrupt ONLY in my main project when an exFAT card is inserted. :(

Any idea's why calling this function when an exFAT card is present would cause a math error interrupt?

Thanks,
Dave

Re: Legacy FAT16 library available for PIC24?

Posted: 20 Nov 2014 15:55
by filip
Hi,

I really do not know why is this happening, I could investigate the issue if I would have your project.

Regards,
Filip.

Re: Legacy FAT16 library available for PIC24?

Posted: 20 Nov 2014 16:40
by ISL_Dave
Thanks Filip,

I have submitted a project via the helpdesk as this is just one of my problems and it has kind of been overtaken by another which is stopping me even compiling my code most of the time.

As for this issue, I have actually created a separate simple project to see if the Mmc_Fat_Init() library function has an inherent problem and it works as it should :shock: in the small project but when I manage to get my code to compile, it permanently crashes the micro with a MATHERR whenever I try to call the initialization function with an exFAT formatted card inserted.

I have even altered the order it tries to initialize but it is always the FAT16 command that crashes with an exFAT.

As you can see, my modified function (I have tried to reduce the amount of conditional compilation to see if this is complicating things) is so simple, there is no reason it should cause a crash

Code: Select all

/*******************************************************************************
SD_Determine_FAT - Find out which FAT we can use if any.
Return:   0 = Error   ;   1 = FAT16   ;   2 = FAT32
*******************************************************************************/
unsigned short Fn_SD_Determine_FAT()
{
  unsigned short res = 0;               //Start with error
  if (Mmc_Fat_Init()    == 0) res = 1;  //Try to initialize with FAT16 library
  else if (FAT32_Init() == 0) res = 2;  //Try to initialize with FAT32 library
  return res;                           //return results
}
Regards,
Dave