cancel
Showing results for 
Search instead for 
Did you mean: 

Newbie looking for help with GPIO

sandtime
Associate II
Posted on September 01, 2014 at 23:00 I have an STM32F4 Discovery board, which I am relatively new to. I'm trying to figure out how to work with GPIO's, and I haven't been able to find a good tutorial yet, so I'm trying to work it out by looking at a few examples. The problem I'm running into is that even duplicating just a few lines of code is causing me problems. For reference, I'm using Keil MDK. This is only an excerpt of some of the code, but I'm starting off with a working blinky project. I've added the below lines:

#include ''stm32f4xx_gpio.h''
GPIO_InitTypeDef GPIO_InitStructure;
// in main():
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);

That last line that enables the peripheral clock is causing the following errors: error: use of undeclared identifier 'RCC_AHB1Periph_GPIOD' warning: implicit declaration of function 'RCC_AHB1PeriphClockCmd' is invalid in C99 I've tried searching, but I haven't found an explanation and solution to this. What am I doing wrong? ---- As a second question, when I'm setting the project runtime environment, I see two different options for GPIO: 1. Device\GPIO 2. Device\StdPeriph Drivers\GPIO What's the difference between the two and which one do I want? #gpio #know-your-tools
6 REPLIES 6
Andrew Neil
Evangelist
Posted on September 01, 2014 at 23:16

''I have an STM32F4 Discovery board, which I am relatively new to''

Sounds like you must also be quite new to 'C' programming in general - yes?

error:  use of undeclared identifier 'RCC_AHB1Periph_GPIOD'

 

warning:  implicit declaration of function 'RCC_AHB1PeriphClockCmd' is invalid in C99

 

The 

#include ''stm32f4xx_gpio.h''

just gives you the GPIO_... stuff - you also need the header for the RCC_... stuff.

Take a look at ST's examples...
sandtime
Associate II
Posted on September 01, 2014 at 23:41

>

> From: neil.andrew

>

> Sounds like you must also be quite new to 'C' programming in general - yes?

>

    I'm on the beginning side of intermediate, however it's been a while since I've had to code in C, so I'm definitely rusty.

    

> The #include ''stm32f4xx_gpio.h'' just gives you the GPIO_... stuff - you

> also need the header for the RCC_... stuff.

>

    Ah, that would definitely do it.  I added the relevant Include directive and the error went away.  Thank you!

    

    Can you shed any light on the second question regarding which GPIO driver to use?

    
Posted on September 02, 2014 at 02:52

Ok, you need to create a project that points to the appropriate library files and include directories. You also want to pay attention to the defines the library passes via the compilers command line.

Nominally you'd pull in stm32f4xx.h, OR stm32f4_discovery.h, and it in turn would pull in other include files you need via a project specific stm32f4xx_conf.h

You really need to get your own copy of the library, and not Keil's, and then familiarize yourself with the project templates and their structure/form.

STM32F4-Discovery_FW_V1.1.0\Project\Peripheral_Examples\IO_Toggle

STM32F4-Discovery_FW_V1.1.0\Project\Peripheral_Examples\IO_Toggle\MDK-ARM\IO_Toggle.uvproj

STM32F4xx_DSP_StdPeriph_Lib_V1.3.0\Project\STM32F4xx_StdPeriph_Templates\MDK-ARM\Project.uvproj

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on September 02, 2014 at 02:55

/* GPIOD Periph clock enable */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
/* Configure PD12, PD13, PD14 and PD15 in output pushpull mode */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOD, &GPIO_InitStructure);
/* PD12 to be toggled */
GPIO_SetBits(GPIOD, GPIO_Pin_12);
/* PD13 to be toggled */
GPIO_SetBits(GPIOD, GPIO_Pin_13);
/* PD14 to be toggled */
GPIO_SetBits(GPIOD, GPIO_Pin_14);
/* PD15 to be toggled */
GPIO_SetBits(GPIOD, GPIO_Pin_15);
GPIO_ResetBits(GPIOD, GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15);

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Andrew Neil
Evangelist
Posted on September 02, 2014 at 08:48

''You really need to get your own copy of the library, and not Keil's''

Absolutely!

Keil's copies of the library are notoriously out-of-date.

''then familiarize yourself with the project templates and their structure/form''

And look at the provided examples.
sandtime
Associate II
Posted on September 22, 2014 at 00:14

> From: neil.andrew

> Posted: Tuesday, September 02, 2014 8:48 AM

> Subject: Newbie looking for help with GPIO

>

> ''You really need to get your own copy of the library, and not Keil's''

>

> Absolutely!

>

> Keil's copies of the library are notoriously out-of-date.

>

> ''then familiarize yourself with the project templates and their

> structure/form''

>

> And look at the provided examples.

This is definitely news to me.  Especially since Keil's Pack Installer lists different versions and periodically comes out with updates, this is absolutely the first I'm hearing about this.

Alright then, I'm grabbing STM32CubeF4 1.3.0 right now.

Here's the thing - all the tutorials I've been using are Keil specific (which is reasonable, since that's the IDE I'm working with).

Are there any write-ups or tutorials which show how to use Keil, specifically, with the seperately downloaded CubeF4 drivers and files?