v0.2.3 Firmware RAM Optimizations Shipped!

We’re thrilled to announce that we’ve just deployed new firmware with significant RAM optimizations!

When you flash code through the Web Build IDE, you should be seeing a lot less of that red blinking light saying “I (your spark core) don’t have enough RAM, so I can’t run the wonderful code you’ve written.” now. If you’re compiling locally, you can grab the commit IDs for each of the core firmware repos from the settings drawer on the IDE and configure your build environment accordingly.

Credit for this work goes to @satishgn, @zachary, and many awesome folks in the community who’ve clamored for this, shared war stories, and provided us with useful examples and feedback. Community, thanks for the clamoring! Devs, thanks for the implementing!

This is the first step we’re taking toward making a guarantee to Spark developers that your apps will always have a certain amount of RAM available. We’ll be making a follow up announcement when we know exactly what that number is. The continuous integration setup we’re working on right now will allow us to measure available RAM for every single commit to the core firmware repos so we are sure this doesn’t slip. More RAM is here to stay, you can count on it.

16 Likes

Sweet! I’m going to write something that uses UDPClient, TCPClient, TCPServer, and store a BGP routing table all in RAM! :wink:

I don’t see a SPARK define in this latest (web IDE) firmware :

this works for me:

#if defined(SPARK)
#include "application.h"
#endif

I started a new project (forked blinking led)

And changed the code like this :

#if defined (SPARK)
// Define the pins we're going to call pinMode on
int led = D0;  // You'll need to wire an LED to this one to see it blink.
int led2 = D7; // This one is the built-in tiny one to the right of the USB jack
#endif

That does not compile until I add #define SPARK at the top

I guess it’s probable that the Web IDE has it’s own makefile that didn’t get updated with the SPARK #define. @Dave will know what to do :wink: Thanks for testing this @mhwlng

1 Like

Hmm, I double checked and it looks like the define for SPARK is in the build farm makefile. I also just added that code snippet and compiled it without errors. We did just roll out updates yesterday, so maybe refresh and try verifying again?

Thanks!
David

It does not work for me…

Is there an issue with Amazon not updating regional load balancing servers ? I am based in Europe…

Ok now I’m seeing some really bizarre issue as well. I have this test2.ino app that I like to just throw stuff in and compile from time to time. I’m PRETTY sure I never had liquid-crystal-spi in there, ever. Here’s my code:

#if defined (SPARK)
// Define the pins we're going to call pinMode on
 int led = D0;  // You'll need to wire an LED to this one to see it blink.
 int led2 = D7; // This one is the built-in tiny one to the right of the USB jack
#endif

// This routine runs only once upon reset
void setup() {
  // Initialize D0 + D7 pin as output
  // It's important you do this here, inside the setup() function rather than outside it or in the loop function.
  pinMode(led, OUTPUT);
  pinMode(led2, OUTPUT);
}

// This routine gets called repeatedly, like once every 5-15 milliseconds.
// Spark firmware interleaves background CPU activity associated with WiFi + Cloud activity with your code. 
// Make sure none of your code delays or blocks for too long (like more than 5 seconds), or weird things can happen.
void loop() {
  digitalWrite(led, HIGH);   // Turn ON the LED pins
  digitalWrite(led2, HIGH);
  delay(1000);               // Wait for 1000mS = 1 second
  digitalWrite(led, LOW);    // Turn OFF the LED pins
  digitalWrite(led2, LOW); 
  delay(1000);               // Wait for 1 second in off mode
}

And here’s the error… check out the weirdness.

In file included from ../inc/spark_wiring.h:30:0,
from ../inc/application.h:29,
from /liquid-crystal-spi/liquid-crystal-spi.h:17,
from /liquid-crystal-spi/liquid-crystal-spi.cpp:33:
../../core-common-lib/SPARK_Firmware_Driver/inc/config.h:12:2: warning: #warning "Defaulting to Release Build" [-Wcpp]
#warning "Defaulting to Release Build"
^
In file included from ../inc/spark_wiring.h:37:0,
from ../inc/application.h:29,
from /liquid-crystal-spi/liquid-crystal-spi.h:17,
from /liquid-crystal-spi/liquid-crystal-spi.cpp:33:
../inc/spark_wiring_ipaddress.h: In member function 'IPAddress::operator uint32_t()':
../inc/spark_wiring_ipaddress.h:53:52: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
operator uint32_t() { return *((uint32_t*)_address); };
^
../inc/spark_wiring_ipaddress.h: In member function 'bool IPAddress::operator==(const IPAddress&)':
../inc/spark_wiring_ipaddress.h:54:72: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
bool operator==(const IPAddress& addr) { return (*((uint32_t*)_address)) == (*((uint32_t*)addr._address)); };
^
../inc/spark_wiring_ipaddress.h:54:105: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
bool operator==(const IPAddress& addr) { return (*((uint32_t*)_address)) == (*((uint32_t*)addr._address)); };
^
/test2.cpp: In function 'void setup()':
/test2.cpp:16:11: error: 'led' was not declared in this scope
pinMode(led, OUTPUT); 
^
/test2.cpp:16:16: error: 'OUTPUT' was not declared in this scope
pinMode(led, OUTPUT); 
^
/test2.cpp:16:22: error: 'pinMode' was not declared in this scope
pinMode(led, OUTPUT); 
^
/test2.cpp:17:11: error: 'led2' was not declared in this scope
pinMode(led2, OUTPUT); 
^
/test2.cpp: In function 'void loop()':
/test2.cpp:24:16: error: 'led' was not declared in this scope
digitalWrite(led, HIGH); // Turn ON the LED pins 
^
/test2.cpp:24:21: error: 'HIGH' was not declared in this scope
digitalWrite(led, HIGH); // Turn ON the LED pins 
^
/test2.cpp:24:25: error: 'digitalWrite' was not declared in this scope
digitalWrite(led, HIGH); // Turn ON the LED pins 
^
/test2.cpp:25:16: error: 'led2' was not declared in this scope
digitalWrite(led2, HIGH); 
^
/test2.cpp:26:13: error: 'delay' was not declared in this scope
delay(1000); // Wait for 1000mS = 1 second 
^
/test2.cpp:27:21: error: 'LOW' was not declared in this scope
digitalWrite(led, LOW); // Turn OFF the LED pins 
^
make: *** [/test2.o] Error 1

