We purchased ESP 32 - WROVER - B, which preserves the functionality of ESP 32 and has an additional 8 mb of PSRAM (pseudo SRAM).
So I tried to see if I could actually access the memory with the Arduino IDE.
ESP 32 - WROVER Series
ESP 32 - WROVER - B has a silver rectangular package., and on the right is ESP32-DevKitC-VB with ESP32-WROVER-B.
B has a longer package than the normal ESP 32, so it may contain an additional 8 mb of PSRAM.
The package has been changed to a rectangle, but the number of pins is the same, and it works just like a normal ESP 32.
There are other types of ESP 32 - WROVER series.
- ESP 32 - WROVER :Type that operates at 1.8V.
- ESP32-WROVER-I:1.8V with external antenna.
- ESP32-WROVER-B:Type that operates at 3.3V.
- ESP32-WROVER-IB: 3.3V with external antenna.
In addition, there are variations in the amount of flash memory : 4 mb, 8 MB, and 16 MB.
"ESP 32 - DevKitC - VB" with USBInterface has ”ESP 32 - WROVER - B” with 4 MB of flash.
Check PSRAM capacity with Arduino
Adding boards
Before writing a program, set up the board. Select Tools → Boards → ESP 32 Wrover Module.
Check Parameters
This program outputs ESP 32 parameters to serial.
void setup() { Serial.begin(115200); Serial.printf("Internal Total heap %d, internal Free Heap %d\n", ESP.getHeapSize(), ESP.getFreeHeap()); Serial.printf("SPIRam Total heap %d, SPIRam Free Heap %d\n", ESP.getPsramSize(), ESP.getFreePsram()); Serial.printf("Flash Size %d, Flash Speed %d\n", ESP.getFlashChipSize(), ESP.getFlashChipSpeed()); Serial.printf("ChipRevision %d, Cpu Freq %d, SDK Version %s\n", ESP.getChipRevision(), ESP.getCpuFreqMHz(), ESP.getSdkVersion()); } void loop() { }
When executed, the parameters are displayed on the serial monitor.
SPIRam Total heap 4194252, SPIRam Free Heap 4194252
Flash Size 4194304, Flash Speed 80000000
ChipRevision 1, Cpu Freq 240, SDK Version v3.2.3-14-gd3e562907
There is a 8 MB PSRAM, but in fact, only 4 MB of memory space is directly accessible from the CPU, so this is the only memory available on Arduino.
Write check
Then, I will check if I can write correctly by actually reserving the memory space.
To make use of PSRAM memory, use ps _ malloc () or ps _ calloc () to ensure the required memory size.
- Ps _ malloc (bytes) : You can reserve the space you want to use in bytes
- Ps _ calloc (array _ num, type _ num) :Reserves enough space for an array of types, such as an int or double. The array is initialized to 0.
This time we will try to allocate PSRAM memory with calloc.
void setup() { Serial.begin(115200); Serial.printf("Internal Total heap %d, internal Free Heap %d\n", ESP.getHeapSize(), ESP.getFreeHeap()); Serial.printf("SPIRam Total heap %d, SPIRam Free Heap %d\n", ESP.getPsramSize(), ESP.getFreePsram()); Serial.printf("Flash Size %d, Flash Speed %d\n", ESP.getFlashChipSize(), ESP.getFlashChipSpeed()); Serial.printf("ChipRevision %d, Cpu Freq %d, SDK Version %s\n", ESP.getChipRevision(), ESP.getCpuFreqMHz(), ESP.getSdkVersion()); Serial.println(""); //All capacity of SPRAM is secured int memMax = ESP.getFreePsram(); char *p = (char*) ps_calloc( memMax , sizeof(char) ); if (p == NULL) { Serial.println("Unable to allocate memory"); } //Check whether value can be written for each byte int i = 0; while ( i < memMax ) { p[i] = (char)i; //Write value if ( p[i] != (char)i ) //Check if the values match { Serial.printf("write error at %d\n", i); i--; break; } i++; } Serial.printf("%d bytes check Ok\n", i); free(p); //Freeing memory } void loop() { }
An array of type char with ps _ calloc will reserve all free space. It then writes a number to all arrays and checks if the value read is the same as the value written.
Here are the results.
Internal Total heap 378940, internal Free Heap 353652
SPIRam Total heap 4194252, SPIRam Free Heap 4194252
Flash Size 4194304, Flash Speed 80000000
ChipRevision 1, Cpu Freq 240, SDK Version v3.2.3-14-gd3e562907
4194252 bytes check Ok
It was 4192452 bytes OK with 4192452 bytes of free space. This means that the value can be written correctly for approximately 4 MB of memory space.
Since ESP 32 can only hold 100 kB at most, 4 MB is a very large memory space. Now, ESP 32 can handle large data such as images.
コメント