kind of works for writing flash. IMPORTANT ISSUE - the memory usage output given by the linker for program size used DOES NOT equal the actual flash space used when programming. INVESTIGATE: did I set a memory space that doesn't lie on a page boundary? or do I just need to increase the flash space allocated to the bootloader

This commit is contained in:
2019-08-11 21:39:11 -04:00
parent 5ab4eceb88
commit 5c2d710bc2
8 changed files with 165 additions and 48 deletions

View File

@@ -9,22 +9,75 @@
#include "usb.h"
#include "bootloader.h"
void main(void) {
//UserInit();
/* Private prototypes */
void main(void);
void BootMain(void);
const unsigned int FlashSignatureWord __at(APP_SIGNATURE_ADDRESS) = APP_SIGNATURE_VALUE;
void main(void)
{
//BootMain();
/**
* TODO: implement hardware IO-based method for forcing entry into bootloader
*/
// normal operation: verify the firmware signature is valid. if it isn't enter
// bootloader (fw update) mode so valid firmware can be flashed
//DoFlashSignatureCheck:
//Check if the application region flash signature is valid
if(*(const unsigned int*)APP_SIGNATURE_ADDRESS == APP_SIGNATURE_VALUE)
{
//The flash signature was valid, implying the previous
//erase/program/verify operation was a success.
//Also make sure the first WORD of program memory in the app space
//is not blank, meaning there is an application image programmed into the device.
if(*(const unsigned int*)REMAPPED_APPLICATION_RESET_VECTOR != 0xFFFF)
{
//Go ahead and jump out of bootloader mode into the application run mode
#asm
goto REMAPPED_APPLICATION_RESET_VECTOR
#endasm
}
}
//else the application image is missing or corrupt. In this case, we
//need to stay in the bootloader mode, so the user has the ability to
//try (again) to re-program a valid application image into the device.
BootMain();
}
void BootMain(void) __at(0x30)
{
//Make sure interrupts are disabled for this code (could still be on,
//if the application firmware jumped into the bootloader via software methods)
INTCON = 0x00;
//Clear the stack pointer, in case the user application jumped into
//bootloader mode with excessive junk on the call stack
STKPTR = 0x00;
// End of the important parts of the C initializer. This bootloader firmware does not use
// any C initialized user variables (idata memory sections). Therefore, the above is all
// the initialization that is required.
// initialize the USB framework
USBDeviceInit();
USBDeviceAttach();
// initialize the bootloader
UserInit();
//Execute main loop
while(1)
{
//Need to call USBDeviceTasks() periodically. This function takes care of
//processing non-USB application related USB packets (ex: "Chapter 9"
//packets associated with USB enumeration)
USBDeviceTasks();
// do nothing if: not connected to USB host, or the host put us in suspend state
if((USBGetDeviceState() < CONFIGURED_STATE) | USBIsDeviceSuspended())
continue;
// run application specific tasks
ProcessIO();
}
}
ProcessIO(); //This is where all the actual bootloader related data transfer/self programming takes
//place see ProcessIO() function in the BootPIC[xxxx].c file.
}//end while
}