(solved) failing to use external RAM

User avatar
mzimmers
Posts: 643
Joined: Wed Mar 07, 2018 11:54 pm
Location: USA

(solved) failing to use external RAM

Postby mzimmers » Wed Jan 29, 2020 10:49 pm

Hi all -

As my application has outgrown the internal RAM resources of the ESP32, I'm attempting to use the external RAM supplied in the WROVER. My efforts, though, result in a system that fails early in the startup. Depending on the options I set, the failure ranges from a stack overflow in one task (wifi), to a failed system call (nvs_flash_init_partition) in another.

Based on the docs, I'd assumed that with the WROVER, everything was provided from a hardware standpoint, and I just needed to do the configuration. Correct or not?

Also, it's worth pointing out that when I undo my changes (in menuconfig), the sdkconfig file is not restored to its pre-change contents, *and* my app still fails. The contents difference could be because I've also changed my idf version, though that doesn't explain the crashing.

Module WROVER, revision 1. Now using v4.0-rc.

Thanks for any help.
Last edited by mzimmers on Tue Feb 04, 2020 2:37 pm, edited 1 time in total.

ESP_Sprite
Posts: 9599
Joined: Thu Nov 26, 2015 4:08 am

Re: failing to use external RAM

Postby ESP_Sprite » Fri Jan 31, 2020 11:44 am

Not sure about the rest, but:
Based on the docs, I'd assumed that with the WROVER, everything was provided from a hardware standpoint, and I just needed to do the configuration. Correct or not?
That is correct, given you provide it with power and all the standard things that a Wroom would also need.

User avatar
mzimmers
Posts: 643
Joined: Wed Mar 07, 2018 11:54 pm
Location: USA

Re: failing to use external RAM

Postby mzimmers » Fri Jan 31, 2020 2:37 pm

Hi Sprite -

My device and application are otherwise functional, and have been for months, so unless there are any special needs that the SPI RAM has, I should be good.

Does the use of the SPI RAM itself consume internal RAM?

ESP_Sprite
Posts: 9599
Joined: Thu Nov 26, 2015 4:08 am

Re: failing to use external RAM

Postby ESP_Sprite » Sat Feb 01, 2020 9:16 am

I don't recall if that's the case, sorry. Should be easy to check.

philippe_44
Posts: 26
Joined: Thu May 23, 2019 3:05 pm

Re: failing to use external RAM

Postby philippe_44 » Sat Feb 01, 2020 10:23 am

I use extensively external RAM and there it should work pretty easily. You need to tweak the malloc parameters if you want malloc() to use it, potentially move some BSS to external RAM as well but all that is fairly transparent once set. Check as well the bus SPI size and speed (I use QIO and 80MHz on WROVER).

The result still use internal RAM, depending on the threshold you have set for malloc() to go external and the other libraries config (you can have WiFi, LWIP and a few others use SPIRAM).

One thing to check is if you are using some GPIO's that are normally used for ChipSelect of the SPIRAM. I can't remember them on top of my head, but they are indicated in the datasheet.

Other thing, you can't use SPIRAM to create tasks, unless you have enable it in menuconfig and even there, you can only have the stack in SPIRAM, not the BCT. ANd your code shall not use ROM code (for example calls to WiFi routines do not work). But I would be surprised this is the problem at this point.

User avatar
mzimmers
Posts: 643
Joined: Wed Mar 07, 2018 11:54 pm
Location: USA

Re: failing to use external RAM

Postby mzimmers » Mon Feb 03, 2020 3:17 pm

Thanks for the information, philippe_44. I'm not sure what I changed, but I tried configuring it again, and it seems to work now. I do have a few remaining questions:

1. you speak of a threshold beyond which malloc() calls begin to use external RAM. Where is this threshold defined?
2. from your statement, do I correctly infer that malloc() attempts to use internal RAM until unavailable (or until this threshold is reached)?
3. Most of my code is C++ and I've been using "new" instead of malloc(). Any idea which RAM this uses?
4. Have you noticed a significant performance difference between internal and external RAM?

Thank you.

philippe_44
Posts: 26
Joined: Thu May 23, 2019 3:05 pm

Re: failing to use external RAM

Postby philippe_44 » Tue Feb 04, 2020 4:35 am

Hi

1- In menuconfig, components, ESP32 specific, SPI RAM config, there you have an item (after you've enabled malloc() in SPIRAM) that sets the max that will *always* be allocated in IRAM first

2- No, malloc uses internal RAM if requested size is above the minimum set in 1-. Now if you only allocate tiny blocks using malloc (or at least below threshold), yes, SPIRAM will be used until exhaustion, the SPIRAM will be used.

3- I'm not sure, but I'd assume it uses malloc()

4- Difficult for me to say. Of course, IRAM will be faster, but the cache is doing an *amazing* job. When I started my fairly large project, I had very little hope that it would work. I had a few tweaks to do, but the vast majority of my data is SPIRAM and I'm able to get WiFi streaming in flac @96kHz/24, decoding, resampling, gain, very high speed I2S (or BT retransmission), an I2C display connected, a HTTP server, a Telnet server and all that together with zero issue. This is simply mindblowing for a Quad-SPI RAM.

mzimmers wrote:
Mon Feb 03, 2020 3:17 pm
Thanks for the information, philippe_44. I'm not sure what I changed, but I tried configuring it again, and it seems to work now. I do have a few remaining questions:

1. you speak of a threshold beyond which malloc() calls begin to use external RAM. Where is this threshold defined?
2. from your statement, do I correctly infer that malloc() attempts to use internal RAM until unavailable (or until this threshold is reached)?
3. Most of my code is C++ and I've been using "new" instead of malloc(). Any idea which RAM this uses?
4. Have you noticed a significant performance difference between internal and external RAM?

Thank you.

User avatar
mzimmers
Posts: 643
Joined: Wed Mar 07, 2018 11:54 pm
Location: USA

Re: (solved) failing to use external RAM

Postby mzimmers » Tue Feb 04, 2020 4:21 pm

Thanks again for all the help, philippe. I've marked this as solved.

Who is online

Users browsing this forum: No registered users and 132 guests