Ruth Hendrix

CW & HC12D60A VECTOR RELOCATION

Discussion created by Ruth Hendrix Employee on Jan 26, 2006
This message contains an entire topic ported from a separate forum. The original message and all replies are in this single message. We have seeded this new forum with selected information that we expect will be of value to you as you search for answers to your questions.
 
Posted: Fri Feb 18, 2005 11:37 am    
 
Hello,
I am using Metrowerks CW for the HC12D60A MCU. I have written a bootloader routine that is located in the upper 32K's bootblock region (upper 8K which includes the interupt vectors). In the application code I used the vector keyword in the flash.prm file and also defined a segment NEW_VECTORS from $DF80 to $DFFB to contain the relocated vectors and had a vector.c file that defined a constant array like this:

Flash.prm file looks like this:
Code:
SECTIONS RAM = READ_WRITE 0x0000 TO 0x06FF; FEE28 = READ_ONLY 0x1000 TO 0x7FFF; FEE32 = READ_ONLY 0x8000 TO 0xDF00; EEPROM1 = NO_INIT 0x0C00 TO 0x0EFF; EEPROM2 = NO_INIT 0x0F00 TO 0x0FFF; END PLACEMENT DEFAULT_ROM, ROM_VAR, STRINGS INTO FEE28, FEE32; DEFAULT_RAM INTO RAM; EEprom_Data1 INTO EEPROM1; EEprom_Data2 INTO EEPROM2; CODE_START INTO READ_ONLY 0xDF40 TO 0xDF43; NEW_VECTORS INTO READ_ONLY 0xDF80 TO 0xDFFB; END STACKTOP 0x7FF VECTOR 4 _VECTOR_REMAP_ OFFSET 100 // VECTOR 5 _VECTOR_REMAP_ OFFSET 96 // 

 
etc........

vector.c looks like this with entries for each interupt vector:
Code:
#pragma CODE_SEG NEW_VECTORS const short _VECTOR_REMAP_[] = { 0xA706, /* NOP, JMP */ (const short) BootBlock_ISR,etc.. }; 

 
I recently fixed a bug in my bootloader that was not checking the last sector of flash written for success or not. In doing this my download program fails the last sector of application code written because using the method above to relocate the interupt vectors produces the right relocated vectors and jumps from $DF80 to DFFB, but also produces vectors at the original location $FFC4 to $FFFF pointing to the secondary vector table. My bootloader has the locations of the secondary interupt table programmed into the original interupt vector table @$FFC0 to $FFFF. When my downloader gets to the application code *.s19 record @$FFC4 and above it correctly fails the program test because I have that 8K bootblock protected. Is there anyway to relocate the vectors so they show up in the *s19 $DF80 to DFFB and not get the code at the original vectors showing up in the *.s19??? If I remove the vector keywords from the flash.prm file both the original and the relocated vectors disappear from the *.s19 output file. Any help would be greatly appreciated. I am kinda new to the metrowerks toolset. I have compiled this in the GNU version for the hc12 with proper results.

Thanks,
Posted: Sat Feb 19, 2005 1:56 am    
 
Hello,

As I did not tested this with all your files and configuration, I can not be 100% of what I write here but I will try :

First some remarks about what you call "relocated vectors" : these are not real "vectors" but more "jump routines" so to speak since it is executable code.

However since you implemented them as a const table I think the right #pragma to locate them would be "#pragma CONST_SECTION NEW_VECTORS"

The problem when you delete the VECTOR is probably that the MW linker gets rid of every single constant that is not used somewhere else in the code.

One method I would recommend is to let the VECTOR undeleted in the prm but to implement in your bootloader code a test on the address that is about to be programmed and reject flash programming (do nothing) for addresses within the protected bootblock.
That way your application can be used either with or without bootloader using the standard BDM programmer.

The other would be to remove the #pragma, the NEW_VECTORS section in the .prm file and directly specifying in your vector.c :

const short _VECTOR_REMAP_[] @0xDF80 = {
0xA706, ...

This way you will force the inclusion of the constant table in your .s19 file.

And another one last remark : with MW you can inline assembler code without writing any hexadecimal code, just like this :
Code:
#pragma NO_EXIT void Vector80_jr (void) { _asm { NOP JMP BootBlock_ISR } } 

 
Not really more compact but less obfuscated to me...
(notice that this time you would need to use the CODE_SECTION #pragma)

HTH

Outcomes