SPIRAM heap allocation

greengnu
Posts: 27
Joined: Wed May 08, 2019 8:45 pm

SPIRAM heap allocation

Postby greengnu » Mon Nov 18, 2019 11:08 am

I have a ESP32-D0WD with 8MB of external ram.
When I run my program, this is the start of the output I get:

Code: Select all

[0;32mI (621) boot: Disabling RNG early entropy source...␛[0m
␛[0;32mI (621) psram: This chip is ESP32-D0WD␛[0m
␛[0;32mI (626) spiram: Found 64MBit SPI RAM device␛[0m
␛[0;32mI (631) spiram: SPI RAM mode: flash 80m sram 80m␛[0m
...
␛[0;32mI (1165) spiram: SPI SRAM memory test OK␛[0m
␛[0;32mI (1165) heap_init: Initializing. RAM available for dynamic allocation:␛[0m
␛[0;32mI (1165) heap_init: At 3FFAFF10 len 000000F0 (0 KiB): DRAM␛[0m
␛[0;32mI (1171) heap_init: At 3FFB6388 len 00001C78 (7 KiB): DRAM␛[0m
␛[0;32mI (1178) heap_init: At 3FFB9A20 len 00004108 (16 KiB): DRAM␛[0m
␛[0;32mI (1184) heap_init: At 3FFBDB5C len 00000004 (0 KiB): DRAM␛[0m
␛[0;32mI (1190) heap_init: At 3FFCF4B8 len 00010B48 (66 KiB): DRAM␛[0m
␛[0;32mI (1196) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM␛[0m
␛[0;32mI (1203) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM␛[0m
␛[0;32mI (1209) heap_init: At 40094818 len 0000B7E8 (45 KiB): IRAM␛[0m
␛[0;32mI (1215) cpu_start: Pro cpu start user code␛[0m
␛[0;32mI (1220) spiram: Adding pool of 4096K of external SPI memory to heap allocator␛[0m
␛[0;32mI (235) cpu_start: Chip Revision: 1␛[0m
␛[0;33mW (236) cpu_start: Chip revision is higher than the one configured in menuconfig. Suggest to upgrade it.␛[0m
␛[0;32mI (239) cpu_start: Starting scheduler on PRO CPU.␛[0m
␛[0;32mI (0) cpu_start: Starting scheduler on APP CPU.␛[0m
␛[0;32mI (249) spiram: Reserving pool of 16K of internal memory for DMA/internal allocations␛[0m
What I wonder about is the following line:

Code: Select all

␛[0;32mI (1220) spiram: Adding pool of 4096K of external SPI memory to heap allocator␛[0m


Is this to expected? shouldn't that be 8192K instead?

These are my external ram related sdkconfig settings:

Code: Select all

#define CONFIG_SPIRAM_SUPPORT 1
#define CONFIG_SPIRAM_TYPE_ESPPSRAM64 1
#define CONFIG_SPIRAM_SPEED_80M 1
#define CONFIG_SPIRAM_OCCUPY_VSPI_HOST 1
#define CONFIG_SPIRAM_SIZE 8388608
#define CONFIG_SPIRAM_CACHE_WORKAROUND 1
#define CONFIG_SPIRAM_BOOT_INIT 1
#define CONFIG_SPIRAM_MEMTEST 1
#define CONFIG_SPIRAM_USE_CAPS_ALLOC 1
#define CONFIG_SPIRAM_USE_MALLOC 1
#define CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL 16384
#define CONFIG_SPIRAM_MALLOC_RESERVE_INTERNAL 16384
#define CONFIG_D0WD_PSRAM_CLK_IO 17
#define CONFIG_D0WD_PSRAM_CS_IO 16
#define CONFIG_D2WD_PSRAM_CLK_IO 9
#define CONFIG_D2WD_PSRAM_CS_IO 10
#define CONFIG_PICO_PSRAM_CS_IO 10
#define CONFIG_BOOTLOADER_SPI_WP_PIN 7

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: SPIRAM heap allocation

Postby WiFive » Mon Nov 18, 2019 12:07 pm


greengnu
Posts: 27
Joined: Wed May 08, 2019 8:45 pm

Re: SPIRAM heap allocation

Postby greengnu » Mon Nov 18, 2019 2:32 pm

Does that mean there's currently no automatic handling of this and if more than 4MB of external ram should be used then one needs to meticulously map and unmap the ranges used by hand?

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: SPIRAM heap allocation

Postby ESP_Angus » Tue Nov 19, 2019 3:24 am

greengnu wrote:
Mon Nov 18, 2019 2:32 pm
Does that mean there's currently no automatic handling of this and if more than 4MB of external ram should be used then one needs to meticulously map and unmap the ranges used by hand?
That's right, the ESP32 MMU can only map 4MB of PSRAM at a time into the address space. So the himem API splits this into an "always accessible" part - which normally is added to heap - and a "himem" part. The position of the split (how much of each kind) is controlled by a setting in the project configuration.

The recommended way to use the himem API is not to map and unmap every range, but if you have some very large buffers that aren't concurrently accessed then you can map/unmap these individually with the himem API. Other smaller buffers can be in the "lomem" part of the range (always accessible, allocated via heap).

If you don't need to store more than 4MB of data in PSRAM then the easiest option is the default which doesn't use himem at all.

Who is online

Users browsing this forum: Baidu [Spider] and 149 guests