cancel
Showing results for 
Search instead for 
Did you mean: 

HAL GPIO assert fails for GPIO_AF3_TIM10 on STM32F4 devices

OleksandrMovchan
Associate

Description
Hello,

I am using STM32F411RET and STM32F407ZGT microcontrollers.
Using STM32CubeMX, I configure a PWM output on GPIOB Pin 8 using TIM10 Channel 1.
After code generation, the following GPIO initialization code is produced:

GPIO_InitStruct.Pin = GPIO_PIN_8;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Alternate = GPIO_AF3_TIM10;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

The PWM output works correctly on hardware.
However, when full assertions are enabled by defining USE_FULL_ASSERT, an assertion failure occurs inside HAL_GPIO_Init() at the following check:

assert_param(IS_GPIO_AF(GPIO_Init->Alternate));

After inspecting the IS_GPIO_AF() macro for STM32F4 devices, I noticed that GPIO_AF3_TIM10 is not included in the list of valid alternate functions, even though TIM10 uses AF3 on STM32F4 devices and is correctly generated by STM32CubeMX.
This causes a false assertion failure when using a valid and supported peripheral configuration.

Expected behavior
GPIO_AF3_TIM10 should be included in the IS_GPIO_AF() validation macro for STM32F4 devices (e.g. STM32F407 / STM32F411), or the assertion logic should be updated to avoid rejecting valid alternate functions generated by CubeMX.

Additional notes
The issue occurs only when USE_FULL_ASSERT is enabled.
The generated code and hardware configuration are otherwise correct.
Disabling full assertions or manually extending IS_GPIO_AF() resolves the issue.

1 ACCEPTED SOLUTION

Accepted Solutions
mƎALLEm
ST Employee

Issue confirmed and it seems IS_GPIO_AF() macros currently omitted all possible peripheral instances (TIM9, TIM10, and TIM11) for GPIO_AF3 selection.

That will be fixed in the next version of the HAL.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

View solution in original post

4 REPLIES 4
mƎALLEm
ST Employee

Hello,

Thank you for raising that issue. I'm escalating it internally for fix.

Indeed:

It's available with STM32F401x device (in stm32f4xx_hal_gpio_ex.h):

#if defined(STM32F401xC) || defined(STM32F401xE)
#define IS_GPIO_AF(AF)   (((AF) == GPIO_AF0_RTC_50Hz)   || ((AF) == GPIO_AF12_SDIO)      || \
                          ((AF) == GPIO_AF0_MCO)        || ((AF) == GPIO_AF0_TAMPER)     || \
                          ((AF) == GPIO_AF0_SWJ)        || ((AF) == GPIO_AF0_TRACE)      || \
                          ((AF) == GPIO_AF1_TIM1)       || ((AF) == GPIO_AF1_TIM2)       || \
                          ((AF) == GPIO_AF2_TIM3)       || ((AF) == GPIO_AF2_TIM4)       || \
                          ((AF) == GPIO_AF2_TIM5)       || ((AF) == GPIO_AF3_TIM9)       || \
                          ((AF) == GPIO_AF3_TIM10)      || ((AF) == GPIO_AF3_TIM11)      || \
                          ((AF) == GPIO_AF4_I2C1)       || ((AF) == GPIO_AF4_I2C2)       || \
                          ((AF) == GPIO_AF4_I2C3)       || ((AF) == GPIO_AF5_SPI1)       || \
                          ((AF) == GPIO_AF5_SPI2)       || ((AF) == GPIO_AF5_SPI4)       || \
                          ((AF) == GPIO_AF6_SPI3)       || ((AF) == GPIO_AF7_USART1)     || \
                          ((AF) == GPIO_AF7_USART2)     || ((AF) == GPIO_AF8_USART6)     || \
                          ((AF) == GPIO_AF9_I2C2)       || ((AF) == GPIO_AF9_I2C3)       || \
                          ((AF) == GPIO_AF10_OTG_FS)    || ((AF) == GPIO_AF15_EVENTOUT))
#endif /* STM32F401xC || STM32F401xE */

While it's missing with STM32F411xE device (in stm32f4xx_hal_gpio_ex.h)::

#if defined(STM32F411xE) 
#define IS_GPIO_AF(AF)   (((AF) == GPIO_AF0_RTC_50Hz)   || ((AF) == GPIO_AF9_TIM14)      || \
                          ((AF) == GPIO_AF0_MCO)        || ((AF) == GPIO_AF0_TAMPER)     || \
                          ((AF) == GPIO_AF0_SWJ)        || ((AF) == GPIO_AF0_TRACE)      || \
                          ((AF) == GPIO_AF1_TIM1)       || ((AF) == GPIO_AF1_TIM2)       || \
                          ((AF) == GPIO_AF2_TIM3)       || ((AF) == GPIO_AF2_TIM4)       || \
                          ((AF) == GPIO_AF2_TIM5)       || ((AF) == GPIO_AF4_I2C1)       || \
                          ((AF) == GPIO_AF4_I2C2)       || ((AF) == GPIO_AF4_I2C3)       || \
                          ((AF) == GPIO_AF5_SPI1)       || ((AF) == GPIO_AF5_SPI2)       || \
                          ((AF) == GPIO_AF5_SPI3)       || ((AF) == GPIO_AF6_SPI4)       || \
                          ((AF) == GPIO_AF6_SPI3)       || ((AF) == GPIO_AF5_SPI4)       || \
                          ((AF) == GPIO_AF6_SPI5)       || ((AF) == GPIO_AF7_SPI3)       || \
                          ((AF) == GPIO_AF7_USART1)     || ((AF) == GPIO_AF7_USART2)     || \
                          ((AF) == GPIO_AF8_USART6)     || ((AF) == GPIO_AF10_OTG_FS)    || \
                          ((AF) == GPIO_AF9_I2C2)       || ((AF) == GPIO_AF9_I2C3)       || \
                          ((AF) == GPIO_AF12_SDIO)      || ((AF) == GPIO_AF15_EVENTOUT))

#endif /* STM32F411xE */

Internal ticket 227747 for fix.

Thank you for your your contribution.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

It also related to the STM32F407xx

Ok thanks. I requested to do a check for all devices for AF3.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
mƎALLEm
ST Employee

Issue confirmed and it seems IS_GPIO_AF() macros currently omitted all possible peripheral instances (TIM9, TIM10, and TIM11) for GPIO_AF3 selection.

That will be fixed in the next version of the HAL.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.