Is it possible to load Teensy4.1 if total data in .hex file exceeds MAX_MEMORY_SIZE?

Status
Not open for further replies.

edsut

Well-known member
Hi,
Apologies if this is already addressed somewhere, I couldn't find anything...
I was attempting to program Teensy4.1 with a .hex file and I kept getting
this error message:

error reading intel hex file "nxp_fmurt1062-v1_default.hex"

After digging a bit, I realized it was because my hex file exceeds the MAX_MEMORY_SIZE value in teensy_loader_cli.c.
I'm guessing that this is not something I can just increase to avoid the read error, true?
Since there is ~8M available on Teensy4.1, is there a way to burn an image that is more than 1M?
Ed
 
If building in the IDE with verbose output enabled the console should detail the memory usage issue.

In total the Flash of 8MB can all be used for code and data.

Though by default all code and non CONST data generally goes into 512MB RAM1 of ITCM and DTCM region.

CONST or static data can be left in Flash or dynamic data used from DMAMEM.

Code not marked FLASHMEM will be loaded to run from the ITCM region. ITCM is loaded first and reduces the room for DTCM.

See this post and linked info: Padding-Blowout!
 
It depends: If you look at the memory diagram on T4 pages...
https://www.pjrc.com/store/teensy41.html#memory

teensy41_memory.png


You will see there are things that do not get copied down into RAM1 and RAM2...

For example if you have large tables or bitmaps you can leave them in flash:

like: const uint8_t myimage[] PROGMEM = {..... }
This will not be copied down into DTCM but instead will be accessed by flash.

Dito for code:

If you mark a bunch of code like: FLASHMEM void myfunction() {....}
These functions will be accessed directly in FLASH and not copied down to the ITCM part of memory...
 
Last edited:
Thanks to both (@defragster & @KurtE) for the quick responses!

Sorry, still confused...

I'm using Teensy4.1 on a few projects, but in a very non-standard way.
In both cases the Teensy4.1 module is mounted to custom hardware,
I don't use the IDE and I just use teensy_loader_cli as my programmer.
So far this has worked well.

The first project (completed) was bootloader based, so I used teensy_loader_cli
just to install the bootloader, then the bootloader would install the application.
This worked out fine because the bootloader was/is much smaller than 1M.

The second project is not bootloader based, and the application is more than 1M of text,
so it hits the MAX_MEMORY_SIZE limitation that I -believe- is what is snagging me now.
As best I can tell (unless I'm looking at the wrong teensy_loader_cli.c file), this 1M
limit comes from a #define MAX_MEMORY_SIZE value in teensy_loader_cli.c.

Does the IDE use teensy_loader_cli to burn the image?
Assuming it does, how does it get around this?
 
One more note...
I tried just changing MAX_MEMORY_SIZE to 0x400000 in teensy_loader_cli.c and that seems to work.
Empirical data can be deceiving. Is that a safe change?
Ed
 
Simple answer first: No the ide does not use teensy_loader_cli, it uses the teensy app.

But what is more important is how is it built. Are you using the Teensy core files and the like either through makefiles, arduino IDE...

Again if you have a lot of code, then marking a bunch of it to run from FLASH as I mentioned above will have it run that code from the FLASH address space and not the RAM1 address space.

If your "Text" is some form of constant data, then moving it to PROGMEM helps a lot as to keep it from being copied down by the startup code:
Lots of the secrets to this are in the <install point?/hardware/teensy/avr/cores/teensy4/startup.c

An example sketch that does this, that is installed with the teensy install is in the ST7735_t3 examples: uncannyEyes_async_st7789_240x240
This is setup for Large images which wont fit in the lower memory.

In this, the code keeps all of the data up in FLASH...

There are lots of large data in the default_large.h file part of the setup... Note: You probably won't see this file up in the arduino ide as it is stored in subdirectory graphics.


Code:
#define SCLERA_WIDTH  375
#define SCLERA_HEIGHT 375

const uint16_t sclera[SCLERA_HEIGHT][SCLERA_WIDTH] PROGMEM = {
  0x6901, 0x6901, 0x6901, 0x6901, 0x6901, 0x6901, 0x6901, 0x6901,
...
 
Thanks again...
I guess my question is a bit more fundamental.
I realize I'm jumping around in space that probably isn't heavily played in, but that's my problem...

All I really want to know is whether or not it is legal for me to have a .hex file that
starts off at 0x60000000 and has 5M of data that should be programmed into the flash
linearly.

After making the modification to teensy_loader_cli.c so that MAX_MEMORY_SIZE allows it,
I have not empirically seen any problems. I just want to make sure that HalfKay really
allows this. I'm coming to the conclusion, based on what you've told me, that it does, and
that changing MAX_MEMORY_SIZE (in teensy_loader_cli.c) to something much larger
(but less than 8M) is safe for Teensy4.

Actually, if my suspicion is correct, it seems to me the value of MAX_MEMORY_SIZE should
be dynamic, based on the CPU selected by -m.
 
Status
Not open for further replies.
Back
Top