I have been following this thread:
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.
* Tell the boot loader to start
RFSYS_REG0 |= 0x01; /* Signal for boot loader */
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).