How to work with GPIO
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-10-18 7:14 AM - last edited on ‎2024-10-18 7:39 AM by mƎALLEm
Please advise where I'm doing wrong, I need to create variables with GPIO output with variable assignment and I don't know how to make it work correctly. 'my_gpio_port' reports as undeclared, but the declaration is without errors. Thanx
GPIO_TypeDef* my_gpio_port;
uint16_t my_gpio_pin;
if (Device_Config == Device_A)
{
my_gpio_port = GPIOA;
my_gpio_pin = GPIO_PIN_7;
}
else
{
my_gpio_port = GPIOG;
my_gpio_pin = GPIO_PIN_4;
}
HAL_GPIO_Write(my_gpio_port, my_gpio_pin, 1);
- Labels:
-
GPIO-EXTI
-
STM32F4 Series
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-10-18 7:29 AM - edited ‎2024-10-18 7:32 AM
,Hello,
First could you please provide the MCU part number? You created this thread on STM32 wireless.
Second, where did you define that typedef?:
GPIO_TypeDef
Third, did you enable the Port RCC clock? did you configure the GPIO pins?
Why are you using such code to access the pins:
if (Device_Config == Device_A)
{
my_gpio_port = GPIOA;
my_gpio_pin = GPIO_PIN_7;
}
else
{
my_gpio_port = GPIOG;
my_gpio_pin = GPIO_PIN_4;
}
Then you use the HAL API to access another pin!
Need to clarify what you need to do.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-10-18 7:37 AM
First could you please provide the MCU part number?
STM32F429ZIT6
You created this thread on STM32 wireless.
I'm sorry, I know I made a mistake and I can't edit it anymore.
where did you define that typedef?
In the int main(void)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-10-18 7:41 AM
Why are you using that kind of access in the first part
if (Device_Config == Device_A)
{
my_gpio_port = GPIOA;
my_gpio_pin = GPIO_PIN_7;
}
else
{
my_gpio_port = GPIOG;
my_gpio_pin = GPIO_PIN_4;
}
then you are using HAL for this part to set the GPIO pin?
HAL_GPIO_Write(my_gpio_port, my_gpio_pin, 1);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-10-18 7:46 AM - edited ‎2024-10-18 7:47 AM
Meanwhile to do a direct access to the register:
You can access it over BRR and BSRR or ODR registers:
GPIOx->BSRR to set the pin and GPIOx->BRR to reset the pin.
You need to look at HAL_GPIO_WritePin() implementation.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-10-18 7:56 AM
@Filipx.87 wrote:Please advise where I'm doing wrong
Not enough context to be sure.
@Filipx.87 wrote:'my_gpio_port' reports as undeclared
Please post a minimum but complete example which illustrates this.
Also post the complete build output. You haven't said what tools you're using but, for STM32CubeIDE, select-all & copy from the 'Console' window:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-10-18 8:00 AM
@mÆŽALLEm wrote:Why are you using that kind of access in the first part
Seems to be just to support 2 different configurations; equivalent to
if (Device_Config == Device_A)
{
HAL_GPIO_Write( GPIOA, GPIO_PIN_7 );
}
else
{
HAL_GPIO_Write( GPIOG, GPIO_PIN_4 );
}
@Filipx.87 - do you really need to do this at run time, or could it be done with conditional compilation?
