T4 Data in Flash

Status
Not open for further replies.

luni

Well-known member
I'm confused about how to place data in the Flash.

What I understood so far:
Code:
const char buffer[500*1024] = {0};

void setup()
{
   Serial1.println(buffer);
}

void loop(){}

places 500kB in the flash. The startup code tries to copy this to DTCM which will fail because there is not enough space in DTCM. Compiling this code indeed gives a linker error complaining about an overflow. Here the linker output:

Code:
Memory region         Used Size  Region Size  %age Used
       ITCM:        6772 B       512 KB      1.29%
       DTCM:      524992 B       512 KB    100.13%
        RAM:          0 GB       512 KB      0.00%
      FLASH:      525012 B      1984 KB     25.84

c:/toolchain/gcc/gcc-arm-none-eabi-5_4-2016q3-20160926-win32/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/bin/ld.exe: address 0x200802c0 of .vsteensy/build/TestProject.elf section `.bss' is not within region `DTCM'

If I add PROGMEM to the buffer definition it should not copy the buffer to the RAM

Code:
PROGMEM const char buffer[500*1024] = {0};

void setup()
{
   Serial1.println(buffer);
}
void loop(){}

Which it doesn't, according to the linker output:
Code:
[LD]  .vsteensy/build/TestProject.elf 
Memory region         Used Size  Region Size  %age Used
            ITCM:        6772 B       512 KB      1.29%
            DTCM:       12992 B       512 KB      2.48%
             RAM:          0 GB       512 KB      0.00%
           FLASH:      525012 B      1984 KB     25.84%
User code built and linked to libraries 

[HEX] .vsteensy/build/TestProject.hex
[LST] .vsteensy/build/TestProject.lst 
Sucessfully built project
So far so good. However, Teensy.exe as well as tyTools complain that the file is too large and don't upload. Any idea what I misunderstood?

Here a snippet from the Teensy.exe log
Code:
...
21:36:54.542 (post_compile 24): Sending command: comment: Teensyduino 1.48-beta3 - WINDOWS (teensy_post_compile)
21:36:54.638 (loader): File "sketch_sep07a.ino.hex". 525012 bytes, 200% used
21:36:54.638 (loader): File contains data beyond chip size, yikes!
21:36:54.653 (loader): remote cmd from 3772: "dir:C:\Users\lutz\AppData\Local\Temp\arduino_build_879626\"
21:36:54.653 (loader): remote cmd from 3772: "file:sketch_sep07a.ino.hex"
...
 
Last edited:
Was that to upload to a T_4 and not a 3.6 or 3.5 ?

Give a bit more console output ...

SEE FOLLOWING POST

Last code compiled for me - but did FAIL upload as follows with TyCommander:
Code:
"T:\\arduino-1.8.9t4\\hardware\\teensy/../tools/arm/bin/arm-none-eabi-size" -A "T:\\TEMP\\arduino_build_891711/forum.ino.elf"
[B]Sketch uses 525664 bytes (25%) of program storage space. Maximum is 2031616 bytes.
Global variables use 24512 bytes (2%) of dynamic memory, leaving 1024064 bytes for local variables. Maximum is 1048576 bytes.[/B]
T:\TyComm\TyCommanderC.exe upload --autostart --wait --multi T:\TEMP\arduino_build_891711/forum.ino.TEENSY40.hex 
Waiting for user selection
[B][COLOR="#FF0000"]Firmware 'T:\TEMP\arduino_build_891711\forum.ino.TEENSY40.hex' has too many segments[/COLOR][/B]
An error occurred while uploading the sketch

