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

Thread: Teensy 4.1, put code in FLASHMEM by default instead of RAM1

  1. #1

    Teensy 4.1, put code in FLASHMEM by default instead of RAM1

    Hello,

    I'm building a portable synth with teensy 4.1, which includes a touch screen GUI built with LVGL graphics library.
    The code became really large as the project grew, it's now more than 250K and does not fit in RAM1.
    I understand that all functions are treated as FASTRUN by default, so they are copied to RAM1.
    Is there a way to only put them in Flash by default? I have tried tinkering with the linker file but had no luck.

    Thanks!

  2. #2
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    16,196
    Putting "FLASHMEM" as a prefix to the function prototype will have it reside in FLASH.

    This example from PJRC's Startup.c for example:
    Code:
    FLASHMEM void configure_external_ram()
    {
    ...
    }
    Start with any one time use or non critical code and see what else is needed.

    Looking at the console build output will give an idea of how far away the next 32KB boundary is based on the padding present for the ITCM region.

    More info on memory on the PJRC T_4.1 product page

  3. #3
    Thanks for the reply.

    Most of the code size comes from the libraries I used, not the code I wrote. I know I can put the FLASHMEM prefix to library functions, but libraries like LVGL are so large that it would not be feasible to do that. Is there a way to put them in FLASH by default?

  4. #4
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    16,196
    This thread pjrc.com/threads/69185-FLASHMEM-for-all-functions-in-a-file

    Has tips on .LD file edits that keep ALL code in FLASH - and notes on pulling select code to RAM.

  5. #5
    The .ld file edits did not work. The code compiles, but the teensy will crash right at startup.

    However, I did use the memory inspection tool in platformIO and moved some large variables in the libraries into DMAMEM. Also moved some one-time use functions into FLASHMEM. Now the code fits! Thanks for the help.

  6. #6
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    16,196
    good to find a non .ld solution.

    Edits to that .ld are non-trivial and have systemic ties

Posting Permissions

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