Frame size needed with FAT16_32 and SD card

  • 1
  • 2
  • 3
  • Page 1 of 3
bgoolsby
 
Avatar
 
Subject:

Frame size needed with FAT16_32 and SD card

 · 
Posted: 22.02.2016 - 22:33  ·  #1
I'm working on a datalogger application that uses an Xmega256A3U and the FAT16_32 driver. I have the SD card on SPI_C and an ADC on SPI_D. How much frame and stack should I define for the FAT16_32 driver? I note that the demo program Xmega_FAT32.pas uses Stacksize = $130 and Framesize = $280. Is $280 really necessary?
mc-electronic
Benutzer
Avatar
Gender: n/a
Location: Sauerland NRW
Posts: 372
Registered: 03 / 2008
Subject:

Re: Frame size needed with FAT16_32 and SD card

 · 
Posted: 23.02.2016 - 12:51  ·  #2
Hello bgoolsby,

hard to say, it depends on the rest of your software. Try to reduce the frame, until your program crashes. That gives you a rough idea, how much is needed. Add a good bit of security by making the frame bigger than the minimum. It is very difficult to judge the required size. If it is too close to the minimum, you may encounter problems when your software grows - and then the frame may not be the first thing on your mind. And the 256A3U has a lot of RAM memory!

Michael
Gunter
Administrator
Avatar
Gender:
Location: Frankfurt Main / Germany
Posts: 1697
Registered: 02 / 2003
Subject:

Re: Frame size needed with FAT16_32 and SD card

 · 
Posted: 23.02.2016 - 13:17  ·  #3
Hi,

Quote by mc-electronic
you may encounter problems when your software grows

the problem is not only the software growth.
If there are circumstances where the program flow leads to deep nestings
(if several things happen moreless simultaneously) the stack/frame increases.

Gunter
miparo
Administrator
Avatar
Gender:
Location: Germany
Age: 58
Posts: 959
Registered: 09 / 2007
Subject:

Re: Frame size needed with FAT16_32 and SD card

 · 
Posted: 23.02.2016 - 13:47  ·  #4
Hello bgoolsby,
try this:
Code

  Writeln(SerOutC0, '');
  Writeln(SerOutC0, ' Uses Stack = ' + IntToStr(StackSize - GETSTACKFREE) + ', Frame = ' + IntToStr(FrameSize - GETFRAMEFREE));


Result from FAT32 Demo is :
Uses Stack = 56, Frame = 175

StackSize = $0050, iData;
FrameSize = $0100, iData;

Is enough for this Prog:


miparo
Merlin
Administrator
Avatar
Gender:
Age: 24
Posts: 1409
Registered: 03 / 2005
Subject:

Re: Frame size needed with FAT16_32 and SD card

 · 
Posted: 23.02.2016 - 16:19  ·  #5
Stack and frame size is a difficult subject - and not really specific to SD cards at all. If you have too much stack/frame the only problem is running out of memory (the compiler will tell you if that happens) - but too little and your program behaves erratically, so definitely better to have too much, particularly during development. As a tip - if you get a problem and you cannot see what it is, try increasing stack/frame (frame is more often the culprit than stack in my experience). If the problem goes away, you know what it was. If it doesn't, put stack and frame back how they were and look somewhere else...It's a bit unscientific, but very easy to do, so worth trying. Be aware that some functions (particularly those that pass strings as parameters) can gobble up frame very quickly.

BTW. don't rely too much on GetStackFree etc. They can only tell you how much was used on this particular run. A different run, with different circumstances, will almost certainly give different answers. They can only be a guide.
bgoolsby
 
Avatar
 
Subject:

Data corruption in SD file

 · 
Posted: 23.02.2016 - 20:58  ·  #6
Continuing with this data logger application - I have a serious bug which I cannot figure out.
As I said before, the device uses an ADC on a SPI port and
writes data to a SD card. The ADC runs at a 1KHz sampling rate and
samples 8 channels. An interrupt procedure is called by timer tick
on TCE0. Time in interrupt procedure is 75us, or 7.5% of CPU time.
The interrupt does an ADC scan and stores the data to a double-
buffer; each buffer holds 2048 samples. The two buffers together use
8KB RAM, leaving 8KB for other stuff. The main program watches for
buffer full, then writes the filled buffer to SD card using
F16_blockwrite.

Some specs:
4-layer PCB with separate analog and digital ground planes.
CPU = Xmega256A3U, 32MHz
SD card on SPI_C. Have tried both FAT16 and FAT16_32 file systems.
ADC = Linear Technology LTC2372, 8-ch, 16-bit, on SPI_D
RTC = NXP PCF2129 on SPI_E
Serport = SerPortF0, 115200 baud, TX buf = 64, RX buf = 20.

My problem is that sometimes the data written to SD is corrupted.
A typical situation is that data is written OK for 20 minutes then
there will be a 5-minute stretch where the data on all channels is
near zero, but not exactly zero - samples are in the range +/-10.
Then after 5 minutes or so, the data recovers and is correct again.

I use a Serout port going to a terminal program on my computer. I
monitor stack and frame usage (with CheckStackValid and CheckFrameValid)
as well as sending the data periodically. The data is always correct,
even during the 5 minutes that it's near zero on the SD.

*SO* - How is it that I can monitor the buffer data on Serout and it
is correct, but when it is written to SD it is not correct?

Is there any way I can debug the lower-level workings of the SD
file system? I admit that a bug in the SD procedures is not likely,
but I can't think of anything else.
Harald_K
 
Avatar
 
Subject:

Re: Frame size needed with FAT16_32 and SD card

 · 
Posted: 23.02.2016 - 23:24  ·  #7
take a look in the produced .asm-file of the AVRCompiler.
it starts with declaration of the registers of the CPU,
followed by all used variables with their adresses in RAM.

at the beginning of the system library (system.reset: is the label), you will find the RAM area for stack and frame.
these areas are both used downwards the adress range.

look which of your variables (those of your program or those of the library functions) are the nearest to the adresses used for stack / frame.

so you can perhaps find out, which variables will be corrupted when stack or frame will leave their areas ...

on the other side, use of the variables may corrupt the out-of-area stack at deep procedure nesting,
or out-of-area usage of the frame might corrupt the stack at low stack usage ...


maybe you simply look at the program informations box of the compiler where you will find the amount of unused RAM after compilation, then increase the stack and frame area for the program until te free RAM is used.
bgoolsby
 
Avatar
 
Subject:

Re: Frame size needed with FAT16_32 and SD card

 · 
Posted: 24.02.2016 - 00:02  ·  #8
Thanks for this suggestion. I'll look at the .asm file.
  • 1
  • 2
  • 3
  • Page 1 of 3
Selected quotes for multi-quoting:   0

Registered users in this topic

Currently no registered users in this section

The statistic shows who was online during the last 5 minutes. Updated every 90 seconds.
MySQL Queries: 14 · Cache Hits: 14   134   148 · Page-Gen-Time: 0.041121s · Memory Usage: 2 MB · GZIP: on · Viewport: SMXL-HiDPI