RTEMS 6.1-rc6
Loading...
Searching...
No Matches
stm32h7xx_hal_comp.c File Reference

COMP HAL module driver. This file provides firmware functions to manage the following functionalities of the COMP peripheral: More...

#include "stm32h7xx_hal.h"

Detailed Description

COMP HAL module driver. This file provides firmware functions to manage the following functionalities of the COMP peripheral:

Author
MCD Application Team
  • Initialization and de-initialization functions
  • Peripheral control functions
  • Peripheral state functions
Attention

Copyright (c) 2017 STMicroelectronics. All rights reserved.

This software is licensed under terms that can be found in the LICENSE file in the root directory of this software component. If no LICENSE file comes with this software, it is provided AS-IS.

================================================================================
                 ##### COMP Peripheral features #####
================================================================================
         
[..]       
    The STM32H7xx device family integrates two analog comparators instances
    COMP1 and COMP2:
    (#) The COMP input minus (inverting input) and input plus (non inverting input)
        can be set to internal references or to GPIO pins
        (refer to GPIO list in reference manual).

    (#) The COMP output level is available using HAL_COMP_GetOutputLevel()
        and can be redirected to other peripherals: GPIO pins (in mode
        alternate functions for comparator), timers.
        (refer to GPIO list in reference manual).

    (#) Pairs of comparators instances can be combined in window mode
        (2 consecutive instances odd and even COMP<x> and COMP<x+1>).

    (#) The comparators have interrupt capability through the EXTI controller
        with wake-up from sleep and stop modes:
        (++) COMP1 is internally connected to EXTI Line 20
        (++) COMP2 is internally connected to EXTI Line 21

[..] 
        From the corresponding IRQ handler, the right interrupt source can be retrieved
        using macro __HAL_COMP_COMP1_EXTI_GET_FLAG() and __HAL_COMP_COMP2_EXTI_GET_FLAG().


  
          ##### How to use this driver #####
================================================================================
[..]
    This driver provides functions to configure and program the comparator instances of 
    STM32H7xx devices.

    To use the comparator, perform the following steps:

    (#)  Initialize the COMP low level resources by implementing the HAL_COMP_MspInit():
    (++) Configure the GPIO connected to comparator inputs plus and minus in analog mode
         using HAL_GPIO_Init().
    (++) If needed, configure the GPIO connected to comparator output in alternate function mode
         using HAL_GPIO_Init().
    (++) If required enable the COMP interrupt by configuring and enabling EXTI line in Interrupt mode and 
         selecting the desired sensitivity level using HAL_GPIO_Init() function. After that enable the comparator
         interrupt vector using HAL_NVIC_EnableIRQ() function.

    (#) Configure the comparator using HAL_COMP_Init() function:
    (++) Select the input minus (inverting input)
    (++) Select the input plus (non-inverting input)
    (++) Select the hysteresis
    (++) Select the blanking source
    (++) Select the output polarity  
    (++) Select the power mode
    (++) Select the window mode
    -@@- HAL_COMP_Init() calls internally __HAL_RCC_SYSCFG_CLK_ENABLE()
        to enable internal control clock of the comparators.
        However, this is a legacy strategy. 
        Therefore, for compatibility anticipation, it is recommended to 
        implement __HAL_RCC_SYSCFG_CLK_ENABLE() in "HAL_COMP_MspInit()".
        In STM32H7,COMP clock enable  __HAL_RCC_COMP12_CLK_ENABLE() must 
        be implemented by user in "HAL_COMP_MspInit()".
    (#) Reconfiguration on-the-fly of comparator can be done by calling again
        function HAL_COMP_Init() with new input structure parameters values.

    (#) Enable the comparator using HAL_COMP_Start() or HAL_COMP_Start_IT()to be enabled 
        with the interrupt through NVIC of the CPU. 
    Note: HAL_COMP_Start_IT() must be called after each interrupt otherwise the interrupt
    mode will stay disabled.
    
    (#) Use HAL_COMP_GetOutputLevel() or HAL_COMP_TriggerCallback()
        functions to manage comparator outputs(output level or events)

    (#) Disable the comparator using HAL_COMP_Stop() or HAL_COMP_Stop_IT() 
        to disable the interrupt too.

    (#) De-initialize the comparator using HAL_COMP_DeInit() function.

    (#) For safety purpose, comparator configuration can be locked using HAL_COMP_Lock() function.
        The only way to unlock the comparator is a device hardware reset.
 
  *** Callback registration ***
  =============================================
  [..]

   The compilation flag USE_HAL_COMP_REGISTER_CALLBACKS, when set to 1,
   allows the user to configure dynamically the driver callbacks.
   Use Functions HAL_COMP_RegisterCallback()
   to register an interrupt callback.
  [..]

   Function HAL_COMP_RegisterCallback() allows to register following callbacks:
     (+) TriggerCallback       : callback for COMP trigger.
     (+) MspInitCallback       : callback for Msp Init.
     (+) MspDeInitCallback     : callback for Msp DeInit.
   This function takes as parameters the HAL peripheral handle, the Callback ID
   and a pointer to the user callback function.
  [..]

   Use function HAL_COMP_UnRegisterCallback to reset a callback to the default
   weak function.
  [..]

   HAL_COMP_UnRegisterCallback takes as parameters the HAL peripheral handle,
   and the Callback ID.
   This function allows to reset following callbacks:
     (+) TriggerCallback       : callback for COMP trigger.
     (+) MspInitCallback       : callback for Msp Init.
     (+) MspDeInitCallback     : callback for Msp DeInit.
   [..]

   By default, after the HAL_COMP_Init() and when the state is HAL_COMP_STATE_RESET
   all callbacks are set to the corresponding weak functions:
   example HAL_COMP_TriggerCallback().
   Exception done for MspInit and MspDeInit functions that are
   reset to the legacy weak functions in the HAL_COMP_Init()/ HAL_COMP_DeInit() only when
   these callbacks are null (not registered beforehand).
  [..]

   If MspInit or MspDeInit are not null, the HAL_COMP_Init()/ HAL_COMP_DeInit()
   keep and use the user MspInit/MspDeInit callbacks (registered beforehand) whatever the state.
   [..]

   Callbacks can be registered/unregistered in HAL_COMP_STATE_READY state only.
   Exception done MspInit/MspDeInit functions that can be registered/unregistered
   in HAL_COMP_STATE_READY or HAL_COMP_STATE_RESET state,
   thus registered (user) MspInit/DeInit callbacks can be used during the Init/DeInit.
  [..]

   Then, the user first registers the MspInit/MspDeInit user callbacks
   using HAL_COMP_RegisterCallback() before calling HAL_COMP_DeInit()
   or HAL_COMP_Init() function.
   [..]

   When the compilation flag USE_HAL_COMP_REGISTER_CALLBACKS is set to 0 or
   not defined, the callback registration feature is not available and all callbacks
   are set to the corresponding weak functions.

Table 1. COMP inputs and output for STM32H7xx devices +------------------------------------------------------—+

COMP1 COMP2
IO1 PB0 PE9
Input plus IO2 PB2 PE11

|-------------—|-------------—|--------------------—| | | 1/4 VrefInt | Available | Available | | | 1/2 VrefInt | Available | Available | | | 3/4 VrefInt | Available | Available | | Input minus | VrefInt | Available | Available | | | DAC1 channel 1 | Available | Available | | | DAC1 channel 2 | Available | Available | | | IO1 | PB1 | PE10 |

IO2 PC4 PE7

+------------------------------------------------------—+ | Output | | PC5 (1) | PE8 (1) | | | | PE12 (1) | PE13 (1) | | | | TIM (2) | TIM (2) | +------------------------------------------------------—+ (1) GPIO must be set to alternate function for comparator (2) Comparators output to timers is set in timers instances.