Skip to main content
KMill
Senior
September 25, 2024
Solved

Debuging fails after HAL_Init()

  • September 25, 2024
  • 4 replies
  • 3565 views

I am debugging an application for an STMF103RCTX Using STM32CubeIDE and an STLINK v2 debugger.

This is my usual combination of tools and my usual hookup.

I find that I can start a debug session and step into main() and even step over anything befoer HAL_Init(); but as soon as I hit that the begugger connection fails.

I've made a short video showing this issue:

 

My hookup from the STLINK to the device is as follows:

STLINK --->  DEVICE
Pin 2 VCC ---> VCC
Pin 4 GND ---> GND
Pin 7 TMS/SWDIO ---> PA13/TMS/SWDIO (46)
Pin 9 TCLK/SWCLK ---> PA14/TCLK/SWCLK (50)
Pin 15 --> RESET ---> nRST (7)

 Any ideas? (The app runs perfectly when not trying to debug it)

    Best answer by KMill

    OK Found it!

    Screenshot 2024-09-25 at 11.36.14.png

    Somehow I have set debug to "No Debug" - Must have been me, but I don't recall ever going there!
    Changing ti back to Serial Wire debug fixes it.

    4 replies

    mƎALLEm
    Technical Moderator
    September 25, 2024

    Hello,

    What memset is doing here? The destination? the size?

    if you remove that line, do you have the same behavior?

    "To give better visibility on the answered topics, please click on ""Accept as Solution"" on the reply which solved your issue or answered your question."
    KMill
    KMillAuthor
    Senior
    September 25, 2024

    The memset is absolutely fine, destination and size are correct.

    I only added it to gove me something to step-over beforr HAL init as as test.

    I will try the things mentioned in the other post...

    Andrew Neil
    Super User
    September 25, 2024

    @KMill wrote:

    I find that I can start a debug session and step into main() and even step over anything befoer HAL_Init(); but as soon as I hit that the begugger connection fails.


    So what happens if you step into HAL_Init() ?

    Where within HAL_Init() does it fail?

    Does your  HAL_Init() disable the SWD pins, perhaps ... ?

    https://community.st.com/t5/stm32-mcus/how-to-solve-debugger-connection-issues/ta-p/49693

     

    A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
    KMill
    KMillAuthor
    Senior
    September 25, 2024

    @Andrew Neil Thanks for the suggestion.

    If I step into HAL_Init() it stops at this line:

    Screenshot 2024-09-25 at 11.04.37.png

    My IOC file has reserved the pins for debug:

    Screenshot 2024-09-25 at 11.05.43.png

    Andrew Neil
    Super User
    September 25, 2024

    @KMill wrote:

    If I step into HAL_Init() it stops at this line:

    Screenshot 2024-09-25 at 11.04.37.png


    Look at the comment immediately above that line: you are disabling the JTAG and SWD - so obviously the debug connection will fail!

    A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
    Karl Yamashita
    Principal
    September 25, 2024

    Start a new project with the bare minimum. Then see if you can debug and get past HAL_Init 

    If a reply has proven helpful, click on Accept as Solution so that it'll show at top of the post.CAN Jammer an open source CAN bus hacking toolCANableV3 Open Source
    Karl Yamashita
    Principal
    September 25, 2024

    Nevermind i found it. I started a new project with just serial debugging enabled, nothing else. I show the same code.

    If a reply has proven helpful, click on Accept as Solution so that it'll show at top of the post.CAN Jammer an open source CAN bus hacking toolCANableV3 Open Source