Question
Unusual GPIO Initialization
Posted on September 26, 2014 at 23:02
I'm maintaining some software for a STM32F103 and came across the following GPIO initialization code.
/* Configure PA5 as push-pull output for LED */
GPIO_WriteBit( GPIOA, GPIO_Pin_5, Bit_SET ); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_WriteBit( GPIOA, GPIO_Pin_5, Bit_SET ); GPIO_WriteBit( GPIOA, GPIO_Pin_5, Bit_RESET ); GPIO_WriteBit( GPIOA, GPIO_Pin_5, Bit_SET ); GPIO_WriteBit( GPIOA, GPIO_Pin_5, Bit_RESET ); GPIO_WriteBit( GPIOA, GPIO_Pin_5, Bit_SET ); GPIO_WriteBit( GPIOA, GPIO_Pin_5, Bit_RESET ); GPIO_WriteBit( GPIOA, GPIO_Pin_5, Bit_SET ); GPIO_WriteBit( GPIOA, GPIO_Pin_5, Bit_RESET ); The first five lines are what I would expect. However the Bit_SET/Bit_RESET pairs are puzzling, and I can't imagine what purpose they would serve. I couldn't find anything in the device reference manual to suggest this was necessary. Any guesses?