4.1 Flash memory location address and Memcpy issues with 4.1

bigboosted

Well-known member
Hello Everyone,
Does anyone know the specs on the Flash memory addressing on the 4.1?
I think it starts at x60,000,000 and goes for 8 Mbyte.
Does anyone know where it stops and the EEPROM starts?
Also the location of the restore program?

I've used the memcpy with 4.0 with great success. Now I want to use the 4.1 with its bigger flash memory.
I started to try and figure this out but memcpy does not seem to work past the 4.0 2 Mbyte mark.

For example;
Code:
byte dest[0x100];

memcpy(dest, 0x601F0000, 0x100);
This above code works correct, however;
Code:
byte dest[0x100];

memcpy(dest, 0x60200000, 0x100);
This code will cause the 4.1 to stop responding and require a button press to upload another program.


I'm currently using Arduino 1.8.11 with Teensyduino 1.53

Thanks for any help!
 
Quick help?

from : ...\hardware\teensy\avr\cores\teensy4\imxrt1062_t41.ld

Code:
MEMORY
{
	ITCM (rwx):  ORIGIN = 0x00000000, LENGTH = 512K
	DTCM (rwx):  ORIGIN = 0x20000000, LENGTH = 512K
	RAM (rwx):   ORIGIN = 0x20200000, LENGTH = 512K
	[B]FLASH (rwx): ORIGIN = 0x60000000, LENGTH = 7936K[/B]
	ERAM (rwx):  ORIGIN = 0x70000000, LENGTH = 16384K
}

EEPROM is mapped within the 8MB FLASH.
 
Quick help?

from : ...\hardware\teensy\avr\cores\teensy4\imxrt1062_t41.ld

Code:
MEMORY
{
	ITCM (rwx):  ORIGIN = 0x00000000, LENGTH = 512K
	DTCM (rwx):  ORIGIN = 0x20000000, LENGTH = 512K
	RAM (rwx):   ORIGIN = 0x20200000, LENGTH = 512K
	[B]FLASH (rwx): ORIGIN = 0x60000000, LENGTH = 7936K[/B]
	ERAM (rwx):  ORIGIN = 0x70000000, LENGTH = 16384K
}

EEPROM is mapped within the 8MB FLASH.

Thanks, defragster.
That's what I figured but I am also assuming that both the restore program and the EEPROM are mapped within the 8MB.

Any idea why the memcpy seems to only work within the 4.0 2MB flash area instead of the 4.1 full 8MB Flash?

I just downloaded 1.8.13 and it also does the same thing. Maybe an update for the 4.1 flash size was not added in the memcpy code?
 
Indeed EEPROM and Restore code block are both in the top of respective FLASH. Not sure either would fail reading though?

See this page for more memory details : pjrc.com/store/teensy40.html

Code:
EEPROM Emulation - 60K of Flash memory is reserved for EEPROM emulation. Normally the Arduino EEPROM library is used, but the AVR eeprom functions are also supported for compatibility with legacy code. During uploading, this portion of the Flash is not erased or altered, so your data saved in the "EEPROM" is retained.
Restore Program - When you press the Teensy 4.0 pushbutton for 15 seconds (a quick flash on the red LED will tell you the moment to release), all of the Flash except this 4K is erased, and this known-good LED blink program is copied to the beginning of the Flash. This top 4K is special read-only memory, so you can always use this 15 second button press to fully erase your Teensy 4.0 and restore it to a known-good blink program.

Not seeing any notes on update for that layout of EEPROM and larger Flash on T_4.1 - and T_4.1 EEPROM emulation area is 4284 Bytes instead of 1024 so it will have a larger footprint.
 
I tried but could not reproduce the problem. Here's the code I ran on a Teensy 4.1.

Code:
void setup() {
  while (!Serial) ;
  Serial.println("memcpy test");
  Serial.flush();
  //delay(10);
  byte dest[0x100];
  memcpy(dest, (void *)0x60200000, 0x100);
  //delay(10);
  Serial.println("ok, got here, memcpy didn't crash, right?");
}

void loop() {
}

Here's the result I see in the serial monitor.

sc.png

Normally I don't investigate this sort of problem unless a complete program is posted. But this seemed so simple. Did I not fill in the rest of the program correctly?

Can you please post a complete program I can copy into Arduino and upload to a Teensy 4.1 to get the same problem you're seeing?
 
Just in case the compiler was somehow recognizing nothing uses the dest[] array and optimizing the memcpy() away, I ran this test:

Code:
void setup() {
  while (!Serial) ;
  Serial.println("memcpy test");
  Serial.flush();
  //delay(10);
  byte dest[0x100];
  memcpy(dest, (void *)0x60200000, 0x100);
  //delay(10);
  Serial.println("ok, got here, memcpy didn't crash, right?");
  for (int i=0; i < 0x100; i++) {
    Serial.print(dest[i]);
    Serial.print(",");
    if ((i & 15) == 15) Serial.println();
  }
}

void loop() {
}

Works fine. Still can't reproduce the problem...
 
Here's even one more, which prints the memory where the restore image is located.

Code:
void setup() {
  while (!Serial) ;
  Serial.println("memcpy test - restore image location on Teensy 4.1");
  byte dest[0x1000];
  memcpy(dest, (void *)0x607FF000, 0x1000);
  Serial.println("ok, got here, memcpy didn't crash, right?");
  for (int i=0; i < 0x1000; i++) {
    Serial.print(dest[i]);
    Serial.print(",");
    if ((i & 15) == 15) Serial.println();
  }
}

void loop() {
}
 
Paul,
Thanks for looking into this!

It turns out your correct. I copied your code to a new sketch and it works perfectly. I then went back into my sketch and it didn't work.
It took me a bit but I slowly copied my code into the new sketch testing as I went to see if it still worked.
In the past, I made this test sketch I had copied Bootdata.c to my sketch to view it (copied before 4.1 was released). Apparently, Arduino references the Bootdata.c in my sketch vs the one in the core folder.
I deleted Bootdata.c from my sketch and everything works as it should.


Is the following corect?

Flash memory starts at 0x60000000 ends at 0x607BFFFF
Eeprom area Starts at 0x607C0000 ends at 0x607FEFFF
Restore Program starts at 0x607FF000 ends at 0x607FFFFF

Thanks for the Help!
 
Last edited:
Back
Top