Teensy 4.1 Memory Uses?

nick703

Member
Hello Friends,
I have Teensy 4.1 and i have a one Program which compile in Atmel studio 7.0 give me message
teensy_size*: Memory Usage on Teensy 4.1
teensy_size*: FLASH: code:110980, data:8164, headers:8852 free for files:7998468
teensy_size*: RAM1: variables:17088, code:108120, padding:22952 free for local variables:376128
teensy_size*: RAM2: variables:12384 free for malloc\new:511904

and when i compile same program using arduinio ide 1.8.15 i got below memory uses
Memory Usage on Teensy 4.1:
FLASH: code:102220, data:8268, headers:8292 free for files:8007684
RAM1: variables:21184, code:99672, padding:31400 free for local variables:372032
RAM2: variables:1632 free for malloc/new:522656

both project compile and working then why is variable and flash memory different?

for fast communication which should i prefer?
 
Not sure that is an Apples to Apples comparison?

Was USB Serial selected the same in both? The RAM2 variables under 2K suggests USB was not selected there?

Building a Blink - very minimal, but with USB Serial - I see this with IDE 1.8.16 and TD 1.55 Beta 2:
Code:
Memory Usage on Teensy 4.0:
  FLASH: code:8348, data:1020, headers:9060   free for files:2013188
   RAM1: variables:8896, code:6656, padding:26112   free for local variables:482624
   [B]RAM2: variables:12384[/B]  free for malloc/new:511904
 
My guess is the Tools > Setting option for USB Type isn't the same.

Using only Arduino 1.8.15 with Teensyduino 1.54, I get this with the default "Serial" setting in Tools > USB Type.

Code:
Memory Usage on Teensy 4.1:
  FLASH: code:9532, data:2332, headers:8612   free for files:8105988
   RAM1: variables:12992, code:6912, padding:25856   free for local variables:478528
   RAM2: variables:12384  free for malloc/new:511904

If I change Tools > USB Type to "RawHID" and all other options at defaults, I get this:

Code:
Memory Usage on Teensy 4.1:
  FLASH: code:9580, data:2460, headers:8436   free for files:8105988
   RAM1: variables:12960, code:6960, padding:25808   free for local variables:478560
   RAM2: variables:1632  free for malloc/new:522656

While neither of these perfectly match the original 2 size, this is with File > Examples > 01.Basics > Blink, and the original is with unknown code, which could easily explain the difference.

But the RAM2 memory usage (which comes from the USB code in these 2 cases) is the same as the 2 shown in msg #1. So I would guess whatever program is being used probably doesn't have any DMAMEM variables, so it gets exactly the same RAM2 usage depending on which Tools > USB Type setting is chosen.
 
Just to make sure I answer this question...

for fast communication which should i prefer?

Assuming the difference really is use of Serial vs RawHID for Tools > USB Type, if you want highest USB communication speed, go with Serial (regardless of which tool compiles the code).

RawHID is limited to 64,000 or 512,000 bytes or second depending on whether the USB runs at 12 or 480 Mbit/sec, because it can transmit at most 1 packet of 64 bytes per frame or micro-frame.

Serial can theoretically use all the USB bandwidth which isn't taken by other devices. In practice the software on the Teensy side and also the PC side is never fast enough to really use it all, but when things are well optimized you can do quite well.

Here is a very simple speed test program. Just run it on your Teensy 4.1 and watch in the Arduino Serial Monitor for how many lines/sec it can print.

https://github.com/PaulStoffregen/USB-Serial-Print-Speed-Test/blob/master/usb_serial_print_speed.ino

If you change between Serial and RawHID, you'll see the pretty incredible difference in speed.

You can also try opening the Serial mode in Arduino's Tools > Ports menu as either "Teensy Ports" (using highly optimized code on the PC side) or "Serial ports" (using Arduino's normal code). If you care about speed, I would highly recommend doing this extremely easy test, so you can see for yourself what an incredible difference the PC side optimization makes. It's the same Teensy running exactly the same code, only different code in the Arduino IDE to receive the data. If you design a special application to receive the data, the way you write the code on the PC has a huge impact on the overall speed!

If using Windows or Mac, you might want to save your work before running those speed tests. The extreme speed can put quite a load on the Arduino IDE and even cause it to lock up or crash in some cases (like using the less optimized "Serial ports" code - the reason the optimized "Teensy Ports" code was written.
 
ok now selection is USB Type to Serial and compile got below memory uses
FLASH: code:102796, data:8148, headers:8860 free for files:8006660
RAM1: variables:17088, code:100248, padding:30824 free for local variables:376128
RAM2: variables:12384 free for malloc/new:511904

still flash code is different ?
 
still flash code is different ?

Maybe it's using the sample makefile, or its own build process similar to that makefile?

The sample makefile just compiles every .cpp and .c file to a .o file, then creates the output using a long list of the .o files. That's simple (the makefile is meant to be a simple example) but not nearly as efficient as the more complex build process Arduino uses.

If you want to see the exact commands Arduino runs, turn on verbose info while compiling in File > Preferences.

But really this is just a blind guess. I've never used Atmel Studio 7.0, and until now I didn't even know anyone had made it work for compiling Teensy code. I can really only answer questions about use of Teensyduino with the Arduino IDE.
 
Back
Top