Toggle two leds every 200ms. We can configure two or more pins from the same port using the same configuration structure, we just need to use the or ( | ) binary operator and the pin definitions
#include "bsp.h"
int main( void )
{
GPIO_InitTypeDef GPIO_InitStruct; /*gpios initial structure*/
HAL_Init(); /*Init HAL library*/
__HAL_RCC_GPIOC_CLK_ENABLE(); /*Enable clock on port C*/
GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1; /*pins to set as output*/
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; /*output on mode push-pull*/
GPIO_InitStruct.Pull = GPIO_NOPULL; /*no pull-up niether pull-down*/
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; /*pin speed*/
/*use the previous parameters to set configuration on pin C0 and C1*/
HAL_GPIO_Init( GPIOC, &GPIO_InitStruct );
while (1)
{
/*Toggle leds connected to C0 and C1 state*/
HAL_GPIO_TogglePin( GPIOC, GPIO_PIN_0 | GPIO_PIN_1 );
/*Blocking delay for 200ms*/
HAL_Delay( 200u );
}
}