S32K118 How to correctly jump from Bootloader to App with S32K Design Studio

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

S32K118 How to correctly jump from Bootloader to App with S32K Design Studio

756 次查看
melvinw
Contributor II

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:

  1. Am i missing something and is my code correct?
  2. Are the settings, linker files, correct to jump to the application or do i need a different address?
  3. How do you correctly jump to the application? 
  4. What steps need to be taken? (Maybe I'm forgetting something.)

Thanks for any help in advance!

 

What I'm using:

  • S32K Design Studio 
  • S32K118 SDK RTM 4.0.1 with two seperate hello world example project for a blinking LED.
  • Costume PCB with S32K118 MCU
  • Multilink Universal debugger/programmer with a SWD connection to the MCU.

 

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);}
}

0 项奖励
回复
0 回复数