Unusual GPIO Initialization
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-09-26 2:02 PM
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?
This discussion is locked. Please start a new topic to ask your question.
2 REPLIES 2
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-09-26 4:26 PM
Posted on September 27, 2014 at 01:26
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?
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Up vote any posts that you find helpful, it shows what's working..
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-09-27 1:28 AM
Posted on September 27, 2014 at 10:28
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
