2025-10-29 7:57 AM
Hi everyone,
I’m trying to generate a square wave using TIM5 Output Compare (OC) on an STM32H7 board. I configured TIM5_CH1 to output on PA0, both in CubeMX and manually in HAL_TIM_MspPostInit(). Here is a snippet of my GPIO init:
GPIO_InitStruct.Pin = GPIO_PIN_0;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF2_TIM5;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);And the TIM5 channel configuration:
sConfigOC.OCMode = TIM_OCMODE_TOGGLE;
sConfigOC.Pulse = 3749;
HAL_TIM_OC_ConfigChannel(&htim5, &sConfigOC, TIM_CHANNEL_1);
The problem is that the square wave always appears on PA1, not PA0, even though I haven’t configured TIM5_CH2 anywhere.
I checked the datasheet pin mapping:
PA0 → TIM5_CH1
PA1 → TIM5_CH2
PA2 → TIM5_CH3
PA3 → TIM5_CH4
I suspect this might be related to alternate function routing or some hardware conflict on PA0 (maybe boot/debug pins), but I’m not sure.
Has anyone seen this behavior on STM32H7? What could cause TIM5_CH1 output to be redirected from PA0 to PA1?
Thanks in advance!
2025-10-29 8:06 AM
> an STM32H7 board
Which board? Which chip? Consult the schematic. Probably PA0/PA1 have been mismatched somehow.
> What could cause TIM5_CH1 output to be redirected from PA0 to PA1?
Nothing will cause this; the problem is elsewhere. The code you showed will initialize PA0. No problems there.
2025-10-29 8:31 AM - edited 2025-10-29 8:33 AM
Thank you for your answer.
> Which board?
STM32 Nucleo-144 development board with STM32H743ZI2 MCU
I’m not sure if it’s a user-related issue. As I mentioned, the situation is the same on different channels, and no matter which pin I initialize, the output always appears on pa1.
2025-10-29 9:18 AM - edited 2025-10-29 9:21 AM
Hello,
Please share your ioc file or even your complete project and what CubeMx version are you using?
2025-10-29 9:31 AM
Also share what pin you're measuring the signal on with a picture. Probably just using the wrong pin and/or it's mislabeled in the reference you're using.
2025-10-29 9:32 AM
> As I mentioned, the situation is the same on different channels, and no matter which pin I initialize, the output always appears on pa1.
Probably you are not running the code that you think you're running.