[ESP32] ESP32의 PSRAM 사용법
이번에는 ESP32의 모듈에있는 PSRAM의 사용법을 작성하고 싶습니다.
JSON이나 대량의 데이터를 WEB나 앱으로부터 수신해, 사용하는 일이 있었습니다.
사용한 모듈
PSRAM은
- ESP32-WROVER-B
- ESP32-WROVER-I
밖에 없기 때문에 확인해보십시오.
PSRAM 설정
예 1
main.inovoid setup() {
// put your setup code here, to run once:
Serial.begin(115200);
//PSRAM Initialisation
if (psramInit()) {
Serial.println("\nThe PSRAM is correctly initialized");
} else {
Serial.println("\nPSRAM does not work");
}
log_d("Total heap: %d", ESP.getHeapSize());
log_d("Free heap: %d", ESP.getFreeHeap());
log_d("Total PSRAM: %d", ESP.getPsramSize());
log_d("Free PSRAM: %d", ESP.getFreePsram());
}
void loop() {
// put your main code here, to run repeatedly:
}
예 1의 결과
16:17:58.266 -> rst:0x10 (RTCWDT_RTC_RESET),boot:0x17 (SPI_FAST_FLASH_BOOT)
16:17:58.266 -> configsip: 0, SPIWP:0xee
16:17:58.266 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
16:17:58.266 -> mode:DIO, clock div:1
16:17:58.266 -> load:0x3fff0030,len:1252
16:17:58.266 -> load:0x40078000,len:12716
16:17:58.266 -> load:0x40080400,len:3068
16:17:58.266 -> entry 0x400805e4
16:17:58.403 ->
16:17:59.264 -> The PSRAM is correctly initialized
16:17:59.264 -> [ 881][D][sketch_apr10a.ino:11] setup(): Total heap: 394571
16:17:59.264 -> [ 882][D][sketch_apr10a.ino:12] setup(): Free heap: 335479
16:17:59.264 -> [ 884][D][sketch_apr10a.ino:13] setup(): Total PSRAM: 4192139
16:17:59.264 -> [ 889][D][sketch_apr10a.ino:14] setup(): Free PSRAM: 4192139
getPsramSize()
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
//PSRAM Initialisation
if (psramInit()) {
Serial.println("\nThe PSRAM is correctly initialized");
} else {
Serial.println("\nPSRAM does not work");
}
log_d("Total heap: %d", ESP.getHeapSize());
log_d("Free heap: %d", ESP.getFreeHeap());
log_d("Total PSRAM: %d", ESP.getPsramSize());
log_d("Free PSRAM: %d", ESP.getFreePsram());
}
void loop() {
// put your main code here, to run repeatedly:
}
16:17:58.266 -> rst:0x10 (RTCWDT_RTC_RESET),boot:0x17 (SPI_FAST_FLASH_BOOT)
16:17:58.266 -> configsip: 0, SPIWP:0xee
16:17:58.266 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
16:17:58.266 -> mode:DIO, clock div:1
16:17:58.266 -> load:0x3fff0030,len:1252
16:17:58.266 -> load:0x40078000,len:12716
16:17:58.266 -> load:0x40080400,len:3068
16:17:58.266 -> entry 0x400805e4
16:17:58.403 ->
16:17:59.264 -> The PSRAM is correctly initialized
16:17:59.264 -> [ 881][D][sketch_apr10a.ino:11] setup(): Total heap: 394571
16:17:59.264 -> [ 882][D][sketch_apr10a.ino:12] setup(): Free heap: 335479
16:17:59.264 -> [ 884][D][sketch_apr10a.ino:13] setup(): Total PSRAM: 4192139
16:17:59.264 -> [ 889][D][sketch_apr10a.ino:14] setup(): Free PSRAM: 4192139
uint32_t EspClass::getPsramSize(void)
{
multi_heap_info_t info;
heap_caps_get_info(&info, MALLOC_CAP_SPIRAM);
return info.total_free_bytes + info.total_allocated_bytes;
}
psramInit()
예 2
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
//PSRAM Initialisation
if (psramInit()) {
Serial.println("\nThe PSRAM is correctly initialized");
} else {
Serial.println("\nPSRAM does not work");
}
log_d("Total heap: %d", ESP.getHeapSize());
log_d("Free heap: %d", ESP.getFreeHeap());
log_d("Total PSRAM: %d", ESP.getPsramSize());
log_d("Free PSRAM: %d", ESP.getFreePsram());
//Create an integer
int *var_int = (int *) ps_malloc(sizeof(int));
*var_int = 42;
log_d("var_int PSRAM: %d", ESP.getPsramSize());
log_d("var_int PSRAM: %d", ESP.getFreePsram());
//Create a float
float *var_float = (float *) ps_malloc(sizeof(float));
*var_float = 42.42;
log_d("var_float PSRAM: %d", ESP.getPsramSize());
log_d("var_float PSRAM: %d", ESP.getFreePsram());
Serial.println((String)"var_int = " + *var_int);
Serial.print("var_float = ");
Serial.println(*var_float);
}
void loop() {
// put your main code here, to run repeatedly:
}
실시예 2의 결과
16:33:16.824 -> The PSRAM is correctly initialized
16:33:16.824 -> [ 881][D][sketch_apr10a.ino:11] setup(): Total heap: 394571
16:33:16.824 -> [ 882][D][sketch_apr10a.ino:12] setup(): Free heap: 335479
16:33:16.824 -> [ 884][D][sketch_apr10a.ino:13] setup(): Total PSRAM: 4192139
16:33:16.824 -> [ 889][D][sketch_apr10a.ino:14] setup(): Free PSRAM: 4192139
16:33:16.824 -> [ 895][D][sketch_apr10a.ino:19] setup(): var_int PSRAM: 4192127
16:33:16.824 -> [ 901][D][sketch_apr10a.ino:20] setup(): var_int PSRAM: 4192123
16:33:16.869 -> [ 907][D][sketch_apr10a.ino:26] setup(): var_float PSRAM: 4192115
16:33:16.869 -> [ 913][D][sketch_apr10a.ino:27] setup(): var_float PSRAM: 4192107
16:33:16.869 -> var_int = 42
16:33:16.869 -> var_float = 42.42
참고
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
//PSRAM Initialisation
if (psramInit()) {
Serial.println("\nThe PSRAM is correctly initialized");
} else {
Serial.println("\nPSRAM does not work");
}
log_d("Total heap: %d", ESP.getHeapSize());
log_d("Free heap: %d", ESP.getFreeHeap());
log_d("Total PSRAM: %d", ESP.getPsramSize());
log_d("Free PSRAM: %d", ESP.getFreePsram());
//Create an integer
int *var_int = (int *) ps_malloc(sizeof(int));
*var_int = 42;
log_d("var_int PSRAM: %d", ESP.getPsramSize());
log_d("var_int PSRAM: %d", ESP.getFreePsram());
//Create a float
float *var_float = (float *) ps_malloc(sizeof(float));
*var_float = 42.42;
log_d("var_float PSRAM: %d", ESP.getPsramSize());
log_d("var_float PSRAM: %d", ESP.getFreePsram());
Serial.println((String)"var_int = " + *var_int);
Serial.print("var_float = ");
Serial.println(*var_float);
}
void loop() {
// put your main code here, to run repeatedly:
}
16:33:16.824 -> The PSRAM is correctly initialized
16:33:16.824 -> [ 881][D][sketch_apr10a.ino:11] setup(): Total heap: 394571
16:33:16.824 -> [ 882][D][sketch_apr10a.ino:12] setup(): Free heap: 335479
16:33:16.824 -> [ 884][D][sketch_apr10a.ino:13] setup(): Total PSRAM: 4192139
16:33:16.824 -> [ 889][D][sketch_apr10a.ino:14] setup(): Free PSRAM: 4192139
16:33:16.824 -> [ 895][D][sketch_apr10a.ino:19] setup(): var_int PSRAM: 4192127
16:33:16.824 -> [ 901][D][sketch_apr10a.ino:20] setup(): var_int PSRAM: 4192123
16:33:16.869 -> [ 907][D][sketch_apr10a.ino:26] setup(): var_float PSRAM: 4192115
16:33:16.869 -> [ 913][D][sketch_apr10a.ino:27] setup(): var_float PSRAM: 4192107
16:33:16.869 -> var_int = 42
16:33:16.869 -> var_float = 42.42
결론
Reference
이 문제에 관하여([ESP32] ESP32의 PSRAM 사용법), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/Dreamwalker/items/01cd216d48b4528c5959텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)