Skip to main content
Filipx.87
Associate II
October 18, 2024
Question

How to work with GPIO

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);

 

 

This topic has been closed for replies.

6 replies

mƎALLEm
ST Technical Moderator
October 18, 2024

,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.

To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.
Filipx.87
Filipx.87Author
Associate II
October 18, 2024

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)

mƎALLEm
ST Technical Moderator
October 18, 2024

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);
To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.
Andrew Neil
Super User
October 18, 2024

@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:

https://community.st.com/t5/community-guidelines/how-to-write-your-question-to-maximize-your-chances-to-find-a/tac-p/725146/highlight/true#M54

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.