I am creating a USB based bootloader.
I have two hex files or programs. Bootloader code is burned into ROM with P&E micro programmer.
THis bootloader code erases and burns my Application code into ROM.
I have protected area of 8kb(E000 - FFFF) and I am using vector table at default place in Bootloader code and my Application code has redirected vector tables to DFC4.
Things are pretty fine till here. After I am done with my bootloader I can start my Application code by a Jump to _EntryPoint where my APllication code resides. My Application gets powered up but then doesn't start reason being NVOPT_INIT which still stays "Vector REdirection" is false ie as NVOPT_INIT lies at location FFBF, I can not write to it as it is a protected area. However, as it still contains value from Bootloader code ie 0x7E, which should be 0x3E for Application code, my application fails.
So, in short how can I update this NVOPT once I am done with my Bootloader code?
I am using 9S08JM60 micro controlloer and Code Warrior IDE Version 5.9.0
Thanks
解決済! 解決策の投稿を見る。
Hello,
I think that you will not be able to use automatic vector redirection, but will need to determine from within the boot loader, whether particular vector is to be redirected to the application ISR code. For example, the interrupt vector at address 0xFFC4 would point to ISR code within the bootloader, but the boot loader would know in advance that the vector at location 0xDFC4 would point to the corresponding application ISR code.
This is relatively easy to handle using assembly, but I am not sure about the C coding equivalent. Perhaps others may be able to help in this respect.
; Part of bootloader codeISR_INT29: ; Vector at $FFC4 points here pshh ; Do bootloader ISR processing and exit ; else handle redirection to application code ldhx #$DFC4 ; Relocated vector jmp DO_ISR; The above code can be replicatated to suit the other vectors, ; except for the reset vector.DO_ISR: ; Execute application ISR - common code ldhx ,x ; Fetch vector contents cphx #$FFFF ; Test for unprogrammed vector beq DI1 ; Branch if unprogrammed jsr .x ; Execute ISRDI1: pulh rti
Note that the application ISR code should terminate with RTS, rather than RTI. In C, this means that a normal function should be used for the ISR code, rather than an interrupt function.
Regards,
Mac
This is something I was looking for, thanks for your response. However, my application still doesn't start up(it is a serial comm interrupt based application). This is what I am doing:
In Bootloader Vector.c:
ISR(AS1_InterruptTx)
{
asm
{
pshh
ldhx #$DFD4
jmp DO_ISR
}
}
.......Similar for other vectors with different address...........
.....................................................................................................
void DO_ISR()
{
asm
{
ldhx ,x
cphx #$FFFF
beq DI1
jsr ,x
DI1:
pulh
rti
}
}
****************************Application Vector.c***********************************
I changed:
ISR(AS1_InterruptTx)
{
...........
...........
}
To:
void AS1_InterruptTx()
{
..........
..........
}
****************************************************************************************
Apart from that, I have kept Vectors at default place 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 overite to this registers as they are protected. However, whenever an interrupt comes it goes to vector table located at 0xFFC4 which further sends it to 0xDFC4.
Logically this seems to be a convincing solution from what all I was trying, however it doesn't seem to work.
Thanks
Hello,
If your application is not starting, there is a problem with jumping from the bootloader code to the the start of the application code. This needs to be handled a little differently than the re-direction of the other interrupt vectors. For the purpose of discussion, I will assume that the vector to the start of the application code is held at address 0xDFFE.
To implement a jump to this location might involve the following code within the bootloader.
asm { ldhx 0xDFFE; // Application startup vector ldhx ,x // Fetch vector contents jmp ,x // Direct jump to application startup }
Once the application code commences, it should never exit, so there is no need to save any register values prior to the jump.
Regards,
Mac
My application does start which I can say because I have a power on routine which gets executed but stops at a point when Serial communication interrupt starts.
I'm not aware of any 'direct' way to have two vector tables -- one for bootloader, and one for application use 'later'. The NVOPT_INIT values can only be set directly at reset from flash. Thus, my bootloaders run 'no interrupts at all'.