Skip to main content
Visitor II
June 6, 2024
Question

GPIO output configuration not working

  • June 6, 2024
  • 2 replies
  • 1451 views

 

Hi, I have an STM32H563ZIT6 board and a simple task: to toggle the GPIO at maximum speed. I set the PA11 pin as an output pin and generated the code. Then, I used the HAL Library function [HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_11);] to toggle the PA11 pin every 1 second. It is working perfectly, and the LED is glowing.

However, when I manually configure the PA11 pin as an output pin, the LED does not blink. I have attached my code for your reference. Any help would be highly appreciated

 

void GPIO_Init()

{

//GPIO Ports Clock Enable

RCC->AHB2ENR|= RCC_AHB2ENR_GPIOAEN;



//Configure GPIO pin Output Level

GPIOA->BRR |= GPIO_BRR_BR11;



//Configure IO Direction mode

GPIOA->MODER |=GPIO_MODER_MODE11_0;



//Configure the IO Speed

GPIOA->OSPEEDR |=GPIO_OSPEEDR_OSPEED11_1;



//Configure the IO Output Type

GPIOA->OTYPER &=~GPIO_OTYPER_OT11;

}

int main()

{

GPIO_Init();

/* Infinite loop */

/* USER CODE BEGIN WHILE */

while (1)

{

GPIOA->BSRR |= GPIO_BSRR_BS11;

HAL_Delay(1000);

GPIOA->BSRR |= GPIO_BSRR_BR11;

HAL_Delay(1000);

}

}
    This topic has been closed for replies.

    2 replies

    Technical Moderator
    June 6, 2024

    Hello,

    Need to debug and check the register contents versus what is expected in the reference manual: especially GPIOx_MODERGPIOx_OTYPER and GPIOx_BSRR.

    PS: in next time please use <\> button to insert your code for best readability.

    Super User
    June 6, 2024

     

    //Configure IO Direction mode
    
    GPIOA->MODER |=GPIO_MODER_MODE11_0;

     

    This does not work as expected, as the reset value of GPIO_MODER in newer STM32 (including 'H5) is not zero.

     

    Generally,

    > check the register contents versus what is expected

    +1.

    JW

     

    PS. Don't RMW (i.e. |=) into BSRR. I'ts harmless, as BSRR reads as zero, but wasting time, as it always reads as zero. Write value directly (i.e. GPIOA->BSRR = 1 << 11;).