Custom Bootloader Error on Jump

cancel
Showing results for 
Search instead for 
Did you mean: 

Custom Bootloader Error on Jump

Jump to solution
348 Views
Contributor III

When I attempt to jump from my custom bootloader for a custom board with the K66 processor I get the following errors:

*** assert failed : ../drivers/fsl_clock.c:236 : g_xtal0Freq
*** assert failed : ../drivers/fsl_clock.c:813 : mcgpll0clk
*** assert failed : ../drivers/fsl_clock.c:236 : g_xtal0Freq
*** assert failed : ../drivers/fsl_clock.c:813 : mcgpll0clk

By looking at the disassembly and the map file for the loaded program I have determined that the stock pointer is on the HardFault_Handler for the loaded application.  Is there something that I am not doing correctly or something that I could add to avoid these assert failed errors and going to the HardFault_Handler right away?

0 Kudos
1 Solution
19 Views
Contributor III

My problems were that I was not setting the stack pointer correctly and that I was not disabling all of the clocks correctly before jumping.

View solution in original post

0 Kudos
21 Replies
20 Views
Contributor III

My problems were that I was not setting the stack pointer correctly and that I was not disabling all of the clocks correctly before jumping.

View solution in original post

0 Kudos
19 Views
NXP TechSupport
NXP TechSupport

Hi Curtis Robertson,

   So, now, do you make it works OK?

   If you still have question about it, please kindly let us know.


Have a great day,
Kerry

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

- We are following threads for 7 weeks 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
18 Views
Contributor III

Kerry,

It does work okay now, thanks for your help.

Curtis

0 Kudos
18 Views
NXP TechSupport
NXP TechSupport

Hi Curtis,

     Thank you for your updated information.

      If your question is solved, please help to mark the correct answer, just to close this case, thank you!

      If you have the new question in the future, welcome to create the new question post.


Have a great day,
Kerry

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

- We are following threads for 7 weeks 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
19 Views
NXP TechSupport
NXP TechSupport

Hi Curtis Robertson,

   Could you give me more details about your question.

   Do you want to use customer bootloader? which customer bootloader or just means flash bootloader?

   Where you get that bootloader?

  I suggest you use nxp official kinetis bootloader, which can be downloaded from the SDK:

 Welcome | MCUXpresso SDK Builder 

pastedImage_2.png

Use SDK_2.5.0\boards\frdmk66f\bootloader_examples\freedom_bootloader

Wish it helps you!

Have a great day,
Kerry

 

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

 

- We are following threads for 7 weeks 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
19 Views
Contributor III

Kerry,

I am writing the bootloader myself as my application requires features that the Kinetis Bootloader doesn't support such as an Ethernet only interface.  I have corrected the assert failed problem, I had forgot to set the stack pointer before changing the program counter.  However, I am still going right to the HardFault_Handler after initially going to the ResetISR function of the loaded application.  Any insight you can provide would be helpful.

0 Kudos
19 Views
NXP TechSupport
NXP TechSupport

Hi Curitis,

    When will your code enter the Hardfault_Handler? What's the operation you have down in the bootloader?

   When you do the flash operation, do you disable the interrupt and the copy the flash launch command function to RAM, this is very important.


Have a great day,
Kerry

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

- We are following threads for 7 weeks 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
19 Views
Contributor III

Kerry,

I now longer get the Hardfault_Handler, I was setting the stack location incorrectly.  Now I am getting a different problem of executing the loaded program for several lines and then the program jumps back to the bootloader code.  The I am jumping to the ResetISR for the loaded application so the operation is the startup code.  I do disable interrupts before jumping, but I'm not sure if I copy the flash launch command function to RAM.  How would this be done?  

0 Kudos
19 Views
NXP TechSupport
NXP TechSupport

Hi Curtis Robertson,

      Please also copy the flash launch command function to RAM, you can refer to the MCU bootloader code, that code don't have the problems, and that code also copy the flash launch command function to RAM.

   Please refer to the official code at first.

Have a great day,
Kerry

 

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

 

- We are following threads for 7 weeks 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
19 Views
Contributor III

Kerry,

