Pergunta

I'm trying to load two programs onto an AVR chip, but I can't find any resources on how to do this.

The purpose of this is to have the chip start running the first program and the first program jumps (using assembly) to the second (which is loaded at a second point in memory). I know this sounds useless, but there is a larger point to it which I want to implement later on.

Is there a way to load programs at a specified point in memory and accomplish this task? Or perhaps is there a way to generate one hex file that could do this otherwise?

Thanks in advance, and I hope this makes sense.

Foi útil?

Solução 2

The start address of your code is normally determined by the linker script or settings. The default for your toolchain will be to run from reset (i.e. the reset vector will point to the start address of the code). Your secondary program needs to be located in a different memory space (via the linker settings) and your primary program will simply need to jump to to the second.

Some gotchas you may need to be wary of; your primary program may not leave I/O and peripherals in the "reset" state, so you secondary program should not make any assumptions. Before making the jump, it is probably important that you disable any peripherals that may be generating interrupts.

As far as combining the hex files, that can be achieved easily with a text editor if you are careful and prepared to interpret the hex records manually or more flexibly (and less error prone) with the SRecord tool.

One problem you may encounter is that while the code itself may be separately located, the vector table in AVR is fixed and will be shared between the two programs. The interrupt vector tables for the two programs must be identical and must share handlers - that is not straightforward if the handlers need to communicate with whichever program is "running". The simplest solution is to arrange it so that only one of the programs uses interrupts. SRecord will usefully resolve or warn of conflicts where both hex files define overlapping memory regions, and I think you can arrange it so that one file overrides the other.

Outras dicas

This sounds like a bootloader. I've implemented this in Microchip's PICs, not AVR, but the trick is in the linker files.

The bootloader runs on a power up. It looks for new application firmware to burn into the flash. If there is no new firmware, it look to see if there is new application firmware. If there is, then it jumps to the application's reset vector. The application starts to run as if it was just a power up.

The trick is that the linker file for the bootloader and application are coupled together. The bootloader reserves address 0x0000 to 0x0FFF. The application reserves addresses 0x1000 to 0xFFFF. Also the bootloader and application need to agree on where the application starts. It may not be address 0x1000.

I too use this technique for bootloader plus application on a PIC processor. As the previous poster mentioned, the first part of the problem is to locate the two programs with the linker so they do not overlap. After building the tow programs separately I use Hexmate to combine the hex files of both programs into a single hex file. You can get a copy of this utility for windows PCs at http://www.schmalzhaus.com/Tools/HexmateInstructions.html

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top