Call to arms | Teensy + SDRAM = true

I thought I would try some goofing off and see how hard some of this might be... Maybe should be own thread.

So far, I have put up a few changes in my fork and new branch: https://github.com/KurtE/cores/tree/variants_override
Morning all
Kind of crashed yesterday evening so not too much done after that.
Using a variant folder might not be a bad idea would really help with custom board definitions. Personally, I would like that for the dev board but here is the catch would it be worth the effort to mod the core if we only have 3 official teensy boards? :) Don't get me wrong - I am all in :)

LittleFS_RAM myfs; works but ListFiles was a boring start with empty disk.
Cool that you started playing with LittleFS - getting sidetracked on getting a OV7670 camera working with the dev board - been a while so trying to remember what we did....
 
@PaulStoffregen

Wanted to post this yesterday but took some meds that knocked me out. Was working with one of the ov7670 libraries on the T4.1 and ran into the same issue as before, i.e.

Losing USB and getting the red flashed

@defragster seems to have run into that again with the T4.1 but not sure if that is same issue or issue with trying to address sdram on a board that does not support it.

@defragster
Runing the simple_datalogger for PSRAM with the SCB of 0x9000000 works for me with no crashes:
Code:
C:\Users\Merli\AppData\Local\Temp\.arduinoIDE-unsaved2024010-5676-1uspepn.7ijm\LittleFS_PSRAM_Simple_Datalogger\LittleFS_PSRAM_Simple_Datalogger.ino Jan 10 2024 07:31:36
Initializing LittleFS ...LittleFS initialized.

Menu Options:
    l - List files on disk
    e - Erase files on disk
    s - Start Logging data (Restarting logger will append records to existing log)
    x - Stop Logging data
    d - Dump Log
    h - Menu


 Space Used = 4096
Filesystem Size = 7340032
Directory
---------


Logging Data!!!
9,8,9
8,8,8
8,8,8
9,8,8
9,8,8
9,8,8
8,7,8
9,8,8
8,8,8
9,8,8
9,8,8
8,8,8
9,8,8
9,8,8
9,8,8
8,8,8
9,8,8
9,8,8
8,8,8
8,8,8
9,8,8
9,9,8
9,8,8
9,8,8
8,8,8
9,8,8
9,8,8

Stopped Logging Data!!!
Records written = 27

Dumping Log!!!
9,8,9
8,8,8
8,8,8
9,8,8
9,8,8
9,8,8
8,7,8
9,8,8
8,8,8
9,8,8
9,8,8
8,8,8
9,8,8
9,8,8
9,8,8
8,8,8
9,8,8
9,8,8
8,8,8
8,8,8
9,8,8
9,9,8
9,8,8
9,8,8
8,8,8
9,8,8
9,8,8
 
Know this was discussed somewhere else but how is the chip identified as a micromod or 4.1 or 4.0 - there has to be a chip id burn in someplace????
I know I am not @PaulStoffregen 😉
But I think it is done simply by the size of the Flash chip...

As I mentioned in the post yesterday bootdata.c file, there is:
Code:
#if defined(ARDUINO_TEENSY40)
    0x00200000,        // sflashA1Size            0x50
#elif defined(ARDUINO_TEENSY41)
    0x00800000,        // sflashA1Size            0x50
#elif defined(ARDUINO_TEENSY_MICROMOD)
    0x01000000,        // sflashA1Size            0x50
#else
#error "Unknow flash chip size";
#endif

EDIT... Also there is stuff in usb_desc.c - for
Code:
  // For USB types that don't explicitly define BCD_DEVICE,
  // use the minor version number to help teensy_ports
  // identify which Teensy model is used.
  #if defined(__IMXRT1062__) && defined(ARDUINO_TEENSY40)
        0x79, 0x02, // Teensy 4.0
  #elif defined(__IMXRT1062__) && defined(ARDUINO_TEENSY41)
        0x80, 0x02, // Teensy 4.1
  #elif defined(__IMXRT1062__) && defined(ARDUINO_TEENSY_MICROMOD)
        0x81, 0x02, // Teensy MicroMod
  #else
        0x00, 0x02,
  #endif
 
