KL17 Flash resident bootloader

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

KL17 Flash resident bootloader

1,206 Views
yonhona
Contributor II

Hi,

I'm developing a flash resident bootloader on the KL17 MCU.

The project consist from a bootloader and application.

The bootloader jump to the application is working correctly, I can see that the some GPIOs are initialized in the application.

But later in the application, the program jumps to hard fault handler due to unknown instruction.

I suspect that the linker script it not right.

this is the bootloader memory:

MEMORY
{
/* Define each memory region */
PROGRAM_FLASH (rx) : ORIGIN = 0x00, LENGTH = 0x400 /* 1K bytes (alias Flash) */

Flash_00 (rx) : ORIGIN = 0x400, LENGTH = 0x3fc00 /* 255K bytes (alias Flash2) */
SRAM (rwx) : ORIGIN = 0x1fffe000, LENGTH = 0x8000 /* 32K bytes (alias RAM) */ 
}

and this is the application:

MEMORY
{
/* Define each memory region */
PROGRAM_FLASH (rx) : ORIGIN = 0x400, LENGTH = 0x3fc00 /* 255K bytes (alias Flash) */

Flash_00 (rx) : ORIGIN = 0x00, LENGTH = 0x400 /* 1K bytes (alias Flash2) */
SRAM (rwx) : ORIGIN = 0x1fffe000, LENGTH = 0x8000 /* 32K bytes (alias RAM) */
}

what am I doing wrong?

Thanks

6 Replies

836 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Yon hona,

   Actually, KL17 already have the ROM bootloader, I don't know you still use the flash bootloader.

  If you want to add some your own function in the bootloader, you can use the flash bootloader.

  But from your linker file,your application code relocate have the problems.

As you know, flash address 0X400 is the flash configuration field, this is the very important area to the kinetis chip.

pastedImage_1.png

I think you can relocate your application code to flash address 0x1000, besides, you must make sure your bootloader code size is smaller than 0x1000.

Then modify the linker file like this:

this is the bootloader memory:

MEMORY
{
/* Define each memory region */
PROGRAM_FLASH (rx) : ORIGIN = 0x00, LENGTH = Your bootloader size/* 1K bytes (alias Flash) */

Flash_00 (rx) : ORIGIN = 0x400, LENGTH = 0x3fc00 /* 255K bytes (alias Flash2) */
SRAM (rwx) : ORIGIN = 0x1fffe000, LENGTH = 0x8000 /* 32K bytes (alias RAM) */ 
}

 

and this is the application:

MEMORY
{
/* Define each memory region */
PROGRAM_FLASH (rx) : ORIGIN = 0x1000, LENGTH = flash total size-0x1000/* 255K bytes (alias Flash) */

Flash_00 (rx) : ORIGIN = 0x1400, LENGTH = 0x400 /* 1K bytes (alias Flash2) */
SRAM (rwx) : ORIGIN = 0x1fffe000, LENGTH = 0x8000 /* 32K bytes (alias RAM) */
}

You can try it again.

I still want to say, if you don't have the special usage, you can use the chip's ROM bootloader, more detail, please refer to the reference manual, Chapter 13
Kinetis ROM Bootloader

If you still have question about it, please let me know!


Have a great day,
Kerry

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

836 Views
yonhona
Contributor II

Thank you for your answer.

I have changed my code as you suggested and now it works, but without interrupts.

The SCB->VTOR register is set to 0x1000, but still not interrupts.

Do you have any idea why?

836 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Yon hona,

   Do you mean, your application can't enter interrupt mode? Please test it, if you don't do the relocate, whether your application can enter the interrupt or not?

  BTW, please also tell me why you don't use the ROM bootloader, but choose the Flash bootloader?


Have a great day,
Kerry

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

836 Views
yonhona
Contributor II

Hi,

Its seems like after setting the flash offset, interrupts are not working. If I set the flash offset to zero, interrupts working.

I don't use the ROM bootloader because I use two banks, the bootloader should jump to the one with the higher version number. There is no host in my project.

836 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Yon hona,

   Please tell me what the module interrupt you are using now?

   You said the interrupt not working, whether the code still runing except the interrupt, take an example, you can blink the LED in your application while(1). Just to test whether the code is blocked after the relocate.

   Please also check the FOPT data, let the MCU boot from the flash directly, not the ROM bootloader, 0x40d, configure bit7-6 to 00:

pastedImage_1.png

Please try again.

Any updated information, please let me know!


Have a great day,
Kerry

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

836 Views
yonhona
Contributor II

Hi, thanks!

this was the problem.

0 Kudos