Lockup after WIZ820io to WIZ850io

Status
Not open for further replies.

juyanith

New member
Hi all, we seem to have an issue when upgrading to a WIZ850io on an existing project. Everything works with the current hardware (see below), but when we switch to a WIZ850io the teensy locks up on the first web request. I'm not sure where to start. What changes do I need to make to get the 850io to work? The only thing I can dig up in the wizwiki is: "WIZ820io users, to migrate to WIZ850io, need to modify the Firmware." However I don't know what those modifications are. Any help would be appreciated.

Current hardware: teensy 3.2, micro SD card adaptor, and WIZ820io
New hardware: replace WIZ820io with WIZ850io

Software uses the Ethernet library v2.0.0 and the SdFat library v1.0.7. There are other libraries but I think those are the relevant ones. Sorry I can't include the current code and I don't have a sample project that isolates the problem but I'll work on it if need be. The issue seems to be with the web server code as everything else runs until the web request(s) come in. I guess what I'm looking for is confirmation that I should be able to replace the 820io with an 850io and expect it to work. Or, if not, what changes I need to make to get it to work.

Thanks!
 
I guess what I'm looking for is confirmation that I should be able to replace the 820io with an 850io and expect it to work.

Confirmed, Ethernet 2.0.0 auto-detects the chip. No changes are supposed to be made.


Regarding this:

The only thing I can dig up in the wizwiki is: "WIZ820io users, to migrate to WIZ850io, need to modify the Firmware." However I don't know what those modifications are.

If you use the old library published by Wiznet (definitely not Ethernet 2.0.0 - their's says 1.0.0 even though it's fork of someone else's code that isn't 1.0.0), then you do need to edit their code to configure which chip. The place in their code to edit is lines 17-19 in w5100.h.

This "need to modify the Firmware" only applies to Wiznet's library. It does not apply to Ethernet 2.0.0 or any of the Ethernet libraries shipped in older versions of Teensyduino over the last couple years.


Sorry I can't include the current code and I don't have a sample project that isolates the problem but I'll work on it if need be.

Yes, this is needed.
 
Thank you for the confirmation. I'll see if I can get a sketch together that replicates the problem or at least report back what was causing the issue.
 
Here is an update. It took a while to get this simplified because it only seems to happen when I use Visual Micro. Of course I was testing using the Arduino IDE (1.8.5) and I couldn't get it to fail! Below is a sample sketch that demonstrates the issue. Basically if the code is run using the SdFat library the file read seems to get into some sort of loop (at least judging by the results displayed in the web browser). Large sections of the file seem to randomly repeat until (I'm guessing) the teensy locks up.

If I use the Arduino IDE either library works as expected. If I use Visual Micro the SdFat version fails while the standard SD version works as expected. I thought perhaps that Visual Micro was doing some sort of optimization that the SdFat library didn't like but changing those options has not had any effect. I'm rather at a loss as to why this is happening but I guess I'll have to try and work with them to sort it out.

Code:
#define SD_PIN 4
#define RESPONSE_BUF_SIZE 512
#define LINE_MAX 128

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

// Modify this for testing.
//#define USE_SDFAT 
#ifdef USE_SDFAT
  #include <SdFat.h>
#else
  #include <SD.h>
#endif

char response_buf[RESPONSE_BUF_SIZE + 1];
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(10, 2, 1, 33);
EthernetServer http(80);
#ifdef USE_SDFAT
  SdFat SD;
#endif
bool hasSD = false;
String method;
String url;

void setup() {
  pinMode(9, OUTPUT);
  digitalWrite(9, LOW);   // begin reset the WIZ820io   
  pinMode(10, OUTPUT);
  digitalWrite(10, HIGH); // de-select WIZ820io   
  pinMode(4, OUTPUT);
  digitalWrite(4, HIGH);  // de-select the SD Card   
  digitalWrite(9, HIGH);  // end reset pulse

  hasSD = SD.begin(SD_PIN);

  Ethernet.begin(mac, ip);

  http.begin();
  Serial.print("Server is at ");
  Serial.println(Ethernet.localIP());
}

void loop() {
  EthernetClient client = http.available();
  if (client) {
    String method = "";
    String url = "";
    int numRead = 0;

    // First line is request method, url and version
    int readVal;
    while (numRead++ < LINE_MAX) {
      readVal = client.read();
      if (readVal < 0) return; // end of stream
      if (readVal == ' ') break;
      method.append((char)readVal);
    }
    while (numRead++ < LINE_MAX) {
      readVal = client.read();
      if (readVal < 0) return; // end of stream
      if (readVal == ' ') break;
      url.append((char)readVal);
    }

    // Request ends with empty line, so just read until blank line
    char prev = '\0';
    while (true) {
      readVal = client.read();
      if (readVal < 0) return; // end of stream
      if (prev == '\n' && readVal == '\n') break; // emtpy line
      if (readVal != '\r') prev = readVal;
    }

    Serial.print("method = ");
    Serial.println(method);
    Serial.print("url = ");
    Serial.println(url);

    if (method == "GET") {
      String filename = "www" + url;
      if (hasSD && SD.exists(filename.c_str())) {
        client.println("HTTP/1.1 200 OK");
        client.println("Content-Type: text/plain");
        client.println("Connection: close");
        client.println();

#ifdef USE_SDFAT
        SdFile file;
        if (file.open(filename.c_str(), FILE_READ)) {
#else
        File file = SD.open(filename.c_str());
        if (file) {
#endif
          int numRead;
          while ((numRead = file.read(response_buf, RESPONSE_BUF_SIZE)) > 0)
          {
            client.write(response_buf, numRead);
          }
          file.close();
        }
        else {
          client.println("HTTP/1.1 404 NOT FOUND");
          client.println("Content-Type: text/plain");
          client.println("Connection: close");
          client.println();

          Serial.print("Unable to open file: ");
          Serial.println(filename);
        }
      }
      else {
        client.println("HTTP/1.1 404 NOT FOUND");
        client.println("Content-Type: text/plain");
        client.println("Connection: close");
        client.println();

        Serial.print("Unable to access SD or file does not exist: ");
        Serial.println(filename);
      }

      delay(1);
      client.stop();

      Serial.println("Done");
    }
  }
}
 
Let me know if you find a case that fails when using Arduino.

If the problem only happens with Visual Micro but the same code works when used with Arduino, I'm afraid I just can't put any engineering time into an investigation.
 
Status
Not open for further replies.
Back
Top