@@This article describes how to do in-system reprogramming of Kinetis for Cortex-M4 core devices using standard communication media such as SCI. Most of the codes are written in C so that make it easy to migrate to other MCUs. The solution has been adopted by customers.
This bootloader is based on FRDM-K22 demo board and KDS3.0. The bootloader and user application source codes are provided. GUI is also provided. Customer can make their own bootloader applications based on them. The application can be used to upgrade single target board and multi boards connected through networks such as RS485. The bootloader application checks the availability of the nodes between the input address range, and upgrades firmware nodes one by one automatically.
Key features of the bootloader:
For Cortex-M0+ products, please refer to here :Kinetis Bootloader to Update Multiple Devices in a Network - for Cortex-M0+ , it based on FRDM-KL26.
The main difference between Cortex-M4 and Cortex-M0+ is the FLASH program routine.
- In Cotex-M4 core kinetis, we need copy the Flash operating routines to RAM. In the bootloader code, the copy to ram code is realized in the function of “FLASH_Initialization()”:
Byte buffer[200]={0};
- In Cotex M0+ core kinetis, we do not need to copy the Flash operating routines to RAM. Platform Control Register (MCM_PLACR) is added. The MCM_PLACR register selects the arbitration policy for the crossbar masters and configures the flash memory controller. Enabling ESFC bit can stall flash controller when flash is busy. Setting ESFC bit can well-balance time sequence of Flash reading and writing – when writing Flash, reading Flash instruction can wait, and vice versa. Using ESFC bit can make our flash programming easier. Thus one Flash can write itself, which is not possible for other one Flash MCU without ESFC bit control.
ESFC bit is easy to be set in C code:
For more information, please see attached document and code.
User can also download the document and source code from Github:
Dear Alice, I was analyzing your code to understand how to develop my owm specific bootloader. I was looking many Freescale AN's, examples, etc. Your seem to be better. But I will need some help from you.
1) in your code...
for(i=0;i<200;i++)
buffer[i] = ((Byte*)FLASH_FlashCommandSequenceStart)[i-1];
[i-1] it will generate a error, because i start with "0".. is it correct ?
2) My code need to execute from RAM memory, to erase all flash memory and read the new firmware from a pre-programmed external SPI flash and put o K63 flash memory.
3) Can you help me, teeling what is the command that write on flash ?
4) How can I put a bootloader fuction on RAM, copying it ? And what will hapen with some command that points to a flash memory instead of RAM memory ?
Can you help me ?
Best Regards
Rodrigo
Hi Rodrigo,
Sorry to reply you late !
Thank for interested in this DOC.
1) Could you please tell me what error you generate ?
And in fact ,the FLash command start from the buffer[1] , you can find this code :
#define FLASH_FlashCommandSequence ((LWord (*)(Byte))&buffer[1])
2) Why do you want copy the bootloader application to the RAM ? If you do this, the bootlaoder will be a one-time programming aid .
And as i know , in the KBOOT , there is a "Kinetis Flashloader" , it is loaded from flash and executed from RAM , and allow the user applicaiton to be placed at the beginning of the on-chip flash .
3)"Can you help me, teeling what is the command that write on flash ?" ? What do you meaning ?
In my project , the write to flash code is here :
and the flash write command is :
FLASH_FlashCommandSequence(PROGRAM_LONGWORD_INDEX);
#define PROGRAM_LONGWORD_INDEX 8
BR
Alice
Hi Alice,
first of all: Thanks for this great bootloader and for sharing code and documentation!
I tried the bootloader in plain UART mode and with RS485 mode. It works excellent with a single device connected.
After that I tried two devices connected via RS485 network. Here I get some troubles while using the bootloader:
In bootloader.c file I found the following line of code "const Byte station_number = 1;" which should be the bus address of the device right?
I programmed the two devices as station_number 1 and station_number 2 and tried updating. But it seems that both devices are responding to both addresses. In single device mode station_number 2 also responded to address 1 in GUI...
Do you know what I'm doing wrong? Where I have to specify the bus address of the devices?
Hi Sebastian,
Thank for you interest for this DOC.
And sorry for one error on my project i attached, now i have attach the new one, please use the new one.
About the station number , you need change two place,
one is in the file of "bootloader.c" : const Byte station_number = 2;
another is in the User Application project , in the bl_mommunication.c file : const Byte station_number = 2;
Then if you want flash to the station 2, on the GUI, please select 2 to 2, this meaning only flash the 2 .
Please have a try , if still can not work ,please contact me without any hesitate.
BR
Alice
Good day Alice,
I was curious if you could provide some guidance upon how to configure a Processor Expert (PE) created project (KL26 processor) for use (PE based user application) with your GUI/Bootloader? I ask, as PE generates a CPU.C file that contains some Flash Configuration values which appear to conflict with where your sample application stores the "APP_OK" signature attribute (in section ".cfmconfig").
Thanks in advance!
Cheers,
Sam
Good day All,
Just a follow up to my original question... If you are using PE you need to turn off Linker File generation in order to correctly update the liker file. In particular the m_cfmprotrom segment... which is not directly accessible within PE. Secondly, you need to manually rename the resulting S19 record file from CW's default extension of ".hex" to ".s19" (Alice's Window's program inteprets the ".hex" file differently). Upon doing this I am able to use the Bootloader and GUI Windows Loader. I still have more testing to do, but at least I now have a basic working system!
Thanks to Alice and the team for this Bootloader infrastructure.
Hello Sam,
Thank you for your interest in this bootloder .
- The User Application can be any project (PE project and bare board project both are ok),
we only need refer to the part of "3.3.8 User application code" to configure the application project .
Yes , if you use PE project , change the linker file directly , you need turn off Linker File generation.
And you also can configure it in "Generate linker file" configure view :
- About the S19 record file name, it not manually rename it , it is generate by KDS:
-On this bootlaoder , the GUI supports both s19 and HEX file :
BR
Alice
Good day Alice,
Excellent! Thank you very much for your help and the information!
Cheers,
Sam
Hi Alice,
Thanks for sharing code.
I want to port this bootloader for MK20DN512, what files do I need to change? I am new with Kinetis Bootloader, please help!
Thanks in advance!
Best regards,
Huy.
Hello Sam,
Please carefully read the DOC of "Kinetis Bootloader Cortex-M4.pdf", know the process clearly,
then you will be know how to porting to your chip.
Also there is a porting into FRDM-K64, when you start porting, you can refer to it :
https://community.nxp.com/docs/DOC-333740
BR
Alice
Dear Alice,
I have ported your bootloader to my MK20DN512 (Landungsbruecke). How can I flash this bootloader to my board? I often use SEGGER-JFlash to flash the user application. Please give me advice!
Thanks a lot!
Best regards,
Huy.
Hi Huy,
You can use everything flash the bootloader into your board.
I use KDS developed it , so I directly use KDS download it . I think SEGGER-JFlash is OK.
BR
Alice
Porting for other chip, say MK10DN512 in my case quite problematic. I should replace a linker file and MK22F51212.h, that gives me a lot of errors in the existing project. also the flash driver is different as I understand.