espressif / arduino-esp32

Arduino core for the ESP32
GNU Lesser General Public License v2.1
12.98k stars 7.29k forks source link

Is there a way to determine between ESP32 Standard unit and an ESP32 WROVER unit? #1613

Closed SoftwareGuy closed 5 years ago

SoftwareGuy commented 6 years ago

Hardware:

Not a hardware issue.

Description:

Is there a reliable way like checking a register or something to determine if you have the extra on-board memory that the WROVER unit has? I have ordered a ESP32-WROVER Wemos board that is supposed to have 4MB of PSRAM vs the standard 520KB that the ESP32 normally has. However, I want to be able to access this extra RAM for application use.

I could check the esp_get_free_heap_size() counter on boot and if it's above a certain amount (usually that's around 223000 bytes on cold boot with Serial output active) then we're using a WROVER, but since I am using composite graphics code from bitluni (@me-no-dev probably knows what I'm talking about) the framebuffer does eat up a lot of RAM on a standard ESP32. Is there a function that I can call that asks the ESP32 to return a byte total of how much memory it knows about (ie. the grand total that it "sees").

How does the ESP32 handle this extra memory? Does it notice it and the RTOS adds it into it's memory manager? Or is there some special things going behind the scenes?

My idea is to be able to tell if the PSRAM is attached or not by some mechanism, and then alert the person controlling the ESP32 with a warning saying that they may suffer sudden reboots due to out of memory errors or other crazy things happening.

Thanks!

cyberman54 commented 5 years ago

I'm using a ESP32 board with external PSRAM. Since Espressif32 v1.1.x core i get the extra RAM reported by esp_get_free_heap_size(), without any further tweaking of my software. So it may be sufficient if your application just checks the free RAM at startup.

Anyway, i also would be interested in a way to safely determine SoC type by software.

dsptech commented 5 years ago

I have not a WROVER but I think that: heap_caps_get_free_size(MALLOC_CAP_SPIRAM) could be useful to you.

http://esp-idf.readthedocs.io/en/latest/api-guides/external-ram.html

dsptech commented 5 years ago

Sorry, I've read now that the heap capability on SPI-RAM must be enabled in the ESP-IDF before compiling. I do not know if a such option is enabled in the arduino library, but you could try.

me-no-dev commented 5 years ago

the option is now available (for the ESP32 dev board and on by default if you select WROVER module) and you have the functions ps_malloc and so on to manage PSRAM :)

me-no-dev commented 5 years ago

@cyberman54 while the chip revision can be detected, WROVER is just a normal ESP32 with extra chip added, so it will not show as different revision/chip. There is also this (still requires you to select WROVER or enable PSRAM in the dev module)

if(psramFound()){
  Serial.println("PSRAM was found and loaded");
}
SoftwareGuy commented 5 years ago

@me-no-dev would that work if we used the #if directive to wrap it to avoid it throwing a function not found compile error on non-PSRAM units?

#if HAS_PSRAM
if(psramFound()){
  Serial.println("PSRAM was found and loaded");
  // ....
}
#endif
me-no-dev commented 5 years ago

that function is already wrapped :) check esp32-hal-psram.c ;) if psram is disabled the function just returns false and no other code is compiled.

SoftwareGuy commented 5 years ago

Beauty. That solves my original issue - I can just check that and if it's anything other than false, we've got extra RAM.

Going to close this, but if there's any additional comments please keep the thread going. Cheers!