/** * @brief Initialize some features of OPAMP instance. * @note This function reset bit of calibration mode to ensure * to be in functional mode, in order to have OPAMP parameters * (inputs selection, ...) set with the corresponding OPAMP mode * to be effective. * @param OPAMPx OPAMP instance * @param OPAMP_InitStruct Pointer to a @ref LL_OPAMP_InitTypeDef structure * @retval An ErrorStatus enumeration value: * - SUCCESS: OPAMP registers are initialized * - ERROR: OPAMP registers are not initialized */ ErrorStatus LL_OPAMP_Init(OPAMP_TypeDef *OPAMPx, LL_OPAMP_InitTypeDef *OPAMP_InitStruct) { ErrorStatus status = SUCCESS; /* Check the parameters */ assert_param(IS_OPAMP_ALL_INSTANCE(OPAMPx)); assert_param(IS_LL_OPAMP_FUNCTIONAL_MODE(OPAMP_InitStruct->FunctionalMode)); assert_param(IS_LL_OPAMP_INPUT_NONINVERTING(OPAMPx, OPAMP_InitStruct->InputNonInverting)); /* Note: OPAMP inverting input can be used with OPAMP in mode standalone */ /* or PGA with external capacitors for filtering circuit. */ /* Otherwise (OPAMP in mode follower), OPAMP inverting input is */ /* not used (not connected to GPIO pin). */ if(OPAMP_InitStruct->FunctionalMode != LL_OPAMP_MODE_FOLLOWER) { assert_param(IS_LL_OPAMP_INPUT_INVERTING(OPAMPx, OPAMP_InitStruct->InputInverting)); } /* Note: Hardware constraint (refer to description of this function): */ /* OPAMP instance must not be locked. */ if(LL_OPAMP_IsLocked(OPAMPx) == 0U) { /* Configuration of OPAMP instance : */ /* - Functional mode */ /* - Input non-inverting */ /* - Input inverting */ /* Note: Bit OPAMP_CSR_CALON reset to ensure to be in functional mode. */ if(OPAMP_InitStruct->FunctionalMode != LL_OPAMP_MODE_FOLLOWER) { MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_CALON | OPAMP_CSR_VMSEL | OPAMP_CSR_VPSEL , OPAMP_InitStruct->FunctionalMode | OPAMP_InitStruct->InputNonInverting | OPAMP_InitStruct->InputInverting ); } else { MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_CALON | OPAMP_CSR_VMSEL | OPAMP_CSR_VPSEL , LL_OPAMP_MODE_FOLLOWER | OPAMP_InitStruct->InputNonInverting ); } } else { /* Initialization error: OPAMP instance is locked. */ status = ERROR; } return status; }
/** * @brief Initialize some features of OPAMP instance. * @note This function reset bit of calibration mode to ensure * to be in functional mode, in order to have OPAMP parameters * (inputs selection, ...) set with the corresponding OPAMP mode * to be effective. * @note This function configures features of the selected OPAMP instance. * Some features are also available at scope OPAMP common instance * (common to several OPAMP instances). * Refer to functions having argument "OPAMPxy_COMMON" as parameter. * @param OPAMPx OPAMP instance * @param OPAMP_InitStruct Pointer to a @ref LL_OPAMP_InitTypeDef structure * @retval An ErrorStatus enumeration value: * - SUCCESS: OPAMP registers are initialized * - ERROR: OPAMP registers are not initialized */ ErrorStatus LL_OPAMP_Init(OPAMP_TypeDef *OPAMPx, LL_OPAMP_InitTypeDef *OPAMP_InitStruct) { /* Check the parameters */ assert_param(IS_OPAMP_ALL_INSTANCE(OPAMPx)); assert_param(IS_LL_OPAMP_POWER_MODE(OPAMP_InitStruct->PowerMode)); assert_param(IS_LL_OPAMP_FUNCTIONAL_MODE(OPAMP_InitStruct->FunctionalMode)); assert_param(IS_LL_OPAMP_INPUT_NONINVERTING(OPAMPx, OPAMP_InitStruct->InputNonInverting)); /* Note: OPAMP inverting input can be used with OPAMP in mode standalone */ /* or PGA with external capacitors for filtering circuit. */ /* Otherwise (OPAMP in mode follower), OPAMP inverting input is */ /* not used (not connected to GPIO pin). */ if(OPAMP_InitStruct->FunctionalMode != LL_OPAMP_MODE_FOLLOWER) { assert_param(IS_LL_OPAMP_INPUT_INVERTING(OPAMPx, OPAMP_InitStruct->InputInverting)); } /* Configuration of OPAMP instance : */ /* - PowerMode */ /* - Functional mode */ /* - Input non-inverting */ /* - Input inverting */ /* Note: Bit OPAMP_CSR_CALON reset to ensure to be in functional mode. */ if(OPAMP_InitStruct->FunctionalMode != LL_OPAMP_MODE_FOLLOWER) { MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_OPALPM | OPAMP_CSR_OPAMODE | OPAMP_CSR_CALON | OPAMP_CSR_VMSEL | OPAMP_CSR_VPSEL , (OPAMP_InitStruct->PowerMode & OPAMP_POWERMODE_CSR_BIT_MASK) | OPAMP_InitStruct->FunctionalMode | OPAMP_InitStruct->InputNonInverting | OPAMP_InitStruct->InputInverting ); } else { MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_OPALPM | OPAMP_CSR_OPAMODE | OPAMP_CSR_CALON | OPAMP_CSR_VMSEL | OPAMP_CSR_VPSEL , (OPAMP_InitStruct->PowerMode & OPAMP_POWERMODE_CSR_BIT_MASK) | LL_OPAMP_MODE_FOLLOWER | OPAMP_InitStruct->InputNonInverting | LL_OPAMP_INPUT_INVERT_CONNECT_NO ); } return SUCCESS; }