mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2025-08-19 09:38:32 -04:00
Added STM32 Rowley demo.
This commit is contained in:
parent
fa73924b8d
commit
5472e527b5
46 changed files with 15154 additions and 0 deletions
907
Demo/CORTEX_STM32F103_GCC_Rowley/ST Library/src/stm32f10x_can.c
Normal file
907
Demo/CORTEX_STM32F103_GCC_Rowley/ST Library/src/stm32f10x_can.c
Normal file
|
@ -0,0 +1,907 @@
|
|||
/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
|
||||
* File Name : stm32f10x_can.c
|
||||
* Author : MCD Application Team
|
||||
* Version : V2.0.1
|
||||
* Date : 06/13/2008
|
||||
* Description : This file provides all the CAN firmware functions.
|
||||
********************************************************************************
|
||||
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
|
||||
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
|
||||
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
|
||||
* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
|
||||
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
|
||||
*******************************************************************************/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32f10x_can.h"
|
||||
#include "stm32f10x_rcc.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* CAN Master Control Register bits */
|
||||
#define CAN_MCR_INRQ ((u32)0x00000001) /* Initialization request */
|
||||
#define CAN_MCR_SLEEP ((u32)0x00000002) /* Sleep mode request */
|
||||
#define CAN_MCR_TXFP ((u32)0x00000004) /* Transmit FIFO priority */
|
||||
#define CAN_MCR_RFLM ((u32)0x00000008) /* Receive FIFO locked mode */
|
||||
#define CAN_MCR_NART ((u32)0x00000010) /* No automatic retransmission */
|
||||
#define CAN_MCR_AWUM ((u32)0x00000020) /* Automatic wake up mode */
|
||||
#define CAN_MCR_ABOM ((u32)0x00000040) /* Automatic bus-off management */
|
||||
#define CAN_MCR_TTCM ((u32)0x00000080) /* time triggered communication */
|
||||
|
||||
/* CAN Master Status Register bits */
|
||||
#define CAN_MSR_INAK ((u32)0x00000001) /* Initialization acknowledge */
|
||||
#define CAN_MSR_WKUI ((u32)0x00000008) /* Wake-up interrupt */
|
||||
#define CAN_MSR_SLAKI ((u32)0x00000010) /* Sleep acknowledge interrupt */
|
||||
|
||||
/* CAN Transmit Status Register bits */
|
||||
#define CAN_TSR_RQCP0 ((u32)0x00000001) /* Request completed mailbox0 */
|
||||
#define CAN_TSR_TXOK0 ((u32)0x00000002) /* Transmission OK of mailbox0 */
|
||||
#define CAN_TSR_ABRQ0 ((u32)0x00000080) /* Abort request for mailbox0 */
|
||||
#define CAN_TSR_RQCP1 ((u32)0x00000100) /* Request completed mailbox1 */
|
||||
#define CAN_TSR_TXOK1 ((u32)0x00000200) /* Transmission OK of mailbox1 */
|
||||
#define CAN_TSR_ABRQ1 ((u32)0x00008000) /* Abort request for mailbox1 */
|
||||
#define CAN_TSR_RQCP2 ((u32)0x00010000) /* Request completed mailbox2 */
|
||||
#define CAN_TSR_TXOK2 ((u32)0x00020000) /* Transmission OK of mailbox2 */
|
||||
#define CAN_TSR_ABRQ2 ((u32)0x00800000) /* Abort request for mailbox2 */
|
||||
#define CAN_TSR_TME0 ((u32)0x04000000) /* Transmit mailbox 0 empty */
|
||||
#define CAN_TSR_TME1 ((u32)0x08000000) /* Transmit mailbox 1 empty */
|
||||
#define CAN_TSR_TME2 ((u32)0x10000000) /* Transmit mailbox 2 empty */
|
||||
|
||||
/* CAN Receive FIFO 0 Register bits */
|
||||
#define CAN_RF0R_FULL0 ((u32)0x00000008) /* FIFO 0 full */
|
||||
#define CAN_RF0R_FOVR0 ((u32)0x00000010) /* FIFO 0 overrun */
|
||||
#define CAN_RF0R_RFOM0 ((u32)0x00000020) /* Release FIFO 0 output mailbox */
|
||||
|
||||
/* CAN Receive FIFO 1 Register bits */
|
||||
#define CAN_RF1R_FULL1 ((u32)0x00000008) /* FIFO 1 full */
|
||||
#define CAN_RF1R_FOVR1 ((u32)0x00000010) /* FIFO 1 overrun */
|
||||
#define CAN_RF1R_RFOM1 ((u32)0x00000020) /* Release FIFO 1 output mailbox */
|
||||
|
||||
/* CAN Error Status Register bits */
|
||||
#define CAN_ESR_EWGF ((u32)0x00000001) /* Error warning flag */
|
||||
#define CAN_ESR_EPVF ((u32)0x00000002) /* Error passive flag */
|
||||
#define CAN_ESR_BOFF ((u32)0x00000004) /* Bus-off flag */
|
||||
|
||||
/* CAN Mailbox Transmit Request */
|
||||
#define CAN_TMIDxR_TXRQ ((u32)0x00000001) /* Transmit mailbox request */
|
||||
|
||||
/* CAN Filter Master Register bits */
|
||||
#define CAN_FMR_FINIT ((u32)0x00000001) /* Filter init mode */
|
||||
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
static ITStatus CheckITStatus(u32 CAN_Reg, u32 It_Bit);
|
||||
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
/*******************************************************************************
|
||||
* Function Name : CAN_DeInit
|
||||
* Description : Deinitializes the CAN peripheral registers to their default
|
||||
* reset values.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void CAN_DeInit(void)
|
||||
{
|
||||
/* Enable CAN reset state */
|
||||
RCC_APB1PeriphResetCmd(RCC_APB1Periph_CAN, ENABLE);
|
||||
/* Release CAN from reset state */
|
||||
RCC_APB1PeriphResetCmd(RCC_APB1Periph_CAN, DISABLE);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : CAN_Init
|
||||
* Description : Initializes the CAN peripheral according to the specified
|
||||
* parameters in the CAN_InitStruct.
|
||||
* Input : CAN_InitStruct: pointer to a CAN_InitTypeDef structure that
|
||||
contains the configuration information for the CAN peripheral.
|
||||
* Output : None.
|
||||
* Return : Constant indicates initialization succeed which will be
|
||||
* CANINITFAILED or CANINITOK.
|
||||
*******************************************************************************/
|
||||
u8 CAN_Init(CAN_InitTypeDef* CAN_InitStruct)
|
||||
{
|
||||
u8 InitStatus = 0;
|
||||
u16 WaitAck;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_FUNCTIONAL_STATE(CAN_InitStruct->CAN_TTCM));
|
||||
assert_param(IS_FUNCTIONAL_STATE(CAN_InitStruct->CAN_ABOM));
|
||||
assert_param(IS_FUNCTIONAL_STATE(CAN_InitStruct->CAN_AWUM));
|
||||
assert_param(IS_FUNCTIONAL_STATE(CAN_InitStruct->CAN_NART));
|
||||
assert_param(IS_FUNCTIONAL_STATE(CAN_InitStruct->CAN_RFLM));
|
||||
assert_param(IS_FUNCTIONAL_STATE(CAN_InitStruct->CAN_TXFP));
|
||||
assert_param(IS_CAN_MODE(CAN_InitStruct->CAN_Mode));
|
||||
assert_param(IS_CAN_SJW(CAN_InitStruct->CAN_SJW));
|
||||
assert_param(IS_CAN_BS1(CAN_InitStruct->CAN_BS1));
|
||||
assert_param(IS_CAN_BS2(CAN_InitStruct->CAN_BS2));
|
||||
assert_param(IS_CAN_PRESCALER(CAN_InitStruct->CAN_Prescaler));
|
||||
|
||||
/* Request initialisation */
|
||||
CAN->MCR = CAN_MCR_INRQ;
|
||||
|
||||
/* ...and check acknowledged */
|
||||
if ((CAN->MSR & CAN_MSR_INAK) == 0)
|
||||
{
|
||||
InitStatus = CANINITFAILED;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Set the time triggered communication mode */
|
||||
if (CAN_InitStruct->CAN_TTCM == ENABLE)
|
||||
{
|
||||
CAN->MCR |= CAN_MCR_TTCM;
|
||||
}
|
||||
else
|
||||
{
|
||||
CAN->MCR &= ~CAN_MCR_TTCM;
|
||||
}
|
||||
|
||||
/* Set the automatic bus-off management */
|
||||
if (CAN_InitStruct->CAN_ABOM == ENABLE)
|
||||
{
|
||||
CAN->MCR |= CAN_MCR_ABOM;
|
||||
}
|
||||
else
|
||||
{
|
||||
CAN->MCR &= ~CAN_MCR_ABOM;
|
||||
}
|
||||
|
||||
/* Set the automatic wake-up mode */
|
||||
if (CAN_InitStruct->CAN_AWUM == ENABLE)
|
||||
{
|
||||
CAN->MCR |= CAN_MCR_AWUM;
|
||||
}
|
||||
else
|
||||
{
|
||||
CAN->MCR &= ~CAN_MCR_AWUM;
|
||||
}
|
||||
|
||||
/* Set the no automatic retransmission */
|
||||
if (CAN_InitStruct->CAN_NART == ENABLE)
|
||||
{
|
||||
CAN->MCR |= CAN_MCR_NART;
|
||||
}
|
||||
else
|
||||
{
|
||||
CAN->MCR &= ~CAN_MCR_NART;
|
||||
}
|
||||
|
||||
/* Set the receive FIFO locked mode */
|
||||
if (CAN_InitStruct->CAN_RFLM == ENABLE)
|
||||
{
|
||||
CAN->MCR |= CAN_MCR_RFLM;
|
||||
}
|
||||
else
|
||||
{
|
||||
CAN->MCR &= ~CAN_MCR_RFLM;
|
||||
}
|
||||
|
||||
/* Set the transmit FIFO priority */
|
||||
if (CAN_InitStruct->CAN_TXFP == ENABLE)
|
||||
{
|
||||
CAN->MCR |= CAN_MCR_TXFP;
|
||||
}
|
||||
else
|
||||
{
|
||||
CAN->MCR &= ~CAN_MCR_TXFP;
|
||||
}
|
||||
|
||||
/* Set the bit timing register */
|
||||
CAN->BTR = (u32)((u32)CAN_InitStruct->CAN_Mode << 30) | ((u32)CAN_InitStruct->CAN_SJW << 24) |
|
||||
((u32)CAN_InitStruct->CAN_BS1 << 16) | ((u32)CAN_InitStruct->CAN_BS2 << 20) |
|
||||
((u32)CAN_InitStruct->CAN_Prescaler - 1);
|
||||
|
||||
InitStatus = CANINITOK;
|
||||
|
||||
/* Request leave initialisation */
|
||||
CAN->MCR &= ~CAN_MCR_INRQ;
|
||||
|
||||
/* Wait the acknowledge */
|
||||
for(WaitAck = 0x400; WaitAck > 0x0; WaitAck--)
|
||||
{
|
||||
}
|
||||
|
||||
/* ...and check acknowledged */
|
||||
if ((CAN->MSR & CAN_MSR_INAK) == CAN_MSR_INAK)
|
||||
{
|
||||
InitStatus = CANINITFAILED;
|
||||
}
|
||||
}
|
||||
|
||||
/* At this step, return the status of initialization */
|
||||
return InitStatus;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : CAN_FilterInit
|
||||
* Description : Initializes the CAN peripheral according to the specified
|
||||
* parameters in the CAN_FilterInitStruct.
|
||||
* Input : CAN_FilterInitStruct: pointer to a CAN_FilterInitTypeDef
|
||||
* structure that contains the configuration information.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void CAN_FilterInit(CAN_FilterInitTypeDef* CAN_FilterInitStruct)
|
||||
{
|
||||
u16 FilterNumber_BitPos = 0;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_CAN_FILTER_NUMBER(CAN_FilterInitStruct->CAN_FilterNumber));
|
||||
assert_param(IS_CAN_FILTER_MODE(CAN_FilterInitStruct->CAN_FilterMode));
|
||||
assert_param(IS_CAN_FILTER_SCALE(CAN_FilterInitStruct->CAN_FilterScale));
|
||||
assert_param(IS_CAN_FILTER_FIFO(CAN_FilterInitStruct->CAN_FilterFIFOAssignment));
|
||||
assert_param(IS_FUNCTIONAL_STATE(CAN_FilterInitStruct->CAN_FilterActivation));
|
||||
|
||||
FilterNumber_BitPos =
|
||||
(u16)((u16)0x0001 << ((u16)CAN_FilterInitStruct->CAN_FilterNumber));
|
||||
|
||||
/* Initialisation mode for the filter */
|
||||
CAN->FMR |= CAN_FMR_FINIT;
|
||||
|
||||
/* Filter Deactivation */
|
||||
CAN->FA1R &= ~(u32)FilterNumber_BitPos;
|
||||
|
||||
/* Filter Scale */
|
||||
if (CAN_FilterInitStruct->CAN_FilterScale == CAN_FilterScale_16bit)
|
||||
{
|
||||
/* 16-bit scale for the filter */
|
||||
CAN->FS1R &= ~(u32)FilterNumber_BitPos;
|
||||
|
||||
/* First 16-bit identifier and First 16-bit mask */
|
||||
/* Or First 16-bit identifier and Second 16-bit identifier */
|
||||
CAN->sFilterRegister[CAN_FilterInitStruct->CAN_FilterNumber].FR1 =
|
||||
((u32)((u32)0x0000FFFF & CAN_FilterInitStruct->CAN_FilterMaskIdLow) << 16) |
|
||||
((u32)0x0000FFFF & CAN_FilterInitStruct->CAN_FilterIdLow);
|
||||
|
||||
/* Second 16-bit identifier and Second 16-bit mask */
|
||||
/* Or Third 16-bit identifier and Fourth 16-bit identifier */
|
||||
CAN->sFilterRegister[CAN_FilterInitStruct->CAN_FilterNumber].FR2 =
|
||||
((u32)((u32)0x0000FFFF & CAN_FilterInitStruct->CAN_FilterMaskIdHigh) << 16) |
|
||||
((u32)0x0000FFFF & CAN_FilterInitStruct->CAN_FilterIdHigh);
|
||||
}
|
||||
if (CAN_FilterInitStruct->CAN_FilterScale == CAN_FilterScale_32bit)
|
||||
{
|
||||
/* 32-bit scale for the filter */
|
||||
CAN->FS1R |= FilterNumber_BitPos;
|
||||
|
||||
/* 32-bit identifier or First 32-bit identifier */
|
||||
CAN->sFilterRegister[CAN_FilterInitStruct->CAN_FilterNumber].FR1 =
|
||||
((u32)((u32)0x0000FFFF & CAN_FilterInitStruct->CAN_FilterIdHigh) << 16) |
|
||||
((u32)0x0000FFFF & CAN_FilterInitStruct->CAN_FilterIdLow);
|
||||
|
||||
/* 32-bit mask or Second 32-bit identifier */
|
||||
CAN->sFilterRegister[CAN_FilterInitStruct->CAN_FilterNumber].FR2 =
|
||||
((u32)((u32)0x0000FFFF & CAN_FilterInitStruct->CAN_FilterMaskIdHigh) << 16) |
|
||||
((u32)0x0000FFFF & CAN_FilterInitStruct->CAN_FilterMaskIdLow);
|
||||
|
||||
}
|
||||
|
||||
/* Filter Mode */
|
||||
if (CAN_FilterInitStruct->CAN_FilterMode == CAN_FilterMode_IdMask)
|
||||
{
|
||||
/*Id/Mask mode for the filter*/
|
||||
CAN->FM1R &= ~(u32)FilterNumber_BitPos;
|
||||
}
|
||||
else /* CAN_FilterInitStruct->CAN_FilterMode == CAN_FilterMode_IdList */
|
||||
{
|
||||
/*Identifier list mode for the filter*/
|
||||
CAN->FM1R |= (u32)FilterNumber_BitPos;
|
||||
}
|
||||
|
||||
/* Filter FIFO assignment */
|
||||
if (CAN_FilterInitStruct->CAN_FilterFIFOAssignment == CAN_FilterFIFO0)
|
||||
{
|
||||
/* FIFO 0 assignation for the filter */
|
||||
CAN->FFA1R &= ~(u32)FilterNumber_BitPos;
|
||||
}
|
||||
if (CAN_FilterInitStruct->CAN_FilterFIFOAssignment == CAN_FilterFIFO1)
|
||||
{
|
||||
/* FIFO 1 assignation for the filter */
|
||||
CAN->FFA1R |= (u32)FilterNumber_BitPos;
|
||||
}
|
||||
|
||||
/* Filter activation */
|
||||
if (CAN_FilterInitStruct->CAN_FilterActivation == ENABLE)
|
||||
{
|
||||
CAN->FA1R |= FilterNumber_BitPos;
|
||||
}
|
||||
|
||||
/* Leave the initialisation mode for the filter */
|
||||
CAN->FMR &= ~CAN_FMR_FINIT;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : CAN_StructInit
|
||||
* Description : Fills each CAN_InitStruct member with its default value.
|
||||
* Input : CAN_InitStruct: pointer to a CAN_InitTypeDef structure which
|
||||
* will be initialized.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void CAN_StructInit(CAN_InitTypeDef* CAN_InitStruct)
|
||||
{
|
||||
/* Reset CAN init structure parameters values */
|
||||
|
||||
/* Initialize the time triggered communication mode */
|
||||
CAN_InitStruct->CAN_TTCM = DISABLE;
|
||||
|
||||
/* Initialize the automatic bus-off management */
|
||||
CAN_InitStruct->CAN_ABOM = DISABLE;
|
||||
|
||||
/* Initialize the automatic wake-up mode */
|
||||
CAN_InitStruct->CAN_AWUM = DISABLE;
|
||||
|
||||
/* Initialize the no automatic retransmission */
|
||||
CAN_InitStruct->CAN_NART = DISABLE;
|
||||
|
||||
/* Initialize the receive FIFO locked mode */
|
||||
CAN_InitStruct->CAN_RFLM = DISABLE;
|
||||
|
||||
/* Initialize the transmit FIFO priority */
|
||||
CAN_InitStruct->CAN_TXFP = DISABLE;
|
||||
|
||||
/* Initialize the CAN_Mode member */
|
||||
CAN_InitStruct->CAN_Mode = CAN_Mode_Normal;
|
||||
|
||||
/* Initialize the CAN_SJW member */
|
||||
CAN_InitStruct->CAN_SJW = CAN_SJW_1tq;
|
||||
|
||||
/* Initialize the CAN_BS1 member */
|
||||
CAN_InitStruct->CAN_BS1 = CAN_BS1_4tq;
|
||||
|
||||
/* Initialize the CAN_BS2 member */
|
||||
CAN_InitStruct->CAN_BS2 = CAN_BS2_3tq;
|
||||
|
||||
/* Initialize the CAN_Prescaler member */
|
||||
CAN_InitStruct->CAN_Prescaler = 1;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : CAN_ITConfig
|
||||
* Description : Enables or disables the specified CAN interrupts.
|
||||
* Input : - CAN_IT: specifies the CAN interrupt sources to be enabled or
|
||||
* disabled.
|
||||
* This parameter can be: CAN_IT_TME, CAN_IT_FMP0, CAN_IT_FF0,
|
||||
* CAN_IT_FOV0, CAN_IT_FMP1, CAN_IT_FF1,
|
||||
* CAN_IT_FOV1, CAN_IT_EWG, CAN_IT_EPV,
|
||||
* CAN_IT_LEC, CAN_IT_ERR, CAN_IT_WKU or
|
||||
* CAN_IT_SLK.
|
||||
* - NewState: new state of the CAN interrupts.
|
||||
* This parameter can be: ENABLE or DISABLE.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void CAN_ITConfig(u32 CAN_IT, FunctionalState NewState)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_CAN_ITConfig(CAN_IT));
|
||||
assert_param(IS_FUNCTIONAL_STATE(NewState));
|
||||
|
||||
if (NewState != DISABLE)
|
||||
{
|
||||
/* Enable the selected CAN interrupt */
|
||||
CAN->IER |= CAN_IT;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Disable the selected CAN interrupt */
|
||||
CAN->IER &= ~CAN_IT;
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : CAN_Transmit
|
||||
* Description : Initiates the transmission of a message.
|
||||
* Input : TxMessage: pointer to a structure which contains CAN Id, CAN
|
||||
* DLC and CAN datas.
|
||||
* Output : None.
|
||||
* Return : The number of the mailbox that is used for transmission
|
||||
* or CAN_NO_MB if there is no empty mailbox.
|
||||
*******************************************************************************/
|
||||
u8 CAN_Transmit(CanTxMsg* TxMessage)
|
||||
{
|
||||
u8 TransmitMailbox = 0;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_CAN_STDID(TxMessage->StdId));
|
||||
assert_param(IS_CAN_EXTID(TxMessage->StdId));
|
||||
assert_param(IS_CAN_IDTYPE(TxMessage->IDE));
|
||||
assert_param(IS_CAN_RTR(TxMessage->RTR));
|
||||
assert_param(IS_CAN_DLC(TxMessage->DLC));
|
||||
|
||||
/* Select one empty transmit mailbox */
|
||||
if ((CAN->TSR&CAN_TSR_TME0) == CAN_TSR_TME0)
|
||||
{
|
||||
TransmitMailbox = 0;
|
||||
}
|
||||
else if ((CAN->TSR&CAN_TSR_TME1) == CAN_TSR_TME1)
|
||||
{
|
||||
TransmitMailbox = 1;
|
||||
}
|
||||
else if ((CAN->TSR&CAN_TSR_TME2) == CAN_TSR_TME2)
|
||||
{
|
||||
TransmitMailbox = 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
TransmitMailbox = CAN_NO_MB;
|
||||
}
|
||||
|
||||
if (TransmitMailbox != CAN_NO_MB)
|
||||
{
|
||||
/* Set up the Id */
|
||||
CAN->sTxMailBox[TransmitMailbox].TIR &= CAN_TMIDxR_TXRQ;
|
||||
if (TxMessage->IDE == CAN_ID_STD)
|
||||
{
|
||||
TxMessage->StdId &= (u32)0x000007FF;
|
||||
TxMessage->StdId = TxMessage->StdId << 21;
|
||||
|
||||
CAN->sTxMailBox[TransmitMailbox].TIR |= (TxMessage->StdId | TxMessage->IDE |
|
||||
TxMessage->RTR);
|
||||
}
|
||||
else
|
||||
{
|
||||
TxMessage->ExtId &= (u32)0x1FFFFFFF;
|
||||
TxMessage->ExtId <<= 3;
|
||||
|
||||
CAN->sTxMailBox[TransmitMailbox].TIR |= (TxMessage->ExtId | TxMessage->IDE |
|
||||
TxMessage->RTR);
|
||||
}
|
||||
|
||||
/* Set up the DLC */
|
||||
TxMessage->DLC &= (u8)0x0000000F;
|
||||
CAN->sTxMailBox[TransmitMailbox].TDTR &= (u32)0xFFFFFFF0;
|
||||
CAN->sTxMailBox[TransmitMailbox].TDTR |= TxMessage->DLC;
|
||||
|
||||
/* Set up the data field */
|
||||
CAN->sTxMailBox[TransmitMailbox].TDLR = (((u32)TxMessage->Data[3] << 24) |
|
||||
((u32)TxMessage->Data[2] << 16) |
|
||||
((u32)TxMessage->Data[1] << 8) |
|
||||
((u32)TxMessage->Data[0]));
|
||||
CAN->sTxMailBox[TransmitMailbox].TDHR = (((u32)TxMessage->Data[7] << 24) |
|
||||
((u32)TxMessage->Data[6] << 16) |
|
||||
((u32)TxMessage->Data[5] << 8) |
|
||||
((u32)TxMessage->Data[4]));
|
||||
|
||||
/* Request transmission */
|
||||
CAN->sTxMailBox[TransmitMailbox].TIR |= CAN_TMIDxR_TXRQ;
|
||||
}
|
||||
|
||||
return TransmitMailbox;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : CAN_TransmitStatus
|
||||
* Description : Checks the transmission of a message.
|
||||
* Input : TransmitMailbox: the number of the mailbox that is used for
|
||||
* transmission.
|
||||
* Output : None.
|
||||
* Return : CANTXOK if the CAN driver transmits the message, CANTXFAILED
|
||||
* in an other case.
|
||||
*******************************************************************************/
|
||||
u8 CAN_TransmitStatus(u8 TransmitMailbox)
|
||||
{
|
||||
/* RQCP, TXOK and TME bits */
|
||||
u8 State = 0;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_CAN_TRANSMITMAILBOX(TransmitMailbox));
|
||||
|
||||
switch (TransmitMailbox)
|
||||
{
|
||||
case (0): State |= (u8)((CAN->TSR & CAN_TSR_RQCP0) << 2);
|
||||
State |= (u8)((CAN->TSR & CAN_TSR_TXOK0) >> 0);
|
||||
State |= (u8)((CAN->TSR & CAN_TSR_TME0) >> 26);
|
||||
break;
|
||||
case (1): State |= (u8)((CAN->TSR & CAN_TSR_RQCP1) >> 6);
|
||||
State |= (u8)((CAN->TSR & CAN_TSR_TXOK1) >> 8);
|
||||
State |= (u8)((CAN->TSR & CAN_TSR_TME1) >> 27);
|
||||
break;
|
||||
case (2): State |= (u8)((CAN->TSR & CAN_TSR_RQCP2) >> 14);
|
||||
State |= (u8)((CAN->TSR & CAN_TSR_TXOK2) >> 16);
|
||||
State |= (u8)((CAN->TSR & CAN_TSR_TME2) >> 28);
|
||||
break;
|
||||
default:
|
||||
State = CANTXFAILED;
|
||||
break;
|
||||
}
|
||||
|
||||
switch (State)
|
||||
{
|
||||
/* transmit pending */
|
||||
case (0x0): State = CANTXPENDING;
|
||||
break;
|
||||
/* transmit failed */
|
||||
case (0x5): State = CANTXFAILED;
|
||||
break;
|
||||
/* transmit succedeed */
|
||||
case (0x7): State = CANTXOK;
|
||||
break;
|
||||
default:
|
||||
State = CANTXFAILED;
|
||||
break;
|
||||
}
|
||||
|
||||
return State;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : CAN_CancelTransmit
|
||||
* Description : Cancels a transmit request.
|
||||
* Input : Mailbox number.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void CAN_CancelTransmit(u8 Mailbox)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_CAN_TRANSMITMAILBOX(Mailbox));
|
||||
|
||||
/* abort transmission */
|
||||
switch (Mailbox)
|
||||
{
|
||||
case (0): CAN->TSR |= CAN_TSR_ABRQ0;
|
||||
break;
|
||||
case (1): CAN->TSR |= CAN_TSR_ABRQ1;
|
||||
break;
|
||||
case (2): CAN->TSR |= CAN_TSR_ABRQ2;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : CAN_FIFORelease
|
||||
* Description : Releases a FIFO.
|
||||
* Input : FIFONumber: FIFO to release, CAN_FIFO0 or CAN_FIFO1.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void CAN_FIFORelease(u8 FIFONumber)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_CAN_FIFO(FIFONumber));
|
||||
|
||||
/* Release FIFO0 */
|
||||
if (FIFONumber == CAN_FIFO0)
|
||||
{
|
||||
CAN->RF0R = CAN_RF0R_RFOM0;
|
||||
}
|
||||
/* Release FIFO1 */
|
||||
else /* FIFONumber == CAN_FIFO1 */
|
||||
{
|
||||
CAN->RF1R = CAN_RF1R_RFOM1;
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : CAN_MessagePending
|
||||
* Description : Returns the number of pending messages.
|
||||
* Input : FIFONumber: Receive FIFO number, CAN_FIFO0 or CAN_FIFO1.
|
||||
* Output : None.
|
||||
* Return : NbMessage which is the number of pending message.
|
||||
*******************************************************************************/
|
||||
u8 CAN_MessagePending(u8 FIFONumber)
|
||||
{
|
||||
u8 MessagePending=0;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_CAN_FIFO(FIFONumber));
|
||||
|
||||
if (FIFONumber == CAN_FIFO0)
|
||||
{
|
||||
MessagePending = (u8)(CAN->RF0R&(u32)0x03);
|
||||
}
|
||||
else if (FIFONumber == CAN_FIFO1)
|
||||
{
|
||||
MessagePending = (u8)(CAN->RF1R&(u32)0x03);
|
||||
}
|
||||
else
|
||||
{
|
||||
MessagePending = 0;
|
||||
}
|
||||
return MessagePending;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : CAN_Receive
|
||||
* Description : Receives a message.
|
||||
* Input : FIFONumber: Receive FIFO number, CAN_FIFO0 or CAN_FIFO1.
|
||||
* Output : RxMessage: pointer to a structure which contains CAN Id,
|
||||
* CAN DLC, CAN datas and FMI number.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void CAN_Receive(u8 FIFONumber, CanRxMsg* RxMessage)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_CAN_FIFO(FIFONumber));
|
||||
|
||||
/* Get the Id */
|
||||
RxMessage->IDE = (u8)0x04 & CAN->sFIFOMailBox[FIFONumber].RIR;
|
||||
if (RxMessage->IDE == CAN_ID_STD)
|
||||
{
|
||||
RxMessage->StdId = (u32)0x000007FF & (CAN->sFIFOMailBox[FIFONumber].RIR >> 21);
|
||||
}
|
||||
else
|
||||
{
|
||||
RxMessage->ExtId = (u32)0x1FFFFFFF & (CAN->sFIFOMailBox[FIFONumber].RIR >> 3);
|
||||
}
|
||||
|
||||
RxMessage->RTR = (u8)0x02 & CAN->sFIFOMailBox[FIFONumber].RIR;
|
||||
|
||||
/* Get the DLC */
|
||||
RxMessage->DLC = (u8)0x0F & CAN->sFIFOMailBox[FIFONumber].RDTR;
|
||||
|
||||
/* Get the FMI */
|
||||
RxMessage->FMI = (u8)0xFF & (CAN->sFIFOMailBox[FIFONumber].RDTR >> 8);
|
||||
|
||||
/* Get the data field */
|
||||
RxMessage->Data[0] = (u8)0xFF & CAN->sFIFOMailBox[FIFONumber].RDLR;
|
||||
RxMessage->Data[1] = (u8)0xFF & (CAN->sFIFOMailBox[FIFONumber].RDLR >> 8);
|
||||
RxMessage->Data[2] = (u8)0xFF & (CAN->sFIFOMailBox[FIFONumber].RDLR >> 16);
|
||||
RxMessage->Data[3] = (u8)0xFF & (CAN->sFIFOMailBox[FIFONumber].RDLR >> 24);
|
||||
|
||||
RxMessage->Data[4] = (u8)0xFF & CAN->sFIFOMailBox[FIFONumber].RDHR;
|
||||
RxMessage->Data[5] = (u8)0xFF & (CAN->sFIFOMailBox[FIFONumber].RDHR >> 8);
|
||||
RxMessage->Data[6] = (u8)0xFF & (CAN->sFIFOMailBox[FIFONumber].RDHR >> 16);
|
||||
RxMessage->Data[7] = (u8)0xFF & (CAN->sFIFOMailBox[FIFONumber].RDHR >> 24);
|
||||
|
||||
/* Release the FIFO */
|
||||
CAN_FIFORelease(FIFONumber);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : CAN_Sleep
|
||||
* Description : Enters the low power mode.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : CANSLEEPOK if sleep entered, CANSLEEPFAILED in an other case.
|
||||
*******************************************************************************/
|
||||
u8 CAN_Sleep(void)
|
||||
{
|
||||
u8 SleepStatus = 0;
|
||||
|
||||
/* Sleep mode entering request */
|
||||
CAN->MCR |= CAN_MCR_SLEEP;
|
||||
SleepStatus = CANSLEEPOK;
|
||||
|
||||
/* Sleep mode status */
|
||||
if ((CAN->MCR&CAN_MCR_SLEEP) == 0)
|
||||
{
|
||||
/* Sleep mode not entered */
|
||||
SleepStatus = CANSLEEPFAILED;
|
||||
}
|
||||
|
||||
/* At this step, sleep mode status */
|
||||
return SleepStatus;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : CAN_WakeUp
|
||||
* Description : Wakes the CAN up.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : CANWAKEUPOK if sleep mode left, CANWAKEUPFAILED in an other
|
||||
* case.
|
||||
*******************************************************************************/
|
||||
u8 CAN_WakeUp(void)
|
||||
{
|
||||
u8 WakeUpStatus = 0;
|
||||
|
||||
/* Wake up request */
|
||||
CAN->MCR &= ~CAN_MCR_SLEEP;
|
||||
WakeUpStatus = CANWAKEUPFAILED;
|
||||
|
||||
/* Sleep mode status */
|
||||
if ((CAN->MCR&CAN_MCR_SLEEP) == 0)
|
||||
{
|
||||
/* Sleep mode exited */
|
||||
WakeUpStatus = CANWAKEUPOK;
|
||||
}
|
||||
|
||||
/* At this step, sleep mode status */
|
||||
return WakeUpStatus;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : CAN_GetFlagStatus
|
||||
* Description : Checks whether the specified CAN flag is set or not.
|
||||
* Input : CAN_FLAG: specifies the flag to check.
|
||||
* This parameter can be: CAN_FLAG_EWG, CAN_FLAG_EPV or
|
||||
* CAN_FLAG_BOF.
|
||||
* Output : None.
|
||||
* Return : The new state of CAN_FLAG (SET or RESET).
|
||||
*******************************************************************************/
|
||||
FlagStatus CAN_GetFlagStatus(u32 CAN_FLAG)
|
||||
{
|
||||
FlagStatus bitstatus = RESET;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_CAN_FLAG(CAN_FLAG));
|
||||
|
||||
/* Check the status of the specified CAN flag */
|
||||
if ((CAN->ESR & CAN_FLAG) != (u32)RESET)
|
||||
{
|
||||
/* CAN_FLAG is set */
|
||||
bitstatus = SET;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* CAN_FLAG is reset */
|
||||
bitstatus = RESET;
|
||||
}
|
||||
/* Return the CAN_FLAG status */
|
||||
return bitstatus;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : CAN_ClearFlag
|
||||
* Description : Clears the CAN's pending flags.
|
||||
* Input : CAN_FLAG: specifies the flag to clear.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void CAN_ClearFlag(u32 CAN_FLAG)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_CAN_FLAG(CAN_FLAG));
|
||||
|
||||
/* Clear the selected CAN flags */
|
||||
CAN->ESR &= ~CAN_FLAG;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : CAN_GetITStatus
|
||||
* Description : Checks whether the specified CAN interrupt has occurred or
|
||||
* not.
|
||||
* Input : CAN_IT: specifies the CAN interrupt source to check.
|
||||
* This parameter can be: CAN_IT_RQCP0, CAN_IT_RQCP1, CAN_IT_RQCP2,
|
||||
* CAN_IT_FF0, CAN_IT_FOV0, CAN_IT_FF1,
|
||||
* CAN_IT_FOV1, CAN_IT_EWG, CAN_IT_EPV,
|
||||
* CAN_IT_BOF, CAN_IT_WKU or CAN_IT_SLK.
|
||||
* Output : None.
|
||||
* Return : The new state of CAN_IT (SET or RESET).
|
||||
*******************************************************************************/
|
||||
ITStatus CAN_GetITStatus(u32 CAN_IT)
|
||||
{
|
||||
ITStatus pendingbitstatus = RESET;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_CAN_ITStatus(CAN_IT));
|
||||
|
||||
switch (CAN_IT)
|
||||
{
|
||||
case CAN_IT_RQCP0:
|
||||
pendingbitstatus = CheckITStatus(CAN->TSR, CAN_TSR_RQCP0);
|
||||
break;
|
||||
case CAN_IT_RQCP1:
|
||||
pendingbitstatus = CheckITStatus(CAN->TSR, CAN_TSR_RQCP1);
|
||||
break;
|
||||
case CAN_IT_RQCP2:
|
||||
pendingbitstatus = CheckITStatus(CAN->TSR, CAN_TSR_RQCP2);
|
||||
break;
|
||||
case CAN_IT_FF0:
|
||||
pendingbitstatus = CheckITStatus(CAN->RF0R, CAN_RF0R_FULL0);
|
||||
break;
|
||||
case CAN_IT_FOV0:
|
||||
pendingbitstatus = CheckITStatus(CAN->RF0R, CAN_RF0R_FOVR0);
|
||||
break;
|
||||
case CAN_IT_FF1:
|
||||
pendingbitstatus = CheckITStatus(CAN->RF1R, CAN_RF1R_FULL1);
|
||||
break;
|
||||
case CAN_IT_FOV1:
|
||||
pendingbitstatus = CheckITStatus(CAN->RF1R, CAN_RF1R_FOVR1);
|
||||
break;
|
||||
case CAN_IT_EWG:
|
||||
pendingbitstatus = CheckITStatus(CAN->ESR, CAN_ESR_EWGF);
|
||||
break;
|
||||
case CAN_IT_EPV:
|
||||
pendingbitstatus = CheckITStatus(CAN->ESR, CAN_ESR_EPVF);
|
||||
break;
|
||||
case CAN_IT_BOF:
|
||||
pendingbitstatus = CheckITStatus(CAN->ESR, CAN_ESR_BOFF);
|
||||
break;
|
||||
case CAN_IT_SLK:
|
||||
pendingbitstatus = CheckITStatus(CAN->MSR, CAN_MSR_SLAKI);
|
||||
break;
|
||||
case CAN_IT_WKU:
|
||||
pendingbitstatus = CheckITStatus(CAN->MSR, CAN_MSR_WKUI);
|
||||
break;
|
||||
|
||||
default :
|
||||
pendingbitstatus = RESET;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Return the CAN_IT status */
|
||||
return pendingbitstatus;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : CAN_ClearITPendingBit
|
||||
* Description : Clears the CAN’s interrupt pending bits.
|
||||
* Input : CAN_IT: specifies the interrupt pending bit to clear.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void CAN_ClearITPendingBit(u32 CAN_IT)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_CAN_ITStatus(CAN_IT));
|
||||
|
||||
switch (CAN_IT)
|
||||
{
|
||||
case CAN_IT_RQCP0:
|
||||
CAN->TSR = CAN_TSR_RQCP0; /* rc_w1*/
|
||||
break;
|
||||
case CAN_IT_RQCP1:
|
||||
CAN->TSR = CAN_TSR_RQCP1; /* rc_w1*/
|
||||
break;
|
||||
case CAN_IT_RQCP2:
|
||||
CAN->TSR = CAN_TSR_RQCP2; /* rc_w1*/
|
||||
break;
|
||||
case CAN_IT_FF0:
|
||||
CAN->RF0R = CAN_RF0R_FULL0; /* rc_w1*/
|
||||
break;
|
||||
case CAN_IT_FOV0:
|
||||
CAN->RF0R = CAN_RF0R_FOVR0; /* rc_w1*/
|
||||
break;
|
||||
case CAN_IT_FF1:
|
||||
CAN->RF1R = CAN_RF1R_FULL1; /* rc_w1*/
|
||||
break;
|
||||
case CAN_IT_FOV1:
|
||||
CAN->RF1R = CAN_RF1R_FOVR1; /* rc_w1*/
|
||||
break;
|
||||
case CAN_IT_EWG:
|
||||
CAN->ESR &= ~ CAN_ESR_EWGF; /* rw */
|
||||
break;
|
||||
case CAN_IT_EPV:
|
||||
CAN->ESR &= ~ CAN_ESR_EPVF; /* rw */
|
||||
break;
|
||||
case CAN_IT_BOF:
|
||||
CAN->ESR &= ~ CAN_ESR_BOFF; /* rw */
|
||||
break;
|
||||
case CAN_IT_WKU:
|
||||
CAN->MSR = CAN_MSR_WKUI; /* rc_w1*/
|
||||
break;
|
||||
case CAN_IT_SLK:
|
||||
CAN->MSR = CAN_MSR_SLAKI; /* rc_w1*/
|
||||
break;
|
||||
default :
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : CheckITStatus
|
||||
* Description : Checks whether the CAN interrupt has occurred or not.
|
||||
* Input : CAN_Reg: specifies the CAN interrupt register to check.
|
||||
* It_Bit: specifies the interrupt source bit to check.
|
||||
* Output : None.
|
||||
* Return : The new state of the CAN Interrupt (SET or RESET).
|
||||
*******************************************************************************/
|
||||
static ITStatus CheckITStatus(u32 CAN_Reg, u32 It_Bit)
|
||||
{
|
||||
ITStatus pendingbitstatus = RESET;
|
||||
|
||||
if ((CAN_Reg & It_Bit) != (u32)RESET)
|
||||
{
|
||||
/* CAN_IT is set */
|
||||
pendingbitstatus = SET;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* CAN_IT is reset */
|
||||
pendingbitstatus = RESET;
|
||||
}
|
||||
|
||||
return pendingbitstatus;
|
||||
}
|
||||
|
||||
/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
|
580
Demo/CORTEX_STM32F103_GCC_Rowley/ST Library/src/stm32f10x_gpio.c
Normal file
580
Demo/CORTEX_STM32F103_GCC_Rowley/ST Library/src/stm32f10x_gpio.c
Normal file
|
@ -0,0 +1,580 @@
|
|||
/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
|
||||
* File Name : stm32f10x_gpio.c
|
||||
* Author : MCD Application Team
|
||||
* Version : V2.0.1
|
||||
* Date : 06/13/2008
|
||||
* Description : This file provides all the GPIO firmware functions.
|
||||
********************************************************************************
|
||||
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
|
||||
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
|
||||
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
|
||||
* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
|
||||
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
|
||||
*******************************************************************************/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32f10x_gpio.h"
|
||||
#include "stm32f10x_rcc.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* ------------ RCC registers bit address in the alias region ----------- */
|
||||
#define AFIO_OFFSET (AFIO_BASE - PERIPH_BASE)
|
||||
|
||||
/* --- EVENTCR Register ---*/
|
||||
/* Alias word address of EVOE bit */
|
||||
#define EVCR_OFFSET (AFIO_OFFSET + 0x00)
|
||||
#define EVOE_BitNumber ((u8)0x07)
|
||||
#define EVCR_EVOE_BB (PERIPH_BB_BASE + (EVCR_OFFSET * 32) + (EVOE_BitNumber * 4))
|
||||
|
||||
#define EVCR_PORTPINCONFIG_MASK ((u16)0xFF80)
|
||||
#define LSB_MASK ((u16)0xFFFF)
|
||||
#define DBGAFR_POSITION_MASK ((u32)0x000F0000)
|
||||
#define DBGAFR_SWJCFG_MASK ((u32)0xF0FFFFFF)
|
||||
#define DBGAFR_LOCATION_MASK ((u32)0x00200000)
|
||||
#define DBGAFR_NUMBITS_MASK ((u32)0x00100000)
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : GPIO_DeInit
|
||||
* Description : Deinitializes the GPIOx peripheral registers to their default
|
||||
* reset values.
|
||||
* Input : - GPIOx: where x can be (A..G) to select the GPIO peripheral.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void GPIO_DeInit(GPIO_TypeDef* GPIOx)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
|
||||
|
||||
switch (*(u32*)&GPIOx)
|
||||
{
|
||||
case GPIOA_BASE:
|
||||
RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOA, ENABLE);
|
||||
RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOA, DISABLE);
|
||||
break;
|
||||
|
||||
case GPIOB_BASE:
|
||||
RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOB, ENABLE);
|
||||
RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOB, DISABLE);
|
||||
break;
|
||||
|
||||
case GPIOC_BASE:
|
||||
RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOC, ENABLE);
|
||||
RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOC, DISABLE);
|
||||
break;
|
||||
|
||||
case GPIOD_BASE:
|
||||
RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOD, ENABLE);
|
||||
RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOD, DISABLE);
|
||||
break;
|
||||
|
||||
case GPIOE_BASE:
|
||||
RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOE, ENABLE);
|
||||
RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOE, DISABLE);
|
||||
break;
|
||||
|
||||
case GPIOF_BASE:
|
||||
RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOF, ENABLE);
|
||||
RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOF, DISABLE);
|
||||
break;
|
||||
|
||||
case GPIOG_BASE:
|
||||
RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOG, ENABLE);
|
||||
RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOG, DISABLE);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : GPIO_AFIODeInit
|
||||
* Description : Deinitializes the Alternate Functions (remap, event control
|
||||
* and EXTI configuration) registers to their default reset
|
||||
* values.
|
||||
* Input : None
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void GPIO_AFIODeInit(void)
|
||||
{
|
||||
RCC_APB2PeriphResetCmd(RCC_APB2Periph_AFIO, ENABLE);
|
||||
RCC_APB2PeriphResetCmd(RCC_APB2Periph_AFIO, DISABLE);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : GPIO_Init
|
||||
* Description : Initializes the GPIOx peripheral according to the specified
|
||||
* parameters in the GPIO_InitStruct.
|
||||
* Input : - GPIOx: where x can be (A..G) to select the GPIO peripheral.
|
||||
* - GPIO_InitStruct: pointer to a GPIO_InitTypeDef structure that
|
||||
* contains the configuration information for the specified GPIO
|
||||
* peripheral.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct)
|
||||
{
|
||||
u32 currentmode = 0x00, currentpin = 0x00, pinpos = 0x00, pos = 0x00;
|
||||
u32 tmpreg = 0x00, pinmask = 0x00;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
|
||||
assert_param(IS_GPIO_MODE(GPIO_InitStruct->GPIO_Mode));
|
||||
assert_param(IS_GPIO_PIN(GPIO_InitStruct->GPIO_Pin));
|
||||
|
||||
/*---------------------------- GPIO Mode Configuration -----------------------*/
|
||||
currentmode = ((u32)GPIO_InitStruct->GPIO_Mode) & ((u32)0x0F);
|
||||
|
||||
if ((((u32)GPIO_InitStruct->GPIO_Mode) & ((u32)0x10)) != 0x00)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_GPIO_SPEED(GPIO_InitStruct->GPIO_Speed));
|
||||
/* Output mode */
|
||||
currentmode |= (u32)GPIO_InitStruct->GPIO_Speed;
|
||||
}
|
||||
|
||||
/*---------------------------- GPIO CRL Configuration ------------------------*/
|
||||
/* Configure the eight low port pins */
|
||||
if (((u32)GPIO_InitStruct->GPIO_Pin & ((u32)0x00FF)) != 0x00)
|
||||
{
|
||||
tmpreg = GPIOx->CRL;
|
||||
|
||||
for (pinpos = 0x00; pinpos < 0x08; pinpos++)
|
||||
{
|
||||
pos = ((u32)0x01) << pinpos;
|
||||
/* Get the port pins position */
|
||||
currentpin = (GPIO_InitStruct->GPIO_Pin) & pos;
|
||||
|
||||
if (currentpin == pos)
|
||||
{
|
||||
pos = pinpos << 2;
|
||||
/* Clear the corresponding low control register bits */
|
||||
pinmask = ((u32)0x0F) << pos;
|
||||
tmpreg &= ~pinmask;
|
||||
|
||||
/* Write the mode configuration in the corresponding bits */
|
||||
tmpreg |= (currentmode << pos);
|
||||
|
||||
/* Reset the corresponding ODR bit */
|
||||
if (GPIO_InitStruct->GPIO_Mode == GPIO_Mode_IPD)
|
||||
{
|
||||
GPIOx->BRR = (((u32)0x01) << pinpos);
|
||||
}
|
||||
/* Set the corresponding ODR bit */
|
||||
if (GPIO_InitStruct->GPIO_Mode == GPIO_Mode_IPU)
|
||||
{
|
||||
GPIOx->BSRR = (((u32)0x01) << pinpos);
|
||||
}
|
||||
}
|
||||
}
|
||||
GPIOx->CRL = tmpreg;
|
||||
}
|
||||
|
||||
/*---------------------------- GPIO CRH Configuration ------------------------*/
|
||||
/* Configure the eight high port pins */
|
||||
if (GPIO_InitStruct->GPIO_Pin > 0x00FF)
|
||||
{
|
||||
tmpreg = GPIOx->CRH;
|
||||
for (pinpos = 0x00; pinpos < 0x08; pinpos++)
|
||||
{
|
||||
pos = (((u32)0x01) << (pinpos + 0x08));
|
||||
/* Get the port pins position */
|
||||
currentpin = ((GPIO_InitStruct->GPIO_Pin) & pos);
|
||||
if (currentpin == pos)
|
||||
{
|
||||
pos = pinpos << 2;
|
||||
/* Clear the corresponding high control register bits */
|
||||
pinmask = ((u32)0x0F) << pos;
|
||||
tmpreg &= ~pinmask;
|
||||
|
||||
/* Write the mode configuration in the corresponding bits */
|
||||
tmpreg |= (currentmode << pos);
|
||||
|
||||
/* Reset the corresponding ODR bit */
|
||||
if (GPIO_InitStruct->GPIO_Mode == GPIO_Mode_IPD)
|
||||
{
|
||||
GPIOx->BRR = (((u32)0x01) << (pinpos + 0x08));
|
||||
}
|
||||
/* Set the corresponding ODR bit */
|
||||
if (GPIO_InitStruct->GPIO_Mode == GPIO_Mode_IPU)
|
||||
{
|
||||
GPIOx->BSRR = (((u32)0x01) << (pinpos + 0x08));
|
||||
}
|
||||
}
|
||||
}
|
||||
GPIOx->CRH = tmpreg;
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : GPIO_StructInit
|
||||
* Description : Fills each GPIO_InitStruct member with its default value.
|
||||
* Input : - GPIO_InitStruct : pointer to a GPIO_InitTypeDef structure
|
||||
* which will be initialized.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void GPIO_StructInit(GPIO_InitTypeDef* GPIO_InitStruct)
|
||||
{
|
||||
/* Reset GPIO init structure parameters values */
|
||||
GPIO_InitStruct->GPIO_Pin = GPIO_Pin_All;
|
||||
GPIO_InitStruct->GPIO_Speed = GPIO_Speed_2MHz;
|
||||
GPIO_InitStruct->GPIO_Mode = GPIO_Mode_IN_FLOATING;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : GPIO_ReadInputDataBit
|
||||
* Description : Reads the specified input port pin.
|
||||
* Input : - GPIOx: where x can be (A..G) to select the GPIO peripheral.
|
||||
* : - GPIO_Pin: specifies the port bit to read.
|
||||
* This parameter can be GPIO_Pin_x where x can be (0..15).
|
||||
* Output : None
|
||||
* Return : The input port pin value.
|
||||
*******************************************************************************/
|
||||
u8 GPIO_ReadInputDataBit(GPIO_TypeDef* GPIOx, u16 GPIO_Pin)
|
||||
{
|
||||
u8 bitstatus = 0x00;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
|
||||
assert_param(IS_GET_GPIO_PIN(GPIO_Pin));
|
||||
|
||||
if ((GPIOx->IDR & GPIO_Pin) != (u32)Bit_RESET)
|
||||
{
|
||||
bitstatus = (u8)Bit_SET;
|
||||
}
|
||||
else
|
||||
{
|
||||
bitstatus = (u8)Bit_RESET;
|
||||
}
|
||||
return bitstatus;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : GPIO_ReadInputData
|
||||
* Description : Reads the specified GPIO input data port.
|
||||
* Input : - GPIOx: where x can be (A..G) to select the GPIO peripheral.
|
||||
* Output : None
|
||||
* Return : GPIO input data port value.
|
||||
*******************************************************************************/
|
||||
u16 GPIO_ReadInputData(GPIO_TypeDef* GPIOx)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
|
||||
|
||||
return ((u16)GPIOx->IDR);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : GPIO_ReadOutputDataBit
|
||||
* Description : Reads the specified output data port bit.
|
||||
* Input : - GPIOx: where x can be (A..G) to select the GPIO peripheral.
|
||||
* : - GPIO_Pin: specifies the port bit to read.
|
||||
* This parameter can be GPIO_Pin_x where x can be (0..15).
|
||||
* Output : None
|
||||
* Return : The output port pin value.
|
||||
*******************************************************************************/
|
||||
u8 GPIO_ReadOutputDataBit(GPIO_TypeDef* GPIOx, u16 GPIO_Pin)
|
||||
{
|
||||
u8 bitstatus = 0x00;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
|
||||
assert_param(IS_GET_GPIO_PIN(GPIO_Pin));
|
||||
|
||||
if ((GPIOx->ODR & GPIO_Pin) != (u32)Bit_RESET)
|
||||
{
|
||||
bitstatus = (u8)Bit_SET;
|
||||
}
|
||||
else
|
||||
{
|
||||
bitstatus = (u8)Bit_RESET;
|
||||
}
|
||||
return bitstatus;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : GPIO_ReadOutputData
|
||||
* Description : Reads the specified GPIO output data port.
|
||||
* Input : - GPIOx: where x can be (A..G) to select the GPIO peripheral.
|
||||
* Output : None
|
||||
* Return : GPIO output data port value.
|
||||
*******************************************************************************/
|
||||
u16 GPIO_ReadOutputData(GPIO_TypeDef* GPIOx)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
|
||||
|
||||
return ((u16)GPIOx->ODR);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : GPIO_SetBits
|
||||
* Description : Sets the selected data port bits.
|
||||
* Input : - GPIOx: where x can be (A..G) to select the GPIO peripheral.
|
||||
* - GPIO_Pin: specifies the port bits to be written.
|
||||
* This parameter can be any combination of GPIO_Pin_x where
|
||||
* x can be (0..15).
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void GPIO_SetBits(GPIO_TypeDef* GPIOx, u16 GPIO_Pin)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
|
||||
assert_param(IS_GPIO_PIN(GPIO_Pin));
|
||||
|
||||
GPIOx->BSRR = GPIO_Pin;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : GPIO_ResetBits
|
||||
* Description : Clears the selected data port bits.
|
||||
* Input : - GPIOx: where x can be (A..G) to select the GPIO peripheral.
|
||||
* - GPIO_Pin: specifies the port bits to be written.
|
||||
* This parameter can be any combination of GPIO_Pin_x where
|
||||
* x can be (0..15).
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void GPIO_ResetBits(GPIO_TypeDef* GPIOx, u16 GPIO_Pin)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
|
||||
assert_param(IS_GPIO_PIN(GPIO_Pin));
|
||||
|
||||
GPIOx->BRR = GPIO_Pin;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : GPIO_WriteBit
|
||||
* Description : Sets or clears the selected data port bit.
|
||||
* Input : - GPIOx: where x can be (A..G) to select the GPIO peripheral.
|
||||
* - GPIO_Pin: specifies the port bit to be written.
|
||||
* This parameter can be one of GPIO_Pin_x where x can be (0..15).
|
||||
* - BitVal: specifies the value to be written to the selected bit.
|
||||
* This parameter can be one of the BitAction enum values:
|
||||
* - Bit_RESET: to clear the port pin
|
||||
* - Bit_SET: to set the port pin
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void GPIO_WriteBit(GPIO_TypeDef* GPIOx, u16 GPIO_Pin, BitAction BitVal)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
|
||||
assert_param(IS_GET_GPIO_PIN(GPIO_Pin));
|
||||
assert_param(IS_GPIO_BIT_ACTION(BitVal));
|
||||
|
||||
if (BitVal != Bit_RESET)
|
||||
{
|
||||
GPIOx->BSRR = GPIO_Pin;
|
||||
}
|
||||
else
|
||||
{
|
||||
GPIOx->BRR = GPIO_Pin;
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : GPIO_Write
|
||||
* Description : Writes data to the specified GPIO data port.
|
||||
* Input : - GPIOx: where x can be (A..G) to select the GPIO peripheral.
|
||||
* - PortVal: specifies the value to be written to the port output
|
||||
* data register.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void GPIO_Write(GPIO_TypeDef* GPIOx, u16 PortVal)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
|
||||
|
||||
GPIOx->ODR = PortVal;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : GPIO_PinLockConfig
|
||||
* Description : Locks GPIO Pins configuration registers.
|
||||
* Input : - GPIOx: where x can be (A..G) to select the GPIO peripheral.
|
||||
* - GPIO_Pin: specifies the port bit to be written.
|
||||
* This parameter can be any combination of GPIO_Pin_x where
|
||||
* x can be (0..15).
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void GPIO_PinLockConfig(GPIO_TypeDef* GPIOx, u16 GPIO_Pin)
|
||||
{
|
||||
u32 tmp = 0x00010000;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
|
||||
assert_param(IS_GPIO_PIN(GPIO_Pin));
|
||||
|
||||
tmp |= GPIO_Pin;
|
||||
/* Set LCKK bit */
|
||||
GPIOx->LCKR = tmp;
|
||||
/* Reset LCKK bit */
|
||||
GPIOx->LCKR = GPIO_Pin;
|
||||
/* Set LCKK bit */
|
||||
GPIOx->LCKR = tmp;
|
||||
/* Read LCKK bit*/
|
||||
tmp = GPIOx->LCKR;
|
||||
/* Read LCKK bit*/
|
||||
tmp = GPIOx->LCKR;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : GPIO_EventOutputConfig
|
||||
* Description : Selects the GPIO pin used as Event output.
|
||||
* Input : - GPIO_PortSource: selects the GPIO port to be used as source
|
||||
* for Event output.
|
||||
* This parameter can be GPIO_PortSourceGPIOx where x can be
|
||||
* (A..E).
|
||||
* - GPIO_PinSource: specifies the pin for the Event output.
|
||||
* This parameter can be GPIO_PinSourcex where x can be (0..15).
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void GPIO_EventOutputConfig(u8 GPIO_PortSource, u8 GPIO_PinSource)
|
||||
{
|
||||
u32 tmpreg = 0x00;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_GPIO_EVENTOUT_PORT_SOURCE(GPIO_PortSource));
|
||||
assert_param(IS_GPIO_PIN_SOURCE(GPIO_PinSource));
|
||||
|
||||
tmpreg = AFIO->EVCR;
|
||||
/* Clear the PORT[6:4] and PIN[3:0] bits */
|
||||
tmpreg &= EVCR_PORTPINCONFIG_MASK;
|
||||
tmpreg |= (u32)GPIO_PortSource << 0x04;
|
||||
tmpreg |= GPIO_PinSource;
|
||||
|
||||
AFIO->EVCR = tmpreg;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : GPIO_EventOutputCmd
|
||||
* Description : Enables or disables the Event Output.
|
||||
* Input : - NewState: new state of the Event output.
|
||||
* This parameter can be: ENABLE or DISABLE.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void GPIO_EventOutputCmd(FunctionalState NewState)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_FUNCTIONAL_STATE(NewState));
|
||||
|
||||
*(vu32 *) EVCR_EVOE_BB = (u32)NewState;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : GPIO_PinRemapConfig
|
||||
* Description : Changes the mapping of the specified pin.
|
||||
* Input : - GPIO_Remap: selects the pin to remap.
|
||||
* This parameter can be one of the following values:
|
||||
* - GPIO_Remap_SPI1
|
||||
* - GPIO_Remap_I2C1
|
||||
* - GPIO_Remap_USART1
|
||||
* - GPIO_Remap_USART2
|
||||
* - GPIO_PartialRemap_USART3
|
||||
* - GPIO_FullRemap_USART3
|
||||
* - GPIO_PartialRemap_TIM1
|
||||
* - GPIO_FullRemap_TIM1
|
||||
* - GPIO_PartialRemap1_TIM2
|
||||
* - GPIO_PartialRemap2_TIM2
|
||||
* - GPIO_FullRemap_TIM2
|
||||
* - GPIO_PartialRemap_TIM3
|
||||
* - GPIO_FullRemap_TIM3
|
||||
* - GPIO_Remap_TIM4
|
||||
* - GPIO_Remap1_CAN
|
||||
* - GPIO_Remap2_CAN
|
||||
* - GPIO_Remap_PD01
|
||||
* - GPIO_Remap_TIM5CH4_LSI
|
||||
* - GPIO_Remap_ADC1_ETRGINJ
|
||||
* - GPIO_Remap_ADC1_ETRGREG
|
||||
* - GPIO_Remap_ADC2_ETRGINJ
|
||||
* - GPIO_Remap_ADC2_ETRGREG
|
||||
* - GPIO_Remap_SWJ_NoJTRST
|
||||
* - GPIO_Remap_SWJ_JTAGDisable
|
||||
* - GPIO_Remap_SWJ_Disable
|
||||
* - NewState: new state of the port pin remapping.
|
||||
* This parameter can be: ENABLE or DISABLE.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void GPIO_PinRemapConfig(u32 GPIO_Remap, FunctionalState NewState)
|
||||
{
|
||||
u32 tmp = 0x00, tmp1 = 0x00, tmpreg = 0x00, tmpmask = 0x00;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_GPIO_REMAP(GPIO_Remap));
|
||||
assert_param(IS_FUNCTIONAL_STATE(NewState));
|
||||
|
||||
tmpreg = AFIO->MAPR;
|
||||
|
||||
tmpmask = (GPIO_Remap & DBGAFR_POSITION_MASK) >> 0x10;
|
||||
tmp = GPIO_Remap & LSB_MASK;
|
||||
|
||||
if ((GPIO_Remap & (DBGAFR_LOCATION_MASK | DBGAFR_NUMBITS_MASK)) == (DBGAFR_LOCATION_MASK | DBGAFR_NUMBITS_MASK))
|
||||
{
|
||||
tmpreg &= DBGAFR_SWJCFG_MASK;
|
||||
AFIO->MAPR &= DBGAFR_SWJCFG_MASK;
|
||||
}
|
||||
else if ((GPIO_Remap & DBGAFR_NUMBITS_MASK) == DBGAFR_NUMBITS_MASK)
|
||||
{
|
||||
tmp1 = ((u32)0x03) << tmpmask;
|
||||
tmpreg &= ~tmp1;
|
||||
tmpreg |= ~DBGAFR_SWJCFG_MASK;
|
||||
}
|
||||
else
|
||||
{
|
||||
tmpreg &= ~(tmp << ((GPIO_Remap >> 0x15)*0x10));
|
||||
tmpreg |= ~DBGAFR_SWJCFG_MASK;
|
||||
}
|
||||
|
||||
if (NewState != DISABLE)
|
||||
{
|
||||
tmpreg |= (tmp << ((GPIO_Remap >> 0x15)*0x10));
|
||||
}
|
||||
|
||||
AFIO->MAPR = tmpreg;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : GPIO_EXTILineConfig
|
||||
* Description : Selects the GPIO pin used as EXTI Line.
|
||||
* Input : - GPIO_PortSource: selects the GPIO port to be used as
|
||||
* source for EXTI lines.
|
||||
* This parameter can be GPIO_PortSourceGPIOx where x can be
|
||||
* (A..G).
|
||||
* - GPIO_PinSource: specifies the EXTI line to be configured.
|
||||
* This parameter can be GPIO_PinSourcex where x can be (0..15).
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void GPIO_EXTILineConfig(u8 GPIO_PortSource, u8 GPIO_PinSource)
|
||||
{
|
||||
u32 tmp = 0x00;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_GPIO_EXTI_PORT_SOURCE(GPIO_PortSource));
|
||||
assert_param(IS_GPIO_PIN_SOURCE(GPIO_PinSource));
|
||||
|
||||
tmp = ((u32)0x0F) << (0x04 * (GPIO_PinSource & (u8)0x03));
|
||||
|
||||
AFIO->EXTICR[GPIO_PinSource >> 0x02] &= ~tmp;
|
||||
AFIO->EXTICR[GPIO_PinSource >> 0x02] |= (((u32)GPIO_PortSource) << (0x04 * (GPIO_PinSource & (u8)0x03)));
|
||||
}
|
||||
|
||||
/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
|
1237
Demo/CORTEX_STM32F103_GCC_Rowley/ST Library/src/stm32f10x_i2c.c
Normal file
1237
Demo/CORTEX_STM32F103_GCC_Rowley/ST Library/src/stm32f10x_i2c.c
Normal file
File diff suppressed because it is too large
Load diff
303
Demo/CORTEX_STM32F103_GCC_Rowley/ST Library/src/stm32f10x_lib.c
Normal file
303
Demo/CORTEX_STM32F103_GCC_Rowley/ST Library/src/stm32f10x_lib.c
Normal file
|
@ -0,0 +1,303 @@
|
|||
/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
|
||||
* File Name : stm32f10x_lib.c
|
||||
* Author : MCD Application Team
|
||||
* Version : V2.0.1
|
||||
* Date : 06/13/2008
|
||||
* Description : This file provides all peripherals pointers initialization.
|
||||
********************************************************************************
|
||||
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
|
||||
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
|
||||
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
|
||||
* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
|
||||
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
|
||||
*******************************************************************************/
|
||||
|
||||
#define EXT
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32f10x_lib.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
#ifdef DEBUG
|
||||
/*******************************************************************************
|
||||
* Function Name : debug
|
||||
* Description : This function initialize peripherals pointers.
|
||||
* Input : None
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void debug(void)
|
||||
{
|
||||
|
||||
/************************************* ADC ************************************/
|
||||
#ifdef _ADC1
|
||||
ADC1 = (ADC_TypeDef *) ADC1_BASE;
|
||||
#endif /*_ADC1 */
|
||||
|
||||
#ifdef _ADC2
|
||||
ADC2 = (ADC_TypeDef *) ADC2_BASE;
|
||||
#endif /*_ADC2 */
|
||||
|
||||
#ifdef _ADC3
|
||||
ADC3 = (ADC_TypeDef *) ADC3_BASE;
|
||||
#endif /*_ADC3 */
|
||||
|
||||
/************************************* BKP ************************************/
|
||||
#ifdef _BKP
|
||||
BKP = (BKP_TypeDef *) BKP_BASE;
|
||||
#endif /*_BKP */
|
||||
|
||||
/************************************* CAN ************************************/
|
||||
#ifdef _CAN
|
||||
CAN = (CAN_TypeDef *) CAN_BASE;
|
||||
#endif /*_CAN */
|
||||
|
||||
/************************************* CRC ************************************/
|
||||
#ifdef _CRC
|
||||
CRC = (CRC_TypeDef *) CRC_BASE;
|
||||
#endif /*_CRC */
|
||||
|
||||
/************************************* DAC ************************************/
|
||||
#ifdef _DAC
|
||||
DAC = (DAC_TypeDef *) DAC_BASE;
|
||||
#endif /*_DAC */
|
||||
|
||||
/************************************* DBGMCU**********************************/
|
||||
#ifdef _DBGMCU
|
||||
DBGMCU = (DBGMCU_TypeDef *) DBGMCU_BASE;
|
||||
#endif /*_DBGMCU */
|
||||
|
||||
/************************************* DMA ************************************/
|
||||
#ifdef _DMA
|
||||
DMA1 = (DMA_TypeDef *) DMA1_BASE;
|
||||
DMA2 = (DMA_TypeDef *) DMA2_BASE;
|
||||
#endif /*_DMA */
|
||||
|
||||
#ifdef _DMA1_Channel1
|
||||
DMA1_Channel1 = (DMA_Channel_TypeDef *) DMA1_Channel1_BASE;
|
||||
#endif /*_DMA1_Channel1 */
|
||||
|
||||
#ifdef _DMA1_Channel2
|
||||
DMA1_Channel2 = (DMA_Channel_TypeDef *) DMA1_Channel2_BASE;
|
||||
#endif /*_DMA1_Channel2 */
|
||||
|
||||
#ifdef _DMA1_Channel3
|
||||
DMA1_Channel3 = (DMA_Channel_TypeDef *) DMA1_Channel3_BASE;
|
||||
#endif /*_DMA1_Channel3 */
|
||||
|
||||
#ifdef _DMA1_Channel4
|
||||
DMA1_Channel4 = (DMA_Channel_TypeDef *) DMA1_Channel4_BASE;
|
||||
#endif /*_DMA1_Channel4 */
|
||||
|
||||
#ifdef _DMA1_Channel5
|
||||
DMA1_Channel5 = (DMA_Channel_TypeDef *) DMA1_Channel5_BASE;
|
||||
#endif /*_DMA1_Channel5 */
|
||||
|
||||
#ifdef _DMA1_Channel6
|
||||
DMA1_Channel6 = (DMA_Channel_TypeDef *) DMA1_Channel6_BASE;
|
||||
#endif /*_DMA1_Channel6 */
|
||||
|
||||
#ifdef _DMA1_Channel7
|
||||
DMA1_Channel7 = (DMA_Channel_TypeDef *) DMA1_Channel7_BASE;
|
||||
#endif /*_DMA1_Channel7 */
|
||||
|
||||
#ifdef _DMA2_Channel1
|
||||
DMA2_Channel1 = (DMA_Channel_TypeDef *) DMA2_Channel1_BASE;
|
||||
#endif /*_DMA2_Channel1 */
|
||||
|
||||
#ifdef _DMA2_Channel2
|
||||
DMA2_Channel2 = (DMA_Channel_TypeDef *) DMA2_Channel2_BASE;
|
||||
#endif /*_DMA2_Channel2 */
|
||||
|
||||
#ifdef _DMA2_Channel3
|
||||
DMA2_Channel3 = (DMA_Channel_TypeDef *) DMA2_Channel3_BASE;
|
||||
#endif /*_DMA2_Channel3 */
|
||||
|
||||
#ifdef _DMA2_Channel4
|
||||
DMA2_Channel4 = (DMA_Channel_TypeDef *) DMA2_Channel4_BASE;
|
||||
#endif /*_DMA2_Channel4 */
|
||||
|
||||
#ifdef _DMA2_Channel5
|
||||
DMA2_Channel5 = (DMA_Channel_TypeDef *) DMA2_Channel5_BASE;
|
||||
#endif /*_DMA2_Channel5 */
|
||||
|
||||
/************************************* EXTI ***********************************/
|
||||
#ifdef _EXTI
|
||||
EXTI = (EXTI_TypeDef *) EXTI_BASE;
|
||||
#endif /*_EXTI */
|
||||
|
||||
/************************************* FLASH and Option Bytes *****************/
|
||||
#ifdef _FLASH
|
||||
FLASH = (FLASH_TypeDef *) FLASH_R_BASE;
|
||||
OB = (OB_TypeDef *) OB_BASE;
|
||||
#endif /*_FLASH */
|
||||
|
||||
/************************************* FSMC ***********************************/
|
||||
#ifdef _FSMC
|
||||
FSMC_Bank1 = (FSMC_Bank1_TypeDef *) FSMC_Bank1_R_BASE;
|
||||
FSMC_Bank1E = (FSMC_Bank1E_TypeDef *) FSMC_Bank1E_R_BASE;
|
||||
FSMC_Bank2 = (FSMC_Bank2_TypeDef *) FSMC_Bank2_R_BASE;
|
||||
FSMC_Bank3 = (FSMC_Bank3_TypeDef *) FSMC_Bank3_R_BASE;
|
||||
FSMC_Bank4 = (FSMC_Bank4_TypeDef *) FSMC_Bank4_R_BASE;
|
||||
#endif /*_FSMC */
|
||||
|
||||
/************************************* GPIO ***********************************/
|
||||
#ifdef _GPIOA
|
||||
GPIOA = (GPIO_TypeDef *) GPIOA_BASE;
|
||||
#endif /*_GPIOA */
|
||||
|
||||
#ifdef _GPIOB
|
||||
GPIOB = (GPIO_TypeDef *) GPIOB_BASE;
|
||||
#endif /*_GPIOB */
|
||||
|
||||
#ifdef _GPIOC
|
||||
GPIOC = (GPIO_TypeDef *) GPIOC_BASE;
|
||||
#endif /*_GPIOC */
|
||||
|
||||
#ifdef _GPIOD
|
||||
GPIOD = (GPIO_TypeDef *) GPIOD_BASE;
|
||||
#endif /*_GPIOD */
|
||||
|
||||
#ifdef _GPIOE
|
||||
GPIOE = (GPIO_TypeDef *) GPIOE_BASE;
|
||||
#endif /*_GPIOE */
|
||||
|
||||
#ifdef _GPIOF
|
||||
GPIOF = (GPIO_TypeDef *) GPIOF_BASE;
|
||||
#endif /*_GPIOF */
|
||||
|
||||
#ifdef _GPIOG
|
||||
GPIOG = (GPIO_TypeDef *) GPIOG_BASE;
|
||||
#endif /*_GPIOG */
|
||||
|
||||
#ifdef _AFIO
|
||||
AFIO = (AFIO_TypeDef *) AFIO_BASE;
|
||||
#endif /*_AFIO */
|
||||
|
||||
/************************************* I2C ************************************/
|
||||
#ifdef _I2C1
|
||||
I2C1 = (I2C_TypeDef *) I2C1_BASE;
|
||||
#endif /*_I2C1 */
|
||||
|
||||
#ifdef _I2C2
|
||||
I2C2 = (I2C_TypeDef *) I2C2_BASE;
|
||||
#endif /*_I2C2 */
|
||||
|
||||
/************************************* IWDG ***********************************/
|
||||
#ifdef _IWDG
|
||||
IWDG = (IWDG_TypeDef *) IWDG_BASE;
|
||||
#endif /*_IWDG */
|
||||
|
||||
/************************************* NVIC ***********************************/
|
||||
#ifdef _NVIC
|
||||
NVIC = (NVIC_TypeDef *) NVIC_BASE;
|
||||
SCB = (SCB_TypeDef *) SCB_BASE;
|
||||
#endif /*_NVIC */
|
||||
|
||||
/************************************* PWR ************************************/
|
||||
#ifdef _PWR
|
||||
PWR = (PWR_TypeDef *) PWR_BASE;
|
||||
#endif /*_PWR */
|
||||
|
||||
/************************************* RCC ************************************/
|
||||
#ifdef _RCC
|
||||
RCC = (RCC_TypeDef *) RCC_BASE;
|
||||
#endif /*_RCC */
|
||||
|
||||
/************************************* RTC ************************************/
|
||||
#ifdef _RTC
|
||||
RTC = (RTC_TypeDef *) RTC_BASE;
|
||||
#endif /*_RTC */
|
||||
|
||||
/************************************* SDIO ***********************************/
|
||||
#ifdef _SDIO
|
||||
SDIO = (SDIO_TypeDef *) SDIO_BASE;
|
||||
#endif /*_SDIO */
|
||||
|
||||
/************************************* SPI ************************************/
|
||||
#ifdef _SPI1
|
||||
SPI1 = (SPI_TypeDef *) SPI1_BASE;
|
||||
#endif /*_SPI1 */
|
||||
|
||||
#ifdef _SPI2
|
||||
SPI2 = (SPI_TypeDef *) SPI2_BASE;
|
||||
#endif /*_SPI2 */
|
||||
|
||||
#ifdef _SPI3
|
||||
SPI3 = (SPI_TypeDef *) SPI3_BASE;
|
||||
#endif /*_SPI3 */
|
||||
|
||||
/************************************* SysTick ********************************/
|
||||
#ifdef _SysTick
|
||||
SysTick = (SysTick_TypeDef *) SysTick_BASE;
|
||||
#endif /*_SysTick */
|
||||
|
||||
/************************************* TIM ************************************/
|
||||
#ifdef _TIM1
|
||||
TIM1 = (TIM_TypeDef *) TIM1_BASE;
|
||||
#endif /*_TIM1 */
|
||||
|
||||
#ifdef _TIM2
|
||||
TIM2 = (TIM_TypeDef *) TIM2_BASE;
|
||||
#endif /*_TIM2 */
|
||||
|
||||
#ifdef _TIM3
|
||||
TIM3 = (TIM_TypeDef *) TIM3_BASE;
|
||||
#endif /*_TIM3 */
|
||||
|
||||
#ifdef _TIM4
|
||||
TIM4 = (TIM_TypeDef *) TIM4_BASE;
|
||||
#endif /*_TIM4 */
|
||||
|
||||
#ifdef _TIM5
|
||||
TIM5 = (TIM_TypeDef *) TIM5_BASE;
|
||||
#endif /*_TIM5 */
|
||||
|
||||
#ifdef _TIM6
|
||||
TIM6 = (TIM_TypeDef *) TIM6_BASE;
|
||||
#endif /*_TIM6 */
|
||||
|
||||
#ifdef _TIM7
|
||||
TIM7 = (TIM_TypeDef *) TIM7_BASE;
|
||||
#endif /*_TIM7 */
|
||||
|
||||
#ifdef _TIM8
|
||||
TIM8 = (TIM_TypeDef *) TIM8_BASE;
|
||||
#endif /*_TIM8 */
|
||||
|
||||
/************************************* USART **********************************/
|
||||
#ifdef _USART1
|
||||
USART1 = (USART_TypeDef *) USART1_BASE;
|
||||
#endif /*_USART1 */
|
||||
|
||||
#ifdef _USART2
|
||||
USART2 = (USART_TypeDef *) USART2_BASE;
|
||||
#endif /*_USART2 */
|
||||
|
||||
#ifdef _USART3
|
||||
USART3 = (USART_TypeDef *) USART3_BASE;
|
||||
#endif /*_USART3 */
|
||||
|
||||
#ifdef _UART4
|
||||
UART4 = (USART_TypeDef *) UART4_BASE;
|
||||
#endif /*_UART4 */
|
||||
|
||||
#ifdef _UART5
|
||||
UART5 = (USART_TypeDef *) UART5_BASE;
|
||||
#endif /*_UART5 */
|
||||
|
||||
/************************************* WWDG ***********************************/
|
||||
#ifdef _WWDG
|
||||
WWDG = (WWDG_TypeDef *) WWDG_BASE;
|
||||
#endif /*_WWDG */
|
||||
}
|
||||
#endif /* DEBUG*/
|
||||
|
||||
/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
|
751
Demo/CORTEX_STM32F103_GCC_Rowley/ST Library/src/stm32f10x_nvic.c
Normal file
751
Demo/CORTEX_STM32F103_GCC_Rowley/ST Library/src/stm32f10x_nvic.c
Normal file
|
@ -0,0 +1,751 @@
|
|||
/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
|
||||
* File Name : stm32f10x_nvic.c
|
||||
* Author : MCD Application Team
|
||||
* Version : V2.0.1
|
||||
* Date : 06/13/2008
|
||||
* Description : This file provides all the NVIC firmware functions.
|
||||
********************************************************************************
|
||||
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
|
||||
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
|
||||
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
|
||||
* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
|
||||
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
|
||||
*******************************************************************************/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32f10x_nvic.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
#define AIRCR_VECTKEY_MASK ((u32)0x05FA0000)
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : NVIC_DeInit
|
||||
* Description : Deinitializes the NVIC peripheral registers to their default
|
||||
* reset values.
|
||||
* Input : None
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void NVIC_DeInit(void)
|
||||
{
|
||||
u32 index = 0;
|
||||
|
||||
NVIC->ICER[0] = 0xFFFFFFFF;
|
||||
NVIC->ICER[1] = 0x0FFFFFFF;
|
||||
NVIC->ICPR[0] = 0xFFFFFFFF;
|
||||
NVIC->ICPR[1] = 0x0FFFFFFF;
|
||||
|
||||
for(index = 0; index < 0x0F; index++)
|
||||
{
|
||||
NVIC->IPR[index] = 0x00000000;
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : NVIC_SCBDeInit
|
||||
* Description : Deinitializes the SCB peripheral registers to their default
|
||||
* reset values.
|
||||
* Input : None
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void NVIC_SCBDeInit(void)
|
||||
{
|
||||
u32 index = 0x00;
|
||||
|
||||
SCB->ICSR = 0x0A000000;
|
||||
SCB->VTOR = 0x00000000;
|
||||
SCB->AIRCR = AIRCR_VECTKEY_MASK;
|
||||
SCB->SCR = 0x00000000;
|
||||
SCB->CCR = 0x00000000;
|
||||
for(index = 0; index < 0x03; index++)
|
||||
{
|
||||
SCB->SHPR[index] = 0;
|
||||
}
|
||||
SCB->SHCSR = 0x00000000;
|
||||
SCB->CFSR = 0xFFFFFFFF;
|
||||
SCB->HFSR = 0xFFFFFFFF;
|
||||
SCB->DFSR = 0xFFFFFFFF;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : NVIC_PriorityGroupConfig
|
||||
* Description : Configures the priority grouping: pre-emption priority
|
||||
* and subpriority.
|
||||
* Input : - NVIC_PriorityGroup: specifies the priority grouping bits
|
||||
* length. This parameter can be one of the following values:
|
||||
* - NVIC_PriorityGroup_0: 0 bits for pre-emption priority
|
||||
* 4 bits for subpriority
|
||||
* - NVIC_PriorityGroup_1: 1 bits for pre-emption priority
|
||||
* 3 bits for subpriority
|
||||
* - NVIC_PriorityGroup_2: 2 bits for pre-emption priority
|
||||
* 2 bits for subpriority
|
||||
* - NVIC_PriorityGroup_3: 3 bits for pre-emption priority
|
||||
* 1 bits for subpriority
|
||||
* - NVIC_PriorityGroup_4: 4 bits for pre-emption priority
|
||||
* 0 bits for subpriority
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void NVIC_PriorityGroupConfig(u32 NVIC_PriorityGroup)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_NVIC_PRIORITY_GROUP(NVIC_PriorityGroup));
|
||||
|
||||
/* Set the PRIGROUP[10:8] bits according to NVIC_PriorityGroup value */
|
||||
SCB->AIRCR = AIRCR_VECTKEY_MASK | NVIC_PriorityGroup;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : NVIC_Init
|
||||
* Description : Initializes the NVIC peripheral according to the specified
|
||||
* parameters in the NVIC_InitStruct.
|
||||
* Input : - NVIC_InitStruct: pointer to a NVIC_InitTypeDef structure
|
||||
* that contains the configuration information for the
|
||||
* specified NVIC peripheral.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void NVIC_Init(NVIC_InitTypeDef* NVIC_InitStruct)
|
||||
{
|
||||
u32 tmppriority = 0x00, tmpreg = 0x00, tmpmask = 0x00;
|
||||
u32 tmppre = 0, tmpsub = 0x0F;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_FUNCTIONAL_STATE(NVIC_InitStruct->NVIC_IRQChannelCmd));
|
||||
assert_param(IS_NVIC_IRQ_CHANNEL(NVIC_InitStruct->NVIC_IRQChannel));
|
||||
assert_param(IS_NVIC_PREEMPTION_PRIORITY(NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority));
|
||||
assert_param(IS_NVIC_SUB_PRIORITY(NVIC_InitStruct->NVIC_IRQChannelSubPriority));
|
||||
|
||||
if (NVIC_InitStruct->NVIC_IRQChannelCmd != DISABLE)
|
||||
{
|
||||
/* Compute the Corresponding IRQ Priority --------------------------------*/
|
||||
tmppriority = (0x700 - (SCB->AIRCR & (u32)0x700))>> 0x08;
|
||||
tmppre = (0x4 - tmppriority);
|
||||
tmpsub = tmpsub >> tmppriority;
|
||||
|
||||
tmppriority = (u32)NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority << tmppre;
|
||||
tmppriority |= NVIC_InitStruct->NVIC_IRQChannelSubPriority & tmpsub;
|
||||
|
||||
tmppriority = tmppriority << 0x04;
|
||||
tmppriority = ((u32)tmppriority) << ((NVIC_InitStruct->NVIC_IRQChannel & (u8)0x03) * 0x08);
|
||||
|
||||
tmpreg = NVIC->IPR[(NVIC_InitStruct->NVIC_IRQChannel >> 0x02)];
|
||||
tmpmask = (u32)0xFF << ((NVIC_InitStruct->NVIC_IRQChannel & (u8)0x03) * 0x08);
|
||||
tmpreg &= ~tmpmask;
|
||||
tmppriority &= tmpmask;
|
||||
tmpreg |= tmppriority;
|
||||
|
||||
NVIC->IPR[(NVIC_InitStruct->NVIC_IRQChannel >> 0x02)] = tmpreg;
|
||||
|
||||
/* Enable the Selected IRQ Channels --------------------------------------*/
|
||||
NVIC->ISER[(NVIC_InitStruct->NVIC_IRQChannel >> 0x05)] =
|
||||
(u32)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (u8)0x1F);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Disable the Selected IRQ Channels -------------------------------------*/
|
||||
NVIC->ICER[(NVIC_InitStruct->NVIC_IRQChannel >> 0x05)] =
|
||||
(u32)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (u8)0x1F);
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : NVIC_StructInit
|
||||
* Description : Fills each NVIC_InitStruct member with its default value.
|
||||
* Input : - NVIC_InitStruct: pointer to a NVIC_InitTypeDef structure which
|
||||
* will be initialized.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void NVIC_StructInit(NVIC_InitTypeDef* NVIC_InitStruct)
|
||||
{
|
||||
/* NVIC_InitStruct members default value */
|
||||
NVIC_InitStruct->NVIC_IRQChannel = 0x00;
|
||||
NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority = 0x00;
|
||||
NVIC_InitStruct->NVIC_IRQChannelSubPriority = 0x00;
|
||||
NVIC_InitStruct->NVIC_IRQChannelCmd = DISABLE;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : NVIC_SETPRIMASK
|
||||
* Description : Enables the PRIMASK priority: Raises the execution priority to 0.
|
||||
* Input : None
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void NVIC_SETPRIMASK(void)
|
||||
{
|
||||
__SETPRIMASK();
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : NVIC_RESETPRIMASK
|
||||
* Description : Disables the PRIMASK priority.
|
||||
* Input : None
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void NVIC_RESETPRIMASK(void)
|
||||
{
|
||||
__RESETPRIMASK();
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : NVIC_SETFAULTMASK
|
||||
* Description : Enables the FAULTMASK priority: Raises the execution priority to -1.
|
||||
* Input : None
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void NVIC_SETFAULTMASK(void)
|
||||
{
|
||||
__SETFAULTMASK();
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : NVIC_RESETFAULTMASK
|
||||
* Description : Disables the FAULTMASK priority.
|
||||
* Input : None
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void NVIC_RESETFAULTMASK(void)
|
||||
{
|
||||
__RESETFAULTMASK();
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : NVIC_BASEPRICONFIG
|
||||
* Description : The execution priority can be changed from 15 (lowest
|
||||
configurable priority) to 1. Writing a zero value will disable
|
||||
* the mask of execution priority.
|
||||
* Input : None
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void NVIC_BASEPRICONFIG(u32 NewPriority)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_NVIC_BASE_PRI(NewPriority));
|
||||
|
||||
__BASEPRICONFIG(NewPriority << 0x04);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : NVIC_GetBASEPRI
|
||||
* Description : Returns the BASEPRI mask value.
|
||||
* Input : None
|
||||
* Output : None
|
||||
* Return : BASEPRI register value
|
||||
*******************************************************************************/
|
||||
u32 NVIC_GetBASEPRI(void)
|
||||
{
|
||||
return (__GetBASEPRI());
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : NVIC_GetCurrentPendingIRQChannel
|
||||
* Description : Returns the current pending IRQ channel identifier.
|
||||
* Input : None
|
||||
* Output : None
|
||||
* Return : Pending IRQ Channel Identifier.
|
||||
*******************************************************************************/
|
||||
u16 NVIC_GetCurrentPendingIRQChannel(void)
|
||||
{
|
||||
return ((u16)((SCB->ICSR & (u32)0x003FF000) >> 0x0C));
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : NVIC_GetIRQChannelPendingBitStatus
|
||||
* Description : Checks whether the specified IRQ Channel pending bit is set
|
||||
* or not.
|
||||
* Input : - NVIC_IRQChannel: specifies the interrupt pending bit to check.
|
||||
* Output : None
|
||||
* Return : The new state of IRQ Channel pending bit(SET or RESET).
|
||||
*******************************************************************************/
|
||||
ITStatus NVIC_GetIRQChannelPendingBitStatus(u8 NVIC_IRQChannel)
|
||||
{
|
||||
ITStatus pendingirqstatus = RESET;
|
||||
u32 tmp = 0x00;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_NVIC_IRQ_CHANNEL(NVIC_IRQChannel));
|
||||
|
||||
tmp = ((u32)0x01 << (NVIC_IRQChannel & (u32)0x1F));
|
||||
|
||||
if (((NVIC->ISPR[(NVIC_IRQChannel >> 0x05)]) & tmp) == tmp)
|
||||
{
|
||||
pendingirqstatus = SET;
|
||||
}
|
||||
else
|
||||
{
|
||||
pendingirqstatus = RESET;
|
||||
}
|
||||
return pendingirqstatus;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : NVIC_SetIRQChannelPendingBit
|
||||
* Description : Sets the NVIC’s interrupt pending bit.
|
||||
* Input : - NVIC_IRQChannel: specifies the interrupt pending bit to Set.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void NVIC_SetIRQChannelPendingBit(u8 NVIC_IRQChannel)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_NVIC_IRQ_CHANNEL(NVIC_IRQChannel));
|
||||
|
||||
*(vu32*) 0xE000EF00 = (u32)NVIC_IRQChannel;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : NVIC_ClearIRQChannelPendingBit
|
||||
* Description : Clears the NVIC’s interrupt pending bit.
|
||||
* Input : - NVIC_IRQChannel: specifies the interrupt pending bit to clear.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void NVIC_ClearIRQChannelPendingBit(u8 NVIC_IRQChannel)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_NVIC_IRQ_CHANNEL(NVIC_IRQChannel));
|
||||
|
||||
NVIC->ICPR[(NVIC_IRQChannel >> 0x05)] = (u32)0x01 << (NVIC_IRQChannel & (u32)0x1F);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : NVIC_GetCurrentActiveHandler
|
||||
* Description : Returns the current active Handler (IRQ Channel and
|
||||
* SystemHandler) identifier.
|
||||
* Input : None
|
||||
* Output : None
|
||||
* Return : Active Handler Identifier.
|
||||
*******************************************************************************/
|
||||
u16 NVIC_GetCurrentActiveHandler(void)
|
||||
{
|
||||
return ((u16)(SCB->ICSR & (u32)0x3FF));
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : NVIC_GetIRQChannelActiveBitStatus
|
||||
* Description : Checks whether the specified IRQ Channel active bit is set
|
||||
* or not.
|
||||
* Input : - NVIC_IRQChannel: specifies the interrupt active bit to check.
|
||||
* Output : None
|
||||
* Return : The new state of IRQ Channel active bit(SET or RESET).
|
||||
*******************************************************************************/
|
||||
ITStatus NVIC_GetIRQChannelActiveBitStatus(u8 NVIC_IRQChannel)
|
||||
{
|
||||
ITStatus activeirqstatus = RESET;
|
||||
u32 tmp = 0x00;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_NVIC_IRQ_CHANNEL(NVIC_IRQChannel));
|
||||
|
||||
tmp = ((u32)0x01 << (NVIC_IRQChannel & (u32)0x1F));
|
||||
|
||||
if (((NVIC->IABR[(NVIC_IRQChannel >> 0x05)]) & tmp) == tmp )
|
||||
{
|
||||
activeirqstatus = SET;
|
||||
}
|
||||
else
|
||||
{
|
||||
activeirqstatus = RESET;
|
||||
}
|
||||
return activeirqstatus;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : NVIC_GetCPUID
|
||||
* Description : Returns the ID number, the version number and the implementation
|
||||
* details of the Cortex-M3 core.
|
||||
* Input : None
|
||||
* Output : None
|
||||
* Return : CPU ID.
|
||||
*******************************************************************************/
|
||||
u32 NVIC_GetCPUID(void)
|
||||
{
|
||||
return (SCB->CPUID);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : NVIC_SetVectorTable
|
||||
* Description : Sets the vector table location and Offset.
|
||||
* Input : - NVIC_VectTab: specifies if the vector table is in RAM or
|
||||
* FLASH memory.
|
||||
* This parameter can be one of the following values:
|
||||
* - NVIC_VectTab_RAM
|
||||
* - NVIC_VectTab_FLASH
|
||||
* - Offset: Vector Table base offset field.
|
||||
* This value must be a multiple of 0x100.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void NVIC_SetVectorTable(u32 NVIC_VectTab, u32 Offset)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_NVIC_VECTTAB(NVIC_VectTab));
|
||||
assert_param(IS_NVIC_OFFSET(Offset));
|
||||
|
||||
SCB->VTOR = NVIC_VectTab | (Offset & (u32)0x1FFFFF80);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : NVIC_GenerateSystemReset
|
||||
* Description : Generates a system reset.
|
||||
* Input : None
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void NVIC_GenerateSystemReset(void)
|
||||
{
|
||||
SCB->AIRCR = AIRCR_VECTKEY_MASK | (u32)0x04;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : NVIC_GenerateCoreReset
|
||||
* Description : Generates a Core (Core + NVIC) reset.
|
||||
* Input : None
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void NVIC_GenerateCoreReset(void)
|
||||
{
|
||||
SCB->AIRCR = AIRCR_VECTKEY_MASK | (u32)0x01;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : NVIC_SystemLPConfig
|
||||
* Description : Selects the condition for the system to enter low power mode.
|
||||
* Input : - LowPowerMode: Specifies the new mode for the system to enter
|
||||
* low power mode.
|
||||
* This parameter can be one of the following values:
|
||||
* - NVIC_LP_SEVONPEND
|
||||
* - NVIC_LP_SLEEPDEEP
|
||||
* - NVIC_LP_SLEEPONEXIT
|
||||
* - NewState: new state of LP condition.
|
||||
* This parameter can be: ENABLE or DISABLE.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void NVIC_SystemLPConfig(u8 LowPowerMode, FunctionalState NewState)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_NVIC_LP(LowPowerMode));
|
||||
assert_param(IS_FUNCTIONAL_STATE(NewState));
|
||||
|
||||
if (NewState != DISABLE)
|
||||
{
|
||||
SCB->SCR |= LowPowerMode;
|
||||
}
|
||||
else
|
||||
{
|
||||
SCB->SCR &= (u32)(~(u32)LowPowerMode);
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : NVIC_SystemHandlerConfig
|
||||
* Description : Enables or disables the specified System Handlers.
|
||||
* Input : - SystemHandler: specifies the system handler to be enabled
|
||||
* or disabled.
|
||||
* This parameter can be one of the following values:
|
||||
* - SystemHandler_MemoryManage
|
||||
* - SystemHandler_BusFault
|
||||
* - SystemHandler_UsageFault
|
||||
* - NewState: new state of specified System Handlers.
|
||||
* This parameter can be: ENABLE or DISABLE.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void NVIC_SystemHandlerConfig(u32 SystemHandler, FunctionalState NewState)
|
||||
{
|
||||
u32 tmpreg = 0x00;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_CONFIG_SYSTEM_HANDLER(SystemHandler));
|
||||
assert_param(IS_FUNCTIONAL_STATE(NewState));
|
||||
|
||||
tmpreg = (u32)0x01 << (SystemHandler & (u32)0x1F);
|
||||
|
||||
if (NewState != DISABLE)
|
||||
{
|
||||
SCB->SHCSR |= tmpreg;
|
||||
}
|
||||
else
|
||||
{
|
||||
SCB->SHCSR &= ~tmpreg;
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : NVIC_SystemHandlerPriorityConfig
|
||||
* Description : Configures the specified System Handlers priority.
|
||||
* Input : - SystemHandler: specifies the system handler to be
|
||||
* enabled or disabled.
|
||||
* This parameter can be one of the following values:
|
||||
* - SystemHandler_MemoryManage
|
||||
* - SystemHandler_BusFault
|
||||
* - SystemHandler_UsageFault
|
||||
* - SystemHandler_SVCall
|
||||
* - SystemHandler_DebugMonitor
|
||||
* - SystemHandler_PSV
|
||||
* - SystemHandler_SysTick
|
||||
* - SystemHandlerPreemptionPriority: new priority group of the
|
||||
* specified system handlers.
|
||||
* - SystemHandlerSubPriority: new sub priority of the specified
|
||||
* system handlers.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void NVIC_SystemHandlerPriorityConfig(u32 SystemHandler, u8 SystemHandlerPreemptionPriority,
|
||||
u8 SystemHandlerSubPriority)
|
||||
{
|
||||
u32 tmp1 = 0x00, tmp2 = 0xFF, handlermask = 0x00;
|
||||
u32 tmppriority = 0x00;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_PRIORITY_SYSTEM_HANDLER(SystemHandler));
|
||||
assert_param(IS_NVIC_PREEMPTION_PRIORITY(SystemHandlerPreemptionPriority));
|
||||
assert_param(IS_NVIC_SUB_PRIORITY(SystemHandlerSubPriority));
|
||||
|
||||
tmppriority = (0x700 - (SCB->AIRCR & (u32)0x700))>> 0x08;
|
||||
tmp1 = (0x4 - tmppriority);
|
||||
tmp2 = tmp2 >> tmppriority;
|
||||
|
||||
tmppriority = (u32)SystemHandlerPreemptionPriority << tmp1;
|
||||
tmppriority |= SystemHandlerSubPriority & tmp2;
|
||||
|
||||
tmppriority = tmppriority << 0x04;
|
||||
tmp1 = SystemHandler & (u32)0xC0;
|
||||
tmp1 = tmp1 >> 0x06;
|
||||
tmp2 = (SystemHandler >> 0x08) & (u32)0x03;
|
||||
tmppriority = tmppriority << (tmp2 * 0x08);
|
||||
handlermask = (u32)0xFF << (tmp2 * 0x08);
|
||||
|
||||
SCB->SHPR[tmp1] &= ~handlermask;
|
||||
SCB->SHPR[tmp1] |= tmppriority;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : NVIC_GetSystemHandlerPendingBitStatus
|
||||
* Description : Checks whether the specified System handlers pending bit is
|
||||
* set or not.
|
||||
* Input : - SystemHandler: specifies the system handler pending bit to
|
||||
* check.
|
||||
* This parameter can be one of the following values:
|
||||
* - SystemHandler_MemoryManage
|
||||
* - SystemHandler_BusFault
|
||||
* - SystemHandler_SVCall
|
||||
* Output : None
|
||||
* Return : The new state of System Handler pending bit(SET or RESET).
|
||||
*******************************************************************************/
|
||||
ITStatus NVIC_GetSystemHandlerPendingBitStatus(u32 SystemHandler)
|
||||
{
|
||||
ITStatus bitstatus = RESET;
|
||||
u32 tmp = 0x00, tmppos = 0x00;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_GET_PENDING_SYSTEM_HANDLER(SystemHandler));
|
||||
|
||||
tmppos = (SystemHandler >> 0x0A);
|
||||
tmppos &= (u32)0x0F;
|
||||
|
||||
tmppos = (u32)0x01 << tmppos;
|
||||
|
||||
tmp = SCB->SHCSR & tmppos;
|
||||
|
||||
if (tmp == tmppos)
|
||||
{
|
||||
bitstatus = SET;
|
||||
}
|
||||
else
|
||||
{
|
||||
bitstatus = RESET;
|
||||
}
|
||||
return bitstatus;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : NVIC_SetSystemHandlerPendingBit
|
||||
* Description : Sets System Handler pending bit.
|
||||
* Input : - SystemHandler: specifies the system handler pending bit
|
||||
* to be set.
|
||||
* This parameter can be one of the following values:
|
||||
* - SystemHandler_NMI
|
||||
* - SystemHandler_PSV
|
||||
* - SystemHandler_SysTick
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void NVIC_SetSystemHandlerPendingBit(u32 SystemHandler)
|
||||
{
|
||||
u32 tmp = 0x00;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_SET_PENDING_SYSTEM_HANDLER(SystemHandler));
|
||||
|
||||
/* Get the System Handler pending bit position */
|
||||
tmp = SystemHandler & (u32)0x1F;
|
||||
/* Set the corresponding System Handler pending bit */
|
||||
SCB->ICSR |= ((u32)0x01 << tmp);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : NVIC_ClearSystemHandlerPendingBit
|
||||
* Description : Clears System Handler pending bit.
|
||||
* Input : - SystemHandler: specifies the system handler pending bit to
|
||||
* be clear.
|
||||
* This parameter can be one of the following values:
|
||||
* - SystemHandler_PSV
|
||||
* - SystemHandler_SysTick
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void NVIC_ClearSystemHandlerPendingBit(u32 SystemHandler)
|
||||
{
|
||||
u32 tmp = 0x00;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_CLEAR_SYSTEM_HANDLER(SystemHandler));
|
||||
|
||||
/* Get the System Handler pending bit position */
|
||||
tmp = SystemHandler & (u32)0x1F;
|
||||
/* Clear the corresponding System Handler pending bit */
|
||||
SCB->ICSR |= ((u32)0x01 << (tmp - 0x01));
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : NVIC_GetSystemHandlerActiveBitStatus
|
||||
* Description : Checks whether the specified System handlers active bit is
|
||||
* set or not.
|
||||
* Input : - SystemHandler: specifies the system handler active bit to
|
||||
* check.
|
||||
* This parameter can be one of the following values:
|
||||
* - SystemHandler_MemoryManage
|
||||
* - SystemHandler_BusFault
|
||||
* - SystemHandler_UsageFault
|
||||
* - SystemHandler_SVCall
|
||||
* - SystemHandler_DebugMonitor
|
||||
* - SystemHandler_PSV
|
||||
* - SystemHandler_SysTick
|
||||
* Output : None
|
||||
* Return : The new state of System Handler active bit(SET or RESET).
|
||||
*******************************************************************************/
|
||||
ITStatus NVIC_GetSystemHandlerActiveBitStatus(u32 SystemHandler)
|
||||
{
|
||||
ITStatus bitstatus = RESET;
|
||||
|
||||
u32 tmp = 0x00, tmppos = 0x00;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_GET_ACTIVE_SYSTEM_HANDLER(SystemHandler));
|
||||
|
||||
tmppos = (SystemHandler >> 0x0E) & (u32)0x0F;
|
||||
|
||||
tmppos = (u32)0x01 << tmppos;
|
||||
|
||||
tmp = SCB->SHCSR & tmppos;
|
||||
|
||||
if (tmp == tmppos)
|
||||
{
|
||||
bitstatus = SET;
|
||||
}
|
||||
else
|
||||
{
|
||||
bitstatus = RESET;
|
||||
}
|
||||
return bitstatus;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : NVIC_GetFaultHandlerSources
|
||||
* Description : Returns the system fault handlers sources.
|
||||
* Input : - SystemHandler: specifies the system handler to get its fault
|
||||
* sources.
|
||||
* This parameter can be one of the following values:
|
||||
* - SystemHandler_HardFault
|
||||
* - SystemHandler_MemoryManage
|
||||
* - SystemHandler_BusFault
|
||||
* - SystemHandler_UsageFault
|
||||
* - SystemHandler_DebugMonitor
|
||||
* Output : None
|
||||
* Return : Source of the fault handler.
|
||||
*******************************************************************************/
|
||||
u32 NVIC_GetFaultHandlerSources(u32 SystemHandler)
|
||||
{
|
||||
u32 faultsources = 0x00;
|
||||
u32 tmpreg = 0x00, tmppos = 0x00;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_FAULT_SOURCE_SYSTEM_HANDLER(SystemHandler));
|
||||
|
||||
tmpreg = (SystemHandler >> 0x12) & (u32)0x03;
|
||||
tmppos = (SystemHandler >> 0x14) & (u32)0x03;
|
||||
|
||||
if (tmpreg == 0x00)
|
||||
{
|
||||
faultsources = SCB->HFSR;
|
||||
}
|
||||
else if (tmpreg == 0x01)
|
||||
{
|
||||
faultsources = SCB->CFSR >> (tmppos * 0x08);
|
||||
if (tmppos != 0x02)
|
||||
{
|
||||
faultsources &= (u32)0x0F;
|
||||
}
|
||||
else
|
||||
{
|
||||
faultsources &= (u32)0xFF;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
faultsources = SCB->DFSR;
|
||||
}
|
||||
return faultsources;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : NVIC_GetFaultAddress
|
||||
* Description : Returns the address of the location that generated a fault
|
||||
* handler.
|
||||
* Input : - SystemHandler: specifies the system handler to get its
|
||||
* fault address.
|
||||
* This parameter can be one of the following values:
|
||||
* - SystemHandler_MemoryManage
|
||||
* - SystemHandler_BusFault
|
||||
* Output : None
|
||||
* Return : Fault address.
|
||||
*******************************************************************************/
|
||||
u32 NVIC_GetFaultAddress(u32 SystemHandler)
|
||||
{
|
||||
u32 faultaddress = 0x00;
|
||||
u32 tmp = 0x00;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_FAULT_ADDRESS_SYSTEM_HANDLER(SystemHandler));
|
||||
|
||||
tmp = (SystemHandler >> 0x16) & (u32)0x01;
|
||||
|
||||
if (tmp == 0x00)
|
||||
{
|
||||
faultaddress = SCB->MMFAR;
|
||||
}
|
||||
else
|
||||
{
|
||||
faultaddress = SCB->BFAR;
|
||||
}
|
||||
return faultaddress;
|
||||
}
|
||||
|
||||
/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
|
1104
Demo/CORTEX_STM32F103_GCC_Rowley/ST Library/src/stm32f10x_rcc.c
Normal file
1104
Demo/CORTEX_STM32F103_GCC_Rowley/ST Library/src/stm32f10x_rcc.c
Normal file
File diff suppressed because it is too large
Load diff
886
Demo/CORTEX_STM32F103_GCC_Rowley/ST Library/src/stm32f10x_spi.c
Normal file
886
Demo/CORTEX_STM32F103_GCC_Rowley/ST Library/src/stm32f10x_spi.c
Normal file
|
@ -0,0 +1,886 @@
|
|||
/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
|
||||
* File Name : stm32f10x_spi.c
|
||||
* Author : MCD Application Team
|
||||
* Version : V2.0.1
|
||||
* Date : 06/13/2008
|
||||
* Description : This file provides all the SPI firmware functions.
|
||||
********************************************************************************
|
||||
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
|
||||
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
|
||||
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
|
||||
* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
|
||||
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
|
||||
*******************************************************************************/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32f10x_spi.h"
|
||||
#include "stm32f10x_rcc.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* SPI SPE mask */
|
||||
#define CR1_SPE_Set ((u16)0x0040)
|
||||
#define CR1_SPE_Reset ((u16)0xFFBF)
|
||||
|
||||
/* I2S I2SE mask */
|
||||
#define I2SCFGR_I2SE_Set ((u16)0x0400)
|
||||
#define I2SCFGR_I2SE_Reset ((u16)0xFBFF)
|
||||
|
||||
/* SPI CRCNext mask */
|
||||
#define CR1_CRCNext_Set ((u16)0x1000)
|
||||
|
||||
/* SPI CRCEN mask */
|
||||
#define CR1_CRCEN_Set ((u16)0x2000)
|
||||
#define CR1_CRCEN_Reset ((u16)0xDFFF)
|
||||
|
||||
/* SPI SSOE mask */
|
||||
#define CR2_SSOE_Set ((u16)0x0004)
|
||||
#define CR2_SSOE_Reset ((u16)0xFFFB)
|
||||
|
||||
/* SPI registers Masks */
|
||||
#define CR1_CLEAR_Mask ((u16)0x3040)
|
||||
#define I2SCFGR_CLEAR_Mask ((u16)0xF040)
|
||||
|
||||
/* SPI or I2S mode selection masks */
|
||||
#define SPI_Mode_Select ((u16)0xF7FF)
|
||||
#define I2S_Mode_Select ((u16)0x0800)
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SPI_I2S_DeInit
|
||||
* Description : Deinitializes the SPIx peripheral registers to their default
|
||||
* reset values (Affects also the I2Ss).
|
||||
* Input : - SPIx: where x can be 1, 2 or 3 to select the SPI peripheral.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void SPI_I2S_DeInit(SPI_TypeDef* SPIx)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_SPI_ALL_PERIPH(SPIx));
|
||||
|
||||
switch (*(u32*)&SPIx)
|
||||
{
|
||||
case SPI1_BASE:
|
||||
/* Enable SPI1 reset state */
|
||||
RCC_APB2PeriphResetCmd(RCC_APB2Periph_SPI1, ENABLE);
|
||||
/* Release SPI1 from reset state */
|
||||
RCC_APB2PeriphResetCmd(RCC_APB2Periph_SPI1, DISABLE);
|
||||
break;
|
||||
|
||||
case SPI2_BASE:
|
||||
/* Enable SPI2 reset state */
|
||||
RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI2, ENABLE);
|
||||
/* Release SPI2 from reset state */
|
||||
RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI2, DISABLE);
|
||||
break;
|
||||
|
||||
case SPI3_BASE:
|
||||
/* Enable SPI3 reset state */
|
||||
RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI3, ENABLE);
|
||||
/* Release SPI3 from reset state */
|
||||
RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI3, DISABLE);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SPI_Init
|
||||
* Description : Initializes the SPIx peripheral according to the specified
|
||||
* parameters in the SPI_InitStruct.
|
||||
* Input : - SPIx: where x can be 1, 2 or 3 to select the SPI peripheral.
|
||||
* - SPI_InitStruct: pointer to a SPI_InitTypeDef structure that
|
||||
* contains the configuration information for the specified
|
||||
* SPI peripheral.
|
||||
* Output : None
|
||||
* Return : None
|
||||
******************************************************************************/
|
||||
void SPI_Init(SPI_TypeDef* SPIx, SPI_InitTypeDef* SPI_InitStruct)
|
||||
{
|
||||
u16 tmpreg = 0;
|
||||
|
||||
/* check the parameters */
|
||||
assert_param(IS_SPI_ALL_PERIPH(SPIx));
|
||||
|
||||
/* Check the SPI parameters */
|
||||
assert_param(IS_SPI_DIRECTION_MODE(SPI_InitStruct->SPI_Direction));
|
||||
assert_param(IS_SPI_MODE(SPI_InitStruct->SPI_Mode));
|
||||
assert_param(IS_SPI_DATASIZE(SPI_InitStruct->SPI_DataSize));
|
||||
assert_param(IS_SPI_CPOL(SPI_InitStruct->SPI_CPOL));
|
||||
assert_param(IS_SPI_CPHA(SPI_InitStruct->SPI_CPHA));
|
||||
assert_param(IS_SPI_NSS(SPI_InitStruct->SPI_NSS));
|
||||
assert_param(IS_SPI_BAUDRATE_PRESCALER(SPI_InitStruct->SPI_BaudRatePrescaler));
|
||||
assert_param(IS_SPI_FIRST_BIT(SPI_InitStruct->SPI_FirstBit));
|
||||
assert_param(IS_SPI_CRC_POLYNOMIAL(SPI_InitStruct->SPI_CRCPolynomial));
|
||||
|
||||
/*---------------------------- SPIx CR1 Configuration ------------------------*/
|
||||
/* Get the SPIx CR1 value */
|
||||
tmpreg = SPIx->CR1;
|
||||
/* Clear BIDIMode, BIDIOE, RxONLY, SSM, SSI, LSBFirst, BR, MSTR, CPOL and CPHA bits */
|
||||
tmpreg &= CR1_CLEAR_Mask;
|
||||
/* Configure SPIx: direction, NSS management, first transmitted bit, BaudRate prescaler
|
||||
master/salve mode, CPOL and CPHA */
|
||||
/* Set BIDImode, BIDIOE and RxONLY bits according to SPI_Direction value */
|
||||
/* Set SSM, SSI and MSTR bits according to SPI_Mode and SPI_NSS values */
|
||||
/* Set LSBFirst bit according to SPI_FirstBit value */
|
||||
/* Set BR bits according to SPI_BaudRatePrescaler value */
|
||||
/* Set CPOL bit according to SPI_CPOL value */
|
||||
/* Set CPHA bit according to SPI_CPHA value */
|
||||
tmpreg |= (u16)((u32)SPI_InitStruct->SPI_Direction | SPI_InitStruct->SPI_Mode |
|
||||
SPI_InitStruct->SPI_DataSize | SPI_InitStruct->SPI_CPOL |
|
||||
SPI_InitStruct->SPI_CPHA | SPI_InitStruct->SPI_NSS |
|
||||
SPI_InitStruct->SPI_BaudRatePrescaler | SPI_InitStruct->SPI_FirstBit);
|
||||
/* Write to SPIx CR1 */
|
||||
SPIx->CR1 = tmpreg;
|
||||
|
||||
/* Activate the SPI mode (Reset I2SMOD bit in I2SCFGR register) */
|
||||
SPIx->I2SCFGR &= SPI_Mode_Select;
|
||||
|
||||
/*---------------------------- SPIx CRCPOLY Configuration --------------------*/
|
||||
/* Write to SPIx CRCPOLY */
|
||||
SPIx->CRCPR = SPI_InitStruct->SPI_CRCPolynomial;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : I2S_Init
|
||||
* Description : Initializes the SPIx peripheral according to the specified
|
||||
* parameters in the I2S_InitStruct.
|
||||
* Input : - SPIx: where x can be 2 or 3 to select the SPI peripheral
|
||||
* (configured in I2S mode).
|
||||
* - I2S_InitStruct: pointer to an I2S_InitTypeDef structure that
|
||||
* contains the configuration information for the specified
|
||||
* SPI peripheral configured in I2S mode.
|
||||
* Output : None
|
||||
* Return : None
|
||||
******************************************************************************/
|
||||
void I2S_Init(SPI_TypeDef* SPIx, I2S_InitTypeDef* I2S_InitStruct)
|
||||
{
|
||||
u16 tmpreg = 0, i2sdiv = 2, i2sodd = 0, packetlength = 1;
|
||||
u32 tmp = 0;
|
||||
RCC_ClocksTypeDef RCC_Clocks;
|
||||
|
||||
/* Check the I2S parameters */
|
||||
assert_param(IS_SPI_23_PERIPH(SPIx));
|
||||
assert_param(IS_I2S_MODE(I2S_InitStruct->I2S_Mode));
|
||||
assert_param(IS_I2S_STANDARD(I2S_InitStruct->I2S_Standard));
|
||||
assert_param(IS_I2S_DATA_FORMAT(I2S_InitStruct->I2S_DataFormat));
|
||||
assert_param(IS_I2S_MCLK_OUTPUT(I2S_InitStruct->I2S_MCLKOutput));
|
||||
assert_param(IS_I2S_AUDIO_FREQ(I2S_InitStruct->I2S_AudioFreq));
|
||||
assert_param(IS_I2S_CPOL(I2S_InitStruct->I2S_CPOL));
|
||||
|
||||
/*----------------------- SPIx I2SCFGR & I2SPR Configuration -----------------*/
|
||||
|
||||
/* Clear I2SMOD, I2SE, I2SCFG, PCMSYNC, I2SSTD, CKPOL, DATLEN and CHLEN bits */
|
||||
SPIx->I2SCFGR &= I2SCFGR_CLEAR_Mask;
|
||||
SPIx->I2SPR = 0x0002;
|
||||
|
||||
/* Get the I2SCFGR register value */
|
||||
tmpreg = SPIx->I2SCFGR;
|
||||
|
||||
/* If the default value has to be written, reinitialize i2sdiv and i2sodd*/
|
||||
if(I2S_InitStruct->I2S_AudioFreq == I2S_AudioFreq_Default)
|
||||
{
|
||||
i2sodd = (u16)0;
|
||||
i2sdiv = (u16)2;
|
||||
}
|
||||
/* If the requested audio frequency is not the default, compute the prescaler */
|
||||
else
|
||||
{
|
||||
/* Check the frame length (For the Prescaler computing) */
|
||||
if(I2S_InitStruct->I2S_DataFormat == I2S_DataFormat_16b)
|
||||
{
|
||||
/* Packet length is 16 bits */
|
||||
packetlength = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Packet length is 32 bits */
|
||||
packetlength = 2;
|
||||
}
|
||||
/* Get System Clock frequency */
|
||||
RCC_GetClocksFreq(&RCC_Clocks);
|
||||
|
||||
/* Compute the Real divider depending on the MCLK output state with a flaoting point */
|
||||
if(I2S_InitStruct->I2S_MCLKOutput == I2S_MCLKOutput_Enable)
|
||||
{
|
||||
/* MCLK output is enabled */
|
||||
tmp = (u16)(((10 * RCC_Clocks.SYSCLK_Frequency) / (256 * I2S_InitStruct->I2S_AudioFreq)) + 5);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* MCLK output is disabled */
|
||||
tmp = (u16)(((10 * RCC_Clocks.SYSCLK_Frequency) / (32 * packetlength * I2S_InitStruct->I2S_AudioFreq)) + 5);
|
||||
}
|
||||
|
||||
/* Remove the flaoting point */
|
||||
tmp = tmp/10;
|
||||
|
||||
/* Check the parity of the divider */
|
||||
i2sodd = (u16)(tmp & (u16)0x0001);
|
||||
|
||||
/* Compute the i2sdiv prescaler */
|
||||
i2sdiv = (u16)((tmp - i2sodd) / 2);
|
||||
|
||||
/* Get the Mask for the Odd bit (SPI_I2SPR[8]) register */
|
||||
i2sodd = (u16) (i2sodd << 8);
|
||||
}
|
||||
|
||||
/* Test if the divider is 1 or 0 */
|
||||
if ((i2sdiv < 2) || (i2sdiv > 0xFF))
|
||||
{
|
||||
/* Set the default values */
|
||||
i2sdiv = 2;
|
||||
i2sodd = 0;
|
||||
}
|
||||
|
||||
/* Write to SPIx I2SPR register the computed value */
|
||||
SPIx->I2SPR = (u16)(i2sdiv | i2sodd | I2S_InitStruct->I2S_MCLKOutput);
|
||||
|
||||
/* Configure the I2S with the SPI_InitStruct values */
|
||||
tmpreg |= (u16)(I2S_Mode_Select | I2S_InitStruct->I2S_Mode | \
|
||||
I2S_InitStruct->I2S_Standard | I2S_InitStruct->I2S_DataFormat | \
|
||||
I2S_InitStruct->I2S_CPOL);
|
||||
|
||||
/* Write to SPIx I2SCFGR */
|
||||
SPIx->I2SCFGR = tmpreg;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SPI_StructInit
|
||||
* Description : Fills each SPI_InitStruct member with its default value.
|
||||
* Input : - SPI_InitStruct : pointer to a SPI_InitTypeDef structure
|
||||
* which will be initialized.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void SPI_StructInit(SPI_InitTypeDef* SPI_InitStruct)
|
||||
{
|
||||
/*--------------- Reset SPI init structure parameters values -----------------*/
|
||||
/* Initialize the SPI_Direction member */
|
||||
SPI_InitStruct->SPI_Direction = SPI_Direction_2Lines_FullDuplex;
|
||||
|
||||
/* initialize the SPI_Mode member */
|
||||
SPI_InitStruct->SPI_Mode = SPI_Mode_Slave;
|
||||
|
||||
/* initialize the SPI_DataSize member */
|
||||
SPI_InitStruct->SPI_DataSize = SPI_DataSize_8b;
|
||||
|
||||
/* Initialize the SPI_CPOL member */
|
||||
SPI_InitStruct->SPI_CPOL = SPI_CPOL_Low;
|
||||
|
||||
/* Initialize the SPI_CPHA member */
|
||||
SPI_InitStruct->SPI_CPHA = SPI_CPHA_1Edge;
|
||||
|
||||
/* Initialize the SPI_NSS member */
|
||||
SPI_InitStruct->SPI_NSS = SPI_NSS_Hard;
|
||||
|
||||
/* Initialize the SPI_BaudRatePrescaler member */
|
||||
SPI_InitStruct->SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2;
|
||||
|
||||
/* Initialize the SPI_FirstBit member */
|
||||
SPI_InitStruct->SPI_FirstBit = SPI_FirstBit_MSB;
|
||||
|
||||
/* Initialize the SPI_CRCPolynomial member */
|
||||
SPI_InitStruct->SPI_CRCPolynomial = 7;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : I2S_StructInit
|
||||
* Description : Fills each I2S_InitStruct member with its default value.
|
||||
* Input : - I2S_InitStruct : pointer to a I2S_InitTypeDef structure
|
||||
* which will be initialized.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void I2S_StructInit(I2S_InitTypeDef* I2S_InitStruct)
|
||||
{
|
||||
/*--------------- Reset I2S init structure parameters values -----------------*/
|
||||
/* Initialize the I2S_Mode member */
|
||||
I2S_InitStruct->I2S_Mode = I2S_Mode_SlaveTx;
|
||||
|
||||
/* Initialize the I2S_Standard member */
|
||||
I2S_InitStruct->I2S_Standard = I2S_Standard_Phillips;
|
||||
|
||||
/* Initialize the I2S_DataFormat member */
|
||||
I2S_InitStruct->I2S_DataFormat = I2S_DataFormat_16b;
|
||||
|
||||
/* Initialize the I2S_MCLKOutput member */
|
||||
I2S_InitStruct->I2S_MCLKOutput = I2S_MCLKOutput_Disable;
|
||||
|
||||
/* Initialize the I2S_AudioFreq member */
|
||||
I2S_InitStruct->I2S_AudioFreq = I2S_AudioFreq_Default;
|
||||
|
||||
/* Initialize the I2S_CPOL member */
|
||||
I2S_InitStruct->I2S_CPOL = I2S_CPOL_Low;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SPI_Cmd
|
||||
* Description : Enables or disables the specified SPI peripheral.
|
||||
* Input : - SPIx: where x can be 1, 2 or 3 to select the SPI peripheral.
|
||||
* - NewState: new state of the SPIx peripheral.
|
||||
* This parameter can be: ENABLE or DISABLE.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void SPI_Cmd(SPI_TypeDef* SPIx, FunctionalState NewState)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_SPI_ALL_PERIPH(SPIx));
|
||||
assert_param(IS_FUNCTIONAL_STATE(NewState));
|
||||
|
||||
if (NewState != DISABLE)
|
||||
{
|
||||
/* Enable the selected SPI peripheral */
|
||||
SPIx->CR1 |= CR1_SPE_Set;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Disable the selected SPI peripheral */
|
||||
SPIx->CR1 &= CR1_SPE_Reset;
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : I2S_Cmd
|
||||
* Description : Enables or disables the specified SPI peripheral (in I2S mode).
|
||||
* Input : - SPIx: where x can be 2 or 3 to select the SPI peripheral.
|
||||
* - NewState: new state of the SPIx peripheral.
|
||||
* This parameter can be: ENABLE or DISABLE.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void I2S_Cmd(SPI_TypeDef* SPIx, FunctionalState NewState)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_SPI_23_PERIPH(SPIx));
|
||||
assert_param(IS_FUNCTIONAL_STATE(NewState));
|
||||
|
||||
if (NewState != DISABLE)
|
||||
{
|
||||
/* Enable the selected SPI peripheral (in I2S mode) */
|
||||
SPIx->I2SCFGR |= I2SCFGR_I2SE_Set;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Disable the selected SPI peripheral (in I2S mode) */
|
||||
SPIx->I2SCFGR &= I2SCFGR_I2SE_Reset;
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SPI_I2S_ITConfig
|
||||
* Description : Enables or disables the specified SPI/I2S interrupts.
|
||||
* Input : - SPIx: where x can be :
|
||||
* - 1, 2 or 3 in SPI mode
|
||||
* - 2 or 3 in I2S mode
|
||||
* - SPI_I2S_IT: specifies the SPI/I2S interrupt source to be
|
||||
* enabled or disabled.
|
||||
* This parameter can be one of the following values:
|
||||
* - SPI_I2S_IT_TXE: Tx buffer empty interrupt mask
|
||||
* - SPI_I2S_IT_RXNE: Rx buffer not empty interrupt mask
|
||||
* - SPI_I2S_IT_ERR: Error interrupt mask
|
||||
* - NewState: new state of the specified SPI/I2S interrupt.
|
||||
* This parameter can be: ENABLE or DISABLE.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void SPI_I2S_ITConfig(SPI_TypeDef* SPIx, u8 SPI_I2S_IT, FunctionalState NewState)
|
||||
{
|
||||
u16 itpos = 0, itmask = 0 ;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_SPI_ALL_PERIPH(SPIx));
|
||||
assert_param(IS_FUNCTIONAL_STATE(NewState));
|
||||
assert_param(IS_SPI_I2S_CONFIG_IT(SPI_I2S_IT));
|
||||
|
||||
/* Get the SPI/I2S IT index */
|
||||
itpos = SPI_I2S_IT >> 4;
|
||||
/* Set the IT mask */
|
||||
itmask = (u16)((u16)1 << itpos);
|
||||
|
||||
if (NewState != DISABLE)
|
||||
{
|
||||
/* Enable the selected SPI/I2S interrupt */
|
||||
SPIx->CR2 |= itmask;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Disable the selected SPI/I2S interrupt */
|
||||
SPIx->CR2 &= (u16)~itmask;
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SPI_I2S_DMACmd
|
||||
* Description : Enables or disables the SPIx/I2Sx DMA interface.
|
||||
* Input : - SPIx: where x can be :
|
||||
* - 1, 2 or 3 in SPI mode
|
||||
* - 2 or 3 in I2S mode
|
||||
* - SPI_I2S_DMAReq: specifies the SPI/I2S DMA transfer request
|
||||
* to be enabled or disabled.
|
||||
* This parameter can be any combination of the following values:
|
||||
* - SPI_I2S_DMAReq_Tx: Tx buffer DMA transfer request
|
||||
* - SPI_I2S_DMAReq_Rx: Rx buffer DMA transfer request
|
||||
* - NewState: new state of the selected SPI/I2S DMA transfer
|
||||
* request.
|
||||
* This parameter can be: ENABLE or DISABLE.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void SPI_I2S_DMACmd(SPI_TypeDef* SPIx, u16 SPI_I2S_DMAReq, FunctionalState NewState)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_SPI_ALL_PERIPH(SPIx));
|
||||
assert_param(IS_FUNCTIONAL_STATE(NewState));
|
||||
assert_param(IS_SPI_I2S_DMAREQ(SPI_I2S_DMAReq));
|
||||
|
||||
if (NewState != DISABLE)
|
||||
{
|
||||
/* Enable the selected SPI/I2S DMA requests */
|
||||
SPIx->CR2 |= SPI_I2S_DMAReq;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Disable the selected SPI/I2S DMA requests */
|
||||
SPIx->CR2 &= (u16)~SPI_I2S_DMAReq;
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SPI_I2S_SendData
|
||||
* Description : Transmits a Data through the SPIx/I2Sx peripheral.
|
||||
* Input : - SPIx: where x can be :
|
||||
* - 1, 2 or 3 in SPI mode
|
||||
* - 2 or 3 in I2S mode
|
||||
* - Data : Data to be transmitted..
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void SPI_I2S_SendData(SPI_TypeDef* SPIx, u16 Data)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_SPI_ALL_PERIPH(SPIx));
|
||||
|
||||
/* Write in the DR register the data to be sent */
|
||||
SPIx->DR = Data;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SPI_I2S_ReceiveData
|
||||
* Description : Returns the most recent received data by the SPIx/I2Sx peripheral.
|
||||
* Input : - SPIx: where x can be :
|
||||
* - 1, 2 or 3 in SPI mode
|
||||
* - 2 or 3 in I2S mode
|
||||
* Output : None
|
||||
* Return : The value of the received data.
|
||||
*******************************************************************************/
|
||||
u16 SPI_I2S_ReceiveData(SPI_TypeDef* SPIx)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_SPI_ALL_PERIPH(SPIx));
|
||||
|
||||
/* Return the data in the DR register */
|
||||
return SPIx->DR;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SPI_NSSInternalSoftwareConfig
|
||||
* Description : Configures internally by software the NSS pin for the selected
|
||||
* SPI.
|
||||
* Input : - SPIx: where x can be 1, 2 or 3 to select the SPI peripheral.
|
||||
* - SPI_NSSInternalSoft: specifies the SPI NSS internal state.
|
||||
* This parameter can be one of the following values:
|
||||
* - SPI_NSSInternalSoft_Set: Set NSS pin internally
|
||||
* - SPI_NSSInternalSoft_Reset: Reset NSS pin internally
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void SPI_NSSInternalSoftwareConfig(SPI_TypeDef* SPIx, u16 SPI_NSSInternalSoft)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_SPI_ALL_PERIPH(SPIx));
|
||||
assert_param(IS_SPI_NSS_INTERNAL(SPI_NSSInternalSoft));
|
||||
|
||||
if (SPI_NSSInternalSoft != SPI_NSSInternalSoft_Reset)
|
||||
{
|
||||
/* Set NSS pin internally by software */
|
||||
SPIx->CR1 |= SPI_NSSInternalSoft_Set;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Reset NSS pin internally by software */
|
||||
SPIx->CR1 &= SPI_NSSInternalSoft_Reset;
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SPI_SSOutputCmd
|
||||
* Description : Enables or disables the SS output for the selected SPI.
|
||||
* Input : - SPIx: where x can be 1, 2 or 3 to select the SPI peripheral.
|
||||
* - NewState: new state of the SPIx SS output.
|
||||
* This parameter can be: ENABLE or DISABLE.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void SPI_SSOutputCmd(SPI_TypeDef* SPIx, FunctionalState NewState)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_SPI_ALL_PERIPH(SPIx));
|
||||
assert_param(IS_FUNCTIONAL_STATE(NewState));
|
||||
|
||||
if (NewState != DISABLE)
|
||||
{
|
||||
/* Enable the selected SPI SS output */
|
||||
SPIx->CR2 |= CR2_SSOE_Set;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Disable the selected SPI SS output */
|
||||
SPIx->CR2 &= CR2_SSOE_Reset;
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SPI_DataSizeConfig
|
||||
* Description : Configures the data size for the selected SPI.
|
||||
* Input : - SPIx: where x can be 1, 2 or 3 to select the SPI peripheral.
|
||||
* - SPI_DataSize: specifies the SPI data size.
|
||||
* This parameter can be one of the following values:
|
||||
* - SPI_DataSize_16b: Set data frame format to 16bit
|
||||
* - SPI_DataSize_8b: Set data frame format to 8bit
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void SPI_DataSizeConfig(SPI_TypeDef* SPIx, u16 SPI_DataSize)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_SPI_ALL_PERIPH(SPIx));
|
||||
assert_param(IS_SPI_DATASIZE(SPI_DataSize));
|
||||
|
||||
/* Clear DFF bit */
|
||||
SPIx->CR1 &= (u16)~SPI_DataSize_16b;
|
||||
/* Set new DFF bit value */
|
||||
SPIx->CR1 |= SPI_DataSize;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SPI_TransmitCRC
|
||||
* Description : Transmit the SPIx CRC value.
|
||||
* Input : - SPIx: where x can be 1, 2 or 3 to select the SPI peripheral.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void SPI_TransmitCRC(SPI_TypeDef* SPIx)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_SPI_ALL_PERIPH(SPIx));
|
||||
|
||||
/* Enable the selected SPI CRC transmission */
|
||||
SPIx->CR1 |= CR1_CRCNext_Set;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SPI_CalculateCRC
|
||||
* Description : Enables or disables the CRC value calculation of the
|
||||
* transfered bytes.
|
||||
* Input : - SPIx: where x can be 1, 2 or 3 to select the SPI peripheral.
|
||||
* - NewState: new state of the SPIx CRC value calculation.
|
||||
* This parameter can be: ENABLE or DISABLE.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void SPI_CalculateCRC(SPI_TypeDef* SPIx, FunctionalState NewState)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_SPI_ALL_PERIPH(SPIx));
|
||||
assert_param(IS_FUNCTIONAL_STATE(NewState));
|
||||
|
||||
if (NewState != DISABLE)
|
||||
{
|
||||
/* Enable the selected SPI CRC calculation */
|
||||
SPIx->CR1 |= CR1_CRCEN_Set;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Disable the selected SPI CRC calculation */
|
||||
SPIx->CR1 &= CR1_CRCEN_Reset;
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SPI_GetCRC
|
||||
* Description : Returns the transmit or the receive CRC register value for
|
||||
* the specified SPI.
|
||||
* Input : - SPIx: where x can be 1, 2 or 3 to select the SPI peripheral.
|
||||
* - SPI_CRC: specifies the CRC register to be read.
|
||||
* This parameter can be one of the following values:
|
||||
* - SPI_CRC_Tx: Selects Tx CRC register
|
||||
* - SPI_CRC_Rx: Selects Rx CRC register
|
||||
* Output : None
|
||||
* Return : The selected CRC register value..
|
||||
*******************************************************************************/
|
||||
u16 SPI_GetCRC(SPI_TypeDef* SPIx, u8 SPI_CRC)
|
||||
{
|
||||
u16 crcreg = 0;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_SPI_ALL_PERIPH(SPIx));
|
||||
assert_param(IS_SPI_CRC(SPI_CRC));
|
||||
|
||||
if (SPI_CRC != SPI_CRC_Rx)
|
||||
{
|
||||
/* Get the Tx CRC register */
|
||||
crcreg = SPIx->TXCRCR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Get the Rx CRC register */
|
||||
crcreg = SPIx->RXCRCR;
|
||||
}
|
||||
|
||||
/* Return the selected CRC register */
|
||||
return crcreg;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SPI_GetCRCPolynomial
|
||||
* Description : Returns the CRC Polynomial register value for the specified SPI.
|
||||
* Input : - SPIx: where x can be 1, 2 or 3 to select the SPI peripheral.
|
||||
* Output : None
|
||||
* Return : The CRC Polynomial register value.
|
||||
*******************************************************************************/
|
||||
u16 SPI_GetCRCPolynomial(SPI_TypeDef* SPIx)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_SPI_ALL_PERIPH(SPIx));
|
||||
|
||||
/* Return the CRC polynomial register */
|
||||
return SPIx->CRCPR;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SPI_BiDirectionalLineConfig
|
||||
* Description : Selects the data transfer direction in bi-directional mode
|
||||
* for the specified SPI.
|
||||
* Input : - SPIx: where x can be 1, 2 or 3 to select the SPI peripheral.
|
||||
* - SPI_Direction: specifies the data transfer direction in
|
||||
* bi-directional mode.
|
||||
* This parameter can be one of the following values:
|
||||
* - SPI_Direction_Tx: Selects Tx transmission direction
|
||||
* - SPI_Direction_Rx: Selects Rx receive direction
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void SPI_BiDirectionalLineConfig(SPI_TypeDef* SPIx, u16 SPI_Direction)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_SPI_ALL_PERIPH(SPIx));
|
||||
assert_param(IS_SPI_DIRECTION(SPI_Direction));
|
||||
|
||||
if (SPI_Direction == SPI_Direction_Tx)
|
||||
{
|
||||
/* Set the Tx only mode */
|
||||
SPIx->CR1 |= SPI_Direction_Tx;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Set the Rx only mode */
|
||||
SPIx->CR1 &= SPI_Direction_Rx;
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SPI_I2S_GetFlagStatus
|
||||
* Description : Checks whether the specified SPI/I2S flag is set or not.
|
||||
* Input : - SPIx: where x can be :
|
||||
* - 1, 2 or 3 in SPI mode
|
||||
* - 2 or 3 in I2S mode
|
||||
* - SPI_I2S_FLAG: specifies the SPI/I2S flag to check.
|
||||
* This parameter can be one of the following values:
|
||||
* - SPI_I2S_FLAG_TXE: Transmit buffer empty flag.
|
||||
* - SPI_I2S_FLAG_RXNE: Receive buffer not empty flag.
|
||||
* - SPI_I2S_FLAG_BSY: Busy flag.
|
||||
* - SPI_I2S_FLAG_OVR: Overrun flag.
|
||||
* - SPI_FLAG_MODF: Mode Fault flag.
|
||||
* - SPI_FLAG_CRCERR: CRC Error flag.
|
||||
* - I2S_FLAG_UDR: Underrun Error flag.
|
||||
* - I2S_FLAG_CHSIDE: Channel Side flag.
|
||||
* Output : None
|
||||
* Return : The new state of SPI_I2S_FLAG (SET or RESET).
|
||||
*******************************************************************************/
|
||||
FlagStatus SPI_I2S_GetFlagStatus(SPI_TypeDef* SPIx, u16 SPI_I2S_FLAG)
|
||||
{
|
||||
FlagStatus bitstatus = RESET;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_SPI_ALL_PERIPH(SPIx));
|
||||
assert_param(IS_SPI_I2S_GET_FLAG(SPI_I2S_FLAG));
|
||||
|
||||
/* Check the status of the specified SPI/I2S flag */
|
||||
if ((SPIx->SR & SPI_I2S_FLAG) != (u16)RESET)
|
||||
{
|
||||
/* SPI_I2S_FLAG is set */
|
||||
bitstatus = SET;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* SPI_I2S_FLAG is reset */
|
||||
bitstatus = RESET;
|
||||
}
|
||||
/* Return the SPI_I2S_FLAG status */
|
||||
return bitstatus;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SPI_I2S_ClearFlag
|
||||
* Description : Clears the SPIx/I2Sx pending flags.
|
||||
* Input : - SPIx: where x can be :
|
||||
* - 1, 2 or 3 in SPI mode
|
||||
* - 2 or 3 in I2S mode
|
||||
* - SPI_I2S_FLAG: specifies the SPI/I2S flag to clear.
|
||||
* This parameter can be one of the following values:
|
||||
* - SPI_I2S_FLAG_OVR: Overrun flag
|
||||
* - SPI_FLAG_MODF: Mode Fault flag.
|
||||
* - SPI_FLAG_CRCERR: CRC Error flag.
|
||||
* - I2S_FLAG_UDR: Underrun Error flag.
|
||||
* Note: Before clearing OVR flag, it is mandatory to read
|
||||
* SPI_I2S_DR register, so that the last data is not lost.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void SPI_I2S_ClearFlag(SPI_TypeDef* SPIx, u16 SPI_I2S_FLAG)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_SPI_ALL_PERIPH(SPIx));
|
||||
assert_param(IS_SPI_I2S_CLEAR_FLAG(SPI_I2S_FLAG));
|
||||
|
||||
/* SPI_FLAG_MODF flag clear */
|
||||
if(SPI_I2S_FLAG == SPI_FLAG_MODF)
|
||||
{
|
||||
/* Read SR register */
|
||||
(void)SPIx->SR;
|
||||
|
||||
/* Write on CR1 register */
|
||||
SPIx->CR1 |= CR1_SPE_Set;
|
||||
}
|
||||
/* SPI_I2S_FLAG_OVR flag or I2S_FLAG_UDR flag clear */
|
||||
else if ((SPI_I2S_FLAG == SPI_I2S_FLAG_OVR) || (SPI_I2S_FLAG == I2S_FLAG_UDR))
|
||||
{
|
||||
/* Read SR register (Before clearing OVR flag, it is mandatory to read
|
||||
SPI_I2S_DR register)*/
|
||||
(void)SPIx->SR;
|
||||
}
|
||||
else /* SPI_FLAG_CRCERR flag clear */
|
||||
{
|
||||
/* Clear the selected SPI flag */
|
||||
SPIx->SR = (u16)~SPI_I2S_FLAG;
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SPI_I2S_GetITStatus
|
||||
* Description : Checks whether the specified SPI/I2S interrupt has occurred or not.
|
||||
* Input : - SPIx: where x can be :
|
||||
* - 1, 2 or 3 in SPI mode
|
||||
* - 2 or 3 in I2S mode
|
||||
* - SPI_I2S_IT: specifies the SPI/I2S interrupt source to check.
|
||||
* This parameter can be one of the following values:
|
||||
* - SPI_I2S_IT_TXE: Transmit buffer empty interrupt.
|
||||
* - SPI_I2S_IT_RXNE: Receive buffer not empty interrupt.
|
||||
* - SPI_I2S_IT_OVR: Overrun interrupt.
|
||||
* - SPI_IT_MODF: Mode Fault interrupt.
|
||||
* - SPI_IT_CRCERR: CRC Error interrupt.
|
||||
* - I2S_IT_UDR: Underrun Error interrupt.
|
||||
* Output : None
|
||||
* Return : The new state of SPI_I2S_IT (SET or RESET).
|
||||
*******************************************************************************/
|
||||
ITStatus SPI_I2S_GetITStatus(SPI_TypeDef* SPIx, u8 SPI_I2S_IT)
|
||||
{
|
||||
ITStatus bitstatus = RESET;
|
||||
u16 itpos = 0, itmask = 0, enablestatus = 0;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_SPI_ALL_PERIPH(SPIx));
|
||||
assert_param(IS_SPI_I2S_GET_IT(SPI_I2S_IT));
|
||||
|
||||
/* Get the SPI/I2S IT index */
|
||||
itpos = (u16)((u16)0x01 << (SPI_I2S_IT & (u8)0x0F));
|
||||
|
||||
/* Get the SPI/I2S IT mask */
|
||||
itmask = SPI_I2S_IT >> 4;
|
||||
/* Set the IT mask */
|
||||
itmask = (u16)((u16)0x01 << itmask);
|
||||
/* Get the SPI_I2S_IT enable bit status */
|
||||
enablestatus = (SPIx->CR2 & itmask) ;
|
||||
|
||||
/* Check the status of the specified SPI/I2S interrupt */
|
||||
if (((SPIx->SR & itpos) != (u16)RESET) && enablestatus)
|
||||
{
|
||||
/* SPI_I2S_IT is set */
|
||||
bitstatus = SET;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* SPI_I2S_IT is reset */
|
||||
bitstatus = RESET;
|
||||
}
|
||||
/* Return the SPI_I2S_IT status */
|
||||
return bitstatus;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SPI_I2S_ClearITPendingBit
|
||||
* Description : Clears the SPIx/I2Sx interrupt pending bits.
|
||||
* Input : - SPIx: where x can be :
|
||||
* - 1, 2 or 3 in SPI mode
|
||||
* - 2 or 3 in I2S mode
|
||||
* - SPI_I2S_IT: specifies the SPI/I2S interrupt pending bit to clear.
|
||||
* This parameter can be one of the following values:
|
||||
* - SPI_I2S_IT_OVR: Overrun interrupt.
|
||||
* - SPI_IT_MODF: Mode Fault interrupt.
|
||||
* - SPI_IT_CRCERR: CRC Error interrupt.
|
||||
* - I2S_IT_UDR: Underrun Error interrupt.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void SPI_I2S_ClearITPendingBit(SPI_TypeDef* SPIx, u8 SPI_I2S_IT)
|
||||
{
|
||||
u16 itpos = 0;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_SPI_ALL_PERIPH(SPIx));
|
||||
assert_param(IS_SPI_I2S_CLEAR_IT(SPI_I2S_IT));
|
||||
|
||||
/* SPI_IT_MODF pending bit clear */
|
||||
if(SPI_I2S_IT == SPI_IT_MODF)
|
||||
{
|
||||
/* Read SR register */
|
||||
(void)SPIx->SR;
|
||||
/* Write on CR1 register */
|
||||
SPIx->CR1 |= CR1_SPE_Set;
|
||||
}
|
||||
/* SPI_I2S_IT_OVR or I2S_IT_UDR pending bit clear */
|
||||
else if((SPI_I2S_IT == SPI_I2S_IT_OVR) || (SPI_I2S_IT == I2S_IT_UDR))
|
||||
{
|
||||
/* Read SR register */
|
||||
(void)(SPIx->SR);
|
||||
}
|
||||
else /* SPI_IT_CRCERR pending bit clear */
|
||||
{
|
||||
/* Get the SPI/I2S IT index */
|
||||
itpos = (u16)((u16)0x01 << (SPI_I2S_IT & (u8)0x0F));
|
||||
/* Clear the selected SPI/I2S interrupt pending bits */
|
||||
SPIx->SR = (u16)~itpos;
|
||||
}
|
||||
}
|
||||
|
||||
/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
|
|
@ -0,0 +1,181 @@
|
|||
/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
|
||||
* File Name : stm32f10x_systick.c
|
||||
* Author : MCD Application Team
|
||||
* Version : V2.0.1
|
||||
* Date : 06/13/2008
|
||||
* Description : This file provides all the SysTick firmware functions.
|
||||
********************************************************************************
|
||||
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
|
||||
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
|
||||
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
|
||||
* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
|
||||
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
|
||||
*******************************************************************************/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32f10x_systick.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* ---------------------- SysTick registers bit mask -------------------- */
|
||||
/* CTRL TICKINT Mask */
|
||||
#define CTRL_TICKINT_Set ((u32)0x00000002)
|
||||
#define CTRL_TICKINT_Reset ((u32)0xFFFFFFFD)
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SysTick_CLKSourceConfig
|
||||
* Description : Configures the SysTick clock source.
|
||||
* Input : - SysTick_CLKSource: specifies the SysTick clock source.
|
||||
* This parameter can be one of the following values:
|
||||
* - SysTick_CLKSource_HCLK_Div8: AHB clock divided by 8
|
||||
* selected as SysTick clock source.
|
||||
* - SysTick_CLKSource_HCLK: AHB clock selected as
|
||||
* SysTick clock source.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void SysTick_CLKSourceConfig(u32 SysTick_CLKSource)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_SYSTICK_CLK_SOURCE(SysTick_CLKSource));
|
||||
|
||||
if (SysTick_CLKSource == SysTick_CLKSource_HCLK)
|
||||
{
|
||||
SysTick->CTRL |= SysTick_CLKSource_HCLK;
|
||||
}
|
||||
else
|
||||
{
|
||||
SysTick->CTRL &= SysTick_CLKSource_HCLK_Div8;
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SysTick_SetReload
|
||||
* Description : Sets SysTick Reload value.
|
||||
* Input : - Reload: SysTick Reload new value.
|
||||
* This parameter must be a number between 1 and 0xFFFFFF.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void SysTick_SetReload(u32 Reload)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_SYSTICK_RELOAD(Reload));
|
||||
|
||||
SysTick->LOAD = Reload;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SysTick_CounterCmd
|
||||
* Description : Enables or disables the SysTick counter.
|
||||
* Input : - SysTick_Counter: new state of the SysTick counter.
|
||||
* This parameter can be one of the following values:
|
||||
* - SysTick_Counter_Disable: Disable counter
|
||||
* - SysTick_Counter_Enable: Enable counter
|
||||
* - SysTick_Counter_Clear: Clear counter value to 0
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void SysTick_CounterCmd(u32 SysTick_Counter)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_SYSTICK_COUNTER(SysTick_Counter));
|
||||
|
||||
if (SysTick_Counter == SysTick_Counter_Enable)
|
||||
{
|
||||
SysTick->CTRL |= SysTick_Counter_Enable;
|
||||
}
|
||||
else if (SysTick_Counter == SysTick_Counter_Disable)
|
||||
{
|
||||
SysTick->CTRL &= SysTick_Counter_Disable;
|
||||
}
|
||||
else /* SysTick_Counter == SysTick_Counter_Clear */
|
||||
{
|
||||
SysTick->VAL = SysTick_Counter_Clear;
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SysTick_ITConfig
|
||||
* Description : Enables or disables the SysTick Interrupt.
|
||||
* Input : - NewState: new state of the SysTick Interrupt.
|
||||
* This parameter can be: ENABLE or DISABLE.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void SysTick_ITConfig(FunctionalState NewState)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_FUNCTIONAL_STATE(NewState));
|
||||
|
||||
if (NewState != DISABLE)
|
||||
{
|
||||
SysTick->CTRL |= CTRL_TICKINT_Set;
|
||||
}
|
||||
else
|
||||
{
|
||||
SysTick->CTRL &= CTRL_TICKINT_Reset;
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SysTick_GetCounter
|
||||
* Description : Gets SysTick counter value.
|
||||
* Input : None
|
||||
* Output : None
|
||||
* Return : SysTick current value
|
||||
*******************************************************************************/
|
||||
u32 SysTick_GetCounter(void)
|
||||
{
|
||||
return(SysTick->VAL);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SysTick_GetFlagStatus
|
||||
* Description : Checks whether the specified SysTick flag is set or not.
|
||||
* Input : - SysTick_FLAG: specifies the flag to check.
|
||||
* This parameter can be one of the following values:
|
||||
* - SysTick_FLAG_COUNT
|
||||
* - SysTick_FLAG_SKEW
|
||||
* - SysTick_FLAG_NOREF
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
FlagStatus SysTick_GetFlagStatus(u8 SysTick_FLAG)
|
||||
{
|
||||
u32 statusreg = 0, tmp = 0 ;
|
||||
FlagStatus bitstatus = RESET;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_SYSTICK_FLAG(SysTick_FLAG));
|
||||
|
||||
/* Get the SysTick register index */
|
||||
tmp = SysTick_FLAG >> 3;
|
||||
|
||||
if (tmp == 2) /* The flag to check is in CTRL register */
|
||||
{
|
||||
statusreg = SysTick->CTRL;
|
||||
}
|
||||
else /* The flag to check is in CALIB register */
|
||||
{
|
||||
statusreg = SysTick->CALIB;
|
||||
}
|
||||
|
||||
if ((statusreg & ((u32)1 << SysTick_FLAG)) != (u32)RESET)
|
||||
{
|
||||
bitstatus = SET;
|
||||
}
|
||||
else
|
||||
{
|
||||
bitstatus = RESET;
|
||||
}
|
||||
return bitstatus;
|
||||
}
|
||||
|
||||
/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
|
|
@ -0,0 +1,989 @@
|
|||
/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
|
||||
* File Name : stm32f10x_usart.c
|
||||
* Author : MCD Application Team
|
||||
* Version : V2.0.1
|
||||
* Date : 06/13/2008
|
||||
* Description : This file provides all the USART firmware functions.
|
||||
********************************************************************************
|
||||
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
|
||||
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
|
||||
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
|
||||
* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
|
||||
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
|
||||
*******************************************************************************/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32f10x_usart.h"
|
||||
#include "stm32f10x_rcc.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* USART UE Mask */
|
||||
#define CR1_UE_Set ((u16)0x2000) /* USART Enable Mask */
|
||||
#define CR1_UE_Reset ((u16)0xDFFF) /* USART Disable Mask */
|
||||
|
||||
/* USART WakeUp Method */
|
||||
#define CR1_WAKE_Mask ((u16)0xF7FF) /* USART WakeUp Method Mask */
|
||||
|
||||
/* USART RWU Mask */
|
||||
#define CR1_RWU_Set ((u16)0x0002) /* USART mute mode Enable Mask */
|
||||
#define CR1_RWU_Reset ((u16)0xFFFD) /* USART mute mode Enable Mask */
|
||||
|
||||
#define CR1_SBK_Set ((u16)0x0001) /* USART Break Character send Mask */
|
||||
|
||||
#define CR1_CLEAR_Mask ((u16)0xE9F3) /* USART CR1 Mask */
|
||||
|
||||
#define CR2_Address_Mask ((u16)0xFFF0) /* USART address Mask */
|
||||
|
||||
/* USART LIN Mask */
|
||||
#define CR2_LINEN_Set ((u16)0x4000) /* USART LIN Enable Mask */
|
||||
#define CR2_LINEN_Reset ((u16)0xBFFF) /* USART LIN Disable Mask */
|
||||
|
||||
/* USART LIN Break detection */
|
||||
#define CR2_LBDL_Mask ((u16)0xFFDF) /* USART LIN Break detection Mask */
|
||||
|
||||
#define CR2_STOP_CLEAR_Mask ((u16)0xCFFF) /* USART CR2 STOP Bits Mask */
|
||||
#define CR2_CLOCK_CLEAR_Mask ((u16)0xF0FF) /* USART CR2 Clock Mask */
|
||||
|
||||
/* USART SC Mask */
|
||||
#define CR3_SCEN_Set ((u16)0x0020) /* USART SC Enable Mask */
|
||||
#define CR3_SCEN_Reset ((u16)0xFFDF) /* USART SC Disable Mask */
|
||||
|
||||
/* USART SC NACK Mask */
|
||||
#define CR3_NACK_Set ((u16)0x0010) /* USART SC NACK Enable Mask */
|
||||
#define CR3_NACK_Reset ((u16)0xFFEF) /* USART SC NACK Disable Mask */
|
||||
|
||||
/* USART Half-Duplex Mask */
|
||||
#define CR3_HDSEL_Set ((u16)0x0008) /* USART Half-Duplex Enable Mask */
|
||||
#define CR3_HDSEL_Reset ((u16)0xFFF7) /* USART Half-Duplex Disable Mask */
|
||||
|
||||
/* USART IrDA Mask */
|
||||
#define CR3_IRLP_Mask ((u16)0xFFFB) /* USART IrDA LowPower mode Mask */
|
||||
|
||||
#define CR3_CLEAR_Mask ((u16)0xFCFF) /* USART CR3 Mask */
|
||||
|
||||
/* USART IrDA Mask */
|
||||
#define CR3_IREN_Set ((u16)0x0002) /* USART IrDA Enable Mask */
|
||||
#define CR3_IREN_Reset ((u16)0xFFFD) /* USART IrDA Disable Mask */
|
||||
|
||||
#define GTPR_LSB_Mask ((u16)0x00FF) /* Guard Time Register LSB Mask */
|
||||
#define GTPR_MSB_Mask ((u16)0xFF00) /* Guard Time Register MSB Mask */
|
||||
|
||||
#define IT_Mask ((u16)0x001F) /* USART Interrupt Mask */
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : USART_DeInit
|
||||
* Description : Deinitializes the USARTx peripheral registers to their
|
||||
* default reset values.
|
||||
* Input : - USARTx: Select the USART or the UART peripheral.
|
||||
* This parameter can be one of the following values:
|
||||
* - USART1, USART2, USART3, UART4 or UART5.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void USART_DeInit(USART_TypeDef* USARTx)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_USART_ALL_PERIPH(USARTx));
|
||||
|
||||
switch (*(u32*)&USARTx)
|
||||
{
|
||||
case USART1_BASE:
|
||||
RCC_APB2PeriphResetCmd(RCC_APB2Periph_USART1, ENABLE);
|
||||
RCC_APB2PeriphResetCmd(RCC_APB2Periph_USART1, DISABLE);
|
||||
break;
|
||||
|
||||
case USART2_BASE:
|
||||
RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART2, ENABLE);
|
||||
RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART2, DISABLE);
|
||||
break;
|
||||
|
||||
case USART3_BASE:
|
||||
RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART3, ENABLE);
|
||||
RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART3, DISABLE);
|
||||
break;
|
||||
|
||||
case UART4_BASE:
|
||||
RCC_APB1PeriphResetCmd(RCC_APB1Periph_UART4, ENABLE);
|
||||
RCC_APB1PeriphResetCmd(RCC_APB1Periph_UART4, DISABLE);
|
||||
break;
|
||||
|
||||
case UART5_BASE:
|
||||
RCC_APB1PeriphResetCmd(RCC_APB1Periph_UART5, ENABLE);
|
||||
RCC_APB1PeriphResetCmd(RCC_APB1Periph_UART5, DISABLE);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : USART_Init
|
||||
* Description : Initializes the USARTx peripheral according to the specified
|
||||
* parameters in the USART_InitStruct .
|
||||
* Input : - USARTx: Select the USART or the UART peripheral.
|
||||
* This parameter can be one of the following values:
|
||||
* - USART1, USART2, USART3, UART4 or UART5.
|
||||
* - USART_InitStruct: pointer to a USART_InitTypeDef structure
|
||||
* that contains the configuration information for the
|
||||
* specified USART peripheral.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void USART_Init(USART_TypeDef* USARTx, USART_InitTypeDef* USART_InitStruct)
|
||||
{
|
||||
u32 tmpreg = 0x00, apbclock = 0x00;
|
||||
u32 integerdivider = 0x00;
|
||||
u32 fractionaldivider = 0x00;
|
||||
u32 usartxbase = 0;
|
||||
RCC_ClocksTypeDef RCC_ClocksStatus;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_USART_ALL_PERIPH(USARTx));
|
||||
assert_param(IS_USART_BAUDRATE(USART_InitStruct->USART_BaudRate));
|
||||
assert_param(IS_USART_WORD_LENGTH(USART_InitStruct->USART_WordLength));
|
||||
assert_param(IS_USART_STOPBITS(USART_InitStruct->USART_StopBits));
|
||||
assert_param(IS_USART_PARITY(USART_InitStruct->USART_Parity));
|
||||
assert_param(IS_USART_MODE(USART_InitStruct->USART_Mode));
|
||||
assert_param(IS_USART_HARDWARE_FLOW_CONTROL(USART_InitStruct->USART_HardwareFlowControl));
|
||||
/* The hardware flow control is available only for USART1, USART2 and USART3 */
|
||||
assert_param(IS_USART_PERIPH_HFC(USARTx, USART_InitStruct->USART_HardwareFlowControl));
|
||||
|
||||
usartxbase = (*(u32*)&USARTx);
|
||||
|
||||
/*---------------------------- USART CR2 Configuration -----------------------*/
|
||||
tmpreg = USARTx->CR2;
|
||||
/* Clear STOP[13:12] bits */
|
||||
tmpreg &= CR2_STOP_CLEAR_Mask;
|
||||
|
||||
/* Configure the USART Stop Bits, Clock, CPOL, CPHA and LastBit ------------*/
|
||||
/* Set STOP[13:12] bits according to USART_StopBits value */
|
||||
tmpreg |= (u32)USART_InitStruct->USART_StopBits;
|
||||
|
||||
/* Write to USART CR2 */
|
||||
USARTx->CR2 = (u16)tmpreg;
|
||||
|
||||
/*---------------------------- USART CR1 Configuration -----------------------*/
|
||||
tmpreg = USARTx->CR1;
|
||||
/* Clear M, PCE, PS, TE and RE bits */
|
||||
tmpreg &= CR1_CLEAR_Mask;
|
||||
|
||||
/* Configure the USART Word Length, Parity and mode ----------------------- */
|
||||
/* Set the M bits according to USART_WordLength value */
|
||||
/* Set PCE and PS bits according to USART_Parity value */
|
||||
/* Set TE and RE bits according to USART_Mode value */
|
||||
tmpreg |= (u32)USART_InitStruct->USART_WordLength | USART_InitStruct->USART_Parity |
|
||||
USART_InitStruct->USART_Mode;
|
||||
|
||||
/* Write to USART CR1 */
|
||||
USARTx->CR1 = (u16)tmpreg;
|
||||
|
||||
/*---------------------------- USART CR3 Configuration -----------------------*/
|
||||
tmpreg = USARTx->CR3;
|
||||
/* Clear CTSE and RTSE bits */
|
||||
tmpreg &= CR3_CLEAR_Mask;
|
||||
|
||||
/* Configure the USART HFC -------------------------------------------------*/
|
||||
/* Set CTSE and RTSE bits according to USART_HardwareFlowControl value */
|
||||
tmpreg |= USART_InitStruct->USART_HardwareFlowControl;
|
||||
|
||||
/* Write to USART CR3 */
|
||||
USARTx->CR3 = (u16)tmpreg;
|
||||
|
||||
/*---------------------------- USART BRR Configuration -----------------------*/
|
||||
/* Configure the USART Baud Rate -------------------------------------------*/
|
||||
RCC_GetClocksFreq(&RCC_ClocksStatus);
|
||||
if (usartxbase == USART1_BASE)
|
||||
{
|
||||
apbclock = RCC_ClocksStatus.PCLK2_Frequency;
|
||||
}
|
||||
else
|
||||
{
|
||||
apbclock = RCC_ClocksStatus.PCLK1_Frequency;
|
||||
}
|
||||
|
||||
/* Determine the integer part */
|
||||
integerdivider = ((0x19 * apbclock) / (0x04 * (USART_InitStruct->USART_BaudRate)));
|
||||
tmpreg = (integerdivider / 0x64) << 0x04;
|
||||
|
||||
/* Determine the fractional part */
|
||||
fractionaldivider = integerdivider - (0x64 * (tmpreg >> 0x04));
|
||||
tmpreg |= ((((fractionaldivider * 0x10) + 0x32) / 0x64)) & ((u8)0x0F);
|
||||
|
||||
/* Write to USART BRR */
|
||||
USARTx->BRR = (u16)tmpreg;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : USART_StructInit
|
||||
* Description : Fills each USART_InitStruct member with its default value.
|
||||
* Input : - USART_InitStruct: pointer to a USART_InitTypeDef structure
|
||||
* which will be initialized.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void USART_StructInit(USART_InitTypeDef* USART_InitStruct)
|
||||
{
|
||||
/* USART_InitStruct members default value */
|
||||
USART_InitStruct->USART_BaudRate = 9600;
|
||||
USART_InitStruct->USART_WordLength = USART_WordLength_8b;
|
||||
USART_InitStruct->USART_StopBits = USART_StopBits_1;
|
||||
USART_InitStruct->USART_Parity = USART_Parity_No ;
|
||||
USART_InitStruct->USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
|
||||
USART_InitStruct->USART_HardwareFlowControl = USART_HardwareFlowControl_None;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : USART_ClockInit
|
||||
* Description : Initializes the USARTx peripheral Clock according to the
|
||||
* specified parameters in the USART_ClockInitStruct .
|
||||
* Input : - USARTx: where x can be 1, 2, 3 to select the USART peripheral.
|
||||
* Note: The Smart Card mode is not available for UART4 and UART5.
|
||||
* - USART_ClockInitStruct: pointer to a USART_ClockInitTypeDef
|
||||
* structure that contains the configuration information for
|
||||
* the specified USART peripheral.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void USART_ClockInit(USART_TypeDef* USARTx, USART_ClockInitTypeDef* USART_ClockInitStruct)
|
||||
{
|
||||
u32 tmpreg = 0x00;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_USART_123_PERIPH(USARTx));
|
||||
assert_param(IS_USART_CLOCK(USART_ClockInitStruct->USART_Clock));
|
||||
assert_param(IS_USART_CPOL(USART_ClockInitStruct->USART_CPOL));
|
||||
assert_param(IS_USART_CPHA(USART_ClockInitStruct->USART_CPHA));
|
||||
assert_param(IS_USART_LASTBIT(USART_ClockInitStruct->USART_LastBit));
|
||||
|
||||
/*---------------------------- USART CR2 Configuration -----------------------*/
|
||||
tmpreg = USARTx->CR2;
|
||||
/* Clear CLKEN, CPOL, CPHA and LBCL bits */
|
||||
tmpreg &= CR2_CLOCK_CLEAR_Mask;
|
||||
|
||||
/* Configure the USART Clock, CPOL, CPHA and LastBit ------------*/
|
||||
/* Set CLKEN bit according to USART_Clock value */
|
||||
/* Set CPOL bit according to USART_CPOL value */
|
||||
/* Set CPHA bit according to USART_CPHA value */
|
||||
/* Set LBCL bit according to USART_LastBit value */
|
||||
tmpreg |= (u32)USART_ClockInitStruct->USART_Clock | USART_ClockInitStruct->USART_CPOL |
|
||||
USART_ClockInitStruct->USART_CPHA | USART_ClockInitStruct->USART_LastBit;
|
||||
|
||||
/* Write to USART CR2 */
|
||||
USARTx->CR2 = (u16)tmpreg;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : USART_ClockStructInit
|
||||
* Description : Fills each USART_ClockInitStruct member with its default value.
|
||||
* Input : - USART_ClockInitStruct: pointer to a USART_ClockInitTypeDef
|
||||
* structure which will be initialized.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void USART_ClockStructInit(USART_ClockInitTypeDef* USART_ClockInitStruct)
|
||||
{
|
||||
/* USART_ClockInitStruct members default value */
|
||||
USART_ClockInitStruct->USART_Clock = USART_Clock_Disable;
|
||||
USART_ClockInitStruct->USART_CPOL = USART_CPOL_Low;
|
||||
USART_ClockInitStruct->USART_CPHA = USART_CPHA_1Edge;
|
||||
USART_ClockInitStruct->USART_LastBit = USART_LastBit_Disable;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : USART_Cmd
|
||||
* Description : Enables or disables the specified USART peripheral.
|
||||
* Input : - USARTx: Select the USART or the UART peripheral.
|
||||
* This parameter can be one of the following values:
|
||||
* - USART1, USART2, USART3, UART4 or UART5.
|
||||
* : - NewState: new state of the USARTx peripheral.
|
||||
* This parameter can be: ENABLE or DISABLE.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void USART_Cmd(USART_TypeDef* USARTx, FunctionalState NewState)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_USART_ALL_PERIPH(USARTx));
|
||||
assert_param(IS_FUNCTIONAL_STATE(NewState));
|
||||
|
||||
if (NewState != DISABLE)
|
||||
{
|
||||
/* Enable the selected USART by setting the UE bit in the CR1 register */
|
||||
USARTx->CR1 |= CR1_UE_Set;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Disable the selected USART by clearing the UE bit in the CR1 register */
|
||||
USARTx->CR1 &= CR1_UE_Reset;
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : USART_ITConfig
|
||||
* Description : Enables or disables the specified USART interrupts.
|
||||
* Input : - USARTx: Select the USART or the UART peripheral.
|
||||
* This parameter can be one of the following values:
|
||||
* - USART1, USART2, USART3, UART4 or UART5.
|
||||
* - USART_IT: specifies the USART interrupt sources to be
|
||||
* enabled or disabled.
|
||||
* This parameter can be one of the following values:
|
||||
* - USART_IT_CTS: CTS change interrupt (not available for
|
||||
* UART4 and UART5)
|
||||
* - USART_IT_LBD: LIN Break detection interrupt
|
||||
* - USART_IT_TXE: Tansmit Data Register empty interrupt
|
||||
* - USART_IT_TC: Transmission complete interrupt
|
||||
* - USART_IT_RXNE: Receive Data register not empty
|
||||
* interrupt
|
||||
* - USART_IT_IDLE: Idle line detection interrupt
|
||||
* - USART_IT_PE: Parity Error interrupt
|
||||
* - USART_IT_ERR: Error interrupt(Frame error, noise
|
||||
* error, overrun error)
|
||||
* - NewState: new state of the specified USARTx interrupts.
|
||||
* This parameter can be: ENABLE or DISABLE.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void USART_ITConfig(USART_TypeDef* USARTx, u16 USART_IT, FunctionalState NewState)
|
||||
{
|
||||
u32 usartreg = 0x00, itpos = 0x00, itmask = 0x00;
|
||||
u32 usartxbase = 0x00;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_USART_ALL_PERIPH(USARTx));
|
||||
assert_param(IS_USART_CONFIG_IT(USART_IT));
|
||||
assert_param(IS_USART_PERIPH_IT(USARTx, USART_IT)); /* The CTS interrupt is not available for UART4 and UART5 */
|
||||
assert_param(IS_FUNCTIONAL_STATE(NewState));
|
||||
|
||||
usartxbase = (*(u32*)&(USARTx));
|
||||
|
||||
/* Get the USART register index */
|
||||
usartreg = (((u8)USART_IT) >> 0x05);
|
||||
|
||||
/* Get the interrupt position */
|
||||
itpos = USART_IT & IT_Mask;
|
||||
|
||||
itmask = (((u32)0x01) << itpos);
|
||||
|
||||
if (usartreg == 0x01) /* The IT is in CR1 register */
|
||||
{
|
||||
usartxbase += 0x0C;
|
||||
}
|
||||
else if (usartreg == 0x02) /* The IT is in CR2 register */
|
||||
{
|
||||
usartxbase += 0x10;
|
||||
}
|
||||
else /* The IT is in CR3 register */
|
||||
{
|
||||
usartxbase += 0x14;
|
||||
}
|
||||
if (NewState != DISABLE)
|
||||
{
|
||||
*(vu32*)usartxbase |= itmask;
|
||||
}
|
||||
else
|
||||
{
|
||||
*(vu32*)usartxbase &= ~itmask;
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : USART_DMACmd
|
||||
* Description : Enables or disables the USART’s DMA interface.
|
||||
* Input : - USARTx: Select the USART or the UART peripheral.
|
||||
* This parameter can be one of the following values:
|
||||
* - USART1, USART2, USART3 or UART4.
|
||||
* Note: The DMA mode is not available for UART5.
|
||||
* - USART_DMAReq: specifies the DMA request.
|
||||
* This parameter can be any combination of the following values:
|
||||
* - USART_DMAReq_Tx: USART DMA transmit request
|
||||
* - USART_DMAReq_Rx: USART DMA receive request
|
||||
* - NewState: new state of the DMA Request sources.
|
||||
* This parameter can be: ENABLE or DISABLE.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void USART_DMACmd(USART_TypeDef* USARTx, u16 USART_DMAReq, FunctionalState NewState)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_USART_1234_PERIPH(USARTx));
|
||||
assert_param(IS_USART_DMAREQ(USART_DMAReq));
|
||||
assert_param(IS_FUNCTIONAL_STATE(NewState));
|
||||
|
||||
if (NewState != DISABLE)
|
||||
{
|
||||
/* Enable the DMA transfer for selected requests by setting the DMAT and/or
|
||||
DMAR bits in the USART CR3 register */
|
||||
USARTx->CR3 |= USART_DMAReq;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Disable the DMA transfer for selected requests by clearing the DMAT and/or
|
||||
DMAR bits in the USART CR3 register */
|
||||
USARTx->CR3 &= (u16)~USART_DMAReq;
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : USART_SetAddress
|
||||
* Description : Sets the address of the USART node.
|
||||
* Input : - USARTx: Select the USART or the UART peripheral.
|
||||
* This parameter can be one of the following values:
|
||||
* - USART1, USART2, USART3, UART4 or UART5.
|
||||
* - USART_Address: Indicates the address of the USART node.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void USART_SetAddress(USART_TypeDef* USARTx, u8 USART_Address)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_USART_ALL_PERIPH(USARTx));
|
||||
assert_param(IS_USART_ADDRESS(USART_Address));
|
||||
|
||||
/* Clear the USART address */
|
||||
USARTx->CR2 &= CR2_Address_Mask;
|
||||
/* Set the USART address node */
|
||||
USARTx->CR2 |= USART_Address;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : USART_WakeUpConfig
|
||||
* Description : Selects the USART WakeUp method.
|
||||
* Input : - USARTx: Select the USART or the UART peripheral.
|
||||
* This parameter can be one of the following values:
|
||||
* - USART1, USART2, USART3, UART4 or UART5.
|
||||
* - USART_WakeUp: specifies the USART wakeup method.
|
||||
* This parameter can be one of the following values:
|
||||
* - USART_WakeUp_IdleLine: WakeUp by an idle line detection
|
||||
* - USART_WakeUp_AddressMark: WakeUp by an address mark
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void USART_WakeUpConfig(USART_TypeDef* USARTx, u16 USART_WakeUp)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_USART_ALL_PERIPH(USARTx));
|
||||
assert_param(IS_USART_WAKEUP(USART_WakeUp));
|
||||
|
||||
USARTx->CR1 &= CR1_WAKE_Mask;
|
||||
USARTx->CR1 |= USART_WakeUp;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : USART_ReceiverWakeUpCmd
|
||||
* Description : Determines if the USART is in mute mode or not.
|
||||
* Input : - USARTx: Select the USART or the UART peripheral.
|
||||
* This parameter can be one of the following values:
|
||||
* - USART1, USART2, USART3, UART4 or UART5.
|
||||
* - NewState: new state of the USART mute mode.
|
||||
* This parameter can be: ENABLE or DISABLE.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void USART_ReceiverWakeUpCmd(USART_TypeDef* USARTx, FunctionalState NewState)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_USART_ALL_PERIPH(USARTx));
|
||||
assert_param(IS_FUNCTIONAL_STATE(NewState));
|
||||
|
||||
if (NewState != DISABLE)
|
||||
{
|
||||
/* Enable the USART mute mode by setting the RWU bit in the CR1 register */
|
||||
USARTx->CR1 |= CR1_RWU_Set;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Disable the USART mute mode by clearing the RWU bit in the CR1 register */
|
||||
USARTx->CR1 &= CR1_RWU_Reset;
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : USART_LINBreakDetectLengthConfig
|
||||
* Description : Sets the USART LIN Break detection length.
|
||||
* Input : - USARTx: Select the USART or the UART peripheral.
|
||||
* This parameter can be one of the following values:
|
||||
* - USART1, USART2, USART3, UART4 or UART5.
|
||||
* - USART_LINBreakDetectLength: specifies the LIN break
|
||||
* detection length.
|
||||
* This parameter can be one of the following values:
|
||||
* - USART_LINBreakDetectLength_10b: 10-bit break detection
|
||||
* - USART_LINBreakDetectLength_11b: 11-bit break detection
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void USART_LINBreakDetectLengthConfig(USART_TypeDef* USARTx, u16 USART_LINBreakDetectLength)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_USART_ALL_PERIPH(USARTx));
|
||||
assert_param(IS_USART_LIN_BREAK_DETECT_LENGTH(USART_LINBreakDetectLength));
|
||||
|
||||
USARTx->CR2 &= CR2_LBDL_Mask;
|
||||
USARTx->CR2 |= USART_LINBreakDetectLength;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : USART_LINCmd
|
||||
* Description : Enables or disables the USART’s LIN mode.
|
||||
* Input : - USARTx: Select the USART or the UART peripheral.
|
||||
* This parameter can be one of the following values:
|
||||
* - USART1, USART2, USART3, UART4 or UART5.
|
||||
* - NewState: new state of the USART LIN mode.
|
||||
* This parameter can be: ENABLE or DISABLE.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void USART_LINCmd(USART_TypeDef* USARTx, FunctionalState NewState)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_USART_ALL_PERIPH(USARTx));
|
||||
assert_param(IS_FUNCTIONAL_STATE(NewState));
|
||||
|
||||
if (NewState != DISABLE)
|
||||
{
|
||||
/* Enable the LIN mode by setting the LINEN bit in the CR2 register */
|
||||
USARTx->CR2 |= CR2_LINEN_Set;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Disable the LIN mode by clearing the LINEN bit in the CR2 register */
|
||||
USARTx->CR2 &= CR2_LINEN_Reset;
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : USART_SendData
|
||||
* Description : Transmits single data through the USARTx peripheral.
|
||||
* Input : - USARTx: Select the USART or the UART peripheral.
|
||||
* This parameter can be one of the following values:
|
||||
* - USART1, USART2, USART3, UART4 or UART5.
|
||||
* - Data: the data to transmit.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void USART_SendData(USART_TypeDef* USARTx, u16 Data)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_USART_ALL_PERIPH(USARTx));
|
||||
assert_param(IS_USART_DATA(Data));
|
||||
|
||||
/* Transmit Data */
|
||||
USARTx->DR = (Data & (u16)0x01FF);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : USART_ReceiveData
|
||||
* Description : Returns the most recent received data by the USARTx peripheral.
|
||||
* Input : - USARTx: Select the USART or the UART peripheral.
|
||||
* This parameter can be one of the following values:
|
||||
* - USART1, USART2, USART3, UART4 or UART5.
|
||||
* Output : None
|
||||
* Return : The received data.
|
||||
*******************************************************************************/
|
||||
u16 USART_ReceiveData(USART_TypeDef* USARTx)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_USART_ALL_PERIPH(USARTx));
|
||||
|
||||
/* Receive Data */
|
||||
return (u16)(USARTx->DR & (u16)0x01FF);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : USART_SendBreak
|
||||
* Description : Transmits break characters.
|
||||
* Input : - USARTx: Select the USART or the UART peripheral.
|
||||
* This parameter can be one of the following values:
|
||||
* - USART1, USART2, USART3, UART4 or UART5.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void USART_SendBreak(USART_TypeDef* USARTx)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_USART_ALL_PERIPH(USARTx));
|
||||
|
||||
/* Send break characters */
|
||||
USARTx->CR1 |= CR1_SBK_Set;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : USART_SetGuardTime
|
||||
* Description : Sets the specified USART guard time.
|
||||
* Input : - USARTx: where x can be 1, 2 or 3 to select the USART
|
||||
* peripheral.
|
||||
* Note: The guard time bits are not available for UART4 and UART5.
|
||||
* - USART_GuardTime: specifies the guard time.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void USART_SetGuardTime(USART_TypeDef* USARTx, u8 USART_GuardTime)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_USART_123_PERIPH(USARTx));
|
||||
|
||||
/* Clear the USART Guard time */
|
||||
USARTx->GTPR &= GTPR_LSB_Mask;
|
||||
/* Set the USART guard time */
|
||||
USARTx->GTPR |= (u16)((u16)USART_GuardTime << 0x08);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : USART_SetPrescaler
|
||||
* Description : Sets the system clock prescaler.
|
||||
* Input : - USARTx: Select the USART or the UART peripheral.
|
||||
* This parameter can be one of the following values:
|
||||
* - USART1, USART2, USART3, UART4 or UART5.
|
||||
* Note: The function is used for IrDA mode with UART4 and UART5.
|
||||
* - USART_Prescaler: specifies the prescaler clock.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void USART_SetPrescaler(USART_TypeDef* USARTx, u8 USART_Prescaler)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_USART_ALL_PERIPH(USARTx));
|
||||
|
||||
/* Clear the USART prescaler */
|
||||
USARTx->GTPR &= GTPR_MSB_Mask;
|
||||
/* Set the USART prescaler */
|
||||
USARTx->GTPR |= USART_Prescaler;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : USART_SmartCardCmd
|
||||
* Description : Enables or disables the USART’s Smart Card mode.
|
||||
* Input : - USARTx: where x can be 1, 2 or 3 to select the USART
|
||||
* peripheral.
|
||||
* Note: The Smart Card mode is not available for UART4 and UART5.
|
||||
* - NewState: new state of the Smart Card mode.
|
||||
* This parameter can be: ENABLE or DISABLE.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void USART_SmartCardCmd(USART_TypeDef* USARTx, FunctionalState NewState)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_USART_123_PERIPH(USARTx));
|
||||
assert_param(IS_FUNCTIONAL_STATE(NewState));
|
||||
|
||||
if (NewState != DISABLE)
|
||||
{
|
||||
/* Enable the SC mode by setting the SCEN bit in the CR3 register */
|
||||
USARTx->CR3 |= CR3_SCEN_Set;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Disable the SC mode by clearing the SCEN bit in the CR3 register */
|
||||
USARTx->CR3 &= CR3_SCEN_Reset;
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : USART_SmartCardNACKCmd
|
||||
* Description : Enables or disables NACK transmission.
|
||||
* Input : - USARTx: where x can be 1, 2 or 3 to select the USART
|
||||
* peripheral.
|
||||
* Note: The Smart Card mode is not available for UART4 and UART5.
|
||||
* - NewState: new state of the NACK transmission.
|
||||
* This parameter can be: ENABLE or DISABLE.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void USART_SmartCardNACKCmd(USART_TypeDef* USARTx, FunctionalState NewState)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_USART_123_PERIPH(USARTx));
|
||||
assert_param(IS_FUNCTIONAL_STATE(NewState));
|
||||
|
||||
if (NewState != DISABLE)
|
||||
{
|
||||
/* Enable the NACK transmission by setting the NACK bit in the CR3 register */
|
||||
USARTx->CR3 |= CR3_NACK_Set;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Disable the NACK transmission by clearing the NACK bit in the CR3 register */
|
||||
USARTx->CR3 &= CR3_NACK_Reset;
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : USART_HalfDuplexCmd
|
||||
* Description : Enables or disables the USART’s Half Duplex communication.
|
||||
* Input : - USARTx: Select the USART or the UART peripheral.
|
||||
* This parameter can be one of the following values:
|
||||
* - USART1, USART2, USART3, UART4 or UART5.
|
||||
* - NewState: new state of the USART Communication.
|
||||
* This parameter can be: ENABLE or DISABLE.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void USART_HalfDuplexCmd(USART_TypeDef* USARTx, FunctionalState NewState)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_USART_ALL_PERIPH(USARTx));
|
||||
assert_param(IS_FUNCTIONAL_STATE(NewState));
|
||||
|
||||
if (NewState != DISABLE)
|
||||
{
|
||||
/* Enable the Half-Duplex mode by setting the HDSEL bit in the CR3 register */
|
||||
USARTx->CR3 |= CR3_HDSEL_Set;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Disable the Half-Duplex mode by clearing the HDSEL bit in the CR3 register */
|
||||
USARTx->CR3 &= CR3_HDSEL_Reset;
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : USART_IrDAConfig
|
||||
* Description : Configures the USART’s IrDA interface.
|
||||
* Input : - USARTx: Select the USART or the UART peripheral.
|
||||
* This parameter can be one of the following values:
|
||||
* - USART1, USART2, USART3, UART4 or UART5.
|
||||
* - USART_IrDAMode: specifies the IrDA mode.
|
||||
* This parameter can be one of the following values:
|
||||
* - USART_IrDAMode_LowPower
|
||||
* - USART_IrDAMode_Normal
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void USART_IrDAConfig(USART_TypeDef* USARTx, u16 USART_IrDAMode)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_USART_ALL_PERIPH(USARTx));
|
||||
assert_param(IS_USART_IRDA_MODE(USART_IrDAMode));
|
||||
|
||||
USARTx->CR3 &= CR3_IRLP_Mask;
|
||||
USARTx->CR3 |= USART_IrDAMode;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : USART_IrDACmd
|
||||
* Description : Enables or disables the USART’s IrDA interface.
|
||||
* Input : - USARTx: Select the USART or the UART peripheral.
|
||||
* This parameter can be one of the following values:
|
||||
* - USART1, USART2, USART3, UART4 or UART5.
|
||||
* - NewState: new state of the IrDA mode.
|
||||
* This parameter can be: ENABLE or DISABLE.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void USART_IrDACmd(USART_TypeDef* USARTx, FunctionalState NewState)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_USART_ALL_PERIPH(USARTx));
|
||||
assert_param(IS_FUNCTIONAL_STATE(NewState));
|
||||
|
||||
if (NewState != DISABLE)
|
||||
{
|
||||
/* Enable the IrDA mode by setting the IREN bit in the CR3 register */
|
||||
USARTx->CR3 |= CR3_IREN_Set;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Disable the IrDA mode by clearing the IREN bit in the CR3 register */
|
||||
USARTx->CR3 &= CR3_IREN_Reset;
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : USART_GetFlagStatus
|
||||
* Description : Checks whether the specified USART flag is set or not.
|
||||
* Input : - USARTx: Select the USART or the UART peripheral.
|
||||
* This parameter can be one of the following values:
|
||||
* - USART1, USART2, USART3, UART4 or UART5.
|
||||
* - USART_FLAG: specifies the flag to check.
|
||||
* This parameter can be one of the following values:
|
||||
* - USART_FLAG_CTS: CTS Change flag (not available for
|
||||
* UART4 and UART5)
|
||||
* - USART_FLAG_LBD: LIN Break detection flag
|
||||
* - USART_FLAG_TXE: Transmit data register empty flag
|
||||
* - USART_FLAG_TC: Transmission Complete flag
|
||||
* - USART_FLAG_RXNE: Receive data register not empty flag
|
||||
* - USART_FLAG_IDLE: Idle Line detection flag
|
||||
* - USART_FLAG_ORE: OverRun Error flag
|
||||
* - USART_FLAG_NE: Noise Error flag
|
||||
* - USART_FLAG_FE: Framing Error flag
|
||||
* - USART_FLAG_PE: Parity Error flag
|
||||
* Output : None
|
||||
* Return : The new state of USART_FLAG (SET or RESET).
|
||||
*******************************************************************************/
|
||||
FlagStatus USART_GetFlagStatus(USART_TypeDef* USARTx, u16 USART_FLAG)
|
||||
{
|
||||
FlagStatus bitstatus = RESET;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_USART_ALL_PERIPH(USARTx));
|
||||
assert_param(IS_USART_FLAG(USART_FLAG));
|
||||
assert_param(IS_USART_PERIPH_FLAG(USARTx, USART_FLAG)); /* The CTS flag is not available for UART4 and UART5 */
|
||||
|
||||
if ((USARTx->SR & USART_FLAG) != (u16)RESET)
|
||||
{
|
||||
bitstatus = SET;
|
||||
}
|
||||
else
|
||||
{
|
||||
bitstatus = RESET;
|
||||
}
|
||||
return bitstatus;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : USART_ClearFlag
|
||||
* Description : Clears the USARTx's pending flags.
|
||||
* Input : - USARTx: Select the USART or the UART peripheral.
|
||||
* This parameter can be one of the following values:
|
||||
* - USART1, USART2, USART3, UART4 or UART5.
|
||||
* - USART_FLAG: specifies the flag to clear.
|
||||
* This parameter can be any combination of the following values:
|
||||
* - USART_FLAG_CTS: CTS Change flag (not available for
|
||||
* UART4 and UART5).
|
||||
* - USART_FLAG_LBD: LIN Break detection flag.
|
||||
* - USART_FLAG_TC: Transmission Complete flag.
|
||||
* - USART_FLAG_RXNE: Receive data register not empty flag.
|
||||
* - USART_FLAG_IDLE: Idle Line detection flag.
|
||||
* - USART_FLAG_ORE: OverRun Error flag.
|
||||
* - USART_FLAG_NE: Noise Error flag.
|
||||
* - USART_FLAG_FE: Framing Error flag.
|
||||
* - USART_FLAG_PE: Parity Error flag.
|
||||
*
|
||||
* Note: - For IDLE, ORE, NE, FE and PE flags user has to read
|
||||
* the USART DR register after calling this function.
|
||||
* - TXE flag can't be cleared by this function, it's
|
||||
* cleared only by a write to the USART DR register.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void USART_ClearFlag(USART_TypeDef* USARTx, u16 USART_FLAG)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_USART_ALL_PERIPH(USARTx));
|
||||
assert_param(IS_USART_CLEAR_FLAG(USART_FLAG));
|
||||
assert_param(IS_USART_PERIPH_FLAG(USARTx, USART_FLAG)); /* The CTS flag is not available for UART4 and UART5 */
|
||||
|
||||
USARTx->SR = (u16)~USART_FLAG;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : USART_GetITStatus
|
||||
* Description : Checks whether the specified USART interrupt has occurred or not.
|
||||
* Input : - USARTx: Select the USART or the UART peripheral.
|
||||
* This parameter can be one of the following values:
|
||||
* - USART1, USART2, USART3, UART4 or UART5.
|
||||
* - USART_IT: specifies the USART interrupt source to check.
|
||||
* This parameter can be one of the following values:
|
||||
* - USART_IT_CTS: CTS change interrupt (not available for
|
||||
* UART4 and UART5)
|
||||
* - USART_IT_LBD: LIN Break detection interrupt
|
||||
* - USART_IT_TXE: Tansmit Data Register empty interrupt
|
||||
* - USART_IT_TC: Transmission complete interrupt
|
||||
* - USART_IT_RXNE: Receive Data register not empty
|
||||
* interrupt
|
||||
* - USART_IT_IDLE: Idle line detection interrupt
|
||||
* - USART_IT_ORE: OverRun Error interrupt
|
||||
* - USART_IT_NE: Noise Error interrupt
|
||||
* - USART_IT_FE: Framing Error interrupt
|
||||
* - USART_IT_PE: Parity Error interrupt
|
||||
* Output : None
|
||||
* Return : The new state of USART_IT (SET or RESET).
|
||||
*******************************************************************************/
|
||||
ITStatus USART_GetITStatus(USART_TypeDef* USARTx, u16 USART_IT)
|
||||
{
|
||||
u32 bitpos = 0x00, itmask = 0x00, usartreg = 0x00;
|
||||
ITStatus bitstatus = RESET;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_USART_ALL_PERIPH(USARTx));
|
||||
assert_param(IS_USART_IT(USART_IT));
|
||||
assert_param(IS_USART_PERIPH_IT(USARTx, USART_IT)); /* The CTS interrupt is not available for UART4 and UART5 */
|
||||
|
||||
/* Get the USART register index */
|
||||
usartreg = (((u8)USART_IT) >> 0x05);
|
||||
|
||||
/* Get the interrupt position */
|
||||
itmask = USART_IT & IT_Mask;
|
||||
|
||||
itmask = (u32)0x01 << itmask;
|
||||
|
||||
if (usartreg == 0x01) /* The IT is in CR1 register */
|
||||
{
|
||||
itmask &= USARTx->CR1;
|
||||
}
|
||||
else if (usartreg == 0x02) /* The IT is in CR2 register */
|
||||
{
|
||||
itmask &= USARTx->CR2;
|
||||
}
|
||||
else /* The IT is in CR3 register */
|
||||
{
|
||||
itmask &= USARTx->CR3;
|
||||
}
|
||||
|
||||
bitpos = USART_IT >> 0x08;
|
||||
|
||||
bitpos = (u32)0x01 << bitpos;
|
||||
bitpos &= USARTx->SR;
|
||||
|
||||
if ((itmask != (u16)RESET)&&(bitpos != (u16)RESET))
|
||||
{
|
||||
bitstatus = SET;
|
||||
}
|
||||
else
|
||||
{
|
||||
bitstatus = RESET;
|
||||
}
|
||||
|
||||
return bitstatus;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : USART_ClearITPendingBit
|
||||
* Description : Clears the USARTx’s interrupt pending bits.
|
||||
* Input : - USARTx: Select the USART or the UART peripheral.
|
||||
* This parameter can be one of the following values:
|
||||
* - USART1, USART2, USART3, UART4 or UART5.
|
||||
* - USART_IT: specifies the interrupt pending bit to clear.
|
||||
* This parameter can be one of the following values:
|
||||
* - USART_IT_CTS: CTS change interrupt (not available for
|
||||
* UART4 and UART5)
|
||||
* - USART_IT_LBD: LIN Break detection interrupt
|
||||
* - USART_IT_TC: Transmission complete interrupt.
|
||||
* - USART_IT_RXNE: Receive Data register not empty interrupt.
|
||||
* - USART_IT_IDLE: Idle line detection interrupt.
|
||||
* - USART_IT_ORE: OverRun Error interrupt.
|
||||
* - USART_IT_NE: Noise Error interrupt.
|
||||
* - USART_IT_FE: Framing Error interrupt.
|
||||
* - USART_IT_PE: Parity Error interrupt.
|
||||
*
|
||||
* Note: - For IDLE, ORE, NE, FE and PE pending bits user has to
|
||||
* read the USART DR register after calling this function.
|
||||
* - TXE pending bit can't be cleared by this function, it's
|
||||
* cleared only by a write to the USART DR register.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void USART_ClearITPendingBit(USART_TypeDef* USARTx, u16 USART_IT)
|
||||
{
|
||||
u16 bitpos = 0x00, itmask = 0x00;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_USART_ALL_PERIPH(USARTx));
|
||||
assert_param(IS_USART_CLEAR_IT(USART_IT));
|
||||
assert_param(IS_USART_PERIPH_IT(USARTx, USART_IT)); /* The CTS interrupt is not available for UART4 and UART5 */
|
||||
|
||||
bitpos = USART_IT >> 0x08;
|
||||
|
||||
itmask = (u16)((u16)0x01 << bitpos);
|
||||
USARTx->SR = (u16)~itmask;
|
||||
}
|
||||
|
||||
/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
|
Loading…
Add table
Add a link
Reference in a new issue