IAP Reinvoke ISP only works when optimization is turned off

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

IAP Reinvoke ISP only works when optimization is turned off

跳至解决方案
3,753 次查看
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

标签 (2)
0 项奖励
回复
1 解答
3,276 次查看
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 项奖励
回复
8 回复数
3,277 次查看
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 项奖励
回复
3,276 次查看
arty
Contributor II

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

0 项奖励
回复
3,276 次查看
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

3,276 次查看
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 项奖励
回复
3,276 次查看
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 项奖励
回复
3,276 次查看
arty
Contributor II

I understand it yet reinvoking doesn't work both ways

0 项奖励
回复
3,276 次查看
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 项奖励
回复
3,276 次查看
arty
Contributor II

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

0 项奖励
回复