S32K344 BOOT to APP MATLAB generated project in Design Studio

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

S32K344 BOOT to APP MATLAB generated project in Design Studio

1,797 Views
AJLFD
Contributor I

Hello all,

I have a S32K344 bootloader application running on a custom board that I've used to jump to applications that were generated in design studio with no prior issues. I now have a MATLAB generated application that I've been trying to jump to but with no success as it keeps hitting the application's hard fault handler or the debugger crashes (J-Trace). 

Boot Flash Start: 0x00400000

App Flash Start: 0x00600000

App VTABLE: 0x0060800

App Jump: 0x00600804

*** This is how I've been jumping that has worked for me and that has appeared on other forums ***

typedef void(*voidFunPtr)(void);

void AppJump(void){

uint32_t pAppJump = (voidFunPtr)(*(uint32_t *) 0x00600804);

S32_SysTick->CSRr = 0;

S32_SCB->VTOR = (uint32_t)0x00600800;

( pAppJump )();

}

Actions I've done:

- Checked the map file generated from the application for the correct jump location, I've confirmed this through the disassembly

- Relocated the vector table to the application's table before the jump ( S32_SCB->VTOR )

- Disabled FreeRTOS and peripheral interrupts before the jump

- DeInit all active peripherals

- Disabled the Systick

- Configured the stack pointer

Are there any configurations going on with the MATLAB generated projects that I have to change? Is there some reinitialization I must do? I've searched through forum posts with boot troubles and tried their solutions but nothing has worked yet. I can jump to the application's startup_cm7.s code but I believe the fault occurs here at some point.

0 Kudos
Reply
3 Replies

774 Views
rathi_tg
Contributor III

Hi @lukaszadrapa  

 

I want to jump from application code to Boot code using matlab code. I have used custom code as follows 

if(userSP == 0xFFFFFFFF){
return;
}
 
/* Set up stack pointer */
__asm("msr msp, r0");
__asm("msr psp, r0");
 
/* Relocate vector table */
S32_SCB->VTOR = (uint32_t)BOOT_START_ADDRESS;
 
/* Jump to BootPC (r1) */
__asm("mov pc, r1");
 
But when i try to build the application i am facing issues with assemble commands. The Boot Address is 0x000000.
 
Regards 
Gopal
 
0 Kudos
Reply

1,745 Views
lukaszadrapa
NXP TechSupport
NXP TechSupport

Hi @AJLFD 

I'm not aware of specific difference in MATLAB project but I guess that something more needs to be deinitialized. That's the most common problem. If I'm not able to find it, I use following approach: reset the device by debugger and dump the peripheral registers to a file(s). Run the bootloader until you reach jump instruction. Now dump the registers again, compare the files and analyze the differences. Don't forget to check also core registers, especially MPU and NVIC - I would start with this.

Regards,

Lukas

0 Kudos
Reply

