STM32F33: Add OPAMP support

This commit is contained in:
raiden00pl 2017-04-30 11:05:34 +02:00
parent b688d41516
commit e4d47d61cc
6 changed files with 1661 additions and 6 deletions

View File

@ -221,6 +221,10 @@ ifeq ($(CONFIG_COMP),y)
CHIP_CSRCS += stm32_comp.c
endif
ifeq ($(CONFIG_OPAMP),y)
CHIP_CSRCS += stm32_opamp.c
endif
ifeq ($(CONFIG_STM32_1WIREDRIVER),y)
CHIP_CSRCS += stm32_1wire.c
endif

View File

@ -54,7 +54,7 @@
/* Register Addresses *******************************************************************************/
#define STM32_OPAMP2_CSR (STM32_OPAMP2_BASE+STM32_OPAMP2_CSR_OFFSET)
#define STM32_OPAMP2_CSR (STM32_OPAMP_BASE+STM32_OPAMP2_CSR_OFFSET)
/* Register Bitfield Definitions ****************************************************/
@ -66,7 +66,7 @@
#define OPAMP_CSR_VPSEL_SHIFT (3) /* Bits 2-3: OPAMP non inverting input selection */
#define OPAMP_CSR_VPSEL_MASK (3 << OPAMP_CSR_VPSEL_SHIFT)
/* 00: Reserved */
# define OPAMP_CSR_VPSEL_PB13 (1 << OPAMP_CSR_VPSEL_SHIFT) /* 01: PB14 */
# define OPAMP_CSR_VPSEL_PB14 (1 << OPAMP_CSR_VPSEL_SHIFT) /* 01: PB14 */
# define OPAMP_CSR_VPSEL_PB0 (2 << OPAMP_CSR_VPSEL_SHIFT) /* 10: PB0 */
# define OPAMP_CSR_VPSEL_PA7 (3 << OPAMP_CSR_VPSEL_SHIFT) /* 11: PA7 */
/* Bit 4: Reserved */
@ -74,7 +74,7 @@
#define OPAMP_CSR_VMSEL_MASK (3 << OPAMP_CSR_VMSEL_SHIFT)
# define OPAMP_CSR_VMSEL_PC5 (0 << OPAMP_CSR_VMSEL_SHIFT) /* 00: PC5 */
# define OPAMP_CSR_VMSEL_PA5 (1 << OPAMP_CSR_VMSEL_SHIFT) /* 01: PA5 */
# define OPAMP_CSR_VMSEL_RESISTOR (2 << OPAMP_CSR_VMSEL_SHIFT) /* 10: Resistor feedback output */
# define OPAMP_CSR_VMSEL_PGA (2 << OPAMP_CSR_VMSEL_SHIFT) /* 10: Resistor feedback output (PGA mode)*/
# define OPAMP_CSR_VMSEL_FOLLOWER (3 << OPAMP_CSR_VMSEL_SHIFT) /* 11: Follower mode */
#define OPAMP_CSR_TCMEN (1 << 7) /* Bit 7: Timer controlled Mux mode enable */
#define OPAMP_CSR_VMSSEL (1 << 8) /* Bit 8: OPAMP inverting input secondary selection */

View File

@ -337,9 +337,10 @@
#define GPIO_OPAMP2_VINM_1 (GPIO_ANALOG|GPIO_PORTA|GPIO_PIN5)
#define GPIO_OPAMP2_VINM_2 (GPIO_ANALOG|GPIO_PORTC|GPIO_PIN5)
#define GPIO_OPAMP2_VOUT (GPIO_ANALOG|GPIO_PORTA|GPIO_PIN6)
#define GPIO_OPAMP2_VINP_1 (GPIO_ANALOG|GPIO_PORTA|GPIO_PIN7)
#define GPIO_OPAMP2_VINP_2 (GPIO_ANALOG|GPIO_PORTB|GPIO_PIN0)
#define GPIO_OPAMP2_VINP_3 (GPIO_ANALOG|GPIO_PORTB|GPIO_PIN14)
#undef GPIO_OPAMP2_VINP_1 /* not supported in F33XX */
#define GPIO_OPAMP2_VINP_2 (GPIO_ANALOG|GPIO_PORTA|GPIO_PIN7)
#define GPIO_OPAMP2_VINP_3 (GPIO_ANALOG|GPIO_PORTB|GPIO_PIN0)
#define GPIO_OPAMP2_VINP_4 (GPIO_ANALOG|GPIO_PORTB|GPIO_PIN14)
/* TSC */

View File

