Can you store and load subroutine in EEPROM in ARM

Thread Starter

Newtoit

Joined Aug 15, 2021
4
Hello,

I was wondering if we can store subroutine of a program inside EEPROM of ARM based Microcontroller.

so the main program runs from flash memory and when it call a specific subroutine then it is run from the EEPROM

Also, there is an external EEPROM which can be used the copy the subroutine to the internal EEPROM.

Basically what I want to do is change part of program by physically changing EEPROM in my circuit without the need the flash the microcontroller again
 

Ian0

Joined Aug 7, 2020
3,761
I use the EEPROM in a NXP LPC1517. According to the datasheet, it can only be read and written by using the IAP routines that they supply in ROM. However, it is perfectly possible to read it with an ordinary LDR instruction, and it doesn't give any hardware errors that it would normally give if trying to read non-existent memory. Therefore it may well execute code from there, but you would be using it outside the recommendations of the datasheet.
You could use the IAP routine to copy the block of EEPROM to RAM and execute it from RAM.
 

sagor

Joined Mar 10, 2019
512
Remember that reading EEPROM is usually very slow compared to regular flash memory. If you could run from EEPROM, your code timing would all go to heck.
You could store code in EEPROM, but for it to run as "code", you would likely need to copy it from EEPROM into some RAM location and then execute the code, somehow.
 

Papabravo

Joined Feb 24, 2006
17,299
It is probably the case that the EEPROM is not even connected in any way to the main address and data bus used for instruction fetch and execution. In most architectures the EEPROM is located in a completely isolated address space.
 

BobTPH

Joined Jun 5, 2013
4,049
Hmm. Must be old technology. In newer PICs, program memory and EEPROM are the same thing, just different addresses.

Bob
 

Papabravo

Joined Feb 24, 2006
17,299
Hmm. Must be old technology. In newer PICs, program memory and EEPROM are the same thing, just different addresses.

Bob
Could be. In the AVR and 16 series PIC devices the EEPROM was the size of data memory (8-bits) while the size of code memory was variable as was the number of bits in the Program Counter or Instruction Address register.
 

AlbertHall

Joined Jun 4, 2014
11,609
On PICs where the program can write to flash, you could read EEPROM and write to flash. I can see some problems with that but it should be possible.
 

Papabravo

Joined Feb 24, 2006
17,299
On PICs where the program can write to flash, you could read EEPROM and write to flash. I can see some problems with that but it should be possible.
In the beginning people thought that executing self modifying code was just about the coolest thing since long pants replaced knickers. Subsequently people wised up and realized what a can of worms it was and it was deprecated. It is still a terrible idea. Doing I/O with chase buffers had me on the edge of my seat waiting for a critical timing flaw to blow everything up.
 

Thread Starter

Newtoit

Joined Aug 15, 2021
4
I use the EEPROM in a NXP LPC1517. According to the datasheet, it can only be read and written by using the IAP routines that they supply in ROM. However, it is perfectly possible to read it with an ordinary LDR instruction, and it doesn't give any hardware errors that it would normally give if trying to read non-existent memory. Therefore it may well execute code from there, but you would be using it outside the recommendations of the datasheet.
You could use the IAP routine to copy the block of EEPROM to RAM and execute it from RAM.
Right, but how should I run it from RAM, can you share any guide were I can get basic idea?
 

BobaMosfet

Joined Jul 1, 2009
1,898
Hello,

I was wondering if we can store subroutine of a program inside EEPROM of ARM based Microcontroller.

so the main program runs from flash memory and when it call a specific subroutine then it is run from the EEPROM

Also, there is an external EEPROM which can be used the copy the subroutine to the internal EEPROM.

Basically what I want to do is change part of program by physically changing EEPROM in my circuit without the need the flash the microcontroller again
The answer is yes- but you need to know a lot more about it than just copying and calling code- you also have to understand stack-frames and register preservation.
 
Top