S32K148: Bootloader not jumping to application

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

S32K148: Bootloader not jumping to application

3,847件の閲覧回数
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 件の賞賛
返信
16 返答(返信)

3,839件の閲覧回数
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 件の賞賛
返信

3,830件の閲覧回数
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 件の賞賛
返信

3,823件の閲覧回数
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 件の賞賛
返信

3,817件の閲覧回数
YogeshG
Contributor I

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

YogeshG_1-1611819404483.png

 

0 件の賞賛
返信

3,781件の閲覧回数
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 件の賞賛
返信

3,739件の閲覧回数
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 件の賞賛
返信

3,711件の閲覧回数
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 件の賞賛
返信

2,632件の閲覧回数
Francesco_Solito
Contributor II

Hello

I have the same problem with JumpToUserApplication. Could you please explain what was the problem in the linker file and how you solved it?

Thank you in advance.

Kind regards,

Francesco

 

0 件の賞賛
返信

3,709件の閲覧回数
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 件の賞賛
返信

3,684件の閲覧回数
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 件の賞賛
返信

3,680件の閲覧回数
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 件の賞賛
返信

3,649件の閲覧回数
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 件の賞賛
返信

3,631件の閲覧回数
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 件の賞賛
返信

3,613件の閲覧回数
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 件の賞賛
返信

3,548件の閲覧回数
YogeshG
Contributor I

Hi,

The status of RX pin is high, as it is pulled-up in the circuit. 

I have made following configuration,

PORTC->PCR[6]|=PORT_PCR_MUX(2);              /* Port C6: MUX = ALT2,UART1 TX */
PORTC->PCR[7]|=PORT_PCR_MUX(2);              /* Port C7: MUX = ALT2,UART1 RX */

While monitoring on the RX pin, I put a breakpoint in the LPUART1_RxTx_IRQHandler function at line 

 if((LPUART1->STAT & LPUART_STAT_RDRF_MASK)>>LPUART_STAT_RDRF_SHIFT)

I am able to see pulses for every character pressed, but this condition is not satisfied, so the program is not entering inside this condition. Probably not getting an interrupt.

During the test I observed the following things,

1. In the first run, I got the interrupt and received complete data and the STAT register values was observed to be 0x40D00000, (IDLE, TC, TDRE, RXEDGIF) bits were set. This is working correctly. 

2. Now, I reset  the board (in debug mode only), in this case I m not able to get interrupt. The STAT register value was observed to be 0x40C00000, (TC, TDRE, RXEDGIF) bits were set. In this IDLE bit was not set.

So, is this causing any problem?

Thank & Regards,

Yogesh.

0 件の賞賛
返信

3,491件の閲覧回数
lukaszadrapa
NXP TechSupport
NXP TechSupport

Hi Yogesh,

I quickly check your projects and it seems there are some clock issues.

This is state of PCC_LPUART1 when the application is executed right after reset without bootloader:

lukaszadrapa_1-1615289236187.png

 

This is when exiting bootloader (it's not reverted back to default state!):

lukaszadrapa_0-1615289178459.png

 

And this is when the application is executed after bootloader:

lukaszadrapa_2-1615289279102.png

I guess this could be one reason of your troubles.

Regards,

Lukas

 

 

0 件の賞賛
返信