I've been trying to implement ISP Reinvoke function for some time now and I've run into problem. My function looks like this:
void IAP_ReinvokeISP(void)
{
    SCB->VTOR = 0;
    volatile unsigned int command[5] = {0};
    volatile unsigned int result[4] = {0};
    LPC_SYSCTL->SYSAHBCLKCTRL |= 0x14440;
    LPC_SYSCTL->SYSAHBCLKDIV = 1;
    //Prepare the command array
    command[0] = 57;
    //Chip_GPIO_SetPinState(LPC_GPIO, 2, 16, 1);
    //Initialize the storage state machine
    init_msdstate();
    //Set stack pointer to ROM value (reset default)
    //This must be the last piece of code executed before calling ISP,
    //because most C expressions and function returns will fail after the stack pointer is changed.
    __set_MSP(*((unsigned int*)0x00000000));
//Invoke IAP call...
    iap_ent((unsigned int *)command, (unsigned int *)result);
}
I've put some variables as volatile even though they shouldn't be optimized whatsoever because they are in function yet I can't get it to open mass storage device. Turning optimization off works well but I need it as my code is fairly big and I would like it to be more compact.
P.S. Before this function I turn off all interrupts except for USB handling
Solved! Go to Solution.
 
					
				
		
 lpcxpresso_supp
		
			lpcxpresso_supp
		
		
		
		
		
		
		
		
	
			
		
		
			
					
		It's not necessary to setup the MSP. Very doubtful the problem is related to the microcontroller ROM. If you want to understand what's going on, instruction step the code to see the difference in code generation. There's probably a stack (relative) access of some kind happening after you zeroed the stack pointer.
Thanks and regards,
MCUXpresso Support
 
					
				
		
 lpcxpresso_supp
		
			lpcxpresso_supp
		
		
		
		
		
		
		
		
	
			
		
		
			
					
		It's not necessary to setup the MSP. Very doubtful the problem is related to the microcontroller ROM. If you want to understand what's going on, instruction step the code to see the difference in code generation. There's probably a stack (relative) access of some kind happening after you zeroed the stack pointer.
Thanks and regards,
MCUXpresso Support
That's exactly what was wrong. Deleting a line which zeroes MSP pointer solved the problem
 
					
				
		
 lpcxpresso_supp
		
			lpcxpresso_supp
		
		
		
		
		
		
		
		
	
			
		
		
			
					
		This IAP call doesn't take up much space. You can move the code into its' own file, and compile this one file without optimization. I am curious why you set the MSP to flash memory. Besides that, you don't need to setup the stack for this call. Every ISP call uses it's own stack.
Thanks and regards,
MCUXpresso Support
Where to should I set my MSP? Should I set it at all?
What is more, have you tried such thing without optimization. Might it be a problem of a specific microcontroller?
 
					
				
		
 jeremyzhou
		
			jeremyzhou
		
		
		
		
		
		
		
		
	
			
		
		
			
					
		Hi Arturas Jonkus,
Have a great day,
TIC
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
I understand it yet reinvoking doesn't work both ways
 
					
				
		
 jeremyzhou
		
			jeremyzhou
		
		
		
		
		
		
		
		
	
			
		
		
			
					
		Hi Arturas Jonkus,
Thanks for your reply.
I was wondering if you can tell me which chip you use.
Have a great day,
TIC
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
LPC11u67. It is used in a lot of my projects.
