PlatformIO Community

My projects are acting weirdly, same code works on other solutions

I recently moved to PlatformIO, because my main code editor is Vim.

My code is:

#include <stm32l0xx.h>
#include <stm32l0xx_hal.h>
#include <stm32l0xx_hal_gpio.h>

int main(void)


GPIO_InitTypeDef gpio;
gpio.Pin = GPIO_PIN_5;
gpio.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &gpio);

gpio.Pin = GPIO_PIN_13; // konfigurujemy pin 13
gpio.Mode = GPIO_MODE_INPUT; // jako wejście
gpio.Pull = GPIO_PULLUP; // włączamy rezystor podciągający
HAL_GPIO_Init(GPIOC, &gpio); // port GPIOC

while (1)
if (HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_13) == GPIO_PIN_RESET) { // jesli przycisk jest przycisniety,
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_SET); // zapal diode
} else {

which is meant to light the LED on board after pressing a button.
Yet… after uploading it with PlatformIO Led lights we acting weirdly, I have to press two buttons at once.
I tried the same code on OpenSTM32, and it works just fine.
My board is Nucleo L073RZ if it helps.
Also, my platformio.ini:

platform = ststm32
board = nucleo_l073rz
framework = stm32cube

I’m under Arch Linux.

You’re forgetting to initialize the .Alternate member here, maybe initialize it to 0?

Which two buttons do you have to press?

You are also setting the speed a GPIO_SPEED_FREQ_LOW but if the button has bouncing, it might change very rapidly. You might want a software debounce here, too.

There, a different version of the STM32 HAL library may be used. According to the Release_Notes.html file for the L0 HAL provided by PIO, it was released 26-October-2018.

1 Like