RESET_VEC of Bootloader_S12 in AN4258SW

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

RESET_VEC of Bootloader_S12 in AN4258SW

770 Views
rotato
Contributor II

Hi,

I cannot understand this code  in the file main.c  of project Bootloader_S12  in AN4258SW

 

if (ProgSRec.LoadAddr == RESET_VEC_SRC)
{
//Program reset vector to address 0xEFFE
if(Error = PFlash_Program(RESET_VEC_DST, (UINT16 *)&ProgSRec.Data[24]))
return(Error);
}

The question is:

1.Why only write the last 8 bytes of ProgSRec.Data  to PFlash, the VECTOR table is longer  than 8 bytes ,such as 64 bytes in S12G128 ?

2.Why do not write the ProgSRec.Data[0:23] to PFlash , What are the first 24 data in ProgSRec.Data ?

3.How to determine the address of RESET_VEC_SRC and RESET_VEC_DST ?

 

Best Regards

Labels (1)
3 Replies

510 Views
RadekS
NXP Employee
NXP Employee

Hi Yu,

1) this part of code write just application reset vector = address where the main application starts. The application vector table must be created in application project at non-default position (+ write into IVBR register). Since the application interrupt vector table is out of bootloader control, the application reset vector and application vector table must be handled separately.

This code takes last 8 bytes (minimum programmable size) with default reset vector from application project (= range 0xFFF8~0xFFFF, reset vector is at address 0xFFFE) and writes them at RESET_VEC_DST address somewhere in Flash dedicated for an application (out of Flash allocated for the bootloader).  

2) The first 24 bytes (range 0xFFE0~0xFFF7) are irrelevant because the application must already contain own vector table at a final position. These data should be 0xFFFF values anyway. Important is only last word with application reset vector.

3) the RESET_VEC_SRC value is the default and you shouldn’t change it. It points to the last 32 bytes S-record with default reset vector generated by application project linker in the last word.

The RESET_VEC_DST should be somewhere in the application’s Flash range. Since this reset vector is handled separately, the whole phrase (8 bytes) must be excluded from application use (due to ECC – for avoiding cumulative writes). So, the optimal position is the last 8 bytes from Flash allocated for the application. In such case, you do not need to split Flash range in application’s linker file (just strip out these last 8 bytes).

The application example in AN4258 defined last ROM_C000 segment as 0xC000 TO   0xEFDF. Here we excluded whole 32bytes (0xEFE0~0xEFFF) just for sure. The bootloader starts at address 0xF000.

So, if you modify bootloader to start at a different address, you should change also RESET_VEC_DST value.  


I hope it helps you

Have a great day,
Radek

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

510 Views
rotato
Contributor II

Hi Radek,

       Thank you for your reply,it is very useful for me.

       But I have some question about your words  " The first 24 bytes (range 0xFFE0~0xFFF7) are irrelevant because the application must already contain own vector table at a final position."

       The  vector table of S12G128 range from 0xFF80  to 0xFFFE.  In AN4258SW the bootloader program only write last 8 bytes of application reset vector  to flash segment,which address is the rest of application vector table written at?

       Does the application program need to change the vector table address?

0 Kudos

510 Views
RadekS
NXP Employee
NXP Employee

Hi Yu,
Good point.
The MCU reset vector at S12(X) devices are always on the address 0xFFFE. Therefore, for safety reason, the whole last Flash sector must be owned by the bootloader. We assume here, that bootloader will stay constant and we will update only Application versions.


Since the interrupt vectors and reset vector is in the same Flash sector, we cannot leave Application to access this area. The Flash sector must be erased prior to programming. An unexpected reset during that time may brick MCU (due to invalid reset vector).

The Application should create own interrupt vector table in Flash or RAM. This vector table must be aligned the same way as in original location. So, if default vector table starts at 0xFF80, the Application vector table must start at address 0xXX80, where XX is upper byte from Vector base = value which we will write into IVBR register.


Note: Since interrupt vectors are here only 16bit values, the vector table must be placed in near (non-banked) memory. Therefore, you may create a vector table in RAM OR in Flash 0x4000~0x7FFF OR in Flash 0xC000~Bootloder start address.

The Application example in AN4258 shows Application vector table at address 0x7F80.

const tIsrFunc VectorTable[] @0x7F80


I hope it helps you

Have a great day,
Radek

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------