S32K148: Bootloader not jumping to application

cancel
Showing results for 
Search instead for 
Did you mean: 

S32K148: Bootloader not jumping to application

294 Views
YogeshG
Contributor I

I have downloaded standard bootloader code from the nxp's website. Built the code and loaded into the Eval board. 

It seems it is not jumping to application. Unable to trace the exact problem.

I have used following bootloader code. It will be helpful if anyone can comment into this.

Code:

#include "timeout.h"
#include "comm.h"
#include "clock.h"

/* Bootloader definitions */
/* Start address for the application received by the bootloader
* application vector table should start at this address
* */
#define APP_START_ADDRESS 0x1000

/* Global variables */
uint8_t boot_from_comm = 0; /* Used to signal activity on the comm channel */

/* Prototype */
void JumpToUserApplication( unsigned int userSP, unsigned int userStartup);

/* Main Application*/
int main(void)
{

/* Initialize clock */
clock_initi();

/* Initialize communication interfaces */
init_comm();

/* Initialize timeout */
init_timeout();

/* Check if boot start has been received or timeout occurred */
do{
uint8_t word_received = comm_status_rx();
if(word_received){
boot_from_comm = 1;
comm_download_app();
}
} while((!timeout()) & (!boot_from_comm));

/* Disable all systems and leave device as if coming out of reset */
disable_timeout();
disable_comm();
reset_clock();

/* Check if a valid application is loaded and jump to it */
JumpToUserApplication(*((uint32_t*)APP_START_ADDRESS), *((uint32_t*)(APP_START_ADDRESS + 4)));

/* Should never return from application code */
for (;;) {};
/* Never leave main */
return 0;
}

/**
* Used to jump to the entry point of the user application
* The Vector table of the user application must be located at 0x1000
*
* */
void JumpToUserApplication( unsigned int userSP, unsigned int userStartup)
{
/* Check if Entry address is erased and return if erased */
if(userSP == 0xFFFFFFFF){
return;
}

/* Set up stack pointer */
__asm("msr msp, r0");
__asm("msr psp, r0");

/* Relocate vector table */
S32_SCB->VTOR = (uint32_t)APP_START_ADDRESS;

/* Jump to application PC (r1) */
__asm("mov pc, r1");
}
////////////////////////////////////////////////////////////////////////////////
// EOF
////////////////////////////////////////////////////////////////////////////////

 

0 Kudos
13 Replies

285 Views
lukaszadrapa
NXP TechSupport
NXP TechSupport

Hi,

did you step the code? Where does it crash exactly?

Is that on this command? __asm("mov pc, r1");

If yes, what is the r1 content? Does it contain expected address?

Regards,

Lukas

 

0 Kudos

276 Views
YogeshG
Contributor I

Eval board:

When I am using UART1, in that case 0xFFFFFFFF value is received in "userSP"

/* Check if Entry address is erased and return if erased */
if(userSP == 0xFFFFFFFF){
return;
}

the code will return from here itself.

 

Custom Board:

I configured it for UART2. In this case, the code will run till "__asm("mov pc, r1");"

After that I get following error,

BusFault: A bus fault has occurred on exception entry.
MemManage: The processor attempted an instruction fetch from a location that does not permit execution.
HardFault: A fault has been escalated to a hard fault.

 

The content in VTOR is correctly assigned to App_Start_address (i.e. 0x1000).

Following are the contents of r1 and r0.

YogeshG_0-1611744784505.png

 

 

0 Kudos

270 Views
lukaszadrapa
NXP TechSupport
NXP TechSupport

Value in r1 is definitely not correct, -58787841 in hex is 0xFC7EF7FF which falls somewhere to peripheral address space. I would check content of flash at 0x1000. The application is obviously not programmed correctly.

Regards,

Lukas

 

0 Kudos

264 Views
YogeshG
Contributor I

After flashing the application through utility, Following are the values at 0x1000. 

YogeshG_1-1611819404483.png

 

0 Kudos

227 Views
YogeshG
Contributor I

I am not getting any clue why the value of r1 is coming negative...

At 0x1000 location some data is written, but yet it is not jumping to application.

In which direction should I proceed?

 

0 Kudos

186 Views
lukaszadrapa
NXP TechSupport
NXP TechSupport

Due to some system issues, I didn't get notification about new message. Sorry about that. Have you solved this problem or do you still need some assistance?

Regards,

Lukas

 

0 Kudos

157 Views
YogeshG
Contributor I

Hi Lukas,

Sorry for late reply.

Ya I have resolved the issue of jumping to application from bootloader. The issue was in the linker file.

 

Thanks for your support.

0 Kudos

155 Views
YogeshG
Contributor I

Hi Lukas,

I am getting another problem related to my previous post.

I have configured UART1 in bootloader and application code. In this case, I am able to load the application through bootloader and it is working well. But, I am not able to get interrupt on UART1.

If I configure UART1 for bootloader and UART2 for application, then in this case application is working fine and I am able to get interrupt on UART2.

Not able to figure out this issue. Why I am not able to use the same UART in both bootloader and application.

Can you suggest something...

Thanks you.

0 Kudos

131 Views
lukaszadrapa
NXP TechSupport
NXP TechSupport

Hi,

could you double check if:

- corresponding interrupt is enabled in LPUART CTRL register

- corresponding interrupt flag is set in LPUART STAT register

- NVIC registers are configured as needed (interrupt enabled, priority configured)

- PRIMASK is cleared

If all these conditions are met, the interrupt should be triggered.

Regards,

Lukas

 

0 Kudos

127 Views
YogeshG
Contributor I

Hi Lukas,

Yes these things are configured as needed. To verify this I loaded only the application at location 0x00000000. In this case its working and I am able to get interrupt too. This means all configuration related to UART interrupt was correct.

But, if I load bootloader at 0x00000000 location and the application at 0x00001000 location. In this case I am not getting the interrupt. 

0 Kudos

95 Views
lukaszadrapa
NXP TechSupport
NXP TechSupport

I can understand but could you check all these configurations at the moment when it doesn't work in the application? The configuration is obviously somehow affected by the bootloader. Are other interrupts working?

Regards,

Lukas

 

0 Kudos

77 Views
YogeshG
Contributor I

Hii,

Ya other interrupts are working properly.

For observation for same UART's, I debugged bootloader and application together by following steps given in this link https://community.nxp.com/t5/S32-Design-Studio-Knowledge-Base/HOWTO-Debug-multiple-elf-files-in-S32-... .

1. When debug started, then after UART initialization the values of registers are as below,

UART1 -> CTRL = 0x002C0000;

UART1 -> STAT = 0x00C00000;

At this point if I run the program, then I am able to get interrupt successfully.

 

2. Then I reset the device. After resetting when I check the register values they are as below,

UART1 -> CTRL = 0x002C0000;

UART1 -> STAT = 0x01C00000;

The highlighted bit is RAF (Receiver Active Flag). I am not able to get why this bit is Set.

 

Is this causing problem? 

0 Kudos

60 Views
lukaszadrapa
NXP TechSupport
NXP TechSupport

Hi,

what is the state of RX pin when RAF is set? Isn't it tied to GND by external circuits? Or what is the configuration of RX pin (PCR register)?

Regards,

Lukas

 

0 Kudos