Last edited:
As I mentioned in the post yesterday bootdata.c file, there is:
Noticed that but they all depend on
Code:
defined(ARDUINO_TEENSY40)
i.e, teensy_xxx defined first? So how does arduino teensy_xx get defined - one of those what comes first :)

Just thought of something must be defined in the boards.txt file - duh.... I am dumb
 
@defragster
I tried this with bot a teens4.1 and the dev boardh and both would just restart (note I commented out the scb 0x9... for testing)
Code:
  char* buf;
  buf = (char*)malloc(390 * 1024 * sizeof(char));

  if (!myfs.begin(&buf, 390 * 1024 * sizeof(char))) {
    Serial.printf("Error starting %s\n", "PSRAM RAM DISK");
    while (1) {
      // Error, so don't do anything more - stay stuck here
    }
  }

Think there may be an issue with using malloc with littlefs :) not sure if it a setting yet - now back to the camera stuff :)
 
@defragster
I tried this with bot a teens4.1 and the dev boardh and both would just restart (note I commented out the scb 0x9... for testing)
Code:
  char* buf;
  buf = (char*)malloc(390 * 1024 * sizeof(char));

  if (!myfs.begin(&buf, 390 * 1024 * sizeof(char))) {
    Serial.printf("Error starting %s\n", "PSRAM RAM DISK");
    while (1) {
      // Error, so don't do anything more - stay stuck here
    }
  }

Think there may be an issue with using malloc with littlefs :) not sure if it a setting yet - now back to the camera stuff :)
You're passing the address of buf to myfs.begin() instead of the value directly.
 
I'll reach out in March, we should have a next gen devboard by then with some more features that's been requested by mjs513 and jmarsh.
If you run out of things to add, I can probably think of a few others :D

My problem with boards, Is I have a hard time leaving any space unused 😆 Like my current my MicroMod board, which is my goto board for testing things:
1704899310872.png

Never have fully populated one yet. (Like add in the parts for doing Dynamixel Servos...)

I also have a similar one for T4.1 which also had connector for OV7670 camera.

Things that would be nice include things like:
USBHost - Even if just the 2 pins lins T4.0 has, although nicer with the actual USB connector and maybe with some power...
Note: Even with connector I like to add pins for D+/D- to make it easy to connect scope/LA

SD cards - SDIO would be nice.

CSI Pins and/or FlexIO pins for doing Camera...

Between those it would give you lots of stuff to experiment with the extra memory, like load images from Disks and display on display...

I have not checked yet to see how many display signals are brought out.. Like maybe enough to connect to something like:
https://www.adafruit.com/product/1590 ?

Other things on my MMOD board, may be overkill: Things like

Display pins setup to easily plug in ILI9341/ILI9488 boards (Currently 9341 plugged in). Also have pins for several Adafruit displays not populated on this one...

Audio/other - setup that could plug in Teensy Audio board
QWIIC connectors

As I said, it is hard to resist adding things when there is space :D
 
You're passing the address of buf to myfs.begin() instead of the value directl
ok - just tried it again and it worked. Ok strange - when I did it the first time it failed. Argh - getting a headache with this!!! Thanks for making me try it again.

Just tried it with sdram_malloc and it worked must have typed something wrong!!!!!!!!!!!! @defragster no hangs
moded sketch:

Code:
/*
  LittleFS  datalogger
 
 This example shows how to log data from three analog sensors
 to an storage device such as a FLASH.
 
 This example code is in the public domain.
 */
#include <LittleFS.h>

// NOTE: This option is only available on the Teensy 4.1 board with added bottomside PSRAM chip(s) in place.

// This declares the LittleFS Media type and gives a text name to Identify in use
LittleFS_RAM myfs;