From Teensy.exe I get this 'VERBOSE' - with no upload:
Code:
13:41:04.767 (ports 1): WM_DEVICECHANGE DBT_DEVICEREMOVECOMPLETE
13:41:04.768 (ports 1): remove: loc=usb:0/140000/0/4/6
13:41:04.768 (ports 1): usb_remove: usb:0/140000/0/4/6
13:41:04.768 (ports 1): nothing new, skipping HID & Ports enum
13:41:04.839 (ports 1): WM_DEVICECHANGE DBT_DEVNODES_CHANGED
13:41:04.840 (ports 1): nothing new, skipping HID & Ports enum
13:41:04.841 (loader): Device went offline
13:41:05.089 (loader): HID/win32:  vid:1B80 pid:B406 ver:0100
13:41:05.089 (loader): HID/win32:  vid:046D pid:C534 ver:2901
13:41:05.089 (loader): HID/win32:  vid:046D pid:C534 ver:2901
13:41:05.089 (loader): HID/win32:  vid:046D pid:C534 ver:2901
13:41:05.089 (loader): HID/win32:  vid:046D pid:C534 ver:2901
13:41:05.099 (loader): HID/win32:  vid:1B80 pid:B406 ver:0100
13:41:05.099 (loader): HID/win32:  vid:1B80 pid:B406 ver:0100
13:41:05.099 (loader): HID/win32:  vid:1B80 pid:B406 ver:0100
13:41:05.099 (loader): HID/win32:  vid:0764 pid:0501 ver:0001
13:41:05.129 (ports 1): WM_DEVICECHANGE DBT_DEVICEARRIVAL
13:41:05.131 (ports 1): found_usb_device, id=\\?\usb#vid_16c0&pid_0478#0008fc81#{a5dcbf10-6530-11d2-901f-00c04fb951ed}
13:41:05.131 (ports 1): found_usb_device, loc=usb:0/140000/0/4/6    Port_#0006.Hub_#0004
13:41:05.131 (ports 1): found_usb_device, hwid=USB\VID_16C0&PID_0478&REV_0105
13:41:05.131 (ports 1): found_usb_device, devinst=0000001d
13:41:05.131 (ports 1): add: loc=usb:0/140000/0/4/6, class=HID, vid=16C0, pid=0478, ver=0105, serial=0008fc81, dev=\\?\usb#vid_16c0&pid_0478#0008fc81#{a5dcbf10-6530-11d2-901f-00c04fb951ed}
13:41:05.131 (ports 1): hiddev_from_devinst_list: iface=0
13:41:05.132 (ports 1): found_usb_device complete
13:41:05.133 (ports 1): usb_add: usb:0/140000/0/4/6  [no_device] (Teensy 4.0) Bootloader
13:41:05.161 (ports 1): WM_DEVICECHANGE DBT_DEVNODES_CHANGED
13:41:05.162 (ports 1): hid, found devinst=0000001E
13:41:05.162 (ports 1): hid, path=\\?\hid#vid_16c0&pid_0478#7&206ffd9d&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
13:41:05.162 (ports 1): hid,  opened handle
13:41:05.162 (ports 1):  devinst=0000001E, location=usb:0/140000/0/4/6
13:41:05.162 (ports 1):  vid=16C0, pid=0478, ver=0105, usepage=FF9C, use=0024
13:41:05.162 (ports 1):  devpath=\\?\hid#vid_16c0&pid_0478#7&206ffd9d&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
13:41:05.162 (ports 1): usb_add: usb:0/140000/0/4/6  hid#vid_16c0&pid_0478 (Teensy 4.0) Bootloader
13:41:05.217 (ports 1): WM_DEVICECHANGE DBT_DEVNODES_CHANGED
13:41:05.218 (ports 1): nothing new, skipping HID & Ports enum
13:41:05.339 (loader): Device came online, code_size = 2031616
13:41:05.339 (loader): Board is: Teensy 4.0 (IMXRT1062), version 1.05
13:41:05.339 (loader): ihex: parse error line 1
13:41:05.350 (loader): set background IMG_ONLINE
13:41:05.598 (loader): HID/win32: HidD_GetPreparsedData ok, device still online :-)

EDIT > Teensy will upload and this is the full verbose:

But it doesn't seem to RUN as I see no print?
Code:
PROGMEM const char buffer[500*1024] = {0};

void setup()
{
  while(!Serial);
   Serial1.println(buffer);
}
void loop(){}
 
I got it to upload with TyCommander

When code changed to this:
Code:
PROGMEM const char buffer[500*1024] = {0};

void setup()
{
[B]  while(!Serial);[/B]
[B][COLOR="#FF0000"]   Serial.println(micros());[/COLOR][/B]
}
void loop(){}

