ESP32 WROOM-32

BillBB
Posts: 7
Joined: Sat Sep 22, 2018 1:58 pm

ESP32 WROOM-32

Postby BillBB » Wed Jan 08, 2020 3:56 pm

I've got an ESP32 WROOM-32 module but I'm slightly confused about which settings to use in the Arduino IDE for this module (ESP32 Dev Board).

My code had previously been running on the ESP32 WROOM, but I have to choose a large app partition with no OTA because the code was so large. The WROOM-32 module has much more memory and I want to incorporate OTA functionality in my code. What menu settings should I select in Arduino?

idahowalker
Posts: 166
Joined: Wed Aug 01, 2018 12:06 pm

Re: ESP32 WROOM-32

Postby idahowalker » Wed Jan 08, 2020 4:56 pm

Humm.

So you had an ESP32 and you replaced it with a ESP32 WROOM and you now expect to get more memory available but a ESP32 DEV is a ESP32 WROOM.

If you want more ram from an ESP32 you'd want to go with a ESP32 WROVER. Many WROVER's come with 8+ MB ram. Using the Arduino IDE with a Wrover you can access about 4MB, which is called HiMem of the WROVER's ram, bank switching (in the Arduino IDE) does not work, yet.

Now when you go to use that extra RAM it is great for storing large data thingies into. I tend to put most of my variables into the HiMem area.

I use the libraries:
#include "sdkconfig.h"
and
extern "C"
{
#include <esp_himem.h>
}
to get access to the extra ram.
I use log_i("Total PSRAM: %d", ESP.getPsramSize()); and log_i("Free PSRAM: %d", ESP.getFreePsram()); to get the extra ram size use / avaialibility.

Here are a few examples of using the WROVERS ram:

Code: Select all

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);
You may want to refer to the ESP32 API https://docs.espressif.com/projects/esp ... himem.html, The himem allocation API for more information.

BillBB
Posts: 7
Joined: Sat Sep 22, 2018 1:58 pm

Re: ESP32 WROOM-32

Postby BillBB » Wed Jan 08, 2020 5:49 pm

My bad - I wasn't clear in my explanation (and I think the ESP32 part naming scheme sucks)

I was using an ESP32 WROOM with 32Mbits flash, on my own PCB, programmed with an FTDI adapter, using the ESP32 dev module option on the IDE.

I have now switched to the ESP32 WROOM with 128Mbits flash, same PCB and setup. The IDE has an option (under the ESPre Dev board) for 128Mbits, but I'm not certain which, if any, of the partition options are suitable. My code compiles to 1396682 bytes, so there is plenty of flash spare on the 128Mbit device. It uses 62308 bytes of dynamic memory (19%)

My guess is that I should use the 16M - 3M APP, 9M FATFS option (as it leaves me with some room for more code)

Is this right?

idahowalker
Posts: 166
Joined: Wed Aug 01, 2018 12:06 pm

Re: ESP32 WROOM-32

Postby idahowalker » Thu Jan 09, 2020 1:58 am

Which partition you select is up to you based upon your applications requirements.

BillBB
Posts: 7
Joined: Sat Sep 22, 2018 1:58 pm

Re: ESP32 WROOM-32

Postby BillBB » Thu Jan 09, 2020 9:28 am

Yes, the partition depends on application requirements, I know, that is why I explained my requirements and asked for help on this support forum to make sure I have understood what the partition options actually mean so I select the correct one.

I think I understand it now - The option I have chosen gives me 3MB app, 9Mb file system and so presumably the last 4MB of the 16MB memory is a partition for the OTA update system.

Who is online

Users browsing this forum: No registered users and 40 guests