2014-09-26 02:02 PM
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?2014-09-26 04:26 PM
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?
Someone wanted to trigger an external scope/analyzer, or test equipment, in a manner that indicated the device initialized and reached this point?2014-09-27 01:28 AM
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIOA->BSRRH=GPIO_Pin_5; //set low
GPIOA->BSRRL=GPIO_Pin_5;// set high