Wednesday, 15 November 2017

avr - Moving the code and interrupt locations in Arduino


I need to be able to choose between two Arduino apps running on an atmega 1280 (megaavr) at boot time. Therefore I need to move one of those apps to a different location in program memory, and I need to move the interrupts to that location as well.


I already have a method of executing the correct interrupts (with the help of the bootloader) in any location in memory.


However, I don't understand the build process enough to see where the linker decides where to place things and how to move both the program and interrupt sections to new memory locations.



  • Where is the location of the interrupt vector defined?

  • Where is the location of the program defined?


The current builds are performed using Arduino 22. While I'd prefer to modify build scripts or files in that environment, if needed I would consider moving it all over to a makefile build process and out of the Arduino environment.



Answer




AVRGCC loads the interrupts and program into the same section, with the interrupts first. The section is simply labeled .text, so only one flag needs to be fed to the compiler to move both the interrupts and the program:


-Wl,--section-start=.text=0x10000 # Exactly 1/2 of a 128k device

I ultimately went with a custom Makefile (there are a multitude of arduino makefile examples on the internet) rather than trying to do this inside Arduino. This will allow me to customize the build process further for other parts of the project as well.


I did not research the linker script further, but I suspect the interrupt section could be separated from the .text section with another simple section directive.


No comments:

Post a Comment

arduino - Can I use TI's cc2541 BLE as micro controller to perform operations/ processing instead of ATmega328P AU to save cost?

I am using arduino pro mini (which contains Atmega328p AU ) along with cc2541(HM-10) to process and transfer data over BLE to smartphone. I...