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
////////////////////////////////////////////////////////////////////////////////
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
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.
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
After flashing the application through utility, Following are the values at 0x1000.
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?
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
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.
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
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.
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
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.
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
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?
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
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.
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:
This is when exiting bootloader (it's not reverted back to default state!):
And this is when the application is executed after bootloader:
I guess this could be one reason of your troubles.
Regards,
Lukas