Setup: MC9S12A256 and CW 3.1
Hi guys!
I'm trying to merge my application with AN3275 bootloader. I want to do it with the HEXFILE instruction on .prm file.
What I do is add HEXFILE bootloader.s19 at the biggining of that file, then reduce segmenet ROM_C000 definition so my app will not invade bootloader area. And also remove reset vector entry, because it's already capture inside the bootloader code. Everything compiles just perfectly, I can enter bootloader menu, but I cannot run the application.
The bootloader checks PAD0, if it is low, it enters bootloading mode, if not, it jumps to user application, my application. But it's not jumping to my app, it jumps to 0x0000.
The asm instruction is JMP [0xFF30, PC] (where PC = F0CA). If I'm not wrong this is program-counter relative addressing mode. I didn't know about it.
But after the jump PC = 0x0000. If I manually change it (when debugging) to PC = 0xC000 application runs.
I don't understand why the bootloader uses PC-relative addressing. Why not just jump (for my app) to 0xC000?
One more thing, when bootloading the same application (updating firmware), The reset vector get erased, so after reset PC = 0x0000 and neither user code, nor bootloader works, unless i manually set it to bootloader startup address. [Note: the app I bootIoad is the same, without merging the bootloader, I mean no HEXFILE and with the reset vector entry]
EDIT:
I would like to add that bootloader does NOT use interrupts, so I don't have 2 vector tables. I just got the one from my application
Solved! Go to Solution.
News!
I can solve this:
>The asm instruction is JMP [0xFF30, PC] (where PC = F0CA). If I'm not wrong this is program-counter relative addressing >mode. I didn't know about it.
>But after the jump PC = 0x0000. If I manually change it (when debugging) to PC = 0xC000 application runs.
by adding the following on main.c
extern void _Startup (void);typedef void (*near tFunc) (void);const tFunc rst_vec @0xEFFE=_Startup;
That's because bootloader places user-reset-vector at address 0xEFFE
Now when not in bootloader mode, user application runs fine.
The only problem that remains, is that after bootloading a new .s19 (the same application no merge with bootloader) the reset vector (0xFFFE) is cleared (= 0x000) so with no reset vector, nothing runs. All the other vectors (I2C, timer, PLL, etc) are fine.
Any clue? I susspect that it might be a problem inside .prm file. So here is it:
NAMES END//HEXFILE bootloader.s19 // UNComment this when merging with BootLoaderSEGMENTS RAM = READ_WRITE 0x1000 TO 0x3FFF; /* unbanked FLASH ROM */ ROM_4000 = READ_ONLY 0x4000 TO 0x7FFF; //ROM_4000 = READ_ONLY 0x4000 TO 0x7F0F; //ROM_C000 = READ_ONLY 0xC000 TO 0xFEFF; ROM_C000 = READ_ONLY 0xC000 TO 0xEFFD; /* banked FLASH ROM */ PAGE_30 = READ_ONLY 0x308000 TO 0x30BFFF; PAGE_31 = READ_ONLY 0x318000 TO 0x31BFFF; PAGE_32 = READ_ONLY 0x328000 TO 0x32BFFF; PAGE_33 = READ_ONLY 0x338000 TO 0x33BFFF; PAGE_34 = READ_ONLY 0x348000 TO 0x34BFFF; PAGE_35 = READ_ONLY 0x358000 TO 0x35BFFF; PAGE_36 = READ_ONLY 0x368000 TO 0x36BFFF; PAGE_37 = READ_ONLY 0x378000 TO 0x37BFFF; PAGE_38 = READ_ONLY 0x388000 TO 0x38BFFF; PAGE_39 = READ_ONLY 0x398000 TO 0x39BFFF; PAGE_3A = READ_ONLY 0x3A8000 TO 0x3ABFFF; PAGE_3B = READ_ONLY 0x3B8000 TO 0x3BBFFF; PAGE_3C = READ_ONLY 0x3C8000 TO 0x3CBFFF; PAGE_3D = READ_ONLY 0x3D8000 TO 0x3DBFFF; PAGE_EEPROM = READ_ONLY 0x0400 TO 0x0FFF;/* PAGE_3E = READ_ONLY 0x3E8000 TO 0x3EBFFF; not used: equivalent to ROM_4000 *//* PAGE_3F = READ_ONLY 0x3F8000 TO 0x3FBFFF; not used: equivalent to ROM_C000 */ENDPLACEMENT _PRESTART, /* Used in HIWARE format: jump to _Startup at the code start */ STARTUP, /* startup data structures */ ROM_VAR, /* constant variables */ //STRINGS, /* string literals */ VIRTUAL_TABLE_SEGMENT, /* C++ virtual table segment */ NON_BANKED, /* runtime routines which must not be banked */ PAGE_IRQs, COPY /* copy down information: how to initialize variables */ /* in case you want to use ROM_4000 here as well, make sure that all files (incl. library files) are compiled with the option: -OnB=b */ INTO ROM_C000; DEFAULT_ROM INTO PAGE_30,PAGE_31,PAGE_32,PAGE_33,PAGE_34,PAGE_35,PAGE_36, PAGE_37,PAGE_38,PAGE_39,PAGE_3A,PAGE_3B,PAGE_3C; DEFAULT_RAM INTO RAM; FONTS_PAGE INTO PAGE_3B; FLASH_DATA_PAGE INTO PAGE_3D; PAGE_TEXT INTO PAGE_3A; STRINGS INTO PAGE_3A; /* string literals */ EEPROM_DATA_PAGE INTO PAGE_EEPROM;ENDSTACKSIZE 0x600/* INTERRUPT VECTOR TABLE *//**************************/ VECTOR ADDRESS 0xFFFE _Startup // Comment this when merging with BootLoader VECTOR ADDRESS 0xFFFC CMF_ISR VECTOR ADDRESS 0xFFFA COP_ISR VECTOR ADDRESS 0xFFF8 UNIMPLEMENTED_02 VECTOR ADDRESS 0xFFF6 UNIMPLEMENTED_03 VECTOR ADDRESS 0xFFF4 UNIMPLEMENTED_04 VECTOR ADDRESS 0xFFF2 IRQ_ISR
Thanks in advance
News!
I can solve this:
>The asm instruction is JMP [0xFF30, PC] (where PC = F0CA). If I'm not wrong this is program-counter relative addressing >mode. I didn't know about it.
>But after the jump PC = 0x0000. If I manually change it (when debugging) to PC = 0xC000 application runs.
by adding the following on main.c
extern void _Startup (void);typedef void (*near tFunc) (void);const tFunc rst_vec @0xEFFE=_Startup;
That's because bootloader places user-reset-vector at address 0xEFFE
Now when not in bootloader mode, user application runs fine.
The only problem that remains, is that after bootloading a new .s19 (the same application no merge with bootloader) the reset vector (0xFFFE) is cleared (= 0x000) so with no reset vector, nothing runs. All the other vectors (I2C, timer, PLL, etc) are fine.
Any clue? I susspect that it might be a problem inside .prm file. So here is it:
NAMES END//HEXFILE bootloader.s19 // UNComment this when merging with BootLoaderSEGMENTS RAM = READ_WRITE 0x1000 TO 0x3FFF; /* unbanked FLASH ROM */ ROM_4000 = READ_ONLY 0x4000 TO 0x7FFF; //ROM_4000 = READ_ONLY 0x4000 TO 0x7F0F; //ROM_C000 = READ_ONLY 0xC000 TO 0xFEFF; ROM_C000 = READ_ONLY 0xC000 TO 0xEFFD; /* banked FLASH ROM */ PAGE_30 = READ_ONLY 0x308000 TO 0x30BFFF; PAGE_31 = READ_ONLY 0x318000 TO 0x31BFFF; PAGE_32 = READ_ONLY 0x328000 TO 0x32BFFF; PAGE_33 = READ_ONLY 0x338000 TO 0x33BFFF; PAGE_34 = READ_ONLY 0x348000 TO 0x34BFFF; PAGE_35 = READ_ONLY 0x358000 TO 0x35BFFF; PAGE_36 = READ_ONLY 0x368000 TO 0x36BFFF; PAGE_37 = READ_ONLY 0x378000 TO 0x37BFFF; PAGE_38 = READ_ONLY 0x388000 TO 0x38BFFF; PAGE_39 = READ_ONLY 0x398000 TO 0x39BFFF; PAGE_3A = READ_ONLY 0x3A8000 TO 0x3ABFFF; PAGE_3B = READ_ONLY 0x3B8000 TO 0x3BBFFF; PAGE_3C = READ_ONLY 0x3C8000 TO 0x3CBFFF; PAGE_3D = READ_ONLY 0x3D8000 TO 0x3DBFFF; PAGE_EEPROM = READ_ONLY 0x0400 TO 0x0FFF;/* PAGE_3E = READ_ONLY 0x3E8000 TO 0x3EBFFF; not used: equivalent to ROM_4000 *//* PAGE_3F = READ_ONLY 0x3F8000 TO 0x3FBFFF; not used: equivalent to ROM_C000 */ENDPLACEMENT _PRESTART, /* Used in HIWARE format: jump to _Startup at the code start */ STARTUP, /* startup data structures */ ROM_VAR, /* constant variables */ //STRINGS, /* string literals */ VIRTUAL_TABLE_SEGMENT, /* C++ virtual table segment */ NON_BANKED, /* runtime routines which must not be banked */ PAGE_IRQs, COPY /* copy down information: how to initialize variables */ /* in case you want to use ROM_4000 here as well, make sure that all files (incl. library files) are compiled with the option: -OnB=b */ INTO ROM_C000; DEFAULT_ROM INTO PAGE_30,PAGE_31,PAGE_32,PAGE_33,PAGE_34,PAGE_35,PAGE_36, PAGE_37,PAGE_38,PAGE_39,PAGE_3A,PAGE_3B,PAGE_3C; DEFAULT_RAM INTO RAM; FONTS_PAGE INTO PAGE_3B; FLASH_DATA_PAGE INTO PAGE_3D; PAGE_TEXT INTO PAGE_3A; STRINGS INTO PAGE_3A; /* string literals */ EEPROM_DATA_PAGE INTO PAGE_EEPROM;ENDSTACKSIZE 0x600/* INTERRUPT VECTOR TABLE *//**************************/ VECTOR ADDRESS 0xFFFE _Startup // Comment this when merging with BootLoader VECTOR ADDRESS 0xFFFC CMF_ISR VECTOR ADDRESS 0xFFFA COP_ISR VECTOR ADDRESS 0xFFF8 UNIMPLEMENTED_02 VECTOR ADDRESS 0xFFF6 UNIMPLEMENTED_03 VECTOR ADDRESS 0xFFF4 UNIMPLEMENTED_04 VECTOR ADDRESS 0xFFF2 IRQ_ISR
Thanks in advance
As merging now is working, I'll take the above post as SOLUTION... And now I'm openning a new thread, because the problem is that when bootloading a new .s19, the reset vector is erased