I wrote the application code into the flash of address 0x740000 by CAN,but I don't know how to jump to the application from my bootloader code.
some config must be done,I don't know how to do.
In AN2458,it suggests that I should modify the .prm file,I want to know some more datailed explanation.and do I have to to some other operation.
who can help me?
Solved! Go to Solution.
Hi Youdong,
It seems that the AN2458 MPC5200 Local Plus Bus Interface do not refer to S12XE bootloader topic.
Do you mean AN4258 Serial Bootloader for S12(X) Microcontrollers Based on 180 nm Technology?
If yes, the jump into the application is realized through MCU reset.
The AN4258 software consists of three main parts.
1. Bootloader code
2. Application code
3. Tiny dispatching code in assembler which decide whether Bootloader or Application will be executed.
The dispatching code is in Bootloader project in StartS12X.s file.
It defines reset vector of user application at address 0xEFFE, detect bootloader condition (e.g. pressed the button) and check whether reset vector of user application is in erased state or not.
The jump to bootloader is executed when bootloader condition come true or when reset vector of user application is in erased (application was not loaded yet).
In other cases, the jump into application code is performed.
About Application code)
The procedure is specified in chapter 6 How to write a user application.
The main tasks are trimming prm linker file for avoiding bootloader and application overlapping and creating application interrupt vector table somewhere in RAM or Flash with appropriate IVBR register settings. The example demo application project is part of the AN4258SW package.
When you make your application project, you must convert generated s19 file by the SRecCvt utility.
When you will load converted the s19 file into MCU, the bootloader code will automatically take original application reset vector from address 0xFFFE and program it at address 0xEFFE.
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!
-----------------------------------------------------------------------------------------------------------------------
Hi Youdong,
It seems that the AN2458 MPC5200 Local Plus Bus Interface do not refer to S12XE bootloader topic.
Do you mean AN4258 Serial Bootloader for S12(X) Microcontrollers Based on 180 nm Technology?
If yes, the jump into the application is realized through MCU reset.
The AN4258 software consists of three main parts.
1. Bootloader code
2. Application code
3. Tiny dispatching code in assembler which decide whether Bootloader or Application will be executed.
The dispatching code is in Bootloader project in StartS12X.s file.
It defines reset vector of user application at address 0xEFFE, detect bootloader condition (e.g. pressed the button) and check whether reset vector of user application is in erased state or not.
The jump to bootloader is executed when bootloader condition come true or when reset vector of user application is in erased (application was not loaded yet).
In other cases, the jump into application code is performed.
About Application code)
The procedure is specified in chapter 6 How to write a user application.
The main tasks are trimming prm linker file for avoiding bootloader and application overlapping and creating application interrupt vector table somewhere in RAM or Flash with appropriate IVBR register settings. The example demo application project is part of the AN4258SW package.
When you make your application project, you must convert generated s19 file by the SRecCvt utility.
When you will load converted the s19 file into MCU, the bootloader code will automatically take original application reset vector from address 0xFFFE and program it at address 0xEFFE.
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!
-----------------------------------------------------------------------------------------------------------------------
Hello Radek:
you are right.And thank you to answer my question.
Now,I have two other problems:
first,I can't change the state of pin PP0 to decide start the bootloader or the user application,so I have to sellect the other ways to decide which program code will be start.I want to write a key into the address of 0x70000 or any other address.through check the key in that address,I decide to which code will be start.how to make the bootloader code to realize the function?
second,In the demo of AN4258SW,The rom code segment of bootloader is from 0xFF000 to 0x7FFCFF and ram code segment is from 0x7FFD00 to 0x7FFEFF.if I want to enlarge the rom code segment and the ram code segment,how to do it?
could you help me?
Hi Youdong,
I suppose that you mean global address 0x700000 instead 0x70000. Such address is quite inconvenient since you should access it through paged access and you should allocate whole 1kB P-Flash sector just for this key (you must erase sector prior any writing). I suppose that EEPROM, D-Flash or potentially also RAM may be used rather than P-Flash.
The RAM content is unaffected by a system reset, but its value is also random after power-up. So, there is still tiny chance that random value may fit our key. For that case, we should combine it with testing PORF flag followed by clearing this flag. The code will jump into bootloader only when Bootloader key will fit and PORF flag is 0 OR when the application is not loaded yet (=erased AppResetVect).
You may use similar code as code for check whether AppResetVect is already written. Here I used BootloaderKey at EEPROM address 0x0C00 with valid value 0x5AA5
BootloaderKey: equ $0C00; here is stored key for enter into bootloader. 0x0C00 points to EEPROM.
ldd BootloaderKey
cpd #$5AA5 ; compare the content of accumulator D with a 16-bit Bootloader key value
beq GoBoot ; if the BootloaderKey fits
; then start the bootloader
ldd AppResetVect
cpd #$ffff
beq GoBoot ; if the application reset vector is not available
; then start the bootloader
ldx AppResetVect
jmp 0,x ; jump to the application
Note: I didn’t test this code – it is rather a just idea.
About your second question)
You may edit bootloader prm linker file and modify RAM_CODE_SEG, ROM_F000 segment ranges.
When you increase the size of RAM_CODE_SEG segment, you should also move down higher RAM segment border.
For example:
RAM = READ_WRITE 0x3700 TO 0x3AFF;
RAM_CODE_SEG = READ_ONLY 0xFB00 TO 0xFEFF RELOCATE_TO 0x3B00;
ROM_E000 = READ_ONLY 0xE000 TO 0xFAFF;
//…
NON_BANKED INTO ROM_E000;
Since we increased RAM_CODE_SEG segment size, we have to edit also address in RAM where we copy this code. Unfortunately, the address is not in macro, but directly hard coded in CopyCodeToRAM() function. Please edit:
// Dst = (UINT8 *)0x3D00;
Dst = (UINT8 *)0x3B00;
Since the original area 0xEFE0~0xEFFF is used for application reset vector, we should move it to somewhere else – the optimal area is between application and bootloader area – for example into 0xDFE0~0xDFFF.
In that case, we should edit main.c:
//#define RESET_VEC_DST 0x7FEFF8
#define RESET_VEC_DST 0x7FDFF8
And Start12X.s:
AppResetVect: equ $dffe ; here is stored reset vector of user application
And finally, the prm linker file in the application project must be updated accordingly. For example:
ROM_C000 = READ_ONLY DATA_NEAR IBCC_NEAR 0xC000 TO 0xDFDF;
Note: Again, I didn’t test this code – it is rather a just idea.
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!
-----------------------------------------------------------------------------------------------------------------------
Hello Sestak
Thank your help ,I have completed the bootloader by CAN with your help.
0x740000 seems being global address. Then you need to convert it to paged and jump to or treat startup address as function and call it. For example like this
#define global_to_ppage(x) ((((x - 0x400000) / 0x4000) * 0x10000) + (x % 0x4000) + 0x8000)
bootloader()
{
...
// like this
((void (* far )(void))global_to_ppage(0x740000))();
// or like this
__asm{
MOVW #global_to_ppage(0x740000), 2,-sp
MOVB #global_to_ppage(0x740000) / 0x10000, 1,-sp
RTC
}
// or, in case bootloader is nonpaged and you are safe to manipulate PPAGE directly, either
PPAGE = global_to_ppage(0x740000) / 0x10000;
((void (* near)(void))global_to_ppage(0x740000))();
// or
PPAGE = global_to_ppage(0x740000) / 0x10000;
__asm JMP global_to_ppage(0x740000);
Hello Edward
Thanks your help.
following your way,maybe it had jumped to adress of 0x740000,but the application doesn't work.
According to the document AN4258,I should modify the .prm file and start12x.s file.I don't know how to modify them.
Maybe, some other operation will also be done.
Furthermore,how to relocate interrupt vector table to make the application work normally.
Do you have some demo ?
I am writing a bootloader code and download the bootloader code into flash using the BMD.I will update application by the bootloader.
Do you have some recommendations or some demos.Thank you~~