[SOLVED] STM32F103RB: Connecting to CPU via connect under reset failed after flashing a stop mode low power software

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • [SOLVED] STM32F103RB: Connecting to CPU via connect under reset failed after flashing a stop mode low power software

    Hello,
    I am using an STM32F103RB MCU in a specific Hardware design with J-Link Base Compact and IAR or J-Link commander as tools to flash and debug.
    The Hardware was always working fine (it is a final product of medical customer) until I flashed a software which implements the stop mode (deep sleep mode) management (by setting the SLEEPDEEP bit in the System control register (SCB_SCR) and configuring the PWR_CR register).
    Here is the code:

    C Source Code

    1. void PWR_EnterStopMode (uint8_t stopEntry)
    2. {
    3. // Disable Systick Interrupt
    4. SysTick->CTRL &= ~SYSTICK_CTRL_TICKINT_MSK;
    5. // clear Power down deepsleep
    6. PWR->CR &= ~PWR_CR_PDDS_MSK;
    7. // Select stop mode
    8. PWR->CR |= PWR_CR_LPDS_MSK;
    9. // Clear wake up flag
    10. PWR->CR |= PWR_CR_CWUF_MSK;
    11. // Set sleep deep in ARM Cortex System control register
    12. SCB->SCR |= SCB_SCR_SLEEPDEEP_MSK;
    13. if(stopEntry == PWR_LOWPOWER_ENTRY_WFI)
    14. {
    15. // Request wait for wakeup interrupt
    16. __WFI();
    17. }
    18. else
    19. {
    20. // Request wait for wakeup event
    21. __WFE();
    22. }
    23. /* Reset SLEEPDEEP bit of Cortex System Control Register */
    24. SCB->SCR &= ~SCB_SCR_SLEEPDEEP_MSK;
    25. // Enable SysTick Timer & activate Systick IRQ, set SysTick Clock Source to Core Clock
    26. SysTick->CTRL |= SYSTICK_CTRL_TICKINT_MSK | SYSTICK_CTRL_ENABLE_MSK;
    27. }
    Display All

    In the Software after calling WFI instruction (wait for interrupt) to wait for an interrupt to wake-up the micro-controller, it still sleeping for ever.
    In debug session by pressing next step in IAR, I can go out from deep sleep mode.
    When I go out from debug session, I can't connect anymore to the micro-controller and I can't flash it anymore.
    I guess that because always when I power on the Hardware, the CPU goes directly in deep sleep mode.

    I have the issue as described in the screenshot below.

    I tried to enable the low power handling mode in J-Link by using a script as following:

    C Source Code: ST_STM32F103RB.JLinkScript

    1. int InitEMU(void) {
    2. Report("STM32F103RB (ARM M3 core) J-Link script");
    3. JLINK_ExecCommand("EnableLowPowerHandlingMode");
    4. return 0;
    5. }
    and call the J-Link commander by Windows cmd:

    Source Code

    1. >JLink.exe -JLinkScriptFile "C:\My_Projects\ST_STM32F103RB.JLinkScript"
    But I am not sure that it's working fine because I didn't have the print of
    Report("STM32F103RB (ARM M3 core) J-Link script");

    Please any help!

    Kind regards,
    Images
    • cannot_connect_to_target.PNG

      38.41 kB, 1,222×668, viewed 541 times
  • Hi,
    Good to hear that you were able to resolve the issue.

    We will close this thread now.

    Best regards,
    Fabian
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.