CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Small Fat/SD library

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Lykos1986



Joined: 26 Nov 2005
Posts: 68

View user's profile Send private message

Small Fat/SD library
PostPosted: Tue Apr 23, 2013 11:57 am     Reply with quote

Hello to everyone!

I was playing with a PIC24F32KA304 micro and the ex_mmcsd.c example.

After the changes at the microcontroller definition and the fuses I try to compile the program but it replies back (MpLab with CCS plug in) that there is not enough memory!!! Is this example so memory hungry that can't fit inside a 16bit 32KB micro?

I've try to decrease a little bit the memory blogs and arrays and I manage to compile and create the hex file (by decreasing the examples functionality as well).

Have you got any other fat/sd driver that is more memory efficient but it is doing almost the same job? I just want to access the SD card and to write/delete data from a txt file.
Ttelmah



Joined: 11 Mar 2010
Posts: 19326

View user's profile Send private message

PostPosted: Wed Apr 24, 2013 2:47 am     Reply with quote

I just took the example 'as is', changed the processor to yours, made a couple of fuse changes to give a reasonable clock, and compiled it. 12% ROM used, and 36% RAM used. No problems.
What compiler version?. I used 4.141.
It'll fit comfortably in chips with a lot less ROM/RAM than yours.
Then made it into a MPLAB project, and again it worked.

Best Wishes
Lykos1986



Joined: 26 Nov 2005
Posts: 68

View user's profile Send private message

PostPosted: Wed Apr 24, 2013 3:41 am     Reply with quote

Sorry, sorry...

I was playing with two SD Card/FAT examples the same day and that's why the mistake! The ex_mmcsd.c is running fine! No problem with the size of the memory at all!

The ex_fat.c is not working because MpLab is saying:
*** Error 74 "SD_Fat.c" Line 486(0,1): Not enough RAM for all variables

CCS Version: 4.140
jeremiah



Joined: 20 Jul 2010
Posts: 1321

View user's profile Send private message

PostPosted: Wed Apr 24, 2013 5:33 am     Reply with quote

This is a very specialized chip (good for low power and for waking up from sleep with timer1 without an external oscillator among other things). However, one tradeoff for this particular chip is that it has 2k RAM, which means you will need to take special care of how many variables you create and how/where you create them.

I actually use this chip in a lot of applications. The fact that it is 16 bit and 32k ROM space has no impact on the amount of RAM it has.

My guess is that the fat library uses some large buffers that take up all or most of your RAM. If that is the case, then you need to either modify it to work differently or perhaps target a chip better suited for your application.
Ttelmah



Joined: 11 Mar 2010
Posts: 19326

View user's profile Send private message

PostPosted: Wed Apr 24, 2013 7:33 am     Reply with quote

The code as written, needs just over 1800bytes. Remember as soon as you 'touch' a FAT file system, you need 512bytes for even one sector file, Add the fact that to work the strings have to be 'passed in RAM', and a couple of KB, is needed. The particular problem here is that on the PIC24, RAM is used for the stack. The code will fit on PIC18's with only 2K, but on the PIC24, more RAM is needed for the stack, taking the size required 'up' over the 2K boundary....
It fits merrily on many other 24K chips, but not this one.
The third party library from Brush Electronics, does have an option to minimise the RAM used, basically halving this (but at a speed penalty), and this would fit on the chip, but is not a 'free' library.

Best Wishes
Lykos1986



Joined: 26 Nov 2005
Posts: 68

View user's profile Send private message

PostPosted: Wed Apr 24, 2013 1:56 pm     Reply with quote

Thank you both for your answers! I will try to find another driver with smaller ROM/RAM footprint. I only need to access a txt file and to write/read text inside it. Nothing else fancy about other FAT functions.

By the way jeremiah, do you know any other PIC24 with the same footprint but better ROM/RAM specs that can replace the one I am using? I will do a research at the Microchips website soon but I am asking in case you know anything about it...
jeremiah



Joined: 20 Jul 2010
Posts: 1321

View user's profile Send private message

PostPosted: Wed Apr 24, 2013 2:34 pm     Reply with quote

In terms of pin count, I've personally used the PIC24FJ64GA004, which has 8k RAM. I've not messed with the FAT or mmcsd libraries however. Also note that a lot changes between the chips (no EEPROM, not as low power, no internal timer1 osc that runs in sleep, some peripheral changes, etc.), so you would need to look at what exactly you need from the chip.

I don't think you will find an exact drop in replacement. Even among chips with the same count, some pins are used differently. Some might be "close" though. It would probably require some soldering magic to get it to fully replace.
Lykos1986



Joined: 26 Nov 2005
Posts: 68

View user's profile Send private message

PostPosted: Thu Apr 25, 2013 2:25 am     Reply with quote

Thank you jeremiah and of cource both of you for your help!

I was checking the 24FJ64GA004 datasheet and it needs lot of soldering/hacking in order to fit project but I will find a solution...
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Thu Apr 25, 2013 2:33 am     Reply with quote

Ttelmah wrote:
The third party library from Brush Electronics, does have an option to minimise the RAM used, basically halving this (but at a speed penalty), and this would fit on the chip, but is not a 'free' library.


The savings are even more dramatic if you require multiple files open at the same time however the trade-off is performance as there is a lot of trashing of the SPI bus to read and write buffers.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
Ttelmah



Joined: 11 Mar 2010
Posts: 19326

View user's profile Send private message

PostPosted: Thu Apr 25, 2013 2:59 am     Reply with quote

Let me just add here, a 'satisfied customer' using this.

I had a working program, using the CCS code, but needed to add SD/HC support. Realised that the time needed to do this, was vastly larger than the cost of this library, so bought it.

Felt that the examples could be rather improved, but the core library worked very well, - ran first time, and I've got a PIC now running SD SD/HC, FAT16, or FAT32, all without having to worry, and three buffered serials, USB, another I2C bus, yet using less than 2.6KB of RAM....

Best Wishes
jeremiah



Joined: 20 Jul 2010
Posts: 1321

View user's profile Send private message

PostPosted: Thu Apr 25, 2013 5:40 am     Reply with quote

Lykos1986 wrote:
Thank you jeremiah and of cource both of you for your help!

I was checking the 24FJ64GA004 datasheet and it needs lot of soldering/hacking in order to fit project but I will find a solution...


One thing to note is that a lot of the peripherals for the one I mentioned are on reprogrammable pins. That particular series of chips often has a lot of "reprogrammable pins" (labeled RP0-RPX usually). I don't know if that helps at all in terms of what actually needs to be moved on your layout, but some people don't notice that when just looking at the pin out. Mind you not all peripherals are reprogrammable pins, but a lot of them are. For more info on that, search #pin_select here on the forums.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group