Prusa MINI Firmware overview
stm32f4xx_hal_adc.c File Reference

This file provides firmware functions to manage the following functionalities of the Analog to Digital Convertor (ADC) peripheral: More...

#include "stm32f4xx_hal.h"

Detailed Description

This file provides firmware functions to manage the following functionalities of the Analog to Digital Convertor (ADC) peripheral:

Author
MCD Application Team
  • Initialization and de-initialization functions
  • IO operation functions
  • State and errors functions
==============================================================================
                  ##### ADC Peripheral features #####
==============================================================================
[..]
(#) 12-bit, 10-bit, 8-bit or 6-bit configurable resolution.
(#) Interrupt generation at the end of conversion, end of injected conversion,
    and in case of analog watchdog or overrun events
(#) Single and continuous conversion modes.
(#) Scan mode for automatic conversion of channel 0 to channel x.
(#) Data alignment with in-built data coherency.
(#) Channel-wise programmable sampling time.
(#) External trigger option with configurable polarity for both regular and
    injected conversion.
(#) Dual/Triple mode (on devices with 2 ADCs or more).
(#) Configurable DMA data storage in Dual/Triple ADC mode.
(#) Configurable delay between conversions in Dual/Triple interleaved mode.
(#) ADC conversion type (refer to the datasheets).
(#) ADC supply requirements: 2.4 V to 3.6 V at full speed and down to 1.8 V at
    slower speed.
(#) ADC input range: VREF(minus) = VIN = VREF(plus).
(#) DMA request generation during regular channel conversion.


                   ##### How to use this driver #####
==============================================================================
[..]
(#)Initialize the ADC low level resources by implementing the HAL_ADC_MspInit():
     (##) Enable the ADC interface clock using __HAL_RCC_ADC_CLK_ENABLE()
     (##) ADC pins configuration
           (+++) Enable the clock for the ADC GPIOs using the following function:
                 __HAL_RCC_GPIOx_CLK_ENABLE()
           (+++) Configure these ADC pins in analog mode using HAL_GPIO_Init()
     (##) In case of using interrupts (e.g. HAL_ADC_Start_IT())
           (+++) Configure the ADC interrupt priority using HAL_NVIC_SetPriority()
           (+++) Enable the ADC IRQ handler using HAL_NVIC_EnableIRQ()
           (+++) In ADC IRQ handler, call HAL_ADC_IRQHandler()
     (##) In case of using DMA to control data transfer (e.g. HAL_ADC_Start_DMA())
           (+++) Enable the DMAx interface clock using __HAL_RCC_DMAx_CLK_ENABLE()
           (+++) Configure and enable two DMA streams stream for managing data
               transfer from peripheral to memory (output stream)
           (+++) Associate the initialized DMA handle to the CRYP DMA handle
               using  __HAL_LINKDMA()
           (+++) Configure the priority and enable the NVIC for the transfer complete
               interrupt on the two DMA Streams. The output stream should have higher
               priority than the input stream.

  *** Configuration of ADC, groups regular/injected, channels parameters ***
==============================================================================
[..]
(#) Configure the ADC parameters (resolution, data alignment, ...)
    and regular group parameters (conversion trigger, sequencer, ...)
    using function HAL_ADC_Init().

(#) Configure the channels for regular group parameters (channel number,
    channel rank into sequencer, ..., into regular group)
    using function HAL_ADC_ConfigChannel().

(#) Optionally, configure the injected group parameters (conversion trigger,
    sequencer, ..., of injected group)
    and the channels for injected group parameters (channel number,
    channel rank into sequencer, ..., into injected group)
    using function HAL_ADCEx_InjectedConfigChannel().

(#) Optionally, configure the analog watchdog parameters (channels
    monitored, thresholds, ...) using function HAL_ADC_AnalogWDGConfig().

(#) Optionally, for devices with several ADC instances: configure the
    multimode parameters using function HAL_ADCEx_MultiModeConfigChannel().

                     *** Execution of ADC conversions ***
==============================================================================
[..]
(#) ADC driver can be used among three modes: polling, interruption,
    transfer by DMA.

   *** Polling mode IO operation ***
   =================================
   [..]
     (+) Start the ADC peripheral using HAL_ADC_Start()
     (+) Wait for end of conversion using HAL_ADC_PollForConversion(), at this stage
         user can specify the value of timeout according to his end application
     (+) To read the ADC converted values, use the HAL_ADC_GetValue() function.
     (+) Stop the ADC peripheral using HAL_ADC_Stop()

   *** Interrupt mode IO operation ***
   ===================================
   [..]
     (+) Start the ADC peripheral using HAL_ADC_Start_IT()
     (+) Use HAL_ADC_IRQHandler() called under ADC_IRQHandler() Interrupt subroutine
     (+) At ADC end of conversion HAL_ADC_ConvCpltCallback() function is executed and user can
         add his own code by customization of function pointer HAL_ADC_ConvCpltCallback
     (+) In case of ADC Error, HAL_ADC_ErrorCallback() function is executed and user can
         add his own code by customization of function pointer HAL_ADC_ErrorCallback
     (+) Stop the ADC peripheral using HAL_ADC_Stop_IT()

   *** DMA mode IO operation ***
   ==============================
   [..]
     (+) Start the ADC peripheral using HAL_ADC_Start_DMA(), at this stage the user specify the length
         of data to be transferred at each end of conversion
     (+) At The end of data transfer by HAL_ADC_ConvCpltCallback() function is executed and user can
         add his own code by customization of function pointer HAL_ADC_ConvCpltCallback
     (+) In case of transfer Error, HAL_ADC_ErrorCallback() function is executed and user can
         add his own code by customization of function pointer HAL_ADC_ErrorCallback
     (+) Stop the ADC peripheral using HAL_ADC_Stop_DMA()

   *** ADC HAL driver macros list ***
   =============================================
   [..]
     Below the list of most used macros in ADC HAL driver.

    (+) __HAL_ADC_ENABLE : Enable the ADC peripheral
    (+) __HAL_ADC_DISABLE : Disable the ADC peripheral
    (+) __HAL_ADC_ENABLE_IT: Enable the ADC end of conversion interrupt
    (+) __HAL_ADC_DISABLE_IT: Disable the ADC end of conversion interrupt
    (+) __HAL_ADC_GET_IT_SOURCE: Check if the specified ADC interrupt source is enabled or disabled
    (+) __HAL_ADC_CLEAR_FLAG: Clear the ADC's pending flags
    (+) __HAL_ADC_GET_FLAG: Get the selected ADC's flag status
    (+) ADC_GET_RESOLUTION: Return resolution bits in CR1 register

   [..]
     (@) You can refer to the ADC HAL driver header file for more useful macros

                    *** Deinitialization of ADC ***
==============================================================================
[..]
(#) Disable the ADC interface
   (++) ADC clock can be hard reset and disabled at RCC top level.
   (++) Hard reset of ADC peripherals
        using macro __HAL_RCC_ADC_FORCE_RESET(), __HAL_RCC_ADC_RELEASE_RESET().
   (++) ADC clock disable using the equivalent macro/functions as configuration step.
             (+++) Example:
                 Into HAL_ADC_MspDeInit() (recommended code location) or with
                 other device clock parameters configuration:
             (+++) HAL_RCC_GetOscConfig(&RCC_OscInitStructure);
             (+++) RCC_OscInitStructure.OscillatorType = RCC_OSCILLATORTYPE_HSI;
             (+++) RCC_OscInitStructure.HSIState = RCC_HSI_OFF; (if not used for system clock)
             (+++) HAL_RCC_OscConfig(&RCC_OscInitStructure);

(#) ADC pins configuration
   (++) Disable the clock for the ADC GPIOs using macro __HAL_RCC_GPIOx_CLK_DISABLE()

(#) Optionally, in case of usage of ADC with interruptions:
   (++) Disable the NVIC for ADC using function HAL_NVIC_DisableIRQ(ADCx_IRQn)

(#) Optionally, in case of usage of DMA:
      (++) Deinitialize the DMA using function HAL_DMA_DeInit().
      (++) Disable the NVIC for DMA using function HAL_NVIC_DisableIRQ(DMAx_Channelx_IRQn)
Attention

© COPYRIGHT(c) 2017 STMicroelectronics

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  3. Neither the name of STMicroelectronics nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.