Hi,
In a specific use case of the application I want to reset the application without triggering the bootloader. From my understanding this can be done by pointing the program counter to the startup code ? But not sure how this can be done ? Also not sure how to find the startup code address ?
Following is the environment I am working on:
MCU : MK20DX256VLL7
Compiler: gcc
IDE: code warrior
Any help would be greatly appreciated.
Hi Mark,
Thanks for the suggestion. I did something similar:
1. Disable interrupts
2. Called the startup function(this from my understanding automatically sets the PC and SP to the relevant addresses).
Cpu_DisableInt();
unsigned long startup = ((unsigned long*)0x00007800)[1]; /// The vector table start address is 7800.
((void(*)(void))startup)();
But I notice a behavior where the device starts from the main and starts executing but then resets after some time(through mostly hard fault).
Could you help me understand the behavior.
Hi
If you have a hard fault it is easy to solve because the hard fault is effectively showing you what has gone wrong.
Mostly it is because of accessing peripherals that haven't been enabled or an un-initialised pointer of some kind. With the debugger the reasons can directly be seen.
Regards
Mark
Hi Mark,
Thanks for the swift response. As you have rightly pointed out, I am using a custom bootloader. Now the challenge is that I am not allowed to change the source code for the bootloader. My idea is to start the application code(not the bootloader) in case on any fault(hard fault, bus fault etc). Could you suggest a mechanism ?
Thanks,
Hi
You will know the start address of the application and its initial stack pointer so you can load the SP and PC with these values and the program will restart.
Before doing this disable interrupt, power down used modules and disable interrupts and pending interrupts so that the processor is in more or less its HW reset state.
Regards
Mark
Eg.
uDisable_Interrupt();
SYSTICK_CSR = 0;
POWER_DOWN(5, (SIM_SCGC5_LPUART0));
IRQ0_31_CER = 0xffffffff;
IRQ32_63_CER = 0xffffffff;
IRQ64_95_CER = 0xffffffff;
IRQ0_31_CPR = 0xffffffff;
IRQ32_63_CPR = 0xffffffff;
IRQ64_95_CPR = 0xfffffff;
// load SP with initial stack pointer value
// load PC with application start address
Hi
The K20 has no (internal) boot loader so you must be referring to a loader that has been programmed to the board.
See appendix C of the uTasker boot loader guide for a method that it supports for allowing the application to command a reset WITH or WITHOUT the boot loader being started. This is a simple and reliable method that can also be added to any boot loaders if needed - it ensures a clean HW reset without complications that can arise by manipulating PC and SP to emulate a reset.
Regards
Mark
Kinetis: http://www.utasker.com/kinetis.html
Kinetis K20:
- http://www.utasker.com/kinetis/FRDM-K20D50M.html
- http://www.utasker.com/kinetis/TWR-K20D50M.html
- http://www.utasker.com/kinetis/TWR-K20D72M.html
- http://www.utasker.com/kinetis/TEENSY_3.1.html
- http://www.utasker.com/kinetis/tinyK20.html
For less questions and restrictions, and faster, cheaper developments: try uTasker for Kinetis