Skip to main content
Graduate
December 16, 2025
Question

STM32F051 Internal comparator configuration

  • December 16, 2025
  • 3 replies
  • 81 views

Hi,

I am trying to configure the internal cooperators in the STM32F051 micro-controller, but in the .ioc file I am able to configure only one Comparator. I require three comparators for my application. Is it possible to configure multiple comparators on the STM32F051 development board? If so, could someone please explain how to configure multiple comparators in the STM32F051 micro-controller?

    This topic has been closed for replies.

    3 replies

    Super User
    December 16, 2025

    > I require three comparators for my application.

    waclawekjan_0-1765883691611.png

    > I am able to configure only one Comparator

    Maybe there's some conflict between second comparator and some other peripheral, which prevents CubeMX from enabling it. I don't use Cube/CubeMX.

    If you don't need the 3 comparators at the same time, you may be able to switch between inputs to use one comparator for two or three inputs. Details need to be looked up in the RM. This is probably not something you can click in CubeMX.

    JW

    Aiswarya1Author
    Graduate
    December 17, 2025

    PA1, PA2, and PA3 are the positive input pins of Comparator 1, and PA0, PA4, and PA5 are the negative input pins of Comparator 1. Can I configure these pins simultaneously and use Comparator 1 as a multiplexer?

    Super User
    December 17, 2025

    I've had a look at the 'F0 and it does not have that flexibility.

    waclawekjan_0-1765980544402.png

    Only PA1 can be used as positive input to COMP1. You can multiplex between PA0, PA4 (you must not enable DAC) and PA5 as negative inputs to COMP1. (And yes, those pins can be all set to Analog at startup, and then selected by controlling the MUX in COMP_CSR.COMP1INSEL field).

    Similarly, PA3 is the only positive input to COMP2.

    So you don't have three pairs of pins which could be used even with multiplexing.

    This is the lowest range of STM32; there are families with more comparators (e.g. 'F3).

    JW

    Super User
    December 16, 2025

    > STM32F051

    What is the full chip number you are using? Letters after this...

     

    Only one ST board that uses this chip and comparators 1 and 2 are easily configurable in CubeMX with it.

    TDK_0-1765891540670.png

     

    Attach your IOC file. Perhaps the pins are already being used by other peripherals.

    Aiswarya1Author
    Graduate
    December 17, 2025

    can I configure comparator 1 as MUX?

     

    Super User
    December 18, 2025

    CubeMX - as any configurator and the associated libraries such as Cube/HAL - inevitably implements only "typical" settings - writing tools  and libraries which would cover all the possibilities these microcontrollers offer would take too much time and cost too much money. I don't use CubeMX, I program directly through registers, in that way I am free to set them up in any way they allow.

    Generally, you should set all four pins as Analog in GPIO_MODER - I believe CubeMX may allow that for the remaining two pins - and then you select whichever negative input you need, in runtime.

    JW