WFI instruction stops debugger

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

WFI instruction stops debugger

Jump to solution
11,270 Views
scottm
Senior Contributor II

I'm using an MK02FN64VLF10 with KDS, porting an application from an HCS08.  I've used the WFI instruction in place of the HCS08's WAIT instruction to pause a loop while waiting for a periodic interrupt.  It works fine, but when I'm using the debugger the WFI instruction causes it to stop with a "suspended : signal : SIGTRAP : Trace/breakpoint trap" message.  After that it seems to keep running but the debugger is disconnected.  My debug connection is via SWD to a P&E Multilink Universal.

It's just a nuisance at this point, but I can't find any information on whether this is the expected behavior and the best way to avoid it.  I can just exclude the WFI instruction in the debug build, but then it's a less accurate representation of the system's actual behavior.  Is there another way around this?

Thanks,

Scott

Labels (1)
Tags (1)
1 Solution
9,263 Views
scottm
Senior Contributor II

Finally got resolution on this.  P&E appears to have fixed the bug in the 2.4.7.201605092133 update of the gdb plugin.  It's now working as expected.

View solution in original post

33 Replies
2,746 Views
scottm
Senior Contributor II

I've got it packed up on Dropbox and I can send you a link, but apparently I can't message you if you're not following me.

The project is using a K02.  You won't get past the self-test without the right SPI flash connected, but you don't need to go that far to see the error.  It's set up right now to use your enter_wait() function, and the macro WAIT_FOR_INTERRUPT has the POWER_SYS_SetMode() call.  Either of those or even just a WFI instruction alone will cause the debugger problem.

Thanks,

Scott

0 Kudos
Reply
2,746 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Scott,

    I already get your project, and test it on my side.

    After I modified your code, and just test the enter_wait() function, I didn't find your problem on my side.

    Take care, when you do debugging in the wait mode, just use the resum(full run) instead of the step in.

    If enter the wait mode, the code will wait the wakeup happens, as you know, any interrupt will wake up the wait mode, then the code will continue to run the code below the enter_wait() function.

    After I check your code, I find  you enable the systick in the OS, if you enable this module, the systick interrupt will happen, and it will wakeup the wait mode automatically, so I suggest you choose the used timer as NONE, just like the following picture, it also include the code I modified.

48.jpg

49.jpg

After the modification, the code runs ok on my side.

Beside, I also help you create a KDS project which just have the enter_wait function and the PTC1 falling interrupt wakeup.

Please find my test project from the attachment.

Following is my test result.

1. enter in the wait mode, the code won't stop, just wait the wakeup happens:

50.jpg

2, after I press the button, which just make PTC1 has a falling edge, then it will enter in the PTC1 interrupt , this interrupt will wake up the wait mode, you can find the code will run to the for(;;) which below etner_wait();

51.jpg

You can find all the process  the debug works ok, and there has none error or reset happen.

Please use my project, and test it on your side!

Wish it helps you!


Have a great day,
Jingjing

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

0 Kudos
Reply
2,746 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Scott,

   I already give you a message, please give me your test project as soon as possible!

Waiting for your reply!

Jingjing

0 Kudos
Reply
2,746 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi SCOTT MILLER,

    WFI instruction is used to let the core enter the sleep mode, and a lot of clocks will be closed, it includes the debugger.

    Your debugger is disconnected phenomena is correct.

    So, when do the low power testing, we also download the code the chip, then disconnect the debugger, and just test the MCU power consumption is OK.

Wish it helps you!

If you still have question, please contact with me!


Have a great day,
Jingjing

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

0 Kudos
Reply
2,746 Views
scottm
Senior Contributor II

I figured that was the case but I was hoping there might be a way to keep the debugger waiting while it's not clocked.  I don't care about power measurement while in debug mode, but it'd be nice to keep the timing representative of normal operation.  The BDM debuggers on the HCS08 and ColdFire never seemed to have any trouble with wait instructions.

In this case, the lack of a wait instruction actually revealed a race condition that had gone unnoticed in the code for about 8 years.  Still, I'd prefer to not have to make WFI instructions conditional macros.

Thanks,

