2026-05-24 8:49 AM
Hello I recently solved an issue I was having with my STM32F303RE chip when using the internal comparators and attempting to connect them to the timers internally.
Here is a description of the issue:
1. Configure COMP6 Output Internal Selection to: Timer 4 Input Capture 4.
2. Configure Timer4 Channel 4 to Input Capture Direct Mode - Doing this automatically enables pin PB9 in CubeMx even though the timer should be wired internally. (important later)
3. Running testing with COMP6 toggling Timer 4 CH4 was never getting a trigger. If I temporarily enable the Comparator output Pin PC6 and wire externally to the Timer4 CH4 Pin PB9, then everything starts working as expected (except for the fact that I have to wire this externally).
4. Suspected a potential conflict between the GPIO Pin PB9 for Timer4 Ch4 and the internal mux wiring to COMP6. In CubeMX it is not possible to disable the Timer pin without also disabling the timer channel. To workaround this I needed to disable the pin after the timer is initialized using this code: HAL_GPIO_DeInit(GPIOB, GPIO_PIN_9); after TIM4 MPS GPIO init. After doing this, the internal routing of the comparator to the timer started working as expected.
5. I suspect that this issue affect all of the comparators that support linking to one of the STM32 timers. I was having this same issue when attempting to get the other comparators internally connected to the timers on the chip until I figured out the workaround.
6. Here is the code that needs to get added to the stm32f3xx_hal_msp.c file
/* USER CODE BEGIN TIM4_MspInit 1 */
/*
* TIM4_CH4 is used for the internal COMP6 -> TIM4_IC4 route, not the
* external PB9 pin. CubeMX generates PB9 as TIM4_CH4 for input capture,
* but leaving that alternate-function pin enabled prevents the internal
* comparator capture path from working on this board/configuration.
*/
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_9);
/* USER CODE END TIM4_MspInit 1 */