0
votes

I have issue with vector tables(Interrupt tables) which are in Bootloader code and could not be accessed by my Application code. Well, the main issue is that the address of ISRs is different in Bootloader and Application code. So, my application fails to start. Any suggestion of how can I make my application code to find correct ISR routine addresses from my Vector table??

I am using HCS08 and Code warrior. It is a USB Bootloader which is loaded into FLASH by programmer and which further loads a S19 file though USB. So, there are two programs lying on my FLASH.

3
You need to be more specific: what processor, what bootloader and what application? - casablanca
Edited my question with specific details. - Punit

3 Answers

1
votes

The HCS08 supports vector redirection, but not multiple vector tables (see the quote at the end of my answer). This thread provides an interesting discussion. From what I read, there is no straight-forward way to use multiple vector tables in FLASH on the HCS08. This leaves you with only a few options:

  1. A RAM vector table
  2. No interrupts in your bootloader
  3. Relocate vectors to unprotected flash and have both the boot and app use that table

RAM Vector Table

You could force interrupt vectors to look up their address in RAM. To do this, you would use the primary vector table location. Each vector would be set to a function which jumped to a RAM address. The RAM address would be the location of your interrupt code.

With this strategy, your application and bootloader code could specify different interrupt functions. It could be risky to use RAM for your vectors.

No Interrupts in the Bootloader

Another option would be to implement your bootloader without interrupts. You could then protect the bootloader memory, redirect the vector location and have your application program the vector table.

Relocate vectors to unprotected flash

See AN2140 for a discussion on this technique.

The following comes from the datasheet for the MC9S08EL/SL:

4.5.8 Vector Redirection

Whenever any FLASH is block protected, the reset and interrupt vectors will be protected. Vector redirection allows users to modify interrupt vector information without unprotecting bootloader and reset vector space. Vector redirection is enabled by programming the FNORED bit in the NVOPT register located at address 0xFFBF to 0. For redirection to occur, at least some portion of the FLASH memory must be block protected by programming the NVPROT register located at address 0xFFBD. All interrupt vectors (memory locations 0xFFC0–0xFFFD) are redirected, though the reset vector (0xFFFE:0xFFFF) is not.

For example, if 1024 bytes of FLASH are protected, the protected address region is from 0xFC00 through 0xFFFF. The interrupt vectors (0xFFC0–0xFFFD) are redirected to the locations 0xFBC0–0xFBFD. If vector redirection is enabled and an interrupt occurs, the values in the locations 0xFBE0:0xFBE1 are used for the vector instead of the values in the locations 0xFFE0:0xFFE1. This allows the user to reprogram the unprotected portion of the FLASH with new program code including new interrupt vector values while leaving the protected area, which includes the default vector locations, unchanged.

See also this application note (AN2295) about implementing a serial bootloader for this family of micros.

0
votes

I'm not an HCS08 expert, but often there are mechanisms to remap or redirect the vectors so you can load software and use new interrupt vectors without disturbing your bootloader. I don't know which exact chip you're using, but try searching for "Vector Redirection" in your chip's reference manual.

0
votes

I have found here which seems to be correct, however it is not working:

***Bootloader Vector.c:*******

ISR(AS1_InterruptTx) { asm { pshh ldhx #$DFD4 pshx jmp DO_ISR } } .......Similar for other vectors with different address...........

..................................................................

void DO_ISR() { asm { pulx ldhx ,x
cphx #$FFFF
beq DI1
jsr ,x

DI1: pulh rti } }

************In Application Vector.c******************

I changed:

ISR(AS1_InterruptTx)

{

...........

...........

}

To:

void AS1_InterruptTx() {

..........

..........

}


Apart from that, I have kept Vectors at default place in Bootloader ie 0xFFC4 and I have redirected Vector table in Application code to 0xDFC4.

The value of NVPROT_INIT being 0xDE and NVOPT_INIT being 0x7E. Although this conflicts with what should be for Application code (NVOPT = 0x3E for redirection), but we can not overwrite to this register as they are protected. However, whenever an interrupt comes it goes to vector table located at 0xFFC4 which further sends it to 0xDFC4.

Does this seems to be a good way to deal with this issue?