I'm trying to develop a bootloader for ATmega16 and, yeah I got a lot of problems.. I want to flash the micros using the NRF24L01 Radio, so I had to share some code between bootloader and application - anyway the NRF24 code is around 3KB and in BLS is not enough space, also I want to be able to use the NRF24 code from application without to duplicate the whole library, so the FLASH layout is something like:
- Bootloader section (0x3800 address) 2KB
- NRF library (0x2840 address) 4KB
- NRF APIs pointers table (0x2800 address) 64B
- Application - 10KB
So I managed to write the bootloader, I'm able to write some pages in FLASH and the application partially can use the NRF library, but the problem is that I got some troubles with the ISRs... The NRF code is compiled alongside bootloader, this means the ISR routine is placed somewhere between 0x2800 - 0x3800 in FLASH, because I want to use the same routine in application, I just replace the Application's flash data at 0x04 address (INT0_vect) with the address of ISR routine from bootloader.. but I got a strange behavior, after few interrupts (or the first one) the MCU starts to act weird - I suspect that is due the stack overflow, or it just jumps somewhere random in FLASH and the things just turn wrong.. but I can't check this since I don't have a debugger - also I moved the .data section at 800090, the NRF library needs at least 32B, so from 800060-800090 is 48B, should be enough.
Any idea how I can properly use the same ISR routine for both, Bootloader and Application? - I don't compile the NRF and Application together, so I just put the Bootloader + NRF code starting with 0x2800 address.
Also what is the correct way to move the .data section to make space for NRF data? I used the following in the miscellaneous tab from Linker settings: -Wl,-section-start=.data_nrf=0x800060 -Wl,-section-start=.data_nrf=0x800090, then I checked the .map file and I saw that the .data begins from 0x800090, and after that is .bss...
Also any manual editing in HEX is fine for me, I intention to use a python script to write the application, so I can make any changes in HEX file.
Based on your answers, I'll provide you more info.