cancel
Showing results for 
Search instead for 
Did you mean: 

Program doesn't run properly when debugger is not connected in STM32L476RE MCU

Pradeep Choudhary
Associate III
Posted on June 11, 2018 at 08:33

Hello,

I am using STM32L476RE MCU for one of my application which publishes some data to server using MQTT and my wifi module communicates with MCU with USART2.I am using atollic truestudio to write a code and debug it.I am using ST LINK V2 as my debugger.Now the problem that i am facing is that when i flash a code to MCU and debugger is connected then it runs fine but as soon as i remove debugger and turn off power and again power up the circuit then it doesnt work.I wrote a simple code for GPIO toggling it runs fine without debugger connected.I have attached the code that i have wrote.Same code works absolutely fine with STM32F401RE.Please help as soon as possible.

Regards,

Pradeep Choudhary

#stlink-v2 #stm32l4 #por-issue

Note: this post was migrated and contained many threaded conversations, some content may be missing.
27 REPLIES 27
Posted on June 11, 2018 at 13:42

Hello Antonio,

I would like to know how ST-LINK utility can be used when debugger wont be connected because i am working on customised board and i do not have any USB on board with help of which i can use it as a virtual com port.

Regards,

Pradeep

Posted on June 11, 2018 at 13:55

Find a USART_TX pin in your design that you can attach too and use that to output debug/telemetry data, or some other GPIO pin you can signal progress on within your code.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on June 11, 2018 at 14:01

Ok but focusing on what the F401 does isn't going to resolve issues you have on the L476. Your observation was noted, but you need to move beyond that.

You perhaps need to check-point your code to see where and how far it gets. Use a GPIO, or LED blink frequency. A GPIO connected to a TIM could be used, as could a scope.

Ideally use a USART to output information without the debugger attached. The SWV viewer in the ST-LINK Utilities should not be quite as invasive as a full debug connection. With custom boards it is important to design in multiple methods of debug, and access, to allow for effective development and testing.

Make sure you Hard_Fault_Handler does something more useful than while(1), similarly for Error_Handler, you perhaps want to toggle a Red LED or something to indicate arrival in either of those infinite failure loops.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on June 11, 2018 at 14:06

So are you saying to redirect printf() to UART and then receive that UART data on any PC application like hyperterminal?

Posted on June 11, 2018 at 14:07

You could use the ST-LINK/V2.1 that is included on STM32 Nucleo boards. You can connect it to your custom board by means of the SWD pins. After this, you can start your code without the debugger, and then, using the STM32 ST-LINK Utility, you'll be able to connect to your 

STM32L476RE chip in HotPlug mode.

Posted on June 11, 2018 at 14:09

That would be useful to understand where your code stops by taking a look at the output of your terminal.

Posted on June 11, 2018 at 14:15

I agree to whatever you have said but according to you what can be probable reasons for code working fine with debugger and not working when debugger is not connected.Code even works when debugger is connected to any 5V power source not particularly PC in which IDE is installed.

Regards,

Pradeep

Posted on June 11, 2018 at 14:22

The debugger fiddles with several internal settings to effect connectivity, the GPIOA clock and DBGMCU settings for example. If you have dependencies on things you haven't set/enabled then you will have problems.

Step One here is to identify where in your code it ends up, and how it gets there. The binary works/not test, or works someplace else with some other conditions, doesn't tell you how it fails here.

while(1) loops with no reporting are primary places where the code will end up and die. If your design has LEDs use those in these paths.

Comment out the bulk of code in main() until you can observe some success/life, and then use bisection to introduce more code until you can establish a pass/fail point.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on June 11, 2018 at 15:41

I would try to diagnose actually which part of code is creating problem after that if i am not able to diagnose cause of problem i will post the problem over here.

Pradeep Choudhary
Associate III
Posted on June 12, 2018 at 12:59

Thanks everyone for the suggestion.I just inserted a delay of 1 sec afterSystemClock_Config() and it started working in stand-alone mode.It would be really great if somebody how insertion of delay after SystemClock_Config() is related with proper booting of MCU.

Hoping for responses from

Turvey.Clive.002

meyer.frank

Vilei.Antonio

Regards,

Pradeep