Moderator Edit: linker script is fine, see this message for info.
I can confirm now, the linker script for Teensy 4.1 is really wrong:
It has this original definition:
(see the 512K for DTCM and ITCM, both, in total as 1.5MB memory available - not true)
But it should have this definition:
(ITCM and DTCM: each 256K, in sum 512K, startup configures as 256K each)
The difference is:
When I compile my project with MODIFIED linker script (256K each), I get this as compile results:
It tells me:
RAM1 as 512K total, but 256K ITCM and 256K DTCM, the code: 262104 plus padding: 40 results in 262,144 bytes = exactly 256KB.
And it works.
And it makes complete sense.
But with the original linker script, where ITCM as well as DTCM are set as 512K each - I get this compile result (error free !!!!) - and with a tiny bit more of code in ITCM:
This is compile error free (!!!!) and tells me:
RAM1 has now code: 262360 plus padding: 32552 (MUCH MORE PADDING NOW!), but the total is: 292,912 bytes = 288 KB (for ITCM).
THIS IS WRONG!!!
This MCU and the startup config has just 256K ITCM (and 256K DTCM)!
It "must" crash - and it does!
I am waiting for UART (luckily):
right afterwards it crashes, with double blinking LED and nothing works anymore.
Not possible to flash this board again in this state (as long as you see a double blinking LED).
Due to waiting for UART - I have still a chance to flash the board again.
Imagine:
I would not wait for UART and run into this "crash" immediately - no way to flash the board again.
It would be dad forever.
The "test source code" is here:
https://github.com/tjaekel/Teesny_4_1
See in file "cmd_dec.cpp" for command "CMD_test" the additional code generated:
I can confirm now, the linker script for Teensy 4.1 is really wrong:
It has this original definition:
Code:
MEMORY
{
ITCM (rwx): ORIGIN = 0x00000000, LENGTH = 512K
DTCM (rwx): ORIGIN = 0x20000000, LENGTH = 512K
RAM (rwx): ORIGIN = 0x20200000, LENGTH = 512K
FLASH (rwx): ORIGIN = 0x60000000, LENGTH = 7936K
ERAM (rwx): ORIGIN = 0x70000000, LENGTH = 16384K
}
But it should have this definition:
Code:
MEMORY
{
ITCM (rwx): ORIGIN = 0x00000000, LENGTH = 256K
DTCM (rwx): ORIGIN = 0x20000000, LENGTH = 256K
RAM (rwx): ORIGIN = 0x20200000, LENGTH = 512K
FLASH (rwx): ORIGIN = 0x60000000, LENGTH = 7936K
ERAM (rwx): ORIGIN = 0x70000000, LENGTH = 16384K
}
The difference is:
- the original one does not fail on compile, does not complain if ITCM overflows! It let me generate more code as possible - which will crash!
- Also an overflow on the DTCM will not be reported (too much data) - might also crash!
- at the end: your program will crash and end up in error handler (double flashing LED, dead for flashing again a new FW if you run into it immediately!)
The generated code overflows the MCU memory size - WITHOUT warning.
When I compile my project with MODIFIED linker script (256K each), I get this as compile results:
Code:
Memory Usage on Teensy 4.1:
FLASH: code:277352, data:89084, headers:8344 free for files:7751684
RAM1: variables:183616, code:262104, padding:40 free for local variables:78528
RAM2: variables:149248 free for malloc/new:37504
It tells me:
RAM1 as 512K total, but 256K ITCM and 256K DTCM, the code: 262104 plus padding: 40 results in 262,144 bytes = exactly 256KB.
And it works.
And it makes complete sense.
But with the original linker script, where ITCM as well as DTCM are set as 512K each - I get this compile result (error free !!!!) - and with a tiny bit more of code in ITCM:
Code:
Memory Usage on Teensy 4.1:
FLASH: code:277608, data:89084, headers:9112 free for files:7750660
RAM1: variables:183616, code:262360, padding:32552 free for local variables:45760
RAM2: variables:149248 free for malloc/new:375040
This is compile error free (!!!!) and tells me:
RAM1 has now code: 262360 plus padding: 32552 (MUCH MORE PADDING NOW!), but the total is: 292,912 bytes = 288 KB (for ITCM).
THIS IS WRONG!!!
This MCU and the startup config has just 256K ITCM (and 256K DTCM)!
It "must" crash - and it does!
I am waiting for UART (luckily):
right afterwards it crashes, with double blinking LED and nothing works anymore.
Not possible to flash this board again in this state (as long as you see a double blinking LED).
Due to waiting for UART - I have still a chance to flash the board again.
Imagine:
I would not wait for UART and run into this "crash" immediately - no way to flash the board again.
It would be dad forever.
The "test source code" is here:
https://github.com/tjaekel/Teesny_4_1
See in file "cmd_dec.cpp" for command "CMD_test" the additional code generated:
- it fails if you add more code (more NOP() calls) - set the #if 0 to #if 1 at the end of function NOP() ) - it will FAIL!
- it complains CORRECTLY if you fix the Linker Script (NOT more as 256K ITCM code) - make it correct and it reports correctly
- it does NOT warn you with original Linker Script (about this overflow issue) - you can generate "too much" code and data without warnings!