• AVR Freaks

Helpful ReplyHot!FatFS implementation for PIC32

Page: < 12 Showing page 2 of 2
Author
Andy123
Super Member
  • Total Posts : 571
  • Reward points : 0
  • Joined: 2005/04/25 14:20:54
  • Status: offline
Re:FatFS implementation for PIC32 2013/04/09 16:25:08 (permalink)
5 (1)
Aiden,
replacing LATG with LATGSET / LATGCLR did not help,
but removing call for disk_timerproc() resolved the stability issue I had with 2GB card
Next I put new 8GB card and it works with disk_timerproc() call as well.
I guess my no-name 2GB card was a problem, probably need Timer1/Timer2 preset change.
 
Now I will switcvh to DMA write version from a sister thread - I did not realize that it was there until I saw you bringing it  up
#21
Aiden.Morrison
Super Member
  • Total Posts : 729
  • Reward points : 0
  • Joined: 2005/02/25 11:18:31
  • Location: Canada
  • Status: offline
Re:FatFS implementation for PIC32 2013/05/12 08:11:39 (permalink)
0
 
As a note, I've noticed that eventually there will be a write error when using this software over a long period of time.  I cannot find anything wrong with the code, though I did have a bug in there with the definition of Chip Select using LAT rather than SET/CLR registers.  I thought fixing that would be the end of it, but from time to time I still see a result come back other than FR_OK, which makes me think that SD cards will sometimes refuse a write operation for one reason or another. 
 
Here is how I work around this:
 
 
//Check if a file buffer is full and if so page it out to disk
    if(filebufferwrpage!=filebufferrdpage)
    {
        FOpenRes=f_write(&file1, (const void *)&filebuffers[filebufferrdpage][0], filebuffersize, &numread);
        if(FOpenRes==FR_OK)
        {
            currwrposfile=currwrposfile+filebuffersize;
            filebufferrdpage++;
            if(filebufferrdpage==numfilebufferpages)
            {filebufferrdpage=0;}
        }
        else
        {
            //A write operation has failed.  Close the file, unmount,
            //reinitialize and seek to the former end of the file.
            f_close(&file1);
            f_mount(0,NULL);
            disk_initialize(0);
            f_mount(0,&Fatfs);
            FOpenRes=f_open(&file1, file2name, (BYTE)accessmode); //Do not create new
            f_lseek(&file1, currwrposfile);
 
        }
    }
 

 
