K22F Kinetis Bootloader FlashEraseRegion

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

K22F Kinetis Bootloader FlashEraseRegion

Jump to solution
3,253 Views
CK3
Contributor III

Hi

I am writing a C++ script for the Kinetis K22F Bootloader to flash some application via USB-HID. I already implemented the getProperty command. Next I want to write the FlashEraseRegion command. However, I am not sure how to find out the end-adress of the application.

Is it correct to assume that end-adress is start-adress + application size? Because I recieve different end-adress compared to the results from the KinetisFlashTool.

Thanks in advance!

0 Kudos
Reply
1 Solution
3,249 Views
nxf56274
NXP Employee
NXP Employee

Hi,

One easiest way is erase the full chip except the bootloader. If your flash is big, it may takes a bit long time. If you want only erase the application, you should calculate how many sectors the application takes up. Then erase memory. Range is the bootloader start address ~ the sector's end address. The erase operation is always do sector erasing.

Have a great day,
TIC

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 days after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

View solution in original post

0 Kudos
Reply
6 Replies
3,227 Views
CK3
Contributor III

Hi,

thank you two (nxf56274 and mykepredkomimet) for the replies. I managed to flash an application now.

At first, I did not realize that the FlashEraseRegion is erasing sectrowise. So what I do now is I calculate the size of my application, round it up to the number of necessary sectors and erase them. This works for me.

Regarding the start a address, I took the one from the reference manual, which is 0xA000. But I am a little confused now after mykepredkomimet post, whether or not I am doing something wrong.

Also I am wondering what the first two bytes of the header in the data phase mean. My header is 02 00 20 00. I already figured out that the last two bytes stand for the size of the message to be send.

Kind regards,
CK3

0 Kudos
Reply
3,219 Views
nxf56274
NXP Employee
NXP Employee

Hi,

You use 0xa000 for application start address. It means your bootloader size should smaller than the 0xa000. His thoughts is that the application start address should change with the bootloader size changing. A fixed address is OK. You just need confirm your bootloader won't be bigger than 0xa000.

Where do you use the header?

Have a great day,
TIC

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 days after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos
Reply
3,215 Views
CK3
Contributor III

Hi,

I use the header when sending the application to the flash. I divide the application size into parts of 32 bytes and attach the 4 byte long header before each write command.

Thanks!

0 Kudos
Reply
3,206 Views
nxf56274
NXP Employee
NXP Employee

Hi,

I am not sure. May be it is just a head frame.

Have a great day,
TIC

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 days after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos
Reply
3,240 Views
myke_predko
Senior Contributor III

Hi @CK3 

I think you're asking multiple questions here and it's a bit confusing.  

If I were to break it out you have a bootloader that takes up some amount of space and you want to load application after it (which needs the Flash after it to be erased before loading in the application).  So you need:

  1. Bootloader size
    1. Using the GCC created code by MCUXpresso for the FRDM-K22F, I take the sum of the words at 0x168 and 0x170
    2. This is SDK version dependent and you may find this information at slightly different locations (for the MK22FN1M0a the values are at 0x188 and 0x190)
  2. Device Flash Size
    1. I use the FLASH_GetProperty API with the kFLASH_PropertyPflash0TotalSize or kFLASH_PropertypflashTotalSize depending on the API
    2. This is one of the reasons why I whine about the different versions of the SDK for different devices
  3. Application Start Address
    1. This can be a bit tricky as you should NEVER place the application at the address following the bootloader size (1) but you need to place it at the sector following.  See below.  

To calculate the Application Start Address, use the statement:

applicationStartAddress = (bootloaderSize * (~(FSL_FEATURE_FLASH_PFLASH_BLOCK_SECTOR_SIZE - 1))) + FSL_FEATURE_FLASH_PFLASH_SECTOR_SIZE;

This will place your application at the start of the sector following the end of the bootloader and is the first sector that you can erase without affecting the bootloader code.  

The "applicationStartAddress" is also the first sector you start erasing to the end of the devices Flash before the bootloader loads the application.  

Good luck!

myke

0 Kudos
Reply
3,250 Views
nxf56274
NXP Employee
NXP Employee

Hi,

One easiest way is erase the full chip except the bootloader. If your flash is big, it may takes a bit long time. If you want only erase the application, you should calculate how many sectors the application takes up. Then erase memory. Range is the bootloader start address ~ the sector's end address. The erase operation is always do sector erasing.

Have a great day,
TIC

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 days after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos
Reply