cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L1xx Pin Configuration + Allocation

pieter239955
Associate
Posted on January 28, 2013 at 15:24

Hi,

I am working with a STM32L1 chip (STM32L152RB to be exact, 64 Pin) and I would like start with the basics and then work up as I do not have any experience with it. I do not have the STM32L1 Dev/Eval board, I am working with our own board.

After looking at some of the example projects on IAR EWB I am getting to grips with some configurations, but I would just like to know how to set up 4 GPIO pins;

2 push-pull output pins configured to pins PB7 and PB8,

2 pull-up input pins configured to pins PB13 and PB14.

Any information for a beginner would be great, at this point just setting a pin of my choice high or low is progress.

The board and chip work fine so far and I can download and debug any example project without any problems.
2 REPLIES 2
Posted on January 28, 2013 at 15:58

void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* GPIOB Periph clock enable */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
/* Configure PB7 and PB8 in output pushpull mode */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_8;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_SetBits(GPIOB, GPIO_Pin_7); // PB7 High
GPIO_ResetBits(GPIOB, GPIO_Pin_8); // PB8 Low
/* Configure PB13 and PB14 in input mode */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_14;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOB, &GPIO_InitStructure);
}

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
pieter239955
Associate
Posted on January 28, 2013 at 17:47

Thanks, seems like I was overlooking the A,B,Cs etc on the end of GPIO enables and it was really confusing me, so simple now.

Thanks again.