Linking everything together...
"T:\\arduino-1.8.9t4\\hardware\\teensy/../tools/arm/bin/arm-none-eabi-gcc" -O2 -Wl,--gc-sections,--relax "-TT:\\arduino-1.8.9t4\\hardware\\teensy\\avr\\cores\\teensy4/imxrt1062.ld" -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 -o "T:\\TEMP\\arduino_build_891711/forum.ino.elf" "T:\\TEMP\\arduino_build_891711\\sketch\\forum.ino.cpp.o" "T:\\TEMP\\arduino_build_891711/..\\arduino_cache_331422\\core\\core_2d2ac97583686748de40bdc1fd01841a.a" "-LT:\\TEMP\\arduino_build_891711" -larm_cortexM7lfsp_math -lm -lstdc++
"T:\\arduino-1.8.9t4\\hardware\\teensy/../tools/arm/bin/arm-none-eabi-objcopy" -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 "T:\\TEMP\\arduino_build_891711/forum.ino.elf" "T:\\TEMP\\arduino_build_891711/forum.ino.eep"
"T:\\arduino-1.8.9t4\\hardware\\teensy/../tools/arm/bin/arm-none-eabi-objcopy" -O ihex -R .eeprom "T:\\TEMP\\arduino_build_891711/forum.ino.elf" "T:\\TEMP\\arduino_build_891711/forum.ino.hex"
"T:\\arduino-1.8.9t4\\hardware\\teensy/../tools/arm/bin/arm-none-eabi-objcopy" -O ihex -R .eeprom "T:\\TEMP\\arduino_build_891711/forum.ino.elf" "T:\\TEMP\\arduino_build_891711/forum.ino.TEENSY40.hex"
"T:\\arduino-1.8.9t4\\hardware\\teensy/../tools/stdout_redirect" "T:\\TEMP\\arduino_build_891711/forum.ino.lst" "T:\\arduino-1.8.9t4\\hardware\\teensy/../tools/arm/bin/arm-none-eabi-objdump" -d -S -C "T:\\TEMP\\arduino_build_891711/forum.ino.elf"
"T:\\arduino-1.8.9t4\\hardware\\teensy/../tools/stdout_redirect" "T:\\TEMP\\arduino_build_891711/forum.ino.sym" "T:\\arduino-1.8.9t4\\hardware\\teensy/../tools/arm/bin/arm-none-eabi-objdump" -t -C "T:\\TEMP\\arduino_build_891711/forum.ino.elf"
"T:\\arduino-1.8.9t4\\hardware\\teensy/../tools/arm/bin/arm-none-eabi-size" -A "T:\\TEMP\\arduino_build_891711/forum.ino.elf"
Sketch uses 13440 bytes (0%) of program storage space. Maximum is 2031616 bytes.
Global variables use 24464 bytes (2%) of dynamic memory, leaving 1024112 bytes for local variables. Maximum is 1048576 bytes.
T:\TyComm\TyCommanderC.exe upload --autostart --wait --multi T:\TEMP\arduino_build_891711/forum.ino.TEENSY40.hex
upload@5889290-Teensy Uploading to board '5889290-Teensy' (Teensy 4.0)
upload@5889290-Teensy Triggering board reboot
upload@5889290-Teensy Firmware: forum.ino.TEENSY40.hex
upload@5889290-Teensy Flash usage: 14 kiB (0.9%)
upload@5889290-Teensy Uploading...
upload@5889290-Teensy Sending reset command
 
I got it to upload with TyCommander
When code changed to this:
Code:
PROGMEM const char buffer[500*1024] = {0};

void setup()
{
  while(!Serial);
   Serial.println(micros());
}
void loop(){}

Yes, because you don't use the array the compiler optimized it completely away...
Here the linker output for your changed code:
Code:
[LD]  .vsteensy/build/TestProject.elf 
Memory region         Used Size  Region Size  %age Used
            ITCM:        6708 B       512 KB      1.28%
            DTCM:       12960 B       512 KB      2.47%
             RAM:          0 GB       512 KB      0.00%
           FLASH:       12948 B      1984 KB      0.64%
User code built and linked to libraries
 
For what it is worth, this built and run on T4...
Code:
PROGMEM const char buffer[500*1024] = {0};

void setup()
{
  while(!Serial && millis() < 5000);
  uint32_t sum = 0;
  for (uint32_t buffer_index = 0; buffer_index < sizeof(buffer); buffer_index++) {
    sum += buffer[buffer_index];
  }
   Serial.printf("size:%u, sum: %u\n", (uint32_t)sizeof(buffer), sum);
}
void loop(){}
Output:
Code:
size:512000, sum: 0

Build info, my extended version:
Code:
FlexRAM section ITCM+DTCM = 512 KB
    Config : aaaaaaab
    ITCM :  22880 B	(69.82% of   32 KB)
    DTCM :  12992 B	( 2.64% of  480 KB)
    Available for Stack: 478528
OCRAM: 512KB
    DMAMEM:   8272 B	( 1.58% of  512 KB)
    Available for Heap: 516016 B	(98.42% of  512 KB)
Flash: 544272 B	(26.79% of 1984 KB)
 
I just got the latest github.com/KurtE/imxrt-size - will need to get that back into my build so I can see such things.

Good follow up KurtE … was in a rush to get back on task and have lunch ready :)

Indeed it did initially FAIL - and got odd result from Teensy.exe - quickly extended it dropping the buffer and reposted without looking.
 
@Kurt, tried your sketch, it kind of uploads when uploaded from the IDE (you see the process in the verbose log) but it then breaks (timeout?) and never reboots.

Loading the same hex file directly with Teensy.exe immediately fails.
Code:
01:14:14.734 (loader): Open File event
01:14:16.385 (loader): File "sketch_sep07a.ino.hex". 543788 bytes, 207% used
01:14:16.385 (loader): File contains data beyond chip size, yikes!

I can't help it it looks like there is something not working correctly if the flash size gets larger than the 512kB.
 
Ok, I know whats wrong: I had a old version of Teensy.exe. Updated to the current version now everything works as it should.

Sorry for the noise....
 
Something seemed off for first post #2 comment :: Was that to upload to a T_4 and not a 3.6 or 3.5 ?

Still odd that I got odd behavior from TyComm - not having any Valid print made it unsure when the code loaded to run too:
Code:
void setup()
{
  while(!Serial);
 
Status
Not open for further replies.
Back
Top