PlatformIO Community

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

Hello.
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)
{
HAL_Init();

__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOC_CLK_ENABLE();

GPIO_InitTypeDef gpio;
gpio.Pin = GPIO_PIN_5;
gpio.Mode = GPIO_MODE_OUTPUT_PP;
gpio.Pull = GPIO_NOPULL;
gpio.Speed = GPIO_SPEED_FREQ_LOW;
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 {
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_RESET);
}
}
}

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:

[env:nucleo_l073rz]
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