Teensy 4.1 with 16MB of PSRAM


#1

Since I’m using the Teensy 4.1 anyway, I wanted to try and extend the Teensy’s memory with PSRAM. After literally having waited months for suitable PSRAM chips to become available at reasonable prices I now got hold of some for about 2 Euros each and soldered two of them them to a board. They do work as expected as a full 16MB of RAM, and they also seem to work just fine with uLisp. The Teensy’s board section needs to be changed only marginally in uLisp.ino, to get the thing running I modified it like this:

#elif defined(ARDUINO_TEENSY40) || defined(ARDUINO_TEENSY41)
  #define BOARD_HAS_PSRAM
  #if defined(BOARD_HAS_PSRAM)
    #define WORKSPACESIZE 1900000         /* Objects (8*bytes) */
  #else
    #define WORKSPACESIZE 60000           /* Objects (8*bytes) */
  #endif
  #define CODESIZE 256                    /* Bytes */
  #define STACKDIFF 15000
  #define LITTLEFS (960 * 1024)
  #include <LittleFS.h>
  LittleFS_Program LittleFS;
  #define FS_FILE_WRITE FILE_WRITE_BEGIN
  #define FS_FILE_READ FILE_READ
  #define CPU_iMXRT1062
  #define SDCARD_SS_PIN BUILTIN_SDCARD
  #define BitOrder uint8_t
  #undef RAMFUNC
  #define RAMFUNC FASTRUN
  #undef MEMBANK
  #if defined(BOARD_HAS_PSRAM)
    #define MEMBANK EXTMEM
  #else
    #define MEMBANK DMAMEM
  #endif

Technically it shouldn’t even be necessary to exchange EXTMEM with DMAMEM since the PJRC website states that DMAMEM will be used automatically when no EXTMEM is detected.

Using this external RAM slows down the Teensy comparable to other boards with PSRAM, it is 2 to 3 times less fast. Not really a problem coming from an extremely high speed. The benchmark results:

Tak 840 ms (about half the speed before)
Q2 2.8 s (a bit less than a third of the speed before)
GC 1 s (much slower, no surprise)

(Not tested with or integrated into the LispBox firmware yet.)