IAP Reinvoke ISP only works when optimization is turned off

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

IAP Reinvoke ISP only works when optimization is turned off

Jump to solution
2,575 Views
arty
Contributor II

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

Labels (2)
0 Kudos
Reply
1 Solution
2,098 Views
lpcxpresso_supp
NXP Employee
NXP Employee

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

View solution in original post

0 Kudos
Reply
8 Replies
2,099 Views
lpcxpresso_supp
NXP Employee
NXP Employee

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

0 Kudos
Reply
2,098 Views
arty
Contributor II

That's exactly what was wrong. Deleting a line which zeroes MSP pointer solved the problem

0 Kudos
Reply
2,098 Views
lpcxpresso_supp
NXP Employee
NXP Employee

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

2,098 Views
arty
Contributor II

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?

0 Kudos
Reply
2,098 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Arturas Jonkus,

Thank you for your interest in NXP Semiconductor products and 
for the opportunity to serve you.
It's not necessary to execute some optimization before call IAP Reinvoke ISP command to enter the Boot mode again.

Have a great day,
TIC

 

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
Reply
2,098 Views
arty
Contributor II

I understand it yet reinvoking doesn't work both ways

0 Kudos
Reply
2,098 Views
jeremyzhou
NXP Employee
NXP Employee

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!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
Reply
2,098 Views
arty
Contributor II

LPC11u67. It is used in a lot of my projects.

0 Kudos
Reply