# STM32 controller: GPIO_SetBits doesn't seem to have any effect

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.

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;
GPIO_StructInit(&GPIOa);

GPIOa.GPIO_Mode = GPIO_Mode_OUT;
GPIOa.GPIO_OType = GPIO_OType_PP;
GPIOa.GPIO_PuPd = GPIO_PuPd_NOPULL;
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;
while(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?

• 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. – Scott Seidman Nov 17 '15 at 17:23
• Look at your PINS definition. It's probably zero so no pins are configured! – rfkortekaas Nov 17 '15 at 17:51
• @ScottSeidman LEDs on demoboards works just fine. I will draw a circuit of my setup in a minute - can you please take a look? – Alexey Malev Nov 17 '15 at 17:51
• @rfkortekaas PINS evaluates to 15 decimal or 1111 binary, as expected. – Alexey Malev Nov 17 '15 at 18:02
• I see LED1 apparently connected to PA0, but I don't see any current-limiting resistor. – Tut Nov 17 '15 at 21:13

GPIOa.GPIO_Mode = GPIO_Speed_2MHz;

GPIOa.GPIO_Speed = GPIO_Speed_2MHz;