Skip to main content
Associate
May 21, 2026
Question

STM32L451 comparator settings with VREFINTx inputs

  • May 21, 2026
  • 8 replies
  • 256 views

Hi All, 

In my application, I am using the STM32L451RCT6 and trying to configure COMP2 with the internal Vref as a reference (specifically 3/4 Vref). For some reason, it never worked. I was only able to get it working when using DAC_CH1 or an external source as the reference. After a few days of troubleshooting and research, I finally found a relevant block diagram along with an important note in the reference manual (page 532).

y_liosha_0-1779367182238.png

The thing is, there are no mentions or explanations of this behavior in the reference manual, datasheet, or errata other than this. Could you confirm whether the STM32L45x series actually supports using the internal Vref as a comparator reference or am I facing some other issue here? Thank you! 

 

8 replies

mƎALLEm
Technical Moderator
May 21, 2026

Hello,

If it was indicated by the reference manual especially the RM0394 / the note under the figure 118, no need to indicate the reason why this was not implemented nor to indicate it in the errata sheet.

Perhaps, it was a choice by the design to not implement the VERFINTxxx on L45xx and L46xx as COMP inputs.

To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.
waclawek.jan
Super User
May 21, 2026

This is a nasty documentation fail... I believe it's a design bug disguised as documented feature, but documented extremely poorly.

waclawekjan_0-1779369140903.png

 

waclawekjan_1-1779369224727.png

 

waclawekjan_2-1779369289417.png

Also in DS:

waclawekjan_3-1779369476303.png

waclawekjan_4-1779369544291.png

If DAC_CH2 is not connected, than that should be documented too.

JW

[EDIT] I've just noticed there's no 'L461; 'L45x/'L46x would be more appropriate; sorry.

[EDIT2] There's no DAC_CH2 in 'L45x/'L46x, that's documented properly in the DAC chapter and DS; should be mentioned in the INMSEL fields description, and the Fig.118 footnote should be formulated clearer.

[EDIT3] 

Footnote to say unavailability of Vrefint and fractions, and DAC_CH2, should be added to Table 90. COMP1 input minus assignment and Table 92. COMP2 input minus assignment, too

Also, COMPx_CSR.SCALEN and COMPx_CSR.BRGEN appear to be linked to Vrefint and fractions. It would be nice if they would be depicted in Fig.118. The "bandgap" term should not be used in description of those bits, as this term is not explained/mentioned anywhere else in the RM (it is in the ADC chapter, where it may be confusing either). "Internal reference voltage", or "Vrefint" is used everywhere else.

y_lioshaAuthor
Associate
May 21, 2026

Yes, I agree. It is really hard to believe that such an important limitation is mentioned only once and in such an unexpected place. Unfortunately, it affects my project a bit. I guess I will have to solder a wire to an external pin.

mƎALLEm
Technical Moderator
May 21, 2026

The case was internally escalated over this internal ticket CDM0062827 for follow-up.

To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.
y_lioshaAuthor
Associate
May 21, 2026

Thank you for such a quick reaction! I really appreciate it.

waclawek.jan
Super User
May 21, 2026

I looked also at Cube (not CubeMX, I don't use it and don't intend to install/run/learn).

In stm32l4xx_hal_comp.c, there's a table listing the options for comparator inputs/outputs. It lists exceptions for 'L41x/'L42x and for 'L43x/'L44x, for which I can't find references in the COMP chapter in RM0394, and, sure, doesn't list the exceptions for 'L45x/'L46x. Haven't had look at the actual code, if it performs some actual validity checks in this regard.

In stm32l4xx_ll_comp.c, there's an actual check, which does not take into account the discussed 'L45x/'L46x exception.

(Just to explain my surge of activity here: I do use the 'L431 and 'L451 actively in a group of projects, and although not COMP so far, it may happen such requirement will come one day as we've expanded the scope already several times, and I don't want to be surprised either. Btw. these are chips with a really nice set of features, truly.)

JW

y_lioshaAuthor
Associate
May 22, 2026

I totally understand that. In my case, I am using the Keil IDE and the HAL library, and every time I set VREFINT as the reference source, the MCU immediately jumps into a hard fault without any explanation or flag being raised (although I should mention that I may have missed something). What I can confirm is that using an external reference source works well, although I only recently started testing that configuration. I have not tested DAC_CH1 as a reference source yet, but I assume it should work too.

waclawek.jan
Super User
May 22, 2026

> every time I set VREFINT as the reference source, the MCU immediately jumps into a hard fault

That's IMO unexpected and I would say there's some other unrelated reason.

Perhaps show, what expression exactly leads to that hardfault.

JW

waclawek.jan
Super User
May 22, 2026

@mƎALLEm ,

Thanks for this information. So, it appears, that - apart from the confusing footnote in Fig.118 - the probem was probably somewhere in  @y_liosha 's code, correct?

Can you also please have a look at this:

waclawekjan_0-1779451808636.png

waclawekjan_1-1779452699896.png

Thanks,

JW

mƎALLEm
Technical Moderator
May 22, 2026

Preferably to ask the question related to the comp driver in the STM32 Embedded software. 

I'll check the documentation next Monday.

To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.
waclawek.jan
Super User
May 22, 2026

@mƎALLEm , thanks.

JW