/** * @brief Initialize the SWPMI peripheral according to the specified parameters in the SWPMI_InitStruct. * @note As some bits in SWPMI configuration registers can only be written when the SWPMI is deactivated (SWPMI_CR_SWPACT bit = 0), * SWPMI IP should be in deactivated state prior calling this function. Otherwise, ERROR result will be returned. * @param SWPMIx SWPMI Instance * @param SWPMI_InitStruct pointer to a @ref LL_SWPMI_InitTypeDef structure that contains * the configuration information for the SWPMI peripheral. * @retval An ErrorStatus enumeration value * - SUCCESS: SWPMI registers are initialized * - ERROR: SWPMI registers are not initialized */ ErrorStatus LL_SWPMI_Init(SWPMI_TypeDef *SWPMIx, LL_SWPMI_InitTypeDef *SWPMI_InitStruct) { ErrorStatus status = SUCCESS; /* Check the parameters */ assert_param(IS_SWPMI_INSTANCE(SWPMIx)); assert_param(IS_LL_SWPMI_BITRATE_VALUE(SWPMI_InitStruct->BitRatePrescaler)); assert_param(IS_LL_SWPMI_SW_BUFFER_TX(SWPMI_InitStruct->TxBufferingMode)); assert_param(IS_LL_SWPMI_SW_BUFFER_RX(SWPMI_InitStruct->RxBufferingMode)); assert_param(IS_LL_SWPMI_VOLTAGE_CLASS(SWPMI_InitStruct->VoltageClass)); /* SWPMI needs to be in deactivated state, in order to be able to configure some bits */ if (LL_SWPMI_IsActivated(SWPMIx) == 0) { /* Configure the BRR register (Bitrate) */ LL_SWPMI_SetBitRatePrescaler(SWPMIx, SWPMI_InitStruct->BitRatePrescaler); /* Configure the voltage class */ LL_SWPMI_SetVoltageClass(SWPMIx, SWPMI_InitStruct->VoltageClass); /* Set the new configuration of the SWPMI peripheral */ MODIFY_REG(SWPMIx->CR, (SWPMI_CR_RXMODE | SWPMI_CR_TXMODE), (SWPMI_InitStruct->TxBufferingMode | SWPMI_InitStruct->RxBufferingMode)); } /* Else (SWPMI not in deactivated state => return ERROR) */ else { status = ERROR; } return status; }
/** * @brief De-initialize the SWPMI peripheral. * @param hswpmi: SWPMI handle * @retval HAL status */ HAL_StatusTypeDef HAL_SWPMI_DeInit(SWPMI_HandleTypeDef *hswpmi) { HAL_StatusTypeDef status = HAL_OK; /* Check the SWPMI handle allocation */ if(hswpmi == NULL) { status = HAL_ERROR; } else { /* Check the parameters */ assert_param(IS_SWPMI_INSTANCE(hswpmi->Instance)); hswpmi->State = HAL_SWPMI_STATE_BUSY; /* Disable SWPMI interface */ CLEAR_BIT(hswpmi->Instance->CR, SWPMI_CR_SWPACT); /* DeInit the low level hardware */ HAL_SWPMI_MspDeInit(hswpmi); hswpmi->ErrorCode = HAL_SWPMI_ERROR_NONE; hswpmi->State = HAL_SWPMI_STATE_RESET; /* Release Lock */ __HAL_UNLOCK(hswpmi); } return status; }
/** * @brief De-initialize the SWPMI peripheral registers to their default reset values. * @param SWPMIx SWPMI Instance * @retval An ErrorStatus enumeration value * - SUCCESS: SWPMI registers are de-initialized * - ERROR: Not applicable */ ErrorStatus LL_SWPMI_DeInit(SWPMI_TypeDef *SWPMIx) { /* Check the parameter */ assert_param(IS_SWPMI_INSTANCE(SWPMIx)); LL_APB1_GRP2_ForceReset(LL_APB1_GRP2_PERIPH_SWPMI1); LL_APB1_GRP2_ReleaseReset(LL_APB1_GRP2_PERIPH_SWPMI1); return SUCCESS; }