Varese Italy
Offline
Newbie
Karma: 0
Posts: 8
Hitech Professional Electronic Engineer
|
 |
« on: March 24, 2011, 07:06:54 am » |
Hi at all,
is there someone that know a system to measure, at runtime or compiler time, real avaiable memory.
I ask this because I have a problem when make a Sketch over 8KB (with Arduino UNO and IDE version 0022), after many tests I find that my upper static variable are located, into ram address 1858, and my dynamical variable (a byte inside my function, therefore located in the upper positions of the stack) have a ram address of 2275. Do you remember that Stacks, tipically, work decrementing the ram location pointer from the upper of the avaiable memory (2303). If I calculate difference 2275-1858 I have 417 free ram address before to have a collision of the stack with static variable, but in thi condition if I add a function (extend stack for call the function), or add two "int" inside an existing function, I have a abnormal response at runtime.
To comprove this phenomena, I have ottimizated the code remoning local variable inside variuos existing function, and with this optimization I have extended the Sketch code until 10KB without runtime problems. At this point I have 420 bytes free, too; but now I need to add a small piece of code, calling a new function, and Now it appeare impossible. Note that I have 20KB free of rom but in the reality it is impossible to use.
There is someone that can help me, please? Thanks
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Online
Brattain Member
Karma: 137
Posts: 19052
I don't think you connected the grounds, Dave.
|
 |
« Reply #1 on: March 24, 2011, 08:17:41 am » |
Don't forget that RAM and program memory are completely different. Do you have large constant arrays or tables?
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Varese Italy
Offline
Newbie
Karma: 0
Posts: 8
Hitech Professional Electronic Engineer
|
 |
« Reply #2 on: March 24, 2011, 09:22:57 am » |
Don't forget that RAM and program memory are completely different. Do you have large constant arrays or tables? No, I have only a small constant array (about 40bytes), but I have many constant string for debugging by serial.print. How I saw before the problem appear to be the RAM, not the ROM (flash). Oddly, the problem is appeared after that I wrote more than 8KB of flash program; I suppose than, after this flash size, the compiler manages in different mode the function calls, and this, for some reason that I don't understand, increases memory usage.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Online
Brattain Member
Karma: 137
Posts: 19052
I don't think you connected the grounds, Dave.
|
 |
« Reply #3 on: March 24, 2011, 09:25:20 am » |
but I have many constant string for debugging by serial.print.
The smoking gun.
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Varese Italy
Offline
Newbie
Karma: 0
Posts: 8
Hitech Professional Electronic Engineer
|
 |
« Reply #4 on: March 24, 2011, 09:32:24 am » |
The smoking gun . Please, could you explain?
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Online
Brattain Member
Karma: 137
Posts: 19052
I don't think you connected the grounds, Dave.
|
 |
« Reply #5 on: March 24, 2011, 09:35:12 am » |
I don't know how many print strings you've got (hint) but each one occupies RAM.
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Varese Italy
Offline
Newbie
Karma: 0
Posts: 8
Hitech Professional Electronic Engineer
|
 |
« Reply #6 on: March 24, 2011, 09:40:41 am » |
I don't know how many print strings you've got (hint) but each one occupies RAM. I thought that serial.print used the ROM and not RAM, but probably you are right, this would explain many things. Now I try to write more short messages into serial.print. thanks.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Online
Brattain Member
Karma: 137
Posts: 19052
I don't think you connected the grounds, Dave.
|
 |
« Reply #7 on: March 24, 2011, 09:42:22 am » |
I thought that serial.print used the ROM and not RAM, but probably you are right, Serial.print uses char arrays. That's all it knows about. It can't know if they're in ROM or RAM, so just to be sure, it always puts them in RAM.
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Varese Italy
Offline
Newbie
Karma: 0
Posts: 8
Hitech Professional Electronic Engineer
|
 |
« Reply #8 on: March 24, 2011, 10:23:06 am » |
It can't know if they're in ROM or RAM, so just to be sure, it always puts them in RAM.
AWOL you are right. with this simple function...
DebugMessage(const char *str ){ Serial.print(str); Serial.println((int)str, DEC); }
I have traced the location of the constant string, and they are in low zone of the ram (from address 470 to 1860).
However, I don't understand how it is possible to have problems with some 400byte ram free, leaved from the higher static (1900) to the dynamic lower (2200). Can someone explain? Does anybody know which function, or system, use those ram locations (between 1900 and 2200)?
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Online
Brattain Member
Karma: 137
Posts: 19052
I don't think you connected the grounds, Dave.
|
 |
« Reply #9 on: March 24, 2011, 10:36:57 am » |
Can someone explain? Without seeing your code? No, I seriously doubt it.
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Varese Italy
Offline
Newbie
Karma: 0
Posts: 8
Hitech Professional Electronic Engineer
|
 |
« Reply #10 on: March 24, 2011, 10:41:24 am » |
thank AWOL, Anyway thank you very much, your help was very helpful to me. Now I'm shortening all the messages in order to save a ton of bytes
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Online
Brattain Member
Karma: 137
Posts: 19052
I don't think you connected the grounds, Dave.
|
 |
« Reply #11 on: March 24, 2011, 10:42:30 am » |
You can put strings into PROGMEM, but you need to handle the printing yourself, but it is fairly simple.
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Global Moderator
Dallas
Offline
Shannon Member
Karma: 118
Posts: 10153
|
 |
« Reply #12 on: March 24, 2011, 10:42:47 am » |
Now I'm shortening all the messages in order to save a ton of bytes This will help... http://arduiniana.org/libraries/flash/
|
|
|
|
|
Logged
|
|
|
|
|
Varese Italy
Offline
Newbie
Karma: 0
Posts: 8
Hitech Professional Electronic Engineer
|
 |
« Reply #13 on: March 24, 2011, 11:15:25 am » |
Thank Coding Badly, very usefull.
|
|
|
|
|
Logged
|
|
|
|
|
Varese Italy
Offline
Newbie
Karma: 0
Posts: 8
Hitech Professional Electronic Engineer
|
 |
« Reply #14 on: March 24, 2011, 11:17:43 am » |
You can put strings into PROGMEM, but you need to handle the printing yourself, but it is fairly simple. Please can you post to me some examples, or some link? Thanks
|
|
|
|
|
Logged
|
|
|
|
|
|