FRDMK64F SD Bootloader

Showing results for 
Search instead for 
Did you mean: 

FRDMK64F SD Bootloader

No ratings

FRDMK64F SD Bootloader

You can put the code directory in the SDK_2.6.0_FRDM-K64F\boards\frdmk64f to use.


As is known to all, we use debugger to download the program or debug the device.

FRDMK64 have the opsenSDA interface on the board, so wo do not need other’s debugger. But if we want to design a board without debugger but can download the program, we can use the bootloader. The bootloader is a small program designed to update the program with the interface such as UART,I2C,SPI and so on.

This document will describe a simple bootloader based on the FRDMK64F.The board uses SD card to update the application. User can put the binary file into the card. When the card insert to the board ,the board will update the application automatically. The bootloader code and application code are all provided so that you can test it on your own board.


2Bootloader’s implementation

  The schematic for SD card is shown below. The board uses SDHC module to communicate with SD card.


                                                 Figure 1.Schematic for SD card


We use the 2.6.0 version of FRDM-K64F’s SDK.You can download the SDK in our website.

The link is “”.

The bootloader uses SDHC and fafts file system. So we should add files to support it.


                  Figure 2.The support file


In main code, the program will wait until the card has inserted. Then it will find the file named “a000.bin” in sd card to update the application. If the file do not exist, the board will directly execute the application. If there is no application, the program will end.

The following code shows how the program wait for inserting sd card. It will also check if the address has the application’s address.


                     Figure 3.The code -- wait for inserting card


The following code shows how the program opens the binary file. If sd card doesn’t have the file, the program will go to the application.


Figure 4.Open the binary file


If the program opens the file normally, the update will begin. It will erase 200k’s space from 0xa000. You can adjust it according to your project.

Now I will explain update’s method in detail. Our data is written to the buffer called “rBUff”. The buffer size is 4K. Before write data to it, it is cleared.

 Please note that when we erase or program the flash, we should disable all interrupts and when the operations finish we should enable the interrupts.

 The file size will decide which way to write the data to flash.

 1If the size < 4k ,we just read the file’s data to buffer and judge if its size aligned with 8 byte. If not , we increase the size of “readSize” to read more data in our data buffer called “rBuffer”. The more data we read is just 0.

   2If the size > 4K, we use “remainSize” to record how much data is left. We read 4k each time until its size is smaller than 4k and then repeat step 1. When finish the operation at a  time, we should clear the buffer and increase the sector numer to prepare the next transmission.


Figure 5.Write flash operation code


The way to clear the space is shown in the figure. It will initialize the flash and erase the given size from the given address.  “SectorNum” is used to show which sector to erase.


Figure 6.Erase operation code


The following figure shows how to write the data to flash.


             Figure 7.Program operation code


Before we go to the application, we should modify the configuration we did in the bootloader.

  •     Close the systick, clear its value.
  •     Set the VTOR to default value.
  •     Our bootloader runs in PEE mode. So we should change it to FEI mode.
  •     Disable the all pins.

You should disable the global interrupt when run these codes. And don’t forget to enable the global interrupt.


Figure 8.Deinitalization code


Then we can go to the application.


Figure 9.Go to Application


3Memory relocation

The FRDMK64 has the 1M flash, from 0x00000000 to 0x00100000.As shown in figure 10,we use the 0xa000 as the application’s start address.


           Figure 10.The memory map


Now, I will show you how to modify the link file for user application in different IDE.



                                   Figure 11.IAR’s ICF



Figure 12.MDK’s SCF


In MCUXpresso


Figure 13.MCUXpresso’s flash configuration

4Run the demo

1) Download the bootloader first.

2) Prepare a user application program. We use the “led blinky” as an example.

3) Modify the Link file.

4) Generate the binary file with your IDE, please name it as “a000.bin”.

5) Put it into the sd card like figure 5.


Figure 14.SD card’s content


6) Insert the card. And power on. Wait for a moment, the application will execute automatically.



1) Kinetis MCUbootloader解决方案

2) KEA128_can_bootloader



There is also an SD card boot loader for the FRDM-K64F which works on SDHC or on SPI - also works on any other Kinetis part - at
It is fully documented at Serial Loader: and can be mixed with other loading methods.
The SD loader can use wild card file matching, and encyryption (including AES256) for IP protection, with SD card clean-up after the loading has completed.
It can be built for any Kinetis part with KDS, MCUXpresso, IAR, Keil, S32, Rowely Crossworks, Green Hills, Atollic, CooCox, GCC make and fully simulated (including Kinetis device and SD card) in Visual Studio.
The SD card loader size is 14k in size (with FAT16, FAT32 and LFN support) and so is more code efficient (application start address can be at 0x4000 - saving 32k over the demo).
It also allows the same operation on memory stick (can be used in parallel to SD card) via USB-host interface: Featured video: which increases the loader size to 26k (link address 0x7000)
It is available as free open source and has been used in many industrial based Kinetis products since 2011 and is thus fully mature and proven.



Simulated FRDM-K64F SD card and Memory stick loader in operation in Visual Studio:


Complete Kinetis solutions for faster/more efficient professional needs, training and support:
i.MX RT project compatibility:
Including FreeRTOS integration for all Kinetis parts

Kinetis K64:

uTasker: supporting >1'000 registered Kinetis users get products faster and cheaper to market

Request Free emergency remote desk-top consulting at

Open Source version at

Version history
Revision #:
1 of 1
Last update:
‎11-05-2019 07:59 PM
Updated by: