Kód: Egész kijelölése
/*
ESP32_S3_PSRAM_activation.ino
forrás: https://forum.arduino.cc/t/esp32-how-to-use-psram-ps-malloc/1055481/2
Board
https://www.cnx-software.com/2022/08/28/7-lolin-s3-esp32-s3-board-ships-with-micropython-firmware/
LOLIN-S3-N16R8
Device Description
IDE Name
Arduino IDE 2.0.2
Operating System
Win10
Flash frequency
QIO 120Mhz adat vonal:4bits
psRam frequency
OIO 120Mhz adat vonal:8bits
Upload speed
921600
Description
IDE params are :
CPU Frequency 240Mhz,
Flash Size : 16mb
psRam Size : 8mb
Partition Scheme : Huge app
Core Debug Level : Nothing
Arduino run on Core 1
Events run on core 1
ESP32 S3 - A PSRAM aktiválása
Sketch
*/
//#include "main.h"
void printPsramSize();
uint32_t i_u32 = 0;
uint16_t n_elements = 1024;
uint16_t *ps_data_all; // pointer a lefoglalt psRam területre
void setup() {
Serial.begin(115200);
Serial.setDebugOutput(true);
//Wire.begin();
Serial.printf("\nStart Example.\n");
ps_data_all = (uint16_t *) ps_malloc (n_elements * sizeof (uint16_t));
if(ps_data_all == NULL){
Serial.printf("Error: ps_data_all=ps_malloc!\n");
} else{
psramInit();
printPsramSize();
}
}
void loop() {
// test ps_data_all
for(uint16_t i = 0; i < n_elements; i++){
ps_data_all[i] = i; // irás
Serial.printf("ps_data_all[%d] : %d \n", i, ps_data_all[i]); // olvasás
}
// a lefoglalt terület
printPsramSize();
// Free the memory
free(ps_data_all);
// teszt:
printPsramSize();
while(1){
}
}
void printPsramSize(){
uint32_t sizePSRAM = ESP.getPsramSize();
Serial.printf("PSRAM init -> size PSRAM : %d Byte\n", sizePSRAM);
uint32_t freePSRAM = ESP.getFreePsram();
Serial.printf("Free PSRAM : %d Byte\n", freePSRAM);
Serial.printf("Foglalt PSRAM : %d Byte\n", sizePSRAM-freePSRAM);
}
mem.Lefoglalás után:
PSRAM init -> size PSRAM : 8386147 Byte
Free PSRAM : 8383839 Byte
Foglalt PSRAM : 2308 Byte
mem.Felszabadítás után
PSRAM init -> size PSRAM : 8386163 Byte
Free PSRAM : 8385903 Byte
Foglalt PSRAM : 260 Byte
A kérdésem: Mért maradt a 260 Byte lefoglalva?