Strange watchdog irq when using systick

Hello, i’ve come across some strange behaviour when dealing with SysTick timer. Basic routine, just wanted to turn on and off LED in order to test my c++ library but when i’m invoking SysTick_Config function program stucks in WWDG Interrupt as soon as it reaches while loop. If systick function is commented everything works fine. I’ve tested this approach in Keil and STM32Cube and issue doesn’t occur. Is a PlatformIO’s CMSIS library systick_config() default behaviour? Or i dunno… Thanks for any help.

int main()

{

    SystemInit();

    SystemCoreClockUpdate();

    SetAPB2PeripheralClock(RCC_APB2ENR_IOPAEN, true);

    SysTick_Config(SystemCoreClock / 1000);

    gpio::GPIO led_pin(GPIOA, 0, gpio::MODE::OUTPUT_PP, gpio::SPEED::SPEED_OF_2MHz);

    led_pin = true;

    while (true)

    {

        pseudoDelay();

        if (led_pin())

            led_pin = false;

        else

            led_pin = true;

    }

    return 0;

}

Due to aliasing multiple interrupt handlers to the same “while(1) { ; }” loop in the startup file, being stuck in WWDG_Handler() usually mean that an unimplemented interrupt was encountered (which default-mapped to the infinite loop), or a hardfault has occurred.

Without having the complete project files it’s very hard to say what’s going on. Can you post it?

Here you are, GPIO class doesn’t have any impact on a program flow because it doesn’t work neither with led_pin variable nor without it. That’s why im not pasting it.

@edit I haven’t mentioned but program doesn’t halt in SysTick_Handler() and in debug mode i don’t have access to msTicks value even though it’s global variable.

#include "stm32f103xb.h"

void pseudoDelay()

{

    for (volatile int i = 0; i < 500000; i++)

    {

    }

}

volatile uint32_t msTicks = 0;

void SysTick_Handler(void)

{

    msTicks++;

}

int main()

{

    SystemInit();

    SystemCoreClockUpdate();

    SysTick_Config(SystemCoreClock / 1000);

    SetAPB2PeripheralClock(RCC_APB2ENR_IOPAEN, true);

    gpio::GPIO led_pin(GPIOA, 0, gpio::MODE::OUTPUT_PP, gpio::SPEED::SPEED_OF_2MHz);

    led_pin = true;

    while (true)

    {

        // pseudoDelay();

        if (led_pin())

            led_pin = false;

        else

            led_pin = true;

    }

    return 0;

}

If this is in C++ code you must extern "C" declare it to prevent name-mangling and so that it links correctly. The startup file uses C-style function names, aka, not mangled.

Is this all the code? There’s only one code file, main.cpp? What is the full platformio.ini?

1 Like

Oh my god…I totally forgot about name-mangling and extern keyword in C++. Now it works, thanks :smiley: