2011-12-12 02:04:53 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* arch/arm/src/stm32/stm32_adc.c
|
|
|
|
*
|
2018-11-12 16:45:55 +01:00
|
|
|
* Copyright (C) 2018 Gregory Nutt. All rights reserved.
|
2015-11-05 16:09:37 +01:00
|
|
|
* Copyright (C) 2015 Omni Hoverboards Inc. All rights reserved.
|
|
|
|
* Authors: Gregory Nutt <gnutt@nuttx.org>
|
|
|
|
* Diego Sanchez <dsanchez@nx-engineering.com>
|
|
|
|
* Paul Alexander Patience <paul-a.patience@polymtl.ca>
|
2018-11-12 16:45:55 +01:00
|
|
|
* Mateusz Szafoni <raiden00@railab.me>
|
2012-03-10 01:02:11 +01:00
|
|
|
*
|
2011-12-12 02:04:53 +01:00
|
|
|
* 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 NuttX 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 OWNER 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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2012-03-10 01:02:11 +01:00
|
|
|
|
2011-12-12 02:04:53 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
2012-03-10 01:02:11 +01:00
|
|
|
|
2011-12-12 02:04:53 +01:00
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
2011-12-17 01:21:10 +01:00
|
|
|
#include <unistd.h>
|
2011-12-16 01:32:11 +01:00
|
|
|
#include <string.h>
|
2011-12-12 02:04:53 +01:00
|
|
|
#include <errno.h>
|
2011-12-15 02:18:49 +01:00
|
|
|
#include <assert.h>
|
2011-12-12 02:04:53 +01:00
|
|
|
#include <debug.h>
|
2011-12-20 01:30:12 +01:00
|
|
|
#include <unistd.h>
|
2011-12-12 02:04:53 +01:00
|
|
|
|
|
|
|
#include <arch/board/board.h>
|
2016-02-14 02:11:09 +01:00
|
|
|
#include <nuttx/irq.h>
|
2011-12-12 02:04:53 +01:00
|
|
|
#include <nuttx/arch.h>
|
|
|
|
#include <nuttx/analog/adc.h>
|
2017-02-25 22:54:10 +01:00
|
|
|
#include <nuttx/analog/ioctl.h>
|
2020-02-01 08:17:32 +01:00
|
|
|
#include <nuttx/semaphore.h>
|
2011-12-12 02:04:53 +01:00
|
|
|
|
2020-05-01 03:20:29 +02:00
|
|
|
#include "arm_internal.h"
|
|
|
|
#include "arm_arch.h"
|
2011-12-12 02:04:53 +01:00
|
|
|
|
|
|
|
#include "chip.h"
|
2013-02-09 16:03:49 +01:00
|
|
|
#include "stm32.h"
|
2015-07-30 16:47:45 +02:00
|
|
|
#include "stm32_dma.h"
|
2011-12-12 02:04:53 +01:00
|
|
|
#include "stm32_adc.h"
|
|
|
|
|
2018-11-24 00:33:45 +01:00
|
|
|
/* The STM32 ADC lower-half driver functionality overview:
|
|
|
|
* - one lower-half driver for all STM32 ADC IP cores,
|
|
|
|
* - general lower-half logic for the Nuttx upper-half ADC driver,
|
2020-04-03 01:10:26 +02:00
|
|
|
* - lower-half ADC driver can be used not only with the upper-half ADC
|
|
|
|
* driver, but also in the lower-half logic for special-case custom
|
|
|
|
* drivers (eg. power-control, custom sensors),
|
2018-11-24 00:33:45 +01:00
|
|
|
* - ADC can be used in time-critical operations (eg. control loop for
|
2020-04-03 01:10:26 +02:00
|
|
|
* converters or motor drivers) therefore it is necessary to support the
|
|
|
|
* high performance, zero latency ADC interrupts,
|
2018-11-24 00:33:45 +01:00
|
|
|
* - ADC triggering from different sources (EXTSEL and JEXTSEL),
|
|
|
|
* - regular sequence conversion (supported in upper-half ADC driver)
|
|
|
|
* - injected sequence conversion (not supported in upper-half ADC driver)
|
|
|
|
*/
|
|
|
|
|
2018-12-09 17:31:57 +01:00
|
|
|
/* STM32 ADC "lower-half" support must be enabled */
|
2013-02-10 20:07:13 +01:00
|
|
|
|
2016-05-27 14:46:33 +02:00
|
|
|
#ifdef CONFIG_STM32_ADC
|
2013-02-10 20:07:13 +01:00
|
|
|
|
|
|
|
/* Some ADC peripheral must be enabled */
|
|
|
|
|
2015-07-29 16:34:27 +02:00
|
|
|
#if defined(CONFIG_STM32_ADC1) || defined(CONFIG_STM32_ADC2) || \
|
2015-11-05 16:09:37 +01:00
|
|
|
defined(CONFIG_STM32_ADC3) || defined(CONFIG_STM32_ADC4)
|
2011-12-12 02:04:53 +01:00
|
|
|
|
2020-04-13 10:08:03 +02:00
|
|
|
/* This implementation is for the STM32 ADC IP version 1 and 2 */
|
2013-02-10 20:07:13 +01:00
|
|
|
|
2018-11-12 16:45:55 +01:00
|
|
|
#if !defined(HAVE_IP_ADC_V1) && !defined(HAVE_IP_ADC_V2)
|
|
|
|
# error "STM32 ADC IP version not specified"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* At this moment only support for the STM32 ADC IPv2 looks fully functional:
|
|
|
|
* - noDMA
|
|
|
|
* - DMA
|
|
|
|
* - TIM trg
|
|
|
|
* - TIM trg + DMA
|
|
|
|
*
|
|
|
|
* Support for the STM32 ADC IPv1 works fine only for:
|
|
|
|
* - noDMA (but only with 1 sample)
|
|
|
|
* - TIM trg
|
|
|
|
* - TIM trg + DMA
|
|
|
|
*
|
|
|
|
* (tested with ADC example app from Nuttx apps repo).
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_IP_ADC_V1
|
|
|
|
# if defined(ADC_HAVE_DMA) && !defined(ADC_HAVE_TIMER)
|
|
|
|
# warning "ADC DMA mode without hardware trigger may not work properly!"
|
|
|
|
# elif !defined(ADC_HAVE_DMA) && !defined(ADC_HAVE_TIMER)
|
|
|
|
# warning "ADC without hardware trigger and without DMA may not work properly!"
|
|
|
|
# endif
|
|
|
|
#endif
|
2015-07-29 16:34:27 +02:00
|
|
|
|
|
|
|
/* At the moment there is no proper implementation for timers external
|
2018-12-20 17:56:42 +01:00
|
|
|
* trigger in STM32L15XX may be added later
|
2015-07-29 16:34:27 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#if defined(ADC_HAVE_TIMER) && defined(CONFIG_STM32_STM32L15XX)
|
|
|
|
# warning "There is no proper implementation for TIMER TRIGGERS at the moment"
|
|
|
|
#endif
|
2013-02-10 20:07:13 +01:00
|
|
|
|
2020-04-03 01:10:26 +02:00
|
|
|
/* If ADC use HSI as clock-source and HSI is not used for PLL and system
|
|
|
|
* clock, then we can control it directly from ADC driver.
|
2018-11-12 16:45:55 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#if defined(HAVE_ADC_CLOCK_HSI) && \
|
|
|
|
(STM32_CFGR_PLLSRC != 0 || STM32_SYSCLK_SW != RCC_CFGR_SW_HSI)
|
2018-11-24 00:33:45 +01:00
|
|
|
# define HAVE_HSI_CONTROL
|
2018-11-12 16:45:55 +01:00
|
|
|
#endif
|
|
|
|
|
2011-12-12 02:04:53 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
2020-01-03 15:34:44 +01:00
|
|
|
|
2015-11-05 16:09:37 +01:00
|
|
|
/* RCC reset ****************************************************************/
|
|
|
|
|
2018-11-12 16:45:55 +01:00
|
|
|
#if defined(HAVE_IP_ADC_V1)
|
|
|
|
# ifdef HAVE_BASIC_ADC
|
2018-11-24 00:33:45 +01:00
|
|
|
# define STM32_RCC_RSTR STM32_RCC_APB2RSTR
|
|
|
|
# define RCC_RSTR_ADC1RST RCC_APB2RSTR_ADC1RST
|
|
|
|
# define RCC_RSTR_ADC2RST RCC_APB2RSTR_ADC2RST
|
|
|
|
# define RCC_RSTR_ADC3RST RCC_APB2RSTR_ADC3RST
|
2018-11-12 16:45:55 +01:00
|
|
|
# else
|
2018-11-24 00:33:45 +01:00
|
|
|
# define STM32_RCC_RSTR STM32_RCC_APB2RSTR
|
|
|
|
# define RCC_RSTR_ADC123RST RCC_APB2RSTR_ADCRST
|
2018-11-12 16:45:55 +01:00
|
|
|
# endif
|
|
|
|
#elif defined(HAVE_IP_ADC_V2)
|
2018-11-24 00:33:45 +01:00
|
|
|
# define STM32_RCC_RSTR STM32_RCC_AHBRSTR
|
|
|
|
# define RCC_RSTR_ADC12RST RCC_AHBRSTR_ADC12RST
|
|
|
|
# define RCC_RSTR_ADC34RST RCC_AHBRSTR_ADC34RST
|
2015-11-05 16:09:37 +01:00
|
|
|
#endif
|
|
|
|
|
2020-04-03 01:10:26 +02:00
|
|
|
/* ADC Channels/DMA *********************************************************/
|
2020-01-03 15:34:44 +01:00
|
|
|
|
2015-07-30 16:47:45 +02:00
|
|
|
/* The maximum number of channels that can be sampled. If DMA support is
|
2011-12-22 22:55:54 +01:00
|
|
|
* not enabled, then only a single channel can be sampled. Otherwise,
|
|
|
|
* data overruns would occur.
|
|
|
|
*/
|
2011-12-15 01:29:35 +01:00
|
|
|
|
2015-07-30 16:47:45 +02:00
|
|
|
#define ADC_MAX_CHANNELS_DMA 16
|
|
|
|
#define ADC_MAX_CHANNELS_NODMA 1
|
|
|
|
|
2015-09-08 16:18:01 +02:00
|
|
|
#ifdef ADC_HAVE_DMA
|
|
|
|
# define ADC_MAX_SAMPLES ADC_MAX_CHANNELS_DMA
|
|
|
|
#else
|
2018-11-24 00:33:45 +01:00
|
|
|
# if defined(CONFIG_STM32_STM32F30XX) || defined(CONFIG_STM32_STM32F33XX)
|
2016-10-25 22:14:10 +02:00
|
|
|
# define ADC_MAX_SAMPLES ADC_MAX_CHANNELS_DMA /* Works without DMA should sampling frequency be reduced */
|
2018-08-16 16:03:25 +02:00
|
|
|
# elif defined(CONFIG_STM32_STM32L15XX)
|
|
|
|
# define ADC_MAX_SAMPLES ADC_MAX_CHANNELS_DMA /* Works without DMA as IO_START_CONV can switch channels on the fly */
|
2016-10-25 22:14:10 +02:00
|
|
|
# else
|
|
|
|
# define ADC_MAX_SAMPLES ADC_MAX_CHANNELS_NODMA
|
|
|
|
# endif
|
2015-09-08 16:18:01 +02:00
|
|
|
#endif
|
|
|
|
|
2020-04-13 10:08:03 +02:00
|
|
|
/* DMA values differs according to STM32 DMA IP core version */
|
2018-11-12 16:45:55 +01:00
|
|
|
|
|
|
|
#if defined(HAVE_IP_DMA_V2)
|
2015-12-22 06:08:48 +01:00
|
|
|
# define ADC_DMA_CONTROL_WORD (DMA_SCR_MSIZE_16BITS | \
|
|
|
|
DMA_SCR_PSIZE_16BITS | \
|
|
|
|
DMA_SCR_MINC | \
|
|
|
|
DMA_SCR_CIRC | \
|
|
|
|
DMA_SCR_DIR_P2M)
|
2018-11-12 16:45:55 +01:00
|
|
|
#elif defined(HAVE_IP_DMA_V1)
|
2015-12-22 06:08:48 +01:00
|
|
|
# define ADC_DMA_CONTROL_WORD (DMA_CCR_MSIZE_16BITS | \
|
|
|
|
DMA_CCR_PSIZE_16BITS | \
|
|
|
|
DMA_CCR_MINC | \
|
|
|
|
DMA_CCR_CIRC)
|
|
|
|
#endif
|
|
|
|
|
2018-11-12 16:45:55 +01:00
|
|
|
/* Sample time default configuration
|
|
|
|
*
|
2018-11-24 00:33:45 +01:00
|
|
|
* REVISIT: simplify this, use adc_sampletime_write() function.
|
2018-11-12 16:45:55 +01:00
|
|
|
* REVISIT: default SMPR configurable from Kconfig
|
|
|
|
*/
|
2011-12-15 01:29:35 +01:00
|
|
|
|
2015-11-05 16:09:37 +01:00
|
|
|
#if defined(CONFIG_STM32_STM32F10XX)
|
|
|
|
# define ADC_SMPR_DEFAULT ADC_SMPR_55p5
|
|
|
|
# define ADC_SMPR1_DEFAULT ((ADC_SMPR_DEFAULT << ADC_SMPR1_SMP10_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR1_SMP11_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR1_SMP12_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR1_SMP13_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR1_SMP14_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR1_SMP15_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR1_SMP16_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR1_SMP17_SHIFT))
|
|
|
|
# define ADC_SMPR2_DEFAULT ((ADC_SMPR_DEFAULT << ADC_SMPR2_SMP0_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR2_SMP1_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR2_SMP2_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR2_SMP3_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR2_SMP4_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR2_SMP5_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR2_SMP6_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR2_SMP7_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR2_SMP8_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR2_SMP9_SHIFT))
|
2018-11-24 00:33:45 +01:00
|
|
|
#elif defined(CONFIG_STM32_STM32F30XX) || defined(CONFIG_STM32_STM32F33XX)
|
2016-11-04 13:59:28 +01:00
|
|
|
# if defined(ADC_HAVE_DMA) || (ADC_MAX_SAMPLES == 1)
|
2016-10-25 22:14:10 +02:00
|
|
|
# define ADC_SMPR_DEFAULT ADC_SMPR_61p5
|
|
|
|
# else /* Slow down sampling frequency */
|
|
|
|
# define ADC_SMPR_DEFAULT ADC_SMPR_601p5
|
|
|
|
# endif
|
2015-11-05 16:09:37 +01:00
|
|
|
# define ADC_SMPR1_DEFAULT ((ADC_SMPR_DEFAULT << ADC_SMPR1_SMP1_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR1_SMP2_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR1_SMP3_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR1_SMP4_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR1_SMP5_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR1_SMP6_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR1_SMP7_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR1_SMP8_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR1_SMP9_SHIFT))
|
|
|
|
# define ADC_SMPR2_DEFAULT ((ADC_SMPR_DEFAULT << ADC_SMPR2_SMP10_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR2_SMP11_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR2_SMP12_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR2_SMP13_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR2_SMP14_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR2_SMP15_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR2_SMP16_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR2_SMP17_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR2_SMP18_SHIFT))
|
2016-10-25 22:14:10 +02:00
|
|
|
#elif defined(CONFIG_STM32_STM32F20XX) || defined(CONFIG_STM32_STM32F37XX) || \
|
2017-07-06 18:20:14 +02:00
|
|
|
defined(CONFIG_STM32_STM32F4XXX)
|
2016-10-25 22:14:10 +02:00
|
|
|
# if defined(CONFIG_STM32_STM32F37XX)
|
|
|
|
# define ADC_SMPR_DEFAULT ADC_SMPR_239p5 /* TODO choose 1p5? */
|
|
|
|
# else
|
|
|
|
# define ADC_SMPR_DEFAULT ADC_SMPR_112
|
|
|
|
# endif
|
2015-11-05 16:09:37 +01:00
|
|
|
# define ADC_SMPR1_DEFAULT ((ADC_SMPR_DEFAULT << ADC_SMPR1_SMP10_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR1_SMP11_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR1_SMP12_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR1_SMP13_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR1_SMP14_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR1_SMP15_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR1_SMP16_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR1_SMP17_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR1_SMP18_SHIFT))
|
|
|
|
# define ADC_SMPR2_DEFAULT ((ADC_SMPR_DEFAULT << ADC_SMPR2_SMP0_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR2_SMP1_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR2_SMP2_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR2_SMP3_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR2_SMP4_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR2_SMP5_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR2_SMP6_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR2_SMP7_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR2_SMP8_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR2_SMP9_SHIFT))
|
|
|
|
#elif defined(CONFIG_STM32_STM32L15XX)
|
|
|
|
# define ADC_SMPR_DEFAULT ADC_SMPR_384
|
2018-11-12 16:45:55 +01:00
|
|
|
# define ADC_SMPR1_DEFAULT ((ADC_SMPR_DEFAULT << ADC_SMPR1_SMP20_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR1_SMP21_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR1_SMP22_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR1_SMP23_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR1_SMP24_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR1_SMP25_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR1_SMP26_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR1_SMP27_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR1_SMP28_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR1_SMP29_SHIFT))
|
|
|
|
# define ADC_SMPR2_DEFAULT ((ADC_SMPR_DEFAULT << ADC_SMPR2_SMP10_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR2_SMP11_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR2_SMP12_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR2_SMP13_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR2_SMP14_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR2_SMP15_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR2_SMP16_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR2_SMP17_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR2_SMP18_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR2_SMP19_SHIFT))
|
|
|
|
# define ADC_SMPR3_DEFAULT ((ADC_SMPR_DEFAULT << ADC_SMPR3_SMP0_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR3_SMP1_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR3_SMP2_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR3_SMP3_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR3_SMP4_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR3_SMP5_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR3_SMP6_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR3_SMP7_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR3_SMP8_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR3_SMP9_SHIFT))
|
|
|
|
# define ADC_SMPR0_DEFAULT ((ADC_SMPR_DEFAULT << ADC_SMPR0_SMP30_SHIFT) | \
|
|
|
|
(ADC_SMPR_DEFAULT << ADC_SMPR0_SMP31_SHIFT))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Number of channels per ADC:
|
2020-02-23 09:50:23 +01:00
|
|
|
* - F0, L0 - 19, but single SMP for all channels
|
2018-11-12 16:45:55 +01:00
|
|
|
* - F1 - 18
|
|
|
|
* - F2,F3,F4,F7,L4,L4+ - 19
|
|
|
|
* - H7 - 20
|
|
|
|
* - L1 - 32
|
|
|
|
*
|
2020-04-03 01:10:26 +02:00
|
|
|
* NOTE: this value can be obtained from SMPRx register description
|
|
|
|
* (ST manual)
|
2018-11-12 16:45:55 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#if defined(CONFIG_STM32_STM32F10XX)
|
|
|
|
# define ADC_CHANNELS_NUMBER 18
|
|
|
|
#elif defined(CONFIG_STM32_STM32F20XX) || defined(CONFIG_STM32_STM32F30XX) || \
|
|
|
|
defined(CONFIG_STM32_STM32F33XX) || defined(CONFIG_STM32_STM32F4XXX)
|
|
|
|
# define ADC_CHANNELS_NUMBER 19
|
|
|
|
#elif defined(CONFIG_STM32_STM32L15XX)
|
|
|
|
# define ADC_CHANNELS_NUMBER 32
|
|
|
|
#else
|
|
|
|
# error "Not supported"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* ADC resolution. Not supported for basic STM32 ADC IPv1 */
|
|
|
|
|
|
|
|
#ifndef CONFIG_STM32_HAVE_IP_ADC_V1_BASIC
|
|
|
|
# define HAVE_ADC_RESOLUTION
|
|
|
|
#else
|
|
|
|
# undef HAVE_ADC_RESOLUTION
|
|
|
|
#endif
|
|
|
|
|
2018-11-24 00:33:45 +01:00
|
|
|
/* ADC have common registers for all cores except basic ADC IPv1 (F1, F37x) */
|
2018-11-12 16:45:55 +01:00
|
|
|
|
2018-11-24 00:33:45 +01:00
|
|
|
#ifdef CONFIG_STM32_HAVE_IP_ADC_V1_BASIC
|
2018-11-12 16:45:55 +01:00
|
|
|
# undef HAVE_ADC_CMN_REGS
|
|
|
|
#else
|
|
|
|
# define HAVE_ADC_CMN_REGS
|
2015-07-29 16:34:27 +02:00
|
|
|
#endif
|
2018-11-24 00:33:45 +01:00
|
|
|
#if defined(HAVE_ADC_CMN_REGS) && STM32_NADC > 1
|
|
|
|
# define HAVE_ADC_CMN_DATA
|
|
|
|
#else
|
|
|
|
# undef HAVE_ADC_CMN_DATA
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* ADCx_EXTSEL_VALUE can be set by this driver (look at stm32_adc.h) or
|
|
|
|
* by board specific logic in board.h file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef ADC1_EXTSEL_VALUE
|
|
|
|
# define ADC1_HAVE_EXTCFG 1
|
|
|
|
# define ADC1_EXTCFG_VALUE (ADC1_EXTSEL_VALUE | ADC_EXTREG_EXTEN_DEFAULT)
|
|
|
|
#else
|
|
|
|
# undef ADC1_HAVE_EXTCFG
|
|
|
|
#endif
|
|
|
|
#ifdef ADC2_EXTSEL_VALUE
|
|
|
|
# define ADC2_HAVE_EXTCFG 1
|
|
|
|
# define ADC2_EXTCFG_VALUE (ADC2_EXTSEL_VALUE | ADC_EXTREG_EXTEN_DEFAULT)
|
|
|
|
#else
|
|
|
|
# undef ADC2_HAVE_EXTCFG
|
|
|
|
#endif
|
|
|
|
#ifdef ADC3_EXTSEL_VALUE
|
|
|
|
# define ADC3_HAVE_EXTCFG 1
|
|
|
|
# define ADC3_EXTCFG_VALUE (ADC3_EXTSEL_VALUE | ADC_EXTREG_EXTEN_DEFAULT)
|
|
|
|
#else
|
|
|
|
# undef ADC3_HAVE_EXTCFG
|
|
|
|
#endif
|
|
|
|
#ifdef ADC4_EXTSEL_VALUE
|
|
|
|
# define ADC4_HAVE_EXTCFG 1
|
|
|
|
# define ADC4_EXTCFG_VALUE (ADC4_EXTSEL_VALUE | ADC_EXTREG_EXTEN_DEFAULT)
|
|
|
|
#else
|
|
|
|
# undef ADC4_HAVE_EXTCFG
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(ADC1_HAVE_EXTCFG) || defined(ADC2_HAVE_EXTCFG) || \
|
|
|
|
defined(ADC3_HAVE_EXTCFG) || defined(ADC3_HAVE_EXTCFG)
|
|
|
|
# define ADC_HAVE_EXTCFG
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Injected channels external trigger support */
|
|
|
|
|
|
|
|
#ifdef ADC1_JEXTSEL_VALUE
|
|
|
|
# define ADC1_HAVE_JEXTCFG 1
|
|
|
|
# define ADC1_JEXTCFG_VALUE (ADC1_JEXTSEL_VALUE | ADC_JEXTREG_JEXTEN_DEFAULT)
|
|
|
|
#endif
|
|
|
|
#ifdef ADC2_JEXTSEL_VALUE
|
|
|
|
# define ADC2_HAVE_JEXTCFG 1
|
|
|
|
# define ADC2_JEXTCFG_VALUE (ADC2_JEXTSEL_VALUE | ADC_JEXTREG_JEXTEN_DEFAULT)
|
|
|
|
#endif
|
|
|
|
#ifdef ADC3_JEXTSEL_VALUE
|
|
|
|
# define ADC3_HAVE_JEXTCFG 1
|
|
|
|
# define ADC3_JEXTCFG_VALUE (ADC3_JEXTSEL_VALUE | ADC_JEXTREG_JEXTEN_DEFAULT)
|
|
|
|
#endif
|
|
|
|
#ifdef ADC4_JEXTSEL_VALUE
|
|
|
|
# define ADC4_HAVE_JEXTCFG 1
|
|
|
|
# define ADC4_JEXTCFG_VALUE (ADC4_JEXTSEL_VALUE | ADC_JEXTREG_JEXTEN_DEFAULT)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(ADC1_HAVE_JEXTCFG) || defined(ADC2_HAVE_JEXTCFG) || \
|
|
|
|
defined(ADC3_HAVE_JEXTCFG) || defined(ADC4_HAVE_JEXTCFG)
|
|
|
|
# define ADC_HAVE_JEXTCFG
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Max 4 injected channels */
|
|
|
|
|
|
|
|
#define ADC_INJ_MAX_SAMPLES 4
|
2015-07-29 16:34:27 +02:00
|
|
|
|
2018-12-02 02:24:36 +01:00
|
|
|
/* ADC DMA configuration bit support */
|
|
|
|
|
|
|
|
#ifndef CONFIG_STM32_HAVE_IP_ADC_V1_BASIC
|
|
|
|
# define ADC_HAVE_DMACFG 1
|
|
|
|
#else
|
|
|
|
# undef ADC_HAVE_DMACFG
|
|
|
|
#endif
|
|
|
|
|
2020-04-21 21:35:54 +02:00
|
|
|
/* We have to support ADC callbacks if default ADC interrupts or
|
|
|
|
* DMA transfer are enabled
|
|
|
|
*/
|
|
|
|
|
|
|
|
#if !defined(CONFIG_STM32_ADC_NOIRQ) || defined(ADC_HAVE_DMA)
|
|
|
|
# define ADC_HAVE_CB
|
|
|
|
#else
|
|
|
|
# undef ADC_HAVE_CB
|
|
|
|
#endif
|
|
|
|
|
2011-12-12 02:04:53 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Types
|
|
|
|
****************************************************************************/
|
2012-03-10 01:02:11 +01:00
|
|
|
|
2018-11-24 00:33:45 +01:00
|
|
|
/* Data common to all ADC instances */
|
|
|
|
|
|
|
|
#ifdef HAVE_ADC_CMN_DATA
|
|
|
|
struct adccmn_data_s
|
|
|
|
{
|
|
|
|
uint8_t initialized; /* How many ADC instances are currently in use */
|
|
|
|
sem_t lock; /* Exclusive access to common ADC data */
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2018-11-12 16:45:55 +01:00
|
|
|
/* This structure describes the state of one ADC block
|
|
|
|
* REVISIT: save some space with bit fields.
|
|
|
|
*/
|
2011-12-14 01:34:12 +01:00
|
|
|
|
2011-12-12 02:04:53 +01:00
|
|
|
struct stm32_dev_s
|
|
|
|
{
|
2018-11-24 00:33:45 +01:00
|
|
|
#ifdef CONFIG_STM32_ADC_LL_OPS
|
|
|
|
FAR const struct stm32_adc_ops_s *llops; /* Low-level ADC ops */
|
|
|
|
#endif
|
2020-04-21 21:35:54 +02:00
|
|
|
#ifdef ADC_HAVE_CB
|
2016-05-26 20:25:54 +02:00
|
|
|
FAR const struct adc_callback_s *cb;
|
2018-11-24 00:33:45 +01:00
|
|
|
uint8_t irq; /* Interrupt generated by this ADC block */
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_ADC_CMN_DATA
|
|
|
|
struct adccmn_data_s *cmn; /* Common ADC data */
|
|
|
|
#endif
|
|
|
|
uint8_t rnchannels; /* Number of regular channels */
|
|
|
|
uint8_t cr_channels; /* Number of configured regular channels */
|
|
|
|
#ifdef ADC_HAVE_INJECTED
|
|
|
|
uint8_t cj_channels; /* Number of configured injected channels */
|
|
|
|
#endif
|
|
|
|
uint8_t intf; /* ADC interface number */
|
|
|
|
uint8_t current; /* Current ADC channel being converted */
|
2018-11-12 16:45:55 +01:00
|
|
|
#ifdef HAVE_ADC_RESOLUTION
|
2018-11-24 00:33:45 +01:00
|
|
|
uint8_t resolution; /* ADC resolution (0-3) */
|
2018-11-12 16:45:55 +01:00
|
|
|
#endif
|
2015-07-30 16:47:45 +02:00
|
|
|
#ifdef ADC_HAVE_DMA
|
2018-11-24 00:33:45 +01:00
|
|
|
uint8_t dmachan; /* DMA channel needed by this ADC */
|
2018-12-02 02:24:36 +01:00
|
|
|
# ifdef ADC_HAVE_DMACFG
|
2018-11-24 00:33:45 +01:00
|
|
|
uint8_t dmacfg; /* DMA channel configuration, only for ADC IPv2 */
|
2018-12-02 02:24:36 +01:00
|
|
|
# endif
|
2018-11-24 00:33:45 +01:00
|
|
|
bool hasdma; /* True: This channel supports DMA */
|
2015-07-30 16:47:45 +02:00
|
|
|
#endif
|
2018-11-12 16:45:55 +01:00
|
|
|
#ifdef CONFIG_STM32_ADC_CHANGE_SAMPLETIME
|
|
|
|
/* Sample time selection. These bits must be written only when ADON=0.
|
|
|
|
* REVISIT: this takes too much space. We need only 3 bits per channel.
|
|
|
|
*/
|
2015-07-30 16:47:45 +02:00
|
|
|
|
|
|
|
uint8_t sample_rate[ADC_CHANNELS_NUMBER];
|
2018-11-24 00:33:45 +01:00
|
|
|
uint8_t adc_channels; /* ADC channels number */
|
2015-07-29 16:34:27 +02:00
|
|
|
#endif
|
2011-12-20 01:30:12 +01:00
|
|
|
#ifdef ADC_HAVE_TIMER
|
2018-11-24 00:33:45 +01:00
|
|
|
uint8_t trigger; /* Timer trigger channel: 0=CC1, 1=CC2, 2=CC3,
|
|
|
|
* 3=CC4, 4=TRGO */
|
|
|
|
#endif
|
|
|
|
xcpt_t isr; /* Interrupt handler for this ADC block */
|
|
|
|
uint32_t base; /* Base address of registers unique to this ADC
|
|
|
|
* block */
|
|
|
|
#ifdef ADC_HAVE_EXTCFG
|
|
|
|
uint32_t extcfg; /* External event configuration for regular group */
|
|
|
|
#endif
|
|
|
|
#ifdef ADC_HAVE_JEXTCFG
|
|
|
|
uint32_t jextcfg; /* External event configuration for injected group */
|
2011-12-20 01:30:12 +01:00
|
|
|
#endif
|
2011-12-16 20:29:41 +01:00
|
|
|
#ifdef ADC_HAVE_TIMER
|
2018-11-24 00:33:45 +01:00
|
|
|
uint32_t tbase; /* Base address of timer used by this ADC block */
|
|
|
|
uint32_t pclck; /* The PCLK frequency that drives this timer */
|
|
|
|
uint32_t freq; /* The desired frequency of conversions */
|
2015-07-30 16:47:45 +02:00
|
|
|
#endif
|
|
|
|
#ifdef ADC_HAVE_DMA
|
2018-11-24 00:33:45 +01:00
|
|
|
DMA_HANDLE dma; /* Allocated DMA channel */
|
2015-07-30 16:47:45 +02:00
|
|
|
|
|
|
|
/* DMA transfer buffer */
|
|
|
|
|
2018-11-24 00:33:45 +01:00
|
|
|
uint16_t r_dmabuffer[ADC_MAX_SAMPLES];
|
2015-07-30 16:47:45 +02:00
|
|
|
#endif
|
2015-09-08 16:18:01 +02:00
|
|
|
|
|
|
|
/* List of selected ADC channels to sample */
|
|
|
|
|
2018-11-24 00:33:45 +01:00
|
|
|
uint8_t r_chanlist[ADC_MAX_SAMPLES];
|
|
|
|
|
|
|
|
#ifdef ADC_HAVE_INJECTED
|
|
|
|
/* List of selected ADC injected channels to sample */
|
|
|
|
|
|
|
|
uint8_t j_chanlist[ADC_INJ_MAX_SAMPLES];
|
|
|
|
#endif
|
2011-12-12 02:04:53 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Function Prototypes
|
|
|
|
****************************************************************************/
|
2011-12-14 01:34:12 +01:00
|
|
|
|
|
|
|
/* ADC Register access */
|
|
|
|
|
2018-11-12 16:45:55 +01:00
|
|
|
#ifndef HAVE_BASIC_ADC
|
2015-11-05 16:09:37 +01:00
|
|
|
static void stm32_modifyreg32(unsigned int addr, uint32_t clrbits,
|
|
|
|
uint32_t setbits);
|
|
|
|
#endif
|
|
|
|
static uint32_t adc_getreg(FAR struct stm32_dev_s *priv, int offset);
|
2018-11-24 00:44:46 +01:00
|
|
|
static void adc_putreg(FAR struct stm32_dev_s *priv, int offset,
|
|
|
|
uint32_t value);
|
|
|
|
static void adc_modifyreg(FAR struct stm32_dev_s *priv, int offset,
|
|
|
|
uint32_t clrbits, uint32_t setbits);
|
2018-11-24 00:33:45 +01:00
|
|
|
#ifdef HAVE_ADC_CMN_REGS
|
2018-11-12 16:45:55 +01:00
|
|
|
static uint32_t adccmn_base_get(FAR struct stm32_dev_s *priv);
|
|
|
|
static void adccmn_modifyreg(FAR struct stm32_dev_s *priv, uint32_t offset,
|
|
|
|
uint32_t clrbits, uint32_t setbits);
|
|
|
|
# ifdef CONFIG_DEBUG_ANALOG_INFO
|
|
|
|
static uint32_t adccmn_getreg(FAR struct stm32_dev_s *priv, uint32_t offset);
|
|
|
|
# endif
|
|
|
|
#endif
|
2011-12-20 01:30:12 +01:00
|
|
|
#ifdef ADC_HAVE_TIMER
|
2015-11-05 16:09:37 +01:00
|
|
|
static uint16_t tim_getreg(FAR struct stm32_dev_s *priv, int offset);
|
2018-11-24 00:44:46 +01:00
|
|
|
static void tim_putreg(FAR struct stm32_dev_s *priv, int offset,
|
|
|
|
uint16_t value);
|
|
|
|
static void tim_modifyreg(FAR struct stm32_dev_s *priv, int offset,
|
|
|
|
uint16_t clrbits, uint16_t setbits);
|
|
|
|
static void tim_dumpregs(FAR struct stm32_dev_s *priv,
|
2015-11-05 16:09:37 +01:00
|
|
|
FAR const char *msg);
|
2011-12-20 01:30:12 +01:00
|
|
|
#endif
|
2015-07-29 16:34:27 +02:00
|
|
|
|
2018-11-24 00:33:45 +01:00
|
|
|
#ifdef HAVE_ADC_CMN_DATA
|
2018-11-24 00:44:46 +01:00
|
|
|
static int adccmn_lock(FAR struct stm32_dev_s *priv, bool lock);
|
2018-11-24 00:33:45 +01:00
|
|
|
#endif
|
|
|
|
|
2015-11-05 16:09:37 +01:00
|
|
|
static void adc_rccreset(FAR struct stm32_dev_s *priv, bool reset);
|
2011-12-14 01:34:12 +01:00
|
|
|
|
2011-12-12 02:04:53 +01:00
|
|
|
/* ADC Interrupt Handler */
|
|
|
|
|
2018-11-24 00:33:45 +01:00
|
|
|
#ifndef CONFIG_STM32_ADC_NOIRQ
|
2018-11-24 00:44:46 +01:00
|
|
|
static int adc_interrupt(FAR struct adc_dev_s *dev);
|
2018-11-24 00:33:45 +01:00
|
|
|
# if defined(STM32_IRQ_ADC1) && defined(CONFIG_STM32_ADC1)
|
2018-11-24 00:44:46 +01:00
|
|
|
static int adc1_interrupt(int irq, FAR void *context, FAR void *arg);
|
2018-11-24 00:33:45 +01:00
|
|
|
# endif
|
|
|
|
# if defined(STM32_IRQ_ADC12) && (defined(CONFIG_STM32_ADC1) || \
|
2016-06-01 01:58:52 +02:00
|
|
|
defined(CONFIG_STM32_ADC2))
|
2018-11-24 00:44:46 +01:00
|
|
|
static int adc12_interrupt(int irq, FAR void *context, FAR void *arg);
|
2018-11-24 00:33:45 +01:00
|
|
|
# endif
|
|
|
|
# if (defined(STM32_IRQ_ADC3) && defined(CONFIG_STM32_ADC3))
|
2018-11-24 00:44:46 +01:00
|
|
|
static int adc3_interrupt(int irq, FAR void *context, FAR void *arg);
|
2018-11-24 00:33:45 +01:00
|
|
|
# endif
|
|
|
|
# if defined(STM32_IRQ_ADC4) && defined(CONFIG_STM32_ADC4)
|
2018-11-24 00:44:46 +01:00
|
|
|
static int adc4_interrupt(int irq, FAR void *context, FAR void *arg);
|
2018-11-24 00:33:45 +01:00
|
|
|
# endif
|
|
|
|
# if defined(STM32_IRQ_ADC)
|
2018-11-24 00:44:46 +01:00
|
|
|
static int adc123_interrupt(int irq, FAR void *context, FAR void *arg);
|
2018-11-24 00:33:45 +01:00
|
|
|
# endif
|
2020-01-31 19:07:39 +01:00
|
|
|
#endif /* CONFIG_STM32_ADC_NOIRQ */
|
2011-12-12 02:04:53 +01:00
|
|
|
|
|
|
|
/* ADC Driver Methods */
|
|
|
|
|
2016-05-26 20:25:54 +02:00
|
|
|
static int adc_bind(FAR struct adc_dev_s *dev,
|
|
|
|
FAR const struct adc_callback_s *callback);
|
2011-12-12 02:04:53 +01:00
|
|
|
static void adc_reset(FAR struct adc_dev_s *dev);
|
|
|
|
static int adc_setup(FAR struct adc_dev_s *dev);
|
|
|
|
static void adc_shutdown(FAR struct adc_dev_s *dev);
|
|
|
|
static void adc_rxint(FAR struct adc_dev_s *dev, bool enable);
|
|
|
|
static int adc_ioctl(FAR struct adc_dev_s *dev, int cmd, unsigned long arg);
|
2011-12-16 20:29:41 +01:00
|
|
|
static void adc_enable(FAR struct stm32_dev_s *priv, bool enable);
|
2015-11-05 16:09:37 +01:00
|
|
|
|
2020-04-03 01:10:26 +02:00
|
|
|
static uint32_t adc_sqrbits(FAR struct stm32_dev_s *priv, int first,
|
|
|
|
int last, int offset);
|
2018-11-24 00:44:46 +01:00
|
|
|
static int adc_set_ch(FAR struct adc_dev_s *dev, uint8_t ch);
|
2015-11-05 16:09:37 +01:00
|
|
|
|
2018-11-24 00:44:46 +01:00
|
|
|
static int adc_ioc_change_ints(FAR struct adc_dev_s *dev, int cmd,
|
2018-11-12 16:45:55 +01:00
|
|
|
bool arg);
|
|
|
|
|
|
|
|
#ifdef HAVE_ADC_RESOLUTION
|
2018-11-24 00:44:46 +01:00
|
|
|
static int adc_resolution_set(FAR struct adc_dev_s *dev, uint8_t res);
|
2018-11-12 16:45:55 +01:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_ADC_VBAT
|
|
|
|
static void adc_enable_vbat_channel(FAR struct adc_dev_s *dev, bool enable);
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_ADC_POWERDOWN
|
2018-11-24 00:44:46 +01:00
|
|
|
static int adc_ioc_change_sleep_between_opers(FAR struct adc_dev_s *dev,
|
|
|
|
int cmd, bool arg);
|
2015-11-05 16:09:37 +01:00
|
|
|
static void adc_power_down_idle(FAR struct stm32_dev_s *priv,
|
|
|
|
bool pdi_high);
|
|
|
|
static void adc_power_down_delay(FAR struct stm32_dev_s *priv,
|
|
|
|
bool pdd_high);
|
2018-11-12 16:45:55 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_STM32_STM32L15XX
|
2015-11-05 16:09:37 +01:00
|
|
|
static void adc_dels_after_conversion(FAR struct stm32_dev_s *priv,
|
|
|
|
uint32_t delay);
|
|
|
|
static void adc_select_ch_bank(FAR struct stm32_dev_s *priv,
|
|
|
|
bool chb_selected);
|
2018-11-12 16:45:55 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_HSI_CONTROL
|
2015-11-05 16:09:37 +01:00
|
|
|
static void adc_enable_hsi(bool enable);
|
|
|
|
static void adc_reset_hsi_disable(FAR struct adc_dev_s *dev);
|
|
|
|
#endif
|
2011-12-16 20:29:41 +01:00
|
|
|
|
|
|
|
#ifdef ADC_HAVE_TIMER
|
2011-12-20 01:30:12 +01:00
|
|
|
static void adc_timstart(FAR struct stm32_dev_s *priv, bool enable);
|
2011-12-16 20:29:41 +01:00
|
|
|
static int adc_timinit(FAR struct stm32_dev_s *priv);
|
|
|
|
#endif
|
2011-12-22 22:55:54 +01:00
|
|
|
|
2018-11-24 00:33:45 +01:00
|
|
|
#if defined(ADC_HAVE_DMA) && !defined(CONFIG_STM32_ADC_NOIRQ)
|
2015-11-05 16:09:37 +01:00
|
|
|
static void adc_dmaconvcallback(DMA_HANDLE handle, uint8_t isr,
|
|
|
|
FAR void *arg);
|
2011-12-22 22:55:54 +01:00
|
|
|
#endif
|
2011-12-12 02:04:53 +01:00
|
|
|
|
2018-11-24 00:33:45 +01:00
|
|
|
static void adc_reg_startconv(FAR struct stm32_dev_s *priv, bool enable);
|
|
|
|
#ifdef ADC_HAVE_INJECTED
|
|
|
|
static void adc_inj_startconv(FAR struct stm32_dev_s *priv, bool enable);
|
|
|
|
static int adc_inj_set_ch(FAR struct adc_dev_s *dev, uint8_t ch);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef ADC_HAVE_EXTCFG
|
|
|
|
static int adc_extcfg_set(FAR struct adc_dev_s *dev, uint32_t extcfg);
|
|
|
|
#endif
|
|
|
|
#ifdef ADC_HAVE_JEXTCFG
|
|
|
|
static int adc_jextcfg_set(FAR struct adc_dev_s *dev, uint32_t jextcfg);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void adc_dumpregs(FAR struct stm32_dev_s *priv);
|
|
|
|
|
|
|
|
#ifdef CONFIG_STM32_ADC_LL_OPS
|
|
|
|
static void adc_intack(FAR struct stm32_adc_dev_s *dev, uint32_t source);
|
|
|
|
static void adc_inten(FAR struct stm32_adc_dev_s *dev, uint32_t source);
|
|
|
|
static void adc_intdis(FAR struct stm32_adc_dev_s *dev, uint32_t source);
|
|
|
|
static uint32_t adc_intget(FAR struct stm32_adc_dev_s *dev);
|
|
|
|
static uint32_t adc_regget(FAR struct stm32_adc_dev_s *dev);
|
2020-04-03 01:10:26 +02:00
|
|
|
static void adc_llops_reg_startconv(FAR struct stm32_adc_dev_s *dev,
|
|
|
|
bool enable);
|
|
|
|
static int adc_offset_set(FAR struct stm32_adc_dev_s *dev, uint8_t ch,
|
|
|
|
uint8_t i, uint16_t offset);
|
2018-11-24 00:33:45 +01:00
|
|
|
# ifdef ADC_HAVE_DMA
|
2020-04-03 01:10:26 +02:00
|
|
|
static int adc_regbufregister(FAR struct stm32_adc_dev_s *dev,
|
|
|
|
uint16_t *buffer, uint8_t len);
|
2018-11-24 00:33:45 +01:00
|
|
|
# endif
|
|
|
|
# ifdef ADC_HAVE_INJECTED
|
|
|
|
static uint32_t adc_injget(FAR struct stm32_adc_dev_s *dev, uint8_t chan);
|
2020-04-03 01:10:26 +02:00
|
|
|
static void adc_llops_inj_startconv(FAR struct stm32_adc_dev_s *dev,
|
|
|
|
bool enable);
|
2018-11-24 00:33:45 +01:00
|
|
|
# endif
|
|
|
|
# ifdef CONFIG_STM32_ADC_CHANGE_SAMPLETIME
|
|
|
|
static void adc_sampletime_set(FAR struct stm32_adc_dev_s *dev,
|
|
|
|
FAR struct adc_sample_time_s *time_samples);
|
|
|
|
static void adc_sampletime_write(FAR struct stm32_adc_dev_s *dev);
|
|
|
|
# endif
|
|
|
|
static void adc_llops_dumpregs(FAR struct stm32_adc_dev_s *dev);
|
|
|
|
#endif
|
2015-11-05 16:09:37 +01:00
|
|
|
|
2011-12-12 02:04:53 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
2011-12-14 02:25:14 +01:00
|
|
|
/* ADC interface operations */
|
|
|
|
|
2011-12-12 02:04:53 +01:00
|
|
|
static const struct adc_ops_s g_adcops =
|
|
|
|
{
|
2016-05-26 20:25:54 +02:00
|
|
|
.ao_bind = adc_bind,
|
2018-11-12 16:45:55 +01:00
|
|
|
#ifdef HAVE_HSI_CONTROL
|
2015-07-29 16:34:27 +02:00
|
|
|
.ao_reset = adc_reset_hsi_disable,
|
|
|
|
#else
|
|
|
|
.ao_reset = adc_reset,
|
|
|
|
#endif
|
|
|
|
.ao_setup = adc_setup,
|
|
|
|
.ao_shutdown = adc_shutdown,
|
|
|
|
.ao_rxint = adc_rxint,
|
|
|
|
.ao_ioctl = adc_ioctl,
|
2011-12-12 02:04:53 +01:00
|
|
|
};
|
|
|
|
|
2018-11-24 00:33:45 +01:00
|
|
|
/* Publicly visible ADC lower-half operations */
|
|
|
|
|
|
|
|
#ifdef CONFIG_STM32_ADC_LL_OPS
|
|
|
|
static const struct stm32_adc_ops_s g_adc_llops =
|
|
|
|
{
|
|
|
|
.int_ack = adc_intack,
|
|
|
|
.int_get = adc_intget,
|
|
|
|
.int_en = adc_inten,
|
|
|
|
.int_dis = adc_intdis,
|
|
|
|
.val_get = adc_regget,
|
|
|
|
.reg_startconv = adc_llops_reg_startconv,
|
2019-01-27 17:17:39 +01:00
|
|
|
.offset_set = adc_offset_set,
|
2018-11-24 00:33:45 +01:00
|
|
|
# ifdef ADC_HAVE_DMA
|
|
|
|
.regbuf_reg = adc_regbufregister,
|
|
|
|
# endif
|
|
|
|
# ifdef ADC_HAVE_INJECTED
|
|
|
|
.inj_get = adc_injget,
|
|
|
|
.inj_startconv = adc_llops_inj_startconv,
|
|
|
|
# endif
|
|
|
|
# ifdef CONFIG_STM32_ADC_CHANGE_SAMPLETIME
|
|
|
|
.stime_set = adc_sampletime_set,
|
|
|
|
.stime_write = adc_sampletime_write,
|
|
|
|
# endif
|
|
|
|
.dump_regs = adc_llops_dumpregs
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* ADC instances are coupled in blocks for all IP versions except
|
|
|
|
* basic ADC IPv1 (F1, F37x).
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_ADC_CMN_DATA
|
|
|
|
# ifdef HAVE_IP_ADC_V1
|
|
|
|
# define ADC1CMN_DATA g_adc123_cmn
|
|
|
|
# define ADC2CMN_DATA g_adc123_cmn
|
|
|
|
# define ADC3CMN_DATA g_adc123_cmn
|
|
|
|
|
|
|
|
/* ADC123 common data */
|
|
|
|
|
|
|
|
struct adccmn_data_s g_adc123_cmn =
|
|
|
|
{
|
|
|
|
.initialized = 0
|
|
|
|
};
|
|
|
|
|
|
|
|
# elif defined(HAVE_IP_ADC_V2)
|
|
|
|
# define ADC1CMN_DATA g_adc12_cmn
|
|
|
|
# define ADC2CMN_DATA g_adc12_cmn
|
|
|
|
# define ADC3CMN_DATA g_adc34_cmn
|
|
|
|
# define ADC4CMN_DATA g_adc34_cmn
|
|
|
|
# if defined(CONFIG_STM32_ADC1) || defined(CONFIG_STM32_ADC2)
|
|
|
|
|
|
|
|
/* ADC12 common data */
|
|
|
|
|
|
|
|
struct adccmn_data_s g_adc12_cmn =
|
|
|
|
{
|
|
|
|
.initialized = 0
|
|
|
|
};
|
|
|
|
|
|
|
|
# endif
|
|
|
|
# if defined(CONFIG_STM32_ADC3) || defined(CONFIG_STM32_ADC4)
|
|
|
|
|
|
|
|
/* ADC34 common data */
|
|
|
|
|
|
|
|
struct adccmn_data_s g_adc34_cmn =
|
|
|
|
{
|
|
|
|
.initialized = 0
|
|
|
|
};
|
|
|
|
|
|
|
|
# endif
|
2020-01-31 19:07:39 +01:00
|
|
|
# endif /* !HAVE_IP_ADC_V1 */
|
|
|
|
#endif /* HAVE_ADC_CMN_DATA */
|
2018-11-24 00:33:45 +01:00
|
|
|
|
2011-12-14 02:25:14 +01:00
|
|
|
/* ADC1 state */
|
|
|
|
|
2011-12-12 02:04:53 +01:00
|
|
|
#ifdef CONFIG_STM32_ADC1
|
|
|
|
static struct stm32_dev_s g_adcpriv1 =
|
|
|
|
{
|
2018-11-24 00:33:45 +01:00
|
|
|
#ifdef CONFIG_STM32_ADC_LL_OPS
|
|
|
|
.llops = &g_adc_llops,
|
|
|
|
#endif
|
|
|
|
#ifndef CONFIG_STM32_ADC_NOIRQ
|
|
|
|
# if defined(STM32_IRQ_ADC1)
|
2015-07-29 16:34:27 +02:00
|
|
|
.irq = STM32_IRQ_ADC1,
|
2015-11-05 16:09:37 +01:00
|
|
|
.isr = adc1_interrupt,
|
2018-11-24 00:33:45 +01:00
|
|
|
# elif defined(STM32_IRQ_ADC12)
|
2016-06-01 01:58:52 +02:00
|
|
|
.irq = STM32_IRQ_ADC12,
|
|
|
|
.isr = adc12_interrupt,
|
2018-11-24 00:33:45 +01:00
|
|
|
# elif defined(STM32_IRQ_ADC)
|
2011-12-14 01:34:12 +01:00
|
|
|
.irq = STM32_IRQ_ADC,
|
|
|
|
.isr = adc123_interrupt,
|
2018-11-24 00:33:45 +01:00
|
|
|
# else
|
|
|
|
# error "No STM32_IRQ_ADC1 STM32_IRQ_ADC12 or STM32_IRQ_ADC defined for CONFIG_STM32_ADC1"
|
|
|
|
# endif
|
2020-01-31 19:07:39 +01:00
|
|
|
#endif /* CONFIG_STM32_ADC_NOIRQ */
|
2018-11-24 00:33:45 +01:00
|
|
|
#ifdef HAVE_ADC_CMN_DATA
|
|
|
|
.cmn = &ADC1CMN_DATA,
|
2011-12-12 02:04:53 +01:00
|
|
|
#endif
|
2011-12-16 01:32:11 +01:00
|
|
|
.intf = 1,
|
2018-11-12 16:45:55 +01:00
|
|
|
#ifdef HAVE_ADC_RESOLUTION
|
|
|
|
.resolution = CONFIG_STM32_ADC1_RESOLUTION,
|
|
|
|
#endif
|
2011-12-14 01:34:12 +01:00
|
|
|
.base = STM32_ADC1_BASE,
|
2018-11-24 00:33:45 +01:00
|
|
|
#ifdef ADC1_HAVE_EXTCFG
|
|
|
|
.extcfg = ADC1_EXTCFG_VALUE,
|
|
|
|
#endif
|
|
|
|
#ifdef ADC1_HAVE_JEXTCFG
|
|
|
|
.jextcfg = ADC1_JEXTCFG_VALUE,
|
|
|
|
#endif
|
2011-12-16 20:29:41 +01:00
|
|
|
#ifdef ADC1_HAVE_TIMER
|
2011-12-21 00:44:21 +01:00
|
|
|
.trigger = CONFIG_STM32_ADC1_TIMTRIG,
|
2011-12-16 20:29:41 +01:00
|
|
|
.tbase = ADC1_TIMER_BASE,
|
2011-12-20 01:30:12 +01:00
|
|
|
.pclck = ADC1_TIMER_PCLK_FREQUENCY,
|
|
|
|
.freq = CONFIG_STM32_ADC1_SAMPLE_FREQUENCY,
|
2011-12-16 20:29:41 +01:00
|
|
|
#endif
|
2015-07-30 16:47:45 +02:00
|
|
|
#ifdef ADC1_HAVE_DMA
|
|
|
|
.dmachan = ADC1_DMA_CHAN,
|
2018-12-02 02:24:36 +01:00
|
|
|
# ifdef ADC_HAVE_DMACFG
|
2018-11-24 00:33:45 +01:00
|
|
|
.dmacfg = CONFIG_STM32_ADC1_DMA_CFG,
|
2018-12-02 02:24:36 +01:00
|
|
|
# endif
|
2015-07-30 16:47:45 +02:00
|
|
|
.hasdma = true,
|
|
|
|
#endif
|
2011-12-12 02:04:53 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct adc_dev_s g_adcdev1 =
|
|
|
|
{
|
2015-10-07 21:45:15 +02:00
|
|
|
.ad_ops = &g_adcops,
|
|
|
|
.ad_priv = &g_adcpriv1,
|
2011-12-12 02:04:53 +01:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2011-12-14 02:25:14 +01:00
|
|
|
/* ADC2 state */
|
|
|
|
|
2011-12-12 02:04:53 +01:00
|
|
|
#ifdef CONFIG_STM32_ADC2
|
|
|
|
static struct stm32_dev_s g_adcpriv2 =
|
|
|
|
{
|
2018-11-24 00:33:45 +01:00
|
|
|
#ifdef CONFIG_STM32_ADC_LL_OPS
|
|
|
|
.llops = &g_adc_llops,
|
|
|
|
#endif
|
|
|
|
#ifndef CONFIG_STM32_ADC_NOIRQ
|
|
|
|
# if defined(STM32_IRQ_ADC12)
|
2011-12-14 01:34:12 +01:00
|
|
|
.irq = STM32_IRQ_ADC12,
|
|
|
|
.isr = adc12_interrupt,
|
2018-11-24 00:33:45 +01:00
|
|
|
# elif defined(STM32_IRQ_ADC)
|
2011-12-14 01:34:12 +01:00
|
|
|
.irq = STM32_IRQ_ADC,
|
|
|
|
.isr = adc123_interrupt,
|
2018-11-24 00:33:45 +01:00
|
|
|
# else
|
|
|
|
# error "No STM32_IRQ_ADC12 or STM32_IRQ_ADC defined for CONFIG_STM32_ADC2"
|
|
|
|
# endif
|
2020-01-31 19:07:39 +01:00
|
|
|
#endif /* CONFIG_STM32_ADC_NOIRQ */
|
2018-11-24 00:33:45 +01:00
|
|
|
#ifdef HAVE_ADC_CMN_DATA
|
|
|
|
.cmn = &ADC2CMN_DATA,
|
2011-12-12 02:04:53 +01:00
|
|
|
#endif
|
2012-04-19 19:52:14 +02:00
|
|
|
.intf = 2,
|
2018-11-12 16:45:55 +01:00
|
|
|
#ifdef HAVE_ADC_RESOLUTION
|
|
|
|
.resolution = CONFIG_STM32_ADC2_RESOLUTION,
|
|
|
|
#endif
|
2011-12-14 01:34:12 +01:00
|
|
|
.base = STM32_ADC2_BASE,
|
2018-11-24 00:33:45 +01:00
|
|
|
#ifdef ADC2_HAVE_EXTCFG
|
|
|
|
.extcfg = ADC2_EXTCFG_VALUE,
|
|
|
|
#endif
|
|
|
|
#ifdef ADC2_HAVE_JEXTCFG
|
|
|
|
.jextcfg = ADC2_JEXTCFG_VALUE,
|
|
|
|
#endif
|
2011-12-16 20:29:41 +01:00
|
|
|
#ifdef ADC2_HAVE_TIMER
|
2012-01-04 00:25:49 +01:00
|
|
|
.trigger = CONFIG_STM32_ADC2_TIMTRIG,
|
2011-12-16 20:29:41 +01:00
|
|
|
.tbase = ADC2_TIMER_BASE,
|
2011-12-20 01:30:12 +01:00
|
|
|
.pclck = ADC2_TIMER_PCLK_FREQUENCY,
|
|
|
|
.freq = CONFIG_STM32_ADC2_SAMPLE_FREQUENCY,
|
2011-12-16 20:29:41 +01:00
|
|
|
#endif
|
2015-07-30 16:47:45 +02:00
|
|
|
#ifdef ADC2_HAVE_DMA
|
|
|
|
.dmachan = ADC2_DMA_CHAN,
|
2018-12-02 02:24:36 +01:00
|
|
|
# ifdef ADC_HAVE_DMACFG
|
2018-11-24 00:33:45 +01:00
|
|
|
.dmacfg = CONFIG_STM32_ADC2_DMA_CFG,
|
2018-12-02 02:24:36 +01:00
|
|
|
# endif
|
2015-07-30 16:47:45 +02:00
|
|
|
.hasdma = true,
|
|
|
|
#endif
|
2011-12-12 02:04:53 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct adc_dev_s g_adcdev2 =
|
|
|
|
{
|
2015-10-07 21:45:15 +02:00
|
|
|
.ad_ops = &g_adcops,
|
|
|
|
.ad_priv = &g_adcpriv2,
|
2011-12-12 02:04:53 +01:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2011-12-14 02:25:14 +01:00
|
|
|
/* ADC3 state */
|
|
|
|
|
2011-12-12 02:04:53 +01:00
|
|
|
#ifdef CONFIG_STM32_ADC3
|
|
|
|
static struct stm32_dev_s g_adcpriv3 =
|
|
|
|
{
|
2018-11-24 00:33:45 +01:00
|
|
|
#ifdef CONFIG_STM32_ADC_LL_OPS
|
|
|
|
.llops = &g_adc_llops,
|
|
|
|
#endif
|
|
|
|
#ifndef CONFIG_STM32_ADC_NOIRQ
|
|
|
|
# if defined(STM32_IRQ_ADC3)
|
2011-12-14 01:34:12 +01:00
|
|
|
.irq = STM32_IRQ_ADC3,
|
|
|
|
.isr = adc3_interrupt,
|
2018-11-24 00:33:45 +01:00
|
|
|
# elif defined(STM32_IRQ_ADC)
|
2011-12-14 01:34:12 +01:00
|
|
|
.irq = STM32_IRQ_ADC,
|
|
|
|
.isr = adc123_interrupt,
|
2018-11-24 00:33:45 +01:00
|
|
|
# else
|
|
|
|
# error "No STM32_IRQ_ADC3 or STM32_IRQ_ADC defined for CONFIG_STM32_ADC3"
|
|
|
|
# endif
|
2020-01-31 19:07:39 +01:00
|
|
|
#endif /* CONFIG_STM32_ADC_NOIRQ */
|
2018-11-24 00:33:45 +01:00
|
|
|
#ifdef HAVE_ADC_CMN_DATA
|
|
|
|
.cmn = &ADC3CMN_DATA,
|
2011-12-12 02:04:53 +01:00
|
|
|
#endif
|
2012-01-04 00:25:49 +01:00
|
|
|
.intf = 3,
|
2018-11-12 16:45:55 +01:00
|
|
|
#ifdef HAVE_ADC_RESOLUTION
|
|
|
|
.resolution = CONFIG_STM32_ADC3_RESOLUTION,
|
|
|
|
#endif
|
2011-12-14 01:34:12 +01:00
|
|
|
.base = STM32_ADC3_BASE,
|
2018-11-24 00:33:45 +01:00
|
|
|
#ifdef ADC3_HAVE_EXTCFG
|
|
|
|
.extcfg = ADC3_EXTCFG_VALUE,
|
|
|
|
#endif
|
|
|
|
#ifdef ADC3_HAVE_JEXTCFG
|
|
|
|
.jextcfg = ADC3_JEXTCFG_VALUE,
|
|
|
|
#endif
|
2011-12-16 20:29:41 +01:00
|
|
|
#ifdef ADC3_HAVE_TIMER
|
2012-01-04 00:25:49 +01:00
|
|
|
.trigger = CONFIG_STM32_ADC3_TIMTRIG,
|
2011-12-16 20:29:41 +01:00
|
|
|
.tbase = ADC3_TIMER_BASE,
|
2011-12-20 01:30:12 +01:00
|
|
|
.pclck = ADC3_TIMER_PCLK_FREQUENCY,
|
|
|
|
.freq = CONFIG_STM32_ADC3_SAMPLE_FREQUENCY,
|
2011-12-16 20:29:41 +01:00
|
|
|
#endif
|
2015-07-30 16:47:45 +02:00
|
|
|
#ifdef ADC3_HAVE_DMA
|
|
|
|
.dmachan = ADC3_DMA_CHAN,
|
2018-12-02 02:24:36 +01:00
|
|
|
# ifdef ADC_HAVE_DMACFG
|
2018-11-24 00:33:45 +01:00
|
|
|
.dmacfg = CONFIG_STM32_ADC3_DMA_CFG,
|
2018-12-02 02:24:36 +01:00
|
|
|
# endif
|
2015-07-30 16:47:45 +02:00
|
|
|
.hasdma = true,
|
|
|
|
#endif
|
2011-12-12 02:04:53 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct adc_dev_s g_adcdev3 =
|
|
|
|
{
|
2015-10-07 21:45:15 +02:00
|
|
|
.ad_ops = &g_adcops,
|
|
|
|
.ad_priv = &g_adcpriv3,
|
2011-12-12 02:04:53 +01:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2015-07-30 16:47:45 +02:00
|
|
|
/* ADC4 state */
|
|
|
|
|
|
|
|
#ifdef CONFIG_STM32_ADC4
|
2015-11-05 16:09:37 +01:00
|
|
|
static struct stm32_dev_s g_adcpriv4 =
|
|
|
|
{
|
2018-11-24 00:33:45 +01:00
|
|
|
#ifdef CONFIG_STM32_ADC_LL_OPS
|
|
|
|
.llops = &g_adc_llops,
|
|
|
|
#endif
|
|
|
|
#ifndef CONFIG_STM32_ADC_NOIRQ
|
2015-11-05 16:09:37 +01:00
|
|
|
.irq = STM32_IRQ_ADC4,
|
|
|
|
.isr = adc4_interrupt,
|
2018-11-24 00:33:45 +01:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_ADC_CMN_DATA
|
|
|
|
.cmn = &ADC4CMN_DATA,
|
|
|
|
#endif
|
2015-11-05 16:09:37 +01:00
|
|
|
.intf = 4,
|
2018-11-12 16:45:55 +01:00
|
|
|
#ifdef HAVE_ADC_RESOLUTION
|
|
|
|
.resolution = CONFIG_STM32_ADC4_RESOLUTION,
|
|
|
|
#endif
|
2015-11-05 16:09:37 +01:00
|
|
|
.base = STM32_ADC4_BASE,
|
2018-11-24 00:33:45 +01:00
|
|
|
#ifdef ADC4_HAVE_EXTCFG
|
|
|
|
.extcfg = ADC4_EXTCFG_VALUE,
|
|
|
|
#endif
|
|
|
|
#ifdef ADC4_HAVE_JEXTCFG
|
|
|
|
.jextcfg = ADC4_JEXTCFG_VALUE,
|
|
|
|
#endif
|
2015-11-05 16:09:37 +01:00
|
|
|
#ifdef ADC4_HAVE_TIMER
|
|
|
|
.trigger = CONFIG_STM32_ADC4_TIMTRIG,
|
|
|
|
.tbase = ADC4_TIMER_BASE,
|
|
|
|
.pclck = ADC4_TIMER_PCLK_FREQUENCY,
|
|
|
|
.freq = CONFIG_STM32_ADC4_SAMPLE_FREQUENCY,
|
|
|
|
#endif
|
|
|
|
#ifdef ADC4_HAVE_DMA
|
|
|
|
.dmachan = ADC4_DMA_CHAN,
|
2018-12-02 02:24:36 +01:00
|
|
|
# ifdef ADC_HAVE_DMACFG
|
2018-11-24 00:33:45 +01:00
|
|
|
.dmacfg = CONFIG_STM32_ADC4_DMA_CFG,
|
2018-12-02 02:24:36 +01:00
|
|
|
# endif
|
2015-11-05 16:09:37 +01:00
|
|
|
.hasdma = true,
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct adc_dev_s g_adcdev4 =
|
|
|
|
{
|
|
|
|
.ad_ops = &g_adcops,
|
|
|
|
.ad_priv = &g_adcpriv4,
|
|
|
|
};
|
2015-07-30 16:47:45 +02:00
|
|
|
#endif
|
|
|
|
|
2011-12-12 02:04:53 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2015-11-05 16:09:37 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: stm32_modifyreg32
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Modify the value of a 32-bit register (not atomic).
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* addr - The address of the register
|
|
|
|
* clrbits - The bits to clear
|
|
|
|
* setbits - The bits to set
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-11-12 16:45:55 +01:00
|
|
|
#ifndef HAVE_BASIC_ADC
|
2015-11-05 16:09:37 +01:00
|
|
|
static void stm32_modifyreg32(unsigned int addr, uint32_t clrbits,
|
|
|
|
uint32_t setbits)
|
|
|
|
{
|
|
|
|
putreg32((getreg32(addr) & ~clrbits) | setbits, addr);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-12-12 02:04:53 +01:00
|
|
|
/****************************************************************************
|
2011-12-14 01:34:12 +01:00
|
|
|
* Name: adc_getreg
|
2011-12-12 02:04:53 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2011-12-14 01:34:12 +01:00
|
|
|
* Read the value of an ADC register.
|
2011-12-12 02:04:53 +01:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
2015-11-05 16:09:37 +01:00
|
|
|
* priv - A reference to the ADC block status
|
2011-12-14 01:34:12 +01:00
|
|
|
* offset - The offset to the register to read
|
2011-12-12 02:04:53 +01:00
|
|
|
*
|
|
|
|
* Returned Value:
|
2015-11-05 16:09:37 +01:00
|
|
|
* The current contents of the specified register
|
2011-12-12 02:04:53 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2015-11-05 16:09:37 +01:00
|
|
|
static uint32_t adc_getreg(FAR struct stm32_dev_s *priv, int offset)
|
2011-12-12 02:04:53 +01:00
|
|
|
{
|
2011-12-14 01:34:12 +01:00
|
|
|
return getreg32(priv->base + offset);
|
|
|
|
}
|
2011-12-12 02:04:53 +01:00
|
|
|
|
2011-12-14 01:34:12 +01:00
|
|
|
/****************************************************************************
|
2015-11-05 16:09:37 +01:00
|
|
|
* Name: adc_putreg
|
2011-12-14 01:34:12 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2015-11-05 16:09:37 +01:00
|
|
|
* Write a value to an ADC register.
|
2011-12-14 01:34:12 +01:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
2015-11-05 16:09:37 +01:00
|
|
|
* priv - A reference to the ADC block status
|
|
|
|
* offset - The offset to the register to write to
|
|
|
|
* value - The value to write to the register
|
2011-12-14 01:34:12 +01:00
|
|
|
*
|
|
|
|
* Returned Value:
|
2015-11-05 16:09:37 +01:00
|
|
|
* None
|
2011-12-14 01:34:12 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
2011-12-12 02:04:53 +01:00
|
|
|
|
2015-11-05 16:09:37 +01:00
|
|
|
static void adc_putreg(FAR struct stm32_dev_s *priv, int offset,
|
|
|
|
uint32_t value)
|
2011-12-14 01:34:12 +01:00
|
|
|
{
|
2011-12-14 02:25:14 +01:00
|
|
|
putreg32(value, priv->base + offset);
|
2011-12-12 02:04:53 +01:00
|
|
|
}
|
|
|
|
|
2015-11-05 16:09:37 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: adc_modifyreg
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Modify the value of an ADC register (not atomic).
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* priv - A reference to the ADC block status
|
|
|
|
* offset - The offset to the register to modify
|
|
|
|
* clrbits - The bits to clear
|
|
|
|
* setbits - The bits to set
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void adc_modifyreg(FAR struct stm32_dev_s *priv, int offset,
|
|
|
|
uint32_t clrbits, uint32_t setbits)
|
|
|
|
{
|
|
|
|
adc_putreg(priv, offset, (adc_getreg(priv, offset) & ~clrbits) | setbits);
|
|
|
|
}
|
|
|
|
|
2018-11-24 00:33:45 +01:00
|
|
|
#ifdef HAVE_ADC_CMN_REGS
|
2018-11-12 16:45:55 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: adccmn_base_get
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static uint32_t adccmn_base_get(FAR struct stm32_dev_s *priv)
|
|
|
|
{
|
2018-11-24 00:33:45 +01:00
|
|
|
uint32_t base = 0;
|
2018-11-12 16:45:55 +01:00
|
|
|
|
|
|
|
#if defined(HAVE_IP_ADC_V2)
|
|
|
|
if (priv->base == STM32_ADC1_BASE || priv->base == STM32_ADC2_BASE)
|
|
|
|
{
|
|
|
|
base = STM32_ADC12CMN_BASE;
|
|
|
|
}
|
2018-11-24 00:33:45 +01:00
|
|
|
# if defined(CONFIG_STM32_ADC3) || defined(CONFIG_STM32_ADC4)
|
2018-11-12 16:45:55 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
base = STM32_ADC34CMN_BASE;
|
|
|
|
}
|
2018-11-24 00:33:45 +01:00
|
|
|
# endif
|
|
|
|
|
2018-11-12 16:45:55 +01:00
|
|
|
#elif defined(HAVE_IP_ADC_V1)
|
|
|
|
base = STM32_ADCCMN_BASE;
|
|
|
|
UNUSED(priv);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return base;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: adccmn_modifyreg
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void adccmn_modifyreg(FAR struct stm32_dev_s *priv, uint32_t offset,
|
|
|
|
uint32_t clrbits, uint32_t setbits)
|
|
|
|
{
|
|
|
|
uint32_t base = 0;
|
|
|
|
|
|
|
|
/* Get base address for ADC common register */
|
|
|
|
|
|
|
|
base = adccmn_base_get(priv);
|
|
|
|
|
|
|
|
/* Modify register */
|
|
|
|
|
|
|
|
stm32_modifyreg32(offset + base, clrbits, setbits);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: adccmn_getreg
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
# ifdef CONFIG_DEBUG_ANALOG_INFO
|
|
|
|
static uint32_t adccmn_getreg(FAR struct stm32_dev_s *priv, uint32_t offset)
|
|
|
|
{
|
|
|
|
uint32_t base = 0;
|
|
|
|
|
|
|
|
/* Get base address for ADC common register */
|
|
|
|
|
|
|
|
base = adccmn_base_get(priv);
|
|
|
|
|
|
|
|
/* Return register value */
|
|
|
|
|
2020-01-03 15:34:44 +01:00
|
|
|
return getreg32(base + offset);
|
2018-11-12 16:45:55 +01:00
|
|
|
}
|
|
|
|
# endif
|
2020-01-31 19:07:39 +01:00
|
|
|
#endif /* HAVE_ADC_CMN_REGS */
|
2018-11-12 16:45:55 +01:00
|
|
|
|
2011-12-16 20:29:41 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: tim_getreg
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Read the value of an ADC timer register.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
2015-11-05 16:09:37 +01:00
|
|
|
* priv - A reference to the ADC block status
|
2011-12-16 20:29:41 +01:00
|
|
|
* offset - The offset to the register to read
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* The current contents of the specified register
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2011-12-17 01:21:10 +01:00
|
|
|
#ifdef ADC_HAVE_TIMER
|
2015-11-05 16:09:37 +01:00
|
|
|
static uint16_t tim_getreg(FAR struct stm32_dev_s *priv, int offset)
|
2011-12-16 20:29:41 +01:00
|
|
|
{
|
2011-12-20 01:30:12 +01:00
|
|
|
return getreg16(priv->tbase + offset);
|
2011-12-16 20:29:41 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: tim_putreg
|
|
|
|
*
|
|
|
|
* Description:
|
2015-11-05 16:09:37 +01:00
|
|
|
* Write a value to an ADC timer register.
|
2011-12-16 20:29:41 +01:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
2015-11-05 16:09:37 +01:00
|
|
|
* priv - A reference to the ADC block status
|
|
|
|
* offset - The offset to the register to write to
|
|
|
|
* value - The value to write to the register
|
2011-12-16 20:29:41 +01:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2011-12-17 01:21:10 +01:00
|
|
|
#ifdef ADC_HAVE_TIMER
|
2015-11-05 16:09:37 +01:00
|
|
|
static void tim_putreg(FAR struct stm32_dev_s *priv, int offset,
|
|
|
|
uint16_t value)
|
2011-12-16 20:29:41 +01:00
|
|
|
{
|
2011-12-20 01:30:12 +01:00
|
|
|
putreg16(value, priv->tbase + offset);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-12-21 00:44:21 +01:00
|
|
|
/****************************************************************************
|
2015-11-05 16:09:37 +01:00
|
|
|
* Name: tim_modifyreg
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Modify the value of an ADC timer register (not atomic).
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* priv - A reference to the ADC block status
|
|
|
|
* offset - The offset to the register to modify
|
|
|
|
* clrbits - The bits to clear
|
|
|
|
* setbits - The bits to set
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef ADC_HAVE_TIMER
|
|
|
|
static void tim_modifyreg(FAR struct stm32_dev_s *priv, int offset,
|
|
|
|
uint16_t clrbits, uint16_t setbits)
|
|
|
|
{
|
|
|
|
tim_putreg(priv, offset, (tim_getreg(priv, offset) & ~clrbits) | setbits);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: tim_dumpregs
|
2011-12-21 00:44:21 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Dump all timer registers.
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Input Parameters:
|
2011-12-21 00:44:21 +01:00
|
|
|
* priv - A reference to the ADC block status
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef ADC_HAVE_TIMER
|
2015-11-05 16:09:37 +01:00
|
|
|
static void tim_dumpregs(FAR struct stm32_dev_s *priv, FAR const char *msg)
|
2011-12-21 00:44:21 +01:00
|
|
|
{
|
2016-06-11 19:59:51 +02:00
|
|
|
ainfo("%s:\n", msg);
|
|
|
|
ainfo(" CR1: %04x CR2: %04x SMCR: %04x DIER: %04x\n",
|
2011-12-21 00:44:21 +01:00
|
|
|
tim_getreg(priv, STM32_GTIM_CR1_OFFSET),
|
|
|
|
tim_getreg(priv, STM32_GTIM_CR2_OFFSET),
|
|
|
|
tim_getreg(priv, STM32_GTIM_SMCR_OFFSET),
|
|
|
|
tim_getreg(priv, STM32_GTIM_DIER_OFFSET));
|
2016-06-11 19:59:51 +02:00
|
|
|
ainfo(" SR: %04x EGR: 0000 CCMR1: %04x CCMR2: %04x\n",
|
2011-12-21 00:44:21 +01:00
|
|
|
tim_getreg(priv, STM32_GTIM_SR_OFFSET),
|
|
|
|
tim_getreg(priv, STM32_GTIM_CCMR1_OFFSET),
|
|
|
|
tim_getreg(priv, STM32_GTIM_CCMR2_OFFSET));
|
2016-06-11 19:59:51 +02:00
|
|
|
ainfo(" CCER: %04x CNT: %04x PSC: %04x ARR: %04x\n",
|
2011-12-21 00:44:21 +01:00
|
|
|
tim_getreg(priv, STM32_GTIM_CCER_OFFSET),
|
|
|
|
tim_getreg(priv, STM32_GTIM_CNT_OFFSET),
|
|
|
|
tim_getreg(priv, STM32_GTIM_PSC_OFFSET),
|
|
|
|
tim_getreg(priv, STM32_GTIM_ARR_OFFSET));
|
2016-06-11 19:59:51 +02:00
|
|
|
ainfo(" CCR1: %04x CCR2: %04x CCR3: %04x CCR4: %04x\n",
|
2011-12-21 00:44:21 +01:00
|
|
|
tim_getreg(priv, STM32_GTIM_CCR1_OFFSET),
|
|
|
|
tim_getreg(priv, STM32_GTIM_CCR2_OFFSET),
|
|
|
|
tim_getreg(priv, STM32_GTIM_CCR3_OFFSET),
|
|
|
|
tim_getreg(priv, STM32_GTIM_CCR4_OFFSET));
|
2018-11-12 16:45:55 +01:00
|
|
|
#if STM32_NATIM > 0
|
2018-12-09 01:09:01 +01:00
|
|
|
if (priv->tbase == STM32_TIM1_BASE
|
|
|
|
# ifdef STM32_TIM8_BASE
|
|
|
|
|| priv->tbase == STM32_TIM8_BASE
|
|
|
|
# endif
|
|
|
|
)
|
2015-10-07 21:45:15 +02:00
|
|
|
{
|
2016-06-11 19:59:51 +02:00
|
|
|
ainfo(" RCR: %04x BDTR: %04x DCR: %04x DMAR: %04x\n",
|
2015-10-07 21:45:15 +02:00
|
|
|
tim_getreg(priv, STM32_ATIM_RCR_OFFSET),
|
|
|
|
tim_getreg(priv, STM32_ATIM_BDTR_OFFSET),
|
|
|
|
tim_getreg(priv, STM32_ATIM_DCR_OFFSET),
|
|
|
|
tim_getreg(priv, STM32_ATIM_DMAR_OFFSET));
|
|
|
|
}
|
|
|
|
else
|
2018-11-12 16:45:55 +01:00
|
|
|
#endif
|
2015-10-07 21:45:15 +02:00
|
|
|
{
|
2016-06-11 19:59:51 +02:00
|
|
|
ainfo(" DCR: %04x DMAR: %04x\n",
|
2015-10-07 21:45:15 +02:00
|
|
|
tim_getreg(priv, STM32_GTIM_DCR_OFFSET),
|
|
|
|
tim_getreg(priv, STM32_GTIM_DMAR_OFFSET));
|
|
|
|
}
|
2011-12-21 00:44:21 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-12-20 01:30:12 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: adc_timstart
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Start (or stop) the timer counter
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* priv - A reference to the ADC block status
|
|
|
|
* enable - True: Start conversion
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2012-03-10 01:02:11 +01:00
|
|
|
|
2015-09-05 17:07:37 +02:00
|
|
|
#ifdef ADC_HAVE_TIMER
|
2015-11-05 16:09:37 +01:00
|
|
|
static void adc_timstart(FAR struct stm32_dev_s *priv, bool enable)
|
2011-12-20 01:30:12 +01:00
|
|
|
{
|
2016-06-11 19:59:51 +02:00
|
|
|
ainfo("enable: %d\n", enable ? 1 : 0);
|
2012-03-10 01:02:11 +01:00
|
|
|
|
2011-12-20 01:30:12 +01:00
|
|
|
if (enable)
|
|
|
|
{
|
|
|
|
/* Start the counter */
|
|
|
|
|
2015-11-05 16:09:37 +01:00
|
|
|
tim_modifyreg(priv, STM32_GTIM_CR1_OFFSET, 0, GTIM_CR1_CEN);
|
2011-12-20 01:30:12 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Disable the counter */
|
|
|
|
|
2015-11-05 16:09:37 +01:00
|
|
|
tim_modifyreg(priv, STM32_GTIM_CR1_OFFSET, GTIM_CR1_CEN, 0);
|
2011-12-20 01:30:12 +01:00
|
|
|
}
|
2011-12-16 20:29:41 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: adc_timinit
|
|
|
|
*
|
|
|
|
* Description:
|
2015-11-05 16:09:37 +01:00
|
|
|
* Initialize the timer that drivers the ADC sampling for this channel
|
|
|
|
* using the pre-calculated timer divider definitions.
|
2011-12-16 20:29:41 +01:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
2011-12-17 01:21:10 +01:00
|
|
|
* priv - A reference to the ADC block status
|
2011-12-16 20:29:41 +01:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero on success; a negated errno value on failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef ADC_HAVE_TIMER
|
|
|
|
static int adc_timinit(FAR struct stm32_dev_s *priv)
|
|
|
|
{
|
2011-12-20 01:30:12 +01:00
|
|
|
uint32_t prescaler;
|
|
|
|
uint32_t reload;
|
2011-12-21 00:44:21 +01:00
|
|
|
uint32_t timclk;
|
|
|
|
|
2015-11-05 16:09:37 +01:00
|
|
|
uint16_t clrbits = 0;
|
|
|
|
uint16_t setbits = 0;
|
2011-12-20 01:30:12 +01:00
|
|
|
uint16_t cr2;
|
|
|
|
uint16_t ccmr1;
|
|
|
|
uint16_t ccmr2;
|
2011-12-21 00:44:21 +01:00
|
|
|
uint16_t ocmode1;
|
|
|
|
uint16_t ocmode2;
|
|
|
|
uint16_t ccenable;
|
|
|
|
uint16_t ccer;
|
2011-12-22 01:31:47 +01:00
|
|
|
uint16_t egr;
|
2012-01-04 00:25:49 +01:00
|
|
|
|
2011-12-17 17:45:40 +01:00
|
|
|
/* If the timer base address is zero, then this ADC was not configured to
|
|
|
|
* use a timer.
|
2011-12-16 20:29:41 +01:00
|
|
|
*/
|
2011-12-17 17:45:40 +01:00
|
|
|
|
2015-11-05 16:09:37 +01:00
|
|
|
if (priv->tbase == 0)
|
2011-12-20 01:30:12 +01:00
|
|
|
{
|
2015-11-05 16:09:37 +01:00
|
|
|
return ERROR;
|
2011-12-20 01:30:12 +01:00
|
|
|
}
|
2011-12-16 20:29:41 +01:00
|
|
|
|
2018-11-24 00:33:45 +01:00
|
|
|
/* NOTE: EXTSEL configuration is done in adc_reset function */
|
2011-12-17 17:45:40 +01:00
|
|
|
|
|
|
|
/* Configure the timer channel to drive the ADC */
|
2011-12-17 01:21:10 +01:00
|
|
|
|
2020-02-23 09:50:23 +01:00
|
|
|
/* Calculate optimal values for the timer prescaler and for the timer
|
2015-07-29 16:34:27 +02:00
|
|
|
* reload register. If freq is the desired frequency, then
|
2011-12-20 01:30:12 +01:00
|
|
|
*
|
|
|
|
* reload = timclk / freq
|
|
|
|
* reload = (pclck / prescaler) / freq
|
|
|
|
*
|
|
|
|
* There are many solutions to do this, but the best solution will be the
|
|
|
|
* one that has the largest reload value and the smallest prescaler value.
|
|
|
|
* That is the solution that should give us the most accuracy in the timer
|
|
|
|
* control. Subject to:
|
|
|
|
*
|
|
|
|
* 0 <= prescaler <= 65536
|
|
|
|
* 1 <= reload <= 65535
|
|
|
|
*
|
|
|
|
* So ( prescaler = pclck / 65535 / freq ) would be optimal.
|
|
|
|
*/
|
|
|
|
|
|
|
|
prescaler = (priv->pclck / priv->freq + 65534) / 65535;
|
2011-12-17 01:21:10 +01:00
|
|
|
|
2015-07-29 16:34:27 +02:00
|
|
|
/* We need to decrement the prescaler value by one, but only, the value
|
|
|
|
* does not underflow.
|
2011-12-17 01:21:10 +01:00
|
|
|
*/
|
|
|
|
|
2011-12-21 00:44:21 +01:00
|
|
|
if (prescaler < 1)
|
2011-12-17 01:21:10 +01:00
|
|
|
{
|
2016-06-16 17:38:16 +02:00
|
|
|
awarn("WARNING: Prescaler underflowed.\n");
|
2011-12-21 00:44:21 +01:00
|
|
|
prescaler = 1;
|
2011-12-17 01:21:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for overflow */
|
|
|
|
|
2011-12-21 00:44:21 +01:00
|
|
|
else if (prescaler > 65536)
|
2011-12-20 01:30:12 +01:00
|
|
|
{
|
2016-06-16 17:38:16 +02:00
|
|
|
awarn("WARNING: Prescaler overflowed.\n");
|
2011-12-21 00:44:21 +01:00
|
|
|
prescaler = 65536;
|
2011-12-20 01:30:12 +01:00
|
|
|
}
|
|
|
|
|
2011-12-21 00:44:21 +01:00
|
|
|
timclk = priv->pclck / prescaler;
|
2012-03-10 01:02:11 +01:00
|
|
|
|
2011-12-21 00:44:21 +01:00
|
|
|
reload = timclk / priv->freq;
|
2011-12-20 01:30:12 +01:00
|
|
|
if (reload < 1)
|
2011-12-17 01:21:10 +01:00
|
|
|
{
|
2016-06-16 17:38:16 +02:00
|
|
|
awarn("WARNING: Reload value underflowed.\n");
|
2011-12-20 01:30:12 +01:00
|
|
|
reload = 1;
|
2011-12-17 01:21:10 +01:00
|
|
|
}
|
2011-12-20 01:30:12 +01:00
|
|
|
else if (reload > 65535)
|
|
|
|
{
|
2016-06-16 17:38:16 +02:00
|
|
|
awarn("WARNING: Reload value overflowed.\n");
|
2011-12-20 01:30:12 +01:00
|
|
|
reload = 65535;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Disable the timer until we get it configured */
|
2011-12-17 01:21:10 +01:00
|
|
|
|
2011-12-20 01:30:12 +01:00
|
|
|
adc_timstart(priv, false);
|
|
|
|
|
2015-11-05 16:09:37 +01:00
|
|
|
/* Set up the timer CR1 register.
|
|
|
|
*
|
|
|
|
* Select the Counter Mode == count up:
|
2011-12-20 01:30:12 +01:00
|
|
|
*
|
|
|
|
* ATIM_CR1_EDGE: The counter counts up or down depending on the
|
|
|
|
* direction bit(DIR).
|
|
|
|
* ATIM_CR1_DIR: 0: count up, 1: count down
|
2015-11-05 16:09:37 +01:00
|
|
|
*
|
|
|
|
* Set the clock division to zero for all
|
2011-12-20 01:30:12 +01:00
|
|
|
*/
|
2012-03-10 01:02:11 +01:00
|
|
|
|
2015-11-05 16:09:37 +01:00
|
|
|
clrbits = GTIM_CR1_DIR | GTIM_CR1_CMS_MASK | GTIM_CR1_CKD_MASK;
|
|
|
|
setbits = GTIM_CR1_EDGE;
|
|
|
|
tim_modifyreg(priv, STM32_GTIM_CR1_OFFSET, clrbits, setbits);
|
2011-12-20 01:30:12 +01:00
|
|
|
|
2011-12-21 00:44:21 +01:00
|
|
|
/* Set the reload and prescaler values */
|
2011-12-20 01:30:12 +01:00
|
|
|
|
2020-01-03 15:34:44 +01:00
|
|
|
tim_putreg(priv, STM32_GTIM_PSC_OFFSET, prescaler - 1);
|
2011-12-21 00:44:21 +01:00
|
|
|
tim_putreg(priv, STM32_GTIM_ARR_OFFSET, reload);
|
2012-03-10 01:02:11 +01:00
|
|
|
|
2015-07-29 16:34:27 +02:00
|
|
|
/* Clear the advanced timers repetition counter in TIM1 */
|
2011-12-20 01:30:12 +01:00
|
|
|
|
2018-11-12 16:45:55 +01:00
|
|
|
#if STM32_NATIM > 0
|
2018-12-09 01:09:01 +01:00
|
|
|
if (priv->tbase == STM32_TIM1_BASE
|
|
|
|
# ifdef STM32_TIM8_BASE
|
|
|
|
|| priv->tbase == STM32_TIM8_BASE
|
|
|
|
# endif
|
|
|
|
)
|
2011-12-20 01:30:12 +01:00
|
|
|
{
|
|
|
|
tim_putreg(priv, STM32_ATIM_RCR_OFFSET, 0);
|
2011-12-22 01:31:47 +01:00
|
|
|
tim_putreg(priv, STM32_ATIM_BDTR_OFFSET, ATIM_BDTR_MOE); /* Check me */
|
2011-12-20 01:30:12 +01:00
|
|
|
}
|
2015-07-29 16:34:27 +02:00
|
|
|
#endif
|
2011-12-20 01:30:12 +01:00
|
|
|
|
|
|
|
/* TIMx event generation: Bit 0 UG: Update generation */
|
2011-12-21 00:44:21 +01:00
|
|
|
|
2015-11-05 16:09:37 +01:00
|
|
|
tim_putreg(priv, STM32_GTIM_EGR_OFFSET, GTIM_EGR_UG);
|
2011-12-21 00:44:21 +01:00
|
|
|
|
|
|
|
/* Handle channel specific setup */
|
|
|
|
|
|
|
|
ocmode1 = 0;
|
|
|
|
ocmode2 = 0;
|
2012-03-10 01:02:11 +01:00
|
|
|
|
2015-11-05 16:09:37 +01:00
|
|
|
switch (priv->trigger)
|
2011-12-20 01:30:12 +01:00
|
|
|
{
|
2011-12-22 01:31:47 +01:00
|
|
|
case 0: /* TimerX CC1 event */
|
2011-12-20 01:30:12 +01:00
|
|
|
{
|
2011-12-21 00:44:21 +01:00
|
|
|
ccenable = ATIM_CCER_CC1E;
|
|
|
|
ocmode1 = (ATIM_CCMR_CCS_CCOUT << ATIM_CCMR1_CC1S_SHIFT) |
|
|
|
|
(ATIM_CCMR_MODE_PWM1 << ATIM_CCMR1_OC1M_SHIFT) |
|
|
|
|
ATIM_CCMR1_OC1PE;
|
2011-12-22 22:55:54 +01:00
|
|
|
|
|
|
|
/* Set the event CC1 */
|
|
|
|
|
2011-12-22 01:31:47 +01:00
|
|
|
egr = ATIM_EGR_CC1G;
|
2011-12-21 00:44:21 +01:00
|
|
|
|
2015-11-05 16:09:37 +01:00
|
|
|
/* Set the duty cycle by writing to the CCR register for this
|
|
|
|
* channel
|
|
|
|
*/
|
2011-12-21 00:44:21 +01:00
|
|
|
|
|
|
|
tim_putreg(priv, STM32_GTIM_CCR1_OFFSET, (uint16_t)(reload >> 1));
|
2011-12-20 01:30:12 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2011-12-22 01:31:47 +01:00
|
|
|
case 1: /* TimerX CC2 event */
|
2011-12-20 01:30:12 +01:00
|
|
|
{
|
2011-12-21 00:44:21 +01:00
|
|
|
ccenable = ATIM_CCER_CC2E;
|
|
|
|
ocmode1 = (ATIM_CCMR_CCS_CCOUT << ATIM_CCMR1_CC2S_SHIFT) |
|
|
|
|
(ATIM_CCMR_MODE_PWM1 << ATIM_CCMR1_OC2M_SHIFT) |
|
|
|
|
ATIM_CCMR1_OC2PE;
|
2011-12-22 22:55:54 +01:00
|
|
|
|
|
|
|
/* Set the event CC2 */
|
|
|
|
|
2011-12-22 01:31:47 +01:00
|
|
|
egr = ATIM_EGR_CC2G;
|
2011-12-21 00:44:21 +01:00
|
|
|
|
2015-11-05 16:09:37 +01:00
|
|
|
/* Set the duty cycle by writing to the CCR register for this
|
|
|
|
* channel
|
|
|
|
*/
|
2011-12-21 00:44:21 +01:00
|
|
|
|
|
|
|
tim_putreg(priv, STM32_GTIM_CCR2_OFFSET, (uint16_t)(reload >> 1));
|
2011-12-20 01:30:12 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2011-12-22 01:31:47 +01:00
|
|
|
case 2: /* TimerX CC3 event */
|
2011-12-20 01:30:12 +01:00
|
|
|
{
|
2011-12-21 00:44:21 +01:00
|
|
|
ccenable = ATIM_CCER_CC3E;
|
|
|
|
ocmode2 = (ATIM_CCMR_CCS_CCOUT << ATIM_CCMR2_CC3S_SHIFT) |
|
|
|
|
(ATIM_CCMR_MODE_PWM1 << ATIM_CCMR2_OC3M_SHIFT) |
|
|
|
|
ATIM_CCMR2_OC3PE;
|
2011-12-22 22:55:54 +01:00
|
|
|
|
|
|
|
/* Set the event CC3 */
|
|
|
|
|
2011-12-22 01:31:47 +01:00
|
|
|
egr = ATIM_EGR_CC3G;
|
2011-12-21 00:44:21 +01:00
|
|
|
|
2015-11-05 16:09:37 +01:00
|
|
|
/* Set the duty cycle by writing to the CCR register for this
|
|
|
|
* channel
|
|
|
|
*/
|
2011-12-21 00:44:21 +01:00
|
|
|
|
|
|
|
tim_putreg(priv, STM32_GTIM_CCR3_OFFSET, (uint16_t)(reload >> 1));
|
2011-12-20 01:30:12 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2011-12-22 01:31:47 +01:00
|
|
|
case 3: /* TimerX CC4 event */
|
2011-12-20 01:30:12 +01:00
|
|
|
{
|
2011-12-21 00:44:21 +01:00
|
|
|
ccenable = ATIM_CCER_CC4E;
|
|
|
|
ocmode2 = (ATIM_CCMR_CCS_CCOUT << ATIM_CCMR2_CC4S_SHIFT) |
|
|
|
|
(ATIM_CCMR_MODE_PWM1 << ATIM_CCMR2_OC4M_SHIFT) |
|
2011-12-22 01:31:47 +01:00
|
|
|
ATIM_CCMR2_OC4PE;
|
2011-12-22 22:55:54 +01:00
|
|
|
|
|
|
|
/* Set the event CC4 */
|
|
|
|
|
2011-12-22 01:31:47 +01:00
|
|
|
egr = ATIM_EGR_CC4G;
|
2011-12-21 00:44:21 +01:00
|
|
|
|
2015-11-05 16:09:37 +01:00
|
|
|
/* Set the duty cycle by writing to the CCR register for this
|
|
|
|
* channel
|
|
|
|
*/
|
2011-12-21 00:44:21 +01:00
|
|
|
|
|
|
|
tim_putreg(priv, STM32_GTIM_CCR4_OFFSET, (uint16_t)(reload >> 1));
|
2011-12-20 01:30:12 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2011-12-22 01:31:47 +01:00
|
|
|
case 4: /* TimerX TRGO event */
|
2011-12-20 01:30:12 +01:00
|
|
|
{
|
2012-10-21 18:53:38 +02:00
|
|
|
/* TODO: TRGO support not yet implemented */
|
2020-01-03 15:34:44 +01:00
|
|
|
|
2011-12-22 22:55:54 +01:00
|
|
|
/* Set the event TRGO */
|
|
|
|
|
2012-10-21 18:53:38 +02:00
|
|
|
ccenable = 0;
|
2011-12-22 01:31:47 +01:00
|
|
|
egr = GTIM_EGR_TG;
|
2012-03-10 01:02:11 +01:00
|
|
|
|
2015-11-05 16:09:37 +01:00
|
|
|
/* Set the duty cycle by writing to the CCR register for this
|
|
|
|
* channel
|
|
|
|
*/
|
2011-12-22 22:55:54 +01:00
|
|
|
|
|
|
|
tim_putreg(priv, STM32_GTIM_CCR4_OFFSET, (uint16_t)(reload >> 1));
|
2011-12-20 01:30:12 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2016-06-16 17:38:16 +02:00
|
|
|
aerr("ERROR: No such trigger: %d\n", priv->trigger);
|
2011-12-20 01:30:12 +01:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2012-03-10 01:02:11 +01:00
|
|
|
|
2011-12-21 00:44:21 +01:00
|
|
|
/* Disable the Channel by resetting the CCxE Bit in the CCER register */
|
|
|
|
|
|
|
|
ccer = tim_getreg(priv, STM32_GTIM_CCER_OFFSET);
|
|
|
|
ccer &= ~ccenable;
|
|
|
|
tim_putreg(priv, STM32_GTIM_CCER_OFFSET, ccer);
|
2012-03-10 01:02:11 +01:00
|
|
|
|
2015-11-26 19:46:53 +01:00
|
|
|
/* Fetch the CR2, CCMR1, and CCMR2 register (already have ccer) */
|
2011-12-21 00:44:21 +01:00
|
|
|
|
|
|
|
cr2 = tim_getreg(priv, STM32_GTIM_CR2_OFFSET);
|
|
|
|
ccmr1 = tim_getreg(priv, STM32_GTIM_CCMR1_OFFSET);
|
|
|
|
ccmr2 = tim_getreg(priv, STM32_GTIM_CCMR2_OFFSET);
|
2012-03-10 01:02:11 +01:00
|
|
|
|
2015-11-05 16:09:37 +01:00
|
|
|
/* Reset the Output Compare Mode Bits and set the select output compare
|
|
|
|
* mode
|
|
|
|
*/
|
2011-12-21 00:44:21 +01:00
|
|
|
|
|
|
|
ccmr1 &= ~(ATIM_CCMR1_CC1S_MASK | ATIM_CCMR1_OC1M_MASK | ATIM_CCMR1_OC1PE |
|
|
|
|
ATIM_CCMR1_CC2S_MASK | ATIM_CCMR1_OC2M_MASK | ATIM_CCMR1_OC2PE);
|
|
|
|
ccmr2 &= ~(ATIM_CCMR2_CC3S_MASK | ATIM_CCMR2_OC3M_MASK | ATIM_CCMR2_OC3PE |
|
|
|
|
ATIM_CCMR2_CC4S_MASK | ATIM_CCMR2_OC4M_MASK | ATIM_CCMR2_OC4PE);
|
|
|
|
ccmr1 |= ocmode1;
|
|
|
|
ccmr2 |= ocmode2;
|
2012-03-10 01:02:11 +01:00
|
|
|
|
2015-11-05 16:09:37 +01:00
|
|
|
/* Reset the output polarity level of all channels (selects high
|
|
|
|
* polarity)
|
|
|
|
*/
|
2011-12-21 00:44:21 +01:00
|
|
|
|
2015-11-05 16:09:37 +01:00
|
|
|
ccer &= ~(ATIM_CCER_CC1P | ATIM_CCER_CC2P |
|
|
|
|
ATIM_CCER_CC3P | ATIM_CCER_CC4P);
|
2012-03-10 01:02:11 +01:00
|
|
|
|
2011-12-21 00:44:21 +01:00
|
|
|
/* Enable the output state of the selected channel (only) */
|
|
|
|
|
2015-11-05 16:09:37 +01:00
|
|
|
ccer &= ~(ATIM_CCER_CC1E | ATIM_CCER_CC2E |
|
|
|
|
ATIM_CCER_CC3E | ATIM_CCER_CC4E);
|
2011-12-21 00:44:21 +01:00
|
|
|
ccer |= ccenable;
|
|
|
|
|
2018-11-12 16:45:55 +01:00
|
|
|
/* TODO: revisit and simplify logic below */
|
2015-07-29 16:34:27 +02:00
|
|
|
|
2018-11-12 16:45:55 +01:00
|
|
|
#if STM32_NATIM > 0
|
2018-12-09 01:09:01 +01:00
|
|
|
if (priv->tbase == STM32_TIM1_BASE
|
|
|
|
# ifdef STM32_TIM8_BASE
|
|
|
|
|| priv->tbase == STM32_TIM8_BASE
|
|
|
|
# endif
|
|
|
|
)
|
2015-11-05 16:09:37 +01:00
|
|
|
{
|
|
|
|
/* Reset output N polarity level, output N state, output compare state,
|
|
|
|
* output compare N idle state.
|
|
|
|
*/
|
2015-07-29 16:34:27 +02:00
|
|
|
|
2015-11-05 16:09:37 +01:00
|
|
|
ccer &= ~(ATIM_CCER_CC1NE | ATIM_CCER_CC1NP |
|
|
|
|
ATIM_CCER_CC2NE | ATIM_CCER_CC2NP |
|
|
|
|
ATIM_CCER_CC3NE | ATIM_CCER_CC3NP);
|
2015-07-29 16:34:27 +02:00
|
|
|
|
2015-11-05 16:09:37 +01:00
|
|
|
/* Reset the output compare and output compare N IDLE State */
|
2015-07-29 16:34:27 +02:00
|
|
|
|
2015-11-05 16:09:37 +01:00
|
|
|
cr2 &= ~(ATIM_CR2_OIS1 | ATIM_CR2_OIS1N |
|
|
|
|
ATIM_CR2_OIS2 | ATIM_CR2_OIS2N |
|
|
|
|
ATIM_CR2_OIS3 | ATIM_CR2_OIS3N |
|
|
|
|
ATIM_CR2_OIS4);
|
|
|
|
}
|
2018-11-12 16:45:55 +01:00
|
|
|
# if defined(HAVE_GTIM_CCXNP)
|
2015-11-05 16:09:37 +01:00
|
|
|
else
|
|
|
|
{
|
2020-01-03 15:34:44 +01:00
|
|
|
ccer &= ~(GTIM_CCER_CC1NP | GTIM_CCER_CC2NP | GTIM_CCER_CC3NP |
|
|
|
|
GTIM_CCER_CC4NP);
|
2015-11-05 16:09:37 +01:00
|
|
|
}
|
2015-09-18 20:47:24 +02:00
|
|
|
# endif
|
2015-07-29 16:34:27 +02:00
|
|
|
|
2018-11-12 16:45:55 +01:00
|
|
|
#else /* No ADV TIM */
|
2015-07-29 16:34:27 +02:00
|
|
|
|
2020-04-03 01:10:26 +02:00
|
|
|
/* For the STM32L15XX family only these timers can be used: 2-4, 6, 7, 9,
|
|
|
|
* 10. Reset the output compare and output compare N IDLE State
|
2015-07-29 16:34:27 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
if (priv->tbase >= STM32_TIM2_BASE && priv->tbase <= STM32_TIM4_BASE)
|
2011-12-21 00:44:21 +01:00
|
|
|
{
|
2015-07-29 16:34:27 +02:00
|
|
|
/* Reset output N polarity level, output N state, output compare state,
|
2011-12-21 00:44:21 +01:00
|
|
|
* output compare N idle state.
|
|
|
|
*/
|
2015-11-05 16:09:37 +01:00
|
|
|
|
2018-11-12 16:45:55 +01:00
|
|
|
ccer &= ~(GTIM_CCER_CC1NE | GTIM_CCER_CC1NP |
|
|
|
|
GTIM_CCER_CC2NE | GTIM_CCER_CC2NP |
|
|
|
|
GTIM_CCER_CC3NE | GTIM_CCER_CC3NP |
|
|
|
|
GTIM_CCER_CC4NP);
|
2011-12-21 00:44:21 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Save the modified register values */
|
|
|
|
|
|
|
|
tim_putreg(priv, STM32_GTIM_CR2_OFFSET, cr2);
|
|
|
|
tim_putreg(priv, STM32_GTIM_CCMR1_OFFSET, ccmr1);
|
|
|
|
tim_putreg(priv, STM32_GTIM_CCMR2_OFFSET, ccmr2);
|
|
|
|
tim_putreg(priv, STM32_GTIM_CCER_OFFSET, ccer);
|
2011-12-22 01:31:47 +01:00
|
|
|
tim_putreg(priv, STM32_GTIM_EGR_OFFSET, egr);
|
2011-12-21 00:44:21 +01:00
|
|
|
|
|
|
|
/* Set the ARR Preload Bit */
|
|
|
|
|
2015-11-05 16:09:37 +01:00
|
|
|
tim_modifyreg(priv, STM32_GTIM_CR1_OFFSET, 0, GTIM_CR1_ARPE);
|
2011-12-21 00:44:21 +01:00
|
|
|
|
2015-11-05 16:09:37 +01:00
|
|
|
/* Enable the timer counter */
|
2011-12-17 01:21:10 +01:00
|
|
|
|
2011-12-20 01:30:12 +01:00
|
|
|
adc_timstart(priv, true);
|
2011-12-21 00:44:21 +01:00
|
|
|
|
2015-11-05 16:09:37 +01:00
|
|
|
tim_dumpregs(priv, "After starting timers");
|
2011-12-21 00:44:21 +01:00
|
|
|
|
2011-12-20 01:30:12 +01:00
|
|
|
return OK;
|
2011-12-16 20:29:41 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
2018-11-24 00:33:45 +01:00
|
|
|
* Name: adc_reg_startconv
|
2011-12-16 20:29:41 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2018-11-24 00:33:45 +01:00
|
|
|
* Start (or stop) the ADC regular conversion process
|
2011-12-16 20:29:41 +01:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* priv - A reference to the ADC block status
|
|
|
|
* enable - True: Start conversion
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-11-12 16:45:55 +01:00
|
|
|
#if defined(HAVE_IP_ADC_V2)
|
2018-11-24 00:33:45 +01:00
|
|
|
static void adc_reg_startconv(FAR struct stm32_dev_s *priv, bool enable)
|
2015-11-05 16:09:37 +01:00
|
|
|
{
|
|
|
|
uint32_t regval;
|
2015-07-29 16:34:27 +02:00
|
|
|
|
2018-11-24 00:33:45 +01:00
|
|
|
ainfo("reg enable: %d\n", enable ? 1 : 0);
|
2015-11-05 16:09:37 +01:00
|
|
|
|
|
|
|
if (enable)
|
|
|
|
{
|
|
|
|
/* Start the conversion of regular channels */
|
2011-12-16 20:29:41 +01:00
|
|
|
|
2015-11-05 16:09:37 +01:00
|
|
|
adc_modifyreg(priv, STM32_ADC_CR_OFFSET, 0, ADC_CR_ADSTART);
|
2011-12-16 20:29:41 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-11-05 16:09:37 +01:00
|
|
|
regval = adc_getreg(priv, STM32_ADC_CR_OFFSET);
|
|
|
|
|
|
|
|
/* Is a conversion ongoing? */
|
2015-07-29 16:34:27 +02:00
|
|
|
|
2015-11-05 16:09:37 +01:00
|
|
|
if ((regval & ADC_CR_ADSTART) != 0)
|
|
|
|
{
|
|
|
|
/* Stop the conversion */
|
2015-07-29 16:34:27 +02:00
|
|
|
|
2015-11-05 16:09:37 +01:00
|
|
|
adc_putreg(priv, STM32_ADC_CR_OFFSET, regval | ADC_CR_ADSTP);
|
2015-07-29 16:34:27 +02:00
|
|
|
|
2015-11-05 16:09:37 +01:00
|
|
|
/* Wait for the conversion to stop */
|
2015-07-29 16:34:27 +02:00
|
|
|
|
2020-04-03 01:10:26 +02:00
|
|
|
while ((adc_getreg(priv, STM32_ADC_CR_OFFSET) &
|
|
|
|
ADC_CR_ADSTP) != 0);
|
2015-11-05 16:09:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-11-12 16:45:55 +01:00
|
|
|
#elif defined(HAVE_IP_ADC_V1) && !defined(HAVE_BASIC_ADC)
|
2018-11-24 00:33:45 +01:00
|
|
|
static void adc_reg_startconv(FAR struct stm32_dev_s *priv, bool enable)
|
2015-11-05 16:09:37 +01:00
|
|
|
{
|
2018-11-24 00:33:45 +01:00
|
|
|
ainfo("reg enable: %d\n", enable ? 1 : 0);
|
2015-11-05 16:09:37 +01:00
|
|
|
|
|
|
|
if (enable)
|
|
|
|
{
|
|
|
|
/* Start the conversion of regular channels */
|
2011-12-16 20:29:41 +01:00
|
|
|
|
2015-11-05 16:09:37 +01:00
|
|
|
adc_modifyreg(priv, STM32_ADC_CR2_OFFSET, 0, ADC_CR2_SWSTART);
|
2011-12-16 20:29:41 +01:00
|
|
|
}
|
2015-11-05 16:09:37 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Stop the conversion */
|
2015-07-30 16:47:45 +02:00
|
|
|
|
2015-11-05 16:09:37 +01:00
|
|
|
adc_modifyreg(priv, STM32_ADC_CR2_OFFSET, ADC_CR2_SWSTART, 0);
|
|
|
|
}
|
2011-12-16 20:29:41 +01:00
|
|
|
}
|
2018-11-12 16:45:55 +01:00
|
|
|
#else /* ADV IPv1 BASIC */
|
2018-11-24 00:33:45 +01:00
|
|
|
static void adc_reg_startconv(FAR struct stm32_dev_s *priv, bool enable)
|
2018-11-12 16:45:55 +01:00
|
|
|
{
|
2018-11-24 00:33:45 +01:00
|
|
|
ainfo("reg enable: %d\n", enable ? 1 : 0);
|
2018-11-12 16:45:55 +01:00
|
|
|
|
|
|
|
if (!enable)
|
|
|
|
{
|
|
|
|
/* Clear ADON to stop the conversion and put the ADC in the
|
|
|
|
* power down state.
|
|
|
|
*/
|
|
|
|
|
|
|
|
adc_enable(priv, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If the ADC is already on, set ADON again to start the conversion.
|
|
|
|
* Otherwise, set ADON once to wake up the ADC from the power down state.
|
|
|
|
*/
|
|
|
|
|
|
|
|
adc_enable(priv, true);
|
|
|
|
}
|
2011-12-22 22:55:54 +01:00
|
|
|
#endif
|
2011-12-16 20:29:41 +01:00
|
|
|
|
2018-11-24 00:33:45 +01:00
|
|
|
#ifdef ADC_HAVE_INJECTED
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: adc_inj_startconv
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Start (or stop) the ADC injected conversion process
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* priv - A reference to the ADC block status
|
|
|
|
* enable - True: Start conversion
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#if defined(HAVE_IP_ADC_V2)
|
|
|
|
static void adc_inj_startconv(FAR struct stm32_dev_s *priv, bool enable)
|
|
|
|
{
|
|
|
|
uint32_t regval;
|
|
|
|
|
|
|
|
ainfo("inj enable: %d\n", enable ? 1 : 0);
|
|
|
|
|
|
|
|
if (enable)
|
|
|
|
{
|
|
|
|
/* Start the conversion of regular channels */
|
|
|
|
|
|
|
|
adc_modifyreg(priv, STM32_ADC_CR_OFFSET, 0, ADC_CR_JADSTART);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
regval = adc_getreg(priv, STM32_ADC_CR_OFFSET);
|
|
|
|
|
|
|
|
/* Is a conversion ongoing? */
|
|
|
|
|
|
|
|
if ((regval & ADC_CR_JADSTART) != 0)
|
|
|
|
{
|
|
|
|
/* Stop the conversion */
|
|
|
|
|
|
|
|
adc_putreg(priv, STM32_ADC_CR_OFFSET, regval | ADC_CR_JADSTP);
|
|
|
|
|
|
|
|
/* Wait for the conversion to stop */
|
|
|
|
|
2020-04-03 01:10:26 +02:00
|
|
|
while ((adc_getreg(priv, STM32_ADC_CR_OFFSET) &
|
|
|
|
ADC_CR_JADSTP) != 0);
|
2018-11-24 00:33:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#elif defined(HAVE_IP_ADC_V1) && !defined(HAVE_BASIC_ADC)
|
|
|
|
static void adc_inj_startconv(FAR struct stm32_dev_s *priv, bool enable)
|
|
|
|
{
|
|
|
|
ainfo("inj enable: %d\n", enable ? 1 : 0);
|
|
|
|
|
|
|
|
if (enable)
|
|
|
|
{
|
|
|
|
/* Start the conversion of injected channels */
|
|
|
|
|
|
|
|
adc_modifyreg(priv, STM32_ADC_CR2_OFFSET, 0, ADC_CR2_JSWSTART);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Stop the conversion */
|
|
|
|
|
|
|
|
adc_modifyreg(priv, STM32_ADC_CR2_OFFSET, ADC_CR2_JSWSTART, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else /* ADV IPv1 BASIC */
|
|
|
|
# error TODO
|
|
|
|
#endif
|
|
|
|
|
2020-01-31 19:07:39 +01:00
|
|
|
#endif /* ADC_HAVE_INJECTED */
|
2018-11-24 00:33:45 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: adccmn_lock
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef HAVE_ADC_CMN_DATA
|
|
|
|
static int adccmn_lock(FAR struct stm32_dev_s *priv, bool lock)
|
|
|
|
{
|
2020-01-03 15:34:44 +01:00
|
|
|
int ret;
|
2018-11-24 00:33:45 +01:00
|
|
|
|
|
|
|
if (lock)
|
|
|
|
{
|
2020-01-02 17:49:34 +01:00
|
|
|
ret = nxsem_wait_uninterruptible(&priv->cmn->lock);
|
2018-11-24 00:33:45 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-01-03 15:34:44 +01:00
|
|
|
ret = nxsem_post(&priv->cmn->lock);
|
2018-11-24 00:33:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-12-15 01:29:35 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: adc_rccreset
|
|
|
|
*
|
|
|
|
* Description:
|
2012-03-10 01:02:11 +01:00
|
|
|
* Deinitializes the ADCx peripheral registers to their default
|
2011-12-15 01:29:35 +01:00
|
|
|
* reset values. It could set all the ADCs configured.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* regaddr - The register to read
|
|
|
|
* reset - Condition, set or reset
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-11-24 00:33:45 +01:00
|
|
|
#if defined(HAVE_IP_ADC_V1) && defined(HAVE_BASIC_ADC)
|
2015-11-05 16:09:37 +01:00
|
|
|
static void adc_rccreset(FAR struct stm32_dev_s *priv, bool reset)
|
2011-12-15 01:29:35 +01:00
|
|
|
{
|
|
|
|
uint32_t adcbit;
|
|
|
|
|
2018-11-24 00:33:45 +01:00
|
|
|
/* Pick the appropriate bit in the RCC reset register.
|
|
|
|
* For the basic STM32 ADC IPv1, there is an individual bit to reset
|
|
|
|
* each ADC (ADC12 and ADC34).
|
2015-11-05 16:09:37 +01:00
|
|
|
*/
|
2011-12-15 01:29:35 +01:00
|
|
|
|
|
|
|
switch (priv->intf)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_STM32_ADC1
|
|
|
|
case 1:
|
2018-11-24 00:33:45 +01:00
|
|
|
{
|
|
|
|
adcbit = RCC_RSTR_ADC1RST;
|
|
|
|
break;
|
|
|
|
}
|
2020-01-03 15:34:44 +01:00
|
|
|
|
2011-12-15 01:29:35 +01:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_STM32_ADC2
|
|
|
|
case 2:
|
2018-11-24 00:33:45 +01:00
|
|
|
{
|
|
|
|
adcbit = RCC_RSTR_ADC2RST;
|
|
|
|
break;
|
|
|
|
}
|
2020-01-03 15:34:44 +01:00
|
|
|
|
2011-12-15 01:29:35 +01:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_STM32_ADC3
|
|
|
|
case 3:
|
2018-11-24 00:33:45 +01:00
|
|
|
{
|
|
|
|
adcbit = RCC_RSTR_ADC3RST;
|
|
|
|
break;
|
|
|
|
}
|
2020-01-03 15:34:44 +01:00
|
|
|
|
2015-11-05 16:09:37 +01:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_STM32_ADC4
|
|
|
|
case 4:
|
2018-11-24 00:33:45 +01:00
|
|
|
{
|
|
|
|
adcbit = RCC_RSTR_ADC4RST;
|
|
|
|
break;
|
|
|
|
}
|
2020-01-03 15:34:44 +01:00
|
|
|
|
2011-12-15 01:29:35 +01:00
|
|
|
#endif
|
|
|
|
default:
|
2018-11-24 00:33:45 +01:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2011-12-15 01:29:35 +01:00
|
|
|
}
|
|
|
|
|
2018-11-24 00:33:45 +01:00
|
|
|
/* Set or clear the selected bit in the RCC reset register */
|
2011-12-22 04:09:25 +01:00
|
|
|
|
2011-12-15 01:29:35 +01:00
|
|
|
if (reset)
|
|
|
|
{
|
2015-11-05 16:09:37 +01:00
|
|
|
/* Enable ADC reset state */
|
2011-12-15 01:29:35 +01:00
|
|
|
|
2015-11-05 16:09:37 +01:00
|
|
|
modifyreg32(STM32_RCC_RSTR, 0, adcbit);
|
2011-12-15 01:29:35 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Release ADC from reset state */
|
|
|
|
|
2015-11-05 16:09:37 +01:00
|
|
|
modifyreg32(STM32_RCC_RSTR, adcbit, 0);
|
2011-12-15 01:29:35 +01:00
|
|
|
}
|
|
|
|
}
|
2018-11-24 00:33:45 +01:00
|
|
|
#elif defined(HAVE_IP_ADC_V1)
|
|
|
|
static void adc_rccreset(FAR struct stm32_dev_s *priv, bool reset)
|
|
|
|
{
|
|
|
|
uint32_t adcbit;
|
2011-12-15 01:29:35 +01:00
|
|
|
|
2018-11-24 00:33:45 +01:00
|
|
|
/* Pick the appropriate bit in the RCC reset register.
|
|
|
|
* For the STM32 ADC IPv1, there is one common reset for all ADCs.
|
|
|
|
*/
|
2015-07-29 16:34:27 +02:00
|
|
|
|
2018-11-24 00:33:45 +01:00
|
|
|
switch (priv->intf)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
case 3:
|
|
|
|
{
|
|
|
|
adcbit = RCC_RSTR_ADC123RST;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set or clear the selected bit in the RCC reset register */
|
|
|
|
|
|
|
|
if (reset)
|
|
|
|
{
|
|
|
|
/* Enable ADC reset state */
|
|
|
|
|
|
|
|
modifyreg32(STM32_RCC_RSTR, 0, adcbit);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Release ADC from reset state */
|
|
|
|
|
|
|
|
modifyreg32(STM32_RCC_RSTR, adcbit, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#elif defined(HAVE_IP_ADC_V2)
|
|
|
|
static void adc_rccreset(FAR struct stm32_dev_s *priv, bool reset)
|
|
|
|
{
|
|
|
|
uint32_t adcbit;
|
|
|
|
|
|
|
|
/* Pick the appropriate bit in the RCC reset register.
|
2020-04-03 01:10:26 +02:00
|
|
|
* For the STM32 ADC IPv2, there is an individual bit to reset each
|
|
|
|
* ADC block.
|
2018-11-24 00:33:45 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
switch (priv->intf)
|
|
|
|
{
|
|
|
|
#if defined(CONFIG_STM32_ADC1) || defined(CONFIG_STM32_ADC2)
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
{
|
|
|
|
adcbit = RCC_RSTR_ADC12RST;
|
|
|
|
break;
|
|
|
|
}
|
2020-01-03 15:34:44 +01:00
|
|
|
|
2018-11-24 00:33:45 +01:00
|
|
|
#endif
|
|
|
|
#if defined(CONFIG_STM32_ADC3) || defined(CONFIG_STM32_ADC4)
|
|
|
|
case 3:
|
|
|
|
case 4:
|
|
|
|
{
|
|
|
|
adcbit = RCC_RSTR_ADC34RST;
|
|
|
|
break;
|
|
|
|
}
|
2020-01-03 15:34:44 +01:00
|
|
|
|
2018-11-24 00:33:45 +01:00
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set or clear the selected bit in the RCC reset register */
|
|
|
|
|
|
|
|
if (reset)
|
|
|
|
{
|
|
|
|
/* Enable ADC reset state */
|
|
|
|
|
|
|
|
modifyreg32(STM32_RCC_RSTR, 0, adcbit);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Release ADC from reset state */
|
|
|
|
|
|
|
|
modifyreg32(STM32_RCC_RSTR, adcbit, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: adc_power_down_idle
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Enables or disables power down during the idle phase.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
*
|
|
|
|
* priv - pointer to the adc device structure
|
|
|
|
* pdi_high - true: The ADC is powered down when waiting for a start event
|
|
|
|
* false: The ADC is powered up when waiting for a start event
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_STM32_STM32L15XX
|
2015-07-29 16:34:27 +02:00
|
|
|
static void adc_power_down_idle(FAR struct stm32_dev_s *priv, bool pdi_high)
|
|
|
|
{
|
2015-11-05 16:09:37 +01:00
|
|
|
uint32_t regval;
|
2015-07-29 16:34:27 +02:00
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
ainfo("PDI: %d\n", pdi_high ? 1 : 0);
|
2015-07-29 16:34:27 +02:00
|
|
|
|
|
|
|
regval = adc_getreg(priv, STM32_ADC_CR1_OFFSET);
|
|
|
|
|
2015-11-05 16:09:37 +01:00
|
|
|
if ((STM32_ADC1_CR2 & ADC_CR2_ADON) == 0)
|
2015-07-29 16:34:27 +02:00
|
|
|
{
|
|
|
|
if (pdi_high)
|
|
|
|
{
|
|
|
|
regval |= ADC_CR1_PDI;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
regval &= ~ADC_CR1_PDI;
|
|
|
|
}
|
|
|
|
|
|
|
|
adc_putreg(priv, STM32_ADC_CR1_OFFSET, regval);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-10-03 15:25:03 +02:00
|
|
|
/****************************************************************************
|
2015-07-29 16:34:27 +02:00
|
|
|
* Name: adc_power_down_delay
|
|
|
|
*
|
2018-02-01 19:03:55 +01:00
|
|
|
* Description:
|
|
|
|
* Enables or disables power down during the delay phase.
|
2015-07-29 16:34:27 +02:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
*
|
|
|
|
* priv - pointer to the adc device structure
|
|
|
|
* pdd_high - true: The ADC is powered down when waiting for a start event
|
|
|
|
* false: The ADC is powered up when waiting for a start event
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None.
|
|
|
|
*
|
2015-10-03 15:25:03 +02:00
|
|
|
****************************************************************************/
|
2015-07-29 16:34:27 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_STM32_STM32L15XX
|
|
|
|
static void adc_power_down_delay(FAR struct stm32_dev_s *priv, bool pdd_high)
|
|
|
|
{
|
2015-11-05 16:09:37 +01:00
|
|
|
uint32_t regval;
|
2015-07-29 16:34:27 +02:00
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
ainfo("PDD: %d\n", pdd_high ? 1 : 0);
|
2015-07-29 16:34:27 +02:00
|
|
|
|
|
|
|
regval = adc_getreg(priv, STM32_ADC_CR1_OFFSET);
|
|
|
|
|
2015-11-05 16:09:37 +01:00
|
|
|
if ((STM32_ADC1_CR2 & ADC_CR2_ADON) == 0)
|
2015-07-29 16:34:27 +02:00
|
|
|
{
|
|
|
|
if (pdd_high)
|
|
|
|
{
|
|
|
|
regval |= ADC_CR1_PDD;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
regval &= ~ADC_CR1_PDD;
|
|
|
|
}
|
|
|
|
|
|
|
|
adc_putreg(priv, STM32_ADC_CR1_OFFSET, regval);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-10-03 15:25:03 +02:00
|
|
|
/****************************************************************************
|
2015-07-29 16:34:27 +02:00
|
|
|
* Name: adc_dels_after_conversion
|
|
|
|
*
|
2018-02-01 19:03:55 +01:00
|
|
|
* Description:
|
|
|
|
* Defines the length of the delay which is applied after a conversion or
|
|
|
|
* a sequence of conversions.
|
2015-07-29 16:34:27 +02:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
*
|
|
|
|
* priv - pointer to the adc device structure
|
|
|
|
* delay - delay selection (see definition in chip/chip/stm32_adc.h
|
|
|
|
* starting from line 284)
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
*
|
2015-10-03 15:25:03 +02:00
|
|
|
****************************************************************************/
|
2015-07-29 16:34:27 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_STM32_STM32L15XX
|
|
|
|
static void adc_dels_after_conversion(FAR struct stm32_dev_s *priv,
|
|
|
|
uint32_t delay)
|
|
|
|
{
|
2016-06-11 19:59:51 +02:00
|
|
|
ainfo("Delay selected: 0x%08x\n", delay);
|
2015-07-29 16:34:27 +02:00
|
|
|
|
2015-11-05 16:09:37 +01:00
|
|
|
adc_modifyreg(priv, STM32_ADC_CR2_OFFSET, ADC_CR2_DELS_MASK, delay);
|
2015-07-29 16:34:27 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-10-03 15:25:03 +02:00
|
|
|
/****************************************************************************
|
2015-07-29 16:34:27 +02:00
|
|
|
* Name: adc_select_ch_bank
|
|
|
|
*
|
2018-02-01 19:03:55 +01:00
|
|
|
* Description:
|
|
|
|
* Selects the bank of channels to be converted
|
2020-04-03 01:10:26 +02:00
|
|
|
* (! Must be modified only when no conversion is on going !)
|
2015-07-29 16:34:27 +02:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
*
|
|
|
|
* priv - pointer to the adc device structure
|
|
|
|
* enable - true: bank of channels B selected
|
|
|
|
* false: bank of channels A selected
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
*
|
2015-10-03 15:25:03 +02:00
|
|
|
****************************************************************************/
|
2015-07-29 16:34:27 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_STM32_STM32L15XX
|
2015-11-05 16:09:37 +01:00
|
|
|
static void adc_select_ch_bank(FAR struct stm32_dev_s *priv,
|
|
|
|
bool chb_selected)
|
2015-07-29 16:34:27 +02:00
|
|
|
{
|
2016-06-11 19:59:51 +02:00
|
|
|
ainfo("Bank of channels selected: %c\n", chb_selected ? 'B' : 'A');
|
2015-07-29 16:34:27 +02:00
|
|
|
|
|
|
|
if (chb_selected)
|
|
|
|
{
|
2015-11-05 16:09:37 +01:00
|
|
|
adc_modifyreg(priv, STM32_ADC_CR2_OFFSET, 0, ADC_CR2_CFG);
|
2015-07-29 16:34:27 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-11-05 16:09:37 +01:00
|
|
|
adc_modifyreg(priv, STM32_ADC_CR2_OFFSET, ADC_CR2_CFG, 0);
|
2015-07-29 16:34:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-10-03 15:25:03 +02:00
|
|
|
/****************************************************************************
|
2011-12-15 01:29:35 +01:00
|
|
|
* Name: adc_enable
|
|
|
|
*
|
2018-02-01 19:03:55 +01:00
|
|
|
* Description:
|
|
|
|
* Enables or disables the specified ADC peripheral. Also, starts a
|
|
|
|
* conversion when the ADC is not triggered by timers
|
2011-12-15 01:29:35 +01:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
*
|
2011-12-16 14:32:46 +01:00
|
|
|
* enable - true: enable ADC conversion
|
|
|
|
* false: disable ADC conversion
|
2011-12-15 01:29:35 +01:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
*
|
2015-10-03 15:25:03 +02:00
|
|
|
****************************************************************************/
|
2011-12-16 01:32:11 +01:00
|
|
|
|
2018-11-12 16:45:55 +01:00
|
|
|
#if defined(HAVE_IP_ADC_V2)
|
2011-12-16 20:29:41 +01:00
|
|
|
static void adc_enable(FAR struct stm32_dev_s *priv, bool enable)
|
2011-12-15 01:29:35 +01:00
|
|
|
{
|
|
|
|
uint32_t regval;
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
ainfo("enable: %d\n", enable ? 1 : 0);
|
2015-07-30 01:37:35 +02:00
|
|
|
|
2015-11-05 16:09:37 +01:00
|
|
|
regval = adc_getreg(priv, STM32_ADC_CR_OFFSET);
|
2015-07-29 16:34:27 +02:00
|
|
|
|
2015-11-05 16:09:37 +01:00
|
|
|
if (enable)
|
2011-12-15 01:29:35 +01:00
|
|
|
{
|
2015-11-05 16:09:37 +01:00
|
|
|
/* Enable the ADC */
|
|
|
|
|
|
|
|
adc_putreg(priv, STM32_ADC_CR_OFFSET, regval | ADC_CR_ADEN);
|
|
|
|
|
|
|
|
/* Wait for the ADC to be ready */
|
|
|
|
|
|
|
|
while ((adc_getreg(priv, STM32_ADC_ISR_OFFSET) & ADC_INT_ARDY) == 0);
|
2011-12-15 01:29:35 +01:00
|
|
|
}
|
2015-11-05 16:09:37 +01:00
|
|
|
else if ((regval & ADC_CR_ADEN) != 0 && (regval & ADC_CR_ADDIS) == 0)
|
2011-12-15 01:29:35 +01:00
|
|
|
{
|
2018-11-24 00:33:45 +01:00
|
|
|
/* Stop ongoing regular conversions */
|
2015-07-29 16:34:27 +02:00
|
|
|
|
2018-11-24 00:33:45 +01:00
|
|
|
adc_reg_startconv(priv, false);
|
2015-11-05 16:09:37 +01:00
|
|
|
|
|
|
|
/* Disable the ADC */
|
|
|
|
|
|
|
|
adc_putreg(priv, STM32_ADC_CR_OFFSET, regval | ADC_CR_ADDIS);
|
|
|
|
|
|
|
|
/* Wait for the ADC to be disabled */
|
|
|
|
|
|
|
|
while ((adc_getreg(priv, STM32_ADC_CR_OFFSET) & ADC_CR_ADEN) != 0);
|
|
|
|
}
|
|
|
|
}
|
2018-11-12 16:45:55 +01:00
|
|
|
#else /* HAVE_IP_ADC_V1 */
|
2015-11-05 16:09:37 +01:00
|
|
|
static void adc_enable(FAR struct stm32_dev_s *priv, bool enable)
|
|
|
|
{
|
|
|
|
#ifdef ADC_SR_ADONS
|
|
|
|
bool enabled = (adc_getreg(priv, STM32_ADC_SR_OFFSET) & ADC_SR_ADONS) != 0;
|
|
|
|
#else
|
|
|
|
bool enabled = false;
|
|
|
|
#endif
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
ainfo("enable: %d\n", enable ? 1 : 0);
|
2015-11-05 16:09:37 +01:00
|
|
|
|
|
|
|
if (!enabled && enable)
|
2015-07-30 01:37:35 +02:00
|
|
|
{
|
2015-11-05 16:09:37 +01:00
|
|
|
adc_modifyreg(priv, STM32_ADC_CR2_OFFSET, 0, ADC_CR2_ADON);
|
2015-07-30 01:37:35 +02:00
|
|
|
}
|
2015-11-05 16:09:37 +01:00
|
|
|
else if (enabled && !enable)
|
2015-07-30 01:37:35 +02:00
|
|
|
{
|
2015-11-05 16:09:37 +01:00
|
|
|
adc_modifyreg(priv, STM32_ADC_CR2_OFFSET, ADC_CR2_ADON, 0);
|
2015-07-30 01:37:35 +02:00
|
|
|
}
|
2011-12-15 01:29:35 +01:00
|
|
|
}
|
2015-11-05 16:09:37 +01:00
|
|
|
#endif
|
2011-12-15 01:29:35 +01:00
|
|
|
|
2015-07-30 16:47:45 +02:00
|
|
|
/****************************************************************************
|
2016-10-25 22:14:10 +02:00
|
|
|
* Name: adc_dmaconvcallback
|
2015-07-30 16:47:45 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Callback for DMA. Called from the DMA transfer complete interrupt after
|
|
|
|
* all channels have been converted and transferred with DMA.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
*
|
|
|
|
* handle - handle to DMA
|
|
|
|
* isr -
|
|
|
|
* arg - adc device
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-11-24 00:33:45 +01:00
|
|
|
#if defined(ADC_HAVE_DMA) && !defined(CONFIG_STM32_ADC_NOIRQ)
|
2020-04-03 01:10:26 +02:00
|
|
|
static void adc_dmaconvcallback(DMA_HANDLE handle, uint8_t isr,
|
|
|
|
FAR void *arg)
|
2015-07-30 16:47:45 +02:00
|
|
|
{
|
2015-11-05 16:09:37 +01:00
|
|
|
FAR struct adc_dev_s *dev = (FAR struct adc_dev_s *)arg;
|
|
|
|
FAR struct stm32_dev_s *priv = (FAR struct stm32_dev_s *)dev->ad_priv;
|
2015-07-30 16:47:45 +02:00
|
|
|
int i;
|
|
|
|
|
2016-05-26 20:42:34 +02:00
|
|
|
/* Verify that the upper-half driver has bound its callback functions */
|
|
|
|
|
|
|
|
if (priv->cb != NULL)
|
2015-07-30 16:47:45 +02:00
|
|
|
{
|
2016-05-26 20:42:34 +02:00
|
|
|
DEBUGASSERT(priv->cb->au_receive != NULL);
|
2015-07-30 16:47:45 +02:00
|
|
|
|
2018-11-24 00:33:45 +01:00
|
|
|
for (i = 0; i < priv->rnchannels; i++)
|
2016-05-26 20:42:34 +02:00
|
|
|
{
|
2018-11-24 00:33:45 +01:00
|
|
|
priv->cb->au_receive(dev, priv->r_chanlist[priv->current],
|
|
|
|
priv->r_dmabuffer[priv->current]);
|
2016-05-26 20:42:34 +02:00
|
|
|
priv->current++;
|
2018-11-24 00:33:45 +01:00
|
|
|
if (priv->current >= priv->rnchannels)
|
2016-05-26 20:42:34 +02:00
|
|
|
{
|
|
|
|
/* Restart the conversion sequence from the beginning */
|
|
|
|
|
|
|
|
priv->current = 0;
|
|
|
|
}
|
2015-07-30 16:47:45 +02:00
|
|
|
}
|
2016-06-18 20:06:33 +02:00
|
|
|
}
|
2016-06-18 21:00:17 +02:00
|
|
|
|
2015-07-30 16:47:45 +02:00
|
|
|
/* Restart DMA for the next conversion series */
|
|
|
|
|
2015-11-05 16:09:37 +01:00
|
|
|
adc_modifyreg(priv, STM32_ADC_DMAREG_OFFSET, ADC_DMAREG_DMA, 0);
|
|
|
|
adc_modifyreg(priv, STM32_ADC_DMAREG_OFFSET, 0, ADC_DMAREG_DMA);
|
2015-07-30 16:47:45 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-05-26 20:25:54 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: adc_bind
|
|
|
|
*
|
|
|
|
* Description:
|
2017-03-18 16:34:24 +01:00
|
|
|
* Bind the upper-half driver callbacks to the lower-half implementation.
|
|
|
|
* This must be called early in order to receive ADC event notifications.
|
2016-05-26 20:25:54 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int adc_bind(FAR struct adc_dev_s *dev,
|
|
|
|
FAR const struct adc_callback_s *callback)
|
|
|
|
{
|
2020-04-21 21:35:54 +02:00
|
|
|
#ifdef ADC_HAVE_CB
|
2016-05-26 20:25:54 +02:00
|
|
|
FAR struct stm32_dev_s *priv = (FAR struct stm32_dev_s *)dev->ad_priv;
|
|
|
|
|
|
|
|
DEBUGASSERT(priv != NULL);
|
|
|
|
priv->cb = callback;
|
2020-04-21 21:35:54 +02:00
|
|
|
#else
|
|
|
|
UNUSED(dev);
|
|
|
|
UNUSED(callback);
|
2018-11-24 00:33:45 +01:00
|
|
|
#endif
|
|
|
|
|
2016-05-26 20:25:54 +02:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2011-12-12 02:04:53 +01:00
|
|
|
/****************************************************************************
|
2018-12-02 19:34:02 +01:00
|
|
|
* Name: adc_watchdog_cfg
|
2011-12-12 02:04:53 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
#if defined(HAVE_IP_ADC_V2)
|
|
|
|
static void adc_watchdog_cfg(FAR struct stm32_dev_s *priv)
|
2011-12-12 02:04:53 +01:00
|
|
|
{
|
2018-12-02 19:34:02 +01:00
|
|
|
uint32_t clrbits = 0;
|
|
|
|
uint32_t setbits = 0;
|
2011-12-16 01:32:11 +01:00
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
/* Initialize the watchdog 1 threshold register */
|
2011-12-12 02:04:53 +01:00
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
adc_putreg(priv, STM32_ADC_TR1_OFFSET, 0x0fff0000);
|
2015-07-29 16:34:27 +02:00
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
/* Enable the analog watchdog */
|
|
|
|
|
|
|
|
clrbits = ADC_CFGR1_AWD1CH_MASK;
|
|
|
|
setbits = ADC_CFGR1_AWD1EN | ADC_CFGR1_AWD1SGL |
|
|
|
|
(priv->r_chanlist[0] << ADC_CFGR1_AWD1CH_SHIFT);
|
|
|
|
|
|
|
|
/* Modify CFGR configuration */
|
2015-07-29 16:34:27 +02:00
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
adc_modifyreg(priv, STM32_ADC_CFGR1_OFFSET, clrbits, setbits);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static void adc_watchdog_cfg(FAR struct stm32_dev_s *priv)
|
|
|
|
{
|
|
|
|
uint32_t clrbits = 0;
|
|
|
|
uint32_t setbits = 0;
|
|
|
|
|
|
|
|
/* Initialize the watchdog high threshold register */
|
|
|
|
|
|
|
|
adc_putreg(priv, STM32_ADC_HTR_OFFSET, 0x00000fff);
|
|
|
|
|
|
|
|
/* Initialize the watchdog low threshold register */
|
|
|
|
|
|
|
|
adc_putreg(priv, STM32_ADC_LTR_OFFSET, 0x00000000);
|
|
|
|
|
|
|
|
clrbits = ADC_CR1_AWDCH_MASK;
|
|
|
|
setbits = ADC_CR1_AWDEN | (priv->r_chanlist[0] << ADC_CR1_AWDCH_SHIFT);
|
|
|
|
|
|
|
|
/* Modify CR1 configuration */
|
|
|
|
|
|
|
|
adc_modifyreg(priv, STM32_ADC_CR1_OFFSET, clrbits, setbits);
|
|
|
|
}
|
2015-11-05 16:09:37 +01:00
|
|
|
#endif
|
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: adc_calibrate
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-11-12 16:45:55 +01:00
|
|
|
#if defined(HAVE_IP_ADC_V2)
|
2018-12-02 19:34:02 +01:00
|
|
|
static void adc_calibrate(FAR struct stm32_dev_s *priv)
|
|
|
|
{
|
|
|
|
#if 0 /* Doesn't work */
|
|
|
|
/* Calibrate the ADC */
|
2015-11-05 16:09:37 +01:00
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
adc_modifyreg(priv, STM32_ADC_CR_OFFSET, ADC_CR_ADCALDIF, AD_CR_ADCAL);
|
2015-11-05 16:09:37 +01:00
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
/* Wait for the calibration to complete */
|
|
|
|
|
|
|
|
while ((adc_getreg(priv, STM32_ADC_CR_OFFSET) & ADC_CR_ADCAL) != 0);
|
2015-11-05 16:09:37 +01:00
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
#else
|
|
|
|
UNUSED(priv);
|
2015-07-29 16:34:27 +02:00
|
|
|
#endif
|
2018-12-02 19:34:02 +01:00
|
|
|
}
|
2019-09-01 01:06:24 +02:00
|
|
|
#elif defined(HAVE_IP_ADC_V1) && defined(HAVE_BASIC_ADC)
|
2018-12-02 19:34:02 +01:00
|
|
|
static void adc_calibrate(FAR struct stm32_dev_s *priv)
|
|
|
|
{
|
2019-08-30 03:01:22 +02:00
|
|
|
/* Power on the ADC */
|
2015-07-29 16:34:27 +02:00
|
|
|
|
2019-08-30 03:01:22 +02:00
|
|
|
adc_modifyreg(priv, STM32_ADC_CR2_OFFSET, 0, ADC_CR2_ADON);
|
|
|
|
|
|
|
|
/* Wait for the ADC power on at least 2 ADCCLK cycles */
|
|
|
|
|
|
|
|
up_udelay(10);
|
|
|
|
|
|
|
|
/* Reset calibration registers */
|
|
|
|
|
|
|
|
adc_modifyreg(priv, STM32_ADC_CR2_OFFSET, 0, ADC_CR2_RSTCAL);
|
|
|
|
|
|
|
|
/* Wait for the calibration register reset to complete */
|
|
|
|
|
|
|
|
while ((adc_getreg(priv, STM32_ADC_CR2_OFFSET) & ADC_CR2_RSTCAL) != 0);
|
|
|
|
|
|
|
|
/* Start ADC auto-calibration procedure */
|
|
|
|
|
|
|
|
adc_modifyreg(priv, STM32_ADC_CR2_OFFSET, 0, ADC_CR2_CAL);
|
|
|
|
|
|
|
|
/* Wait for the calibration procedure to complete */
|
|
|
|
|
|
|
|
while ((adc_getreg(priv, STM32_ADC_CR2_OFFSET) & ADC_CR2_CAL) != 0);
|
|
|
|
|
|
|
|
/* Power off the ADC */
|
|
|
|
|
|
|
|
adc_modifyreg(priv, STM32_ADC_CR2_OFFSET, ADC_CR2_ADON, 0);
|
2018-12-02 19:34:02 +01:00
|
|
|
}
|
2019-09-01 01:12:15 +02:00
|
|
|
#else
|
|
|
|
# define adc_calibrate(priv)
|
2018-12-02 19:34:02 +01:00
|
|
|
#endif
|
2018-11-24 00:33:45 +01:00
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: adc_mode_cfg
|
|
|
|
****************************************************************************/
|
2018-11-24 00:33:45 +01:00
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
#ifdef HAVE_IP_ADC_V2
|
|
|
|
static void adc_mode_cfg(FAR struct stm32_dev_s *priv)
|
|
|
|
{
|
|
|
|
uint32_t clrbits = 0;
|
|
|
|
uint32_t setbits = 0;
|
|
|
|
|
|
|
|
/* Disable continuous mode and set align to right */
|
|
|
|
|
|
|
|
clrbits = ADC_CFGR1_CONT | ADC_CFGR1_ALIGN;
|
|
|
|
|
|
|
|
/* Disable external trigger for regular channels */
|
|
|
|
|
|
|
|
clrbits |= ADC_CFGR1_EXTEN_MASK;
|
|
|
|
setbits |= ADC_CFGR1_EXTEN_NONE;
|
|
|
|
|
|
|
|
/* Set CFGR configuration */
|
|
|
|
|
|
|
|
adc_modifyreg(priv, STM32_ADC_CFGR1_OFFSET, clrbits, setbits);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static void adc_mode_cfg(FAR struct stm32_dev_s *priv)
|
|
|
|
{
|
|
|
|
uint32_t clrbits = 0;
|
|
|
|
uint32_t setbits = 0;
|
|
|
|
|
|
|
|
#ifdef HAVE_BASIC_ADC
|
|
|
|
/* Set independent mode */
|
|
|
|
|
|
|
|
clrbits |= ADC_CR1_DUALMOD_MASK;
|
|
|
|
setbits |= ADC_CR1_IND;
|
2018-11-24 00:33:45 +01:00
|
|
|
#endif
|
2018-12-02 19:34:02 +01:00
|
|
|
|
|
|
|
#ifdef ADC_HAVE_DMA
|
|
|
|
if (priv->hasdma)
|
2018-11-24 00:33:45 +01:00
|
|
|
{
|
2018-12-02 19:34:02 +01:00
|
|
|
setbits |= ADC_CR1_SCAN;
|
|
|
|
}
|
|
|
|
#endif
|
2018-11-24 00:33:45 +01:00
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
/* Set CR1 configuration */
|
2011-12-15 01:29:35 +01:00
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
adc_modifyreg(priv, STM32_ADC_CR1_OFFSET, clrbits, setbits);
|
2011-12-15 01:29:35 +01:00
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
/* REVISIT: */
|
2011-12-15 01:29:35 +01:00
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
#ifdef CONFIG_STM32_STM32L15XX
|
2012-03-10 01:02:11 +01:00
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
/* Select the bank of channels A */
|
2011-12-14 01:34:12 +01:00
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
adc_select_ch_bank(priv, false);
|
2011-12-15 01:29:35 +01:00
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
# ifdef HAVE_ADC_POWERDOWN
|
|
|
|
/* Disables power down during the delay phase */
|
2011-12-15 01:29:35 +01:00
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
adc_power_down_idle(priv, false);
|
|
|
|
adc_power_down_delay(priv, false);
|
|
|
|
# endif
|
2011-12-15 01:29:35 +01:00
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
/* Delay until the converted data has been read */
|
2011-12-15 01:29:35 +01:00
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
adc_dels_after_conversion(priv, ADC_CR2_DELS_TILLRD);
|
|
|
|
#endif
|
2011-12-15 01:29:35 +01:00
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
/* Disable continuous mode and set align to right */
|
2011-12-17 01:21:10 +01:00
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
clrbits = ADC_CR2_CONT | ADC_CR2_ALIGN;
|
|
|
|
setbits = 0;
|
2011-12-14 01:34:12 +01:00
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
/* Disable external trigger for regular channels */
|
2012-03-10 01:02:11 +01:00
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
clrbits |= ADC_EXTREG_EXTEN_MASK;
|
|
|
|
setbits |= ADC_EXTREG_EXTEN_NONE;
|
2015-11-05 16:09:37 +01:00
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
/* Enable software trigger for regular channels
|
|
|
|
* REVISIT: SWSTART must be set if no EXT trigger and basic ADC IPv1
|
|
|
|
*/
|
2015-11-05 16:09:37 +01:00
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
#ifdef CONFIG_STM32_STM32F37XX
|
|
|
|
clrbits |= ADC_CR2_EXTSEL_MASK;
|
|
|
|
setbits |= ADC_CR2_EXTSEL_SWSTART | ADC_CR2_EXTTRIG; /* SW is considered as external trigger */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Set CR2 configuration */
|
2012-01-02 19:22:19 +01:00
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
adc_modifyreg(priv, STM32_ADC_CR2_OFFSET, clrbits, setbits);
|
|
|
|
}
|
2012-01-02 19:22:19 +01:00
|
|
|
#endif
|
2012-03-10 01:02:11 +01:00
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: adc_voltreg_cfg
|
|
|
|
****************************************************************************/
|
2011-12-16 01:32:11 +01:00
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
#if defined(HAVE_IP_ADC_V2)
|
|
|
|
static void adc_voltreg_cfg(FAR struct stm32_dev_s *priv)
|
|
|
|
{
|
|
|
|
/* Set ADC voltage regulator to intermediate state */
|
2012-03-10 01:02:11 +01:00
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
adc_modifyreg(priv, STM32_ADC_CR_OFFSET, ADC_CR_ADVREGEN_MASK,
|
|
|
|
ADC_CR_ADVREGEN_INTER);
|
2012-03-10 01:02:11 +01:00
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
/* Enable the ADC voltage regulator */
|
2012-03-10 01:02:11 +01:00
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
adc_modifyreg(priv, STM32_ADC_CR_OFFSET, ADC_CR_ADVREGEN_MASK,
|
|
|
|
ADC_CR_ADVREGEN_ENABLED);
|
2015-11-05 16:09:37 +01:00
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
/* Wait for the ADC voltage regulator to startup */
|
2015-11-05 16:09:37 +01:00
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
up_udelay(10);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static void adc_voltreg_cfg(FAR struct stm32_dev_s *priv)
|
|
|
|
{
|
|
|
|
/* Nothing to do here */
|
2015-11-05 16:09:37 +01:00
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
UNUSED(priv);
|
|
|
|
}
|
2015-11-05 16:09:37 +01:00
|
|
|
#endif
|
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: adc_voltreg_cfg
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void adc_sampletime_cfg(FAR struct adc_dev_s *dev)
|
|
|
|
{
|
2015-11-05 16:09:37 +01:00
|
|
|
/* Initialize the same sample time for each ADC.
|
|
|
|
* During sample cycles channel selection bits must remain unchanged.
|
|
|
|
*/
|
|
|
|
|
2018-11-12 16:45:55 +01:00
|
|
|
#ifdef CONFIG_STM32_ADC_CHANGE_SAMPLETIME
|
2018-11-24 00:33:45 +01:00
|
|
|
adc_sampletime_write((FAR struct stm32_adc_dev_s *)dev);
|
2015-11-05 16:09:37 +01:00
|
|
|
#else
|
2018-12-03 21:49:49 +01:00
|
|
|
FAR struct stm32_dev_s *priv = (FAR struct stm32_dev_s *)dev->ad_priv;
|
|
|
|
|
2015-11-05 16:09:37 +01:00
|
|
|
adc_putreg(priv, STM32_ADC_SMPR1_OFFSET, ADC_SMPR1_DEFAULT);
|
|
|
|
adc_putreg(priv, STM32_ADC_SMPR2_OFFSET, ADC_SMPR2_DEFAULT);
|
2018-11-12 16:45:55 +01:00
|
|
|
# ifdef STM32_ADC_SMPR3_OFFSET
|
|
|
|
adc_putreg(priv, STM32_ADC_SMPR3_OFFSET, ADC_SMPR3_DEFAULT);
|
|
|
|
# endif
|
|
|
|
# ifdef STM32_ADC_SMPR0_OFFSET
|
|
|
|
adc_putreg(priv, STM32_ADC_SMPR0_OFFSET, ADC_SMPR0_DEFAULT);
|
|
|
|
# endif
|
2015-11-05 16:09:37 +01:00
|
|
|
#endif
|
2018-12-02 19:34:02 +01:00
|
|
|
}
|
2015-11-05 16:09:37 +01:00
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: adc_common_cfg
|
|
|
|
****************************************************************************/
|
2015-11-05 16:09:37 +01:00
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
#if defined(HAVE_IP_ADC_V2)
|
|
|
|
static void adc_common_cfg(FAR struct stm32_dev_s *priv)
|
|
|
|
{
|
|
|
|
uint32_t clrbits = 0;
|
|
|
|
uint32_t setbits = 0;
|
2015-11-05 16:09:37 +01:00
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
/* REVISIT: */
|
2015-11-05 16:09:37 +01:00
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
clrbits = ADC_CCR_DUAL_MASK | ADC_CCR_DELAY_MASK | ADC_CCR_DMACFG |
|
|
|
|
ADC_CCR_MDMA_MASK | ADC_CCR_CKMODE_MASK | ADC_CCR_VREFEN |
|
|
|
|
ADC_CCR_TSEN | ADC_CCR_VBATEN;
|
|
|
|
setbits = ADC_CCR_DUAL_IND | ADC_CCR_DELAY(0) | ADC_CCR_MDMA_DISABLED |
|
|
|
|
ADC_CCR_CKMODE_ASYNCH;
|
2015-11-05 16:09:37 +01:00
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
adccmn_modifyreg(priv, STM32_ADC_CCR_OFFSET, clrbits, setbits);
|
|
|
|
}
|
|
|
|
#elif defined(HAVE_IP_ADC_V1) && !defined(HAVE_BASIC_ADC)
|
|
|
|
static void adc_common_cfg(FAR struct stm32_dev_s *priv)
|
|
|
|
{
|
|
|
|
uint32_t clrbits = 0;
|
|
|
|
uint32_t setbits = 0;
|
2018-11-24 00:33:45 +01:00
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
clrbits = ADC_CCR_ADCPRE_MASK | ADC_CCR_TSVREFE;
|
|
|
|
setbits = ADC_CCR_ADCPRE_DIV2;
|
2018-11-24 00:33:45 +01:00
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
/* REVISIT: */
|
2015-11-05 16:09:37 +01:00
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
#if !defined(CONFIG_STM32_STM32L15XX)
|
|
|
|
clrbits |= ADC_CCR_MULTI_MASK | ADC_CCR_DELAY_MASK | ADC_CCR_DDS |
|
|
|
|
ADC_CCR_DMA_MASK | ADC_CCR_VBATEN;
|
|
|
|
setbits |= ADC_CCR_MULTI_NONE | ADC_CCR_DMA_DISABLED;
|
2020-01-31 19:07:39 +01:00
|
|
|
#endif /* !defined(CONFIG_STM32_STM32L15XX) */
|
2015-11-05 16:09:37 +01:00
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
adccmn_modifyreg(priv, STM32_ADC_CCR_OFFSET, clrbits, setbits);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static void adc_common_cfg(FAR struct stm32_dev_s *priv)
|
|
|
|
{
|
|
|
|
/* Do nothing here */
|
2015-07-30 16:47:45 +02:00
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
UNUSED(priv);
|
|
|
|
}
|
|
|
|
#endif
|
2015-11-05 16:09:37 +01:00
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
#ifdef ADC_HAVE_DMA
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: adc_dma_cfg
|
|
|
|
****************************************************************************/
|
2015-11-05 16:09:37 +01:00
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
#ifdef HAVE_IP_ADC_V2
|
|
|
|
static void adc_dma_cfg(FAR struct stm32_dev_s *priv)
|
|
|
|
{
|
|
|
|
uint32_t clrbits = 0;
|
|
|
|
uint32_t setbits = 0;
|
2015-11-05 16:09:37 +01:00
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
/* Set DMA mode */
|
2015-11-05 16:09:37 +01:00
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
if (priv->dmacfg == 0)
|
|
|
|
{
|
|
|
|
/* One Shot Mode */
|
|
|
|
|
|
|
|
clrbits |= ADC_CFGR1_DMACFG;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Circular Mode */
|
|
|
|
|
|
|
|
setbits |= ADC_CFGR1_DMACFG;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Enable DMA */
|
|
|
|
|
|
|
|
setbits |= ADC_CFGR1_DMAEN;
|
|
|
|
|
|
|
|
/* Modify CFGR configuration */
|
2011-12-16 01:32:11 +01:00
|
|
|
|
2018-11-12 16:45:55 +01:00
|
|
|
adc_modifyreg(priv, STM32_ADC_CFGR1_OFFSET, clrbits, setbits);
|
2018-12-02 19:34:02 +01:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
static void adc_dma_cfg(FAR struct stm32_dev_s *priv)
|
|
|
|
{
|
|
|
|
uint32_t clrbits = 0;
|
|
|
|
uint32_t setbits = 0;
|
2015-11-05 16:09:37 +01:00
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
#ifdef ADC_HAVE_DMACFG
|
2020-01-03 15:34:44 +01:00
|
|
|
/* Set DMA mode */
|
2015-11-05 16:09:37 +01:00
|
|
|
|
2020-01-03 15:34:44 +01:00
|
|
|
if (priv->dmacfg == 0)
|
|
|
|
{
|
|
|
|
/* One Shot Mode */
|
2015-11-05 16:09:37 +01:00
|
|
|
|
2020-01-03 15:34:44 +01:00
|
|
|
clrbits |= ADC_CR2_DDS;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Circular Mode */
|
2015-11-05 16:09:37 +01:00
|
|
|
|
2020-01-03 15:34:44 +01:00
|
|
|
setbits |= ADC_CR2_DDS;
|
|
|
|
}
|
2018-12-02 19:34:02 +01:00
|
|
|
#endif
|
2015-11-05 16:09:37 +01:00
|
|
|
|
2020-01-03 15:34:44 +01:00
|
|
|
/* Enable DMA */
|
2015-11-05 16:09:37 +01:00
|
|
|
|
2020-01-03 15:34:44 +01:00
|
|
|
setbits |= ADC_CR2_DMA;
|
2015-11-05 16:09:37 +01:00
|
|
|
|
2020-01-03 15:34:44 +01:00
|
|
|
/* Modify CR2 configuration */
|
2015-11-05 16:09:37 +01:00
|
|
|
|
2020-01-03 15:34:44 +01:00
|
|
|
adc_modifyreg(priv, STM32_ADC_CR2_OFFSET, clrbits, setbits);
|
2018-12-02 19:34:02 +01:00
|
|
|
}
|
|
|
|
#endif
|
2015-11-05 16:09:37 +01:00
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: adc_dma_start
|
|
|
|
****************************************************************************/
|
2015-11-05 16:09:37 +01:00
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
static void adc_dma_start(FAR struct adc_dev_s *dev)
|
|
|
|
{
|
|
|
|
FAR struct stm32_dev_s *priv = (FAR struct stm32_dev_s *)dev->ad_priv;
|
|
|
|
|
|
|
|
/* Stop and free DMA if it was started before */
|
|
|
|
|
|
|
|
if (priv->dma != NULL)
|
2015-11-05 16:09:37 +01:00
|
|
|
{
|
2018-12-02 19:34:02 +01:00
|
|
|
stm32_dmastop(priv->dma);
|
|
|
|
stm32_dmafree(priv->dma);
|
2015-11-05 16:09:37 +01:00
|
|
|
}
|
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
priv->dma = stm32_dmachannel(priv->dmachan);
|
2015-11-05 16:09:37 +01:00
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
#ifndef CONFIG_STM32_ADC_NOIRQ
|
2020-04-21 21:35:54 +02:00
|
|
|
/* Start DMA only if standard ADC interrupts used */
|
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
stm32_dmasetup(priv->dma,
|
|
|
|
priv->base + STM32_ADC_DR_OFFSET,
|
|
|
|
(uint32_t)priv->r_dmabuffer,
|
|
|
|
priv->rnchannels,
|
|
|
|
ADC_DMA_CONTROL_WORD);
|
2012-01-02 19:22:19 +01:00
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
stm32_dmastart(priv->dma, adc_dmaconvcallback, dev, false);
|
|
|
|
#endif
|
|
|
|
}
|
2020-01-31 19:07:39 +01:00
|
|
|
#endif /* ADC_HAVE_DMA */
|
2018-11-12 16:45:55 +01:00
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
/****************************************************************************
|
2018-12-09 01:09:01 +01:00
|
|
|
* Name: adc_configure
|
2018-12-02 19:34:02 +01:00
|
|
|
****************************************************************************/
|
2018-11-12 16:45:55 +01:00
|
|
|
|
2018-12-09 01:09:01 +01:00
|
|
|
static void adc_configure(FAR struct adc_dev_s *dev)
|
2018-12-02 19:34:02 +01:00
|
|
|
{
|
|
|
|
FAR struct stm32_dev_s *priv = (FAR struct stm32_dev_s *)dev->ad_priv;
|
2015-07-29 16:34:27 +02:00
|
|
|
|
2018-12-09 01:09:01 +01:00
|
|
|
/* Turn off the ADC before configuration */
|
2012-03-10 01:02:11 +01:00
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
adc_enable(priv, false);
|
2018-11-24 00:33:45 +01:00
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
/* Configure voltage regulator if present */
|
2018-11-24 00:33:45 +01:00
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
adc_voltreg_cfg(priv);
|
2018-11-24 00:33:45 +01:00
|
|
|
|
2020-02-22 19:31:14 +01:00
|
|
|
/* Calibrate ADC - doesn't work for now */
|
2018-11-24 00:33:45 +01:00
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
adc_calibrate(priv);
|
2015-07-30 16:47:45 +02:00
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
/* Initialize the ADC watchdog */
|
2011-12-14 01:34:12 +01:00
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
adc_watchdog_cfg(priv);
|
2015-10-07 21:45:15 +02:00
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
/* Initialize the ADC sample time */
|
|
|
|
|
|
|
|
adc_sampletime_cfg(dev);
|
|
|
|
|
|
|
|
/* Set ADC working mode */
|
|
|
|
|
|
|
|
adc_mode_cfg(priv);
|
2012-03-10 01:02:11 +01:00
|
|
|
|
2015-11-05 16:09:37 +01:00
|
|
|
/* Configuration of the channel conversions */
|
2012-01-04 00:25:49 +01:00
|
|
|
|
2018-11-24 00:33:45 +01:00
|
|
|
if (priv->cr_channels > 0)
|
|
|
|
{
|
|
|
|
adc_set_ch(dev, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef ADC_HAVE_INJECTED
|
|
|
|
/* Configuration of the injected channel conversions after adc enabled */
|
|
|
|
|
|
|
|
if (priv->cj_channels > 0)
|
|
|
|
{
|
|
|
|
adc_inj_set_ch(dev, 0);
|
|
|
|
}
|
|
|
|
#endif
|
2015-07-29 16:34:27 +02:00
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
/* ADC common register configuration */
|
2011-12-15 01:29:35 +01:00
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
adc_common_cfg(priv);
|
2012-03-10 01:02:11 +01:00
|
|
|
|
2015-07-30 16:47:45 +02:00
|
|
|
#ifdef ADC_HAVE_DMA
|
2018-12-02 19:34:02 +01:00
|
|
|
/* Configure ADC DMA if enabled */
|
2015-07-30 16:47:45 +02:00
|
|
|
|
|
|
|
if (priv->hasdma)
|
|
|
|
{
|
2018-12-02 19:34:02 +01:00
|
|
|
/* Configure ADC DMA */
|
2015-07-30 16:47:45 +02:00
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
adc_dma_cfg(priv);
|
2015-07-30 16:47:45 +02:00
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
/* Start ADC DMA */
|
2015-07-30 16:47:45 +02:00
|
|
|
|
2018-12-02 19:34:02 +01:00
|
|
|
adc_dma_start(dev);
|
2015-07-30 16:47:45 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-11-12 16:45:55 +01:00
|
|
|
#ifdef HAVE_ADC_RESOLUTION
|
|
|
|
/* Configure ADC resolution */
|
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
adc_resolution_set(dev, priv->resolution);
|
2018-11-12 16:45:55 +01:00
|
|
|
#endif
|
|
|
|
|
2018-11-24 00:33:45 +01:00
|
|
|
#ifdef ADC_HAVE_EXTCFG
|
|
|
|
/* Configure external event for regular group */
|
|
|
|
|
|
|
|
adc_extcfg_set(dev, priv->extcfg);
|
|
|
|
#endif
|
|
|
|
|
2019-01-27 17:17:39 +01:00
|
|
|
/* Enable ADC */
|
|
|
|
|
|
|
|
adc_enable(priv, true);
|
|
|
|
|
2018-11-24 00:33:45 +01:00
|
|
|
#ifdef ADC_HAVE_JEXTCFG
|
2019-01-27 17:17:39 +01:00
|
|
|
/* Configure external event for injected group when ADC enabled */
|
2018-11-24 00:33:45 +01:00
|
|
|
|
|
|
|
adc_jextcfg_set(dev, priv->jextcfg);
|
|
|
|
|
2019-01-27 17:17:39 +01:00
|
|
|
#if defined(HAVE_IP_ADC_V2)
|
|
|
|
/* For ADC IPv2 there is queue of context for injected conversion.
|
|
|
|
* JEXTCFG configuration is the second write to JSQR register which means
|
|
|
|
* configuration is stored on queue.
|
|
|
|
* We trigger single INJ conversion here to update context.
|
|
|
|
*/
|
2018-12-02 19:34:02 +01:00
|
|
|
|
2019-01-27 17:17:39 +01:00
|
|
|
adc_inj_startconv(priv, true);
|
|
|
|
#endif
|
|
|
|
#endif
|
2018-12-02 19:34:02 +01:00
|
|
|
|
2018-12-09 01:09:01 +01:00
|
|
|
/* Dump regs */
|
2018-11-12 16:45:55 +01:00
|
|
|
|
2018-12-09 01:09:01 +01:00
|
|
|
adc_dumpregs(priv);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: adc_reset
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Reset the ADC device. Called early to initialize the hardware.
|
|
|
|
* This is called, before adc_setup() and on error conditions.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void adc_reset(FAR struct adc_dev_s *dev)
|
|
|
|
{
|
|
|
|
FAR struct stm32_dev_s *priv = (FAR struct stm32_dev_s *)dev->ad_priv;
|
|
|
|
irqstate_t flags;
|
|
|
|
|
|
|
|
ainfo("intf: %d\n", priv->intf);
|
|
|
|
flags = enter_critical_section();
|
|
|
|
|
|
|
|
#ifdef HAVE_HSI_CONTROL
|
|
|
|
/* The STM32L15XX family uses HSI as an independent clock-source
|
|
|
|
* for the ADC
|
|
|
|
*/
|
|
|
|
|
|
|
|
adc_enable_hsi(true);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(HAVE_IP_ADC_V2)
|
|
|
|
/* Turn off the ADC so we can write the RCC bits */
|
|
|
|
|
|
|
|
adc_enable(priv, false);
|
2015-11-05 16:09:37 +01:00
|
|
|
#endif
|
2018-12-09 01:09:01 +01:00
|
|
|
|
|
|
|
/* Only if this is the first initialzied ADC instance in the ADC block */
|
|
|
|
|
|
|
|
#ifdef HAVE_ADC_CMN_DATA
|
nuttx: Fix the nightly build warning
lpc2148_spi1.c:142:24: warning: initialization of 'uint32_t (*)(struct spi_dev_s *, uint32_t)' {aka 'unsigned int (*)(struct spi_dev_s *, unsigned int)'} from incompatible pointer type 'uint16_t (*)(struct spi_dev_s *, uint16_t)' {aka 'short unsigned int (*)(struct spi_dev_s *, short unsigned int)'} [-Wincompatible-pointer-types]
142 | .send = spi_send,
| ^~~~~~~~
lpc2148_spi1.c:142:24: note: (near initialization for 'g_spiops.send')
In file included from ieee802154/mac802154_bind.c:49:
ieee802154/mac802154_internal.h: In function 'mac802154_setdevmode':
ieee802154/mac802154_internal.h:788:42: warning: converting a packed 'enum ieee802154_devmode_e' pointer (alignment 1) to a 'const union ieee802154_attr_u' pointer (alignment 4) may result in an unaligned pointer value [-Waddress-of-packed-member]
788 | (FAR const union ieee802154_attr_u *)&mode);
| ^~~~~~~~~~~~~~~~~
chip/stm32_hciuart.c: In function 'hciuart_read':
chip/stm32_hciuart.c:2104:30: warning: statement with no effect [-Wunused-value]
2104 | ntotal == (ssize_t)ret;
| ~~~~~~~^~~~~~~~~~~~~~~
wireless/ieee80211/bcm43xxx/bcmf_driver.c: In function 'bcmf_wl_auth_event_handler':
wireless/ieee80211/bcm43xxx/bcmf_driver.c:579:23: warning: taking address of packed member of 'struct bcmf_event_s' may result in an unaligned pointer value [-Waddress-of-packed-member]
579 | type = bcmf_getle32(&event->type);
| ^~~~~~~~~~~~
wireless/ieee80211/bcm43xxx/bcmf_driver.c:580:25: warning: taking address of packed member of 'struct bcmf_event_s' may result in an unaligned pointer value [-Waddress-of-packed-member]
580 | status = bcmf_getle32(&event->status);
| ^~~~~~~~~~~~~~
wireless/ieee80211/bcm43xxx/bcmf_driver.c: In function 'bcmf_wl_scan_event_handler':
wireless/ieee80211/bcm43xxx/bcmf_driver.c:619:25: warning: taking address of packed member of 'struct bcmf_event_s' may result in an unaligned pointer value [-Waddress-of-packed-member]
619 | status = bcmf_getle32(&event->status);
| ^~~~~~~~~~~~~~
wireless/ieee80211/bcm43xxx/bcmf_driver.c:620:35: warning: taking address of packed member of 'struct bcmf_event_s' may result in an unaligned pointer value [-Waddress-of-packed-member]
620 | escan_result_len = bcmf_getle32(&event->len);
| ^~~~~~~~~~~
wireless/ieee80211/bcm43xxx/bcmf_bdc.c: In function 'bcmf_bdc_process_event_frame':
wireless/ieee80211/bcm43xxx/bcmf_bdc.c:166:27: warning: taking address of packed member of 'struct bcmf_event_s' may result in an unaligned pointer value [-Waddress-of-packed-member]
166 | event_id = bcmf_getle32(&event_msg->event.type);
| ^~~~~~~~~~~~~~~~~~~~~~
wireless/ieee80211/bcm43xxx/mmc_sdio.c: In function 'sdio_io_rw_direct':
wireless/ieee80211/bcm43xxx/mmc_sdio.c:157:3: warning: converting a packed 'struct sdio_resp_R5' pointer (alignment 1) to a 'uint32_t' {aka 'unsigned int'} pointer (alignment 4) may result in an unaligned pointer value [-Waddress-of-packed-member]
157 | ret = SDIO_RECVR5(dev, SD_ACMD52, (uint32_t *)&resp);
| ^~~
wireless/ieee80211/bcm43xxx/mmc_sdio.c:79:28: note: defined here
79 | begin_packed_struct struct sdio_resp_R5
| ^~~~~~~~~~~~
wireless/ieee80211/bcm43xxx/mmc_sdio.c: In function 'sdio_io_rw_extended':
wireless/ieee80211/bcm43xxx/mmc_sdio.c:239:11: warning: converting a packed 'struct sdio_resp_R5' pointer (alignment 1) to a 'uint32_t' {aka 'unsigned int'} pointer (alignment 4) may result in an unaligned pointer value [-Waddress-of-packed-member]
239 | ret = SDIO_RECVR5(dev, SD_ACMD53, (uint32_t *)&resp);
| ^~~
wireless/ieee80211/bcm43xxx/mmc_sdio.c:79:28: note: defined here
79 | begin_packed_struct struct sdio_resp_R5
| ^~~~~~~~~~~~
wireless/ieee80211/bcm43xxx/mmc_sdio.c:244:11: warning: converting a packed 'struct sdio_resp_R5' pointer (alignment 1) to a 'uint32_t' {aka 'unsigned int'} pointer (alignment 4) may result in an unaligned pointer value [-Waddress-of-packed-member]
244 | ret = SDIO_RECVR5(dev, SD_ACMD53, (uint32_t *)&resp);
| ^~~
wireless/ieee80211/bcm43xxx/mmc_sdio.c:79:28: note: defined here
79 | begin_packed_struct struct sdio_resp_R5
| ^~~~~~~~~~~~
wireless/ieee80211/bcm43xxx/mmc_sdio.c:257:7: warning: converting a packed 'struct sdio_resp_R5' pointer (alignment 1) to a 'uint32_t' {aka 'unsigned int'} pointer (alignment 4) may result in an unaligned pointer value [-Waddress-of-packed-member]
257 | ret = SDIO_RECVR5(dev, SD_ACMD53, (uint32_t *)&resp);
| ^~~
wireless/ieee80211/bcm43xxx/mmc_sdio.c:79:28: note: defined here
79 | begin_packed_struct struct sdio_resp_R5
| ^~~~~~~~~~~~
wireless/ieee80211/bcm43xxx/mmc_sdio.c:265:3: warning: converting a packed 'struct sdio_resp_R5' pointer (alignment 1) to a 'uint32_t' {aka 'unsigned int'} pointer (alignment 4) may result in an unaligned pointer value [-Waddress-of-packed-member]
265 | SDIO_RECVR1(dev, SD_ACMD52ABRT, (uint32_t *)&resp);
| ^~~~~~~~~~~
wireless/ieee80211/bcm43xxx/mmc_sdio.c:79:28: note: defined here
79 | begin_packed_struct struct sdio_resp_R5
| ^~~~~~~~~~~~
chip/stm32_adc.c: In function 'adc_reset':
chip/stm32_adc.c:2860:7: warning: unused variable 'ret' [-Wunused-variable]
2860 | int ret;
| ^~~
chip/stm32_adc.c: In function 'adc_shutdown':
chip/stm32_adc.c:3044:7: warning: unused variable 'ret' [-Wunused-variable]
3044 | int ret;
| ^~~
chip/stm32_i2c.c:722:12: warning: 'stm32_i2c_sem_wait_noncancelable' defined but not used [-Wunused-function]
722 | static int stm32_i2c_sem_wait_noncancelable(FAR struct i2c_master_s *dev)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
wireless/gs2200m.c: In function 'gs2200m_read':
wireless/gs2200m.c:727:20: warning: passing argument 1 of 'nxsem_wait' from incompatible pointer type [-Wincompatible-pointer-types]
727 | ret = nxsem_wait(dev);
| ^~~
| |
| struct gs2200m_dev_s *
.config:1207:warning: symbol value '' invalid for TESTING_OSTEST_FPUSIZE
platform/audio/cxd56_audio_analog.c:69:13: warning: inline function 'cxd56_audio_clock_is_enabled' declared but never defined
69 | inline bool cxd56_audio_clock_is_enabled(void);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
platform/audio/cxd56_audio_analog.c:68:13: warning: inline function 'cxd56_audio_clock_disable' declared but never defined
68 | inline void cxd56_audio_clock_disable(void);
| ^~~~~~~~~~~~~~~~~~~~~~~~~
platform/audio/cxd56_audio_analog.c:67:13: warning: inline function 'cxd56_audio_clock_enable' declared but never defined
67 | inline void cxd56_audio_clock_enable(uint32_t clk, uint32_t div);
| ^~~~~~~~~~~~~~~~~~~~~~~~
chip/stm32_adc.c: In function 'adc_reset':
chip/stm32_adc.c:1348:7: warning: unused variable 'ret' [-Wunused-variable]
1348 | int ret;
| ^~~
chip/stm32_adc.c: In function 'adc_shutdown':
chip/stm32_adc.c:1496:7: warning: unused variable 'ret' [-Wunused-variable]
1496 | int ret;
| ^~~
chip/stm32_i2c.c:729:12: warning: 'stm32_i2c_sem_wait_uninterruptble' defined but not used [-Wunused-function]
729 | static int stm32_i2c_sem_wait_uninterruptble(FAR struct i2c_master_s *dev)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
wireless/lpwan/sx127x/sx127x.c:147:52: warning: missing terminating ' character
147 | # warning OOK support is not complete, RX+TX doesn't work yet!
| ^
str71_spi.c:435:24: warning: initialization of 'uint32_t (*)(struct spi_dev_s *, uint32_t)' {aka 'unsigned int (*)(struct spi_dev_s *, unsigned int)'} from incompatible pointer type
'uint16_t (*)(struct spi_dev_s *, uint16_t)' {aka 'short unsigned int (*)(struct spi_dev_s *, short unsigned int)'} [-Wincompatible-pointer-types]
435 | .send = spi_send,
| ^~~~~~~~
str71_spi.c:435:24: note: (near initialization for 'g_spiops.send')
chip/pic32mx-lowconsole.c:147:24: warning: 'pic32mx_getreg' defined but not used [-Wunused-function]
static inline uint32_t pic32mx_getreg(uintptr_t uart_base,
^
chip/pic32mx-gpio.c:113:20: warning: 'pic32mx_value' defined but not used [-Wunused-function]
static inline bool pic32mx_value(uint16_t pinset)
^
chip/pic32mz-gpio.c:124:20: warning: 'pic32mz_value' defined but not used [-Wunused-function]
static inline bool pic32mz_value(pinset_t pinset)
^
chip/pic32mx-usbdev.c:3065:1: warning: 'pic32mx_epreserved' defined but not used [-Wunused-function]
pic32mx_epreserved(struct pic32mx_usbdev_s *priv, int epno)
^
mmcsd/mmcsd_spi.c: In function 'mmcsd_mediachanged':
mmcsd/mmcsd_spi.c:1938:7: warning: 'return' with a value, in function returning void
return ret;
^
In file included from partition/fs_partition.c:42:0:
partition/partition.h:66:19: warning: 'read_partition_block' defined but not used [-Wunused-function]
static inline int read_partition_block(FAR struct partition_state_s *state,
^
local/local_netpoll.c: In function 'local_pollsetup':
local/local_netpoll.c:305:1: warning: label 'pollerr' defined but not used [-Wunused-label]
pollerr:
^~~~~~~
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: If3ea8f32b878aa218072130f7c3018f0d3c1aca5
2020-04-12 15:52:28 +02:00
|
|
|
if (adccmn_lock(priv, true) < 0)
|
2020-04-03 01:10:26 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2018-12-09 01:09:01 +01:00
|
|
|
|
|
|
|
if (priv->cmn->initialized == 0)
|
2015-11-05 16:09:37 +01:00
|
|
|
#endif
|
|
|
|
{
|
2018-12-09 01:09:01 +01:00
|
|
|
/* Enable ADC reset state */
|
2018-11-24 00:33:45 +01:00
|
|
|
|
2018-12-09 01:09:01 +01:00
|
|
|
adc_rccreset(priv, true);
|
|
|
|
|
|
|
|
/* Release ADC from reset state */
|
|
|
|
|
|
|
|
adc_rccreset(priv, false);
|
2015-11-05 16:09:37 +01:00
|
|
|
}
|
2018-12-09 01:09:01 +01:00
|
|
|
|
|
|
|
#ifdef HAVE_ADC_CMN_DATA
|
|
|
|
adccmn_lock(priv, false);
|
2015-11-05 16:09:37 +01:00
|
|
|
#endif
|
2011-12-21 00:44:21 +01:00
|
|
|
|
2016-02-14 02:11:09 +01:00
|
|
|
leave_critical_section(flags);
|
2018-11-24 00:33:45 +01:00
|
|
|
}
|
2011-12-12 02:04:53 +01:00
|
|
|
|
2015-07-29 16:34:27 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: adc_reset_hsi_disable
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Reset the ADC device with HSI and ADC shut down. Called early to
|
|
|
|
* initialize the hardware. This is called, before adc_setup() and on
|
|
|
|
* error conditions. In STM32L15XX case sometimes HSI must be shut
|
|
|
|
* down after the first initialization
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-11-12 16:45:55 +01:00
|
|
|
#ifdef HAVE_HSI_CONTROL
|
2015-07-29 16:34:27 +02:00
|
|
|
static void adc_reset_hsi_disable(FAR struct adc_dev_s *dev)
|
|
|
|
{
|
|
|
|
adc_reset(dev);
|
|
|
|
adc_shutdown(dev);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-12-12 02:04:53 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: adc_setup
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Configure the ADC. This method is called the first time that the ADC
|
|
|
|
* device is opened. This will occur when the port is first opened.
|
2015-11-05 16:09:37 +01:00
|
|
|
* This setup includes configuring and attaching ADC interrupts.
|
|
|
|
* Interrupts are all disabled upon return.
|
2011-12-12 02:04:53 +01:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int adc_setup(FAR struct adc_dev_s *dev)
|
|
|
|
{
|
2018-12-09 01:09:01 +01:00
|
|
|
#if !defined(CONFIG_STM32_ADC_NOIRQ) || defined(HAVE_ADC_CMN_DATA) || \
|
|
|
|
defined(ADC_HAVE_TIMER) || !defined(CONFIG_STM32_ADC_NO_STARTUP_CONV)
|
2011-12-12 02:04:53 +01:00
|
|
|
FAR struct stm32_dev_s *priv = (FAR struct stm32_dev_s *)dev->ad_priv;
|
2018-11-24 00:33:45 +01:00
|
|
|
#endif
|
|
|
|
int ret = OK;
|
2011-12-16 01:32:11 +01:00
|
|
|
|
2011-12-12 02:04:53 +01:00
|
|
|
/* Attach the ADC interrupt */
|
|
|
|
|
2018-11-24 00:33:45 +01:00
|
|
|
#ifndef CONFIG_STM32_ADC_NOIRQ
|
2017-02-27 13:27:56 +01:00
|
|
|
ret = irq_attach(priv->irq, priv->isr, NULL);
|
2015-11-05 16:09:37 +01:00
|
|
|
if (ret < 0)
|
2011-12-12 02:04:53 +01:00
|
|
|
{
|
2016-06-11 19:59:51 +02:00
|
|
|
ainfo("irq_attach failed: %d\n", ret);
|
2015-11-05 16:09:37 +01:00
|
|
|
return ret;
|
|
|
|
}
|
2018-11-24 00:33:45 +01:00
|
|
|
#endif
|
2012-10-21 18:53:38 +02:00
|
|
|
|
2015-11-05 16:09:37 +01:00
|
|
|
/* Make sure that the ADC device is in the powered up, reset state */
|
2012-10-21 18:53:38 +02:00
|
|
|
|
2015-11-05 16:09:37 +01:00
|
|
|
adc_reset(dev);
|
2011-12-12 02:04:53 +01:00
|
|
|
|
2018-12-09 01:09:01 +01:00
|
|
|
/* Configure ADC device */
|
|
|
|
|
|
|
|
adc_configure(dev);
|
|
|
|
|
|
|
|
#ifdef ADC_HAVE_TIMER
|
|
|
|
/* Configure timer */
|
|
|
|
|
|
|
|
if (priv->tbase != 0)
|
|
|
|
{
|
|
|
|
ret = adc_timinit(priv);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
aerr("ERROR: adc_timinit failed: %d\n", ret);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* As default conversion is started here.
|
|
|
|
*
|
|
|
|
* NOTE: for ADC IPv2 (J)ADSTART bit must be set to start ADC conversion
|
|
|
|
* even if hardware trigger is selected.
|
|
|
|
* This can be done here during the opening of the ADC device
|
|
|
|
* or later with ANIOC_TRIGGER ioctl call.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CONFIG_STM32_ADC_NO_STARTUP_CONV
|
|
|
|
/* Start regular conversion */
|
|
|
|
|
|
|
|
adc_reg_startconv(priv, true);
|
|
|
|
|
|
|
|
# ifdef ADC_HAVE_INJECTED
|
|
|
|
/* Start injected conversion */
|
|
|
|
|
|
|
|
adc_inj_startconv(priv, true);
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2015-11-05 16:09:37 +01:00
|
|
|
/* Enable the ADC interrupt */
|
|
|
|
|
2018-11-24 00:33:45 +01:00
|
|
|
#ifndef CONFIG_STM32_ADC_NOIRQ
|
2016-06-11 19:59:51 +02:00
|
|
|
ainfo("Enable the ADC interrupt: irq=%d\n", priv->irq);
|
2015-11-05 16:09:37 +01:00
|
|
|
up_enable_irq(priv->irq);
|
2018-11-24 00:33:45 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_ADC_CMN_DATA
|
|
|
|
/* Increase instances counter */
|
|
|
|
|
2020-04-03 01:10:26 +02:00
|
|
|
ret = adccmn_lock(priv, true);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-11-24 00:33:45 +01:00
|
|
|
priv->cmn->initialized += 1;
|
|
|
|
adccmn_lock(priv, false);
|
|
|
|
#endif
|
2011-12-15 01:29:35 +01:00
|
|
|
|
2011-12-12 02:04:53 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: adc_shutdown
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Disable the ADC. This method is called when the ADC device is closed.
|
|
|
|
* This method reverses the operation the setup method.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void adc_shutdown(FAR struct adc_dev_s *dev)
|
|
|
|
{
|
|
|
|
FAR struct stm32_dev_s *priv = (FAR struct stm32_dev_s *)dev->ad_priv;
|
|
|
|
|
2018-11-24 00:33:45 +01:00
|
|
|
/* Disable ADC */
|
|
|
|
|
2015-07-29 16:34:27 +02:00
|
|
|
adc_enable(priv, false);
|
2018-11-24 00:33:45 +01:00
|
|
|
|
2018-11-12 16:45:55 +01:00
|
|
|
#ifdef HAVE_HSI_CONTROL
|
2015-11-05 16:09:37 +01:00
|
|
|
adc_enable_hsi(false);
|
2015-07-29 16:34:27 +02:00
|
|
|
#endif
|
|
|
|
|
2018-11-24 00:33:45 +01:00
|
|
|
#ifndef CONFIG_STM32_ADC_NOIRQ
|
2011-12-12 02:04:53 +01:00
|
|
|
/* Disable ADC interrupts and detach the ADC interrupt handler */
|
|
|
|
|
|
|
|
up_disable_irq(priv->irq);
|
|
|
|
irq_detach(priv->irq);
|
2018-11-24 00:33:45 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_ADC_CMN_DATA
|
nuttx: Fix the nightly build warning
lpc2148_spi1.c:142:24: warning: initialization of 'uint32_t (*)(struct spi_dev_s *, uint32_t)' {aka 'unsigned int (*)(struct spi_dev_s *, unsigned int)'} from incompatible pointer type 'uint16_t (*)(struct spi_dev_s *, uint16_t)' {aka 'short unsigned int (*)(struct spi_dev_s *, short unsigned int)'} [-Wincompatible-pointer-types]
142 | .send = spi_send,
| ^~~~~~~~
lpc2148_spi1.c:142:24: note: (near initialization for 'g_spiops.send')
In file included from ieee802154/mac802154_bind.c:49:
ieee802154/mac802154_internal.h: In function 'mac802154_setdevmode':
ieee802154/mac802154_internal.h:788:42: warning: converting a packed 'enum ieee802154_devmode_e' pointer (alignment 1) to a 'const union ieee802154_attr_u' pointer (alignment 4) may result in an unaligned pointer value [-Waddress-of-packed-member]
788 | (FAR const union ieee802154_attr_u *)&mode);
| ^~~~~~~~~~~~~~~~~
chip/stm32_hciuart.c: In function 'hciuart_read':
chip/stm32_hciuart.c:2104:30: warning: statement with no effect [-Wunused-value]
2104 | ntotal == (ssize_t)ret;
| ~~~~~~~^~~~~~~~~~~~~~~
wireless/ieee80211/bcm43xxx/bcmf_driver.c: In function 'bcmf_wl_auth_event_handler':
wireless/ieee80211/bcm43xxx/bcmf_driver.c:579:23: warning: taking address of packed member of 'struct bcmf_event_s' may result in an unaligned pointer value [-Waddress-of-packed-member]
579 | type = bcmf_getle32(&event->type);
| ^~~~~~~~~~~~
wireless/ieee80211/bcm43xxx/bcmf_driver.c:580:25: warning: taking address of packed member of 'struct bcmf_event_s' may result in an unaligned pointer value [-Waddress-of-packed-member]
580 | status = bcmf_getle32(&event->status);
| ^~~~~~~~~~~~~~
wireless/ieee80211/bcm43xxx/bcmf_driver.c: In function 'bcmf_wl_scan_event_handler':
wireless/ieee80211/bcm43xxx/bcmf_driver.c:619:25: warning: taking address of packed member of 'struct bcmf_event_s' may result in an unaligned pointer value [-Waddress-of-packed-member]
619 | status = bcmf_getle32(&event->status);
| ^~~~~~~~~~~~~~
wireless/ieee80211/bcm43xxx/bcmf_driver.c:620:35: warning: taking address of packed member of 'struct bcmf_event_s' may result in an unaligned pointer value [-Waddress-of-packed-member]
620 | escan_result_len = bcmf_getle32(&event->len);
| ^~~~~~~~~~~
wireless/ieee80211/bcm43xxx/bcmf_bdc.c: In function 'bcmf_bdc_process_event_frame':
wireless/ieee80211/bcm43xxx/bcmf_bdc.c:166:27: warning: taking address of packed member of 'struct bcmf_event_s' may result in an unaligned pointer value [-Waddress-of-packed-member]
166 | event_id = bcmf_getle32(&event_msg->event.type);
| ^~~~~~~~~~~~~~~~~~~~~~
wireless/ieee80211/bcm43xxx/mmc_sdio.c: In function 'sdio_io_rw_direct':
wireless/ieee80211/bcm43xxx/mmc_sdio.c:157:3: warning: converting a packed 'struct sdio_resp_R5' pointer (alignment 1) to a 'uint32_t' {aka 'unsigned int'} pointer (alignment 4) may result in an unaligned pointer value [-Waddress-of-packed-member]
157 | ret = SDIO_RECVR5(dev, SD_ACMD52, (uint32_t *)&resp);
| ^~~
wireless/ieee80211/bcm43xxx/mmc_sdio.c:79:28: note: defined here
79 | begin_packed_struct struct sdio_resp_R5
| ^~~~~~~~~~~~
wireless/ieee80211/bcm43xxx/mmc_sdio.c: In function 'sdio_io_rw_extended':
wireless/ieee80211/bcm43xxx/mmc_sdio.c:239:11: warning: converting a packed 'struct sdio_resp_R5' pointer (alignment 1) to a 'uint32_t' {aka 'unsigned int'} pointer (alignment 4) may result in an unaligned pointer value [-Waddress-of-packed-member]
239 | ret = SDIO_RECVR5(dev, SD_ACMD53, (uint32_t *)&resp);
| ^~~
wireless/ieee80211/bcm43xxx/mmc_sdio.c:79:28: note: defined here
79 | begin_packed_struct struct sdio_resp_R5
| ^~~~~~~~~~~~
wireless/ieee80211/bcm43xxx/mmc_sdio.c:244:11: warning: converting a packed 'struct sdio_resp_R5' pointer (alignment 1) to a 'uint32_t' {aka 'unsigned int'} pointer (alignment 4) may result in an unaligned pointer value [-Waddress-of-packed-member]
244 | ret = SDIO_RECVR5(dev, SD_ACMD53, (uint32_t *)&resp);
| ^~~
wireless/ieee80211/bcm43xxx/mmc_sdio.c:79:28: note: defined here
79 | begin_packed_struct struct sdio_resp_R5
| ^~~~~~~~~~~~
wireless/ieee80211/bcm43xxx/mmc_sdio.c:257:7: warning: converting a packed 'struct sdio_resp_R5' pointer (alignment 1) to a 'uint32_t' {aka 'unsigned int'} pointer (alignment 4) may result in an unaligned pointer value [-Waddress-of-packed-member]
257 | ret = SDIO_RECVR5(dev, SD_ACMD53, (uint32_t *)&resp);
| ^~~
wireless/ieee80211/bcm43xxx/mmc_sdio.c:79:28: note: defined here
79 | begin_packed_struct struct sdio_resp_R5
| ^~~~~~~~~~~~
wireless/ieee80211/bcm43xxx/mmc_sdio.c:265:3: warning: converting a packed 'struct sdio_resp_R5' pointer (alignment 1) to a 'uint32_t' {aka 'unsigned int'} pointer (alignment 4) may result in an unaligned pointer value [-Waddress-of-packed-member]
265 | SDIO_RECVR1(dev, SD_ACMD52ABRT, (uint32_t *)&resp);
| ^~~~~~~~~~~
wireless/ieee80211/bcm43xxx/mmc_sdio.c:79:28: note: defined here
79 | begin_packed_struct struct sdio_resp_R5
| ^~~~~~~~~~~~
chip/stm32_adc.c: In function 'adc_reset':
chip/stm32_adc.c:2860:7: warning: unused variable 'ret' [-Wunused-variable]
2860 | int ret;
| ^~~
chip/stm32_adc.c: In function 'adc_shutdown':
chip/stm32_adc.c:3044:7: warning: unused variable 'ret' [-Wunused-variable]
3044 | int ret;
| ^~~
chip/stm32_i2c.c:722:12: warning: 'stm32_i2c_sem_wait_noncancelable' defined but not used [-Wunused-function]
722 | static int stm32_i2c_sem_wait_noncancelable(FAR struct i2c_master_s *dev)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
wireless/gs2200m.c: In function 'gs2200m_read':
wireless/gs2200m.c:727:20: warning: passing argument 1 of 'nxsem_wait' from incompatible pointer type [-Wincompatible-pointer-types]
727 | ret = nxsem_wait(dev);
| ^~~
| |
| struct gs2200m_dev_s *
.config:1207:warning: symbol value '' invalid for TESTING_OSTEST_FPUSIZE
platform/audio/cxd56_audio_analog.c:69:13: warning: inline function 'cxd56_audio_clock_is_enabled' declared but never defined
69 | inline bool cxd56_audio_clock_is_enabled(void);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
platform/audio/cxd56_audio_analog.c:68:13: warning: inline function 'cxd56_audio_clock_disable' declared but never defined
68 | inline void cxd56_audio_clock_disable(void);
| ^~~~~~~~~~~~~~~~~~~~~~~~~
platform/audio/cxd56_audio_analog.c:67:13: warning: inline function 'cxd56_audio_clock_enable' declared but never defined
67 | inline void cxd56_audio_clock_enable(uint32_t clk, uint32_t div);
| ^~~~~~~~~~~~~~~~~~~~~~~~
chip/stm32_adc.c: In function 'adc_reset':
chip/stm32_adc.c:1348:7: warning: unused variable 'ret' [-Wunused-variable]
1348 | int ret;
| ^~~
chip/stm32_adc.c: In function 'adc_shutdown':
chip/stm32_adc.c:1496:7: warning: unused variable 'ret' [-Wunused-variable]
1496 | int ret;
| ^~~
chip/stm32_i2c.c:729:12: warning: 'stm32_i2c_sem_wait_uninterruptble' defined but not used [-Wunused-function]
729 | static int stm32_i2c_sem_wait_uninterruptble(FAR struct i2c_master_s *dev)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
wireless/lpwan/sx127x/sx127x.c:147:52: warning: missing terminating ' character
147 | # warning OOK support is not complete, RX+TX doesn't work yet!
| ^
str71_spi.c:435:24: warning: initialization of 'uint32_t (*)(struct spi_dev_s *, uint32_t)' {aka 'unsigned int (*)(struct spi_dev_s *, unsigned int)'} from incompatible pointer type
'uint16_t (*)(struct spi_dev_s *, uint16_t)' {aka 'short unsigned int (*)(struct spi_dev_s *, short unsigned int)'} [-Wincompatible-pointer-types]
435 | .send = spi_send,
| ^~~~~~~~
str71_spi.c:435:24: note: (near initialization for 'g_spiops.send')
chip/pic32mx-lowconsole.c:147:24: warning: 'pic32mx_getreg' defined but not used [-Wunused-function]
static inline uint32_t pic32mx_getreg(uintptr_t uart_base,
^
chip/pic32mx-gpio.c:113:20: warning: 'pic32mx_value' defined but not used [-Wunused-function]
static inline bool pic32mx_value(uint16_t pinset)
^
chip/pic32mz-gpio.c:124:20: warning: 'pic32mz_value' defined but not used [-Wunused-function]
static inline bool pic32mz_value(pinset_t pinset)
^
chip/pic32mx-usbdev.c:3065:1: warning: 'pic32mx_epreserved' defined but not used [-Wunused-function]
pic32mx_epreserved(struct pic32mx_usbdev_s *priv, int epno)
^
mmcsd/mmcsd_spi.c: In function 'mmcsd_mediachanged':
mmcsd/mmcsd_spi.c:1938:7: warning: 'return' with a value, in function returning void
return ret;
^
In file included from partition/fs_partition.c:42:0:
partition/partition.h:66:19: warning: 'read_partition_block' defined but not used [-Wunused-function]
static inline int read_partition_block(FAR struct partition_state_s *state,
^
local/local_netpoll.c: In function 'local_pollsetup':
local/local_netpoll.c:305:1: warning: label 'pollerr' defined but not used [-Wunused-label]
pollerr:
^~~~~~~
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: If3ea8f32b878aa218072130f7c3018f0d3c1aca5
2020-04-12 15:52:28 +02:00
|
|
|
if (adccmn_lock(priv, true) < 0)
|
2020-04-03 01:10:26 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2011-12-12 02:04:53 +01:00
|
|
|
|
2018-11-24 00:33:45 +01:00
|
|
|
if (priv->cmn->initialized <= 1)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
/* Disable and reset the ADC module.
|
|
|
|
*
|
|
|
|
* NOTE: The ADC block will be reset to its reset state only if all
|
2020-04-03 01:10:26 +02:00
|
|
|
* ADC block instances are closed. This means that the closed
|
|
|
|
* ADC may not be reset which in turn may affect low-power
|
|
|
|
* applications. (But ADC is turned off here, is not that
|
|
|
|
* enough?)
|
2018-11-24 00:33:45 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
adc_rccreset(priv, true);
|
|
|
|
}
|
2011-12-22 01:31:47 +01:00
|
|
|
|
2018-12-09 01:09:01 +01:00
|
|
|
#ifdef ADC_HAVE_TIMER
|
|
|
|
/* Disable timer */
|
|
|
|
|
|
|
|
if (priv->tbase != 0)
|
|
|
|
{
|
|
|
|
adc_timstart(priv, false);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-11-24 00:33:45 +01:00
|
|
|
#ifdef HAVE_ADC_CMN_DATA
|
|
|
|
/* Decrease instances counter */
|
|
|
|
|
|
|
|
priv->cmn->initialized -= 1;
|
|
|
|
|
|
|
|
adccmn_lock(priv, false);
|
|
|
|
#endif
|
2011-12-12 02:04:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: adc_rxint
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Call to enable or disable RX interrupts.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void adc_rxint(FAR struct adc_dev_s *dev, bool enable)
|
|
|
|
{
|
|
|
|
FAR struct stm32_dev_s *priv = (FAR struct stm32_dev_s *)dev->ad_priv;
|
2016-11-02 17:46:04 +01:00
|
|
|
uint32_t regval;
|
2011-12-16 01:32:11 +01:00
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
ainfo("intf: %d enable: %d\n", priv->intf, enable ? 1 : 0);
|
2015-07-29 16:34:27 +02:00
|
|
|
|
2011-12-12 02:04:53 +01:00
|
|
|
if (enable)
|
|
|
|
{
|
2016-10-25 22:14:10 +02:00
|
|
|
/* Enable the analog watchdog / overrun interrupts, and if no DMA,
|
|
|
|
* end-of-conversion ADC.
|
|
|
|
*/
|
2011-12-14 01:34:12 +01:00
|
|
|
|
2016-11-02 17:46:04 +01:00
|
|
|
regval = ADC_IER_ALLINTS;
|
|
|
|
#ifdef ADC_HAVE_DMA
|
|
|
|
if (priv->hasdma)
|
|
|
|
{
|
|
|
|
regval &= ~(ADC_IER_EOC | ADC_IER_JEOC);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
adc_modifyreg(priv, STM32_ADC_IER_OFFSET, 0, regval);
|
2015-07-29 16:34:27 +02:00
|
|
|
}
|
2011-12-12 02:04:53 +01:00
|
|
|
else
|
|
|
|
{
|
2011-12-16 01:32:11 +01:00
|
|
|
/* Disable all ADC interrupts */
|
2011-12-14 01:34:12 +01:00
|
|
|
|
2015-11-05 16:09:37 +01:00
|
|
|
adc_modifyreg(priv, STM32_ADC_IER_OFFSET, ADC_IER_ALLINTS, 0);
|
2011-12-12 02:04:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2015-07-29 16:34:27 +02:00
|
|
|
* Name: adc_enable_tvref_register
|
2011-12-12 02:04:53 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2015-07-29 16:34:27 +02:00
|
|
|
* Enable/disable the temperature sensor and the VREFINT channel.
|
2011-12-12 02:04:53 +01:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
2015-07-29 16:34:27 +02:00
|
|
|
* dev - pointer to device structure used by the driver
|
2015-11-05 16:09:37 +01:00
|
|
|
* enable - true: Temperature sensor and V REFINT channel enabled
|
|
|
|
* (ch 16 and 17)
|
|
|
|
* false: Temperature sensor and V REFINT channel disabled
|
|
|
|
* (ch 16 and 17)
|
2011-12-12 02:04:53 +01:00
|
|
|
*
|
|
|
|
* Returned Value:
|
2015-07-29 16:34:27 +02:00
|
|
|
* None.
|
2011-12-12 02:04:53 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-11-12 16:45:55 +01:00
|
|
|
#if defined(HAVE_IP_ADC_V1)
|
2017-10-30 13:21:48 +01:00
|
|
|
static void adc_ioc_enable_tvref_register(FAR struct adc_dev_s *dev,
|
|
|
|
bool enable)
|
|
|
|
{
|
|
|
|
FAR struct stm32_dev_s *priv = (FAR struct stm32_dev_s *)dev->ad_priv;
|
|
|
|
|
2018-11-12 16:45:55 +01:00
|
|
|
#ifdef HAVE_BASIC_ADC
|
|
|
|
# if defined(CONFIG_STM32_ADC1)
|
2017-10-30 13:21:48 +01:00
|
|
|
/* TSVREF bit is only available in the STM32_ADC1_CR2 register. */
|
|
|
|
|
|
|
|
if (priv->intf == 1)
|
|
|
|
{
|
|
|
|
if (enable)
|
|
|
|
{
|
|
|
|
adc_modifyreg(priv, STM32_ADC_CR2_OFFSET, 0, ADC_CR2_TSVREFE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
adc_modifyreg(priv, STM32_ADC_CR2_OFFSET, ADC_CR2_TSVREFE, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ainfo("STM32_ADC_CR2 value: 0x%08x\n",
|
|
|
|
adc_getreg(priv, STM32_ADC_CR2_OFFSET));
|
2018-11-12 16:45:55 +01:00
|
|
|
# endif /* CONFIG_STM32_ADC1 */
|
|
|
|
#else /* !HAVE_BASIC_ADC */
|
|
|
|
if (enable)
|
|
|
|
{
|
|
|
|
adccmn_modifyreg(priv, STM32_ADC_CCR_OFFSET, 0, ADC_CCR_TSVREFE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
adccmn_modifyreg(priv, STM32_ADC_CCR_OFFSET, ADC_CCR_TSVREFE, 0);
|
|
|
|
}
|
|
|
|
|
2020-04-03 01:10:26 +02:00
|
|
|
ainfo("STM32_ADC_CCR value: 0x%08x\n",
|
|
|
|
adccmn_getreg(priv, STM32_ADC_CCR_OFFSET));
|
2018-11-12 16:45:55 +01:00
|
|
|
#endif
|
|
|
|
}
|
2020-01-31 19:07:39 +01:00
|
|
|
#endif /* HAVE_IP_ADC_V1 */
|
2018-11-12 16:45:55 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: adc_resolution_set
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef HAVE_ADC_RESOLUTION
|
|
|
|
static int adc_resolution_set(FAR struct adc_dev_s *dev, uint8_t res)
|
|
|
|
{
|
|
|
|
FAR struct stm32_dev_s *priv = (FAR struct stm32_dev_s *)dev->ad_priv;
|
|
|
|
int ret = OK;
|
|
|
|
|
|
|
|
/* Check input */
|
|
|
|
|
|
|
|
if (res > 3)
|
|
|
|
{
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Modify appropriate register */
|
|
|
|
|
|
|
|
#if defined(HAVE_IP_ADC_V1)
|
|
|
|
adc_modifyreg(priv, STM32_ADC_CR1_OFFSET, ADC_CR1_RES_MASK,
|
|
|
|
res << ADC_CR1_RES_SHIFT);
|
|
|
|
#elif defined(HAVE_IP_ADC_V2)
|
|
|
|
adc_modifyreg(priv, STM32_ADC_CFGR1_OFFSET, ADC_CFGR1_RES_MASK,
|
|
|
|
res << ADC_CFGR1_RES_SHIFT);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
errout:
|
|
|
|
return ret;
|
2017-10-30 13:21:48 +01:00
|
|
|
}
|
2015-07-29 16:34:27 +02:00
|
|
|
#endif
|
|
|
|
|
2018-11-24 00:33:45 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: adc_extsel_set
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef ADC_HAVE_EXTCFG
|
|
|
|
static int adc_extcfg_set(FAR struct adc_dev_s *dev, uint32_t extcfg)
|
|
|
|
{
|
|
|
|
FAR struct stm32_dev_s *priv = (FAR struct stm32_dev_s *)dev->ad_priv;
|
|
|
|
uint32_t exten = 0;
|
|
|
|
uint32_t extsel = 0;
|
|
|
|
uint32_t setbits = 0;
|
|
|
|
uint32_t clrbits = 0;
|
|
|
|
|
|
|
|
/* Get EXTEN and EXTSEL from input */
|
|
|
|
|
|
|
|
exten = (extcfg & ADC_EXTREG_EXTEN_MASK);
|
|
|
|
extsel = (extcfg & ADC_EXTREG_EXTSEL_MASK);
|
|
|
|
|
|
|
|
/* EXTSEL selection: These bits select the external event used
|
|
|
|
* to trigger the start of conversion of a regular group. NOTE:
|
|
|
|
*
|
|
|
|
* - The position with of the EXTSEL field varies from one STM32 MCU
|
|
|
|
* to another.
|
|
|
|
* - The width of the EXTSEL field varies from one STM32 MCU to another.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (exten > 0)
|
|
|
|
{
|
|
|
|
setbits = (extsel | exten);
|
|
|
|
clrbits = (ADC_EXTREG_EXTEN_MASK | ADC_EXTREG_EXTSEL_MASK);
|
|
|
|
|
|
|
|
ainfo("Initializing extsel = 0x%08x\n", extsel);
|
|
|
|
|
|
|
|
/* Write register */
|
|
|
|
|
|
|
|
adc_modifyreg(priv, STM32_ADC_EXTREG_OFFSET, clrbits, setbits);
|
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: adc_jextsel_set
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef ADC_HAVE_JEXTCFG
|
|
|
|
static int adc_jextcfg_set(FAR struct adc_dev_s *dev, uint32_t jextcfg)
|
|
|
|
{
|
|
|
|
FAR struct stm32_dev_s *priv = (FAR struct stm32_dev_s *)dev->ad_priv;
|
|
|
|
uint32_t jexten = 0;
|
|
|
|
uint32_t jextsel = 0;
|
|
|
|
uint32_t setbits = 0;
|
|
|
|
uint32_t clrbits = 0;
|
|
|
|
|
|
|
|
/* Get JEXTEN and JEXTSEL from input */
|
|
|
|
|
|
|
|
jexten = (jextcfg & ADC_JEXTREG_JEXTEN_MASK);
|
|
|
|
jextsel = (jextcfg & ADC_JEXTREG_JEXTSEL_MASK);
|
|
|
|
|
|
|
|
/* JEXTSEL selection: These bits select the external event used
|
|
|
|
* to trigger the start of conversion of a injected group. NOTE:
|
|
|
|
*
|
|
|
|
* - The position with of the JEXTSEL field varies from one STM32 MCU
|
|
|
|
* to another.
|
|
|
|
* - The width of the JEXTSEL field varies from one STM32 MCU to another.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (jexten > 0)
|
|
|
|
{
|
|
|
|
setbits = (jexten | jextsel);
|
|
|
|
clrbits = (ADC_JEXTREG_JEXTEN_MASK | ADC_JEXTREG_JEXTSEL_MASK);
|
|
|
|
|
|
|
|
ainfo("Initializing jextsel = 0x%08x\n", jextsel);
|
|
|
|
|
|
|
|
/* Write register */
|
|
|
|
|
|
|
|
adc_modifyreg(priv, STM32_ADC_JEXTREG_OFFSET, clrbits, setbits);
|
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: adc_dumpregs
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void adc_dumpregs(FAR struct stm32_dev_s *priv)
|
|
|
|
{
|
|
|
|
UNUSED(priv);
|
|
|
|
|
|
|
|
#if defined(HAVE_IP_ADC_V2)
|
2019-01-27 17:17:39 +01:00
|
|
|
ainfo("ISR: 0x%08x IER: 0x%08x CR: 0x%08x CFGR1: 0x%08x\n",
|
2018-11-24 00:33:45 +01:00
|
|
|
adc_getreg(priv, STM32_ADC_ISR_OFFSET),
|
2019-01-27 17:17:39 +01:00
|
|
|
adc_getreg(priv, STM32_ADC_IER_OFFSET),
|
2018-11-24 00:33:45 +01:00
|
|
|
adc_getreg(priv, STM32_ADC_CR_OFFSET),
|
|
|
|
adc_getreg(priv, STM32_ADC_CFGR1_OFFSET));
|
|
|
|
#else
|
|
|
|
ainfo("SR: 0x%08x CR1: 0x%08x CR2: 0x%08x\n",
|
|
|
|
adc_getreg(priv, STM32_ADC_SR_OFFSET),
|
|
|
|
adc_getreg(priv, STM32_ADC_CR1_OFFSET),
|
|
|
|
adc_getreg(priv, STM32_ADC_CR2_OFFSET));
|
|
|
|
#endif
|
|
|
|
|
2019-05-31 16:50:38 +02:00
|
|
|
ainfo("SQR1: 0x%08x SQR2: 0x%08x SQR3: 0x%08x\n",
|
2018-11-24 00:33:45 +01:00
|
|
|
adc_getreg(priv, STM32_ADC_SQR1_OFFSET),
|
|
|
|
adc_getreg(priv, STM32_ADC_SQR2_OFFSET),
|
2019-05-31 16:50:38 +02:00
|
|
|
adc_getreg(priv, STM32_ADC_SQR3_OFFSET));
|
2019-01-27 17:17:39 +01:00
|
|
|
|
|
|
|
ainfo("SMPR1: 0x%08x SMPR2: 0x%08x\n",
|
|
|
|
adc_getreg(priv, STM32_ADC_SMPR1_OFFSET),
|
|
|
|
adc_getreg(priv, STM32_ADC_SMPR2_OFFSET));
|
2018-11-24 00:33:45 +01:00
|
|
|
|
2019-05-31 16:50:38 +02:00
|
|
|
#if defined(STM32_ADC_SQR4_OFFSET)
|
|
|
|
ainfo("SQR4: 0x%08x\n",
|
|
|
|
adc_getreg(priv, STM32_ADC_SQR5_OFFSET));
|
|
|
|
#endif
|
|
|
|
|
2018-11-24 00:33:45 +01:00
|
|
|
#if defined(STM32_ADC_SQR5_OFFSET)
|
2019-01-27 17:17:39 +01:00
|
|
|
ainfo("SQR5: 0x%08x\n",
|
|
|
|
adc_getreg(priv, STM32_ADC_SQR4_OFFSET));
|
2018-11-24 00:33:45 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef ADC_HAVE_INJECTED
|
|
|
|
ainfo("JSQR: 0x%08x\n", adc_getreg(priv, STM32_ADC_JSQR_OFFSET));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(HAVE_IP_ADC_V2) || (defined(HAVE_IP_ADC_V1) && !defined(HAVE_BASIC_ADC))
|
|
|
|
ainfo("CCR: 0x%08x\n", adccmn_getreg(priv, STM32_ADC_CCR_OFFSET));
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-05-18 14:45:46 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: adc_enable_vbat_channel
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Enable/disable the Vbat voltage measurement channel.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* dev - pointer to device structure used by the driver
|
|
|
|
* enable - true: Vbat input channel enabled (ch 18)
|
|
|
|
* false: Vbat input channel disabled (ch 18)
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-11-12 16:45:55 +01:00
|
|
|
#ifdef HAVE_ADC_VBAT
|
2018-05-18 14:45:46 +02:00
|
|
|
static void adc_enable_vbat_channel(FAR struct adc_dev_s *dev, bool enable)
|
|
|
|
{
|
2018-11-12 16:45:55 +01:00
|
|
|
FAR struct stm32_dev_s *priv = (FAR struct stm32_dev_s *)dev->ad_priv;
|
|
|
|
|
2018-05-18 14:45:46 +02:00
|
|
|
if (enable)
|
|
|
|
{
|
2018-11-12 16:45:55 +01:00
|
|
|
adccmn_modifyreg(priv, STM32_ADC_CCR_OFFSET, 0, ADC_CCR_VBATEN);
|
2018-05-18 14:45:46 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-11-12 16:45:55 +01:00
|
|
|
adccmn_modifyreg(priv, STM32_ADC_CCR_OFFSET, ADC_CCR_VBATEN, 0);
|
2018-05-18 14:45:46 +02:00
|
|
|
}
|
|
|
|
|
2020-04-03 01:10:26 +02:00
|
|
|
ainfo("STM32_ADC_CCR value: 0x%08x\n",
|
|
|
|
adccmn_getreg(priv, STM32_ADC_CCR_OFFSET));
|
2018-05-18 14:45:46 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-07-29 16:34:27 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: adc_ioc_change_sleep_between_opers
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Changes PDI and PDD bits to save battery.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* dev - pointer to device structure used by the driver
|
|
|
|
* cmd - command
|
|
|
|
* arg - arguments passed with command
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-11-12 16:45:55 +01:00
|
|
|
#ifdef HAVE_ADC_POWERDOWN
|
2015-07-29 16:34:27 +02:00
|
|
|
static int adc_ioc_change_sleep_between_opers(FAR struct adc_dev_s *dev,
|
|
|
|
int cmd, bool arg)
|
|
|
|
{
|
|
|
|
int ret = OK;
|
|
|
|
FAR struct stm32_dev_s *priv = (FAR struct stm32_dev_s *)dev->ad_priv;
|
|
|
|
|
|
|
|
adc_enable(priv, false);
|
|
|
|
|
|
|
|
switch (cmd)
|
|
|
|
{
|
|
|
|
case IO_ENABLE_DISABLE_PDI:
|
|
|
|
adc_power_down_idle(priv, arg);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IO_ENABLE_DISABLE_PDD:
|
|
|
|
adc_power_down_delay(priv, arg);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IO_ENABLE_DISABLE_PDD_PDI:
|
|
|
|
adc_power_down_idle(priv, arg);
|
|
|
|
adc_power_down_delay(priv, arg);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2016-06-11 19:59:51 +02:00
|
|
|
ainfo("unknown cmd: %d\n", cmd);
|
2015-07-29 16:34:27 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
adc_enable(priv, true);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: adc_ioc_enable_awd_int
|
|
|
|
*
|
|
|
|
* Description:
|
2015-11-05 16:09:37 +01:00
|
|
|
* Turns ON/OFF ADC analog watchdog interrupt.
|
2015-07-29 16:34:27 +02:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* dev - pointer to device structure used by the driver
|
|
|
|
* arg - true: Turn ON interrupt
|
|
|
|
* false: Turn OFF interrupt
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void adc_ioc_enable_awd_int(FAR struct stm32_dev_s *priv, bool enable)
|
|
|
|
{
|
|
|
|
if (enable)
|
|
|
|
{
|
2015-11-05 16:09:37 +01:00
|
|
|
adc_modifyreg(priv, STM32_ADC_IER_OFFSET, 0, ADC_IER_AWD);
|
2015-07-29 16:34:27 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-11-05 16:09:37 +01:00
|
|
|
adc_modifyreg(priv, STM32_ADC_IER_OFFSET, ADC_IER_AWD, 0);
|
2015-07-29 16:34:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: adc_ioc_enable_eoc_int
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Turns ON/OFF ADC EOC interrupt.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* dev - pointer to device structure used by the driver
|
|
|
|
* arg - true: Turn ON interrupt
|
|
|
|
* false: Turn OFF interrupt
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void adc_ioc_enable_eoc_int(FAR struct stm32_dev_s *priv, bool enable)
|
|
|
|
{
|
|
|
|
if (enable)
|
|
|
|
{
|
2015-11-05 16:09:37 +01:00
|
|
|
adc_modifyreg(priv, STM32_ADC_IER_OFFSET, 0, ADC_IER_EOC);
|
2015-07-29 16:34:27 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-11-05 16:09:37 +01:00
|
|
|
adc_modifyreg(priv, STM32_ADC_IER_OFFSET, ADC_IER_EOC, 0);
|
2015-07-29 16:34:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: adc_ioc_enable_jeoc_int
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Turns ON/OFF ADC injected channels interrupt.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* dev - pointer to device structure used by the driver
|
|
|
|
* arg - true: Turn ON interrupt
|
|
|
|
* false: Turn OFF interrupt
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-04-03 01:10:26 +02:00
|
|
|
static void adc_ioc_enable_jeoc_int(FAR struct stm32_dev_s *priv,
|
|
|
|
bool enable)
|
2015-07-29 16:34:27 +02:00
|
|
|
{
|
|
|
|
if (enable)
|
|
|
|
{
|
2015-11-05 16:09:37 +01:00
|
|
|
adc_modifyreg(priv, STM32_ADC_IER_OFFSET, 0, ADC_IER_JEOC);
|
2015-07-29 16:34:27 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-11-05 16:09:37 +01:00
|
|
|
adc_modifyreg(priv, STM32_ADC_IER_OFFSET, ADC_IER_JEOC, 0);
|
2015-07-29 16:34:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: adc_ioc_enable_ovr_int
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Turns ON/OFF ADC overrun interrupt.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* dev - pointer to device structure used by the driver
|
|
|
|
* arg - true: Turn ON interrupt
|
|
|
|
* false: Turn OFF interrupt
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void adc_ioc_enable_ovr_int(FAR struct stm32_dev_s *priv, bool enable)
|
|
|
|
{
|
|
|
|
if (enable)
|
|
|
|
{
|
2015-11-05 16:09:37 +01:00
|
|
|
adc_modifyreg(priv, STM32_ADC_IER_OFFSET, 0, ADC_IER_OVR);
|
2015-07-29 16:34:27 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-11-05 16:09:37 +01:00
|
|
|
adc_modifyreg(priv, STM32_ADC_IER_OFFSET, ADC_IER_OVR, 0);
|
2015-07-29 16:34:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: adc_ioc_change_ints
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Turns ON/OFF ADC interrupts.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* dev - pointer to device structure used by the driver
|
|
|
|
* cmd - command
|
|
|
|
* arg - arguments passed with command
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int adc_ioc_change_ints(FAR struct adc_dev_s *dev, int cmd, bool arg)
|
|
|
|
{
|
|
|
|
int ret = OK;
|
|
|
|
FAR struct stm32_dev_s *priv = (FAR struct stm32_dev_s *)dev->ad_priv;
|
|
|
|
|
|
|
|
switch (cmd)
|
|
|
|
{
|
|
|
|
case IO_ENABLE_DISABLE_AWDIE:
|
|
|
|
adc_ioc_enable_awd_int(priv, arg);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IO_ENABLE_DISABLE_EOCIE:
|
|
|
|
adc_ioc_enable_eoc_int(priv, arg);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IO_ENABLE_DISABLE_JEOCIE:
|
|
|
|
adc_ioc_enable_jeoc_int(priv, arg);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IO_ENABLE_DISABLE_OVRIE:
|
|
|
|
adc_ioc_enable_ovr_int(priv, arg);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IO_ENABLE_DISABLE_ALL_INTS:
|
|
|
|
adc_ioc_enable_awd_int(priv, arg);
|
|
|
|
adc_ioc_enable_eoc_int(priv, arg);
|
|
|
|
adc_ioc_enable_jeoc_int(priv, arg);
|
|
|
|
adc_ioc_enable_ovr_int(priv, arg);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2016-06-11 19:59:51 +02:00
|
|
|
ainfo("unknown cmd: %d\n", cmd);
|
2015-07-29 16:34:27 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: adc_ioc_wait_rcnr_zeroed
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* For the STM3215XX-family the ADC_SR_RCNR bit must be zeroed,
|
|
|
|
* before next conversion.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* dev - pointer to device structure used by the driver
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_STM32_STM32L15XX
|
|
|
|
static int adc_ioc_wait_rcnr_zeroed(FAR struct stm32_dev_s *priv)
|
|
|
|
{
|
2015-11-05 16:09:37 +01:00
|
|
|
int i;
|
2015-07-29 16:34:27 +02:00
|
|
|
|
|
|
|
for (i = 0; i < 30000; i++)
|
|
|
|
{
|
2015-11-05 16:09:37 +01:00
|
|
|
if ((adc_getreg(priv, STM32_ADC_SR_OFFSET) & ADC_SR_RCNR) == 0)
|
2015-07-29 16:34:27 +02:00
|
|
|
{
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -ENODATA;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: adc_enable_hsi
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Enable/Disable HSI clock
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* enable - true : HSI clock for ADC enabled
|
|
|
|
* false : HSI clock for ADC disabled
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-11-12 16:45:55 +01:00
|
|
|
#ifdef HAVE_HSI_CONTROL
|
2015-07-29 16:34:27 +02:00
|
|
|
static void adc_enable_hsi(bool enable)
|
|
|
|
{
|
|
|
|
if (enable)
|
|
|
|
{
|
2015-11-05 16:09:37 +01:00
|
|
|
/* Enable the HSI */
|
|
|
|
|
|
|
|
stm32_modifyreg32(STM32_RCC_CR, 0, RCC_CR_HSION);
|
2015-07-29 16:34:27 +02:00
|
|
|
while ((getreg32(STM32_RCC_CR) & RCC_CR_HSIRDY) == 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-11-05 16:09:37 +01:00
|
|
|
/* Disable the HSI */
|
|
|
|
|
|
|
|
stm32_modifyreg32(STM32_RCC_CR, RCC_CR_HSION, 0);
|
2015-07-29 16:34:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
2015-11-05 16:09:37 +01:00
|
|
|
* Name: adc_sqrbits
|
2015-07-29 16:34:27 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
2020-04-03 01:10:26 +02:00
|
|
|
static uint32_t adc_sqrbits(FAR struct stm32_dev_s *priv, int first,
|
|
|
|
int last, int offset)
|
2015-07-29 16:34:27 +02:00
|
|
|
{
|
2015-11-05 16:09:37 +01:00
|
|
|
uint32_t bits = 0;
|
|
|
|
int i;
|
2015-07-29 16:34:27 +02:00
|
|
|
|
2015-11-05 16:09:37 +01:00
|
|
|
for (i = first - 1;
|
2018-11-24 00:33:45 +01:00
|
|
|
i < priv->rnchannels && i < last;
|
2015-11-05 16:09:37 +01:00
|
|
|
i++, offset += ADC_SQ_OFFSET)
|
2015-07-29 16:34:27 +02:00
|
|
|
{
|
2018-11-24 00:33:45 +01:00
|
|
|
bits |= (uint32_t)priv->r_chanlist[i] << offset;
|
2015-07-29 16:34:27 +02:00
|
|
|
}
|
2015-11-05 16:09:37 +01:00
|
|
|
|
|
|
|
return bits;
|
2015-07-29 16:34:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2015-07-30 15:42:31 +02:00
|
|
|
* Name: adc_set_ch
|
2015-07-29 16:34:27 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2015-07-30 15:42:31 +02:00
|
|
|
* Sets the ADC channel.
|
2015-07-29 16:34:27 +02:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* dev - pointer to device structure used by the driver
|
|
|
|
* ch - ADC channel number + 1. 0 reserved for all configured channels
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* int - errno
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int adc_set_ch(FAR struct adc_dev_s *dev, uint8_t ch)
|
|
|
|
{
|
|
|
|
FAR struct stm32_dev_s *priv = (FAR struct stm32_dev_s *)dev->ad_priv;
|
2015-11-05 16:09:37 +01:00
|
|
|
uint32_t bits;
|
|
|
|
int i;
|
2015-07-29 16:34:27 +02:00
|
|
|
|
|
|
|
if (ch == 0)
|
|
|
|
{
|
2015-11-05 16:09:37 +01:00
|
|
|
priv->current = 0;
|
2018-11-24 00:33:45 +01:00
|
|
|
priv->rnchannels = priv->cr_channels;
|
2015-11-05 16:09:37 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-04-03 01:10:26 +02:00
|
|
|
for (i = 0; i < priv->cr_channels && priv->r_chanlist[i] != ch - 1;
|
|
|
|
i++);
|
2015-07-29 16:34:27 +02:00
|
|
|
|
2018-11-24 00:33:45 +01:00
|
|
|
if (i >= priv->cr_channels)
|
2015-10-07 21:45:15 +02:00
|
|
|
{
|
2015-11-05 16:09:37 +01:00
|
|
|
return -ENODEV;
|
2015-10-07 21:45:15 +02:00
|
|
|
}
|
2015-07-29 16:34:27 +02:00
|
|
|
|
2015-11-05 16:09:37 +01:00
|
|
|
priv->current = i;
|
2018-11-24 00:33:45 +01:00
|
|
|
priv->rnchannels = 1;
|
2015-11-05 16:09:37 +01:00
|
|
|
}
|
2015-07-29 16:34:27 +02:00
|
|
|
|
2015-11-05 16:09:37 +01:00
|
|
|
#ifdef STM32_ADC_SQR5_OFFSET
|
2020-04-03 01:10:26 +02:00
|
|
|
bits = adc_sqrbits(priv, ADC_SQR5_FIRST, ADC_SQR5_LAST,
|
|
|
|
ADC_SQR5_SQ_OFFSET);
|
2015-11-05 16:09:37 +01:00
|
|
|
adc_modifyreg(priv, STM32_ADC_SQR5_OFFSET, ~ADC_SQR5_RESERVED, bits);
|
|
|
|
#endif
|
2015-07-29 16:34:27 +02:00
|
|
|
|
2015-11-05 16:09:37 +01:00
|
|
|
#ifdef STM32_ADC_SQR4_OFFSET
|
2020-04-03 01:10:26 +02:00
|
|
|
bits = adc_sqrbits(priv, ADC_SQR4_FIRST, ADC_SQR4_LAST,
|
|
|
|
ADC_SQR4_SQ_OFFSET);
|
2015-11-05 16:09:37 +01:00
|
|
|
adc_modifyreg(priv, STM32_ADC_SQR4_OFFSET, ~ADC_SQR4_RESERVED, bits);
|
|
|
|
#endif
|
2015-07-29 16:34:27 +02:00
|
|
|
|
2020-04-03 01:10:26 +02:00
|
|
|
bits = adc_sqrbits(priv, ADC_SQR3_FIRST, ADC_SQR3_LAST,
|
|
|
|
ADC_SQR3_SQ_OFFSET);
|
2015-11-05 16:09:37 +01:00
|
|
|
adc_modifyreg(priv, STM32_ADC_SQR3_OFFSET, ~ADC_SQR3_RESERVED, bits);
|
2015-07-29 16:34:27 +02:00
|
|
|
|
2020-04-03 01:10:26 +02:00
|
|
|
bits = adc_sqrbits(priv, ADC_SQR2_FIRST, ADC_SQR2_LAST,
|
|
|
|
ADC_SQR2_SQ_OFFSET);
|
2015-11-05 16:09:37 +01:00
|
|
|
adc_modifyreg(priv, STM32_ADC_SQR2_OFFSET, ~ADC_SQR2_RESERVED, bits);
|
2015-07-29 16:34:27 +02:00
|
|
|
|
2018-11-24 00:33:45 +01:00
|
|
|
bits = ((uint32_t)priv->rnchannels - 1) << ADC_SQR1_L_SHIFT;
|
2020-04-03 01:10:26 +02:00
|
|
|
bits |= adc_sqrbits(priv, ADC_SQR1_FIRST,
|
|
|
|
ADC_SQR1_LAST, ADC_SQR1_SQ_OFFSET);
|
2015-11-05 16:09:37 +01:00
|
|
|
adc_modifyreg(priv, STM32_ADC_SQR1_OFFSET, ~ADC_SQR1_RESERVED, bits);
|
2015-07-29 16:34:27 +02:00
|
|
|
|
2015-11-05 16:09:37 +01:00
|
|
|
return OK;
|
2015-07-29 16:34:27 +02:00
|
|
|
}
|
|
|
|
|
2018-11-24 00:33:45 +01:00
|
|
|
#ifdef ADC_HAVE_INJECTED
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: adc_inj_set_ch
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int adc_inj_set_ch(FAR struct adc_dev_s *dev, uint8_t ch)
|
|
|
|
{
|
|
|
|
FAR struct stm32_dev_s *priv = (FAR struct stm32_dev_s *)dev->ad_priv;
|
|
|
|
uint32_t clrbits;
|
|
|
|
uint32_t setbits;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Configure injected sequence length */
|
|
|
|
|
|
|
|
setbits = ADC_JSQR_JL(priv->cj_channels);
|
|
|
|
clrbits = ADC_JEXTREG_JEXTSEL_MASK | ADC_JSQR_JL_MASK;
|
|
|
|
|
|
|
|
/* Configure injected channels */
|
|
|
|
|
|
|
|
for (i = 0 ; i < priv->cj_channels; i += 1)
|
|
|
|
{
|
2020-04-21 21:37:47 +02:00
|
|
|
#if defined(HAVE_IP_ADC_V1)
|
|
|
|
/* Injected channels sequence for for ADC IPv1:
|
|
|
|
*
|
|
|
|
* 1 2 3 4
|
|
|
|
* IL=1: JSQR4,
|
|
|
|
* IL=2: JSQR3, JSQR4
|
|
|
|
* IL=3: JSQR2, JSQR3, JSQR4
|
|
|
|
* IL=4: JSQR1, JSQR2, JSQR3, JSQR4
|
|
|
|
*/
|
|
|
|
|
|
|
|
setbits |= (priv->j_chanlist[priv->cj_channels - 1 - i] <<
|
|
|
|
(ADC_JSQR_JSQ4_SHIFT - ADC_JSQR_JSQ_SHIFT * i));
|
|
|
|
#else
|
2018-11-24 00:33:45 +01:00
|
|
|
setbits |= priv->j_chanlist[i] << (ADC_JSQR_JSQ1_SHIFT +
|
2020-04-21 21:37:47 +02:00
|
|
|
ADC_JSQR_JSQ_SHIFT * i);
|
|
|
|
#endif
|
2018-11-24 00:33:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Write register */
|
|
|
|
|
|
|
|
adc_modifyreg(priv, STM32_ADC_JSQR_OFFSET, clrbits, setbits);
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-07-29 16:34:27 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: adc_ioctl
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* All ioctl calls will be routed through this method.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* dev - pointer to device structure used by the driver
|
|
|
|
* cmd - command
|
|
|
|
* arg - arguments passed with command
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int adc_ioctl(FAR struct adc_dev_s *dev, int cmd, unsigned long arg)
|
|
|
|
{
|
2015-11-05 16:09:37 +01:00
|
|
|
FAR struct stm32_dev_s *priv = (FAR struct stm32_dev_s *)dev->ad_priv;
|
2018-11-12 16:45:55 +01:00
|
|
|
int ret = OK;
|
2015-07-29 16:34:27 +02:00
|
|
|
|
|
|
|
switch (cmd)
|
2015-07-30 16:47:45 +02:00
|
|
|
{
|
|
|
|
case ANIOC_TRIGGER:
|
2018-11-12 16:45:55 +01:00
|
|
|
{
|
2018-11-24 00:33:45 +01:00
|
|
|
/* Start regular conversion if regular channels configured */
|
|
|
|
|
|
|
|
if (priv->cr_channels > 0)
|
|
|
|
{
|
|
|
|
adc_reg_startconv(priv, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef ADC_HAVE_INJECTED
|
|
|
|
/* Start injected conversion if injected channels configured */
|
|
|
|
|
|
|
|
if (priv->cj_channels > 0)
|
|
|
|
{
|
|
|
|
adc_inj_startconv(priv, true);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case IO_TRIGGER_REG:
|
|
|
|
{
|
|
|
|
/* Start regular conversion if regular channels configured */
|
|
|
|
|
|
|
|
if (priv->cr_channels > 0)
|
|
|
|
{
|
|
|
|
adc_reg_startconv(priv, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef ADC_HAVE_INJECTED
|
|
|
|
case IO_TRIGGER_INJ:
|
|
|
|
{
|
|
|
|
/* Start injected conversion if injected channels configured */
|
|
|
|
|
|
|
|
if (priv->cj_channels > 0)
|
|
|
|
{
|
|
|
|
adc_inj_startconv(priv, true);
|
|
|
|
}
|
|
|
|
|
2018-11-12 16:45:55 +01:00
|
|
|
break;
|
|
|
|
}
|
2018-11-24 00:33:45 +01:00
|
|
|
#endif
|
2015-07-30 16:47:45 +02:00
|
|
|
|
2018-11-12 16:45:55 +01:00
|
|
|
case IO_ENABLE_DISABLE_AWDIE:
|
|
|
|
case IO_ENABLE_DISABLE_EOCIE:
|
|
|
|
case IO_ENABLE_DISABLE_JEOCIE:
|
|
|
|
case IO_ENABLE_DISABLE_OVRIE:
|
|
|
|
case IO_ENABLE_DISABLE_ALL_INTS:
|
|
|
|
{
|
|
|
|
adc_ioc_change_ints(dev, cmd, *(bool *)arg);
|
|
|
|
break;
|
|
|
|
}
|
2017-10-30 13:21:48 +01:00
|
|
|
|
2018-11-12 16:45:55 +01:00
|
|
|
#if defined(HAVE_IP_ADC_V1)
|
2017-10-30 13:21:48 +01:00
|
|
|
case IO_ENABLE_TEMPER_VOLT_CH:
|
2018-11-12 16:45:55 +01:00
|
|
|
{
|
|
|
|
adc_ioc_enable_tvref_register(dev, *(bool *)arg);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
2017-10-30 13:21:48 +01:00
|
|
|
|
2018-11-12 16:45:55 +01:00
|
|
|
#ifdef HAVE_ADC_VBAT
|
2018-05-18 14:45:46 +02:00
|
|
|
case IO_ENABLE_DISABLE_VBAT_CH:
|
2018-11-12 16:45:55 +01:00
|
|
|
{
|
|
|
|
adc_enable_vbat_channel(dev, *(bool *)arg);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
2015-07-29 16:34:27 +02:00
|
|
|
|
2018-11-12 16:45:55 +01:00
|
|
|
#ifdef HAVE_ADC_POWERDOWN
|
2015-07-30 16:47:45 +02:00
|
|
|
case IO_ENABLE_DISABLE_PDI:
|
|
|
|
case IO_ENABLE_DISABLE_PDD:
|
|
|
|
case IO_ENABLE_DISABLE_PDD_PDI:
|
2018-11-12 16:45:55 +01:00
|
|
|
{
|
|
|
|
adc_ioc_change_sleep_between_opers(dev, cmd, *(bool *)arg);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
2015-07-29 16:34:27 +02:00
|
|
|
|
2018-11-12 16:45:55 +01:00
|
|
|
case IO_STOP_ADC:
|
|
|
|
{
|
|
|
|
adc_enable(priv, false);
|
|
|
|
#ifdef HAVE_HSI_CONTROL
|
|
|
|
adc_enable_hsi(false);
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case IO_START_ADC:
|
|
|
|
{
|
|
|
|
#ifdef HAVE_HSI_CONTROL
|
|
|
|
adc_enable_hsi(true);
|
|
|
|
#endif
|
|
|
|
adc_enable(priv, true);
|
|
|
|
break;
|
|
|
|
}
|
2015-07-29 16:34:27 +02:00
|
|
|
|
2015-07-30 16:47:45 +02:00
|
|
|
case IO_START_CONV:
|
|
|
|
{
|
|
|
|
uint8_t ch = ((uint8_t)arg);
|
2015-07-29 16:34:27 +02:00
|
|
|
|
2018-11-12 16:45:55 +01:00
|
|
|
#ifdef CONFIG_STM32_STM32L15XX
|
2015-07-30 16:47:45 +02:00
|
|
|
ret = adc_ioc_wait_rcnr_zeroed(priv);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
2018-11-12 16:45:55 +01:00
|
|
|
#endif
|
2015-07-29 16:34:27 +02:00
|
|
|
|
2015-10-07 21:45:15 +02:00
|
|
|
ret = adc_set_ch(dev, ch);
|
2015-07-30 16:47:45 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-11-20 19:29:37 +01:00
|
|
|
#ifdef CONFIG_ADC
|
2015-07-30 16:47:45 +02:00
|
|
|
if (ch)
|
|
|
|
{
|
2018-11-24 00:33:45 +01:00
|
|
|
/* Clear fifo if upper-half driver enabled */
|
2015-07-30 16:47:45 +02:00
|
|
|
|
|
|
|
dev->ad_recv.af_head = 0;
|
|
|
|
dev->ad_recv.af_tail = 0;
|
|
|
|
}
|
2018-11-20 19:29:37 +01:00
|
|
|
#endif
|
2015-07-30 16:47:45 +02:00
|
|
|
|
2018-11-24 00:33:45 +01:00
|
|
|
adc_reg_startconv(priv, true);
|
2018-11-12 16:45:55 +01:00
|
|
|
break;
|
2015-07-30 16:47:45 +02:00
|
|
|
}
|
2015-07-29 16:34:27 +02:00
|
|
|
|
2015-07-30 16:47:45 +02:00
|
|
|
default:
|
2018-11-12 16:45:55 +01:00
|
|
|
{
|
|
|
|
aerr("ERROR: Unknown cmd: %d\n", cmd);
|
|
|
|
ret = -ENOTTY;
|
|
|
|
break;
|
|
|
|
}
|
2015-07-29 16:34:27 +02:00
|
|
|
}
|
|
|
|
|
2015-07-30 16:47:45 +02:00
|
|
|
return ret;
|
2015-07-29 16:34:27 +02:00
|
|
|
}
|
|
|
|
|
2018-11-24 00:33:45 +01:00
|
|
|
#ifndef CONFIG_STM32_ADC_NOIRQ
|
|
|
|
|
2015-07-29 16:34:27 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: adc_interrupt
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Common ADC interrupt handler.
|
2011-12-14 01:34:12 +01:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2011-12-16 01:32:11 +01:00
|
|
|
static int adc_interrupt(FAR struct adc_dev_s *dev)
|
2011-12-14 01:34:12 +01:00
|
|
|
{
|
2011-12-16 01:32:11 +01:00
|
|
|
FAR struct stm32_dev_s *priv = (FAR struct stm32_dev_s *)dev->ad_priv;
|
2015-11-05 16:09:37 +01:00
|
|
|
uint32_t regval;
|
|
|
|
uint32_t pending;
|
|
|
|
int32_t data;
|
|
|
|
|
|
|
|
regval = adc_getreg(priv, STM32_ADC_ISR_OFFSET);
|
|
|
|
pending = regval & ADC_ISR_ALLINTS;
|
|
|
|
if (pending == 0)
|
|
|
|
{
|
|
|
|
return OK;
|
|
|
|
}
|
2011-12-15 01:29:35 +01:00
|
|
|
|
2012-01-04 00:25:49 +01:00
|
|
|
/* Identifies the interruption AWD, OVR or EOC */
|
2012-03-10 01:02:11 +01:00
|
|
|
|
2015-11-05 16:09:37 +01:00
|
|
|
if ((regval & ADC_ISR_AWD) != 0)
|
2011-12-15 01:29:35 +01:00
|
|
|
{
|
2016-06-20 17:37:08 +02:00
|
|
|
awarn("WARNING: Analog Watchdog, Value converted out of range!\n");
|
2011-12-15 01:29:35 +01:00
|
|
|
}
|
2011-12-20 01:30:12 +01:00
|
|
|
|
2015-11-05 16:09:37 +01:00
|
|
|
if ((regval & ADC_ISR_OVR) != 0)
|
2012-01-04 00:25:49 +01:00
|
|
|
{
|
2016-06-20 17:37:08 +02:00
|
|
|
awarn("WARNING: Overrun has occurred!\n");
|
2012-01-04 00:25:49 +01:00
|
|
|
}
|
|
|
|
|
2011-12-15 01:29:35 +01:00
|
|
|
/* EOC: End of conversion */
|
2011-12-14 01:34:12 +01:00
|
|
|
|
2015-11-05 16:09:37 +01:00
|
|
|
if ((regval & ADC_ISR_EOC) != 0)
|
2011-12-15 01:29:35 +01:00
|
|
|
{
|
2012-03-10 01:02:11 +01:00
|
|
|
/* Read the converted value and clear EOC bit
|
|
|
|
* (It is cleared by reading the ADC_DR)
|
2011-12-22 01:31:47 +01:00
|
|
|
*/
|
2011-12-16 01:32:11 +01:00
|
|
|
|
2015-11-05 16:09:37 +01:00
|
|
|
data = adc_getreg(priv, STM32_ADC_DR_OFFSET) & ADC_DR_RDATA_MASK;
|
2011-12-20 01:30:12 +01:00
|
|
|
|
2016-05-26 20:25:54 +02:00
|
|
|
/* Verify that the upper-half driver has bound its callback functions */
|
2011-12-15 01:29:35 +01:00
|
|
|
|
2016-05-26 20:25:54 +02:00
|
|
|
if (priv->cb != NULL)
|
|
|
|
{
|
|
|
|
/* Give the ADC data to the ADC driver. The ADC receive() method
|
|
|
|
* accepts 3 parameters:
|
|
|
|
*
|
|
|
|
* 1) The first is the ADC device instance for this ADC block.
|
|
|
|
* 2) The second is the channel number for the data, and
|
|
|
|
* 3) The third is the converted data for the channel.
|
|
|
|
*/
|
|
|
|
|
|
|
|
DEBUGASSERT(priv->cb->au_receive != NULL);
|
2018-11-24 00:33:45 +01:00
|
|
|
priv->cb->au_receive(dev, priv->r_chanlist[priv->current], data);
|
2016-05-26 20:25:54 +02:00
|
|
|
}
|
2011-12-21 00:44:21 +01:00
|
|
|
|
2015-07-29 16:34:27 +02:00
|
|
|
/* Set the channel number of the next channel that will complete
|
|
|
|
* conversion.
|
|
|
|
*/
|
2011-12-16 14:32:46 +01:00
|
|
|
|
2011-12-22 01:31:47 +01:00
|
|
|
priv->current++;
|
|
|
|
|
2018-11-24 00:33:45 +01:00
|
|
|
if (priv->current >= priv->rnchannels)
|
2011-12-16 17:17:34 +01:00
|
|
|
{
|
2011-12-16 20:29:41 +01:00
|
|
|
/* Restart the conversion sequence from the beginning */
|
2011-12-22 01:31:47 +01:00
|
|
|
|
2011-12-16 20:29:41 +01:00
|
|
|
priv->current = 0;
|
2011-12-16 01:32:11 +01:00
|
|
|
}
|
2011-12-15 01:29:35 +01:00
|
|
|
}
|
2011-12-14 01:34:12 +01:00
|
|
|
|
2017-10-20 19:15:48 +02:00
|
|
|
/* Clear pending interrupts */
|
|
|
|
|
|
|
|
adc_putreg(priv, STM32_ADC_ISR_OFFSET, pending);
|
2016-11-02 17:46:04 +01:00
|
|
|
|
2011-12-15 01:29:35 +01:00
|
|
|
return OK;
|
2011-12-14 01:34:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2015-11-05 16:09:37 +01:00
|
|
|
* Name: adc1_interrupt
|
2011-12-14 01:34:12 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2015-11-05 16:09:37 +01:00
|
|
|
* ADC interrupt handler for the STM32 L15XX family.
|
2011-12-14 01:34:12 +01:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
2015-11-05 16:09:37 +01:00
|
|
|
* irq - The IRQ number that generated the interrupt.
|
|
|
|
* context - Architecture specific register save information.
|
2011-12-14 01:34:12 +01:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2016-06-01 01:58:52 +02:00
|
|
|
#if defined(STM32_IRQ_ADC1)
|
2017-03-01 01:20:45 +01:00
|
|
|
static int adc1_interrupt(int irq, FAR void *context, FAR void *arg)
|
2011-12-14 01:34:12 +01:00
|
|
|
{
|
2015-11-05 16:09:37 +01:00
|
|
|
adc_interrupt(&g_adcdev1);
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
#endif
|
2011-12-14 01:34:12 +01:00
|
|
|
|
2015-11-05 16:09:37 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: adc12_interrupt
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* ADC1/2 interrupt handler for the STM32 F1/F3 families.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2011-12-14 01:34:12 +01:00
|
|
|
|
2016-06-01 01:58:52 +02:00
|
|
|
#if defined(STM32_IRQ_ADC12) && \
|
2015-11-05 16:09:37 +01:00
|
|
|
(defined(CONFIG_STM32_ADC1) || defined(CONFIG_STM32_ADC2))
|
2017-03-01 01:20:45 +01:00
|
|
|
static int adc12_interrupt(int irq, FAR void *context, FAR void *arg)
|
2015-11-05 16:09:37 +01:00
|
|
|
{
|
2011-12-14 01:34:12 +01:00
|
|
|
#ifdef CONFIG_STM32_ADC1
|
2015-11-05 16:09:37 +01:00
|
|
|
adc_interrupt(&g_adcdev1);
|
2011-12-14 01:34:12 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_STM32_ADC2
|
2015-11-05 16:09:37 +01:00
|
|
|
adc_interrupt(&g_adcdev2);
|
2011-12-14 01:34:12 +01:00
|
|
|
#endif
|
2015-11-05 16:09:37 +01:00
|
|
|
|
2011-12-14 01:34:12 +01:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: adc3_interrupt
|
|
|
|
*
|
|
|
|
* Description:
|
2015-11-05 16:09:37 +01:00
|
|
|
* ADC3 interrupt handler for the STM32 F1 family.
|
2011-12-14 01:34:12 +01:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2016-06-01 01:58:52 +02:00
|
|
|
#if defined(STM32_IRQ_ADC3) && defined(CONFIG_STM32_ADC3)
|
2017-03-01 01:20:45 +01:00
|
|
|
static int adc3_interrupt(int irq, FAR void *context, FAR void *arg)
|
2011-12-14 01:34:12 +01:00
|
|
|
{
|
2015-11-05 16:09:37 +01:00
|
|
|
adc_interrupt(&g_adcdev3);
|
2011-12-14 01:34:12 +01:00
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-07-29 16:34:27 +02:00
|
|
|
/****************************************************************************
|
2015-11-05 16:09:37 +01:00
|
|
|
* Name: adc4_interrupt
|
2015-07-29 16:34:27 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2015-11-05 16:09:37 +01:00
|
|
|
* ADC4 interrupt handler for the STM32 F3 family.
|
2015-07-29 16:34:27 +02:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2016-06-01 01:58:52 +02:00
|
|
|
#if defined(STM32_IRQ_ADC4) && defined(CONFIG_STM32_ADC4)
|
2017-03-01 01:20:45 +01:00
|
|
|
static int adc4_interrupt(int irq, FAR void *context, FAR void *arg)
|
2015-07-29 16:34:27 +02:00
|
|
|
{
|
2015-11-05 16:09:37 +01:00
|
|
|
adc_interrupt(&g_adcdev4);
|
2018-11-24 00:33:45 +01:00
|
|
|
|
2015-07-29 16:34:27 +02:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-12-14 01:34:12 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: adc123_interrupt
|
|
|
|
*
|
|
|
|
* Description:
|
2015-11-05 16:09:37 +01:00
|
|
|
* ADC1/2/3 interrupt handler for the STM32 F2/F4 families.
|
2011-12-14 01:34:12 +01:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2016-06-01 01:58:52 +02:00
|
|
|
#if defined(STM32_IRQ_ADC)
|
2017-03-01 01:20:45 +01:00
|
|
|
static int adc123_interrupt(int irq, FAR void *context, FAR void *arg)
|
2011-12-14 01:34:12 +01:00
|
|
|
{
|
|
|
|
#ifdef CONFIG_STM32_ADC1
|
2015-11-05 16:09:37 +01:00
|
|
|
adc_interrupt(&g_adcdev1);
|
2011-12-14 01:34:12 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_STM32_ADC2
|
2015-11-05 16:09:37 +01:00
|
|
|
adc_interrupt(&g_adcdev2);
|
2011-12-14 01:34:12 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_STM32_ADC3
|
2015-11-05 16:09:37 +01:00
|
|
|
adc_interrupt(&g_adcdev3);
|
2011-12-14 01:34:12 +01:00
|
|
|
#endif
|
2015-11-05 16:09:37 +01:00
|
|
|
|
2011-12-14 01:34:12 +01:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
#endif
|
2020-01-31 19:07:39 +01:00
|
|
|
#endif /* CONFIG_STM32_ADC_NOIRQ */
|
2018-11-24 00:33:45 +01:00
|
|
|
|
|
|
|
#ifdef CONFIG_STM32_ADC_LL_OPS
|
2011-12-14 01:34:12 +01:00
|
|
|
|
2011-12-12 02:04:53 +01:00
|
|
|
/****************************************************************************
|
2018-11-24 00:33:45 +01:00
|
|
|
* Name: adc_intack
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void adc_intack(FAR struct stm32_adc_dev_s *dev, uint32_t source)
|
|
|
|
{
|
|
|
|
FAR struct stm32_dev_s *priv = (FAR struct stm32_dev_s *)dev;
|
|
|
|
|
|
|
|
/* Clear pending interrupts */
|
|
|
|
|
|
|
|
#ifdef HAVE_IP_ADC_V2
|
|
|
|
/* Cleared by writing 1 to it */
|
|
|
|
|
|
|
|
adc_putreg(priv, STM32_ADC_ISR_OFFSET, (source & ADC_ISR_ALLINTS));
|
|
|
|
#else
|
|
|
|
/* Cleared by writing 0 to it */
|
|
|
|
|
|
|
|
adc_modifyreg(priv, STM32_ADC_ISR_OFFSET, (source & ADC_ISR_ALLINTS), 0);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: adc_inten
|
2011-12-12 02:04:53 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
2018-11-24 00:33:45 +01:00
|
|
|
static void adc_inten(FAR struct stm32_adc_dev_s *dev, uint32_t source)
|
|
|
|
{
|
|
|
|
FAR struct stm32_dev_s *priv = (FAR struct stm32_dev_s *)dev;
|
|
|
|
|
|
|
|
/* Enable interrupts */
|
|
|
|
|
|
|
|
adc_modifyreg(priv, STM32_ADC_IER_OFFSET, 0, (source & ADC_IER_ALLINTS));
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: adc_intdis
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void adc_intdis(FAR struct stm32_adc_dev_s *dev, uint32_t source)
|
|
|
|
{
|
|
|
|
FAR struct stm32_dev_s *priv = (FAR struct stm32_dev_s *)dev;
|
|
|
|
|
|
|
|
/* Disable interrupts */
|
|
|
|
|
|
|
|
adc_modifyreg(priv, STM32_ADC_IER_OFFSET, (source & ADC_IER_ALLINTS), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: adc_ackget
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static uint32_t adc_intget(FAR struct stm32_adc_dev_s *dev)
|
|
|
|
{
|
|
|
|
FAR struct stm32_dev_s *priv = (FAR struct stm32_dev_s *)dev;
|
|
|
|
uint32_t regval;
|
|
|
|
uint32_t pending;
|
|
|
|
|
|
|
|
regval = adc_getreg(priv, STM32_ADC_ISR_OFFSET);
|
|
|
|
pending = regval & ADC_ISR_ALLINTS;
|
|
|
|
|
|
|
|
return pending;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: adc_regget
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static uint32_t adc_regget(FAR struct stm32_adc_dev_s *dev)
|
|
|
|
{
|
|
|
|
FAR struct stm32_dev_s *priv = (FAR struct stm32_dev_s *)dev;
|
|
|
|
|
|
|
|
return adc_getreg(priv, STM32_ADC_DR_OFFSET) & ADC_DR_RDATA_MASK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: adc_llops_reg_startconv
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-04-03 01:10:26 +02:00
|
|
|
static void adc_llops_reg_startconv(FAR struct stm32_adc_dev_s *dev,
|
|
|
|
bool enable)
|
2018-11-24 00:33:45 +01:00
|
|
|
{
|
|
|
|
FAR struct stm32_dev_s *priv = (FAR struct stm32_dev_s *)dev;
|
|
|
|
|
|
|
|
adc_reg_startconv(priv, enable);
|
|
|
|
}
|
|
|
|
|
2020-04-21 21:31:27 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: adc_offset_set
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef HAVE_IP_ADC_V2
|
|
|
|
static int adc_offset_set(FAR struct stm32_adc_dev_s *dev, uint8_t ch,
|
|
|
|
uint8_t i, uint16_t offset)
|
|
|
|
{
|
|
|
|
FAR struct stm32_dev_s *priv = (FAR struct stm32_dev_s *)dev;
|
|
|
|
uint32_t regval = 0;
|
|
|
|
uint32_t reg = 0;
|
|
|
|
int ret = OK;
|
|
|
|
|
|
|
|
if (i >= 4)
|
|
|
|
{
|
|
|
|
/* There are only four offset registers. */
|
|
|
|
|
|
|
|
ret = -E2BIG;
|
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
|
|
|
|
reg = STM32_ADC_OFR1_OFFSET + i * 4;
|
|
|
|
|
|
|
|
regval = ADC_OFR_OFFSETY_EN;
|
|
|
|
adc_putreg(priv, reg, regval);
|
|
|
|
|
|
|
|
regval |= ADC_OFR_OFFSETY_CH(ch) | ADC_OFR_OFFSETY(offset);
|
|
|
|
adc_putreg(priv, reg, regval);
|
|
|
|
|
|
|
|
errout:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#else /* HAVE_IP_ADC_V1 */
|
|
|
|
static int adc_offset_set(FAR struct stm32_adc_dev_s *dev, uint8_t ch,
|
|
|
|
uint8_t i, uint16_t offset)
|
|
|
|
{
|
|
|
|
FAR struct stm32_dev_s *priv = (FAR struct stm32_dev_s *)dev;
|
|
|
|
uint32_t reg = 0;
|
|
|
|
int ret = OK;
|
|
|
|
|
|
|
|
/* WARNING: Offset only for injected channels! */
|
|
|
|
|
|
|
|
UNUSED(ch);
|
|
|
|
|
|
|
|
if (i >= 4)
|
|
|
|
{
|
|
|
|
/* There are only four offset registers. */
|
|
|
|
|
|
|
|
ret = -E2BIG;
|
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
|
|
|
|
reg = STM32_ADC_JOFR1_OFFSET + i * 4;
|
|
|
|
|
|
|
|
adc_putreg(priv, reg, offset);
|
|
|
|
|
|
|
|
errout:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-11-24 00:33:45 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: adc_regbufregister
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef ADC_HAVE_DMA
|
2020-04-03 01:10:26 +02:00
|
|
|
static int adc_regbufregister(FAR struct stm32_adc_dev_s *dev,
|
|
|
|
uint16_t *buffer, uint8_t len)
|
2018-11-24 00:33:45 +01:00
|
|
|
{
|
|
|
|
FAR struct stm32_dev_s *priv = (FAR struct stm32_dev_s *)dev;
|
|
|
|
|
|
|
|
stm32_dmasetup(priv->dma,
|
|
|
|
priv->base + STM32_ADC_DR_OFFSET,
|
|
|
|
(uint32_t)buffer,
|
|
|
|
len,
|
|
|
|
ADC_DMA_CONTROL_WORD);
|
|
|
|
|
|
|
|
/* No DMA callback */
|
|
|
|
|
|
|
|
stm32_dmastart(priv->dma, NULL, dev, false);
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
2020-01-31 19:07:39 +01:00
|
|
|
#endif /* ADC_HAVE_DMA */
|
2018-11-24 00:33:45 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: adc_inj_get
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef ADC_HAVE_INJECTED
|
|
|
|
static uint32_t adc_injget(FAR struct stm32_adc_dev_s *dev, uint8_t chan)
|
|
|
|
{
|
|
|
|
FAR struct stm32_dev_s *priv = (FAR struct stm32_dev_s *)dev;
|
|
|
|
uint32_t regval = 0;
|
|
|
|
|
2020-01-03 15:34:44 +01:00
|
|
|
if (chan > (priv->cj_channels - 1))
|
2018-11-24 00:33:45 +01:00
|
|
|
{
|
|
|
|
/* REVISIT: return valute with MSB set to indicate error ? */
|
|
|
|
|
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
|
2020-01-03 15:34:44 +01:00
|
|
|
regval = adc_getreg(priv, STM32_ADC_JDR1_OFFSET + 4 * (chan)) &
|
|
|
|
ADC_JDR_JDATA_MASK;
|
2018-11-24 00:33:45 +01:00
|
|
|
|
|
|
|
errout:
|
|
|
|
return regval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: adc_llops_inj_startconv
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-04-03 01:10:26 +02:00
|
|
|
static void adc_llops_inj_startconv(FAR struct stm32_adc_dev_s *dev,
|
|
|
|
bool enable)
|
2018-11-24 00:33:45 +01:00
|
|
|
{
|
|
|
|
FAR struct stm32_dev_s *priv = (FAR struct stm32_dev_s *)dev;
|
|
|
|
|
|
|
|
adc_inj_startconv(priv, enable);
|
|
|
|
}
|
|
|
|
|
2020-01-31 19:07:39 +01:00
|
|
|
#endif /* ADC_HAVE_INJECTED */
|
2018-11-24 00:33:45 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: adc_sampletime_write
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Writes previously defined values into ADC_SMPRx registers.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_STM32_ADC_CHANGE_SAMPLETIME
|
|
|
|
static void adc_sampletime_write(FAR struct stm32_adc_dev_s *dev)
|
|
|
|
{
|
|
|
|
FAR struct stm32_dev_s *priv = (FAR struct stm32_dev_s *)dev;
|
|
|
|
uint32_t value = 0;
|
|
|
|
uint8_t i;
|
|
|
|
uint8_t shift;
|
|
|
|
|
|
|
|
/* Sampling time individually for each channel.
|
|
|
|
* It's different for families.
|
|
|
|
*/
|
|
|
|
|
|
|
|
for (i = 0, shift = 0; i < priv->adc_channels; i++)
|
|
|
|
{
|
|
|
|
value |= priv->sample_rate[i] << (shift * 3);
|
|
|
|
switch (i)
|
|
|
|
{
|
|
|
|
#if defined(STM32_ADC_SMPR0_OFFSET) && defined(STM32_ADC_SMPR3_OFFSET)
|
|
|
|
case 9:
|
|
|
|
{
|
|
|
|
adc_putreg(priv, STM32_ADC_SMPR3_OFFSET, value);
|
|
|
|
shift = 0;
|
|
|
|
value = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 19:
|
|
|
|
{
|
|
|
|
adc_putreg(priv, STM32_ADC_SMPR2_OFFSET, value);
|
|
|
|
shift = 0;
|
|
|
|
value = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 29:
|
|
|
|
{
|
|
|
|
adc_putreg(priv, STM32_ADC_SMPR1_OFFSET, value);
|
|
|
|
shift = 0;
|
|
|
|
value = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case (ADC_CHANNELS_NUMBER - 1):
|
|
|
|
{
|
|
|
|
adc_putreg(priv, STM32_ADC_SMPR0_OFFSET, value);
|
|
|
|
shift = 0;
|
|
|
|
value = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
#elif defined(STM32_ADC_SMPR1_OFFSET) && defined(STM32_ADC_SMPR2_OFFSET)
|
|
|
|
case (ADC_CHANNELS_NUMBER - 1):
|
|
|
|
{
|
|
|
|
adc_putreg(priv, STM32_ADC_SMPR2_OFFSET, value);
|
|
|
|
shift = 0;
|
|
|
|
value = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 9:
|
|
|
|
{
|
|
|
|
adc_putreg(priv, STM32_ADC_SMPR1_OFFSET, value);
|
|
|
|
shift = 0;
|
|
|
|
value = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
# error "Not supported SMPRx configuration"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
shift++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-03 15:25:03 +02:00
|
|
|
/****************************************************************************
|
2015-07-29 16:34:27 +02:00
|
|
|
* Name: adc_change_sample_time
|
|
|
|
*
|
2015-11-05 16:09:37 +01:00
|
|
|
* Description:
|
|
|
|
* Changes sample times for specified channels. This method
|
|
|
|
* doesn't make any register writing. So, it's only stores the information.
|
|
|
|
* Values provided by user will be written in registers only on the next
|
|
|
|
* ADC peripheral start, as it was told to do in manual. However, before
|
|
|
|
* very first start, user can call this method and override default values
|
|
|
|
* either for every channels or for only some predefined by user channel(s)
|
2015-07-29 16:34:27 +02:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* priv - pointer to the adc device structure
|
|
|
|
* pdi_high - true: The ADC is powered down when waiting for a start event
|
|
|
|
* false: The ADC is powered up when waiting for a start event
|
|
|
|
*
|
|
|
|
* Returned Value:
|
2015-11-05 16:09:37 +01:00
|
|
|
* None
|
2015-07-29 16:34:27 +02:00
|
|
|
*
|
2015-10-03 15:25:03 +02:00
|
|
|
****************************************************************************/
|
2015-07-29 16:34:27 +02:00
|
|
|
|
2018-11-24 00:33:45 +01:00
|
|
|
void adc_sampletime_set(FAR struct stm32_adc_dev_s *dev,
|
|
|
|
FAR struct adc_sample_time_s *time_samples)
|
2015-07-29 16:34:27 +02:00
|
|
|
{
|
2018-11-24 00:33:45 +01:00
|
|
|
FAR struct stm32_dev_s *priv = (FAR struct stm32_dev_s *)dev;
|
2015-07-29 16:34:27 +02:00
|
|
|
uint8_t ch_index;
|
|
|
|
uint8_t i;
|
|
|
|
|
|
|
|
/* Check if user wants to assign the same value for all channels
|
2020-01-03 15:34:44 +01:00
|
|
|
* or just wants to change sample time values for certain channels
|
|
|
|
*/
|
2015-07-29 16:34:27 +02:00
|
|
|
|
|
|
|
if (time_samples->all_same)
|
|
|
|
{
|
|
|
|
memset(priv->sample_rate, time_samples->all_ch_sample_time,
|
|
|
|
ADC_CHANNELS_NUMBER);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (i = 0; i < time_samples->channels_nbr; i++)
|
|
|
|
{
|
2019-01-27 17:17:39 +01:00
|
|
|
ch_index = time_samples->channel[i].channel;
|
2015-07-29 16:34:27 +02:00
|
|
|
if (ch_index >= ADC_CHANNELS_NUMBER)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-01-27 17:17:39 +01:00
|
|
|
priv->sample_rate[ch_index] = time_samples->channel[i].sample_time;
|
2015-07-29 16:34:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-01-31 19:07:39 +01:00
|
|
|
#endif /* CONFIG_STM32_ADC_CHANGE_SAMPLETIME */
|
2018-11-24 00:33:45 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: adc_llops_dumpregs
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void adc_llops_dumpregs(FAR struct stm32_adc_dev_s *dev)
|
|
|
|
{
|
|
|
|
FAR struct stm32_dev_s *priv = (FAR struct stm32_dev_s *)dev;
|
|
|
|
|
|
|
|
adc_dumpregs(priv);
|
|
|
|
}
|
|
|
|
|
2020-01-31 19:07:39 +01:00
|
|
|
#endif /* CONFIG_STM32_ADC_LL_OPS */
|
2018-11-24 00:33:45 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
2015-07-29 16:34:27 +02:00
|
|
|
|
2011-12-12 02:04:53 +01:00
|
|
|
/****************************************************************************
|
2011-12-15 01:29:35 +01:00
|
|
|
* Name: stm32_adcinitialize
|
2011-12-12 02:04:53 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2011-12-15 14:33:15 +01:00
|
|
|
* Initialize the ADC.
|
|
|
|
*
|
2018-11-24 00:33:45 +01:00
|
|
|
* The logic allow initialize ADC regular and injected channels.
|
|
|
|
*
|
|
|
|
* The number of injected channels for given ADC is selected from Kconfig
|
|
|
|
* with CONFIG_STM32_ADCx_INJECTED_CHAN definitions
|
|
|
|
*
|
|
|
|
* The number of regular channels is obtained from the equation:
|
|
|
|
*
|
|
|
|
* cr_channels = channels - cj_channels
|
|
|
|
*
|
|
|
|
* where:
|
|
|
|
* cr_channels - regular channels
|
|
|
|
* cj_channels - injected channels
|
|
|
|
* channels - this function parameter
|
|
|
|
*
|
|
|
|
* The chanlist array store both regular channels and injected channels
|
|
|
|
* configuration so that regular channels are the first in order:
|
|
|
|
*
|
|
|
|
* # regular channels start from here
|
|
|
|
* chanlist[0] -> ADC_SQRx_SQ1
|
|
|
|
* chanlist[1] -> ADC_SQRx_SQ2
|
2011-12-15 14:33:15 +01:00
|
|
|
* ...
|
2018-11-24 00:33:45 +01:00
|
|
|
* # injected channels start from here
|
|
|
|
* chanlist[channels - (y - 1)] -> ADC_JSQR_JSQ1
|
|
|
|
* ...
|
|
|
|
* chanlist[channels] -> ADC_JSQR_ISQy
|
|
|
|
*
|
|
|
|
* where:
|
|
|
|
* y = CONFIG_STM32_ADCx_INJECTED_CHAN, and y > 0
|
2011-12-15 14:33:15 +01:00
|
|
|
*
|
2018-11-24 00:33:45 +01:00
|
|
|
* If CONFIG_STM32_ADCx_INJECTED_CHAN = 0, then all channels from chanlist
|
|
|
|
* are regular channels.
|
2011-12-15 01:29:35 +01:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
2018-11-24 00:33:45 +01:00
|
|
|
* intf - Could be {1,2,3,4} for ADC1, ADC2, ADC3 or ADC4
|
|
|
|
* chanlist - The list of channels (regular + injected)
|
|
|
|
* channels - Number of channels (regular + injected)
|
2011-12-12 02:04:53 +01:00
|
|
|
*
|
|
|
|
* Returned Value:
|
2019-09-17 18:46:23 +02:00
|
|
|
* Valid ADC device structure reference on success; a NULL on failure
|
2011-12-12 02:04:53 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2015-11-05 16:09:37 +01:00
|
|
|
struct adc_dev_s *stm32_adcinitialize(int intf, FAR const uint8_t *chanlist,
|
2018-11-24 00:33:45 +01:00
|
|
|
int channels)
|
2011-12-12 02:04:53 +01:00
|
|
|
{
|
2011-12-15 01:29:35 +01:00
|
|
|
FAR struct adc_dev_s *dev;
|
|
|
|
FAR struct stm32_dev_s *priv;
|
2018-11-24 00:33:45 +01:00
|
|
|
uint8_t cr_channels = 0;
|
|
|
|
uint8_t cj_channels = 0;
|
|
|
|
#ifdef ADC_HAVE_INJECTED
|
|
|
|
FAR uint8_t *j_chanlist = NULL;
|
|
|
|
#endif
|
2011-12-16 01:32:11 +01:00
|
|
|
|
2015-11-05 16:09:37 +01:00
|
|
|
switch (intf)
|
2011-12-12 02:04:53 +01:00
|
|
|
{
|
2015-11-05 16:09:37 +01:00
|
|
|
#ifdef CONFIG_STM32_ADC1
|
|
|
|
case 1:
|
2018-11-24 00:33:45 +01:00
|
|
|
{
|
|
|
|
ainfo("ADC1 selected\n");
|
|
|
|
dev = &g_adcdev1;
|
|
|
|
cj_channels = CONFIG_STM32_ADC1_INJECTED_CHAN;
|
|
|
|
cr_channels = channels - cj_channels;
|
|
|
|
# ifdef ADC_HAVE_INJECTED
|
|
|
|
if (cj_channels > 0)
|
|
|
|
{
|
|
|
|
j_chanlist = (FAR uint8_t *)chanlist + cr_channels;
|
|
|
|
}
|
|
|
|
# endif
|
|
|
|
break;
|
|
|
|
}
|
2020-01-03 15:34:44 +01:00
|
|
|
|
2020-01-31 19:07:39 +01:00
|
|
|
#endif /* CONFIG_STM32_ADC1 */
|
2011-12-12 02:04:53 +01:00
|
|
|
#ifdef CONFIG_STM32_ADC2
|
2015-11-05 16:09:37 +01:00
|
|
|
case 2:
|
2018-11-24 00:33:45 +01:00
|
|
|
{
|
|
|
|
ainfo("ADC2 selected\n");
|
|
|
|
dev = &g_adcdev2;
|
|
|
|
cj_channels = CONFIG_STM32_ADC2_INJECTED_CHAN;
|
|
|
|
cr_channels = channels - cj_channels;
|
|
|
|
# ifdef ADC_HAVE_INJECTED
|
|
|
|
if (cj_channels > 0)
|
|
|
|
{
|
|
|
|
j_chanlist = (FAR uint8_t *)chanlist + cr_channels;
|
|
|
|
}
|
|
|
|
# endif
|
|
|
|
break;
|
|
|
|
}
|
2020-01-03 15:34:44 +01:00
|
|
|
|
2020-01-31 19:07:39 +01:00
|
|
|
#endif /* CONFIG_STM32_ADC2 */
|
2011-12-12 02:04:53 +01:00
|
|
|
#ifdef CONFIG_STM32_ADC3
|
2015-11-05 16:09:37 +01:00
|
|
|
case 3:
|
2018-11-24 00:33:45 +01:00
|
|
|
{
|
|
|
|
ainfo("ADC3 selected\n");
|
|
|
|
dev = &g_adcdev3;
|
|
|
|
cj_channels = CONFIG_STM32_ADC3_INJECTED_CHAN;
|
|
|
|
cr_channels = channels - cj_channels;
|
|
|
|
# ifdef ADC_HAVE_INJECTED
|
|
|
|
if (cj_channels > 0)
|
|
|
|
{
|
|
|
|
j_chanlist = (FAR uint8_t *)chanlist + cr_channels;
|
|
|
|
}
|
|
|
|
# endif
|
|
|
|
break;
|
|
|
|
}
|
2020-01-03 15:34:44 +01:00
|
|
|
|
2020-01-31 19:07:39 +01:00
|
|
|
#endif /* CONFIG_STM32_ADC3 */
|
2015-11-05 16:09:37 +01:00
|
|
|
#ifdef CONFIG_STM32_ADC4
|
|
|
|
case 4:
|
2018-11-24 00:33:45 +01:00
|
|
|
{
|
|
|
|
ainfo("ADC4 selected\n");
|
|
|
|
dev = &g_adcdev4;
|
|
|
|
cj_channels = CONFIG_STM32_ADC4_INJECTED_CHAN;
|
|
|
|
cr_channels = channels - cj_channels;
|
|
|
|
# ifdef ADC_HAVE_INJECTED
|
|
|
|
if (cj_channels > 0)
|
|
|
|
{
|
|
|
|
j_chanlist = (FAR uint8_t *)chanlist + cr_channels;
|
|
|
|
}
|
|
|
|
# endif
|
|
|
|
break;
|
|
|
|
}
|
2020-01-03 15:34:44 +01:00
|
|
|
|
2020-01-31 19:07:39 +01:00
|
|
|
#endif /* CONFIG_STM32_ADC4 */
|
2015-11-05 16:09:37 +01:00
|
|
|
default:
|
2018-11-24 00:33:45 +01:00
|
|
|
{
|
|
|
|
aerr("ERROR: No ADC interface defined\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-12-12 02:04:53 +01:00
|
|
|
}
|
2011-12-15 01:29:35 +01:00
|
|
|
|
|
|
|
/* Configure the selected ADC */
|
|
|
|
|
2015-11-05 16:09:37 +01:00
|
|
|
priv = (FAR struct stm32_dev_s *)dev->ad_priv;
|
2012-03-10 01:02:11 +01:00
|
|
|
|
2018-11-24 00:33:45 +01:00
|
|
|
/* Configure regular channels */
|
|
|
|
|
|
|
|
DEBUGASSERT(cr_channels <= ADC_MAX_SAMPLES);
|
|
|
|
|
|
|
|
priv->cr_channels = cr_channels;
|
|
|
|
memcpy(priv->r_chanlist, chanlist, cr_channels);
|
|
|
|
|
|
|
|
#ifdef ADC_HAVE_INJECTED
|
|
|
|
/* Configure injected channels */
|
|
|
|
|
|
|
|
DEBUGASSERT(cj_channels <= ADC_INJ_MAX_SAMPLES);
|
|
|
|
|
|
|
|
priv->cj_channels = cj_channels;
|
|
|
|
memcpy(priv->j_chanlist, j_chanlist, cj_channels);
|
|
|
|
#endif
|
|
|
|
|
2018-11-12 16:45:55 +01:00
|
|
|
#ifdef CONFIG_STM32_ADC_CHANGE_SAMPLETIME
|
2015-07-29 16:34:27 +02:00
|
|
|
/* Assign default values for the sample time table */
|
|
|
|
|
2015-11-05 16:09:37 +01:00
|
|
|
memset(priv->sample_rate, ADC_SMPR_DEFAULT, ADC_CHANNELS_NUMBER);
|
2018-11-12 16:45:55 +01:00
|
|
|
priv->adc_channels = ADC_CHANNELS_NUMBER;
|
2015-07-29 16:34:27 +02:00
|
|
|
#endif
|
|
|
|
|
2020-04-21 21:35:54 +02:00
|
|
|
#ifdef ADC_HAVE_CB
|
2016-05-26 20:25:54 +02:00
|
|
|
priv->cb = NULL;
|
2018-11-24 00:33:45 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef ADC_HAVE_INJECTED
|
|
|
|
ainfo("intf: %d cr_channels: %d, cj_channels: %d\n",
|
|
|
|
intf, priv->cr_channels, priv->cj_channels);
|
|
|
|
#else
|
|
|
|
ainfo("intf: %d cr_channels: %d\n", intf, priv->cr_channels);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_ADC_CMN_DATA
|
|
|
|
/* Initialize the ADC common data semaphore.
|
|
|
|
*
|
|
|
|
* REVISIT: This will be done several times for each initialzied ADC in
|
|
|
|
* the ADC block.
|
|
|
|
*/
|
2015-07-29 16:34:27 +02:00
|
|
|
|
2018-11-24 00:33:45 +01:00
|
|
|
nxsem_init(&priv->cmn->lock, 0, 1);
|
|
|
|
#endif
|
2012-03-10 01:02:11 +01:00
|
|
|
|
2011-12-15 01:29:35 +01:00
|
|
|
return dev;
|
2011-12-12 02:04:53 +01:00
|
|
|
}
|
|
|
|
|
2015-11-05 16:09:37 +01:00
|
|
|
#endif /* CONFIG_STM32_ADC1 || CONFIG_STM32_ADC2 ||
|
|
|
|
* CONFIG_STM32_ADC3 || CONFIG_STM32_ADC4
|
|
|
|
*/
|
2016-05-27 14:46:33 +02:00
|
|
|
#endif /* CONFIG_STM32_ADC */
|