Skip to main content
Explorer
October 18, 2024
Question

How to work with GPIO

  • October 18, 2024
  • 2 replies
  • 1294 views

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.

    2 replies

    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.

    Filipx.87Author
    Explorer
    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)

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