cancel
Showing results for 
Search instead for 
Did you mean: 

Is it possible to use a comparator with STM32CubeMX and STM32 Mat-target?

JLaba.1
Associate II

Hello everyone,

I'd like to use a NUCLEO-G474RE to control a buck converter in current mode. To do that I work with STM32CubeMX and Simulink, and I need to use a comparator. My problem is that whatever the input configuration I choose on CubeMX and the voltage I apply on the pins the output is always zero.

After searching into mthe generated code I discovered that the function HAL_COMP_Init is called but HAL_COMP_Start isn't . This is understandable because there aren't any COMP block in my Simulink model but the problem is that these blocks don't exist. So is it possible to generate the full functionning code to drive the comparator with this workflow?

I know I could probably add a few lines in the already generated code, but I would like to share my work only through the Simulink and CubeMX files without any need for the users to code by themselves.

1 REPLY 1
Igor Cesko
ST Employee

Hi JLaba.1,

The STM32CubeMX performs only configuration of peripherals to given operational state. But the starting of the peripheral is up to user : for example you configure timer but "TimerStart()" function must be called by user code at appropriate state. For comparator is there only one function to start if - but for another peripherals is the "Start" function more complicated: we can start peripheral in various modes (with interrupt/polling/DMA , with ADC in regular or injected mode, ... ).

So - for COMP it is implemented in the same way.

I don't know how to solve your problem - probably with some additional automation software. But if you write the "Start" function once into source code into user section then it will be there forever - also while next code generation by STM32CubeMX.

Regards

Igor