#include <SDRAM_t4.h>

//constructor for
SDRAM_t4 sdram;

#define MYPSRAM 7 // compile time PSRAM size and is T_4.1 specific either 8 or 16, or smaller portion
//EXTMEM char buf[MYPSRAM * 1024 * 1024];  // Contents preserved with Power on Restart and Upload
File dataFile;  // Specifes that dataFile is of File type

int record_count = 0;
bool write_data = false;

void setup()
{

  // Open serial communications and wait for port to open:
  Serial.begin(115200);
  while (!Serial) {
    // wait for serial port to connect.
  }
  Serial.println("\n" __FILE__ " " __DATE__ " " __TIME__);

    if(CrashReport) {
      Serial.print(CrashReport);
      while(1);
    }
 
    // sdram.begin initializes the available SDRAM Module
    // begin defaults to 32mb but you can specify the size
    // from begin
    // begin(uint16 external_memory_size) where size is in
    // MB
    if(!sdram.begin()) {
      Serial.printf("SDRAM Init Failed!!!\n");
      while(1);
    };

  Serial.print("Initializing LittleFS ...");

  // see if you are able to create a RAM disk in the space you a lotted
  // buf = is the name of the array you created, sizedf(buf) is how large the
  // array is, in our case 390 * 1024.
  char* buf;
  buf = (char*)sdram_malloc(MYPSRAM * 1024 * 1024 * sizeof(char));

  if (!myfs.begin(buf, MYPSRAM * 1024 * 1024 * sizeof(char))) {
    Serial.printf("Error starting %s\n", "PSRAM RAM DISK");
    while (1) {
      // Error, so don't do anything more - stay stuck here
    }
  }
  Serial.println("LittleFS initialized.");
 
  menu();
 
}

void loop()
{
  if ( Serial.available() ) {
    char rr;
    rr = Serial.read();
    switch (rr) {
      case 'l': listFiles(); break;
      case 'e': eraseFiles(); break;
      case 's':
        {
          Serial.println("\nLogging Data!!!");
          write_data = true;   // sets flag to continue to write data until new command is received
          // opens a file or creates a file if not present,  FILE_WRITE will append data to
          // to the file created.
          dataFile = myfs.open("datalog.txt", FILE_WRITE);
          logData();
        }
        break;
      case 'x': stopLogging(); break;

      case 'd': dumpLog(); break;
      case '\r':
      case '\n':
      case 'h': menu(); break;
    }
    while (Serial.read() != -1) ; // remove rest of characters.
  }

  if(write_data) logData();
}

void logData()
{
    // make a string for assembling the data to log:
    String dataString = "";
 
    // read three sensors and append to the string:
    for (int analogPin = 0; analogPin < 3; analogPin++) {
      int sensor = analogRead(analogPin);
      dataString += String(sensor);
      if (analogPin < 2) {
        dataString += ",";
      }
    }
 
    // if the file is available, write to it:
    if (dataFile) {
      dataFile.println(dataString);
      // print to the serial port too:
      Serial.println(dataString);
      record_count += 1;
    } else {
      // if the file isn't open, pop up an error:
      Serial.println("error opening datalog.txt");
    }
    delay(100); // run at a reasonable not-too-fast speed for testing
}

void stopLogging()
{
  Serial.println("\nStopped Logging Data!!!");
  write_data = false;
  // Closes the data file.
  dataFile.close();
  Serial.printf("Records written = %d\n", record_count);
}


void dumpLog()
{
  Serial.println("\nDumping Log!!!");
  // open the file.
  dataFile = myfs.open("datalog.txt");

  // if the file is available, write to it:
  if (dataFile) {
    while (dataFile.available()) {
      Serial.write(dataFile.read());
    }
    dataFile.close();
  } 
  // if the file isn't open, pop up an error:
  else {
    Serial.println("error opening datalog.txt");
  }
}

