enabling 8 mb psram within micropython 1.19.1 on an esp32-s3 development board

I’ve managed to build MicroPython 1.19.1 with ESP-IDF v4.3.3 with PSRAM enabled. The screen capture above shows the free memory (the free heap, actually) in megabytes. The ESP32-S3-DevKitC-1-N8R8 has 8 MB of flash and 8 MB of external PSRAM, of which only half of that is shown. That’s because MicroPython only shows half of it in its environment. The build date is back on 16 December. The IDF version is 4.4.3, which is the last major version before 5.0 was released. I’m glad I was able to achieve this with 4.4.3 as there’s going to have to be some major changes to MicroPython 1.19.1 because of breaking changes to ESP-IDF 5.0.

The file to edit is micropython/ports/esp32/ boards/GENERIC_S3_SPIRAM/sdkconfig.board, which is listed below. The lines I added are highlighted in green and start at line 14. I found those lines by using idf.py menuconfig with one of my other ESP-IDF projects and enabling SPIRAM/PSRAM on a specific ESP32-S3 development board. That development board has 8 MB FLASH and 8 MB PSRAM. I then opened an editor with the configuration file modified by idf.py and a second window with the same configuration file in the MicroPython port board and copied from the modified configuration to the port board configuration file. Once the copy was finished the changes were saved and I moved to micropython/ports/esp32 and executed make BOARD=GENERIC_S3_SPIRAM, then flashed the development board with the product of make. After that I used idf.py -p /dev/ttyUSB0 monitor (because that’s the port my ESP32-S3 development board was connected to) and I was able to run the REPL without issue. I was also able to develop on the board with Thonny, again without any issue.

I’m so satisfied to have found this because every other explanation for how to make this work I found via searches did not work, or worked with a very old beta of ESP-IDF and involved too many file changes. This change only required modification of one file, and then a make.

CONFIG_FLASHMODE_QIO=y
CONFIG_ESPTOOLPY_FLASHFREQ_80M=y
CONFIG_ESPTOOLPY_FLASHSIZE_DETECT=y
CONFIG_ESPTOOLPY_AFTER_NORESET=y

CONFIG_SPIRAM_MEMTEST=

CONFIG_ESPTOOLPY_FLASHSIZE_4MB=
CONFIG_ESPTOOLPY_FLASHSIZE_8MB=y
CONFIG_ESPTOOLPY_FLASHSIZE_16MB=
CONFIG_PARTITION_TABLE_CUSTOM=y
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions-8MiB.csv"

#
# START OF ADDED CONFIGURATIONS FOR PSRAM ENABLEMENT
#
CONFIG_SOC_PSRAM_DMA_CAPABLE=y
CONFIG_SOC_GDMA_SUPPORT_PSRAM=y
CONFIG_SOC_GDMA_PSRAM_MIN_ALIGN=16

#
# ESP PSRAM
#
CONFIG_SPIRAM=y

#
# SPI RAM config
#
# CONFIG_SPIRAM_MODE_QUAD is not set
CONFIG_SPIRAM_MODE_OCT=y
CONFIG_SPIRAM_TYPE_AUTO=y
# CONFIG_SPIRAM_TYPE_ESPPSRAM64 is not set
CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY=y

#
# PSRAM Clock and CS IO for ESP32S3
#
CONFIG_DEFAULT_PSRAM_CLK_IO=30
CONFIG_DEFAULT_PSRAM_CS_IO=26
# end of PSRAM Clock and CS IO for ESP32S3

# CONFIG_SPIRAM_FETCH_INSTRUCTIONS is not set
# CONFIG_SPIRAM_RODATA is not set
# CONFIG_SPIRAM_SPEED_80M is not set
CONFIG_SPIRAM_SPEED_40M=y
CONFIG_SPIRAM_SPEED=40
CONFIG_SPIRAM_BOOT_INIT=y
# CONFIG_SPIRAM_IGNORE_NOTFOUND is not set
# CONFIG_SPIRAM_USE_MEMMAP is not set
# CONFIG_SPIRAM_USE_CAPS_ALLOC is not set
CONFIG_SPIRAM_USE_MALLOC=y
CONFIG_SPIRAM_MEMTEST=y
CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL=16384
# CONFIG_SPIRAM_TRY_ALLOCATE_WIFI_LWIP is not set
CONFIG_SPIRAM_MALLOC_RESERVE_INTERNAL=32768
# CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY is not set
# CONFIG_SPIRAM_ECC_ENABLE is not set
# end of SPI RAM config
# end of ESP PSRAM

emacs upgrade from its git repo

There is a full Emacs Git repository on the Emacs Savannah site. I had cloned a local copy to work with, but when I read the README and then tried to run configure, there was no configure script to run. I didn’t know why at the time so I deleted the local clone copy and instead downloaded a released source tarball and built from that. Before deleteing the clone copy I found out that that version was 30.0.50.

After building version 28.2 and then building a minimal init.el, I cloned the Git repo again with the intent to do a bit more reading. Sure enough, buried in the top level README text file was a single reference to the script autogen.sh. I ran that script and it in turn produced the necessary configure script.

The version of configure for this version of Emacs wanted makeinfo, which is a part of texinfo. Sure enough Linux Mint 21 needed to have texinfo installed, which in turn fullfilled the makeinfo build requirement and allowed configure to complete. Once completed I installed that emacs locally to my home directory and started to use it. No problems encountered so far, and my very modest init.el works identically in this latest version as it did in Emacs 28.2.

My biggest annoyance so far is cosmetic, and that’s with attempting to duplicate Vim’s PowerLine feature. I found several Emacs Lisp packages that attempt to replicate the look, but they don’t seem to want to work with my Emacs theme, doom-material-dark. So I’ve turned it off/removed it from my init.el file. I’ve started to re-learn Emacs Lisp again, with an eye towards either fixing one of the existing packages, or else trying to write something from scratch.

Otherwise I’m happy with how it works. There’s a slight irony in me selecting Emacs because of its small resource footprint compared to VSCode. I remember distinctly “back in the day” when Emacs was the heavy-duty application that sysadmins frowned upon, especially those with multi-user resource-constrained boxen running Unix or VMS. I knew¬† a guy by the name of Bob Talley (one of the three Bobs) who, in the mid-to-late 1980s ran a microVAX at his home, upon which he ran Emacs. This was a machine with two whole megabytes of RAM and a ridiculously small DEC hard drive. It was his personal system upon which he hosted Emacs, and according to him he lived inside of Emacs, although I don’t know what that means exactly. Bob took great pride in multi-month uptimes as well as having a local terminal constantly logged in. He could do that because he was the only user on the system. Leap ahead 35 years and I’m running the latest Emacs release on a personal computer running Linux Mint that cost a fraction of what that microVAX cost, with 16 GB of RAM, a 1 TB SSD, a 64-bit processor with four hyper-threading cores, the same shape and size of Apple’s Mac Mini, upon which Emacs is now considered a light-weight tool. So much computational power that was unaffordable back in the mid-1980s, but which is considered more than sufficient today. At least by me.