Scott

0 Kudos
Reply
2,746 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi SCOTT MILLER,

    Actually, in the STOP mode, the debug(SWD) is  power off in the system, the hardware is power off the DEBUG interface, so you can't debug it in the STOP mode,

  Just as the flowing picture shows:

41.jpg


Have a great day,
Jingjing

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

0 Kudos
Reply
2,746 Views
scottm
Senior Contributor II

Not sure I follow.  Are you saying that the system is in STOP mode when it executes the WFI instruction?  I haven't dug in to the Kinetis low-power modes in detail yet because I haven't had the need.  I assumed it worked like the WAIT mode on the HCS08, distinct from STOP.

0 Kudos
Reply
2,746 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi SCOTT MILLER,

      HCS08 is not the same core as the kinetis, K02 is the ARM Cortex M4 core, in ARM cortex M4 core, the WFI is used to enter in the low power standby state.

      WFI is not only enter in the STOP mode, but also can enter in the WAIT mode, it should associate with the SCB_SCR register, SLEEPDEEP bit, SMC_PMCTRL, SMC_STOPCTRL register.

    If you just want to enter in the WAIT mode, and you don't disable the SWD interface, of course you can still stay in the debug mode.

   But you said, you don't want to enter in any low power mode, could you tell me what the function of "WFI" in your K02 code? what the function do you want to realize? You can post some code, then it will help us to get more information.

Best Regards,

Jingjing

0 Kudos
Reply
2,746 Views
scottm
Senior Contributor II

But you said, you don't want to enter in any low power mode, could you tell me what the function of "WFI" in your K02 code? what the function do you want to realize? You can post some code, then it will help us to get more information.

I think we're having a language problem here.  I said that I didn't need to measure power consumption with the debugger connected, and I said that I have not yet learned Kinetis low power modes in detail because I haven't had the need.  "Have not had" is present perfect tense and indicates a state of affairs up until the present.  In this context, and used in contrast to the present tense "do not have", it implies that this state of affairs has changed in the present time.  To put it more clearly, I did not need to know the Kinetis low power modes until this time because until now I have not had the need for low power modes, but now I do.

I compared my knowledge of the HCS08 low-power modes to explain my expectations regarding the behavior of the debugger and to give you a frame of reference in which to explain the differences between the wait mode operation of the two cores on the assumption that you would have at least a passing familiarity with both.  I'm certain you meant no offense, but to imply that I don't know that the Kinetis has a Cortex M4 core and not an HCS08 core is a little insulting.

WFI is not only enter in the STOP mode, but also can enter in the WAIT mode, it should associate with the SCB_SCR register, SLEEPDEEP bit, SMC_PMCTRL, SMC_STOPCTRL register.

I think what you're saying here is the WFI enters either STOP mode or WAIT mode, depending on the state of the SLEEPDEEP bit of the SCB SCR register and the SMC_STOPCTRL bit of the SMC_PMCTRL register.  Is that correct?  "In the STOP mode" and "in the WAIT mode" would suggest that the WAIT and STOP modes are the starting state.  "Into STOP mode" or "into WAIT mode" would suggest a transition to those states.

"It should associate with..." is unclear and suggests that the association is uncertain.  "It is associated with" might be a better choice to indicate an unconditional relationship between WFI and the registers.

Listing the four items separated by commas makes their associations unclear.  "the SCB_SCR register's SLEEPDEEP bit", "SLEEPDEEP bit of the SCB_SCR register", or "SCB_SCR[SLEEPDEEP]" would all be better ways to indicate the association between the register and the bit.  At the least, keeping the register:bit order consistent would be helpful.

To get back to the problem, the project is using KSDK 1.3 and Processor Expert and at the moment this is the code I'm using to enter wait mode:

POWER_SYS_SetMode(1, kPowerManagerPolicyAgreement);

Configuration 1 is set to wait mode with PSTOP2 as the partial stop option.  I've stepped through with the debugger and verified that the power state transitions follow the diagram given in section 7.5 of the reference manual and that the SLEEPDEEP and STOPCTRL bits seem to be set properly.  The debugger still loses its connection.

