4 years, 4 months ago.

Why does my program end up in an infinite loop (Default_Handler)?

I'm going to try and give as brief of a description as a I can. I think I know what I causing the problem, but I'm not sure how to fix it.

I'm trying to use MBED (gcc4mbed) on a self-made board. It's very similar to the NUCLEO F103RB, but uses the F103C6 instead. I used the porting guide to make the board support files, along with some minor adjustments to existing and shared code. (These changed were due to the fact that the F103C6 has no I2C_2, SPI_2 and UART_3 and the HAL files expect these to exist.

Anyway, the project builds fine on my existing NUCLEO F401RE and runs fine. This is my code:

#include "mbed.h"

DigitalOut myled(LED1);
Serial pc(SERIAL_TX, SERIAL_RX);

int main() 
{
    while(1) 
    {
        myled = 1;
        wait(0.05);
        myled = 0;
        wait(0.2);
    }
}

As you can see, I basically just added the Serial object there and nothing else to the HelloWorld example. (Without that line, everything works and the light blinks!) Using the GDB debugging environment in Eclipse, I narrowed down the line which causes the jump to the infinite loop to happen. It is this line: https://github.com/mbedmicro/mbed/blob/master/libraries/mbed/common/Stream.cpp#L26

A few steps earlier, the irq handler is set: https://github.com/mbedmicro/mbed/blob/master/libraries/mbed/common/SerialBase.cpp#L30. I think this has something to do with it, because the comments in the startup_stm32f103x6.S say that the program ends up there "when the processor receives an unexpected interrupt."

I'm quite confused now. Can someone point me in the right direction ?

Comment on this question

3 Answers

3 years, 11 months ago.

I'm having the same problem right now, with my self-made STM32F103RE board.

In the beggining it was OK, so I started adding code... and I got this problem. Somewhere between _start and main() it goes to this infinit loop:

(gdb) c Continuing. ^C Program received signal SIGINT, Interrupt. WWDG_IRQHandler () at /opt/mbed/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F1/TARGET_BOARD_F103RE/TOOLCHAIN_GCC_ARM/startup_stm32f103xe.S:138

138 b Infinite_Loop

(I'm not enabling the WWDG in my code)

By coincidence, I added the RTC XTAL (32.768 KHz) and started working.

But more lines of code and I got the problem again...

2 years, 6 months ago.

Is there a solution to this issue yet ?

4 years, 4 months ago.

Quick question:

How are following pins defined: LED1, SERIAL_TX, SERIAL_RX (what are the uC hardware pins) ? Also, where does this jump to infinite loop happen - before main() or inside main()/while(1) ?

Regards Miloje


You need to log in to post a question