4.6.1 Combining the Bootloader and Application for AVR® Devices
This section demonstrates how to merge the bootloader and application projects into a single hex file for 8-bit AVR® devices.
In a production environment, it is common practice to build both the bootloader code and the application code together into a single hex file. This allows both projects to be programmed at the exact same time. This section demonstrates how to combine the bootloader and application projects into a unified hex file using MPLAB X.
- Set the application project as the
Main Project.
- Create a new configuration in the
application project and rename it to ‘COMBINED’.
Navigate to Project Properties>Manage Configurations.... Click Duplicate with the bootable configuration selected and then Rename the resulting copy to ‘COMBINED’. Then click OK and OK again.
Figure 4-161. Create the New Combined Configuration - Add the bootloader configuration as a
loadable project to the ‘COMBINED’ application configuration.
In the COMBINED configuration, navigate to Project Properties>Loading and then click the Add Loadable Project... button.
Figure 4-162. Adding the Bootloader to the Application Figure 4-163. Select the Bootloader Configuration Click Add and then Apply.
Figure 4-164. Completed COMBINED Configuration - Update the post build operations to
combined the application hex file for the COMBINED configuration. Add the
corresponding command to the post build script after the calculation
command.
postBuild.bat
set isCombinedBuild='%5' == 'COMBINED' set unifiedHexFile=%3\%2.X.%4.unified.hex ... ... REM - Update the unified hex file for the COMBINED configuration if %isCombinedBuild% hexmate r2000-1FFFF,%appHexFile% r0-1FFF,%unifiedHexFile% -O%unifiedHexFile%
postBuild.sh
isCombinedBuild='$5' == 'COMBINED' unifiedHexFile=$3\$2.X.$4.unified.hex ... ... # - Update the unified hex file for the COMBINED configuration if [$isCombinedBuild]; then hexmate r2000-1FFFF,%appHexFile r0-1FFF,$unifiedHexFile -O$unifiedHexFile
Figure 4-165. Update the Post Build Script Update the post build command from within the new COMBINED configuration by navigating to Project Properties>COMBINED>Building and adding
COMBINED
onto the end of the command.Figure 4-166. Update Post Build Command -
Figure 4-167. Select the COMBINED Configuration - Clean and Build the COMBINED
configuration.