This prevents data loss, though in the case of high speed logging (100's of kB/sec) you will need a substantial file buffer to keep up while the SD card is reinitialized.
 
Wish I had a more elegant solution, but hey.
 
P.S.  if the compiler complains about not finding f_lseek, you need to go edit ffconf.h and be sure to set FS_MINIMIZE to 2 or lower.
#22
arunsharma0731@gmail.com
Junior Member
  • Total Posts : 104
  • Reward points : 0
  • Joined: 2011/07/23 20:00:47
  • Location: 0
  • Status: offline
Re:FatFS implementation for PIC32 2013/08/08 19:16:24 (permalink)
0
Hello!!! Everyone
 
Sorry for interruption.
 
I tried your code and got errors while compiling.
spi.h header file not there
osc.h header file not there
system.h header file not there
 
As in new version of MPLABC32 compilers and the peripheral libraries can be accessed by using plib.h
So i replaced those with that, Is it okay now the project is compiling fine.
#23
arunsharma0731@gmail.com
Junior Member
  • Total Posts : 104
  • Reward points : 0
  • Joined: 2011/07/23 20:00:47
  • Location: 0
  • Status: offline
Re:FatFS implementation for PIC32 2013/08/12 01:34:22 (permalink)
0
Hello!! Sir i used your code and modify this to understand the things.
 
I am able to write things in memory card, like creating file and writing something in it.
But i have to append text in this file every time, the file is opened.
 
Here is my Code.

int main (void)
{
    FATFS fs;
    FIL fdst;
    FRESULT res;
    UINT numread;
    DWORD size;

    unsigned char buffer[] = "This is a text file.";
    // Enable optimal performance
    INTEnableSystemMultiVectoredInt();
    SYSTEMConfigPerformance(GetSystemClock());
    mOSCSetPBDIV(OSC_PB_DIV_1);                // Use 1:1 CPU Core:Peripheral clocks

    //Initialize the disk
    disk_initialize(0);

    f_mount(0,&fs);
    res = f_open(&fdst,"file.txt",FA_WRITE | FA_OPEN_ALWAYS | FA_READ);

    size = (&fdst)->fsize;

    res = f_lseek(&fdst,size+1);
   
    res = f_write(&fdst,buffer,21,&numread);

    f_close(&fdst);
    f_mount(0,NULL);
    while(1);
}

 
During first run everything works fine, a file is created and text is written into it.
During second run it must append the same text.
But everything is created into junk values.
Please suggest me something.
#24
arunsharma0731@gmail.com
Junior Member
  • Total Posts : 104
  • Reward points : 0
  • Joined: 2011/07/23 20:00:47
  • Location: 0
  • Status: offline
Re:FatFS implementation for PIC32 2013/08/12 04:41:46 (permalink)
0
And i found a very new problem, write this code.

 int main (void) {     FATFS fs;     FIL fdst;     FRESULT res;     UINT numread;     DWORD size;     unsigned char i = 0;;          unsigned char buffer[] = "This is a text file.";     // Enable optimal performance     INTEnableSystemMultiVectoredInt();     SYSTEMConfigPerformance(GetSystemClock());     mOSCSetPBDIV(OSC_PB_DIV_1);				// Use 1:1 CPU Core:Peripheral clocks      //Initialize the disk     disk_initialize(0);      f_mount(0,&fs);      for(i=0;i<3;i++)     {         res = f_open(&fdst,"james.txt",FA_WRITE | FA_OPEN_ALWAYS);          size = (&fdst)->fsize;          res = f_lseek(&fdst,size);          res = f_write(&fdst,&buffer,21,&numread);          f_close(&fdst);     }      res = f_open(&fdst,"essel.txt",FA_WRITE | FA_OPEN_ALWAYS | FA_READ);     res = f_write(&fdst,&buffer,21,&numread);      f_close(&fdst);     f_mount(0,NULL);     while(1); }

I append code same text three times, in a single run and it works.
In file james.txt the buffer text was written three times.

But when i restart the unit, and then again see the memory card data. all the things are corrupted.

It means that restarting of unit is creating some problem.

If the controller is operating then appending is okay, but after power-off appending is not working.







#25
arunsharma0731@gmail.com
Junior Member
  • Total Posts : 104
  • Reward points : 0
  • Joined: 2011/07/23 20:00:47
  • Location: 0
  • Status: offline
Re:FatFS implementation for PIC32 2013/08/12 06:10:16 (permalink)
0


int main (void)
{
    FATFS fs;
    FIL fdst;
    FRESULT res;
    UINT numread;
    DWORD size;
    unsigned char i = 0;;
   
    unsigned char buffer[] = "This is a text file.";
    // Enable optimal performance
    INTEnableSystemMultiVectoredInt();
    SYSTEMConfigPerformance(GetSystemClock());
    mOSCSetPBDIV(OSC_PB_DIV_1);                // Use 1:1 CPU Core:Peripheral clocks

    //Initialize the disk
    disk_initialize(0);

    f_mount(0,&fs);
    for(i=0;i<3;i++)
    {
        res = f_open(&fdst,"james.txt",FA_WRITE | FA_OPEN_ALWAYS);

        size = (&fdst)->fsize;

        res = f_lseek(&fdst,size);

        res = f_write(&fdst,&buffer,21,&numread);

        f_close(&fdst);
    }

    res = f_open(&fdst,"file.txt",FA_WRITE | FA_OPEN_ALWAYS | FA_READ);
    res = f_write(&fdst,&buffer,21,&numread);

    f_close(&fdst);
    f_mount(0,NULL);
    while(1);
}


#26
Mysil
Super Member
  • Total Posts : 3330
  • Reward points : 0
  • Joined: 2012/07/01 04:19:50
  • Location: Norway
  • Status: offline
Re:FatFS implementation for PIC32 2019/02/01 16:24:29 (permalink)
0
Standalone  FatFs example program for PIC32MZ2048EFG100
 
Have experimented with the FatFs program in this thread, and merged with a tutorial example by Cytron.
FatFs version R0.13c is now used.
For use on PIC32MZ, all dependencies on Plib have been removed.
There are some pieces lifted from Plib, and modified to work without other dependencies.
From the Cytron code, there are some UART routines extracted and put into a separate file.
From the code by Riccardo Leonardi, the millisecond interrupt timer: CoreTimerHandler(),
is also removed from main.c and moved into Ticktimer.c 
together with timer initialization and get_fattime() function. 
 
There is also another time service available, using the hardware RTCC
Rtcc_driver.c   will pick up  __DATE__ and __TIME__  from the operating system when compiled, 
and use this for initial time setting.
 
The board used for testing is a Wi-Fire board from Digilent, with PIC32MZ2048EFG100.
This device do not have a working Secondary crystal Oscillator, and the board have no crystal,
so a Reference Clock divider is used to synthesize 32.768 kHz from the system Primary oscillator signal.
This is routed by PPS to SOSCO pin.
 
Hardware settings for SD card and SPI interface are in: mmc_spi.h
Other hardware dependent definitions are in:  HardwareProfile.h
Configuration bits are moved to separate file:  ConfigBits_MZ.c  or ConfigBits_MX.c
 
With PIC32MZ running with 200 MHz system clock, 100 MHz peripheral clock and
SPIBRG = 1, giving 25 MHz SPI clock frequency,
24 MegaByte test is performed in 22949 millisecond, giving  1070 kByte/s.
 
    Mysil
post edited by Mysil - 2019/02/01 16:46:12
#27
MisterHemi
Senior Member
  • Total Posts : 143
  • Reward points : 0
  • Joined: 2017/11/02 12:24:21
  • Location: Commerce, CA USA
  • Status: offline
Re:FatFS implementation for PIC32 2019/02/01 17:56:46 (permalink)
0
Thank you!
I attempted using another version by Aiden Morrison from his blog but couldn't get it to work right for some reason. I had considered tackling this on my own but it requires a lot of time and work. I'll try yours soon, I already downloaded it.

My configuration:
MacBook Pro (Retina, 15-inch, Mid 2015) with MacOS High Sierra (10.14.5) and MPLAB X IDE v5.20
 
Curiosity PIC32MZ EF, PIC24F Curiosity, XPRESS EVAL BOARD (PIC16F18855), SAMA5D3 Xplained and various custom boards.
#28
wave.jaco
New Member
  • Total Posts : 18
  • Reward points : 0
  • Joined: 2015/07/31 23:05:29
  • Location: South Africa
  • Status: offline
Re:FatFS implementation for PIC32 2019/02/06 22:03:36 (permalink)
0
MisterHemi
Thank you!
I attempted using another version by Aiden Morrison from his blog but couldn't get it to work right for some reason. I had considered tackling this on my own but it requires a lot of time and work. I'll try yours soon, I already downloaded it.


Any update with regards to this?
#29
MisterHemi
Senior Member
  • Total Posts : 143
  • Reward points : 0
  • Joined: 2017/11/02 12:24:21
  • Location: Commerce, CA USA
  • Status: offline
Re:FatFS implementation for PIC32 2019/02/07 07:59:59 (permalink)
0
wave.jaco
MisterHemi
Thank you!
I attempted using another version by Aiden Morrison from his blog but couldn't get it to work right for some reason. I had considered tackling this on my own but it requires a lot of time and work. I'll try yours soon, I already downloaded it.


Any update with regards to this?


I haven't tested it yet as i've been busy debugging a PIC24 board I made and a another board I made.

My configuration:
MacBook Pro (Retina, 15-inch, Mid 2015) with MacOS High Sierra (10.14.5) and MPLAB X IDE v5.20
 
Curiosity PIC32MZ EF, PIC24F Curiosity, XPRESS EVAL BOARD (PIC16F18855), SAMA5D3 Xplained and various custom boards.
#30
karan123
Super Member
  • Total Posts : 833
  • Reward points : 0
  • Joined: 2009/02/02 11:11:21
  • Location: 0
  • Status: offline
Re:FatFS implementation for PIC32 2019/07/09 10:04:47 (permalink)
0
Hi,
 
I am using the code as Posted in Msg#1 for PIC32MX460F512L . With some modifications it works well according to my application up to 32GB SDCard.
But I need to enable long file name (with short file name ) support as FATFS version below:
 
 FatFs - FAT file system module configuration file  R0.09  (C)ChaN, 2011
 
I have tried to change _USE_LFN   1,2 , 3

 
#define _USE_LFN   1          /* 0 to 3 */
#define _MAX_LFN 255 /* Maximum LFN length to handle (12 to 255) */
/* The _USE_LFN option switches the LFN support.
/
/ 0: Disable LFN feature. _MAX_LFN and _LFN_UNICODE have no effect.
/ 1: Enable LFN with static working buffer on the BSS. Always NOT reentrant.
/ 2: Enable LFN with dynamic working buffer on the STACK.
/ 3: Enable LFN with dynamic working buffer on the HEAP.
 

But Got below errors..

 
In function `cmp_lfn':
\fatfs/ff.c:1199: undefined reference to `ff_wtoupper'
\fatfs/ff.c:1200: undefined reference to `ff_wtoupper'
In function `create_name':
\fatfs/ff.c:1655: undefined reference to `ff_convert'
\fatfs/ff.c:1712: undefined reference to `ff_wtoupper'
\fatfs/ff.c:1712: undefined reference to `ff_convert'
ff.o: In function `get_fileinfo':
\fatfs/ff.c:1896: undefined reference to `ff_convert'
 

 
How to enable long file name (and short file name ) support for FATFS   R0.09   ?
 
--
karan123
 
 
post edited by karan123 - 2019/07/09 10:16:17
#31
jg_ee
Super Member
  • Total Posts : 160
  • Reward points : 0
  • Joined: 2015/04/30 10:54:52
  • Location: Colorado
  • Status: offline
Re:FatFS implementation for PIC32 2019/07/09 10:42:10 (permalink)
0
http://elm-chan.org/fsw/ff/doc/config.html#use_lfn
 
You must add ffunicode.c to your project.
#32
karan123
Super Member
  • Total Posts : 833
  • Reward points : 0
  • Joined: 2009/02/02 11:11:21
  • Location: 0
  • Status: offline
Re:FatFS implementation for PIC32 2019/07/09 20:47:48 (permalink)
0
Justin Grantham
http://elm-chan.org/fsw/ff/doc/config.html#use_lfn You must add ffunicode.c to your project.

I have checked ffunicode.c

But this file is not compatible with
FATFS R0.09.
Any other clue
post edited by karan123 - 2019/07/09 21:52:01
#33
karan123
Super Member
  • Total Posts : 833
  • Reward points : 0
  • Joined: 2009/02/02 11:11:21
  • Location: 0
  • Status: offline
Re:FatFS implementation for PIC32 2019/07/10 23:22:19 (permalink)
0
Hi, 


Long File Name Support for FATFS R0.09 is solved from below thread .. https://community.nxp.com/thread/388767 



Thanks


 --Karan
post edited by karan123 - 2019/07/11 03:41:57
#34
MisterHemi
Senior Member
  • Total Posts : 143
  • Reward points : 0
  • Joined: 2017/11/02 12:24:21
  • Location: Commerce, CA USA
  • Status: offline
Re:FatFS implementation for PIC32 2019/07/11 04:51:10 (permalink)
0
wave.jaco
MisterHemi
Thank you!
I attempted using another version by Aiden Morrison from his blog but couldn't get it to work right for some reason. I had considered tackling this on my own but it requires a lot of time and work. I'll try yours soon, I already downloaded it.


Any update with regards to this?




Well so far no luck... i've tried the version posted and tried other versions. It seems to partially work, for example f_mount might work but trying to read a directory or a file causes it to freeze.
 
I'm not sure why and I really need to get it working. Admittedly i've been tempted to write my own though it seems a bit daunting.... but so was USB and I was able to make that work.... 
 
I'm testing it on a Curiosity PIC MZ EF development board.

My configuration:
MacBook Pro (Retina, 15-inch, Mid 2015) with MacOS High Sierra (10.14.5) and MPLAB X IDE v5.20
 
Curiosity PIC32MZ EF, PIC24F Curiosity, XPRESS EVAL BOARD (PIC16F18855), SAMA5D3 Xplained and various custom boards.
#35
karan123
Super Member
  • Total Posts : 833
  • Reward points : 0
  • Joined: 2009/02/02 11:11:21
  • Location: 0
  • Status: offline
Re:FatFS implementation for PIC32 2019/07/13 08:41:16 (permalink)
0
Hi,

Will it possible to interface two (Physical Media) microSD cards by modifying with code as in Msg#1 (FATFS) ?

Any idea....


Karan
post edited by karan123 - 2019/07/13 09:07:29
#36
Page: < 12 Showing page 2 of 2
Jump to:
© 2019 APG vNext Commercial Version 4.5