Teensy 4.1 external flash memory read on software level.

Status
Not open for further replies.

Han

Active member
Hi,

My goal is to "client.print" html file from flash memory, but I'm running out my knowledge to do so.

So far, I was able to write a file to a external flash memory (thanks to mjs513) then read it using a char buffer (EXTMEM from PSRAM).

Is there a way to read a file without using a char buffer?

Best,

Alex Han
 
Last edited:
@Han
Good morning.

Not sure what you want to do here. Have you checked out the structured read/writes examples.
 
@mjs513
Good to see you again :)

I thought this was another SPIFFS issue, but it turns out Ethernet side issue.

I'm successfully getting a html file from SD card and write to an external flash memory.

However, now I'm stuck on sending that file through Ethernet. Simply my web page is cutting off at the same line.

Quite confused... I don't know why teensy 4.1 is not able to send a file (html web page) via Ethernet.

Web page is always truncated at the same spot.
 
Some early testing was done on file transfers with T_4.1 ethernet code IIRC for speed and function. Find and visit that thread.
 
Sorry for late reply,

I had to go over with my boss and make it clear that I'm releasing some of our code sections to get much needed technical help.

Previously with Teesny 4.0, I was able to make a prototype LRU (line replacement unit) for a drone.

Instead of being a dumb power distributor, we added a cheap micro-controller where it monitor and record a power system behavior during entire flight mission.

So, the hardware set up is same as described from https://www.pjrc.com/store/wiz820_sd_adaptor.html but with WIZ850 Ethernet adapter.

On software side, I converted entire HTML/ajax web server file to a C string format using my python code and put it into T4.0.
1.jpg

Then I "client.print" the whole thing like this...
2.PNG

Output looks like this...
2.jpg
so if you type an ip address of web server, you will see this without using SD card or any type of portable memory devices which is against the ITAR standard.
 
Now with a Teensy 4.1, we got a built-in Ethernet module DP83825I.

I have a separate stand alone software that gets a HTML file from a SD card and save it to an external flash memory.
Code:
extern "C" uint8_t external_psram_size;
#include <SD.h>
#include <SPI.h>
#include <spiffs_t4.h>
#include <spiffs.h>

spiffs_t4 eFLASH;

//Setup files IO
spiffs_file file1;
#define DO_DEBUG 1
char ART_buf_ART_Webserver[387500];

char fname1[16] = "ART_Webserver";
elapsedMicros my_us;

void setup() {
  while (!Serial);
Serial.println("\n" __FILE__ " " __DATE__ " " __TIME__);
  Serial.printf("PSRAM: %d MB\n", external_psram_size);

  Serial.println("\n Enter y in 10 seconds to format FlashChip - other to skip");
  uint32_t pauseS = millis();
  char chIn = 9;
  while ( pauseS + 10000 > millis() && 9 == chIn ) {
    if ( Serial.available() ) {
      do {
        if ( chIn != 'y' )
          chIn = Serial.read();
        else
          Serial.read();
      }
      while ( Serial.available() );
    }
  }
  if ( chIn == 'y' ) {
    int8_t result = eFLASH.begin();
    if(result == 0) {
      eFLASH.eraseFlashChip();
    } else if(result == 1){
      eFLASH.eraseDevice();
    } else {
      Serial.println("ERROR!");
    }
  }
  Serial.print("Initializing SD card...");
  
  // see if the card is present and can be initialized:
  if (!SD.begin(BUILTIN_SDCARD)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    return;
  }
  Serial.println("card initialized.");

  Serial.println();
  Serial.println("Mount SPIFFS:");
  eFLASH.begin();
  eFLASH.fs_mount();
  
  // open the file.
  File ART_Webserver_file = SD.open("RD0030~1.HTM");
  if (ART_Webserver_file) { 
    uint32_t count = 0;
    while (ART_Webserver_file.available()) {
      ART_buf_ART_Webserver[count] = ART_Webserver_file.read();
      count++;
    }
    ART_buf_ART_Webserver[count] = '\0';
    Serial.println("Write files...");
    eFLASH.f_writeFile(fname1, ART_buf_ART_Webserver, SPIFFS_CREAT | SPIFFS_TRUNC | SPIFFS_RDWR);
    Serial.println("Writing successful");
    ART_Webserver_file.close();
  } else {
    Serial.println("error opening RD0030~1.HTM file, power cycle the Teensy 4.1");
    return;
  }
  memset(ART_buf_ART_Webserver, 0, sizeof(ART_buf_ART_Webserver)); 
  
  Serial.println("Read file:");
  eFLASH.f_readFile(fname1, ART_buf_ART_Webserver, sizeof(ART_buf_ART_Webserver)/sizeof(char), SPIFFS_RDONLY);
 
  Serial.println(ART_buf_ART_Webserver);
  Serial.println();
  
  Serial.println("Mount SPIFFS:");
  Serial.println("Directory contents:");
  eFLASH.fs_listDir();
}