1,752 Views
AJLFD
Contributor I
There may also be a problem with FreeRTOS. In some attempts using xCreateTask() will also set the hard fault handler or crash the debugger after it has made the jump. Some variables for the pxTaskCode, pcName, pxStack are replaced with 0xA5A5A5A5.
0 Kudos
Reply
%3CLINGO-SUB%20id%3D%22lingo-sub-1816882%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ES32K344%20BOOT%20to%20APP%20MATLAB%20generated%20project%20in%20Design%20Studio%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1816882%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHello%20all%2C%3C%2FP%3E%3CP%3EI%20have%20a%20S32K344%20bootloader%20application%20running%20on%20a%20custom%20board%20that%20I've%20used%20to%20jump%20to%20applications%20that%20were%20generated%20in%20design%20studio%20with%20no%20prior%20issues.%20I%20now%20have%20a%20MATLAB%20generated%20application%20that%20I've%20been%20trying%20to%20jump%20to%20but%20with%20no%20success%20as%20it%20keeps%20hitting%20the%20application's%20hard%20fault%20handler%20or%20the%20debugger%20crashes%20(J-Trace).%26nbsp%3B%3C%2FP%3E%3CP%3EBoot%20Flash%20Start%3A%200x00400000%3C%2FP%3E%3CP%3EApp%20Flash%20Start%3A%200x00600000%3C%2FP%3E%3CP%3EApp%20VTABLE%3A%200x0060800%3C%2FP%3E%3CP%3EApp%20Jump%3A%200x00600804%3C%2FP%3E%3CP%3E%3CSTRONG%3E***%20This%20is%20how%20I've%20been%20jumping%20that%20has%20worked%20for%20me%20and%20that%20has%20appeared%20on%20other%20forums%20***%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3Etypedef%20void(*voidFunPtr)(void)%3B%3C%2FP%3E%3CP%3Evoid%20AppJump(void)%7B%3C%2FP%3E%3CP%3Euint32_t%20pAppJump%20%3D%26nbsp%3B(voidFunPtr)(*(uint32_t%20*)%200x00600804)%3B%3C%2FP%3E%3CP%3ES32_SysTick-%26gt%3BCSRr%20%3D%200%3B%3C%2FP%3E%3CP%3ES32_SCB-%26gt%3BVTOR%20%3D%20(uint32_t)0x00600800%3B%3C%2FP%3E%3CP%3E(%26nbsp%3BpAppJump%20)()%3B%3C%2FP%3E%3CP%3E%7D%3C%2FP%3E%3CP%3E%3CSTRONG%3EActions%20I've%20done%3A%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E-%20Checked%20the%20map%20file%20generated%20from%20the%20application%20for%20the%20correct%20jump%20location%2C%20I've%20confirmed%20this%20through%20the%20disassembly%3C%2FP%3E%3CP%3E-%20Relocated%20the%20vector%20table%20to%20the%20application's%20table%20before%20the%20jump%20(%20S32_SCB-%26gt%3BVTOR%20)%3C%2FP%3E%3CP%3E-%20Disabled%20FreeRTOS%20and%20peripheral%20interrupts%20before%20the%20jump%3C%2FP%3E%3CP%3E-%20DeInit%20all%20active%20peripherals%3C%2FP%3E%3CP%3E-%20Disabled%20the%20Systick%3C%2FP%3E%3CP%3E-%20Configured%20the%20stack%20pointer%3C%2FP%3E%3CP%3EAre%20there%20any%20configurations%20going%20on%20with%20the%20MATLAB%20generated%20projects%20that%20I%20have%20to%20change%3F%20Is%20there%20some%20reinitialization%20I%20must%20do%3F%20I've%20searched%20through%20forum%20posts%20with%20boot%20troubles%20and%20tried%20their%20solutions%20but%20nothing%20has%20worked%20yet.%20I%20can%20jump%20to%20the%20application's%20startup_cm7.s%20code%20but%20I%20believe%20the%20fault%20occurs%20here%20at%20some%20point.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2267911%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20S32K344%20BOOT%20to%20APP%20MATLAB%20generated%20project%20in%20Design%20Studio%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2267911%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F37795%22%20target%3D%22_blank%22%3E%40lukaszadrapa%3C%2FA%3E%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EI%20want%20to%20jump%20from%20application%20code%20to%20Boot%20code%20using%20matlab%20code.%20I%20have%20used%20custom%20code%20as%20follows%26nbsp%3B%3C%2FP%3E%3CDIV%3Eif(userSP%20%3D%3D%200xFFFFFFFF)%7B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3Ereturn%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%7D%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%2F*%20Set%20up%20stack%20pointer%20*%2F%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E__asm(%22msr%20msp%2C%20r0%22)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E__asm(%22msr%20psp%2C%20r0%22)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%2F*%20Relocate%20vector%20table%20*%2F%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3ES32_SCB-%26gt%3BVTOR%20%3D%20(uint32_t)BOOT_START_ADDRESS%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%2F*%20Jump%20to%20BootPC%20(r1)%20*%2F%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E__asm(%22mov%20pc%2C%20r1%22)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3EBut%20when%20i%20try%20to%20build%20the%20application%20i%20am%20facing%20issues%20with%20assemble%20commands.%20The%20Boot%20Address%20is%200x000000.%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3ERegards%26nbsp%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3EGopal%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1818995%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20S32K344%20BOOT%20to%20APP%20MATLAB%20generated%20project%20in%20Design%20Studio%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1818995%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%20%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F227269%22%20target%3D%22_blank%22%3E%40AJLFD%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI'm%20not%20aware%20of%20specific%20difference%20in%20MATLAB%20project%20but%20I%20guess%20that%20something%20more%20needs%20to%20be%20deinitialized.%20That's%20the%20most%20common%20problem.%20If%20I'm%20not%20able%20to%20find%20it%2C%20I%20use%20following%20approach%3A%20reset%20the%20device%20by%20debugger%20and%20dump%20the%20peripheral%20registers%20to%20a%20file(s).%20Run%20the%20bootloader%20until%20you%20reach%20jump%20instruction.%20Now%20dump%20the%20registers%20again%2C%20compare%20the%20files%20and%20analyze%20the%20differences.%20Don't%20forget%20to%20check%20also%20core%20registers%2C%20especially%20MPU%20and%20NVIC%20-%20I%20would%20start%20with%20this.%3C%2FP%3E%0A%3CP%3ERegards%2C%3C%2FP%3E%0A%3CP%3ELukas%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1818870%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20S32K344%20BOOT%20to%20APP%20MATLAB%20generated%20project%20in%20Design%20Studio%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1818870%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3EThere%20may%20also%20be%20a%20problem%20with%20FreeRTOS.%20In%20some%20attempts%20using%20xCreateTask()%20will%20also%20set%20the%20hard%20fault%20handler%20or%20crash%20the%20debugger%20after%20it%20has%20made%20the%20jump.%20Some%20variables%20for%20the%20pxTaskCode%2C%20pcName%2C%20pxStack%20are%20replaced%20with%200xA5A5A5A5.%3C%2FLINGO-BODY%3E