void menu()
{
  Serial.println();
  Serial.println("Menu Options:");
  Serial.println("\tl - List files on disk");
  Serial.println("\te - Erase files on disk");
  Serial.println("\ts - Start Logging data (Restarting logger will append records to existing log)");
  Serial.println("\tx - Stop Logging data");
  Serial.println("\td - Dump Log");
  Serial.println("\th - Menu");
  Serial.println();
}

void listFiles()
{
  Serial.print("\n Space Used = ");
  Serial.println(myfs.usedSize());
  Serial.print("Filesystem Size = ");
  Serial.println(myfs.totalSize());

  printDirectory(myfs);
}

void eraseFiles()
{
  myfs.quickFormat();  // performs a quick format of the created di
  Serial.println("\nFiles erased !");
}

void printDirectory(FS &fs) {
  Serial.println("Directory\n---------");
  printDirectory(fs.open("/"), 0);
  Serial.println();
}

void printDirectory(File dir, int numSpaces) {
   while(true) {
     File entry = dir.openNextFile();
     if (! entry) {
       //Serial.println("** no more files **");
       break;
     }
     printSpaces(numSpaces);
     Serial.print(entry.name());
     if (entry.isDirectory()) {
       Serial.println("/");
       printDirectory(entry, numSpaces+2);
     } else {
       // files have sizes, directories do not
       printSpaces(36 - numSpaces - strlen(entry.name()));
       Serial.print("  ");
       Serial.println(entry.size(), DEC);
     }
     entry.close();
   }
}

void printSpaces(int num) {
  for (int i=0; i < num; i++) {
    Serial.print(" ");
  }
}

Test output:
Code:
C:\Users\Merli\AppData\Local\Temp\.arduinoIDE-unsaved2024010-34448-7vj3fm.x2xk\LittleFS_PSRAM_Simple_Datalogger\LittleFS_PSRAM_Simple_Datalogger.ino Jan 10 2024 10:58:44
Initializing LittleFS ...LittleFS initialized.

Menu Options:
    l - List files on disk
    e - Erase files on disk
    s - Start Logging data (Restarting logger will append records to existing log)
    x - Stop Logging data
    d - Dump Log
    h - Menu


 Space Used = 4096
Filesystem Size = 7340032
Directory
---------


Logging Data!!!
7,3,7
7,4,8
7,3,8
6,3,8
6,3,8
7,4,10
7,4,8
8,4,8
6,2,8
8,3,8
7,4,9
8,3,8
7,3,9
8,2,9
7,3,6
7,2,8
7,2,11
7,3,8
6,3,8
7,2,8
5,3,8
7,3,8
7,2,8
7,3,9
7,3,8
8,2,8
8,3,8
7,3,9

Stopped Logging Data!!!
Records written = 28

Dumping Log!!!
7,3,7
7,4,8
7,3,8
6,3,8
6,3,8
7,4,10
7,4,8
8,4,8
6,2,8
8,3,8
7,4,9
8,3,8
7,3,9
8,2,9
7,3,6
7,2,8
7,2,11
7,3,8
6,3,8
7,2,8
5,3,8
7,3,8
7,2,8
7,3,9
7,3,8
8,2,8
8,3,8
7,3,9

 Space Used = 4096
Filesystem Size = 7340032
Directory
---------
datalog.txt                           198
 
@PaulStoffregen - @defragster
If I try that same sketch on a T4.1 it freezes the T41. If I unplug it and plug it back in it show the 9 red blinks.

EDIT: If reload the psram simple datalogger sketch it works with the SCB set at 0x9......

Bottom line - dont include sdram_t4 if there is no SDRAM chip available.
 
Last edited:
I have not checked yet to see how many display signals are brought out.. Like maybe enough to connect to something like:
https://www.adafruit.com/product/1590 ?
All eLCDIF/FlexIO2 pins have been brought out.
But I wonder if we can use CSI, LCD,Audio and SDRAM together.

