FRDMK64F SD Bootloader

cancel
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.

1Introduction

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.

sd.png

                                                 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 “mcuxpresso.nxp.com”.

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

support_file.png

                  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.

wait_insert.png

                     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.

open_card.png

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.

write_operation.png

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.

pastedImage_29.png

Figure 6.Erase operation code

 

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

pastedImage_7.png

             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.

pastedImage_10.png

Figure 8.Deinitalization code

 

Then we can go to the application.

pastedImage_11.png

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.

pastedImage_12.png

           Figure 10.The memory map

 

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

In IAR

icf.png

                                   Figure 11.IAR’s ICF

In MDK

pastedImage_17.png

Figure 12.MDK’s SCF

 

In MCUXpresso

pastedImage_18.png

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.

pastedImage_22.png

Figure 14.SD card’s content

      

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

pastedImage_23.png

5、Reference

1) Kinetis MCUbootloader解决方案

2) KEA128_can_bootloader

Attachments
Comments


Hi

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 http://www.utasker.com/kinetis/FRDM-K64F.html
It is fully documented at Serial Loader: http://www.utasker.com/docs/uTasker/uTaskerSerialLoader.pdf 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: https://www.youtube.com/watch?v=VJ7YveF4_8g&list=PLWKlVb_MqDQFZAulrUywU30v869JBYi9Q&index=26 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.

Regards

Mark

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

pastedImage_3.png

Complete Kinetis solutions for faster/more efficient professional needs, training and support: http://www.utasker.com/kinetis.html
i.MX RT project compatibility: http://www.utasker.com/iMX.html
Including FreeRTOS integration for all Kinetis parts

Kinetis K64:
- http://www.utasker.com/kinetis/FRDM-K64F.html
- http://www.utasker.com/kinetis/TWR-K64F120M.html
- http://www.utasker.com/kinetis/TEENSY_3.5.html
- http://www.utasker.com/kinetis/Hexiwear-K64F.html

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

Request Free emergency remote desk-top consulting at http://www.utasker.com/services.html

Open Source version at https://github.com/uTasker/uTasker-Kinetis

https://community.nxp.com/thread/512558
https://community.nxp.com/thread/352862
https://community.nxp.com/thread/498809

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