This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Code run from RAM that can program itself

I am building a USB bootloader that needs to be able to reprogram both an application and itself in flash. As a result I have looked into an approach like in the RAM_Function example where the code I need to execute the flash write and USB communication is located in RAM.

I am assuming if the linker locates code in RAM that upon powerup will re-init this code from a flash location automaticly. Otherwise it is gone after a power cycle. Is this correct?

In this scenario is it possile for the RAM code to re-write the entire bootloader, including the code that is located in RAM? I would assume not, that I would need to create a system where all the code was defined in flash and I manually copy the functions I need into RAM and then run them from there.

On the other hand, if the linker is actualy placing the code in flash and it is initializing the RAM section on startup then I should be able to overwrite the flash and reset to find the bootloader RAM functions also updated.

The final question I have is since the USB drivers we have are interrupt based if the ISR functions are running from RAM what do I need to do to make sure the interrupts trigger correctly? I assume I would need to relocate the Vector Table when I jump to my RAM code so the old table can be overwritten but do I need to do anything else? Shouldn't the interrupt vectors point to RAM since that is where the functions are located in the linker?

Thanks in advance for any guidance!

Parents
  • You don't have to worry about the code in RAM. Replace the code in flash, and reboot. Then the newer versin of the firmware will decide if it too has any code to copy to RAM.

    If you build a boot loader and an application as two binaries, then you can have the application linked so that the interrupt vector table is stored in flash and gets copied to RAM before the application calls main(). Initially, the boot loader will have the vector table in flash. The new appliation will then copy a new vector table to RAM, and then remap so this piece of RAM overlaps and replaces the original interrupt vector table.

Reply
  • You don't have to worry about the code in RAM. Replace the code in flash, and reboot. Then the newer versin of the firmware will decide if it too has any code to copy to RAM.

    If you build a boot loader and an application as two binaries, then you can have the application linked so that the interrupt vector table is stored in flash and gets copied to RAM before the application calls main(). Initially, the boot loader will have the vector table in flash. The new appliation will then copy a new vector table to RAM, and then remap so this piece of RAM overlaps and replaces the original interrupt vector table.

Children