I see on compile log, some "free" memory left.
I want to increase a buffer to make use of it.
But the code of my project crashes. Why?
Here, compile log when it still works:
Now, I change a definition, from:
to:
which means: increase an unsigned char buffer size from 128K to (128K + 32K) now.
The compile log is now this:
It makes sense:
now 50784 free (before 83552), so: 32768 bytes more now used (my exact 32K increase on buffer size).
it looks still ok, still some "free" left, no complains. All compile clean. No code changes, just a bit larger buffer.
BUT THE FW CRASHES!
I wait for UART: LUCKILY!
When I start terminal on PC - my FW crashes!
Nothing on terminal!
And I see a flashing LED: 2x with pause
The generate FW has crashed, even without any complains from linker, no code changes, nothing really modified (just a buffer size increased).
Remark:
How to recover from it?
As long as I see this flashing LED - I cannot flash the board anymore
(sure, it runs in Hardfault Handler endlessly for the rest of its life, the bootloader is dead).
Luckily, when I press the program button again - and I do NOT start my UART terminal (MCU still waiting for it),
the boot loader is alive again (due to waiting for Serial).
But it tells me this:
If you do not wait for UART and your FW crashes on startup- you do not have a chance to recover the board
(just by this 'trick' to press program button long enough until the "blinky" is flashed)
Conclusion:
Never write your FW in a way that it would NOT wait for Serial connected!
This "waiting for Serial" gives you the option to re-flash again, but when running immediately (without waiting) into issues:
your board is almost bricked.
My main concern:
Why I cannot make use of this "free" memory reported?
I want to increase a buffer to make use of it.
But the code of my project crashes. Why?
Here, compile log when it still works:
Code:
Memory Usage on Teensy 4.1:
FLASH: code:270504, data:88660, headers:8448 free for files:7758852
RAM1: variables:178592, code:256712, padding:5432 free for local variables:83552
RAM2: variables:145152 free for malloc/new:379136
Now, I change a definition, from:
Code:
#define SDRAM_SIZE_BYTES (1024 * 32 * 4)
Code:
#define SDRAM_SIZE_BYTES (1024 * 32 * 5)
The compile log is now this:
Code:
Memory Usage on Teensy 4.1:
FLASH: code:270504, data:88660, headers:8448 free for files:7758852
RAM1: variables:211360, code:256712, padding:5432 free for local variables:50784
RAM2: variables:145152 free for malloc/new:379136
It makes sense:
now 50784 free (before 83552), so: 32768 bytes more now used (my exact 32K increase on buffer size).
it looks still ok, still some "free" left, no complains. All compile clean. No code changes, just a bit larger buffer.
BUT THE FW CRASHES!
I wait for UART: LUCKILY!
When I start terminal on PC - my FW crashes!
Nothing on terminal!
And I see a flashing LED: 2x with pause
The generate FW has crashed, even without any complains from linker, no code changes, nothing really modified (just a buffer size increased).
Remark:
How to recover from it?
As long as I see this flashing LED - I cannot flash the board anymore
(sure, it runs in Hardfault Handler endlessly for the rest of its life, the bootloader is dead).
Luckily, when I press the program button again - and I do NOT start my UART terminal (MCU still waiting for it),
the boot loader is alive again (due to waiting for Serial).
But it tells me this:
If you do not wait for UART and your FW crashes on startup- you do not have a chance to recover the board
(just by this 'trick' to press program button long enough until the "blinky" is flashed)
Conclusion:
Never write your FW in a way that it would NOT wait for Serial connected!
This "waiting for Serial" gives you the option to re-flash again, but when running immediately (without waiting) into issues:
your board is almost bricked.
My main concern:
Why I cannot make use of this "free" memory reported?