This message will disappear after all relevant tasks have been resolved.
Semantic MediaWiki
There are 1 incomplete or pending task to finish installation of Semantic MediaWiki. An administrator or user with sufficient rights can complete it. This should be done before adding new data to avoid inconsistencies.This article explain what is and how to use GPIO through examplesl
1. GPIO definition
Stands for General Purpose Input/Output. GPIO is a type of pin found on an integrated circuit that does not have a specific function. While most pins have a dedicated purpose, such as sending a signal to a certain component, the function of a GPIO pin is customizable and can be controlled by software.
1.1. Configure GPIO for LED toggling
1.1.1. Objective
- Learn how to setup pin and GPIO port in STM32CubeMX
- How to Generate Code in STM32CubeMX and use HAL functions
1.1.2. Goal
- Configure GPIO pin in CubeMX and Generate Code
- Add in to project HAL_Delay function and HAL_GPIO_Toggle function
- Verify the correct functionality on toggling LED
1.1.3. Create project in CubeMX
- Menu > File > New Project
- Select STM32F4 > STM32F429/439 > LQFP144 > STM32F439ZITx
- Configure LED pin as GPIO_Output
1.1.4. For debug purpose is recommended to select debug pins SWD or JTAG
- Select can be done in TAB>Pinout>SYS
- On discovery is available only SWD option
- If SWD/JTAG is not selected and the Set all free pins as analog (MENU>Project>Settings>TAB>Code Generator) is selected, debug is not possible
1.1.4.1. Clock Configuration overview 10
- External clock enabling
- TAB>Pinout
- Select HSE and LSE clocks
- Bypass or crystal
1.1.4.2. In order to run on maximum frequency, setup clock system
1.1.4.3. GPIO Configuration
- TAB>Configuration>System>GPIO
1.1.4.4. GPIO(Pin) Configuration
- Select Push Pull mode
- No pull-up and pull-down
- Output speed to HIGH is important for faster peripheries like SPI, USART
- Button OK
1.1.4.5. GPIO(Pin) output speed configuration
- Change the rising and falling edge when pin change state from high to low or low to high
- Higher GPIO speed increase EMI noise from STM32 and increase STM32 consumption
- It is good to adapt GPIO speed with periphery speed. Ex.: Toggling GPIO on 1Hz is LOW optimal settings, but SPI on 45MHz the HIGH must be set
1.1.4.6. Now we set the project details for generation
- Menu > Project > Project Settings
- Set the project name
- Project location
- Type of toolchain
1.1.4.7. Now we can Generate Code
- Menu > Project > Generate Code
1.1.4.8. Now we open the project in our IDE
- The functions we want to put into main.c
/* USER CODE BEGIN 3 */
/* Infinite loop */
while (1)
{
HAL_GPIO_WritePin(GPIOG, GPIO_PIN_14, GPIO_PIN_SET);
HAL_Delay(500);
HAL_GPIO_WritePin(GPIOG, GPIO_PIN_14, GPIO_PIN_RESET);
HAL_Delay(500);
}
/* USER CODE END 3 */