I have some problem with a STM32F030F4P6 MCU. The circuit consists of MCU itself, 3V rail connected to VDD and VDDA pins, ground connected to GND and BOOT0 pin and an LED connected to each of PA0-PA3 pins. Here is a circuit diagram (lines drawn near SV1 and SV2 connectors means external wires going to LED/power/ground/SWCLK/SWDIO pins.

enter image description here

Here is my code in it:

#include "stm32f0xx.h"
#include "stm32f0xx_gpio.h"
#include "stm32f0xx_rcc.h"

const uint16_t PINS = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3;

int main(void)
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
    GPIO_InitTypeDef GPIOa;

    GPIOa.GPIO_Mode = GPIO_Mode_OUT;
    GPIOa.GPIO_OType = GPIO_OType_PP;
    GPIOa.GPIO_Pin = PINS;
    GPIOa.GPIO_Mode = GPIO_Speed_2MHz;
    GPIO_Init(GPIOA, &GPIOa);

    volatile uint32_t i;

    GPIO_SetBits(GPIOA, PINS);
    volatile uint8_t state = 1;
        // Waste some time
        for (i = 0; i < 500000; i++) {};
        if (state == 1) {
            GPIO_ResetBits(GPIOA, PINS);
            state = 0;
        } else {
            GPIO_SetBits(GPIOA, PINS);
            state = 1;

The problem is - LEDs connected to pins doesn't light up. I have connected a voltmeter to the output pins and debugged a program and found out that voltage goes up a little bit (to about 0.1V) each time I do GPIO_SetBits or GPIO_ResetBits, but instantly drops down to zero afterwards. Also to rule out lack-of-current issues, I changed GPIOa.GPIO_PuPd to GPIO_PuPd_UP and all the LEDs light up, but doesn't light down.

I use STM32VLDiscovery board as a debugger and CooCoox IDE.

During debugging, I can see GPIOA_ODR register bits are changing (and no longer changing if I remove the first line of main()), so it seems to be some problem with the output.

Can anyone give me any advise of what am I doing wrong?

  • \$\begingroup\$ If you're using the discovery board, and it has LEDs on it, you should minimally modify your code to try to make one of the on-board LED's light first. If you can do this, you probably have some basic circuit issue, as opposed to initialization or code. \$\endgroup\$ Commented Nov 17, 2015 at 17:23
  • \$\begingroup\$ Look at your PINS definition. It's probably zero so no pins are configured! \$\endgroup\$ Commented Nov 17, 2015 at 17:51
  • \$\begingroup\$ @ScottSeidman LEDs on demoboards works just fine. I will draw a circuit of my setup in a minute - can you please take a look? \$\endgroup\$ Commented Nov 17, 2015 at 17:51
  • \$\begingroup\$ @rfkortekaas PINS evaluates to 15 decimal or 1111 binary, as expected. \$\endgroup\$ Commented Nov 17, 2015 at 18:02
  • \$\begingroup\$ I see LED1 apparently connected to PA0, but I don't see any current-limiting resistor. \$\endgroup\$
    – Tut
    Commented Nov 17, 2015 at 21:13

1 Answer 1


Here is the problem:

GPIOa.GPIO_Mode = GPIO_Speed_2MHz;

Should be

GPIOa.GPIO_Speed = GPIO_Speed_2MHz;

Very dumb. 8 hours of life wasted :(


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.