スポンサーリンク

ESP 32 – WROVWE – B Gets 4 MB Of Memory

スポンサーリンク

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.
There are these 4 types.
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 ToolsBoards → 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() {
}
Write the program.
When executed, the parameters are displayed on the serial monitor.
Internal Total heap 379064, internal Free Heap 353776
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
The free space of PSRAM is 4194252 bytes:About 4 MB.

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.

In a development environment called ESP-IDF, the himem API seems to allow access to 8 MB of space.

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.

Roseをフォローする
English ver. 電子工作
スポンサーリンク
スポンサーリンク

関連記事

kohacraftのblog

コメント