2024-10-18 07:14 AM - last edited on 2024-10-18 07:39 AM by SofLit
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);
2024-10-18 07:29 AM - edited 2024-10-18 07: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.
2024-10-18 07: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)
2024-10-18 07: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);
2024-10-18 07:46 AM - edited 2024-10-18 07: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.
2024-10-18 07: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:
2024-10-18 08:00 AM
@SofLit 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?