@ -69,6 +69,7 @@
#include "stm32_gpio.h"
#include "stm32_i2c.h"
#include "stm32_ltdc.h"
#include "stm32_opamp.h"
#include "stm32_pwr.h"
#include "stm32_rcc.h"
#include "stm32_rtc.h"

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,231 @@
/************************************************************************************
* arch/arm/src/stm32/stm32_opamp.h
*
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
* Author: Mateusz Szafoni <raiden00@railab.me>
*
* 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.
*
************************************************************************************/
#ifndef __ARCH_ARM_SRC_STM32_STM32_OPAMP_H
#define __ARCH_ARM_SRC_STM32_STM32_OPAMP_H
/************************************************************************************
* Included Files
************************************************************************************/
#include <nuttx/config.h>
#include "chip.h"
#ifdef CONFIG_STM32_OPAMP
#if defined(CONFIG_STM32_STM32F30XX)
# error "OPAMP support for STM32F30XX not implemented yet"
#elif defined(CONFIG_STM32_STM32F33XX)
# include "chip/stm32f33xxx_opamp.h"
#endif
#include <nuttx/analog/opamp.h>
/************************************************************************************
* Pre-processor definitions
************************************************************************************/
/* OPAMP operation mode */
#define OPAMP_MODE_STANDALONE 0
#define OPAMP_MODE_FOLLOWER 1
#define OPAMP_MODE_PGA 2
/* Timer controlled Mux mode */
#define OPAMP_MUX_DISABLE 0
#define OPAMP_MUX_ENABLE 1
/* User callibration */
#define OPAMP_USERCAL_DISABLE 0
#define OPAMP_USERCAL_ENABLE 1
/* Default configuration */
#define OPAMP_MODE_DEFAULT OPAMP_MODE_STANDALONE /* Standalone mode */
#define OPAMP_MUX_DEFAULT OPAMP_MUX_DISABLE /* MUX disabled */
#define OPAMP_USERCAL_DEFAULT OPAMP_USERCAL_DISABLE /* User calibration disabled */
#define OPAMP_GAIN_DEFAULT OPAMP_GAIN_2 /* Gain in PGA mode = 2 */
#define OPAMP_LOCK_DEFAULT OPAMP_LOCK_RW /* Do not lock CSR register */
/************************************************************************************
* Public Types
************************************************************************************/
/* CSR register lock state */
enum stm32_opamp_lock_e
{
OPAMP_LOCK_RW,
OPAMP_LOCK_RO
};
/* Gain in PGA mode */
enum stm32_opamp_gain_e
{
OPAMP_GAIN_2,
OPAMP_GAIN_4,
OPAMP_GAIN_8,
OPAMP_GAIN_2_VM0,
OPAMP_GAIN_4_VM0,
OPAMP_GAIN_8_VM0,
OPAMP_GAIN_16_VM0,
OPAMP_GAIN_2_VM1,
OPAMP_GAIN_4_VM1,
OPAMP_GAIN_8_VM1,
OPAMP_GAIN_16_VM1
};
/* Input selection and secondary input selection use the same GPIOs */
#ifdef CONFIG_STM32_OPAMP1
enum stm32_opamp1_vpsel_e
{
OPAMP1_VPSEL_PA7,
OPAMP1_VPSEL_PA5,
OPAMP1_VPSEL_PA3,
OPAMP1_VPSEL_PA1
};
enum stm32_opamp1_vmsel_e
{
OPAMP1_VMSEL_PC5,
OPAMP1_VMSEL_PA3,
OPAMP1_VMSEL_PGAMODE,
OPAMP1_VMSEL_FOLLOWER,
};
#endif
#ifdef CONFIG_STM32_OPAMP2
enum stm32_opamp2_vpsel_e
{
#ifndef CONFIG_STM32_STM32F33XX
/* TODO: STM32F303xB/C and STM32F358C devices only */
OPAMP2_VPSEL_PD14,
#endif
OPAMP2_VPSEL_PB14,
OPAMP2_VPSEL_PB0,
OPAMP2_VPSEL_PA7
};
enum stm32_opamp2_vmsel_e
{
OPAMP2_VMSEL_PC5,
OPAMP2_VMSEL_PA5,
OPAMP2_VMSEL_PGAMODE,
OPAMP2_VMSEL_FOLLOWER
};
#endif
#ifdef CONFIG_STM32_OPAMP3
enum stm32_opamp3_vpsel_e
{
OPAMP3_VPSEL_PB13,
OPAMP3_VPSEL_PA5,
OPAMP3_VPSEL_PA1,
OPAMP3_VPSEL_PB0
};
enum stm32_opamp3_vmsel_e
{
OPAMP3_VMSEL_PB10,
OPAMP3_VMSEL_PB2,
OPAMP3_VMSEL_PGAMODE,
OPAMP3_VMSEL_FOLLOWER
};
#endif
#ifdef CONFIG_STM32_OPAMP4
enum stm32_opamp4_vpsel_e
{
OPAMP4_VPSEL_PD11,
OPAMP4_VPSEL_PB11,
OPAMP4_VPSEL_PA4,
OPAMP4_VPSEL_PB13
};
enum stm32_opamp4_vmsel_e
{
OPAMP4_VMSEL_PB10,
OPAMP4_VMSEL_PD8,
OPAMP4_VMSEL_PGAMODE,
OPAMP4_VMSEL_FOLLOWER
};
#endif
/************************************************************************************
* Public Function Prototypes
************************************************************************************/
#ifndef __ASSEMBLY__
#ifdef __cplusplus
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
/****************************************************************************
* Name: stm32_opampinitialize
*
* Description:
* Initialize the OPAMP.
*
* Input Parameters:
* intf - The OPAMP interface number.
*
* Returned Value:
* Valid OPAMP device structure reference on succcess; a NULL on failure.
*
* Assumptions:
* 1. Clock to the OPAMP block has enabled,
* 2. Board-specific logic has already configured
*
****************************************************************************/
FAR struct opamp_dev_s* stm32_opampinitialize(int intf);
#undef EXTERN
#ifdef __cplusplus
}
#endif
#endif /* __ASSEMBLY__ */
#endif /* CONFIG_STM32_OPAMP */
#endif /* __ARCH_ARM_SRC_STM32_STM32_OPAMP_H */