letscontrolit / ESPEasy

Easy MultiSensor device based on ESP8266/ESP32
http://www.espeasy.com
Other
3.22k stars 2.2k forks source link

iRAM usage for plugins using SoftwareSerial #630

Closed TD-er closed 6 years ago

TD-er commented 6 years ago

I noticed that all plugins using SoftwareSerial, use 380 Bytes of iRAM. And since we are almost running out of iRAM (current 32364 of 32768 max), it may make sense to try to keep this down a bit. Current plugins using this:

My first question is, is it correct to assume the Software Serial module does indeed add about 380 Bytes of iRAM usage?

Do all these plugins need their own SoftwareSerial object?

How many of these can be active concurrently?

Does it make sense to add some serial layer class, which can be re-used?

Edit: Hmm, I was just reading into the source code of the SoftwareSerial and it looks like there is this object SoftwareSerial *ObjList[MAX_PIN+1]; is not defined static. I am not entirely sure it should be. But it may lead to either extra use of iRAM, or double counts by the memory analyzer. And also not to mention, a number of entries is not being used because the pins are not usable for serial communications. So adding a simple function to address the indices, may reduce the iRAM usage and save about 150 Bytes for each use of SoftwareSerial.

papperone commented 6 years ago

+1 and probably other plugins use it from the playground (like my _P171_PZEM-004T)

TD-er commented 6 years ago

I created a pull request for this. Hopefully the iRAM usage is now lower. This should be tested thoroughly with >1 software serial plugin.

TD-er commented 6 years ago

Like I mentioned also with the pull request (which is currently still a work in progress), I would rather label this as a 2.1 feature, not 2.0

psy0rz commented 6 years ago

yep needs to go in 2.1.0.

i think some plugins already create the SoftwareSerial object dynamicly, exactly for this reason.

It does indeed use valuable iRAM or IRAM, since its not an apple product :P