Kinetis Bootloader from Application Code

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

Kinetis Bootloader from Application Code

1,288 Views
JBM
Contributor IV

I have been following this thread:

Kinetis bootloader start from application 

and have implemented everything (I think).  I'm using the Freedom Bootloader with a K22 Freedom development board.  I did the following:

1) Downloaded the bootloader source, MCUXpresso IDE

2) Compiled the bootloader source

3) Created some LED blinking applications (one red, one green and one blue) to load (these were created with KDS)

4) Tested it on an FRDMK22 board -- it works.  I can install the bootloader, talk to it with blhost.exe and the KinetisFlashTool.  I can send applications to be loaded and it loads them successfully and the leds blink as expected.

Since I need to be able to call it from application code, I made the following changes:

1) We only need serial, so I configured a BCA to only use serial (I had to move the BCA address in the bootloader startup to make room for the K22 interrupt table and the flash config).  I also disabled the bootloader timeout and crc checking.

2) Modified my applications to set RFSYS_REG0 to 0x01 just before calling NVIC_SystemReset() and to reset when switch on the development board is pressed.  Here is that section of code (it is in main.c in the blink.zip file) -- I disable interrupts, set the bit in the register file and reset the system.

DisableInterrupts;
/*
 * Tell the boot loader to start
 */
 RFSYS_REG0 |= 0x01; /* Signal for boot loader */
 NVIC_SystemReset();

3) Modified the boot loader to look at RFSYS_REG0 by adding a function to call -- analogous to the boot pin check:

    if (!(is_reg_file_set(true) || is_boot_pin_asserted()) && is_application_ready_for_executing(applicationAddress))

My thinking was that my bit in the register file could act just like the boot pin.

This seems to work with one exception.  I can start the boot loader, load application code, and execute it.  When I press switch 2, the application code exits, but the boot loader will not talk over the serial port.   The blhost.exe message looks like:

Error: UartPeripheral() cannot open PC UART port(COM13), speed(57600 Hz).

Similarly, the KinetisFlashTool error is:

Error: Connect device failed(Error: Initial ping failure: No response received for ping command.).

If I reset the board, I can talk to the bootloader again.  

I have code in the blink application that opens the serial port (default UART1 on Port E 0 & 1 -- same as the boatload).  I thought that might be a problem and ran a test with it commented out -- didn't matter.

I'm using a USB to serial converter cable to talk to the board (trying to match our desired hardware configuration as much as possible).  I program with a PEMicro Multilink Universal.

I was trying to attach the debugger to the running bootloader to see what it was doing, but didnt' have any luck (maybe I'm just not doing it right).

0 Kudos
3 Replies

920 Views
jingpan
NXP TechSupport
NXP TechSupport

Hi,

I tested your code. It seems the problem lies in blink. You call ports_done, this cause system fall into a isolated and unknown status. I think is step can be omited. NVIC_SystemReset() can make all pin back to default status.

Regards,

Jing

0 Kudos

920 Views
JBM
Contributor IV

It was a stupid mistake on my part.  I wasn't clocking port B, so I was probably getting a fault in ports_done() and the bootloader was never started.

Thanks for the help!

0 Kudos

920 Views
JBM
Contributor IV

Thanks, I will give that a try.  I'm not sure I understand why disabling ports would affect the bootloader though.  I'll see if I can find it.

0 Kudos