65 #define MEM_VECTORS_START 0x00000000
66 #define MEM_VECTORS_END 0x00000400 //One page of vectors + general purpose program memory. Word Address
70 #if defined(__PIC24FJ256GB210__) || defined(__PIC24FJ256GB206__)
71 #define MEM_PROGRAM_START 0x00003800 //Byte address in internal Program Memory of PIC (Word adr = 0x1C00)
72 #define MEM_PROGRAM_LAST 0x00054FFF //Last Byte address in internal Program Memory of PIC (Word adr = 0x2A7FF)
74 #define MEM_EEPROM_START 0xFFFFFFFF //No internal EEPROM
75 #define MEM_EEPROM_LAST 0xFFFFFFFF //No internal EEPROM
77 #define MEM_CONFIG_START 0x00055000 //Byte address in internal Program Memory of PIC (Word adr = 0x2A800)
78 #define MEM_CONFIG_LAST 0x000557FF //Last Byte address in internal Program Memory of PIC (Word adr = 0x2ABFF)
80 #define MEM_XEEPROM_START 0x01000000 //Byte address (in hex file) of start of "FirmwareX Configuration" in external Flash = 0x800000 word address
82 #define MEM_XEEPROM_LAST (MEM_XEEPROM_START + (XFLASH_FIRMWARE_CONFIG_SIZE_IN_SECTORS*0x1000*2) - 1)
86 #define MEM_XFLASH_START 0x01040000 //Byte address (in hex file) of start of User Space in external Flash = 0x820000 word address
88 #define MEM_XFLASH_LAST (MEM_XFLASH_START_SBC66EC + (XFLASH_USER_SPACE_SIZE_IN_SECTORS*0x1000*2) - 1)
92 #define PROGRAM_MEM_WR_ROW_SIZE 128 //For PIC24F family, 128 (0x80) Words can be written at a time. This is 128 x 1.5 = 192 bytes. Upper byte of each odd address Word is not implemented
93 #define PROGRAM_MEM_WR_ROW_MASK (PROGRAM_MEM_WR_ROW_SIZE-1)
95 #define PROGRAM_MEM_ERASE_BLOCK_SIZE 1024 //Smallest number of words that can be erased. To get bytes x 1.5
96 #define PROGRAM_MEM_ERASE_BLOCK_MASK (PROGRAM_MEM_ERASE_BLOCK_SIZE-1)
97 #elif defined(__PIC24FJ128GB210__) || defined(__PIC24FJ128GB206__) || defined(__PIC24FJ128GB106__)
98 #define MEM_PROGRAM_START 0x00003800 //Byte address in internal Program Memory of PIC (Word adr = 0x1C00)
99 #define MEM_PROGRAM_LAST 0x0002A7FF //Last Byte address in internal Program Memory of PIC (Word adr = 0x153FF)
101 #define MEM_EEPROM_START 0xFFFFFFFF //No internal EEPROM
102 #define MEM_EEPROM_LAST 0xFFFFFFFF //No internal EEPROM
104 #define MEM_CONFIG_START 0x0002A800 //Byte address in internal Program Memory of PIC (Word adr = 0x???)
105 #define MEM_CONFIG_LAST 0x0002AFFF //Last Byte address in internal Program Memory of PIC (Word adr = 0x???)
107 #define MEM_XEEPROM_START 0x01000000 //Byte address (in hex file) of start of "FirmwareX Configuration" in external Flash = 0x800000 word address
109 #define MEM_XEEPROM_LAST (MEM_XEEPROM_START + (XFLASH_FIRMWARE_CONFIG_SIZE_IN_SECTORS*0x1000*2) - 1)
113 #define MEM_XFLASH_START 0x01040000 //Byte address (in hex file) of start of User Space in external Flash = 0x820000 word address
115 #define MEM_XFLASH_LAST (MEM_XFLASH_START_SBC66ECL + (XFLASH_USER_SPACE_SIZE_IN_SECTORS*0x1000*2) - 1)
119 #define PROGRAM_MEM_WR_ROW_SIZE 128 //For PIC24F family, 128 (0x80) Words can be written at a time. This is 128 x 1.5 = 192 bytes. Upper byte of each odd address Word is not implemented
120 #define PROGRAM_MEM_WR_ROW_MASK (PROGRAM_MEM_WR_ROW_SIZE-1)
122 #define PROGRAM_MEM_ERASE_BLOCK_SIZE 1024 //Smallest number of words that can be erased. To get bytes x 1.5
123 #define PROGRAM_MEM_ERASE_BLOCK_MASK (PROGRAM_MEM_ERASE_BLOCK_SIZE-1)
125 #error "This bootloader only covers the PIC24FJ256GB210 family devices. Please see another folder for the bootloader appropriate for the selected device."
137 #define XFLASH_USERSPACE_START 0x00820000 //Beginning of "External FLASH User Space" memory, Word address. Byte address = 0x1040000. This is the address as given in hex file
138 #define XFLASH_USERSPACE_END 0x00900000 //End of "External FLASH User Space" memory. Word address. Byte address = 0x1200000. This address does not get updated, but the one just below it does.
154 #define XFLASH_FIRMWAREA_INFO_ADR 0 //Byte address of start of "FirmwareA Info"
155 #define XFLASH_FIRMWAREA_ADR 0x1000 //Byte address of start of "FirmwareA"
156 #define XFLASH_FIRMWAREA_CONFIG 0x40000 //Byte address of start of "FirmwareA Configuration"
158 #define XFLASH_FIRMWAREB_INFO_ADR 0x42000 //Byte address of start of "FirmwareB Info"
159 #define XFLASH_FIRMWAREB_ADR 0x43000 //Byte address of start of "FirmwareB"
160 #define XFLASH_FIRMWAREB_CONFIG 0x82000 //Byte address of start of "FirmwareB Configuration"
162 #define XFLASH_MODIFIED_CONFIG 0x84000
164 #define XFLASH_FIRMWAREB_OFFSET_FROMA (XFLASH_FIRMWAREB_INFO_ADR - XFLASH_FIRMWAREA_INFO_ADR)
166 #define XFLASH_FIRMWARE_SIZE_IN_SECTORS 63 //Indicates size of FirmwareA and FirmwareB areas in 4096 byte sectors = 63x4096 = 258,048 Bytes
167 #define XFLASH_FIRMWARE_CONFIG_SIZE_IN_SECTORS 2 //Indicates size of "FirmwareA Config" and "FirmwareB Config" in 4096 byte sectors = 2x4096 = 8k
168 #define XFLASH_SECTOR_SIZE 4096 //Byte size of a sector of external FLASH. A sector is the smallest area that can be erased.
173 #define XFLASH_USER_SPACE_ADR 0x86000
185 struct __attribute__ ((packed)){
190 struct __attribute__ ((packed)) {
191 unsigned int bNew : 1;
192 unsigned int bCurrent : 1;
193 unsigned int bPrevious : 1;
194 unsigned int bRestored : 1;
195 unsigned int bFaulty : 1;
196 unsigned int bFill : 11;
199 #define FIRMWARE_STATE_NEW 0b11111111
200 #define FIRMWARE_STATE_CURRENT 0b11111110
201 #define FIRMWARE_STATE_PREVIOUS 0b11111100
202 #define FIRMWARE_STATE_RESTORED 0b11111000
203 #define FIRMWARE_STATE_FAULTY 0b11110000
220 WORD_VAL magicNumber;
234 DWORD checksum1ProgMem;
235 DWORD checksum2ProgMem;
238 DWORD checksum1XeeMem;
239 DWORD checksum2XeeMem;
242 DWORD checksum1XflashMem;
243 DWORD checksum2XflashMem;
245 #define FIRMWARE_INFO_MAGIC_NUMBER 0x536A