Skip to main content
Associate II
June 24, 2026
Question

Comparateor inputs selection in CubeMx2

  • June 24, 2026
  • 3 replies
  • 77 views

Split from this post: 

Dear ST Technical Moderator,
(mEALLEm)

many thanks for your prompt answer !

You actually solved my problem by using CubeMX2 tool,
where one can assign selected peripheral pins (in my case COMP2 two inputs and one output)
to actual package IO pins.

As far as I see, CubeMX2 tool “offered” to make assignment of 

Comparator Plus input with one of four IO pins
COMP2_INP:
IO1: PA3
IO2: PB15
IO3: PC0
(I want to use PA3) !

and 
Comparator Minus input with one of four IO pins
COMP2_INM:
IO1: PC1
IO2: PC5
IO3: PA2
(I want to use PA2) !

it is stated in my text, in the very beginning !
... quote
In new design,  where planned MCU is STM32C542CCT6 device, (LQFP48 package),
I plan to use internal Comparator COMP2.
...
PA7 pin as Comparator2 Output
and pin PA2 as Comparator2 -INPut, 
and pin PA3 as Comparator2 +INPut.
... unquote


Well, 
the only problem is that I did not install SW development environment yet,
so,
 I did not use CubeMX2 tool,
 I was just reading the documentation, RefManual and device DS,
and I did not find any sentence related to IO correspondence you showed to me !

Besides, it seems to me that you also did not find such information in docs, as you mentioned in your reply
...
Meanwhile, I don’t see the I/O correspondence with COMPx-INy in the documentation.
...
??

 

However,
problem of STM32C5 MCU COMP2_IN Pins assignment
can be easily solved using CubeMX2,
but, there is not any specific instruction how to do that in docs !

Finally,
could you send me the code snippet as generated in CubeMX2
to see how the registers are filled to get the desired assignment ?


Once more,
Many thanks for your help !


Blažimir Miše,
BUCK
 

3 replies

blaziBUCKAuthor
Associate II
June 25, 2026

Dear all,

if the problem of STM32C5 MCU COMP2_IN Pins assignment
can be easily/correctly solved using CubeMX2 ONLY  (sic),
what is the purpose of reading 2500+ page Document such is Reference Manual ?

(btw, there is not INFO about that)

 

Also,

where I could find some CODE examples of setting/assignments related to

“correspondence” between Comparators Pins (COMP2_INP, COMP2_INM)

and PORT pins (PA2, PA3) properly ?

 

Many thanks for your help !

T_Hamdi
ST Employee
August 13, 2026

Hello ​@blaziBUCK 

For the pin assignment, refer to the datasheet of the SoC STM32C542xx, not the reference manual. Go to Section 4: “Pinouts/ballouts, pin description, and alternate functions.” In this section, you can find the functions available for each pin. For example, for pin PA3, one of the possible functions is COMP1_OUT.

 about CODE examples You can refer to the examples delivered with the STM32CubeC5 package for additional guidance.

STM32CubeC5/examples/hal/comp/vref_it at main · STMicroelectronics/STM32CubeC5

 

with regards,

Hamdi

"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.Hamdi Teyeb"
blaziBUCKAuthor
Associate II
August 13, 2026

Dear Hamdi,

Many thanks for your reply trying to help me with Pins Assignment for the Comparator Inputs, but, You only confirmed what I mentioned in my original post!

Namely, let me remind that I plan to use Comparator2 in such way :

PA7 pin as Comparator2 Output
and pin PA2 as Comparator2 -INPut, 
and pin PA3 as Comparator2 +INPut.

In short,
it is not a problem to "assign" Comparator Output, COMP2_OUT to pin PA7, since I will declare AF14 = COMP2_OUT in appropriate GPIOA_AFRL register, see page 352 in RM0522 Reference manual, (RM)

but,

how to assign Comparator Inputs mentioned in “Additional Functions” in rightmost column in Table 12 in DS ?

In other words, how to assign, for example, pin PA2 to Comparator2 INPUT Minus ?

Is there some Register to do so ?

or the only way is to do that “assignment” in Software using CubeMX2 tool ?

(I did not find such statements in Code Examples you pointed...)

Best regards,

Blazi