This section covers how to modify the size of the HID boot loader. This can be useful when adding features to the boot loader that increase the size beyond the default example or if a version of the compiler is used that doesn't provide a sufficient level of optimizations to fit the default boot loader. The boot loaders provided by default assume full optimizations and may not work with compilers that don't have access to full optimizations.
Please read all of the other topics in the PIC24F boot loader section before proceeding in this topic. This topic will show where the modifications need to be made and how they need to match up, but will not describe what the sections that are being modified are or how they are implemented. This information is in previous sections.
There are three places that require corresponding changes: the boot loader linker script, the application linker script, and the boot loader code. You may wish to make copies of the original files so that you preserve the original non-modified files.
In the following examples we will be increasing the size of the boot loader from 0x1400 to 0x2400 in length.
First start by determining the size that you want the boot loader to be. This must be a multiple of an erase page. On many PIC24F devices there is a 512 instruction word erase page (1024 addresses per page). Please insure that the address you select for the end of the boot loader corresponds to a page boundary. There are several ways to determine the size of the boot loader application. Below is an example of one method.
1) Remove the boot loader linker script provided if it is causing link errors due either to optimization settings or added code.
2) Build the project
3) Open the memory window and find the last non-blank address in the program memory space.
4) Find the next flash erase page address after this address. Add any additional buffer room that you might want for future boot loader development, growth, or changes. Use this address as your new boot loader end address.
Once the end address of the boot loader is known, start by modifying the boot loader linker script program memory region to match that change. The boot loader linker script can either be found in the folder containing the boot loader project file or in a folder that is specified for boot loader linker scripts. In the linker script find the memory regions.
MEMORY { data (a!xr) : ORIGIN = 0x800, LENGTH = 0x4000 reset : ORIGIN = 0x0, LENGTH = 0x4 ivt : ORIGIN = 0x4, LENGTH = 0xFC aivt : ORIGIN = 0x104, LENGTH = 0xFC program (xr) : ORIGIN = 0x400, LENGTH = 0x2000 config4 : ORIGIN = 0x2ABF8, LENGTH = 0x2 config3 : ORIGIN = 0x2ABFA, LENGTH = 0x2 config2 : ORIGIN = 0x2ABFC, LENGTH = 0x2 config1 : ORIGIN = 0x2ABFE, LENGTH = 0x2 }
Change the LENGTH field of the program memory section to match the new length. Note that this is length and not the end address. To get the end address, please add LENGTH + ORIGIN.
Next, locate the __APP_IVT_BASE definition in the linker file. Change this to equal the end address of your boot loader.
__APP_IVT_BASE = 0x2400;
Once the length of the boot loader is changed, you will need to make similar changes in the application boot loader linker script. The application boot loader linker scripts are typically found in a folder with the boot loader project. In the application linker file, locate the memory regions section. In this section there are three items that need to change.
MEMORY { data (a!xr) : ORIGIN = 0x800, LENGTH = 0x4000 reset : ORIGIN = 0x0, LENGTH = 0x4 ivt : ORIGIN = 0x4, LENGTH = 0xFC aivt : ORIGIN = 0x104, LENGTH = 0xFC app_ivt : ORIGIN = 0x2400, LENGTH = 0x110 program (xr) : ORIGIN = 0x2510, LENGTH = 0x286E8 config4 : ORIGIN = 0x2ABF8, LENGTH = 0x2 config3 : ORIGIN = 0x2ABFA, LENGTH = 0x2 config2 : ORIGIN = 0x2ABFC, LENGTH = 0x2 config1 : ORIGIN = 0x2ABFE, LENGTH = 0x2 }
The final changes that needs to be made are in the boot loader code itself. Open up the boot loader project.
#define ProgramMemStart 0x00002400
#if defined(__PIC24FJ256GB110__) || defined(__PIC24FJ256GB108__) || defined(__PIC24FJ256GB106__) #define BeginPageToErase 5 //Bootloader and vectors occupy first six 1024 word (1536 bytes due to 25% unimplemented bytes) pages #define MaxPageToEraseNoConfigs 169 //Last full page of flash on the PIC24FJ256GB110, which does not contain the flash configuration words. #define MaxPageToEraseWithConfigs 170 //Page 170 contains the flash configurations words on the PIC24FJ256GB110. Page 170 is also smaller than the rest of the (1536 byte) pages. #define ProgramMemStopNoConfigs 0x0002A800 //Must be instruction word aligned address. This address does not get updated, but the one just below it does: //IE: If AddressToStopPopulating = 0x200, 0x1FF is the last programmed address (0x200 not programmed) #define ProgramMemStopWithConfigs 0x0002ABF8 //Must be instruction word aligned address. This address does not get updated, but the one just below it does: IE: If AddressToStopPopulating = 0x200, 0x1FF is the last programmed address (0x200 not programmed) #define ConfigWordsStartAddress 0x0002ABF8 //0x2ABFA is start of CW3 on PIC24FJ256GB110 Family devices #define ConfigWordsStopAddress 0x0002AC00
This should be all of the changes required in order to change the size of the HID boot loader.
Please note that since the boot loader and the application code are developed as two separate applications, they do not need to use the same optimization settings.
MLA - USB Library Help Version : 2.16
![]() |