PSRAM error in ESP32-CAM

Hi, I am trying to make a project with an ESP32-CAM using the Arduino ide. The particular microcontroller is this (https://www.amazon.es/TECNOIOT-ESP32-CAM-Bluetooth-Development-Included/dp/B07RT1S35R/ref=sr_1_7?__mk_es_ES=ÅMÅ�% BD% C3% 95% C3% 91 & dchild = 1 & keywords = esp32 + cam & qid = 1611749295 & sr = 8-7). According to the specifications it has psram memory. I configure it in the Arduino IDE as AI-Thinker ESP32-CAM and ESP32 Wrober module. But in none of those settings can I access the PSRAM. When I run these instructions:

psramInit();
  
  Serial.println("\n\n##################################");
  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("ChipRevision %d, Cpu Freq %d, SDK Version %s\n", ESP.getChipRevision(), ESP.getCpuFreqMHz(), ESP.getSdkVersion());
  Serial.printf("Flash Size %d, Flash Speed %d\n", ESP.getFlashChipSize(), ESP.getFlashChipSpeed());
  Serial.println("##################################\n\n");

The output is:

##################################
Internal Total heap 363600, internal Free Heap 338348
SPIRam Total heap 0, SPIRam Free Heap 0
ChipRevision 1, Cpu Freq 240, SDK Version v3.2.3-14-gd3e562907
Flash Size 4194304, Flash Speed 80000000
##################################

I don't know if it is necessary to initialize or configure the memory in some special way to be able to use it. If anyone knows any way to use it I would appreciate the help. Thanks in advance.

1 Like

I used this program to test the various ways to access PSRAM under the Arduino IDE.

The Arduino IDE can ONLY access 4MB of PSRAM, the himem library does not work in the Arduino IDE to toggle bank switching.

#include "esp_system.h" //This inclusion configures the peripherals in the ESP system.
#include "esp32-hal-psram.h"
#include "esp_himem.h"
// #include "esp_spiram.h"
// #include "rom/cache.h"
extern "C"
{
#include <esp_spiram.h>
}
////
const int SerialDataBits = 115200;
////
struct stuTime
{
  int iSeconds = 0;
  int iMinutes = 0;
  int iHours = 0;
};
////
void setup()
{

//  Serial.begin(115200);
//
//  Serial.println("========================================");
//  Serial.printf("PSRAM total size     : %u \n", esp_spiram_get_size());
//  Serial.println("----------------------------------------");
//  Serial.printf("PSRAM first 4MB size : %u \n", ESP.getPsramSize());
//  Serial.printf("PSRAM first 4MB free : %u \n", ESP.getMaxAllocPsram());
//  Serial.printf("PSRAM HI-MEM    size : %u \n", esp_himem_get_phys_size());
//  Serial.printf("PSRAM HI-MEM    free : %u \n", esp_himem_get_free_size());
//  Serial.println("========================================");
//  Serial.printf("Internal RAM  size   : %u \n", ESP.getHeapSize()); 
//  Serial.printf("Internal RAM  free   : %u \n", ESP.getFreeHeap()); 
//  Serial.println("========================================");
//
//  Serial.println("Testing the free memory of PSRAM HI-MEM ...");
//  test_region(esp_himem_get_free_size(), 0xaaaa);
//  Serial.println("Done!");

  ////////////////////////////////////////////////////////////////////////////////
  esp_spiram_init();
  vTaskDelay(1);
//  esp_himem_handle_t mh; //Handle for the address space we're using
//    esp_himem_rangehandle_t rh; //Handle for the actual RAM.
//    esp_himem_alloc( 1024, &mh);
  // Serial.begin( SerialDataBits );
  // psramInit();
  // vTaskDelay(3);
  // esp_spiram_init();
  // vTaskDelay(1);
  //   log_i("Total heap: %u", ESP.getHeapSize());
  //   log_i("Free heap: %u", ESP.getFreeHeap());
  // log_i("Total PSRAM: %u", ESP.getPsramSize());
  // log_i("Free PSRAM: %d", ESP.getFreePsram());
  // log_i("spiram size %u", esp_spiram_get_size());
//  log_i("himem free %u", esp_himem_get_free_size());
//  log_i("himem phys %u", esp_himem_get_phys_size());
//  log_i("himem reserved %u", esp_himem_reserved_area_size());
  //
  //   int *ptr, *ptr1;
  //   int n, n1, i, sum = 0;
  //   float *ptrFloat;
  //   // Get the number of elements for the array
  //   n = 10;
  //   n1 = 20;
  //   log_i("Number of elements ptr: %d", n);
  //   log_i("Number of elements ptr1: %d", n1);
  //   log_i("Number of elements ptr1: %d\n", n1);
  //   // Dynamically allocate memory using malloc()
  //   // ptr = (int*)ps_malloc(n * sizeof(int)); //works
  //   ptr = (int*)ps_calloc( n, sizeof(int) ); // works
  //   log_i("Free PSRAM: %d", ESP.getFreePsram());
  //   ptr1 = (int*)ps_calloc( n1, sizeof(int) ); // works
  //   log_i("Free PSRAM: %d", ESP.getFreePsram());
  //    // Check if the memory has been successfully
  //    // allocated in ps_ram
  //    ptrFloat = (float*)ps_calloc( n, sizeof(float) ); // works
  //    if (ptr == NULL) {
  //      log_i(" ptr memory not allocated.\n");
  //      exit(0);
  //    }
  //    if (ptr1 == NULL)
  //    {
  //      log_i("ptr1 memory not allocated.\n");
  //      exit(0);
  //    }
  //    else
  //    {
  //       // Memory has been successfully allocated
  //      // log_i("ps_ram memory successfully allocated using ps_calloc.");
  //      // put elements into ps_ram array
  //      for (i = 0; i < n; ++i)
  //      {
  //        ptr[i] = i + 1;
  //      }
  //      for (i = 0; i < n1; ++i)
  //      {
  //        ptr1[i] = i + 2;
  //      }
  //      for (i = 0; i < n; ++i)
  //      {
  //        ptrFloat[i] = (float)i + 1.06555f;
  //      }
  //      // Print the elements of the array
  //      log_i("The elements of the ptr array are: ");
  //      for (i = 0; i < n; ++i) {
  //        log_i("%d, ", ptr[i]);
  //      }
  //      log_i("The elements of the ptr1 array are: ");
  //      for (i = 0; i < n1; ++i) {
  //        log_i("%d, ", ptr1[i]);
  //      }
  //      log_i("The elements of the ptrFloat array are: ");
  //      for (i = 0; i < n1; ++i) {
  //        log_i("%f, ", ptrFloat[i]);
  //      }
  //    }
  //    //
  //    // put a structure into psram. Works.
  //    struct stuTime *ptrStuTime;
  //    log_i("size of structure: %d", sizeof(struct stuTime) );
  //     //
  //    ptrStuTime = (struct stuTime *)ps_malloc(sizeof(struct stuTime));
  //    log_i("Free PSRAM after structure: %d", ESP.getFreePsram());
  //    ptrStuTime->iSeconds = 10;
  //    ptrStuTime->iMinutes = 60;
  //    ptrStuTime->iHours = 100;
  //    log_i("Seconds: %d Minutes: %d Hours: %d", ptrStuTime->iSeconds, ptrStuTime->iMinutes, ptrStuTime->iHours );
  //    free(ptr);
  // free(ptr1);
  //    free(ptrStuTime);
  //    // works
  //    log_i("Free PSRAM before String: %d", ESP.getFreePsram());
  //    char *str;
  //    char OneChar = 'a';
  //    char TwoChar = 'b';
  //    char ThreeChar = 'c';
  //    str = (char *)ps_calloc(300, sizeof(char) );
  //    log_i("Free PSRAM after String: %d", ESP.getFreePsram());
  //    // concantenate one char variable to end of char array to the str
  //    strncat( str, &OneChar, 1 ); //works
  //    strncat( str, &TwoChar, 1 );
  //    strncat( str, &ThreeChar, 1 );
  //    //
  //    //*(str+0) = 'G';  // works
  //    //*(str+1) = 'f';
  //    //*(str+2) = 'G';
  //    //*(str+3) = '\0';
  //    log_i("%s", str );
  //    free(str);

  ///////
  //size_t memfree=esp_himem_get_free_size();
  //log_i( "himemFree %d", memfree );
  //  int memcnt=esp_himem_get_phys_size();
  // int memfree=esp_himem_get_free_size();
  //  log_i( "SpiRamPhysSize %d", memcnt );
  //  log_i( "SpiRamFree %d", memfree );
  // esp_himem_get_phys_size(void)
  // esp_himem_handle_t mh; //Handle for the address space we're using
  // esp_himem_rangehandle_t rh; //Handle for the actual RAM.
  // esp_err_t intError = esp_himem_alloc( 4095, &mh);
  // log_i( "%s", esp_err_to_name( intError) );
  // log_i("spiram size %u", esp_spiram_get_size());
  // log_i( "Handle %d", mh );


} // setup()
////
void loop() {}

Thanks Idahowalker for your answer. When I run your application, it returns:

E (129) spiram: SPI RAM not initialized
E (129) esp_himem: Cannot allocate memory for meta info. Not initializing!
========================================
E (43) spiram: SPI RAM not initialized
PSRAM total size     : 4294967295 
----------------------------------------
PSRAM first 4MB size : 0 
PSRAM first 4MB free : 0 
E (50) spiram: SPI RAM not initialized
Internal RAM  size   : 378952 
Internal RAM  free   : 353116 
========================================
Testing the free memory of PSRAM HI-MEM ...
Done!

The application says that the PSRAM has not been initialized, but I have previously executed the psramInit and esp_spiram_init instructions.

I don't know what the problem is, but I'm starting to think it's hardware. As you can see in the article (ESP32-CAM Video Streaming and Face Recognition with Arduino IDE | Random Nerd Tutorials), there are people who access the PSRAM memory from an ESP32-CAM and the Arduino IDE . The only difference is the ESP32-CAM model, the article uses the original AI-Thinker. Has anyone else had problems with the microcontroller and PSRAM memory? Has anyone gotten the PSRAM to work on an ESP32 device?

nacheitor:
Has anyone else had problems with the microcontroller and PSRAM memory? Has anyone gotten the PSRAM to work on an ESP32 device?

No.

Yes.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.