SD Causing Reset on Diecimila

I'm trying to add an SD card to my project to dump sensor data on my Diecimila board, however, it seems as if the SD library or perhaps my SD reader is causing the board to reset. I presume this is due to being out of memory - if I strip down the commands to practically nothing it can SD.begin() fine but if I add more, like opening a file, it falls over.

After a bit of searching I have found perhaps a sentence or two that seems to indicate I'm correct in my assumptions on the memory being swamped.

So I guess all this rambling boils down to a single question, is this known to anyone?

Causes restarts, barely any serial data makes it over (a few bytes) before it dies:

void setup() {
    Serial.begin(9600);
    setMode(10, OUTPUT);
    if(!SD.begin(10)) {
        Serial.println("FAIL");
        return; 
    }
    char fname[] = "foo.txt"; 
    File f = SD.open(fname, FILE_WRITE);
    f.write("123 ABC");
    f.close();
}

Do you have a 168 or a 328 chip. The 168 doesn't have enough memory. The SD library needs 512 bytes of memory just for the buffer that holds the data to be written to the file. No, you can't change that. It's defined by the write block size of the SD cards.

Dang. I'm using a Diecimila which has a 168 chip.

Dang. I'm using a Diecimila which has a 168 chip.

Which you could replace with a 328 chip.

Is it seriously that simple? Like plug and play?

I've tried instead using the Fat16 library, which seems to be a lot more optimised however it fails to initialise the card still.

]$ cat test_sd.cpp 
#include <Fat16.h>
#include <Fat16util.h>

SdCard card;

extern "C"
void setup() {
    Serial.begin(9600);
    PgmPrint("R: ");
    Serial.println(FreeRam());

    if(!card.init()) {
        PgmPrint("F");
    } else {
        PgmPrint("W");
    }
}

extern "C"
void loop() {}

Output:

R: 816
F

I have double checked all the connections, including with a multimeter - I would say it is wired correctly. I also dumped which SS pin it was using, and it was 10 which is correct for my case. Any thoughts?

Why are there extern "C" statements in your code?

Is it seriously that simple? Like plug and play?

It is.

Why are there extern "C" statements in your code?

Because avr-gcc complains of linkage scheme redefinition for setup() and loop() otherwise.

... But now that you mention it - during my process of figuring out this problem I updated my Arduino library from whatever version is in the default Fedora distribution to rawhide repo and it seems to have been fixed.