2024-06-06 12:46 AM - last edited on 2024-06-06 01:44 AM by SofLit
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);
}
}
2024-06-06 01:42 AM - edited 2024-06-06 01:43 AM
Hello,
Need to debug and check the register contents versus what is expected in the reference manual: especially GPIOx_MODER, GPIOx_OTYPER and GPIOx_BSRR.
PS: in next time please use <\> button to insert your code for best readability.
2024-06-06 01:56 AM - edited 2024-06-06 01:57 AM
//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;).