Code working only in debugger

22 Jul 2015

Hello!

I'm new to mbed and facing a strange problem I've never seen before. The code is only working when executed step by step in the debugger. It is not running, or not running correctly, when running freely. I'm working on an STM32F4 discovery board, which is essentially an STM32F407VG CPU.

First of all, this is the simple demo program:

#include "mbed.h"

DigitalOut myled(LED5);
DigitalIn userButton(USER_BUTTON);

int main() {
	while(1) {
		myled = userButton;
	}
}

If this code is running freely, it is not detecting any button change. The LED reflects only the initial state of the button on reset. If I step through the program with GDB, only with step over, not diving into any function, it works correctly.

The Makefile is available as a gist: https://gist.github.com/anonymous/3460918dcb039c31f2fe

Has anyone seen this behavior before and can help out here?

Btw.: The hardware is working fine. The blinky demo program of the GNU ARM Eclipse-plugin is working correctly.

The hello world blinking LED from the handbook (or was it the cookbook?) didn't work either. I could not convince gdb to look into the hal source files, which is required for debugging into the timer stuff, like wait_ms. But this is more a gdb question and not really related to mbed.

I don't know if this is really a Hello World! question, but as I didn't manage to get past the Hello World! level in mbed, I post it here.

01 Aug 2015
  • push*

Is there some information missing?

Because the STM32F4 Discovery is a quite often sold board, I would really think that I'm doing something wrong here and this is not really an mbed issue.

17 Aug 2015

Is the online compiler able to build code for this target platform? If so, have you tried that?

It sounds like a timing issue of some kind. If you single step for a bit and see it work correctly for a few iterations and then give GDB the continue command, does it still work or start to fail updating again? When it is failing to update the LED, what happens if you attach GDB and break into the program?

Christoph Rüdiger wrote:

The hello world blinking LED from the handbook (or was it the cookbook?) didn't work either. I could not convince gdb to look into the hal source files, which is required for debugging into the timer stuff, like wait_ms. But this is more a gdb question and not really related to mbed.

This typically happens if the mbed SDK is built without symbols. Where did you get your mbed SDK libraries? If you used the Python build system then you may need to add the --options debug-info command line option.