I referred to the MCU bootloader and the code for the jump is mostly the same as what I currently have.  I would appreciate any help you could provide in solving my problem.

Thanks,

Curtis

0 Kudos
19 Views
NXP TechSupport
NXP TechSupport

Hi Curtis,

   I think you can run the official bootloader code on your side, then add your own code again to test the function.

Have a great day,
Kerry

 

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

 

- We are following threads for 7 weeks 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
19 Views
Contributor III

Kerry,

When I build the official bootloader it is unsuccessful because I get an unresolved inclusion for wchar.h.

Thanks,

Curtis

0 Kudos
19 Views
NXP TechSupport
NXP TechSupport

Hi Curtis,

   What the IDE you are using?

   Please refer to this project:

Use SDK_2.5.0\boards\frdmk66f\bootloader_examples\freedom_bootloader

 Please update the IDE to the new version.

If you still have the problem, please also give me the error picture, and tell me your IDE version.

Have a great day,
Kerry

 

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

 

- We are following threads for 7 weeks 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
19 Views
Contributor III

I am using the SDK 2.5 and IDE 10.3.1.  The errors I get are below.

pastedImage_1.png

0 Kudos
19 Views
NXP TechSupport
NXP TechSupport

Hi Curtis Robertson,

   Please refer to this SDK doc:

KSDK_2.0.0\SDK_2.5.0_FRDM-K66F\docs\Getting Started with MCUXpresso SDK.pdf

Chapter 3 Run a demo using MCUXpresso IDE

You need to : Drag and drop the SDK zip file into the “Installed SDKs” view to install an SDK.

Do you do this operation before your build and import the frdmk66f_feedom_bootloader project?

  This is my build result:

pastedImage_4.png

No errors.

Please refer to the doc, and import build the project again.


Have a great day,
kerry

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

- We are following threads for 7 weeks 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
19 Views
Senior Contributor III

Could you provide the code that you are using?

0 Kudos
19 Views
Contributor III

This is my jump function:

void JumpToUserApplication(unsigned long userSP, unsigned long userStartup, unsigned long userTable)

{

      // Disable IRQs
      for (int i = 0; i < 8; i ++) NVIC->ICER[i] = 0xFFFFFFFF;
      // Clear pending IRQs
      for (int i = 0; i < 8; i ++) NVIC->ICPR[i] = 0xFFFFFFFF;

      SCB->VTOR = (uint32_t) userTable;

      // Set up stack pointer

      __asm("msr msp, r0");

      __asm("msr psp, r0");

      // Disable global interrupts

      __asm volatile ("cpsid i");

      // Jump to user application

      static void (*userApp )(void) = 0;

      userApp = (void (*)(void)) userStartup;

      userApp();

}

0 Kudos
19 Views
Senior Contributor III

The obvious problem is that you are setting up the stack pointer with r0, but you have no idea if that contains a valid value. At the start of the function it will contain userSP, but R0 is likely to be used in the dIsabel IRQ code, although that is very dependent on the compiler and optimisation level. So, to start, I would setup the stack with a known, correct, value.

also, you don’t say what parameters you are passing when calling the function - are they correct?

0 Kudos
19 Views
Contributor III

I have tried both the way I posted and hardcoded and the result is the same.  So I doubt that is my problem because of that.  My setup for testing is to split my flash in half, the first half (0x100000) for the bootloader and the second half (0x100000) for the application.  The values I am passing are 0x20000000 for the start of the stack, 0x00100221 for the start address, and 0x100000 for the vector table position.  All these values were taken from the disassembly of the axf file for the application so to my knowledge they are correct.  They seem to at least be reasonably valid as the I do jump to the application at first before I begin having problems.  I know this because I am stepping through the disassembly to see where the program pointer goes after the jump.

0 Kudos
19 Views
Senior Contributor III

If you have a conventional project, all of the information required is provided in the vector table. The first location in the vector table is the stack (offset 0x0), the second location is the start address (offset 0x4). Most boot loaders just use the address of the vector table and extract the initial SP and PC from the vector table.

Perhaps you could show us you vector table - in both source form and the hex from the image, and then we can tell you if your addresses are correct.

0 Kudos