I'm creating my first bootloader with the S32K118 processor and i can't seem to correctly jump to my application.
What I'm trying to do is first flash my application on the MCU with a debug configuration. After that i flash my bootloader without erasing the application. When running my bootloader runs without problems but, when it tries to jump to the application i opens a new tab in IDE and stops the debugger at a breakpoint at address 0x346c. Which if I'm looking at the .map file of my application is my reset handler? But i doesn't execute any code. When it runs without debugger it seems to hang at the same point without executing the application.
Questions i have:
Thanks for any help in advance!
What I'm using:
My code and linker files:
////////// Application //////////
map file:
.interrupts 0x00003000 0xc0
0x00003000 __VECTOR_TABLE = .
0x00003000 __interrupts_start__ = .
0x00003000 . = ALIGN (0x4)
*(.isr_vector)
.isr_vector 0x00003000 0xc0 ./Project_Settings/Startup_Code/startup_S32K118.o
0x00003000 __isr_vector
0x000030c0 __interrupts_end__ = .
0x000030c0 . = ALIGN (0x4)
.flash_config 0x00003400 0x10
0x00003400 . = ALIGN (0x4)
*(.FlashConfig)
.FlashConfig 0x00003400 0x10 ./Project_Settings/Startup_Code/startup_S32K118.o
0x00003410 . = ALIGN (0x4)
.text 0x00003410 0xe74
0x00003410 . = ALIGN (0x4)
*(.text)
.text 0x00003410 0x60 ./Project_Settings/Startup_Code/startup_S32K118.o
0x00003410 Reset_Handler
0x0000346c SysTick_Handler
0x0000346c ERM_fault_IRQHandler
0x0000346c PendSV_Handler
0x0000346c NMI_Handler
0x0000346c DMA2_IRQHandler
0x0000346c LPIT0_IRQHandler
linker file:
/* Specify the memory areas */
MEMORY
{
m_interrupts (RX) : ORIGIN = 0x00003000, LENGTH = 0x00000400
m_flash_config (RX) : ORIGIN = 0x00003400, LENGTH = 0x00000010
m_text (RX) : ORIGIN = 0x00003410, LENGTH = 0x00020000
/* SRAM_L */
m_custom (RW) : ORIGIN = 0x1FFFFC00, LENGTH = 0x00000400
/* SRAM_U */
m_data (RW) : ORIGIN = 0x20000000, LENGTH = 0x000030C0
m_data_2 (RW) : ORIGIN = 0x200030C0, LENGTH = 0x00002740
}
////////// Bootloader //////////
Linker file:
/* Specify the memory areas */
MEMORY
{
/* Flash */
m_interrupts (RX) : ORIGIN = 0x00000000, LENGTH = 0x000000C0
m_flash_config (RX) : ORIGIN = 0x00000400, LENGTH = 0x00000010
m_text (RX) : ORIGIN = 0x00000410, LENGTH = 0x00002000
/*APP info*/
m_APP_INFO (RX) : ORIGIN = 0x00003000, LENGTH = 0x000200D0
/*APP*/
/*m_APP_INFO (RX) : ORIGIN = 0x00000400, LENGTH = 0x0000EC00*/
/* SRAM_L */
m_custom (RW) : ORIGIN = 0x1FFFFC00, LENGTH = 0x00000400
/* SRAM_U */
m_data (RW) : ORIGIN = 0x20000000, LENGTH = 0x000030C0
m_data_2 (RW) : ORIGIN = 0x200030C0, LENGTH = 0x00002740
}
main.c
#define APP_RESET_ADDRESS 0x00003410
void JumpToUserApplication( unsigned int userSP, unsigned int userStartup)
{
/* Set up stack pointer */
DISABLE_INTERRUPTS();
__asm("msr msp, r0");
__asm("msr psp, r0");
ENABLE_INTERRUPTS();
/* Jump to application PC (r1) */
AppAddr resetHandle = (AppAddr)(userStartup);
(resetHandle)();
//__asm("mov pc, r1");
}
void Boot_JumpToApp(const uint32_t i_AppAddr)
{
if((*((uint32_t*)i_AppAddr)) != 0xFFFFFFFF)
{
/* Relocate vector table */
S32_SCB->VTOR = (uint32_t)0x00003000;
JumpToUserApplication(*((uint32_t*)i_AppAddr), *((uint32_t*)(i_AppAddr + 4)));
}
}
int main(void)
{
status_t error;
/* Configure clocks for PORT */
error = CLOCK_DRV_Init(&clockMan1_InitConfig0);
DEV_ASSERT(error == STATUS_SUCCESS);
/* Set pins as GPIO */
error = PINS_DRV_Init(NUM_OF_CONFIGURED_PINS0, g_pin_mux_InitConfigArr0);
DEV_ASSERT(error == STATUS_SUCCESS);
/* Set Output value LED0 */
PINS_DRV_SetPins(LED0_PORT, 1 << LED0_PIN);
for (;;)
{
for(int i = 0; i < 20; i++)
{
/* Insert a small delay to make the blinking visible */
delay(1440000);
/* Toggle output value LED0 & LED1 */
PINS_DRV_TogglePins(LED0_PORT, 1 << LED0_PIN);
}
Boot_JumpToApp(APP_RESET_ADDRESS);}
}