Jump to application only works with debugger

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

Jump to application only works with debugger

Jump to solution
2,195 Views
Robert123
Contributor III

I have problems jumping to the main application from a secondary bootloader and I have read AN12604SW and several NXP threads such as: https://community.nxp.com/t5/i-MX-RT/Problem-with-exiting-the-second-bootloader-and-jumping-to-user/....

The jump to application only works if I am running with a debugger. The the application is running without the debugger it will not start.

I have a Embedded Artists imx-rt1062 developers kit with the version 2.9.3 of the SDK.

I have reproduced the problem with the iled-blinky SDK example with attached files.

I have split up the flash memory in 3 parts:

The BOOT_FLASH at 0x60000000 contains the boot and dcd data. The secondary bootloader is located in START_FLASH and the main application is located at 0x60006000.

Screenshot from 2021-11-01 14-09-44.png

The this a minimal version of my secondary bootloader (ota_bootloader_hdr.c) which makes a jump to the start-up code (ResetISR2) at location 0x6000631c for the main application.

 

 

#define BL_APP_VECTOR_TABLE_ADDRESS 0x60006000
#define APP_VECTOR_TABLE ((uint32_t *)BL_APP_VECTOR_TABLE_ADDRESS)

extern void ResetISR2();

void goToApp()
{
static void (*farewellBootloader)(void) = 0;
farewellBootloader = (void (*)(void))(0x6000631c);
SCB->VTOR = (uint32_t)APP_VECTOR_TABLE;
__set_MSP(APP_VECTOR_TABLE[0]);
__set_PSP(APP_VECTOR_TABLE[0]);
farewellBootloader();
for (int i = 33000; i >= 0; i--) {
     __NOP();
 }
}

// TODO(roberi) Cannot change name of the entry point in the MCUexpresso IDE for auto generated linker script.
void ResetISR(void) {
	goToApp();
	// ResetISR2();  // This call will work without the debugger
}

 

If I am running with the debugger attached the code will work fine. But If run the application without the debugger it will crash. The application also works fine if I call “ResetISR2” from the secondary bootloader.

 

 

Labels (1)
0 Kudos
1 Solution
2,157 Views
Robert123
Contributor III

Hi, I think the reason was either unaligned access or that the last bit shall be 1. Changing the address pointer to 0x6000631d solved this issue

From https://interrupt.memfault.com/blog/cortex-m-fault-debug:

INVSTATE - Indicates the processor has tried to execute an instruction with an invalid Execution Program Status Register (EPSR) value. Among other things the ESPR tracks whether or not the processor is in thumb mode state. Instructions which use “interworking addresses”2 (bx & blx or ldr & ldm when loading a pc-relative value) must set bit[0] of the instruction to 1 as this is used to update ESPR.T. If this rule is violated, a INVSTATE exception will be generated. When writing C code, the compiler will take care of this automatically, but this is a common bug which can arise when hand-writing assembly.

 

View solution in original post

0 Kudos
4 Replies
2,158 Views
Robert123
Contributor III

Hi, I think the reason was either unaligned access or that the last bit shall be 1. Changing the address pointer to 0x6000631d solved this issue

From https://interrupt.memfault.com/blog/cortex-m-fault-debug:

INVSTATE - Indicates the processor has tried to execute an instruction with an invalid Execution Program Status Register (EPSR) value. Among other things the ESPR tracks whether or not the processor is in thumb mode state. Instructions which use “interworking addresses”2 (bx & blx or ldr & ldm when loading a pc-relative value) must set bit[0] of the instruction to 1 as this is used to update ESPR.T. If this rule is violated, a INVSTATE exception will be generated. When writing C code, the compiler will take care of this automatically, but this is a common bug which can arise when hand-writing assembly.

 

0 Kudos
2,166 Views
Robert123
Contributor III

Thanks for the replies but the problem remains. The jump works fine and the application runs but only when I am stepping through using the Debugger (J-Link) in the MCUXpresso IDE.

Since I am using a different XIP Flash (Embedded Artist board), the OTA Flashloader SDK example (AN12604SW.zip) doesn't even start. But I have gone through the code.

 

0 Kudos
2,176 Views
jeremyzhou
NXP Employee
NXP Employee

Hi,
Thank you for your interest in NXP Semiconductor products and for the opportunity to serve you.
To provide the fastest possible support, I'd highly recommend you to refer to the application note, further, you can download the related sample code via the below link.

https://www.nxp.com.cn/docs/en/application-note-software/AN12604SW.zip
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 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
2,192 Views
Masmiseim
Senior Contributor I

Hello Robert123,

 

try to start the Application like this:

void __attribute__((naked)) StartXasm ([[maybe_unused]] uint32_t startAddr)
{
   __asm
   (
      "LDR SP, [R0]\n"
      "LDR R14, [R0]\n"
      "LDR PC, [R0, #4]\n"
   );
}

void StartX (uint32_t StartAddress)
{
   __disable_irq ();
   SCB->VTOR = StartAddress;   // Set the vector table
   StartXasm (StartAddress);   // Jump into the Application
}

This code assumes, that the vtor of the Application is first in your image.

 

Best regards

0 Kudos