cancel
Showing results for 
Search instead for 
Did you mean: 

STM32IDE not supporting alternate functions on PD13 for PWM on STM32G474VET

rclar.6
Senior

 

CubeMX didn’t configure PD13 (TIM4_CH2, AF2) for PWM on STM32G474VET — manual GPIO init required

MCU/Package: STM32G474VET (LQFP100)
Tooling: STM32CubeMX / STM32CubeIDE (version:Version: 1.16.0Build: 21983_20240628_1741 (UTC))

Project type: HAL, PWM on TIM4_CH2
Clocking: System clock 168 MHz (TIM4 clock effectively 168 MHz), PSC=3, ARR=999 → ~42 kHz; CCR2=500 (50%)

Summary

Enabling TIM4 CH2 PWM on PD13 in CubeMX generated code that started the timer, but no waveform appeared on PD13. The generated project did not set PD13 to Alternate Function 2 (TIM4). Manually adding the GPIO init for PD13 (AF2) fixed it immediately.

Again I am finding alternate pins not supported (actually more like ignored)  by STM32IDE Cube. The previous one was CANFD3 on alternate pins.

Steps to reproduce

  1. Create a new CubeMX project for STM32G474VETx.

  2. Configure TIM4 → Channel 2 as PWM Generation CH2.

  3. Assign PD13 as the output pin for CH2.

  4. Set clocking for ~168 MHz system. Example PWM params: PSC=3, ARR=999, CCR2=500.

  5. Generate code and build. In main(), call HAL_TIM_PWM_Start(&htim4, TIM_CHANNEL_2);

  6. Probe PD13 on a scope.

Observed behavior

  • No PWM seen on PD13.

  • Inspecting generated code showed no GPIO init for PD13→AF2 (neither in MX_GPIO_Init() nor in HAL_TIM_MspPostInit()), or HAL_TIM_MspPostInit(&htim4) was not called from MX_TIM4_Init() (depends on the exact generation state).

  • Timer counter was running; CCR/ARR correct.

Expected behavior

CubeMX should generate the GPIO alternate-function configuration for PD13 → AF2 (TIM4_CH2), and ensure HAL_TIM_MspPostInit(&htim4) is called from MX_TIM4_Init() so the pin is properly muxed to the timer.

Workaround (verified)

Explicitly configure PD13 as AF2 for TIM4 in GPIO init (or add it inside HAL_TIM_MspPostInit()):

 

 
 
/* insert into GPIO_Init */
GPIO_InitTypeDef g = {0};
g.Pin       = GPIO_PIN_13;          // PD13
g.Mode      = GPIO_MODE_AF_PP;
g.Pull      = GPIO_NOPULL;
g.Speed     = GPIO_SPEED_FREQ_HIGH;
g.Alternate = GPIO_AF2_TIM4;        // AF2 = TIM4 on PD13
HAL_GPIO_Init(GPIOD, &g);

 

0 REPLIES 0