cancel
Showing results for 
Search instead for 
Did you mean: 

jump from custom bootloader to main user application

rhoek9
Associate II
Posted on November 18, 2009 at 08:54

jump from custom bootloader to main user application

5 REPLIES 5
rhoek9
Associate II
Posted on May 17, 2011 at 15:05

Hi,

I am working on a custom bootloader code for the STM8S207 / 208.

for 90% its finished, I can write the firmware to flash with my custom bootloader. also reading, erassing and other things.

the next step is to jump van the ''custom bootloader'' to the ''firmware''.

using the standard jump routings that are used in the example code AN2659.

I am using the ST Visual decelop software with the 16k free cosmic toolset.

The disassebly view in debugging mode shows that the jump is made to the start of the firmware location (0xA400).(using breakpoints to check this) But when I run the program from the breakpoint is jumps back to 0x8210.

when i have written the firmware to the microcontroller what are the steps needed to succesfully run the firmware????

i have the impression that i am forgetting a few steps.

http://www.st.com/mcu/forums-cat-8781-27.html&start=0

http://null

luca239955_st
Associate III
Posted on May 17, 2011 at 15:05

Hello,

you don't provide many details... but, assuming that the problem is not trivial (that is, the application is linked to run at the address where it is actually stored, and you can execute at least its first assembler instructions), the problem might come from interrupts: if you use them both in the BL and in the application, you need to re-route the interrupt table before giving control to the user application.

Hope it helps.

Regards,

Luca (Cosmic)

rhoek9
Associate II
Posted on May 17, 2011 at 15:05

nevermind the questings in de last reply, I got it working now.

make a few mistacs:

Firmware starting locations

I needed to alter the starting address of the firmware (0x8080) and its interrupt table (0x8000). that is why it jump back every time.

interrupt table

I replaced the bootloader interrupt vector table at location 0x8080 with a jump table that redirect every interrupt to a location outside custom bootloader protection area. when the bootloader starts it will write the CBL table or that of the firware to the ''jump to location''.

rhoek9
Associate II
Posted on May 17, 2011 at 15:05

Code:

<BR><BR><BR>//typedef @far void (*)(void) TFunction; <BR><BR><BR>typedef @far void (*TFunction)(void); <BR><BR><BR> <BR><BR><BR>//main application code (user reset) - init user code start - to interrupt table reset jump <BR><BR><BR>const TFunction MainUserApplication = (TFunction)MAIN_USER_RESET_ADDR; <BR><BR><BR>//address for GO command <BR><BR><BR>TFunction GoAddress; <BR><BR><BR> <BR><BR><BR>u8 RoutinesInRAM = 0; //if routines loaded into RAM <BR><BR><BR> <BR><BR><BR>void main() <BR><BR><BR>{ <BR><BR><BR> // disable interrupts <BR><BR><BR> disableInterrupts(); <BR><BR><BR> RoutinesInRAM = 0; <BR><BR><BR> <BR><BR><BR> //check EEPROM to check if the Custom Bootloader is enabled. ENABLE_CBL = 0x33, ENABLE_CBL_NEG = 0xCC <BR><BR><BR> if(!((*((@far u8*)CBL_EEPROM_LOCATION1)==ENABLE_CBL) <BR><BR><BR> && (*((@far u8*)CBL_EEPROM_LOCATION2)==ENABLE_CBL_NEG))) <BR><BR><BR> { <BR><BR><BR> //if user application is not virgin - valid reset vector jump <BR><BR><BR> if((*((@far u8*)MainUserApplication)==0x82) || (*((@far u8*)MainUserApplication)==0xAC)) <BR><BR><BR> { <BR><BR><BR> //reset stack pointer (lower byte - because compiler decreases SP with some bytes) <BR><BR><BR> _asm(''LDW X, SP ''); <BR><BR><BR> _asm(''LD A, $FF''); <BR><BR><BR> _asm(''LD XL, A ''); <BR><BR><BR> _asm(''LDW SP, X ''); <BR><BR><BR> <BR><BR><BR> // then jump to user application <BR><BR><BR> _asm(''JPF [_MainUserApplication]''); <BR><BR><BR> //MainUserApplication(); <BR><BR><BR> } <BR><BR><BR> } //else start bootloader itself <BR><BR><BR> <BR><BR><BR> // copy routines to RAM <BR><BR><BR> _fctcpy('F'); <BR><BR><BR> RoutinesInRAM = 1; <BR><BR><BR> <BR><BR><BR> //set unlock keys <BR><BR><BR> FLASH_Unlock(FLASH_MEMTYPE_PROG); <BR><BR><BR> FLASH_Unlock(FLASH_MEMTYPE_DATA); <BR><BR><BR> <BR><BR><BR>//main while is removed, also a few variables!! <BR><BR><BR> <BR><BR><BR> //received GO command - set back all microcontroller changes to reset values <BR><BR><BR> DeInitBootloader(); <BR><BR><BR> <BR><BR><BR> <BR><BR><BR> // Erase the custom bootloader enable bytes <BR><BR><BR> FLASH_EraseByte(CBL_EEPROM_LOCATION1); <BR><BR><BR> FLASH_EraseByte(CBL_EEPROM_LOCATION2); <BR><BR><BR> <BR><BR><BR> //lock flash program and data memory <BR><BR><BR> if(RoutinesInRAM) <BR><BR><BR> { <BR><BR><BR> FLASH_Lock(FLASH_MEMTYPE_PROG); <BR><BR><BR> FLASH_Lock(FLASH_MEMTYPE_DATA); <BR><BR><BR> } <BR><BR><BR> <BR><BR><BR> //jump to GO address <BR><BR><BR> GoAddress(); <BR><BR><BR> }while (1); <BR><BR><BR>}//main <BR><BR><BR>//************************************************************************** <BR><BR><BR>

