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

Thread: [Teensy 3.6] Max size memory

  1. #1

    [Teensy 3.6] Max size memory

    Hi,
    I would like to know what is the maximum memory size for:
    - RAM
    - HEAP
    and the maximum size for the receive buffer for Serial5
    Thank you for your help.

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,309
    Quote Originally Posted by andromeda View Post
    I would like to know what is the maximum memory size for:
    - RAM
    256K.

    - HEAP
    All of the RAM not used by your global/static variables, plus the stack (which is mostly your local variables).

    I hope you can understand there is no single answer, as it depends on the program you write.

    and the maximum size for the receive buffer for Serial5
    64K.

  3. #3
    thank you for your answer, it is especially the buffer port serial5 which poses me problem because I use a esp-01 to recover an image via http, when the image is greater than 64k the program no longer works, so we are limited to 64k, I change the value of the receive buffer to 64000 on file Serial5.c, if I put a higher value it does not work, how to recover data greater than 64k via serial port.

  4. #4
    Senior Member+ MichaelMeissner's Avatar
    Join Date
    Nov 2012
    Location
    Ayer Massachussetts
    Posts
    3,069

    Cool

    Quote Originally Posted by andromeda View Post
    thank you for your answer, it is especially the buffer port serial5 which poses me problem because I use a esp-01 to recover an image via http, when the image is greater than 64k the program no longer works, so we are limited to 64k, I change the value of the receive buffer to 64000 on file Serial5.c, if I put a higher value it does not work, how to recover data greater than 64k via serial port.
    I would suspect you may be running into data overflow issues. I don't know if the ESP-01 supports serial port flow control (CTS - clear to send and RTS - request to send), but if it does, you probably want to use that. On the Teensy, 3.6, the CTS pin must be on a specific pin (pin 24 on the Teensy 3.5/3.6 for Serial5), and RTS can be any pin. However, you might want to see if you can arrange your pins to use Serial1 or Serial2 as these two serial ports have an 8 byte hardware FIFO buffer that can allow for higher speeds with less interrupt latency:


  5. #5
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    5,053
    Again hard to say, without knowing what you are doing in your code?

    I almost never need to increase the size of the Serial buffer, but if needed, simply read in the data into my own buffer that I control the size of.

    That is there are many ways to do this:
    a) Have code in my main loop that checks for data available: while (Serial5.available()) {myBuffer[my_buffer_index++] = Serial5.read(); }
    b) Use the Serial Event type code, to do the same.
    c) If it is call coming at once, again just loop reading in the data, or call Serial5.readBytes(my_buffer, image_size); (Which has a timeout)...

    So again without knowing more about your program it is sort of hard to suggest what you should do.

  6. #6
    i use teensy 3.6 with esp8266-01 with library WiFiEsp and FT813 newhavendisplay , i connect esp-01 to an url with image and i save the image on the sd card, this work well with image less than 64k. the code for receive data on buffer is :

    Code:
    long CHTTP::ReceiveData()
    {
      m_nRcvBufLen = 0;
      unsigned int totalBytes = 0;
      int retval = 0;
    
      assert(RecvBuf);
    
      if (RecvBuf == NULL) {
        LOGERROR(ECSock::GetErrorText(ECSock::RECVBUF_IS_EMPTY));
        while (true);
      }
    
      memset(RecvBuf, 0, BUFFER_SIZE);
    
      while (m_client.available())
      {
        if (totalBytes >= BUFFER_SIZE)
        {
          LOGERROR(ECSock::GetErrorText(ECSock::LACK_OF_MEMORY));
          while (true);
        }
    
        totalBytes += retval;
        char c;
    
        if ((c = m_client.read()) != -1) {
          retval = 1;
          memcpy(&RecvBuf[totalBytes], &c, retval);
        }
    
      }
      m_nRcvBufLen = totalBytes;
      RecvBuf[m_nRcvBufLen] = '\0';
    
      LOGINFO1("Len data received: ", m_nRcvBufLen);
    
      return m_nRcvBufLen;
    }
    BUFFER_SIZE is define with 64000 value.

    char RecvBuf [BUFFER_SIZE];

    the problem is not the code, is a problem for Serial, because esp-01 retrieve data from teensy serial.

    i can't use RX2/TX2 and RX3/TX3 because i use this pin with FT813, the RX1/TX1 is reserved for serial usb it seem ?
    Last edited by KurtE; 08-06-2019 at 03:14 PM. Reason: Code tag

  7. #7
    may be the problem is for WiFiEsp library m_client is variable WiFiEspClient m_client; and m_client.read() come to WiFiEsp library, may be, esp-01 can not deliver more than 64k.

  8. #8
    you are right, the AT firmware pushes the response data without control i read data fast to 115200, lose some bytes and time out.
    I will try to change the baud to 9600 or use the control flow RTS / CTS
    thanks for your help.

  9. #9
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    5,053
    I assume if you are trying to receive something > 64K that you change BUFFER_SIZE in your code above which you have defined as 64000 so anything bigger will trash memory.

    Note sure what you are saying about RX1/TX1? Serial object uses the built in USB code native to the teensy. Serial1 is defined for those pins. Also on T3.x Serial1 and Serial2 have the bigger hardware buffers than the other Serial ports have, so they are the best ones to use and not lose any data.

    Also I am not sure why you are using memcpy? and the like in your loop? If available() returns non-zero than you don't need to check for -1 on read...
    You can probably reduce that loop to something like:
    Code:
    while (m_client.available())
      {
        if (totalBytes >= BUFFER_SIZE)
        {
          LOGERROR(ECSock::GetErrorText(ECSock::LACK_OF_MEMORY));
          while (true);
        }
    
        RecvBuff[totalBytes] = m_client.read);
        totalBytes++;
    
      }

  10. #10
    Senior Member+ MichaelMeissner's Avatar
    Join Date
    Nov 2012
    Location
    Ayer Massachussetts
    Posts
    3,069
    Quote Originally Posted by andromeda View Post
    i can't use RX2/TX2 and RX3/TX3 because i use this pin with FT813, the RX1/TX1 is reserved for serial usb it seem ?
    Assuming you mean RX1 and TX1 on the Teensy (i.e. pins 0 and 1), those pins are used for the hardware serial1 port. They are NOT used for USB communications. On some other chips using the Arduino software, pins 0 and 1 indeed are used for both USB and the hardware serial port (such as the Arduino UNO, which has a separate chip that reads pins 0/1 and does USB), but not the Teensy 3.x and LC microprocessors.

    So if you are reading the documentation with the ESP-01 chip, it may mention this because there are boards that do use pins 0/1 for both communications.

  11. #11
    Yes BUFFER_SIZE is modified accordingly.
    I use memcpy because I get binary data, if the character is <32 for example 0 or 2, are not ascii code, suddenly the character string is cut as soon as I receive a 0. I will try RX1, for instance i use 9600 bauds, i can write more 64k, for text file and binary data but for binary file (from image png) not all data is write, i can open image but at bottom is black, the lenght of data for my response url is ok. when i get data from response url i get only stream for write to file, the position after \r\n\r\n is a data binary

    //Write raw data receive buffer to file
    void CHTTP::WriteRawDataHTMLToFile()
    {
    char *p = NULL;

    //assert(RecvBuf);

    if (RecvBuf == NULL) {
    LOGERROR(ECSock::GetErrorText(ECSock::RECVBUF_IS_E MPTY));
    while (true);
    }

    if (!m_sFileName.length()) {
    LOGERROR(ECSock::GetErrorText(ECSock::FILENAME_IS_ EMPTY));
    while (true);
    }

    p = RecvBuf;
    p = strstr(RecvBuf, "\r\n\r\n");
    p = p + 4;

    long lenResponse = (long)((char *)p - (char *)RecvBuf);
    long lenStream = (long) ((char *)(&(RecvBuf[m_nRcvBufLen])) - (char *)p); //(RecvBuf + m_nRcvBufLen) - p;

    Serial.println(lenResponse); Serial.println(lenStream); Serial.println(m_nRcvBufLen);

    if (m_bAscii)
    {
    File myFile = SD2.open(m_sFileName.c_str(), FILE_WRITE);
    if (myFile)
    {
    myFile.print(&RecvBuf[lenResponse]); <= ok for text file
    LOGINFO1("Text file writing successfully!", myFile.size());
    myFile.close();
    delay(500);
    }
    else
    LOGERROR(ECSock::GetErrorText(ECSock::WRITE_FILE_E RROR));
    }
    else
    {
    File myFile = SD2.open(m_sFileName.c_str(), FILE_WRITE);
    if (myFile )
    {
    myFile.write(&RecvBuf[lenResponse], lenStream); <== problem is here
    LOGINFO1("Binary file writing successfully!", myFile.size());
    delay(500);
    myFile.close();
    }
    else
    LOGERROR(ECSock::GetErrorText(ECSock::WRITE_FILE_E RROR));
    }

    p = 0;
    }

  12. #12
    Problem resolved using RX1\TX1 at 9600 bauds all work fine, i can receive image from http and display it to FT813.

    what exactly is Serial5 used for if it does not work, I guess it's just to recover some data or to send some commands. the data must be short ?

    thanks for MichaelMessner and to KurtE.

Posting Permissions

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