0

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.

Punit
  • 37
  • 2
  • 6

3 Answers3

1

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.

Tim Henigan
  • 60,452
  • 11
  • 85
  • 78
  • Yes, this feature is there in my controller. However, may be I am misunderstanding something somewhere. So, here is the situation: Bootloader need to protect its vector table, so even if it is redirected I need to protect it as I am using USb Interrupt in Bootloader. So, as this HAS to be protected then I can not over write it for my Application's vector table. Moreover, the address of ISRs is different in both Bootloader and Application code. Please improve me here. – Punit Nov 21 '10 at 23:50
  • @Punit: Your bootloader will always use the primary vector table (0xFFC0-0xFFFD) which resides in protected memory. It will not modify the FNORED register. Your application will always use the secondary vector table (0xFBE0 or where ever it resides for your application). When the application runs, it sets FNORED which routes interrupts to the secondary table. Only your application needs to be concerned with the secondary vector table. – Tim Henigan Nov 22 '10 at 00:32
  • If I understand: Bootloader uses default vector table ie at FBC4. but NVOPT(0x7E) AND NVPROT have some value Application uses redirected vector table at DBC4(do not remember exact address), although my vector table is fine here as I can write it BUT NVOPT(0x3E). Now, as NVOPT and NVPROT are written ONLY at reset, my application code can not re-write this. Am I correct? – Punit Nov 22 '10 at 00:45
  • @Punit: That sounds correct (disclaimer: I have never implemented this on an HCS08, but have used similar strategies on HCS12) – Tim Henigan Nov 22 '10 at 01:38
  • But that is the issue, I can not have two vector tables as NVOPT and NVPROT could not be re-written as they are set at RESET only. Moreover, they lie in the protected FLASH area. If they are not updated for Application code (ie once bootloader code gets executed and starts Application code) then my Application code fails. Really appreciate your response. – Punit Nov 22 '10 at 01:50
  • @Punit: I now see your point. I updated my answer with some new ideas. – Tim Henigan Nov 22 '10 at 02:53
  • RAM vector table only seems to be an option. I need to use Interrupt in Bootlaoder. We can not have Vector tables in unprotected area to be shared by Application and Bootloader code, because Application code can only write after EEPROM erase and if erased, Bootloader code will stop working thereafter. Anyways thanks for your response. I will try to implement first option. – Punit Nov 22 '10 at 03:55
0

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.

Splat
  • 753
  • 3
  • 10
  • Yes, vector redirection is available however, it also need to be protected as Bootloader also uses one interrupt and needs this vector table. And my application code requires lot of interrupts and the address of these ISRs also varies. Please suggest something. – Punit Nov 21 '10 at 23:55
0

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?

Punit
  • 35
  • 1
  • 1
  • 5