cancel
Showing results for 
Search instead for 
Did you mean: 

Debuging fails after HAL_Init()

KMill
Senior

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)

1 ACCEPTED SOLUTION

Accepted Solutions

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.

View solution in original post

12 REPLIES 12
SofLit
ST Employee

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 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

 

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...

Karl Yamashita
Lead III

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

Tips and Tricks with TimerCallback https://www.youtube.com/@eebykarl
If you find my solution useful, please click the Accept as Solution so others see the solution.

@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


@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!

@Andrew Neil Aye, I see that! The question is why is it being disabled?

I am in a debug configuration, and the pins are reserved for debug! 
I had a browse through the stm32f1xx_hal_msp.c but can't see any clues as to why that is there?

 

Are you overriding HAL_MspInit function? That function is usually defined as __weak

Tips and Tricks with TimerCallback https://www.youtube.com/@eebykarl
If you find my solution useful, please click the Accept as Solution so others see the solution.

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.