Skip to main content
Associate III
July 6, 2024
Solved

My code works when stepping in debug only, does not work in run mode

I have an STM32F407 Discovery board. My project works fine using the dicovery board.

Now it is time to move it to my own PCB, using a STM32F405.

As a board "bring up" I tried to run a simple LED toggle program. When I flash the program I get a Download verified successfully message.

It does not work unless I step through it in debug mode. In run mode the output pin for the LED stays high. If I add a variable and increment it every time the LED toggles I can see it incrementing normally in debug mode.

I have an external resonator crystal at 8MHz. I can see it working at 8 MHz on the scope.

I have a 10K resistor pulling BOOT0 to ground. The two VCaps are present. A 10k resistor pulls NRST up to 3.3v rail.

All power and grounds ok with decoupling caps.

I have checked all settings in my .ioc file. Cant see any issues. (The settings are the same as for my discovery board program that works correctly).

Im sure one of you can help.

 

Thanks in advance...

This topic has been closed for replies.
Tesla DeLorean
Tesla DeLoreanBest answer
Guru
July 7, 2024

Need two delays otherwise it loops immediately and state changes over a handful of nanoseconds and you miss it. Add a delay in both states or use a scope.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..

9 replies

Tesla DeLorean
Guru
July 6, 2024

So code probably is running..

Your code would be only thing turning on 8 MHz

Instrument Error_Hander() and HardFault_Handler() so you know if it ends up there. 

Do you have a UART you can use? Different LEDs?

SysTick needs to be working for delays to function. You need a delay to see LEDs toggling.

Can you toggle a GPIO/LED from a TIM pin or TIM IRQ Handler?

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Associate III
July 6, 2024

Hi,

How do I implement: Instrument Error_Hander() and HardFault_Handler() so you know if it ends up there. 

Im using an oscilloscope to monitor the output pin, so no LEDS required.

Why do I need a UART?

I call HAL_Init(); in the main function so the Systick will be running.

Ive never done (toggle a GPIO/LED from a TIM pin or TIM IRQ Handler). I need help with this one.

Tesla DeLorean
Guru
July 6, 2024

>>Why do I need a UART?

So you have some idea what's going on inside the MCU without the debugger interfering?

>>How do I implement:

Perhaps by using __FILE__ and __LINE__ on the calling side so you can find where it came from, and print that out to a UART, or set a RED LED or something to alert you to failure.

This can be migrated to GNU/GCC

https://github.com/cturvey/RandomNinjaChef/blob/main/KeilHardFault.c

Step One is knowing that you died..

 

Also, you don't need to start the HSE, the MCU can continue running from the HSI is started running with.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..