Author Topic: Serial Loader and EEPROM  (Read 201 times)

Offline Al

  • Newbie
  • *
  • Posts: 12
    • View Profile
Serial Loader and EEPROM
« on: January 18, 2021, 08:09:15 PM »
I have the MSD serial loader working with a custom NXP MK20DX256 board (same processor as on a Teensy 3.1 and 3.2).  I have searched but cannot find how to prevent the serial loader from overwriting the processor EEPROM. 

I did find these lines in app_hw_kinetis.h but am unsure how to use them (or even if they are appropriate).

#define KINETIS_FLASH_CONFIGURATION_EEPROM_PROT        0xff
#define KINETIS_FLASH_CONFIGURATION_DATAFLASH_PROT     0xff

Is this the way to do it and if so what do I set the values to?

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3117
    • View Profile
    • uTasker
Re: Serial Loader and EEPROM
« Reply #1 on: January 18, 2021, 08:33:37 PM »
Hi

The area of Flash deleted by the serial loader is controlled (in Loader.h) by:
#define UTASKER_APP_START  (16 * 1024)                       // application starts at this address (0x4000)
#define UTASKER_APP_END   (unsigned char *)(SIZE_OF_FLASH)   // end of application space - after maximum application size

so the amount that is deleted can be controlled by these defines (specifically the value of UTASKER_APP_END.

However, since SIZE_OF_FLASH is 256k and includes the program flash and not the FlexFlash I wouldn't expect EEPROM data to be affected (unless the data is in program flash rather than FlexFlash).

Regards

Mark


Offline Al

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Serial Loader and EEPROM
« Reply #2 on: January 19, 2021, 12:06:52 AM »
Thanks for the reply, Mark.

The data being deleted is strictly in EEPROM.  I am using the Teensy libraries for this project, specifically:
Code: [Select]
    EEPROM.h - EEPROM library
  Original Copyright (c) 2006 David A. Mellis.  All right reserved.
  New version by Christopher Andrews 2015.
  This copy has minor modificatons for use with Teensy, by Paul Stoffregen

I read the contents of multiple EEPROM locations (including strings) on start-up and write occasionally during code execution.  I have code controlled by a #define to load the EEPROM for test pruposes but this is commented out in application the serial loader uses. 

Do the defines I mentioned in my original post have anything to do with protecting EEPROM?

Thanks
Al


Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3117
    • View Profile
    • uTasker
Re: Serial Loader and EEPROM
« Reply #3 on: January 19, 2021, 12:50:51 AM »
Al

The flash configuration settings allow EEPROM and Data Flash areas to be protected by setting bits to 0.
Data flash is used for EEPROM emulation so I presume that when configured for EEPROM use the data flash is not relevant and the EEPROM bits protect the EEPROM.
When protected I don't know whether they can be unprotected during operation to temporarily allow programing again (I suspect not - I believe the code flash protection bits behave like this).
Since the serial loader doesn't have a driver for the data flash (EEPROM) I doubt that it can be deleting it - possibly there is another explanation (?)

Personally I have never used the EEPROM (EEPROM emulation in data flash) because I found it easier and more flexible to emulate it in software directly in data flash without reconfiguring the memory of the chip.

Regards

Mark


Offline Al

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Serial Loader and EEPROM
« Reply #4 on: January 19, 2021, 03:21:31 AM »
I tried setting both the EEPROM and then both Dataflash and EEPROM protect to zero (from 0xff) and neither worked, i.e. the EEPROM was still overwritten (cleared to 0xFF).  I don't know if further EEPROM operation was permitted or not.  I put the two defines back to 0xff and rebuilt the serial loader

You are probably correct that it is another explanation but at this point I am not sure what that is.  Any ideas?

Offline Al

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Serial Loader and EEPROM
« Reply #5 on: January 19, 2021, 05:05:05 PM »
Could the problem be in my linker load file? 

I am using the "standard" Teensy file (attached) and building the application code using PlatformIO/VSCode which uses the GCC toolchain. I modified the start address to 0x00008080.  I attempted to use K_256_64.ld in the uTasker GNU_Kinetis folder but the linking fails as follows.  I know next to zero about linker scripts.  Do you see anything in here that could cause the EEPROM overwrite?

Code: [Select]
Linking .pio\build\teensy3x\firmware.elf
c:/users/al testani/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/bin/ld.exe: section .fini loaded at [00008080,00008083] overlaps section .text loaded at [00000414,00019723].pio\build\teensy3x\libFrameworkArduino.a(mk20dx128.c.o): In function `ResetHandler':
mk20dx128.c:(.startup+0x17c): undefined reference to `_edata'
mk20dx128.c:(.startup+0x180): undefined reference to `_etext'
mk20dx128.c:(.startup+0x184): undefined reference to `_sdata'
mk20dx128.c:(.startup+0x188): undefined reference to `_sbss'
mk20dx128.c:(.startup+0x18c): undefined reference to `_ebss'
.pio\build\teensy3x\libFrameworkArduino.a(mk20dx128.c.o):(.data.__brkval+0x0): undefined reference to `_ebss'
.pio\build\teensy3x\libFrameworkArduino.a(mk20dx128.c.o):(.vectors+0x0): undefined reference to `_estack'
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\teensy3x\firmware.elf] Error 1

EDIT:  I attached the wrong file.  The correct one is now attached
« Last Edit: January 19, 2021, 05:11:04 PM by Al »

Offline Al

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Serial Loader and EEPROM
« Reply #6 on: January 19, 2021, 07:44:32 PM »
Mark,

The serial loader wasn't clearing out EEPROM, I was! 

When this project is complete I will inialize the EEPROM using external means but right now the way I am initializing EEPROM is using the firmware itself using a #define.  I would run the firmware once to load EEPROM and then turn of the EEPROM #define and load it again, all of that without the serial loader.  Then I would rebuild using *ld file for the serial loader and use a JLINK to load the serial loader.  Well... to load the serial loader I had to erase the chip.  That is where I messed up. Of course the EEPROM was getting cleared!

I can't believe how dumb I was about this!  I apologize for all the confusion.

Al