void loop() {
}

After that, using an actual code for this project, I just simply read that to an EXTMEM char buffer...
1.PNG
3.PNG

and client.print the whole char array which is a string.
2.PNG

But, I get this as an output
4.jpg

If you pay attention to the html file from client side, client side web browser didn't get the whole html file.
5.PNG
It's actually truncated at the middle of the code for some reason.

Compared to my Teensy 4.0 project to this one, there are three different factors.

- I'm currently using built-in Ethernet module with NativeEthernet.h library.

- Hardware set up looks like this.
20200729_223205.jpg
I just cut off the RJ45 and directly solder it to T4.1.

-Instead of converting a HTML file to a c-string, now I get that using spiffs feature.

Other than that, HTML file and other software components are the same.

Should I just go back to Wiz850 and use a simple Ethernet.h library?

I'm no Ethernet related engineer but willing to learn what is really going on.
Already went over couple different engineering department in our company but no one knows what's the core issue I'm missing.
 
if read right... the desired HTML starts in one place - SD - moves once to place #2 and then is sent to place ethernet - seems it also then moves to SPIFFS?. ... it is all simple ASCII text that in the end isn't looking right?

Note: It will fit into DMAMEM if the needed space is really 373809 bytes, does the behavior change if stored there from SD card? If sent from there directly to the ethernet without going through SPIFFS?

With ASCII text then each transfer - read/write/read should have printable characters perhaps dump it out to USB Serial with each read for use? From SD and From

That may show if there is trouble in the text movement truncating or adding odd characters calling for a hex dump.

If that shows well then the trouble is as suspected in the final ethernet transfer.

Is it unique to this file and length? How many bytes make it in the end where truncated.
 
This is a little out of my lane but interesting problem. @KrisKasprzak posted the other day a similar issue but you may want to take a look at his problem. Maybe it will give you an idea. The thread is at: https://forum.pjrc.com/threads/6210...AX-to-update-a-page-stuck?highlight=html+ajax

EDIT: Confused on something but maybe too may moving pieces.
in one spot you show
Code:
EXTMEM char ART_buf_ART_Webserver[387500];
then when you read the file you have "memset" to zero out the buffer. Not sure memset works on EXTMEM? Maybe somebody else jumps in.

There are a couple of debugging things i would do besides what @defragster mentioned. Try just a simple web page as a check - maybe use a Hello world example.

EDIT2: Are you ending your lines that you put into the file with NLs?
 
Last edited:
Is it safe to use PROGMEM for teensy 4.1?

I have an experience bricking teensy 4.0 while messing around with PROGMEM.
 
PROGMEM is designed to be safe for use on T_4.0 and T_4.1. It puts DATA into FLASH for static storage not using RAM. But with the ARM memory layout it provides directly addressable memory.

If there was a problem it should be shown. Assuming the 'bricking' was fixable with 15second Restore Button press?
 
@defragster

I completely forgot about the existence of DMAMEM. I'm happy to learn more about that.

I tried sending a html file from SD card and it works... which means I gotta so something about SPIFFS side.

But you and mjs513 pointed out critical points, let me test out file transmission and see if I can find any issues.

It could be as simple as a character being null or non-ascii in char array.
 
Last edited:
Status
Not open for further replies.
Back
Top