2020-03-13 02:21 PM
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.
Solved! Go to Solution.
2020-03-14 12:22 AM
> 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.
2020-03-13 02:41 PM
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.
2020-03-13 02:48 PM
Hi @Community member , thank you for replying so quickly. I am using the STM32CubeIDE. I am right clicking the data type but nothing happens.
2020-03-13 02:56 PM
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;
2020-03-13 03:14 PM
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 ?
2020-03-13 03:30 PM
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
2020-03-13 04:55 PM
> 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
2020-03-14 12:22 AM
> 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.
2020-03-14 12:57 AM
@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
2020-03-14 01:10 AM
In Eclipse (STM32CubeIDE) press F3, press F3 again, it cycles between definition and declaration. If this doesn't help use Search > File > Enclosing Project.