Arduino: Is the Serial.print command ("some string text") occupied by SRAM?

I have a rather large Arduino project (in eclipse) that has a lot of debugging messages using the Serial.print commands ("some string texts") so that I can debug along this path.

One thing that I noticed is that I am reaching the limit for how many of them I can have in a project. If I become too much, the program stops in very strange places. That is: often long before my new addition of the print command is completed. A.

My project .hex file is about 20k at the moment. Arduino Uno limits about 30kb right? Therefore, it should not be too big.

So I feel that the actual problem is probably that maybe these sequential commands fill my sram. It is only 2 KB. I use a lot of libraries.

Is the Serial.print command ("some string text") occupying SRAM? Of course, gcc puts these lines in program space? but maybe it is not?

Or is it something else? I have an alternative theory about the existence of the serial.print buffer, and I probably just populate it with too many messages.

+4
source share
4 answers

Yup, the string is saved in RAM by default. Although they are also in flash memory, they are loaded into RAM when Arduino boots.

However, if you are using Arduino version 1.0 or later, you can tell the compiler to read the lines directly from Flash and not load them into RAM using the F() macro:

 Serial.Println(F("This string is read from Flash!")); 

This will save RAM, which is a good thing, since there is much less RAM than Flash. See here for more details: * http://www.arduino.cc/playground/Main/Printf

+11
source

This is not my code, but I find that the solution in: http://www.utopiamechanicus.com/article/low-memory-serial-print/ is very good for debugging. A decent combination of printf, using flash memory and macros, so converting is often as easy as deleting "." from Serial.print ().

I am a complete noob for C ++ and arduino, hope someone finds this useful.

+3
source

Please try marking lines as PROGMEM, which should put them in flash. Arduino does not seem to have Serial.write for PROGMEM, so a copy is required. See http://arduino.cc/en/Reference/PROGMEM (String arrays for more details).

EDIT: http://deans-avr-tutorials.googlecode.com/svn/trunk/Progmem/Output/Progmem.pdf perfectly explains the PROGMEM argument.

+1
source

Yes, it is stored in RAM by default. You can use the @Marty solution.

Alternatively, you can also use the MemoryFree library to track your memory.

0
source

Source: https://habr.com/ru/post/1438749/


All Articles