AnsweredAssumed Answered

GPIO actions - is this how people really write code?

Question asked by TSK on May 12, 2015
Latest reply on May 12, 2015 by Clive One
After searching for a long time I understood that the only reading materials I can get are the reference manual and the ST library comments - not a lot. I imagine this is the main reason I can't get even simple things to work.

My goal is to write a simple program that will light a green LED when a button is pressed and a red one when it isn't. The button is hooked up PA0, LEDs to PG13 & 14. I used CubeMX to generate init code. At this point there is no debounce or anything like this. This is my equivalent to a hello world app.

Here is the code from the while loop:
while (1)
  {
        if (HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_0) == GPIO_PIN_SET)
        {
            HAL_GPIO_WritePin(GPIOG,GPIO_PIN_13,GPIO_PIN_SET);
            HAL_GPIO_WritePin(GPIOG,GPIO_PIN_14,GPIO_PIN_RESET);
        }
        else
        {
            HAL_GPIO_WritePin(GPIOG,GPIO_PIN_14,GPIO_PIN_SET);
            HAL_GPIO_WritePin(GPIOG,GPIO_PIN_13,GPIO_PIN_RESET);
        }
    }
This seems kind of long for something this basic, no? Also aren't these functions add a lot to the overhead? Of course now I couldn't care less but what happens when more and more things are running?

Outcomes