unicore -> more IRAM0 ?

tvoneicken
Posts: 33
Joined: Tue Nov 17, 2015 5:20 am

unicore -> more IRAM0 ?

Postby tvoneicken » Thu Dec 24, 2020 4:41 am

I'm running into trouble moving MicroPython to esp-idf v4.2 because IRAM usage has shot through the roof, it seems. Compiled with the same options it's 20k over iram0_0_seg. Questions:
- if I set CONFIG_FREERTOS_UNICORE=y is there a way to get the 32KB of core 1's cache added to iram0_0_seg?
- Is there a way to drastically cut down BlueTooth IRAM usage?
- I slashed a bunch of stuff, including compiler optimization and I have the following "size-components" output (sorted by iram size), does that suggest anything I can do?

Code: Select all

            Archive File DRAM .data & .bss & other   IRAM   D/IRAM Flash code & rodata   Total
           libbtdm_app.a        763   2405       0  27614        0      67298     4551  102631
                 libpp.a       1262   3785       0  20825        0      35005     4485   65362
           libfreertos.a       2084    736       0  13487        0        141     1460   17908
           libnet80211.a       1038   6181       0  11724        0      98623    21536  139102
                libsoc.a        267      4       0  11479        0       6800     2008   20558
                libphy.a       1621    675       0   7829        0      32399        0   42524
             libdriver.a        335    248       0   5375        0      37763     9739   53460
          libspi_flash.a        746    288       0   5085        0       1281      292    7692
            libcoexist.a       2030     28       0   3696        0       4632      325   10711
              libesp32.a         88    127       0   3573        0       3999      781    8568
        libesp_ringbuf.a          0      0       0   3442        0          0      569    4011
                librtc.a          0      4       0   2231        0          0        0    2235
         libesp_system.a       1682     17       0   2188        0        266       68    4221
               libheap.a         12      8       0   1811        0        921       35    2787
             libnewlib.a        190    272       0    961        0        999       95    2517
          libesp_timer.a         16     20       0    954        0        926       87    2003
 libbootloader_support.a          0      4       0    886        0       2642     1110    4642
           libesp_wifi.a        500     72       0    509        0       4762     2222    8065
                libhal.a          0      0       0    443        0          0       32     475
               libmain.a         65   1935       0    416        0     193398    96236  292050
             libxtensa.a          0      0       0    416        0          0       58     474
                 libbt.a        387   4829       0    394        0      58950     2767   67327
                liblog.a          8    268       0    258        0        552        2    1088
         libesp_common.a         61     98       0    225        0       2037     5724    8145
                libgcc.a          8     12       0    193        0       5653      872    6738
            libpthread.a         16     12       0    186        0        658      220    1092
         libapp_update.a          1     12       0    154        0       1198      645    2010
         libmbedcrypto.a         64     85       0     30        0      72810    10755   83744
                   (exe)          0      0       0      3        0          3       12      18
                  libc.a          4      0       0      0        0      55411     4115   59530
               libcore.a          0     29       0      0        0        605      228     862
                libcxx.a          0      0       0      0        0         11        0      11
              libefuse.a         36      4       0      0        0        728      136     904
            libesp_eth.a          4      0       0      0        0          0       10      14
          libesp_event.a          4     13       0      0        0       2901      945    3863
          libesp_netif.a         16     25       0      0        0       6295     2721    9057
               liblwip.a         25   3820       0      0        0     102983     8207  115035
                  libm.a          4      0       0      0        0      24435     1882   26321
            libmbedtls.a         60    200       0      0        0      22131     4935   27326
           libmbedx509.a          0      0       0      0        0       6268      105    6373
               libmdns.a          0   1882       0      0        0      20082      410   22374
               libmesh.a          0      0       0      0        0          0        0       0
          libnvs_flash.a          0     24       0      0        0      10595       80   10699
          libsoc_esp32.a          0      0       0      0        0          0     1780    1780
             libstdc++.a          8     20       0      0        0       2553     1044    3625
      libtcpip_adapter.a          0     17       0      0        0        596      169     782
                libulp.a          0      0       0      0        0        432        0     432
                libvfs.a        308     48       0      0        0       5631      323    6310
     libwpa_supplicant.a         12    844       0      0        0      36784     3104   40744

ESP_igrr
Posts: 2067
Joined: Tue Dec 01, 2015 8:37 am

Re: unicore -> more IRAM0 ?

Postby ESP_igrr » Thu Dec 24, 2020 12:56 pm

Hi tvoneicken, could you please attach the sdkconfig file of your project?

A few options you can adjust to reduce IRAM usage:

CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH=y
CONFIG_ESP32_WIFI_IRAM_OPT=n
CONFIG_ESP32_WIFI_RX_IRAM_OPT=n
CONFIG_ESP_PANIC_HANDLER_IRAM=n
CONFIG_SPI_MASTER_ISR_IN_IRAM=n
CONFIG_SPI_SLAVE_ISR_IN_IRAM=n
CONFIG_UART_ISR_IN_IRAM=n
CONFIG_LWIP_IRAM_OPTIMIZATION=n

Unfortunately when the APP CPU is disabled, the 32kB memory pool at 0x40078000 is only added as a heap region. The reason for this is that the 2nd stage bootloader itself is located in that pool, so starting the IRAM region there would overwrite the bootloader.

In cases when flash encryption and secure boot are not enabled, the actual IRAM usage of the bootloader in that region is within 16kB, so another 16kB can theoretically be given to the application...
For a test, you can try modifying the linker scripts as follows:
1. in components/bootloader/subproject/main/ld/esp32/bootloader.ld, change iram_loader_seg length to 0x4000.
2. in components/esp32/ld/esp32.ld, change iram0_0_seg org=0x4007C000, len=0x24000
"idf.py size" might report incorrect values after this, but the available IRAM size should increase.

tvoneicken
Posts: 33
Joined: Tue Nov 17, 2015 5:20 am

Re: unicore -> more IRAM0 ?

Postby tvoneicken » Thu Dec 24, 2020 4:45 pm

Thanks for all the info, igrr! I only had half the CONFIG_ options, so that gives me some more to play with, and the info about how to change the load map is also very helpful!

Who is online

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