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

Thread: Targeting Teensy 4.1 uses 5x as much dynamic memory as Teensy 3.6

  1. #1
    Junior Member
    Join Date
    Oct 2018
    Posts
    8

    Targeting Teensy 4.1 uses 5x as much dynamic memory as Teensy 3.6

    This is only a curiosity at this point. I have been working on a project using the Teensy 3.6 and decided it would be interesting to see if it would even compile when targeting the Teensy 4.1. I switched from using TeensyDelay for the timers, to using TeensyTimerTool in order to get it to compile without error. I am using Teensyduino 1.52 / Arduino 1.8.12. The 5X increase in dynamic memory strikes me as being a bit unusual, so I am only interested in knowing if this could possibly be expected.

    This is memory usage when compiled for the Teensy 4.1:

    Sketch uses 114272 bytes (1%) of program storage space. Maximum is 8126464 bytes.

    Global variables use 139956 bytes (26%) of dynamic memory, leaving 384332 bytes for local variables. Maximum is 524288 bytes.


    This is memory usage when compiled for the Teensy 3.6:

    Sketch uses 107216 bytes (10%) of program storage space. Maximum is 1048576 bytes.

    Global variables use 25484 bytes (9%) of dynamic memory, leaving 236660 bytes for local variables. Maximum is 262144 bytes.
    The project uses the following libraries:

    Using library ILI9341_t3 at version 1.0
    Using library SPI at version 1.0
    Using library ADC at version 8.0
    Using library SdFat-beta-master at version 2.0.0-beta.6
    Using library USBHost_t36 at version 0.1
    Using library TeensyTimerTool-master at version 0.1.9
    Using library Encoder at version 1.4.1
    Using library XPT2046_Touchscreen at version 1.3
    I would like to see if I can move my project to the Teensy 4.1 without major breadboard changes. That is what prompted me to do this comparison, without knowing how practical it might be to make the change.

    Thanks,

    Chuck

  2. #2
    Senior Member
    Join Date
    Oct 2015
    Location
    Roma (IT, EU)
    Posts
    312
    With the "Blink" example it's even worse: using "Faster" (1.8.12 + 1.52)

    BLINK
    Code:
    T3.6:
    Sketch uses 10724 bytes (1%) of program storage space. Maximum is 1048576 bytes.
    Global variables use 3828 bytes (1%) of dynamic memory, leaving 258316 bytes for local variables. Maximum is 262144 bytes.
    
    T4.1:
    Sketch uses 14688 bytes (0%) of program storage space. Maximum is 8126464 bytes.
    Global variables use 41660 bytes (7%) of dynamic memory, leaving 482628 bytes for local variables. Maximum is 524288 bytes

  3. #3
    Junior Member
    Join Date
    Oct 2018
    Posts
    8
    Interesting, thanks for that information. I never thought about trying the simple case.

  4. #4
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    6,624
    My guess it is something like, differences in some of the buffers, like USB. And of course you do have the other 256KB of DMAMEM available to you as well.

  5. #5
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    21,812
    On Teensy 4.x, the main 512K RAM1 bank is divided into ITCM and DTCM, where I=Instructions and D=Data. ITCM is used by default for functions, unless you add "FLASHMEM" to them. The FlexRAM hardware supports memory partitioning in 32K chunks, so even if you have only 1 small function in ITCM, a minimum of 32K must be allocated. Most of that memory usage Arduino is reporting is one 32K chunk dedicated to ITCM.

    ITCM is basically zero wait memory with a wide 64 bit bus directly to the M7 processor. Code runs extremely fast from ITCM. Caching is never used with ITCM because it's as fast as the M7 caches, so you also get very consistent & deterministic speed.

    All code not in ITCM shares a 32K cache. Usually that gives excellent performance for normal code, though cache misses are quite slow if the code is executing from the flash chip (what "FLASHMEM" does). Normally FLASHMEM is used with startup code. But if your program becomes large, you would probably want to start using FLASHMEM on functions where performance is less important.

  6. #6
    Junior Member
    Join Date
    Oct 2018
    Posts
    8
    KurtE and Paul: Thanks, sounds like it is to be expected. The 4.1 has more than enough memory for me even with this, so it is good to know nothing bad is going on. I am new to all of this, so it is great to have this forum as a resource. I will go ahead and order a 4.1 to experiment with in parallel with my several 3.6 modules while continuing to work on the project.

    Thanks again.

  7. #7
    Senior Member
    Join Date
    Oct 2015
    Location
    Roma (IT, EU)
    Posts
    312
    Excellent explanation Paul, thanks.
    To be honest there were already bits of explanations across the various 4.x topics, but this message should really be in the T4.x web pages, IMHO.

  8. #8
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    11,490
    This product page has lots of 4.0 details that generally apply to 4.1 as well for the 1062 aspects:: pjrc.com/store/teensy40.html

    It gives a larger explanation of memory on the 1062 processor

  9. #9
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,874
    Yup.

    quote. "Teensy 4.0 is the latest Teensy, "
    "Teensy 3.6Teensy 3.6 with Pins – The Most Powerful Teensy"

    I'll take a break.

  10. #10
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    11,490
    Teensy 4.0 is the latest Teensy, offering the fastest microcontroller and powerful peripherals in the Teensy 1.4 by 0.7 inch form factor
    too picky Frank ... full context:
    Teensy 4.0 is the latest Teensy ... in the Teensy 1.4 by 0.7 inch form factor

    And to update for the T_4.1::
    Teensy 4.1 is the latest Teensy ... in the Teensy 2.4 by 0.7 inch form factor

    Good to see updates on the PJRC website

  11. #11
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,874
    Interrupt Service Routine Syntax

    To use interrupts, you must include the AVR interrupt header.
    #include <avr/io.h>
    #include <avr/interrupt.h>
    --etc

    For debug:
    #include <usb_debug_only.h>

    --etc

  12. #12
    Senior Member
    Join Date
    Oct 2015
    Location
    Roma (IT, EU)
    Posts
    312
    Quote Originally Posted by defragster View Post
    This product page has lots of 4.0 details that generally apply to 4.1 as well for the 1062 aspects:: pjrc.com/store/teensy40.html

    It gives a larger explanation of memory on the 1062 processor
    A user reads this (Teensy 4.0):
    https://www.pjrc.com/store/teensy40.html
    "1024K RAM (512K is tightly coupled)
    2048K Flash (64K reserved for recovery & EEPROM emulation) "

    And this (Teensy 3.6):
    https://www.pjrc.com/teensy/techspecs.html
    "256K RAM
    1024K flash"

    and should figure out by himself that actually there are cases where his sketches could fit the 3.6 but not the 4.x?

    I humbly think this is asking too much.

  13. #13
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,874
    There could be a very simple fix for this which would make the T4.x more compatible to the older models by optionally switching to a different linkage.
    But this has not found much love I don't know why. ... which reminds me, I still have to close the PR.

  14. #14
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    11,490
    Quote Originally Posted by Frank B View Post
    There could be a very simple fix for this which would make the T4.x more compatible to the older models by optionally switching to a different linkage.
    But this has not found much love I don't know why. ... which reminds me, I still have to close the PR.
    Referring to this work Frank? - just posted on similar thread :: T4-0-Memory-trying-to-make-sense-of-the-different-regions

  15. #15
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,874
    yes.
    For the history: This is the now closed pull request (without the boards.txt - did not know where to do a PR for it.)
    https://github.com/PaulStoffregen/cores/pull/440

  16. #16
    Senior Member
    Join Date
    Jul 2014
    Posts
    2,637
    Quote Originally Posted by Frank B View Post
    There could be a very simple fix for this which would make the T4.x more compatible to the older models by optionally switching to a different linkage.
    But this has not found much love I don't know why. ... which reminds me, I still have to close the PR.
    That is why I use Makefiles for projects that do not need to be Arduino compatible, or where the word Arduino has a bad taste.

  17. #17
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,874
    Since the weather is getting better now and I have other hobbies and will move, I will leave this forum again for a while.

    @all: Stay healthy. Keep the distance.
    Best wishes,
    Frank.

  18. #18
    Senior Member
    Join Date
    Oct 2015
    Location
    Roma (IT, EU)
    Posts
    312
    Quote Originally Posted by Frank B View Post
    There could be a very simple fix for this which would make the T4.x more compatible to the older models by optionally switching to a different linkage.
    Indeed it would be an excellent solution.

    For example, it could have been called automatically by the toolchain when the user selects "Smallest Code" (which means it has memory occupation issues).

  19. #19
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    11,490
    Quote Originally Posted by Frank B View Post
    Since the weather is getting better now and I have other hobbies and will move, I will leave this forum again for a while.

    @all: Stay healthy. Keep the distance.
    Best wishes,
    Frank.
    Moving? A new residence - or getting out for exercise moving?

    Stay well, looking forward to your next posts.

  20. #20
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,874
    A new residence.

    @WMXZ, why not do a step more and switch to MBED or MCUxpresso?
    I'll use the time off to think about it.
    Last edited by Frank B; 05-20-2020 at 11:35 AM.

Posting Permissions

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