WizNet W5100 and SD Card : Ram & Flash usage

Hi All

I need to run a W5100 shield and SD card simultaneously

With the Ethernet, I would need to run a server, and UDP (but not at the same time)
With the SD Card, its likley I need to run just read/write functions on a fat16 only

Using the standard Arduino libraries, they both seem to gobble quite a fair amount of Flash and Ram when running just the simplest of WebServer and SD readWrite in the same sketch

Does anyone have any tips to smaller libraries, or perhaps something in the libs that can be set to save ram/flash ?

I am really looking for at least 1K available ram and 15K available flash for use in my own application

Thanks ever-so, in advance

Bob

Does anyone have any tips to smaller libraries, or perhaps something in the libs that can be set to save ram/flash ?

I am really looking for at least 1K available ram and 15K available flash for use in my own application

The Ethernet library is usually not a big RAM eater but the SD card library is and this cannot be changed as you have to buffer a complete cell.

As both the free RAM and the available flash depend on the Arduino type you should tell us what you're using.

Post your sketch as there is a good chance that a lot of the used memory is not from the libraries but in that code. If you use libraries that are not part of the IDE post links to them too.

This code runs we and reports the SD card back into the browser, and I have enough ram left for me to play with

But now I am wondering if there is a define somewhere that can change the number of sockets and socket sizes as I am only using a small amount of TX but mostly RX

#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 1, 200);

EthernetServer server(80);
File myFile;

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) { ; } // wait for serial port to connect. Needed for native USB port only

  Ethernet.begin(mac, ip);
  server.begin();
  Serial.print(F("server is at "));
  Serial.println(Ethernet.localIP());
  Serial.println();

  Serial.print(F("Initializing SD card..."));
  if (!SD.begin(4)) {
    Serial.println(F("initialization failed!"));
    return;
  }
  Serial.println(F("initialization done."));
}


void loop() {
  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
    Serial.println(F("new client"));
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
        if (c == '\n' && currentLineIsBlank) {
          client.println(F("HTTP/1.1 200 OK"));
          client.println(F("Content-Type: text/html"));
          client.println(F("Connection: close"));  // the connection will be closed after completion of the response
          client.println();
          client.println(F("<!DOCTYPE HTML>"));
          client.print(F("<html><b>WebServer & SDCard Test</b>

")); 

          myFile = SD.open("test.txt", FILE_WRITE);
          if (myFile) {
            client.print(F("<b>Writing to test.txt : </b>"));
            myFile.println(F("testing 1, 2, 3.
"));
            myFile.close();
            client.print(F("done.
"));
          } else {
            client.println(F("error opening test.txt
"));
          }
        
          myFile = SD.open("test.txt");
          client.print(F("<b>Reading from test.txt :</b>
"));
          if (myFile) {
            while (myFile.available()) {
              client.write(myFile.read());
            }
            myFile.close();
          } else {
            client.print(F("error opening test.txt"));
          }

          client.print(F("</html>"));        
        
          break;
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        } else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);
    // close the connection:
    client.stop();
    Serial.println(F("client disconnected"));
  }
}

The socket memory is on the Wiznet device. Changing that will not affect your SRAM usage.

SurferTim:
The socket memory is on the Wiznet device. Changing that will not affect your SRAM usage.

Thank you Tim, good to know
I think I read somewhere you can adjust the number of sockets and buffer memory split on the wiznet device ?

The number of sockets is fixed: 4 and as far as I know you cannot change the memory layout.

pylon:
The number of sockets is fixed: 4 and as far as I know you cannot change the memory layout.

I found this in w5100.h, not sure if this is something that can be changed
What I would ideally like is more on the RX than on the TX and only 2 sockets

private:
  static const uint8_t  RST = 7; // Reset BIT

  static const int SOCKETS = 4;
  static const uint16_t SMASK = 0x07FF; // Tx buffer MASK
  static const uint16_t RMASK = 0x07FF; // Rx buffer MASK
public:
  static const uint16_t SSIZE = 2048; // Max Tx buffer size
private:
  static const uint16_t RSIZE = 2048; // Max Rx buffer size
  uint16_t SBASE[SOCKETS]; // Tx buffer base address
  uint16_t RBASE[SOCKETS]; // Rx buffer base address

I found this in w5100.h, not sure if this is something that can be changed

No, that's a restriction of the hardware. You can change the library but the hardware is still the same and won't work correctly if you change these values.

thats a shame, I thought the W5100 would be better than that, I can change it in the W5500 and also ENC28J60 device