added massive comment in memory.h about how memory is laid out to work with the bootloader. more code cleanup
This commit is contained in:
@@ -90,7 +90,7 @@
|
||||
<property key="default-bitfield-type" value="true"/>
|
||||
<property key="default-char-type" value="true"/>
|
||||
<property key="define-macros" value=""/>
|
||||
<property key="disable-optimizations" value="false"/>
|
||||
<property key="disable-optimizations" value="true"/>
|
||||
<property key="extra-include-directories"
|
||||
value="..\src;..\..\common_src;..\src\minimal_usb_driver"/>
|
||||
<property key="favor-optimization-for" value="-speed,+space"/>
|
||||
@@ -105,7 +105,7 @@
|
||||
<property key="optimization-debug" value="false"/>
|
||||
<property key="optimization-invariant-enable" value="false"/>
|
||||
<property key="optimization-invariant-value" value="16"/>
|
||||
<property key="optimization-level" value="-O1"/>
|
||||
<property key="optimization-level" value="-O0"/>
|
||||
<property key="optimization-speed" value="false"/>
|
||||
<property key="optimization-stable-enable" value="false"/>
|
||||
<property key="pack-struct" value="true"/>
|
||||
@@ -131,7 +131,7 @@
|
||||
<property key="calibrate-oscillator-value" value="0x3400"/>
|
||||
<property key="clear-bss" value="true"/>
|
||||
<property key="code-model-external" value="wordwrite"/>
|
||||
<property key="code-model-rom" value="default,-2000-7FFF"/>
|
||||
<property key="code-model-rom" value="default,-1400-7FFF"/>
|
||||
<property key="create-html-files" value="false"/>
|
||||
<property key="data-model-ram" value=""/>
|
||||
<property key="data-model-size-of-double" value="32"/>
|
||||
|
||||
@@ -20,14 +20,14 @@
|
||||
;//High priority interrupt vector remapping
|
||||
PSECT HiVector,class=CODE,delta=1,abs
|
||||
org 0x08
|
||||
goto 0x2008 ;Resides at 0x0008 (hardware high priority interrupt vector), and causes PC to jump to 0x2008 upon a high priority interrupt event
|
||||
goto 0x1408 ;Resides at 0x0008 (hardware high priority interrupt vector), and causes PC to jump to application's interrupt vector upon a high priority interrupt event
|
||||
|
||||
|
||||
;//Low priority interrupt vector remapping, as well as bootloader mode absolute
|
||||
;//entry point (located at 0x001C).
|
||||
PSECT LoVector,class=CODE,delta=1,abs
|
||||
org 0x18
|
||||
goto 0x2018 ;Resides at 0x0018 (hardware low priority interrupt vector), and causes PC to jump to 0x2018 upon a low priority interrupt event
|
||||
goto 0x1418 ;Resides at 0x0018 (hardware low priority interrupt vector), and causes PC to jump to application's interrupt vector upon a low priority interrupt event
|
||||
goto 0x30 ;Resides at 0x001C //Serves as absolute entry point from application program into the bootloader mode
|
||||
|
||||
|
||||
|
||||
@@ -28,21 +28,94 @@
|
||||
#define MEMORY_
|
||||
|
||||
/**
|
||||
* When changing the location of the application in flash memory these files and settings
|
||||
* must be updated.
|
||||
* In bootloader project:
|
||||
* VectorRemap.asm HiVector goto -> APP_FW_MEMORY_OFFSET + 0x08
|
||||
* LoVector goto -> APP_FW_MEMORY_OFFSET + 0x18
|
||||
* Configuration > Linker > Memory Model > ROM space -> default,-APP_FW_MEMORY_OFFSET-7FFF
|
||||
* In application project:
|
||||
* Configuration > Linker > Memory Model > ROM space -> default,-0-[[APP_FW_MEMORY_OFFSET-1]],-[[APP_FW_MEMORY_OFFSET+6]]-[[APP_FW_MEMORY_OFFSET+7]],-[[APP_FW_MEMORY_OFFSET+0x16]]-[[APP_FW_MEMORY_OFFSET+0x17]]
|
||||
* ##########################################################################################
|
||||
* ### Regarding the modified memory layout of program flash to accomodate the bootloader ###
|
||||
* ##########################################################################################
|
||||
*
|
||||
* This firmware implements a bootloader to allow the user to flash firmware over USB without requiring an external
|
||||
* programmer/debugger such as the ICD or Pickit 3. The bootloader and the application are separate binaries that
|
||||
* are compiled and linked independently of each other.
|
||||
*
|
||||
* The bootloader occupies memory in program flash starting at address 0x0000. The MCU will always start program
|
||||
* execution at this address. The application occupies program flash memory starting from a predetermined address after
|
||||
* the end of the memory space occupied by the bootloader through the remainder of the program flash memory. As an
|
||||
* example let's assume the application starts at address 0x1400. The memory map of the corresponding program flash is
|
||||
* shown below.
|
||||
*
|
||||
* ###############################
|
||||
* # Memory Map of Program Flash #
|
||||
* ###############################
|
||||
*
|
||||
* Address Description
|
||||
* ------------------------
|
||||
* 0x0000 Bootloader reset vector
|
||||
* 0x0008 Bootloader interrupt vector (high)
|
||||
* 0x0018 Bootloader interrupt vector (low)
|
||||
* ...
|
||||
* 0x0030 Bootloader absolute entrypoint (application can enter bootloader by jumping to this address)
|
||||
* ==[Remainder of bootloader code]==
|
||||
* 0x1400 Application reset vector
|
||||
* 0x1406 Application signature word**
|
||||
* 0x1408 Application interrupt vector (high)****
|
||||
* 0x1416 Application version word***
|
||||
* 0x1418 Application interrupt vector (low)****
|
||||
* ==[Remainder of application code]==
|
||||
* 0x7FFF (Last byte of program flash)
|
||||
*
|
||||
* Notes: ** The signature word is written with a known value by the bootloader after it writes the application
|
||||
* code to flash memory and verifies the data written. If the bootloader does not read this exact value
|
||||
* at this address at startup it will assume the application code is corrupted and immediately enter
|
||||
* firmware update mode so valid application code can be flashed.
|
||||
* *** The version word is stored at this address by the application code at link time. Currently unused
|
||||
* but I'm leaving the functionality in so the bootloader can report the version of the current
|
||||
* application.
|
||||
* **** The bootloader's interrupt vectors will forward interrupts to the application's interrupt vectors
|
||||
* because they were moved when we offset the application code to 0x1400.
|
||||
*
|
||||
* ##############################################
|
||||
* # Changing the application's memory location #
|
||||
* ##############################################
|
||||
*
|
||||
* 2 source files must be modified, as well as the project configurations for both the bootloader and application
|
||||
* projects.
|
||||
*
|
||||
* #
|
||||
* # File changes
|
||||
* #
|
||||
* File Location Changes
|
||||
* ------------------------------------------------
|
||||
* VectorRemap.asm bootloader * Change address in HiVector goto instruction to address of application
|
||||
* high priority interrupt vector (ex. 0x1408).
|
||||
* * Change address in LoVector goto instruction (NOT the goto 0x30) to address
|
||||
* of application low priority interrupt vector (ex. 0x1418).
|
||||
* THIS FILE shared * Change APP_FW_MEMORY_OFFSET to the starting address of the application
|
||||
* (ex. 0x1400)
|
||||
*
|
||||
* #
|
||||
* # BOOTLOADER project configuration changes
|
||||
* #
|
||||
* Configuration > Linker > Memory Model > ROM space
|
||||
* * Add memory range of application as a protected region. Ranges are separated by a single comma. Ranges that
|
||||
* start with a '-' will be considered protected. Memory addresses specified in hexadecimal. No spaces allowed.
|
||||
* (ex. 'default,-1400-7FFF')
|
||||
*
|
||||
* #
|
||||
* # APPLICATION project configuration changes
|
||||
* #
|
||||
* Configuration > Linker > Memory Model > Additional Options > Code offset
|
||||
* * Set to APP_FW_MEMORY_OFFSET
|
||||
* Configuration > Linker > Memory Model > ROM space
|
||||
* * Add memory ranges for bootloader, application signature word, and application version word as protected
|
||||
* regions. Ranges are separated by a single comma. Ranges that start with a '-' will be considered protected.
|
||||
* Memory addresses specified in hexadecimal. No spaces allowed.
|
||||
* (ex. 'default,-0-13FF,-1406-1407,-1416-1417')
|
||||
*/
|
||||
|
||||
/**
|
||||
* The base address of the application memory space. The application's reset vector will be
|
||||
* at this address.
|
||||
*/
|
||||
#define APP_FW_MEMORY_OFFSET 0x2000
|
||||
#define APP_FW_MEMORY_OFFSET 0x1400
|
||||
|
||||
/**
|
||||
* The address in application memory space that stores the application's version number.
|
||||
@@ -59,7 +132,7 @@
|
||||
* The absolute address of the bootloader entrypoint. The application can jump to the
|
||||
* bootloader by executing a "goto" instruction with this address.
|
||||
*/
|
||||
#define BOOTLOADER_ENTRYPOINT 0x001C
|
||||
#define BOOTLOADER_ENTRYPOINT 0x0030
|
||||
|
||||
#endif /* MEMORY_ */
|
||||
|
||||
|
||||
@@ -141,7 +141,7 @@
|
||||
<property key="asmlist" value="true"/>
|
||||
<property key="default-bitfield-type" value="true"/>
|
||||
<property key="default-char-type" value="true"/>
|
||||
<property key="define-macros" value="LINK_FOR_BOOTLOADER"/>
|
||||
<property key="define-macros" value=""/>
|
||||
<property key="disable-optimizations" value="true"/>
|
||||
<property key="extra-include-directories"
|
||||
value="..\src;..\..\common_src\framework\usb\inc;..\..\common_src"/>
|
||||
@@ -172,7 +172,7 @@
|
||||
</HI-TECH-COMP>
|
||||
<HI-TECH-LINK>
|
||||
<property key="additional-options-checksum" value=""/>
|
||||
<property key="additional-options-code-offset" value="0x2000"/>
|
||||
<property key="additional-options-code-offset" value="0x1400"/>
|
||||
<property key="additional-options-command-line" value=""/>
|
||||
<property key="additional-options-errata" value=""/>
|
||||
<property key="additional-options-extend-address" value="false"/>
|
||||
@@ -183,7 +183,7 @@
|
||||
<property key="calibrate-oscillator-value" value="0x3400"/>
|
||||
<property key="clear-bss" value="true"/>
|
||||
<property key="code-model-external" value="wordwrite"/>
|
||||
<property key="code-model-rom" value="default,-0-1FFF,-2006-2007,-2016-2017"/>
|
||||
<property key="code-model-rom" value="default,-0-13FF,-1406-1407,-1416-1417"/>
|
||||
<property key="create-html-files" value="false"/>
|
||||
<property key="data-model-ram" value=""/>
|
||||
<property key="data-model-size-of-double" value="32"/>
|
||||
@@ -275,7 +275,7 @@
|
||||
<conf name="standalone" type="2">
|
||||
<toolsSet>
|
||||
<developmentServer>localhost</developmentServer>
|
||||
<targetDevice>PIC18F2550</targetDevice>
|
||||
<targetDevice>PIC18F4550</targetDevice>
|
||||
<targetHeader></targetHeader>
|
||||
<targetPluginBoard></targetPluginBoard>
|
||||
<platformTool>PICkit3PlatformTool</platformTool>
|
||||
@@ -294,9 +294,10 @@
|
||||
<archiverTool>
|
||||
</archiverTool>
|
||||
<loading>
|
||||
<loadableFile>../../bootloader/clubdance_v2_bootloader.X/dist/default/production/clubdance_v2_bootloader.X.production.hex</loadableFile>
|
||||
<useAlternateLoadableFile>false</useAlternateLoadableFile>
|
||||
<parseOnProdLoad>false</parseOnProdLoad>
|
||||
<alternateLoadableFile></alternateLoadableFile>
|
||||
<alternateLoadableFile>../../bootloader/clubdance_v2_bootloader.X/dist/default/production/clubdance_v2_bootloader.X.production.hex</alternateLoadableFile>
|
||||
</loading>
|
||||
<subordinates>
|
||||
</subordinates>
|
||||
@@ -318,7 +319,7 @@
|
||||
<property key="define-macros" value=""/>
|
||||
<property key="disable-optimizations" value="true"/>
|
||||
<property key="extra-include-directories"
|
||||
value="..\src;..\..\common_src\framework\usb\inc"/>
|
||||
value="..\src;..\..\common_src\framework\usb\inc;..\..\common_src"/>
|
||||
<property key="favor-optimization-for" value="-speed,+space"/>
|
||||
<property key="garbage-collect-data" value="true"/>
|
||||
<property key="garbage-collect-functions" value="true"/>
|
||||
@@ -337,7 +338,7 @@
|
||||
<property key="pack-struct" value="true"/>
|
||||
<property key="preprocess-assembler" value="true"/>
|
||||
<property key="short-enums" value="true"/>
|
||||
<property key="undefine-macros" value="LINK_FOR_BOOTLOADER"/>
|
||||
<property key="undefine-macros" value=""/>
|
||||
<property key="use-cci" value="false"/>
|
||||
<property key="use-iar" value="false"/>
|
||||
<property key="verbose" value="false"/>
|
||||
@@ -346,7 +347,7 @@
|
||||
</HI-TECH-COMP>
|
||||
<HI-TECH-LINK>
|
||||
<property key="additional-options-checksum" value=""/>
|
||||
<property key="additional-options-code-offset" value=""/>
|
||||
<property key="additional-options-code-offset" value="1400"/>
|
||||
<property key="additional-options-command-line" value=""/>
|
||||
<property key="additional-options-errata" value=""/>
|
||||
<property key="additional-options-extend-address" value="false"/>
|
||||
@@ -357,7 +358,7 @@
|
||||
<property key="calibrate-oscillator-value" value="0x3400"/>
|
||||
<property key="clear-bss" value="true"/>
|
||||
<property key="code-model-external" value="wordwrite"/>
|
||||
<property key="code-model-rom" value=""/>
|
||||
<property key="code-model-rom" value="default,-0-13FF,-1406-1407,-1416-1417"/>
|
||||
<property key="create-html-files" value="false"/>
|
||||
<property key="data-model-ram" value=""/>
|
||||
<property key="data-model-size-of-double" value="32"/>
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
|
||||
#ifdef LINK_FOR_BOOTLOADER
|
||||
// only define this if building fw to be used with the bootloader
|
||||
const uint16_t VersionWord __at(0x2016) = 0x0100;
|
||||
const uint16_t VersionWord __at(APP_FW_VERSION_ADDRESS) = 0x0100;
|
||||
#endif
|
||||
|
||||
void main(void)
|
||||
|
||||
Reference in New Issue
Block a user