Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 12 of 12

Thread: Teensy 4.1 external flash memory read on software level.

  1. #1
    Member
    Join Date
    Jul 2020
    Location
    California
    Posts
    29

    Teensy 4.1 external flash memory read on software level.

    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 by Han; 07-27-2020 at 10:10 PM.

  2. #2
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    5,878
    @Han
    Good morning.

    Not sure what you want to do here. Have you checked out the structured read/writes examples.

  3. #3
    Member
    Join Date
    Jul 2020
    Location
    California
    Posts
    29
    @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.

  4. #4
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    12,660
    Some early testing was done on file transfers with T_4.1 ethernet code IIRC for speed and function. Find and visit that thread.

  5. #5
    Member
    Join Date
    Jul 2020
    Location
    California
    Posts
    29
    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.
    Click image for larger version. 

Name:	1.jpg 
Views:	17 
Size:	40.5 KB 
ID:	21198

    Then I "client.print" the whole thing like this...
    Click image for larger version. 

Name:	2.PNG 
Views:	21 
Size:	33.4 KB 
ID:	21199

    Output looks like this...
    Click image for larger version. 

Name:	2.jpg 
Views:	15 
Size:	100.9 KB 
ID:	21200
    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.

  6. #6
    Member
    Join Date
    Jul 2020
    Location
    California
    Posts
    29
    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...
    Click image for larger version. 

Name:	1.PNG 
Views:	16 
Size:	1.9 KB 
ID:	21201
    Click image for larger version. 

Name:	3.PNG 
Views:	21 
Size:	12.1 KB 
ID:	21203

    and client.print the whole char array which is a string.
    Click image for larger version. 

Name:	2.PNG 
Views:	19 
Size:	27.4 KB 
ID:	21202

    But, I get this as an output
    Click image for larger version. 

Name:	4.jpg 
Views:	15 
Size:	59.7 KB 
ID:	21204

    If you pay attention to the html file from client side, client side web browser didn't get the whole html file.
    Click image for larger version. 

Name:	5.PNG 
Views:	13 
Size:	57.1 KB 
ID:	21205
    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.
    Click image for larger version. 

Name:	20200729_223205.jpg 
Views:	9 
Size:	124.2 KB 
ID:	21207
    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.

  7. #7
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    12,660
    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.

  8. #8
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    5,878
    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/62108...ight=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 by mjs513; 07-30-2020 at 12:51 PM.

  9. #9
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    5,878
    @Han
    Also take a look at the example Web Server in the Native Ethernet examples.

  10. #10
    Member
    Join Date
    Jul 2020
    Location
    California
    Posts
    29
    Is it safe to use PROGMEM for teensy 4.1?

    I have an experience bricking teensy 4.0 while messing around with PROGMEM.

  11. #11
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    12,660
    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?

  12. #12
    Member
    Join Date
    Jul 2020
    Location
    California
    Posts
    29
    @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 by Han; 07-30-2020 at 07:42 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •