@Dave If I look at the outcome of the compiler the memory usage seems to be within the limits:
Invoking: ARM GNU Print Size
arm-none-eabi-size --format=berkeley core-firmware.elf
text data bss dec hex filename
91548 3020 12980 107548 1a41c core-firmware.elf
Is there another way to check the memory usage of the firmware?
@nika8991, I just tested the above code in setup() with the LED part commented. It worked fine on my side. What else apart from this code are you trying to run ?
@satishgn, there is more code, it is a statemachine that does a number of steps. In the last step it gets the time from an NTP server and sends a status email.
Before I used the #include “spark_disable_wlan.h” and “spark_disable_cloud.h” the firmware ran successfully but with the start up delay of 4+ seconds. Then I included both include files and first tried to access the WiFi, that went okay (the firmware was able to get the time, send the email and the start up was roughly 1 sec.). After that I added the connection to the Cloud and got the red SOS after successful WiFi access. As @Dave already mentioned it might be a memory problem, but I like to know how to check that.
nika8991, if the linker output you included is correct, then the total statically allocated RAM is 3020+12980 = 16,000 or 0x3E80 which is under the 0x4000 (or so) limit. So to exceed available RAM, your program must be dynamically allocating extra RAM above and beyond the statically allocated RAM. I can review your code privately if you don’t wish to share it if that helps.
You could try running this and seeing if your memory pushes up against the 20k limit.
Also, you might not see it get past like 15k used, 5k free because the background tasks are dynamically allocating and freeing RAM when your application is not running.
@peekay123, it might be the dynamically allocated RAM that causes the problem. I do have a linked list with logging information that will be send in the mail to show all the steps that has been taken.
Thanks for the offer to review my ‘code’ really appriciated, I will PM it to you.
@BDub, I have added to code to the application and commented out the Leds and the delays, see below.
WiFi.on(); // Startup WiFi connection
Serial.print("After WiFi.on(), freeMemory()=");
Serial.println(freeMemory());
do {
//yellowLed->on();
wifiStatus = WiFi.status();
//delay(500);
//yellowLed->off();
//delay(500);
}
while (wifiStatus != WIFI_ON); // Repeat until WiFi is connected
/* Begin problem
* Here the part that causing the problem !!!!
*
*/
Spark.connect(); // Connect to the Spark Cloud
Serial.print("After Spark.connect(),freeMemory()=");
Serial.println(freeMemory());
do {
//yellowLed->on();
cloudStatus = Spark.connected();
// delay(500);
// yellowLed->off();
// delay(500);
}
while (cloudStatus == false); // Repeat until Spark Cloud is connected
Serial.print("After Spark.connected() loop, freeMemory()=");
Serial.println(freeMemory());
/*
* End problem
*/
The result is:
After WiFi.on(), freeMemory()=17460
After Spark.connect(),freeMemory()=17460
It seems that the code doesn’t pass the while (cloudStatus == false); statement.
With these changes I don’t see the red SOS anymore but the RGB led keeps breathing green, I assume indicating connection to the WiFi.
BDub, you’re right on the credentials. One thing to remember is that the wifi related buffers are pre-allocated during the core firmware startup so you won’t see any memory changes with wifi.on and spark.connect. I think any memory problems my be related to the rest of his code and dynamic allocation.
@bufferout, though this is not yet documented (mostly because this will change), you can start your core without wifi or cloud by including one or both of these lines in your application:
#include "spark_disable_wlan.h" //Turn off both wifi and cloud
#include "spark_disable_cloud.h" //Turn off cloud only
Then in your code, you can turn wifi on and off using WiFi.on() and WiFi.off() while you can do the same with the cloud connection using Spark.connect() and Spark.disconnect().