26-10-2018, 16:53
Ale on działa, tylko się zawiesza - to jest dziwne , kod jest przecież dobry - jeszcze sprawdzę zużycie pamięci według kodów "es2".
Ocena wątku:
Zawieszanie wyświetlacza OLED
|
size_t freeRam ()
{
return RAMEND - size_t (__malloc_heap_start);
} // end of freeRam
void setup ()
{
Serial.begin (115200);
Serial.println ();
Serial.print (F("Free memory = "));
Serial.println (freeRam ());
} // end of setup
void loop () { }
/* This function places the current value of the heap and stack pointers in the
* variables. You can call it from any place in your code and save the data for
* outputting or displaying later. This allows you to check at different parts of
* your program flow.
* The stack pointer starts at the top of RAM and grows downwards. The heap pointer
* starts just above the static variables etc. and grows upwards. SP should always
* be larger than HP or you'll be in big trouble! The smaller the gap, the more
* careful you need to be. Julian Gall 6-Feb-2009.
*/
/*
void check_mem() {
//uint8_t * heapptr, * stackptr; // I declared these globally
stackptr = (uint8_t *)malloc(4); // use stackptr temporarily
heapptr = stackptr; // save value of heap pointer
free(stackptr); // free up the memory again (sets stackptr to 0)
stackptr = (uint8_t *)(SP); // save value of stack pointer
}
check_mem(); // heappstr, stackptr have been declared (as uint8_t * heapptr, * stackptr;)
Serial.print(" heapptr: "); Serial.println(*heapptr);
Serial.print("stackptr: "); Serial.println(*stackptr);
Serial.println ((int) heapptr);
*/
Cytat:Znalazłem kiedyś dwa przykłady jak sprawdzić wolny RAM, zapisałem sobie "na kiedyś", na razie nie miałem potrzeby testować. Możesz sobie sprawdzić:kaczakat czy do tych kodów nie należy użyć żadnych bibliotek? Pierwszy kod w zasadzie nie wyświetla mi nic (jeden znak zapytania jedynie). A z drugim jest problem z kompilacją.
(26-10-2018, 16:27)Automatyk231 napisał(a): błąd przy kompilacji : expected initializer before 'NOINIT' (niewiem co on znaczy )
#define NOINIT __attribute__ ((section(".noinit")))
uint8_t * heapptr, * stackptr;
size_t freeRam ()
{
return RAMEND - size_t (__malloc_heap_start);
} // end of freeRam
void setup ()
{
Serial.begin (115200);
Serial.println ();
Serial.print (F("Free memory = "));
Serial.println (freeRam ());
} // end of setup
void loop () {
Serial.print (("Free memory = "));
Serial.println (freeRam ());
check_mem(); // heappstr, stackptr have been declared (as uint8_t * heapptr, * stackptr;)
Serial.print(" heapptr: "); Serial.println((int) heapptr);
Serial.print("stackptr: "); Serial.println((int) stackptr);
Serial.println ((int) stackptr-(int) heapptr);
Serial.println();
Serial.println( jakies_obliczenia(12));
Serial.print(" heapptr: "); Serial.println((int) heapptr);
Serial.print("stackptr: "); Serial.println((int) stackptr);
Serial.println ((int) stackptr- (int) heapptr);
delay(1000);
}
uint32_t jakies_obliczenia(uint32_t sumka)
{
Serial.println(F("Dane ze srodka funkcji"));
Serial.print(F("Free RAM:"));
uint32_t dana1=56, dana2=234234, dana4;
uint32_t cosik=freeRam();
dana4=dana1*dana2+sumka;
check_mem();
dana1=dana4-dana2;
return cosik;
}
/* This function places the current value of the heap and stack pointers in the
* variables. You can call it from any place in your code and save the data for
* outputting or displaying later. This allows you to check at different parts of
* your program flow.
* The stack pointer starts at the top of RAM and grows downwards. The heap pointer
* starts just above the static variables etc. and grows upwards. SP should always
* be larger than HP or you'll be in big trouble! The smaller the gap, the more
* careful you need to be. Julian Gall 6-Feb-2009.
*/
void check_mem() {
//uint8_t * heapptr, * stackptr; // I declared these globally
stackptr = (uint8_t *)malloc(4); // use stackptr temporarily
heapptr = stackptr; // save value of heap pointer
free(stackptr); // free up the memory again (sets stackptr to 0)
stackptr = (uint8_t *)(SP); // save value of stack pointer
}
(28-10-2018, 13:37)es2 napisał(a): Po kompilacji w raporcie jaki jest pokazane zużycie RAM?