Kinetis bootloader start from application

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Kinetis bootloader start from application

Jump to solution
1,560 Views
dusek_martin
Contributor IV

Hi,

I want to initiate firmware upgrade from application, so I want to start bootloader (KBOOT 2) from application and keep it running. I didn't find this option in bootloader. Do I have to program it myself? Can you recommend how to do it? Eg. write some register that is guaranted not to change during reset with an information, that bootloader should and perform software reset to enter bootloader...?

Next question: I would like to enter my app with all peripherals, clocks, etc. unitialized. I think Kinetis bootloader initializes some peripherals, clocks, etc. and then it jumps to application's reset vector. Is there an option, where e.g. bootloader writes some register that is guaranted not to change during reset with an information that application should run, then it executes software reset and during next bootloader startup, it checks that register and it immediatelly jumps to the application? Or, again, do I have to implement it myself?

Labels (1)
0 Kudos
1 Solution
1,232 Views
jingpan
NXP TechSupport
NXP TechSupport

No, you have to modify the code. But if the MCU has register file, I think it's not very difficult.

View solution in original post

0 Kudos
10 Replies
1,233 Views
jingpan
NXP TechSupport
NXP TechSupport

No, you have to modify the code. But if the MCU has register file, I think it's not very difficult.

0 Kudos
1,232 Views
dusek_martin
Contributor IV

No problem, I will modify it. When switching between bootloader and application I prefere performing that by writing some register/RAM with information whether bootloader/app should run followed by software reset.

Is RAM or some registers guaranteed not to be modified during software reset?

If not I thought about using some RTC registers (e.g. RTC alaram register which I'm not going to use in my app) which are persistent as long as VBAT is present.

0 Kudos
1,232 Views
jingpan
NXP TechSupport
NXP TechSupport

Hi,

please search "register file" in reference manual.

registerfile.png

0 Kudos
1,232 Views
dusek_martin
Contributor IV

I'm sorry, I didn't understand what you mean by register file in your previous post.

So great, there will be no problem in implementing what I want. Thanks

0 Kudos
1,232 Views
jingpan
NXP TechSupport
NXP TechSupport

Hi Martin,

Flashloader hasn't run_bootloader() function. But in fact, if you look into its final code bootloader_user_entry(), it only reset the chip. So, if you want to jump back to bootloader, just call NVIC_SystemReset().

After reset, the bootloader will wait for peripheral connection. The default time is 5000ms which is defined in bootloader_config.h. The macro name is BL_DEFAULT_PERIPHERAL_DETECT_TIMEOUT.

If you want to keep some value when system reset, you can put the value in sytem register file. It reset by POR only. Not all of kinetis device has this register file. But most of them have. If the chip you're using hasn't it, you have to save data into flash or external memory.

Regards,

Jing

0 Kudos
1,232 Views
dusek_martin
Contributor IV

Hi Jing,

thanks for your reply.

In normal situation the bootloader should not wait and should jump to valid application immediatelly (the user of my device can't wait 5 seconds every time the device is turned on for bootloader to timeout and jump to application).

In a situation, where user of my application explicitly requests bootloader to run, the bootloader should wait 5 s (or even longer, till next reset) for peripheral to connect.

Is that possible with kinetis bootloader? 

0 Kudos
1,232 Views
bobpaddock
Senior Contributor III

See the attached files for correctly formatted code.

.h:

   void boot_loader_start( void ) __attribute__ ((noreturn));

.c:


/* Function Pointer returning void, passed void pointer: */
void (*_boot_loader_start)( void * arg );

void boot_loader_start( void )
{
/* Read the function address from the ROM API tree: */
uint32_t const _boot_loader_start_address = **(uint32_t **)(0x1C00001CUL);

/* Turn address in to a function pointer: */


_boot_loader_start = (void (*)(void * arg))_boot_loader_start_address;

_boot_loader_start( NULL ); /* Call the function. Will not return from here */

for(;;) /* Pacify the compiler about returning from a no return function */
;
}

0 Kudos
1,232 Views
dusek_martin
Contributor IV

Thanks. I don't use ROM bootloader but flash resident bootloader. I guess I haveto change the 0x1C00001CUL to my bootloader's start address which is 0x0 as my bootloader is at the beginning of the flash. So I guess this code can be replaced by performing software cpu reset.

The problem is: when bootloader starts, it detects valid application and immediatelly jumps back to my application. I want the bootloader to run and wait till host (USB HID in my case) connects to it and performs firmware upgrade.

0 Kudos
1,232 Views
bobpaddock
Senior Contributor III
I want to start bootloader (KBOOT 2)

I took that as you were using the KBOOT-2 bootloader in the standard ROM.
The ROM gives the address of the actual bootloader start at a known location, so have to look up that value before using it.


0 Kudos
1,232 Views
dusek_martin
Contributor IV

But still, will the bootloader wait for the user to connect to it or will it detect valid application and automatically jump to it? I think this is not solution to my problem.

0 Kudos