STM32F4 ConfigPin

Ok im getting tired of how that CMSIS is setup and find it to be more of hassle.Here is a simple but very useful function:

void ConfigPin(GPIO_TypeDef *myGPIO, uint32_t PIN, uint32_t MODE, uint32_t SPEED, uint32_t PUPD)
{
    /*
 myGPIO: The GPIOx port for the selected pin

 MODE: 0 = INPUT .... 1 = OUTPUT .... 2 = ALTERNATE FUNCTION .... 3 = ANALOG

 SPEED: 0 = 2MHz (Low Speed) .... 1 = 25MHz (Med. Speed) .... 2 = 50MHz (Fast Speed) .... 3 = 100MHz/80MHz (High Speed)(100MHz(30pf) - 80MHz(15pf))

 PUPD: 0 = No Pull-Up / No Pull-Down .... 1 = Pull-Up Enabled .... 2 = Pull-Down Enabled .... 3 = Reserved
 */
    myGPIO->MODER |= (MODE << (PIN * 2));//OUTPUT
    myGPIO->OSPEEDR |= (SPEED << (PIN * 2));//50MHz
    myGPIO->PUPDR |= (PUPD << (PIN * 2));   //Set it for NO PUPD
}

 

Advertisements

About atomsoft

Starting a small company. Trying to build it from ground up. Only 2 employees so far. Nothing serious yet but soon!

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: