IAP Reinvoke ISP only works when optimization is turned off

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

IAP Reinvoke ISP only works when optimization is turned off

ソリューションへジャンプ
2,455件の閲覧回数
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 解決策
1,978件の閲覧回数
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 返答(返信)
1,979件の閲覧回数
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 件の賞賛
返信
1,978件の閲覧回数
arty
Contributor II

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

0 件の賞賛
返信
1,978件の閲覧回数
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

1,978件の閲覧回数
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 件の賞賛
返信
1,978件の閲覧回数
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 件の賞賛
返信
1,978件の閲覧回数
arty
Contributor II

I understand it yet reinvoking doesn't work both ways

0 件の賞賛
返信
1,978件の閲覧回数
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 件の賞賛
返信
1,978件の閲覧回数
arty
Contributor II

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

0 件の賞賛
返信