cancel
Showing results for 
Search instead for 
Did you mean: 

Where to find documentation on GPIO_InitTypeDef ?

jefazo92
Associate III

Hi everyone,

I am student who is new to STM32. I am trying to understand how to program the MCU and noticed GPIO_InitTypeDef data type. I went into the reference manual but did not find anything about it. Is there a document including all the functions a user can apply to the STM32 (and hopefully find information on GPIO_InitTypeDef) ? Thank you in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
berendi
Principal

> Is there a document including all the functions a user can apply to the STM32

It is the reference manual and the datasheet. The reference manual documents the interface to the user program, the datasheet documents the external connections.

The full functionality of the microcontroller is exposed through the hardware registers, which are extensively documented in the reference manual.

> and hopefully find information on GPIO_InitTypeDef

GPIO_InitTypeDef belongs to a software library (called HAL - Hardware Abstraction Layer for no apparent reason) which can be used to program STM32 microcontrollers. The HAL library however does not cover all the functionality of the MCU, and the documentation mostly consists of one-liner Captain Obvious descriptions of its functions and data structures, not very suitable for understanding the workings of the microcontroller. Fortunately it is not needed to program the MCU, there is nothing in HAL that can't be achieved using the well documented register interface.

View solution in original post

17 REPLIES 17

Grep the source code, most stuff has a lot of the documentation in the comments.

If you are using a suitable IDE you should be able to Right Click and go to the definitions of structures and functions.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
jefazo92
Associate III

Hi @Community member​ , thank you for replying so quickly. I am using the STM32CubeIDE. I am right clicking the data type but nothing happens.

Using Keil here.

Then use "Find in Files" or equivalent to navigate to the source/include file

Probably in stm32xyz_hal_gpio.h

/**
  * @brief GPIO Init structure definition
  */
typedef struct
{
  uint32_t Pin;       /*!< Specifies the GPIO pins to be configured.
                           This parameter can be any value of @ref GPIO_pins_define */
 
  uint32_t Mode;      /*!< Specifies the operating mode for the selected pins.
                           This parameter can be a value of @ref GPIO_mode_define */
 
  uint32_t Pull;      /*!< Specifies the Pull-up or Pull-Down activation for the selected pins.
                           This parameter can be a value of @ref GPIO_pull_define */
 
  uint32_t Speed;     /*!< Specifies the speed for the selected pins.
                           This parameter can be a value of @ref GPIO_speed_define */
 
  uint32_t Alternate;  /*!< Peripheral to be connected to the selected pins.
                            This parameter can be a value of @ref GPIO_Alternate_function_selection */
}GPIO_InitTypeDef;

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
jefazo92
Associate III

​Hi @Community member​  thank you again for your quick answers to both posts. For the CubeIDE I've found that when you hover over keywords highlighted in green, like GPIO_InitTypeDef, the information appears. But what I am trying to understand now is why

GPIO_InitTypeDef GPIO_InitStruct = {0};

Why is is it set to 0 and not any other number ?

This is general C, not STM32-specific. This initializes the first member of given struct explicitly to 0 and other members implicitly to 0. This mimics the same behaviour than if the struct would be defined as a global uninitialised variable (when it is entirely zeroed at the program entry). Local variables without explicit initializer have undefined value.

The "library" is deliberately designed so that zero init struct members "do no harm" (i.e. usually don't change the reset default values, or previously set values of the peripheral registers).

JW

Pavel A.
Evangelist III

> I am using the STM32CubeIDE. I am right clicking the data type but nothing happens.

This should work. If it does not, right click on the project (in the project explorer tree) and select Index-> Rebuild.

If still won't find the declaration - check the indexing settings in Eclipse

Window-> Preferences-> C/C++ -> Indexer

(Note: you want to find declaration of the GPIO_InitTypeDef struct, not the GPIO_InitStruct variable - the latter is trivial =)

-- pa

berendi
Principal

> Is there a document including all the functions a user can apply to the STM32

It is the reference manual and the datasheet. The reference manual documents the interface to the user program, the datasheet documents the external connections.

The full functionality of the microcontroller is exposed through the hardware registers, which are extensively documented in the reference manual.

> and hopefully find information on GPIO_InitTypeDef

GPIO_InitTypeDef belongs to a software library (called HAL - Hardware Abstraction Layer for no apparent reason) which can be used to program STM32 microcontrollers. The HAL library however does not cover all the functionality of the MCU, and the documentation mostly consists of one-liner Captain Obvious descriptions of its functions and data structures, not very suitable for understanding the workings of the microcontroller. Fortunately it is not needed to program the MCU, there is nothing in HAL that can't be achieved using the well documented register interface.

@berendi​ had a rant on the pros and cons of using "libraries" or not - maybe he could link it in here.

Imo this is educational thus generational thing - novices are taught and told to expect things to come in "libraries" and manufacturers like ST are just too happy to supply them, as they are a good tool to lock in the user. The downside is, that manufacturers such as ST then refuse to produce clean and concise examples, which are the real pinnacle of support and education (together with accompanying documentation, a.k.a. Application notes).

JW

In Eclipse (STM32CubeIDE) press F3, press F3 again, it cycles between definition and declaration. If this doesn't help use Search > File > Enclosing Project.