Skip to main content
Explorer
July 6, 2024
Solved

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

  • July 6, 2024
  • 1 reply
  • 5068 views

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.
    Best answer by Tesla DeLorean

    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.

    1 reply

    Graduate II
    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?

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

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