If you comment out the #if defined (SPARK) and #endif it compiles fine.

The web IDE won’t complain if you just add this code to a blank sketch if you don’t also use the led and led2 variables:

#if defined (SPARK)
// Define the pins we're going to call pinMode on
 int led = D0;  // You'll need to wire an LED to this one to see it blink.
 int led2 = D7; // This one is the built-in tiny one to the right of the USB jack
#endif

As a side note, I’m seeing this warning now in local build and web IDE

../inc/spark_wiring_ipaddress.h: In member function 'IPAddress::operator uint32_t()':
../inc/spark_wiring_ipaddress.h:53:52: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
operator uint32_t() { return *((uint32_t*)_address); };
^
../inc/spark_wiring_ipaddress.h: In member function 'bool IPAddress::operator==(const IPAddress&)':
../inc/spark_wiring_ipaddress.h:54:72: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
bool operator==(const IPAddress& addr) { return (*((uint32_t*)_address)) == (*((uint32_t*)addr._address)); };
^
../inc/spark_wiring_ipaddress.h:54:105: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
bool operator==(const IPAddress& addr) { return (*((uint32_t*)_address)) == (*((uint32_t*)addr._address)); };

From this recent change: https://github.com/spark/core-firmware/pull/219/files Issue?

Okay, that’s super weird. Looking into it!

Thanks,
David

I was getting a bunch of the spark_wiring_ipaddress.h warnings/errors yesterday when I was trying to work on a library that uses TCPClient. I chalked it up to my ineptitude. Now I know I’m a little less inept than I previously thought!

Oh, that said… my Test2.ino app did previously have some TCPClient stuff in it… but I’m sure those specific warnings pop up even if you don’t include anything from the TCPClient Class.

Hello All,

After v.0.2.3 fimware Tcpclient is not reading in my project now. The project code is here

Do you have any idea?

My result ;

millis(): 1200011
connection failed

millis(): 1500016
can not find http reponse body

millis(): 1800017
can not find http reponse body

millis(): 2100020
can not find http reponse body

millis(): 2400021
can not find http reponse body

millis(): 2700024
can not find http reponse body

It seems like it could not hit the url mentioned. Can you try hitting the API using a browser?

as roman using own personel webpage. Apı is working try below link. My code was working yesterday morning. But after lunched v.0.2.3 firmware now not working.

http://roman-mueller.ch/api/weather

One thing that changed was the size of the buffer in TCPClient, you might need to do multiple reads from the client socket into another buffer until you have your whole message? Or you could increase the size of that socket buffer again? I know we wanted to expose that easily in the constructor so it was more flexible.

Thanks,
David

Doesn’t look like much data returned W-[255,255,000][000,100,000]-Temp:21,7°C;Yellow-Condition:BrokenClouds;DarkGreen Probably not the buffer issue.

Well, that would include the response headers and other stuff as well. e.g:

Cache-Control:no-cache
Content-Length:81
Content-Type:text/html; charset=utf-8
Date:Fri, 20 Jun 2014 16:29:13 GMT
Expires:-1
Pragma:no-cache
Server:Microsoft-IIS/7.0
X-AspNet-Version:4.0.30319
X-Powered-By:ASP.NET
X-Powered-By-Plesk:PleskWin

Heh, yeah… kinda forgot about that part! xD

267 + 81 = 348

Reduced from 512 to 128

Looks like we need to update the Docs with a good example of how to buffer data until complete… considering 128 bytes won’t even cover most Response Headers. That would be better than increasing the TCP buffer because most users probably allocate a larger buffer for the HTTP responses anyway.

edit: I updated the Documentation Needs post with this request.

1 Like