So there are 3 way I can jump to the firmware code in the described bootloader code.

_asm(''JPF [_MainUserApplication]'');

GoAddress();

MainUserApplication();

all point to the same address: 0xA400

when run in debugger (ST develop, cosmic toolset)

(Disassembly view) breakpoint at jump location 0xA400:

0xa400 0x820081ED INT 0x0081ed INT 0x0081ed

when I continue the code and pause it again after a few seconds it will stop at around 0x8200 location

When the bootloader code is started the interrupts are disabled but in the bootloader init I enable them.

I am using the “stm8_interrupt_vector.c�? and when I look at the first few bytes of the custom bootloader code it seems that the first +/-128 bytes are used for interrupts. (a lote of 0x82)

The test application that i wrote to the flash is a simple program. so far i can see it does not use any interrups, exept maybe the reset interrupt.

first few bytes of the test application:

00:A400: 82 00 81 ED 31 32 33 34

00:A408: 36 35 34 39 38 31 33 32

00:A410: 31 36 34 32 31 33 34 36

As you indicated in you reply I need to re-route the interrupts table.

So only jumping to the location of the code is not enough.

For a succesfull jump do i also need to erase the RAM, re-route the stackpointer?

Never redirected the interrupts table.

I guess it has something to do with the “stm8_interrupt_vector.c�?.

Can someone give me a hint or a example how to redirect the interrupt table?

And do I need to re-route the whole table or just the interrups I use in CBL and application because i dont know what for interrupts are going to be use in the application (firmware)?

Where to jump to, first address (0xA400) or jump over de interrupt area when using interrupts in application (firmware)?

Does the main application / firmware need to be specially prepared because of the custom bootloader or can i use standard applications?

[ This message was edited by: r.hoek on 28-10-2009 10:39 ]

[ This message was edited by: r.hoek on 28-10-2009 10:46 ]

[ This message was edited by: r.hoek on 28-10-2009 15:36 ]

movieira
Associate
Posted on May 17, 2011 at 15:05

Hi r.hoek

Can you show how you wrote your code to redirect the interrupt table?

Can you with your custom boot loader still able to debug your main application with the SWIN Debug tool?

I'm using the R-Link tool and when I change the UBC bits, the STVD showns a error message asking me to reduce the UBC size.

Regards