We are using a 10x10 mm chip so it has less pads, thus less signals to break out.

But the next gen dev board will definitely have more pads exposed. And perhaps the 12x12mm version for more signals.
 
Not TD 1.59 specific! Clean 1.8.19 unzipped to two folders then 1.57 in one and 1.58 in the other have the similar behavior
> except counting 8 Blinks on TD1.57 - and 9 Blinks on 1.59.4.
> Had to go back to 1.58 : it fails to show on USB, but is not showing any Blink codes.



BETA 4 of 1.59 Issue ? @PaulStoffregen
Clean unzip of Arduino IDE 1.8.19 to new folder and install TD 1.59.4.

Using example: "...\hardware\teensy\avr\libraries\LittleFS\examples\Test_Integrity\RAM\RAM.ino"

Build default FASTER and it works as expected with 1st T_4.1 below.

Build DEBUG and it goes OFFLINE/Missing after Upload.

> 1st T_4.1 LOCKED and NO BLINKS on power on
> 2nd T_4.1 pre-lockable and 9Blinks on power on.
@mjs513 - this issue {p#374 & #375} was the existing shipped RAM example - not PSRAM or SDRAM - just: char buf[ 390 * 1024 ]; // BUFFER in RAM1

Tried that on CLEAN TD 1.57 and 1.58 and failed with DEBUG.
Given that THOSE failed it seemed there was some other issue at hand with it not working with SDRAM so I tried those.

SDRAM example here fails with the same 9Blinks as posted version - not sure what was edited - but failing.
Given it won't run DEBUG with a RAM example and that 9Blinks has been seen on other posts, it seems there is some underlying issue ? Certainly confusing results ...

As far as SDRAM - just to be sure - put SDRAM_t4 'coreFiles' in the otherwise cleam td1.59.4 install and it still 9Blinks
Also interesting that LittlFS RAM example dir 8Blink, NoBlink, 9Blink diff behavior with TD 1.57, 1.58, 1.59.4
 
Last edited:
@PaulStoffregen - @defragster
If I try that same sketch on a T4.1 it freezes the T41. If I unplug it and plug it back in it show the 9 red blinks.

EDIT: If reload the psram simple datalogger sketch it works with the SCB set at 0x9......

Bottom line - dont include sdram_t4 if there is no SDRAM chip available.
just to reiterate - prior posts had no relation to SDRAM - JUST LittleFS using RAM on DEBUG build on a T_4.1
Seeing ODD SDRAM results had me go back and try similar with OLD RAM sketch to see failure to start after upload.
Not related to this thread - but without that working seeing odd behavior with prior LittleFS can relate to SDRAM fail on this SDRAM DevBoard.
 
Alcon
Last couple of days I have been getting a OV7650 camera working with the development board and using sdram for both the framebuffer and reading in the pixels.

Been using @KurtE's ILI9341_t3n and Arduino_OV767x (branch for Micromod) and the ILI9488 libraries (which need the framebuffer and pixel buffer in sdram). To do so had to hack the core_pins, digital.c and pins_arduino files to add in a pin that is available on the T41 but not the micromod. Finally got them working this morning for single frame capture and continuous stream modes - unfortunately the dmaupdate option didn;t work (seem to remember we always had problems with this with the HB01 library as well). Note: the Camera is using flexio since we don't have the CSI pins yet.

Yes lots of wires :) surprise it works!
IMG_1053.jpg


An interesting issue cropped up - with the camera and display. When trying to run the ILI9341_t3n (no sdram needed) would loss the dev board until I commented out the SCB region. But if i just run graphicstest with it - no issues???
 