Debugger issues aside, the POWER_SYS_SetMode() call is hundreds of instructions long.  The program's main loop wakes up at a rate of 20 kHz and during most waking cycles executes only a few dozen instructions.  Can you tell me what the most efficient WAIT mode entry procedure is from RUN or HSRUN modes?

And please understand that I'm not trying to insult your English skills.  I'm trying to provide usable feedback rather than just venting my frustrations.

Thanks,

Scott

0 Kudos
Reply
2,746 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi SCOTT MILLER,

  Thank you very much for your more question details and the patience to explain it.

  I am really very sorry for the confuse which I bring you with my inaccurate statements, but I really don't mean any offense to you, all I wanted was to help you get out of this problem and get more question information which is useful to the problem solution.

  Now, you already give me enough information:KSDK 1.3, WAIT low power mode, MK02FN64VLF10, POWER_SYS_SetMode(1, kPowerManagerPolicyAgreement);

  Answer your 2 questions:

1. Debugger lost when enter WAIT mode

  If you use the POWER_SYS_SetMode(1, kPowerManagerPolicyAgreement); to enter in the WAIT mode, actually, just like what I have said, WAIT mode won't disconnect the debugger, except you disable the SWD interface with code.

  When you do step debugging in POWER_SYS_SetMode, did you meet this code:

  disable_unused_pins();

43.jpg

void disable_unused_pins(void)

{

  /* Disable debug pins when MCU sleeps */

  setup_debug_pins(kPortPinDisabled);

  /* Disable uart pins */

  setup_uart_pins(kPortPinDisabled);

}

              }

If yes, please comment it, this code is used to disable the SWD debug interface and the uart interface.

I already check it with the KSDK1.3.0 sample code with our FRDMK22:C:\Freescale\KSDK_1.3.0\examples\frdmk22f\demo_apps\power_manager_hal_demo

After I comment code disable_unused_pins();, even I enter in the WAIT mode with debugger, the debugger still can be connected, and after the WAIT mode is wakeup, the debugger can enter in the RUN mode again.

2.The most efficient WAIT mode entry procedure

  Yes, you are correct, the KSDK code is really long, complicate.

  If you want to enter in the WAIT mode, actually, you don't need to call all that functions, the KSDK is the full function for all the low power code.

You can write your own simplified code.

Take an example:

void enter_wait()

{

    volatile uint32_t dummyRead;

            SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk;

            /*

            * Ensure that all register writes associated with setting up the

            * low power mode being entered have completed before the MCU enters

            * the low power mode.

            */

            dummyRead = SMC_RD_PMCTRL(SMC);

            dummyRead = dummyRead;

            __WFI();

         

}

Then just call enter_wait() instead of POWER_SYS_SetMode(1, kPowerManagerPolicyAgreement);

Please use my code and try again!

If you still have question, please contact with me!

Have a great day,
Jingjing

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

0 Kudos
Reply
2,746 Views
scottm
Senior Contributor II

I apologize for my last message; I was frustrated that morning and it came out as linguistic pedantry.

I don't actually see a callback in there at all, and it's not disabling any pins.  I tried your wait code and it does the same thing - in all cases it's the WFI instruction that causes it.  It does not stop working if I step through the code, though - only if it's running normally.  It's showing up like a reset, with the debug display halted at 0x4d8 (which is the startup code) but the device continues running normally.

Any ideas?

Scott

0 Kudos
Reply
2,746 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi SCOTT MILLER,

   Please send me the whole project which you are testing and modified with me wait code, I need to check your project, and test it on my side to find the root problem.

   Besides, tell me the IDE you are using, KDS or CW?

Waiting for your reply!

Best Regards,

Jingjing

0 Kudos
Reply
2,746 Views
scottm
Senior Contributor II

This project is using KDS.  There doesn't seem to be support for the K02 in CW10 or I'd be using that.  I tried adding a WFI instruction to a K22 project in CW10 and the debugger didn't have any trouble.  I don't have any K22 projects set up for KDS at the moment to test with.

Let me know how I can send the project securely and I'll pack it up for you.

Thanks,

Scott

0 Kudos
Reply