Hi,
I am working on LPC2368 microcontroller. I need to develop two codes. One for bootloader and other is the actual application code.
The bootloader resides at 0x0000 and the application code is at 0x2000 The bootloader RAM is from 0x40000000 to 0x40000BFF and the application code RAM is from 0x40000C00 onwards.
I am using a flag in the bootloader to identify if there is a firmware upgrade. If this flag is set then the new firmware stored at a location other than actual application will be loaded into the application location i.e., 0x2000 and hence the firmware had been upgraded.
Now my problem is when my actual application code is running the interrupts are being called from the IVT of the Bootloader. Since i am using the VIC Vector Table for interrupts so both the IVT from Bootloader and application code are pointing to the same location. So i am not having any trouble with the IRQs.
Now i need to add a Data Abort handler which calls a function in the application code for handling data abort instructions.
This handling i have added in the IVT of the application code. But since the interrupts are being called from the IVT of the bootloader i couldnt write handling for Data Abort from application code.
I had seen many threads and all suggest to remap the interrupt vectors to RAM Mode. But if i did so the IVT of the application code will be mapped to 0x40000000.
But my bootloader is using the RAM from 0x40000000 so should i leave the first 64 bytes of RAM for application IVT and then allocate my Bootloader RAM and after that allocate my Application RAM??
Please do suggest me how i need to achieve this.
Thanks in advance
The interrupt vector code is identical.
The processor remaps the interrupt vector table, so it will take a block of RAM and map on top of the lowest addresses of the flash. So the processor will still think that the interrupt vector table starts from address 0 - just as it did before.
The only difference is that your application (which starts at address 0x2000) will be linked with an interrupt vector table at address 0x2000. And the startup code will copy these bytes from address 0x2000 into RAM. And then map that RAM block on top of address 0x0000.
But back to the bootloader use of RAM again.
You write: "I will then assaign the RAM location for Bootloader from 0x40000040 to 0x40000400 i.e., 1024 bytes for the bootloader. And the remaining RAM will be assigned to the actual application code."
Why not map 0x40000040 .. whatever you feel you need (only matters how much memory to zero-init on boot).
And map 0x40000040 .. max to the application, where max represents all RAM supported by the chip.
There is zero reason for the application to leave the RAM that the boot loader used. The boot loader doesn't need it anymore at the same moment the processor enters the startup file of the application. So the startup code for the application is free to initialize all ram but the bytes reserved for the interrupt vector table. No reason to waste 1kB RAM for the boot loader, if the interrupt vector table remapping only requires 64 bytes. The other 1024-64 bytes will just be wasted by your configuration.