Cool that you started playing with LittleFS - getting sidetracked on getting a OV7670 camera working with the dev board - been a while so trying to remember what we did....
It was an early task I mentioned - finally remembered it might be a fun test - FUN IT HAS NOT BEEN :(
Seems there might be something 'non-static'? Not sure what would explain any failures using the 'known LittleFS examples' using the Debug build in 1.57, 1.58, and 1.59.4 causing T_4.1 to go offline immediately after Upload or fresh power on with 8Blinks, NO_Blinks, and 9Blinks.
> This is a different issue - but discovered here wondering about local issues building LittleFS for SDRAM on this DevBoard ...
> maybe this needs a new thread for attention?

@mjs513 - noticed coreFiles on the extra github created does not include the T_MM.LD.

The post #386 SDRAM example - like the one here - fails building here under 1.8.19 for some reason. Mayve there is something else in cores out of sync?
 
noticed coreFiles on the extra github created does not include the T_MM.LD.
Nope - not needed when using the library - only need the mod to the t_mm.ld if you want to use it like extmem which Paul has already said he is not going to entertain for now.

The post #386 SDRAM example - like the one here - fails building here under 1.8.19 for some reason. Mayve there is something else in cores out of sync?
Dont see why it shouldnt build - will check when I get a chance - probably late today
 
The post #386 SDRAM example - like the one here - fails building here under 1.8.19 for some reason. Mayve there is something else in cores out of sync?
Builds fine for me using faster but I get a crash report when it runs

Code:
D:\Users\Merli\Documents\Arduino\sketch_jan11a\sketch_jan11a.ino Jan 11 2024 12:17:57
CrashReport:
  A problem occurred at (system time) 12:18:1
  Code was executing from address 0x6D86
  CFSR: 400
    (IMPRECISERR) Data bus error but address not related to instruction
  Temperature inside the chip was 50.12 °C
  Startup CPU clock speed is 600MHz
  Reboot was caused by auto reboot after fault or bad interrupt detected
 
The post #386 SDRAM example - like the one here - fails building here under 1.8.19 for some reason. Mayve there is something else in cores out of sync?
Builds fine for me using faster but I get a crash report when it runs
...
Opps - Yes, it builds - no issues there. But will not run as prev noted.
 
Recommend testing with the latest core library startup.c (which enables 80000000-BFFFFFFF). Testing (without SDRAM) showed a delay is needed between writing the MPU config and actually enabling the MPU.

Code:
    SCB_MPU_RBAR = 0x80000000 | REGION(i++); // SEMC: SDRAM, NAND, SRAM, etc
    SCB_MPU_RASR = MEM_CACHE_WBWA | READWRITE | NOEXEC | SIZE_1G;
    // hardware: https://forum.pjrc.com/index.php?threads/73898/#post-334041
    // software: https://github.com/mjs513/SDRAM_t4

    asm("nop"); // allow a few cycles for bus writes before enable MPU
    asm("nop");
    asm("nop");
    asm("nop");
    asm("nop");
    asm("nop");
    SCB_MPU_CTRL = SCB_MPU_CTRL_ENABLE;
 
@PaulStoffregen
Retested some of the issue sketches and some that were not. ( all testing done with FASTER and on 2.2.2)
Sketch​
T4.1​
Dev board​
Other
w 2mbw/o 2mbw/2mbw/o 2mb
LittleFS/SDRAMWorks, dies gracefullyWorks, dies gracefullyworks - runs successfullylooses the Dev boardTO MAKE IT WORK with no 2 2mb HAD TO COMMENT OUT ONE NOP??? Timinig issue???
ILI9341_t3n/Camer/SDRAMNot testedNot Testedworks - runs successfullyworks - runs successfullyTO MAKE IT WORK HAD TO COMMENT OUT ONE NOP??? Timinig issue???
ILI9488/Camer/SDRAM (note special branch used)Not testedNot Testedworks - runs successfullyworks - runs successfullyTO MAKE IT WORK HAD TO COMMENT OUT ONE NOP??? Timinig issue???
LittleFS Pgm Data loggerWorksWorksWorksWorksTO MAKE IT WORK HAD TO COMMENT OUT ONE NOP??? Timinig issue???

Note - haven't tested I2C yet - more to follow :)
 
Back
Top