Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
239 views
in Technique[技术] by (71.8m points)

Arduino global variable not well calculate?

Here is my arduino ide compilation summary : " Les variables globales utilisent 1684 octets (82%) de mémoire dynamique, ce qui laisse 364 octets pour les variables locales. Le maximum est de 2048 octets. La mémoire disponible faible, des problèmes de stabilité pourraient survenir."

Well, it seems I have too much global variable so I try to reduce that. After analyse my code, I realize I did not have that much global variable. To try, I just erase code inside function and well, I was surprised but the total global variable memory used redure.

How is it possible ?

To illustrate with some code everyone have, if I use ArduinoISP sample, when I compile it, it use 23% of memory

If I just delete code inside avrisp() function, the memory used is 9%

I don't see how it could use that much global memory ...

void avrisp() {
 uint8_t ch = getch();
 switch (ch) {
   case '0': // signon
     error = 0;
     empty_reply();
     break;
   case '1':
     if (getch() == CRC_EOP) {
       SERIAL.print((char) STK_INSYNC);
       SERIAL.print("AVR ISP");
       SERIAL.print((char) STK_OK);
     }
     else {
       error++;
       SERIAL.print((char) STK_NOSYNC);
     }
     break;
   case 'A':
     get_version(getch());
     break;
   case 'B':
     fill(20);
     set_parameters();
     empty_reply();
     break;
   case 'E': // extended parameters - ignore for now
     fill(5);
     empty_reply();
     break;
   case 'P':
     if (!pmode)
       start_pmode();
     empty_reply();
     break;
   case 'U': // set address (word)
     here = getch();
     here += 256 * getch();
     empty_reply();
     break;

   case 0x60: //STK_PROG_FLASH
     getch(); // low addr
     getch(); // high addr
     empty_reply();
     break;
   case 0x61: //STK_PROG_DATA
     getch(); // data
     empty_reply();
     break;

   case 0x64: //STK_PROG_PAGE
     program_page();
     break;

   case 0x74: //STK_READ_PAGE 't'
     read_page();
     break;

   case 'V': //0x56
     universal();
     break;
   case 'Q': //0x51
     error = 0;
     end_pmode();
     empty_reply();
     break;

   case 0x75: //STK_READ_SIGN 'u'
     read_signature();
     break;

   // expecting a command, not CRC_EOP
   // this is how we can get back in sync
   case CRC_EOP:
     error++;
     SERIAL.print((char) STK_NOSYNC);
     break;

   // anything else we will return STK_UNKNOWN
   default:
     error++;
     if (CRC_EOP == getch())
       SERIAL.print((char)STK_UNKNOWN);
     else
       SERIAL.print((char)STK_NOSYNC);
 }
}

if replace by

void avrisp() {}
question from:https://stackoverflow.com/questions/65944475/arduino-global-variable-not-well-calculate

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...