Before logging an issue, please update to the latest release of Visual Micro from the Downloads Page.

When Logging a Support Issue in the Forum, please ensure you have also:-

  • Enabled vMicro > Compiler > Show Build Properties
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
  • Click the Reply button and attach as .txt file OR
  • Click here to Email us with the file attached, and a link to your post
Support requests without the output above may be impossible to answer, so please help us to help you
 
Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 8 Replies) Visual Micro code fails while Arduino IDE does not (Read 4560 times)
J.
Newbies
*
Offline


Posts: 4
Joined: Sep 19th, 2018
Visual Micro code fails while Arduino IDE does not
Sep 19th, 2018 at 1:44pm
Print Post  
Below is a sample sketch that demonstrates the issue I'm having with a simple arduino web server using the SdFat library. If I use the Arduino IDE (1.8.5) both the standard and SdFat library work as expected. However, if I use Visual Micro the SdFat version fails while the standard SD version works.

The hardware is a teensy 3.2, micro SD card adaptor, and WIZ850io. We discovered the issue when upgrading from a WIZ820io -- with that hardware everything works, but with the new hardware it does not. Just to be clear with either hardware or library code created with the Arduino IDE works.

I've tried adjusting the compiler optimization level but that has had no effect. I'm at a loss as to what else to try to get this sorted out. 

Code (C++)
Select All
#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");
    }
  }
}
 

  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12187
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Visual Micro code fails while Arduino IDE does not
Reply #1 - Sep 19th, 2018 at 2:25pm
Print Post  
Thanks for the report

is debug on of off?

is "vmicro>compiler>deep search" on or off?

which version of visual micro shows in "tools>extensions and updates"?
  
Back to top
IP Logged
 
J.
Newbies
*
Offline


Posts: 4
Joined: Sep 19th, 2018
Re: Visual Micro code fails while Arduino IDE does not
Reply #2 - Sep 19th, 2018 at 2:34pm
Print Post  
Debug: off (Release mode)
Deep search: on
Visual Micro: 1808.30.4

  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12187
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Visual Micro code fails while Arduino IDE does not
Reply #3 - Sep 19th, 2018 at 2:42pm
Print Post  
I'll have to give it a try. One thing that might or might not help is ensuring the arduino.h gets included before other files. Visual Micro will auto insert the arduino.h #include during .ino build before the first code line. In your case that would be after the #includes in your code.


Code
Select All
int dummy = 0;

#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");
    }
  }
}
  

  
Back to top
IP Logged
 
J.
Newbies
*
Offline


Posts: 4
Joined: Sep 19th, 2018
Re: Visual Micro code fails while Arduino IDE does not
Reply #4 - Sep 19th, 2018 at 3:12pm
Print Post  
I tried that version (with the dummy line) but there was no change.
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12187
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Visual Micro code fails while Arduino IDE does not
Reply #5 - Oct 1st, 2018 at 4:50pm
Print Post  
Please switch on file>preferences>compile verbose in the arduino ide and build then copy the output to a .txt.

Then in visual micro switch on vmicro>compiler>verbose and "show build properties". then build and copy the output to a .txt

Then email both text files to info[at]visualmicro.com along with a link to this thread

Thanks
  
Back to top
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12187
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Visual Micro code fails while Arduino IDE does not
Reply #6 - Oct 1st, 2018 at 4:50pm
Print Post  
Please switch on file>preferences>compile verbose in the arduino ide and build then copy the output to a .txt.

Then in visual micro switch on vmicro>compiler>verbose and "show build properties". then build and copy the output to a .txt

Then email both text files to info[at]visualmicro.com along with a link to this thread

Thanks

ps: also check that you have the same board options selected between the two ide's, such as cpu speed

edit: I found 1 difference when I compiled your code. Visual Micro used the spi library that is installed by the teensy installed into "arduino_ide\hardware\teensy\avr\libraries" but the arduino ide used the spi library in the "arduino_ide\libraries" folder. In my view visual micro is using the correct one because platform specific libraries override all others.

« Last Edit: Oct 1st, 2018 at 5:06pm by Tim@Visual Micro »  
Back to top
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12187
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Visual Micro code fails while Arduino IDE does not
Reply #7 - Oct 2nd, 2018 at 4:36pm
Print Post  
Thanks for the files. I think the issue is as suspected.

You can see in the Visual Micro output that these Teensy specific libraries have been discovered for the teensy board:-

C:/Program%20Files%20(x86)/Arduino/hardware/teensy/avr/libraries/SPI
C:/Program%20Files%20(x86)/Arduino/hardware/teensy/avr/libraries/Ethernet
C:/Program%20Files%20(x86)/Arduino/hardware/teensy/avr/libraries/SD


Yet we can see the Arduino IDE ignores the Teensy libraries and uses the ones installed with the IDE or ones that you have installed in documents\arduino\libraries.

C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SPI
C:\Users\stonecypherv\Documents\Arduino\libraries\Ethernet
C:\Users\stonecypherv\Documents\Arduino\libraries\SdFat\


For now I suggest you delete the Teensy specific libraries in C:/Program%20Files%20(x86)/Arduino/hardware/teensy/avr/libraries then restart Visual Studio

I will write to Paul at Teensy to ask him what he intended for his architecture specific libraries. It doesn't make sense to me to ignore all other libs when we have libs made for the board.


  
Back to top
IP Logged
 
J.
Newbies
*
Offline


Posts: 4
Joined: Sep 19th, 2018
Re: Visual Micro code fails while Arduino IDE does not
Reply #8 - Oct 2nd, 2018 at 5:16pm
Print Post  
The files are on the way. I did check the CPU and speed options and they are the same. Also, I think you are correct about which spi library should be used. It's interesting that the arduino IDE did something different though.

EDIT -- Whoops, I was distracted while posting this and didn't see your reply until afterwards. I had already posted about this issue on the PJRC forum: https://forum.pjrc.com/threads/53789-Lockup-after-WIZ820io-to-WIZ850io I don't believe there is any new information there, but if you are going to contact Paul you may want to be aware of that thread.
« Last Edit: Oct 2nd, 2018 at 5:24pm by J. »  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12187
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Visual Micro code fails while Arduino IDE does not
Reply #9 - Oct 3rd, 2018 at 10:19am
Print Post  
The latest release in the market place should resolve the issue.

In recent builds the platform\architecture folder was given priority but this has been reverted to the following

1) Sketchbook/Libraries
2) Platform/Libraries
3) IDE/Libraries

Visual Micro v1810.3.1
  
Back to top
IP Logged
 
h4nd
Newbies
*
Offline


Posts: 4
Joined: Aug 5th, 2015
Re: Visual Micro code fails while Arduino IDE does not
Reply #10 - Oct 13th, 2018 at 3:56am
Print Post  
I may be having a similar problem. For a temporary work-around, I have copied the core libraries from \libraries\  to my \Arduino\libraries directory, and can continue on for the moment. I needed to do this with the SPI and the EEPROM libraries for my project.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint