mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2025-08-13 14:48:33 -04:00
Add FreeRTOS-Plus directory.
This commit is contained in:
parent
7bd5f21ad5
commit
f508a5f653
6798 changed files with 134949 additions and 19 deletions
|
@ -0,0 +1,278 @@
|
|||
;******************** (C) COPYRIGHT 2007 STMicroelectronics ********************
|
||||
;* File Name : cortexm3_macro.s
|
||||
;* Author : MCD Application Team
|
||||
;* Date First Issued : 02/19/2007
|
||||
;* Description : Instruction wrappers for special Cortex-M3 instructions.
|
||||
;*******************************************************************************
|
||||
; History:
|
||||
; 04/02/2007: V0.2
|
||||
; 02/19/2007: V0.1
|
||||
;*******************************************************************************
|
||||
; THE PRESENT SOFTWARE 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 SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
|
||||
; INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
|
||||
;*******************************************************************************
|
||||
|
||||
SECTION .text:CODE(2)
|
||||
|
||||
; Exported functions
|
||||
EXPORT __WFI
|
||||
EXPORT __WFE
|
||||
EXPORT __SEV
|
||||
EXPORT __ISB
|
||||
EXPORT __DSB
|
||||
EXPORT __DMB
|
||||
EXPORT __SVC
|
||||
EXPORT __MRS_CONTROL
|
||||
EXPORT __MSR_CONTROL
|
||||
EXPORT __MRS_PSP
|
||||
EXPORT __MSR_PSP
|
||||
EXPORT __MRS_MSP
|
||||
EXPORT __MSR_MSP
|
||||
EXPORT __SETPRIMASK
|
||||
EXPORT __RESETPRIMASK
|
||||
EXPORT __SETFAULTMASK
|
||||
EXPORT __RESETFAULTMASK
|
||||
EXPORT __BASEPRICONFIG
|
||||
EXPORT __GetBASEPRI
|
||||
EXPORT __REV_HalfWord
|
||||
EXPORT __REV_Word
|
||||
|
||||
;*******************************************************************************
|
||||
; Function Name : __WFI
|
||||
; Description : Assembler function for the WFI instruction.
|
||||
; Input : None
|
||||
; Return : None
|
||||
;*******************************************************************************
|
||||
__WFI
|
||||
|
||||
WFI
|
||||
BX r14
|
||||
|
||||
;*******************************************************************************
|
||||
; Function Name : __WFE
|
||||
; Description : Assembler function for the WFE instruction.
|
||||
; Input : None
|
||||
; Return : None
|
||||
;*******************************************************************************
|
||||
__WFE
|
||||
|
||||
WFE
|
||||
BX r14
|
||||
|
||||
;*******************************************************************************
|
||||
; Function Name : __SEV
|
||||
; Description : Assembler function for the SEV instruction.
|
||||
; Input : None
|
||||
; Return : None
|
||||
;*******************************************************************************
|
||||
__SEV
|
||||
|
||||
SEV
|
||||
BX r14
|
||||
|
||||
;*******************************************************************************
|
||||
; Function Name : __ISB
|
||||
; Description : Assembler function for the ISB instruction.
|
||||
; Input : None
|
||||
; Return : None
|
||||
;*******************************************************************************
|
||||
__ISB
|
||||
|
||||
ISB
|
||||
BX r14
|
||||
|
||||
;*******************************************************************************
|
||||
; Function Name : __DSB
|
||||
; Description : Assembler function for the DSB instruction.
|
||||
; Input : None
|
||||
; Return : None
|
||||
;*******************************************************************************
|
||||
__DSB
|
||||
|
||||
DSB
|
||||
BX r14
|
||||
|
||||
;*******************************************************************************
|
||||
; Function Name : __DMB
|
||||
; Description : Assembler function for the DMB instruction.
|
||||
; Input : None
|
||||
; Return : None
|
||||
;*******************************************************************************
|
||||
__DMB
|
||||
|
||||
DMB
|
||||
BX r14
|
||||
|
||||
;*******************************************************************************
|
||||
; Function Name : __SVC
|
||||
; Description : Assembler function for the SVC instruction.
|
||||
; Input : None
|
||||
; Return : None
|
||||
;*******************************************************************************
|
||||
__SVC
|
||||
|
||||
SVC 0x01
|
||||
BX r14
|
||||
|
||||
;*******************************************************************************
|
||||
; Function Name : __MRS_CONTROL
|
||||
; Description : Assembler function for the MRS instruction.
|
||||
; Input : None
|
||||
; Return : - r0 : Cortex-M3 CONTROL register value.
|
||||
;*******************************************************************************
|
||||
__MRS_CONTROL
|
||||
|
||||
MRS r0, CONTROL
|
||||
BX r14
|
||||
|
||||
;*******************************************************************************
|
||||
; Function Name : __MSR_CONTROL
|
||||
; Description : Assembler function for the MSR instruction.
|
||||
; Input : - r0 : Cortex-M3 CONTROL register new value.
|
||||
; Return : None
|
||||
;*******************************************************************************
|
||||
__MSR_CONTROL
|
||||
|
||||
MSR CONTROL, r0
|
||||
ISB
|
||||
BX r14
|
||||
|
||||
;*******************************************************************************
|
||||
; Function Name : __MRS_PSP
|
||||
; Description : Assembler function for the MRS instruction.
|
||||
; Input : None
|
||||
; Return : - r0 : Process Stack value.
|
||||
;*******************************************************************************
|
||||
__MRS_PSP
|
||||
|
||||
MRS r0, PSP
|
||||
BX r14
|
||||
|
||||
;*******************************************************************************
|
||||
; Function Name : __MSR_PSP
|
||||
; Description : Assembler function for the MSR instruction.
|
||||
; Input : - r0 : Process Stack new value.
|
||||
; Return : None
|
||||
;*******************************************************************************
|
||||
__MSR_PSP
|
||||
|
||||
MSR PSP, r0 ; set Process Stack value
|
||||
BX r14
|
||||
|
||||
;*******************************************************************************
|
||||
; Function Name : __MRS_MSP
|
||||
; Description : Assembler function for the MRS instruction.
|
||||
; Input : None
|
||||
; Return : - r0 : Main Stack value.
|
||||
;*******************************************************************************
|
||||
__MRS_MSP
|
||||
|
||||
MRS r0, MSP
|
||||
BX r14
|
||||
|
||||
;*******************************************************************************
|
||||
; Function Name : __MSR_MSP
|
||||
; Description : Assembler function for the MSR instruction.
|
||||
; Input : - r0 : Main Stack new value.
|
||||
; Return : None
|
||||
;*******************************************************************************
|
||||
__MSR_MSP
|
||||
|
||||
MSR MSP, r0 ; set Main Stack value
|
||||
BX r14
|
||||
|
||||
;*******************************************************************************
|
||||
; Function Name : __SETPRIMASK
|
||||
; Description : Assembler function to set the PRIMASK.
|
||||
; Input : None
|
||||
; Return : None
|
||||
;*******************************************************************************
|
||||
__SETPRIMASK
|
||||
|
||||
CPSID i
|
||||
BX r14
|
||||
|
||||
;*******************************************************************************
|
||||
; Function Name : __RESETPRIMASK
|
||||
; Description : Assembler function to reset the PRIMASK.
|
||||
; Input : None
|
||||
; Return : None
|
||||
;*******************************************************************************
|
||||
__RESETPRIMASK
|
||||
|
||||
CPSIE i
|
||||
BX r14
|
||||
|
||||
;*******************************************************************************
|
||||
; Function Name : __SETFAULTMASK
|
||||
; Description : Assembler function to set the FAULTMASK.
|
||||
; Input : None
|
||||
; Return : None
|
||||
;*******************************************************************************
|
||||
__SETFAULTMASK
|
||||
|
||||
CPSID f
|
||||
BX r14
|
||||
|
||||
;*******************************************************************************
|
||||
; Function Name : __RESETFAULTMASK
|
||||
; Description : Assembler function to reset the FAULTMASK.
|
||||
; Input : None
|
||||
; Return : None
|
||||
;*******************************************************************************
|
||||
__RESETFAULTMASK
|
||||
|
||||
CPSIE f
|
||||
BX r14
|
||||
|
||||
;*******************************************************************************
|
||||
; Function Name : __BASEPRICONFIG
|
||||
; Description : Assembler function to set the Base Priority.
|
||||
; Input : - r0 : Base Priority new value
|
||||
; Return : None
|
||||
;*******************************************************************************
|
||||
__BASEPRICONFIG
|
||||
|
||||
MSR BASEPRI, r0
|
||||
BX r14
|
||||
|
||||
;*******************************************************************************
|
||||
; Function Name : __GetBASEPRI
|
||||
; Description : Assembler function to get the Base Priority value.
|
||||
; Input : None
|
||||
; Return : - r0 : Base Priority value
|
||||
;*******************************************************************************
|
||||
__GetBASEPRI
|
||||
|
||||
MRS r0, BASEPRI_MAX
|
||||
BX r14
|
||||
|
||||
;*******************************************************************************
|
||||
; Function Name : __REV_HalfWord
|
||||
; Description : Reverses the byte order in HalfWord(16-bit) input variable.
|
||||
; Input : - r0 : specifies the input variable
|
||||
; Return : - r0 : holds tve variable value after byte reversing.
|
||||
;*******************************************************************************
|
||||
__REV_HalfWord
|
||||
|
||||
REV16 r0, r0
|
||||
BX r14
|
||||
|
||||
;*******************************************************************************
|
||||
; Function Name : __REV_Word
|
||||
; Description : Reverses the byte order in Word(32-bit) input variable.
|
||||
; Input : - r0 : specifies the input variable
|
||||
; Return : - r0 : holds tve variable value after byte reversing.
|
||||
;*******************************************************************************
|
||||
__REV_Word
|
||||
|
||||
REV r0, r0
|
||||
BX r14
|
||||
|
||||
END
|
||||
|
||||
;******************* (C) COPYRIGHT 2007 STMicroelectronics *****END OF FILE*****
|
1305
FreeRTOS/Demo/CORTEX_STM32F103_IAR/STM32F10xFWLib/src/lcd.c
Normal file
1305
FreeRTOS/Demo/CORTEX_STM32F103_IAR/STM32F10xFWLib/src/lcd.c
Normal file
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,263 @@
|
|||
/******************** (C) COPYRIGHT 2007 STMicroelectronics ********************
|
||||
* File Name : stm32f10x_bkp.c
|
||||
* Author : MCD Application Team
|
||||
* Date First Issued : 09/29/2006
|
||||
* Description : This file provides all the BKP firmware functions.
|
||||
********************************************************************************
|
||||
* History:
|
||||
* 04/02/2007: V0.2
|
||||
* 02/05/2007: V0.1
|
||||
* 09/29/2006: V0.01
|
||||
********************************************************************************
|
||||
* THE PRESENT SOFTWARE 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 SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
|
||||
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
|
||||
*******************************************************************************/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32f10x_bkp.h"
|
||||
#include "stm32f10x_rcc.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* ------------ BKP registers bit address in the alias region ----------- */
|
||||
#define BKP_OFFSET (BKP_BASE - PERIPH_BASE)
|
||||
|
||||
/* --- RTCCR Register ---*/
|
||||
/* Alias word address of CCO bit */
|
||||
#define RTCCR_OFFSET (BKP_OFFSET + 0x2C)
|
||||
#define CCO_BitNumber 0x07
|
||||
#define RTCCR_CCO_BB (PERIPH_BB_BASE + (RTCCR_OFFSET * 32) + (CCO_BitNumber * 4))
|
||||
|
||||
/* --- CR Register ---*/
|
||||
/* Alias word address of TPAL bit */
|
||||
#define CR_OFFSET (BKP_OFFSET + 0x30)
|
||||
#define TPAL_BitNumber 0x01
|
||||
#define CR_TPAL_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (TPAL_BitNumber * 4))
|
||||
|
||||
/* Alias word address of TPE bit */
|
||||
#define TPE_BitNumber 0x00
|
||||
#define CR_TPE_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (TPE_BitNumber * 4))
|
||||
|
||||
/* --- CSR Register ---*/
|
||||
/* Alias word address of TPIE bit */
|
||||
#define CSR_OFFSET (BKP_OFFSET + 0x34)
|
||||
#define TPIE_BitNumber 0x02
|
||||
#define CSR_TPIE_BB (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (TPIE_BitNumber * 4))
|
||||
|
||||
/* Alias word address of TIF bit */
|
||||
#define TIF_BitNumber 0x09
|
||||
#define CSR_TIF_BB (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (TIF_BitNumber * 4))
|
||||
|
||||
/* Alias word address of TEF bit */
|
||||
#define TEF_BitNumber 0x08
|
||||
#define CSR_TEF_BB (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (TEF_BitNumber * 4))
|
||||
|
||||
|
||||
/* ---------------------- BKP registers bit mask ------------------------ */
|
||||
/* RTCCR register bit mask */
|
||||
#define RTCCR_CAL_Mask ((u16)0xFF80)
|
||||
|
||||
/* CSR register bit mask */
|
||||
#define CSR_CTE_Set ((u16)0x0001)
|
||||
#define CSR_CTI_Set ((u16)0x0002)
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : BKP_DeInit
|
||||
* Description : Deinitializes the BKP peripheral registers to their default
|
||||
* reset values.
|
||||
* Input : None
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void BKP_DeInit(void)
|
||||
{
|
||||
RCC_BackupResetCmd(ENABLE);
|
||||
RCC_BackupResetCmd(DISABLE);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : BKP_TamperPinLevelConfig
|
||||
* Description : Configures the Tamper Pin active level.
|
||||
* Input : - BKP_TamperPinLevel: specifies the Tamper Pin active level.
|
||||
* This parameter can be one of the following values:
|
||||
* - BKP_TamperPinLevel_High: Tamper pin active on high level
|
||||
* - BKP_TamperPinLevel_Low: Tamper pin active on low level
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void BKP_TamperPinLevelConfig(u16 BKP_TamperPinLevel)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert(IS_BKP_TAMPER_PIN_LEVEL(BKP_TamperPinLevel));
|
||||
|
||||
*(vu32 *) CR_TPAL_BB = BKP_TamperPinLevel;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : BKP_TamperPinCmd
|
||||
* Description : Enables or disables the Tamper Pin activation.
|
||||
* Input : - NewState: new state of the Tamper Pin activation.
|
||||
* This parameter can be: ENABLE or DISABLE.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void BKP_TamperPinCmd(FunctionalState NewState)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert(IS_FUNCTIONAL_STATE(NewState));
|
||||
|
||||
*(vu32 *) CR_TPE_BB = (u32)NewState;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : BKP_ITConfig
|
||||
* Description : Enables or disables the Tamper Pin Interrupt.
|
||||
* Input : - NewState: new state of the Tamper Pin Interrupt.
|
||||
* This parameter can be: ENABLE or DISABLE.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void BKP_ITConfig(FunctionalState NewState)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert(IS_FUNCTIONAL_STATE(NewState));
|
||||
|
||||
*(vu32 *) CSR_TPIE_BB = (u32)NewState;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : BKP_RTCCalibrationClockOutputCmd
|
||||
* Description : Enables or disables the output of the Calibration Clock.
|
||||
* Input : - NewState: new state of the Calibration Clock output.
|
||||
* This parameter can be: ENABLE or DISABLE.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void BKP_RTCCalibrationClockOutputCmd(FunctionalState NewState)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert(IS_FUNCTIONAL_STATE(NewState));
|
||||
|
||||
*(vu32 *) RTCCR_CCO_BB = (u32)NewState;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : BKP_SetRTCCalibrationValue
|
||||
* Description : Sets RTC Clock Calibration value.
|
||||
* Input : - CalibrationValue: specifies the RTC Clock Calibration value.
|
||||
* This parameter must be a number between 0 and 0x7F.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void BKP_SetRTCCalibrationValue(u8 CalibrationValue)
|
||||
{
|
||||
u16 tmpreg = 0;
|
||||
|
||||
/* Check the parameters */
|
||||
assert(IS_BKP_CALIBRATION_VALUE(CalibrationValue));
|
||||
|
||||
tmpreg = BKP->RTCCR;
|
||||
|
||||
/* Clear CAL[6:0] bits */
|
||||
tmpreg &= RTCCR_CAL_Mask;
|
||||
|
||||
/* Set CAL[6:0] bits according to CalibrationValue value */
|
||||
tmpreg |= CalibrationValue;
|
||||
|
||||
/* Store the new value */
|
||||
BKP->RTCCR = tmpreg;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : BKP_WriteBackupRegister
|
||||
* Description : Writes user data to the specified Data Backup Register.
|
||||
* Input : - BKP_DR: specifies the Data Backup Register.
|
||||
* This parameter can be BKP_DRx where x:[1, 10]
|
||||
* - Data: data to write
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void BKP_WriteBackupRegister(u16 BKP_DR, u16 Data)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert(IS_BKP_DR(BKP_DR));
|
||||
|
||||
*(vu16 *) (BKP_BASE + BKP_DR) = Data;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : BKP_ReadBackupRegister
|
||||
* Description : Reads data from the specified Data Backup Register.
|
||||
* Input : - BKP_DR: specifies the Data Backup Register.
|
||||
* This parameter can be BKP_DRx where x:[1, 10]
|
||||
* Output : None
|
||||
* Return : The content of the specified Data Backup Register
|
||||
*******************************************************************************/
|
||||
u16 BKP_ReadBackupRegister(u16 BKP_DR)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert(IS_BKP_DR(BKP_DR));
|
||||
|
||||
return (*(vu16 *) (BKP_BASE + BKP_DR));
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : BKP_GetFlagStatus
|
||||
* Description : Checks whether the Tamper Pin Event flag is set or not.
|
||||
* Input : None
|
||||
* Output : None
|
||||
* Return : The new state of the Tamper Pin Event flag (SET or RESET).
|
||||
*******************************************************************************/
|
||||
FlagStatus BKP_GetFlagStatus(void)
|
||||
{
|
||||
return (FlagStatus)(*(vu32 *) CSR_TEF_BB);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : BKP_ClearFlag
|
||||
* Description : Clears Tamper Pin Event pending flag.
|
||||
* Input : None
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void BKP_ClearFlag(void)
|
||||
{
|
||||
/* Set CTE bit to clear Tamper Pin Event flag */
|
||||
BKP->CSR |= CSR_CTE_Set;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : BKP_GetITStatus
|
||||
* Description : Checks whether the Tamper Pin Interrupt has occurred or not.
|
||||
* Input : None
|
||||
* Output : None
|
||||
* Return : The new state of the Tamper Pin Interrupt (SET or RESET).
|
||||
*******************************************************************************/
|
||||
ITStatus BKP_GetITStatus(void)
|
||||
{
|
||||
return (ITStatus)(*(vu32 *) CSR_TIF_BB);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : BKP_ClearITPendingBit
|
||||
* Description : Clears Tamper Pin Interrupt pending bit.
|
||||
* Input : None
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void BKP_ClearITPendingBit(void)
|
||||
{
|
||||
/* Set CTI bit to clear Tamper Pin Interrupt pending bit */
|
||||
BKP->CSR |= CSR_CTI_Set;
|
||||
}
|
||||
|
||||
/******************* (C) COPYRIGHT 2007 STMicroelectronics *****END OF FILE****/
|
|
@ -0,0 +1,873 @@
|
|||
/******************** (C) COPYRIGHT 2007 STMicroelectronics ********************
|
||||
* File Name : stm32f10x_can.c
|
||||
* Author : MCD Application Team
|
||||
* Date First Issued : 09/29/2006
|
||||
* Description : This file provides all the CAN firmware functions.
|
||||
********************************************************************************
|
||||
* History:
|
||||
* 04/02/2007: V0.2
|
||||
* 02/05/2007: V0.1
|
||||
* 09/29/2006: V0.01
|
||||
********************************************************************************
|
||||
* THE PRESENT SOFTWARE 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 SOFTWARE 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;
|
||||
|
||||
/* Check the parameters */
|
||||
assert(IS_FUNCTIONAL_STATE(CAN_InitStruct->CAN_TTCM));
|
||||
assert(IS_FUNCTIONAL_STATE(CAN_InitStruct->CAN_ABOM));
|
||||
assert(IS_FUNCTIONAL_STATE(CAN_InitStruct->CAN_AWUM));
|
||||
assert(IS_FUNCTIONAL_STATE(CAN_InitStruct->CAN_NART));
|
||||
assert(IS_FUNCTIONAL_STATE(CAN_InitStruct->CAN_RFLM));
|
||||
assert(IS_FUNCTIONAL_STATE(CAN_InitStruct->CAN_TXFP));
|
||||
assert(IS_CAN_MODE(CAN_InitStruct->CAN_Mode));
|
||||
assert(IS_CAN_SJW(CAN_InitStruct->CAN_SJW));
|
||||
assert(IS_CAN_BS1(CAN_InitStruct->CAN_BS1));
|
||||
assert(IS_CAN_BS2(CAN_InitStruct->CAN_BS2));
|
||||
assert(IS_CAN_CLOCK(CAN_InitStruct->CAN_Clock));
|
||||
assert(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_Clock << 15) | ((u32)CAN_InitStruct->CAN_Prescaler - 1);
|
||||
|
||||
InitStatus = CANINITOK;
|
||||
|
||||
/* Request leave initialisation */
|
||||
CAN->MCR &= ~CAN_MCR_INRQ;
|
||||
|
||||
/* ...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(IS_CAN_FILTER_NUMBER(CAN_FilterInitStruct->CAN_FilterNumber));
|
||||
assert(IS_CAN_FILTER_MODE(CAN_FilterInitStruct->CAN_FilterMode));
|
||||
assert(IS_CAN_FILTER_SCALE(CAN_FilterInitStruct->CAN_FilterScale));
|
||||
assert(IS_CAN_FILTER_FIFO(CAN_FilterInitStruct->CAN_FilterFIFOAssignment));
|
||||
assert(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->FA0R &= ~(u32)FilterNumber_BitPos;
|
||||
|
||||
/* Filter Scale */
|
||||
if (CAN_FilterInitStruct->CAN_FilterScale == CAN_FilterScale_16bit)
|
||||
{
|
||||
/* 16-bit scale for the filter */
|
||||
CAN->FS0R &= ~(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].FR0 = ((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].FR1 = ((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->FS0R |= FilterNumber_BitPos;
|
||||
|
||||
/* 32-bit identifier or First 32-bit identifier */
|
||||
CAN->sFilterRegister[CAN_FilterInitStruct->CAN_FilterNumber].FR0 = ((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].FR1 = ((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->FM0R &= ~(u32)FilterNumber_BitPos;
|
||||
}
|
||||
else /* CAN_FilterInitStruct->CAN_FilterMode == CAN_FilterMode_IdList */
|
||||
{
|
||||
/*Identifier list mode for the filter*/
|
||||
CAN->FM0R |= (u32)FilterNumber_BitPos;
|
||||
}
|
||||
|
||||
/* Filter FIFO assignment */
|
||||
if (CAN_FilterInitStruct->CAN_FilterFIFOAssignment == CAN_FilterFIFO0)
|
||||
{
|
||||
/* FIFO 0 assignation for the filter */
|
||||
CAN->FFA0R &= ~(u32)FilterNumber_BitPos;
|
||||
}
|
||||
if (CAN_FilterInitStruct->CAN_FilterFIFOAssignment == CAN_FilterFIFO1)
|
||||
{
|
||||
/* FIFO 1 assignation for the filter */
|
||||
CAN->FFA0R |= (u32)FilterNumber_BitPos;
|
||||
}
|
||||
|
||||
/* Filter activation */
|
||||
if (CAN_FilterInitStruct->CAN_FilterActivation == ENABLE)
|
||||
{
|
||||
CAN->FA0R |= 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_0tq;
|
||||
|
||||
/* 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_Clock member */
|
||||
CAN_InitStruct->CAN_Clock = CAN_Clock_APB;
|
||||
|
||||
/* Initialize the CAN_Prescaler member */
|
||||
CAN_InitStruct->CAN_Prescaler = 1;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : CAN_ITConfig
|
||||
* Description : Enables or disables the CAN interrupts.
|
||||
* Input : - CAN_IT: specifies the CAN interrupt sources to be enabled or
|
||||
* disabled.
|
||||
* - 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(IS_CAN_IT(CAN_IT));
|
||||
assert(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(IS_CAN_STDID(TxMessage->StdId));
|
||||
assert(IS_CAN_EXTID(TxMessage->StdId));
|
||||
assert(IS_CAN_IDTYPE(TxMessage->IDE));
|
||||
assert(IS_CAN_RTR(TxMessage->RTR));
|
||||
assert(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 */
|
||||
TxMessage->StdId &= (u32)0x000007FF;
|
||||
TxMessage->StdId = TxMessage->StdId << 21;
|
||||
TxMessage->ExtId &= (u32)0x0003FFFF;
|
||||
TxMessage->ExtId <<= 3;
|
||||
|
||||
CAN->sTxMailBox[TransmitMailbox].TIR &= CAN_TMIDxR_TXRQ;
|
||||
CAN->sTxMailBox[TransmitMailbox].TIR |= (TxMessage->StdId | 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 : Check 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.
|
||||
*******************************************************************************/
|
||||
u32 CAN_TransmitStatus(u8 TransmitMailbox)
|
||||
{
|
||||
/* RQCP, TXOK and TME bits */
|
||||
u32 State = 0;
|
||||
|
||||
/* Check the parameters */
|
||||
assert(IS_CAN_TRANSMITMAILBOX(TransmitMailbox));
|
||||
|
||||
switch (TransmitMailbox)
|
||||
{
|
||||
case (0): State |= ((CAN->TSR & CAN_TSR_RQCP0) << 2);
|
||||
State |= ((CAN->TSR & CAN_TSR_TXOK0) >> 0);
|
||||
State |= ((CAN->TSR & CAN_TSR_TME0) >> 26);
|
||||
break;
|
||||
case (1): State |= ((CAN->TSR & CAN_TSR_RQCP1) >> 6);
|
||||
State |= ((CAN->TSR & CAN_TSR_TXOK1) >> 8);
|
||||
State |= ((CAN->TSR & CAN_TSR_TME1) >> 27);
|
||||
break;
|
||||
case (2): State |= ((CAN->TSR & CAN_TSR_RQCP2) >> 14);
|
||||
State |= ((CAN->TSR & CAN_TSR_TXOK2) >> 16);
|
||||
State |= ((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(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 : Release 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(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 : Return 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(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(IS_CAN_FIFO(FIFONumber));
|
||||
|
||||
/* Get the Id */
|
||||
RxMessage->StdId = (u32)0x000007FF & (CAN->sFIFOMailBox[FIFONumber].RIR >> 21);
|
||||
RxMessage->ExtId = (u32)0x0003FFFF & (CAN->sFIFOMailBox[FIFONumber].RIR >> 3);
|
||||
|
||||
RxMessage->IDE = (u32)0x00000004 & CAN->sFIFOMailBox[FIFONumber].RIR;
|
||||
RxMessage->RTR = (u32)0x00000002 & CAN->sFIFOMailBox[FIFONumber].RIR;
|
||||
|
||||
/* Get the DLC */
|
||||
RxMessage->DLC = (u32)0x0000000F & CAN->sFIFOMailBox[FIFONumber].RDTR;
|
||||
|
||||
/* Get the FMI */
|
||||
RxMessage->FMI = (u32)0x000000FF & (CAN->sFIFOMailBox[FIFONumber].RDTR >> 8);
|
||||
|
||||
/* Get the data field */
|
||||
RxMessage->Data[0] = (u32)0x000000FF & CAN->sFIFOMailBox[FIFONumber].RDLR;
|
||||
RxMessage->Data[1] = (u32)0x000000FF & (CAN->sFIFOMailBox[FIFONumber].RDLR >> 8);
|
||||
RxMessage->Data[2] = (u32)0x000000FF & (CAN->sFIFOMailBox[FIFONumber].RDLR >> 16);
|
||||
RxMessage->Data[3] = (u32)0x000000FF & (CAN->sFIFOMailBox[FIFONumber].RDLR >> 24);
|
||||
|
||||
RxMessage->Data[4] = (u32)0x000000FF & CAN->sFIFOMailBox[FIFONumber].RDHR;
|
||||
RxMessage->Data[5] = (u32)0x000000FF & (CAN->sFIFOMailBox[FIFONumber].RDHR >> 8);
|
||||
RxMessage->Data[6] = (u32)0x000000FF & (CAN->sFIFOMailBox[FIFONumber].RDHR >> 16);
|
||||
RxMessage->Data[7] = (u32)0x000000FF & (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 CAN flag is set or not.
|
||||
* Input : CAN_FLAG: specifies the flag to check.
|
||||
* 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(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(IS_CAN_FLAG(CAN_FLAG));
|
||||
|
||||
/* Clear the selected CAN flags */
|
||||
CAN->ESR &= ~CAN_FLAG;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : CAN_GetITStatus
|
||||
* Description : Checks whether the CAN interrupt has occurred or not.
|
||||
* Input : CAN_IT: specifies the CAN interrupt source to check.
|
||||
* 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(IS_CAN_IT(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(IS_CAN_IT(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 2007 STMicroelectronics *****END OF FILE****/
|
|
@ -0,0 +1,503 @@
|
|||
/******************** (C) COPYRIGHT 2007 STMicroelectronics ********************
|
||||
* File Name : stm32f10x_dma.c
|
||||
* Author : MCD Application Team
|
||||
* Date First Issued : 09/29/2006
|
||||
* Description : This file provides all the DMA firmware functions.
|
||||
********************************************************************************
|
||||
* History:
|
||||
* 04/02/2007: V0.2
|
||||
* 02/05/2007: V0.1
|
||||
* 09/29/2006: V0.01
|
||||
********************************************************************************
|
||||
* THE PRESENT SOFTWARE 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 SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
|
||||
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
|
||||
*******************************************************************************/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32f10x_dma.h"
|
||||
#include "stm32f10x_rcc.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* DMA ENABLE mask */
|
||||
#define CCR_ENABLE_Set ((u32)0x00000001)
|
||||
#define CCR_ENABLE_Reset ((u32)0xFFFFFFFE)
|
||||
|
||||
/* DMA Channelx interrupt pending bit masks */
|
||||
#define DMA_Channel1_IT_Mask ((u32)0x0000000F)
|
||||
#define DMA_Channel2_IT_Mask ((u32)0x000000F0)
|
||||
#define DMA_Channel3_IT_Mask ((u32)0x00000F00)
|
||||
#define DMA_Channel4_IT_Mask ((u32)0x0000F000)
|
||||
#define DMA_Channel5_IT_Mask ((u32)0x000F0000)
|
||||
#define DMA_Channel6_IT_Mask ((u32)0x00F00000)
|
||||
#define DMA_Channel7_IT_Mask ((u32)0x0F000000)
|
||||
|
||||
/* DMA registers Masks */
|
||||
#define CCR_CLEAR_Mask ((u32)0xFFFF800F)
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : DMA_DeInit
|
||||
* Description : Deinitializes the DMA Channelx registers to their default reset
|
||||
* values.
|
||||
* Input : - DMA_Channelx: where x can be 1, 2 to 7 to select the DMA
|
||||
* Channel.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void DMA_DeInit(DMA_Channel_TypeDef* DMA_Channelx)
|
||||
{
|
||||
/* DMA Channelx disable */
|
||||
DMA_Cmd(DMA_Channelx, DISABLE);
|
||||
|
||||
/* Reset Channelx control register */
|
||||
DMA_Channelx->CCR = 0;
|
||||
|
||||
/* Reset Channelx remaining bytes register */
|
||||
DMA_Channelx->CNDTR = 0;
|
||||
|
||||
/* Reset Channelx peripheral address register */
|
||||
DMA_Channelx->CPAR = 0;
|
||||
|
||||
/* Reset Channelx memory address register */
|
||||
DMA_Channelx->CMAR = 0;
|
||||
|
||||
switch (*(u32*)&DMA_Channelx)
|
||||
{
|
||||
case DMA_Channel1_BASE:
|
||||
/* Reset interrupt pending bits for Channel1 */
|
||||
DMA->IFCR |= DMA_Channel1_IT_Mask;
|
||||
break;
|
||||
|
||||
case DMA_Channel2_BASE:
|
||||
/* Reset interrupt pending bits for Channel2 */
|
||||
DMA->IFCR |= DMA_Channel2_IT_Mask;
|
||||
break;
|
||||
|
||||
case DMA_Channel3_BASE:
|
||||
/* Reset interrupt pending bits for Channel3 */
|
||||
DMA->IFCR |= DMA_Channel3_IT_Mask;
|
||||
break;
|
||||
|
||||
case DMA_Channel4_BASE:
|
||||
/* Reset interrupt pending bits for Channel4 */
|
||||
DMA->IFCR |= DMA_Channel4_IT_Mask;
|
||||
break;
|
||||
|
||||
case DMA_Channel5_BASE:
|
||||
/* Reset interrupt pending bits for Channel5 */
|
||||
DMA->IFCR |= DMA_Channel5_IT_Mask;
|
||||
break;
|
||||
|
||||
case DMA_Channel6_BASE:
|
||||
/* Reset interrupt pending bits for Channel6 */
|
||||
DMA->IFCR |= DMA_Channel6_IT_Mask;
|
||||
break;
|
||||
|
||||
case DMA_Channel7_BASE:
|
||||
/* Reset interrupt pending bits for Channel7 */
|
||||
DMA->IFCR |= DMA_Channel7_IT_Mask;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : DMA_Init
|
||||
* Description : Initializes the DMA Channelx according to the specified
|
||||
* parameters in the DMA_InitStruct.
|
||||
* Input : - DMA_Channelx: where x can be 1, 2 to 7 to select the DMA
|
||||
* Channel.
|
||||
* - DMA_InitStruct: pointer to a DMA_InitTypeDef structure that
|
||||
* contains the configuration information for the specified
|
||||
* DMA Channel.
|
||||
* Output : None
|
||||
* Return : None
|
||||
******************************************************************************/
|
||||
void DMA_Init(DMA_Channel_TypeDef* DMA_Channelx, DMA_InitTypeDef* DMA_InitStruct)
|
||||
{
|
||||
u32 tmpreg = 0;
|
||||
|
||||
/* Check the parameters */
|
||||
assert(IS_DMA_DIR(DMA_InitStruct->DMA_DIR));
|
||||
assert(IS_DMA_BUFFER_SIZE(DMA_InitStruct->DMA_BufferSize));
|
||||
assert(IS_DMA_PERIPHERAL_INC_STATE(DMA_InitStruct->DMA_PeripheralInc));
|
||||
assert(IS_DMA_MEMORY_INC_STATE(DMA_InitStruct->DMA_MemoryInc));
|
||||
assert(IS_DMA_PERIPHERAL_DATA_SIZE(DMA_InitStruct->DMA_PeripheralDataSize));
|
||||
assert(IS_DMA_MEMORY_DATA_SIZE(DMA_InitStruct->DMA_MemoryDataSize));
|
||||
assert(IS_DMA_MODE(DMA_InitStruct->DMA_Mode));
|
||||
assert(IS_DMA_PRIORITY(DMA_InitStruct->DMA_Priority));
|
||||
assert(IS_DMA_M2M_STATE(DMA_InitStruct->DMA_M2M));
|
||||
|
||||
/*--------------------------- DMA Channelx CCR Configuration -----------------*/
|
||||
/* Get the DMA_Channelx CCR value */
|
||||
tmpreg = DMA_Channelx->CCR;
|
||||
/* Clear MEM2MEM, PL, MSIZE, PSIZE, MINC, PINC, CIRCULAR and DIR bits */
|
||||
tmpreg &= CCR_CLEAR_Mask;
|
||||
/* Configure DMA Channelx: data transfer, data size, priority level and mode */
|
||||
/* Set DIR bit according to DMA_DIR value */
|
||||
/* Set CIRCULAR bit according to DMA_Mode value */
|
||||
/* Set PINC bit according to DMA_PeripheralInc value */
|
||||
/* Set MINC bit according to DMA_MemoryInc value */
|
||||
/* Set PSIZE bits according to DMA_PeripheralDataSize value */
|
||||
/* Set MSIZE bits according to DMA_MemoryDataSize value */
|
||||
/* Set PL bits according to DMA_Priority value */
|
||||
/* Set the MEM2MEM bit according to DMA_M2M value */
|
||||
tmpreg |= DMA_InitStruct->DMA_DIR | DMA_InitStruct->DMA_Mode |
|
||||
DMA_InitStruct->DMA_PeripheralInc | DMA_InitStruct->DMA_MemoryInc |
|
||||
DMA_InitStruct->DMA_PeripheralDataSize | DMA_InitStruct->DMA_MemoryDataSize |
|
||||
DMA_InitStruct->DMA_Priority | DMA_InitStruct->DMA_M2M;
|
||||
/* Write to DMA Channelx CCR */
|
||||
DMA_Channelx->CCR = tmpreg;
|
||||
|
||||
/*--------------------------- DMA Channelx CNBTR Configuration ---------------*/
|
||||
/* Write to DMA Channelx CNBTR */
|
||||
DMA_Channelx->CNDTR = DMA_InitStruct->DMA_BufferSize;
|
||||
|
||||
/*--------------------------- DMA Channelx CPAR Configuration ----------------*/
|
||||
/* Write to DMA Channelx CPAR */
|
||||
DMA_Channelx->CPAR = DMA_InitStruct->DMA_PeripheralBaseAddr;
|
||||
|
||||
/*--------------------------- DMA Channelx CMAR Configuration ----------------*/
|
||||
/* Write to DMA Channelx CMAR */
|
||||
DMA_Channelx->CMAR = DMA_InitStruct->DMA_MemoryBaseAddr;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : DMA_StructInit
|
||||
* Description : Fills each DMA_InitStruct member with its default value.
|
||||
* Input : - DMA_InitStruct : pointer to a DMA_InitTypeDef structure
|
||||
* which will be initialized.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void DMA_StructInit(DMA_InitTypeDef* DMA_InitStruct)
|
||||
{
|
||||
/*-------------- Reset DMA init structure parameters values ------------------*/
|
||||
/* Initialize the DMA_PeripheralBaseAddr member */
|
||||
DMA_InitStruct->DMA_PeripheralBaseAddr = 0;
|
||||
|
||||
/* Initialize the DMA_MemoryBaseAddr member */
|
||||
DMA_InitStruct->DMA_MemoryBaseAddr = 0;
|
||||
|
||||
/* Initialize the DMA_DIR member */
|
||||
DMA_InitStruct->DMA_DIR = DMA_DIR_PeripheralSRC;
|
||||
|
||||
/* Initialize the DMA_BufferSize member */
|
||||
DMA_InitStruct->DMA_BufferSize = 0;
|
||||
|
||||
/* Initialize the DMA_PeripheralInc member */
|
||||
DMA_InitStruct->DMA_PeripheralInc = DMA_PeripheralInc_Disable;
|
||||
|
||||
/* Initialize the DMA_MemoryInc member */
|
||||
DMA_InitStruct->DMA_MemoryInc = DMA_MemoryInc_Disable;
|
||||
|
||||
/* Initialize the DMA_PeripheralDataSize member */
|
||||
DMA_InitStruct->DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
|
||||
|
||||
/* Initialize the DMA_MemoryDataSize member */
|
||||
DMA_InitStruct->DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
|
||||
|
||||
/* Initialize the DMA_Mode member */
|
||||
DMA_InitStruct->DMA_Mode = DMA_Mode_Normal;
|
||||
|
||||
/* Initialize the DMA_Priority member */
|
||||
DMA_InitStruct->DMA_Priority = DMA_Priority_Low;
|
||||
|
||||
/* Initialize the DMA_M2M member */
|
||||
DMA_InitStruct->DMA_M2M = DMA_M2M_Disable;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : DMA_Cmd
|
||||
* Description : Enables or disables the specified DMA Channel.
|
||||
* Input : - DMA_Channelx: where x can be 1, 2 to 7 to select the DMA
|
||||
* Channel.
|
||||
* - NewState: new state of the DMAx Channel.
|
||||
* This parameter can be: ENABLE or DISABLE.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void DMA_Cmd(DMA_Channel_TypeDef* DMA_Channelx, FunctionalState NewState)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert(IS_FUNCTIONAL_STATE(NewState));
|
||||
|
||||
if (NewState != DISABLE)
|
||||
{
|
||||
/* Enable the selected DMA Channelx */
|
||||
DMA_Channelx->CCR |= CCR_ENABLE_Set;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Disable the selected DMA Channelx */
|
||||
DMA_Channelx->CCR &= CCR_ENABLE_Reset;
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : DMA_ITConfig
|
||||
* Description : Enables or disables the specified DMA interrupts.
|
||||
* Input : - DMA_IT: specifies the DMA interrupts sources to be enabled
|
||||
* or disabled.
|
||||
* This parameter can be any combination of the following values:
|
||||
* - DMA_IT_TC: Transfer complete interrupt mask
|
||||
* - DMA_IT_HT: Half transfer interrupt mask
|
||||
* - DMA_IT_TE: Transfer error interrupt mask
|
||||
* - NewState: new state of the specified DMA interrupts.
|
||||
* This parameter can be: ENABLE or DISABLE.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void DMA_ITConfig(DMA_Channel_TypeDef* DMA_Channelx, u32 DMA_IT, FunctionalState NewState)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert(IS_DMA_CONFIG_IT(DMA_IT));
|
||||
assert(IS_FUNCTIONAL_STATE(NewState));
|
||||
|
||||
if (NewState != DISABLE)
|
||||
{
|
||||
/* Enable the selected DMA interrupts */
|
||||
DMA_Channelx->CCR |= DMA_IT;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Disable the selected DMA interrupts */
|
||||
DMA_Channelx->CCR &= ~DMA_IT;
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : DMA_GetCurrDataCounter
|
||||
* Description : Returns the number of remaining data units in the current
|
||||
* DMA Channel transfer.
|
||||
* Input : - DMA_Channelx: where x can be 1, 2 to 7 to select the DMA
|
||||
* Channel.
|
||||
* Output : None
|
||||
* Return : The number of remaining data units in the current DMA Channel
|
||||
* transfer..
|
||||
*******************************************************************************/
|
||||
u16 DMA_GetCurrDataCounter(DMA_Channel_TypeDef* DMA_Channelx)
|
||||
{
|
||||
/* Return the current memory address value for Channelx */
|
||||
return ((u16)(DMA_Channelx->CNDTR));
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : DMA_GetFlagStatus
|
||||
* Description : Checks whether the specified DMA flag is set or not.
|
||||
* Input : - DMA_FLAG: specifies the flag to check.
|
||||
* This parameter can be one of the following values:
|
||||
* - DMA_FLAG_GL1: Channel1 global flag.
|
||||
* - DMA_FLAG_TC1: Channel1 transfer complete flag.
|
||||
* - DMA_FLAG_HT1: Channel1 half transfer flag.
|
||||
* - DMA_FLAG_TE1: Channel1 transfer error flag.
|
||||
* - DMA_FLAG_GL2: Channel2 global flag.
|
||||
* - DMA_FLAG_TC2: Channel2 transfer complete flag.
|
||||
* - DMA_FLAG_HT2: Channel2 half transfer flag.
|
||||
* - DMA_FLAG_TE2: Channel2 transfer error flag.
|
||||
* - DMA_FLAG_GL3: Channel3 global flag.
|
||||
* - DMA_FLAG_TC3: Channel3 transfer complete flag.
|
||||
* - DMA_FLAG_HT3: Channel3 half transfer flag.
|
||||
* - DMA_FLAG_TE3: Channel3 transfer error flag.
|
||||
* - DMA_FLAG_GL4: Channel4 global flag.
|
||||
* - DMA_FLAG_TC4: Channel4 transfer complete flag.
|
||||
* - DMA_FLAG_HT4: Channel4 half transfer flag.
|
||||
* - DMA_FLAG_TE4: Channel4 transfer error flag.
|
||||
* - DMA_FLAG_GL5: Channel5 global flag.
|
||||
* - DMA_FLAG_TC5: Channel5 transfer complete flag.
|
||||
* - DMA_FLAG_HT5: Channel5 half transfer flag.
|
||||
* - DMA_FLAG_TE5: Channel5 transfer error flag.
|
||||
* - DMA_FLAG_GL6: Channel6 global flag.
|
||||
* - DMA_FLAG_TC6: Channel6 transfer complete flag.
|
||||
* - DMA_FLAG_HT6: Channel6 half transfer flag.
|
||||
* - DMA_FLAG_TE6: Channel6 transfer error flag.
|
||||
* - DMA_FLAG_GL7: Channel7 global flag.
|
||||
* - DMA_FLAG_TC7: Channel7 transfer complete flag.
|
||||
* - DMA_FLAG_HT7: Channel7 half transfer flag.
|
||||
* - DMA_FLAG_TE7: Channel7 transfer error flag.
|
||||
* Output : None
|
||||
* Return : The new state of DMA_FLAG (SET or RESET).
|
||||
*******************************************************************************/
|
||||
FlagStatus DMA_GetFlagStatus(u32 DMA_FLAG)
|
||||
{
|
||||
FlagStatus bitstatus = RESET;
|
||||
|
||||
/* Check the parameters */
|
||||
assert(IS_DMA_GET_FLAG(DMA_FLAG));
|
||||
|
||||
/* Check the status of the specified DMA flag */
|
||||
if ((DMA->ISR & DMA_FLAG) != (u32)RESET)
|
||||
{
|
||||
/* DMA_FLAG is set */
|
||||
bitstatus = SET;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* DMA_FLAG is reset */
|
||||
bitstatus = RESET;
|
||||
}
|
||||
/* Return the DMA_FLAG status */
|
||||
return bitstatus;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : DMA_ClearFlag
|
||||
* Description : Clears the DMA's pending flags.
|
||||
* Input : - DMA_FLAG: specifies the flag to clear.
|
||||
* This parameter can be any combination of the following values:
|
||||
* - DMA_FLAG_GL1: Channel1 global flag.
|
||||
* - DMA_FLAG_TC1: Channel1 transfer complete flag.
|
||||
* - DMA_FLAG_HT1: Channel1 half transfer flag.
|
||||
* - DMA_FLAG_TE1: Channel1 transfer error flag.
|
||||
* - DMA_FLAG_GL2: Channel2 global flag.
|
||||
* - DMA_FLAG_TC2: Channel2 transfer complete flag.
|
||||
* - DMA_FLAG_HT2: Channel2 half transfer flag.
|
||||
* - DMA_FLAG_TE2: Channel2 transfer error flag.
|
||||
* - DMA_FLAG_GL3: Channel3 global flag.
|
||||
* - DMA_FLAG_TC3: Channel3 transfer complete flag.
|
||||
* - DMA_FLAG_HT3: Channel3 half transfer flag.
|
||||
* - DMA_FLAG_TE3: Channel3 transfer error flag.
|
||||
* - DMA_FLAG_GL4: Channel4 global flag.
|
||||
* - DMA_FLAG_TC4: Channel4 transfer complete flag.
|
||||
* - DMA_FLAG_HT4: Channel4 half transfer flag.
|
||||
* - DMA_FLAG_TE4: Channel4 transfer error flag.
|
||||
* - DMA_FLAG_GL5: Channel5 global flag.
|
||||
* - DMA_FLAG_TC5: Channel5 transfer complete flag.
|
||||
* - DMA_FLAG_HT5: Channel5 half transfer flag.
|
||||
* - DMA_FLAG_TE5: Channel5 transfer error flag.
|
||||
* - DMA_FLAG_GL6: Channel6 global flag.
|
||||
* - DMA_FLAG_TC6: Channel6 transfer complete flag.
|
||||
* - DMA_FLAG_HT6: Channel6 half transfer flag.
|
||||
* - DMA_FLAG_TE6: Channel6 transfer error flag.
|
||||
* - DMA_FLAG_GL7: Channel7 global flag.
|
||||
* - DMA_FLAG_TC7: Channel7 transfer complete flag.
|
||||
* - DMA_FLAG_HT7: Channel7 half transfer flag.
|
||||
* - DMA_FLAG_TE7: Channel7 transfer error flag.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void DMA_ClearFlag(u32 DMA_FLAG)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert(IS_DMA_CLEAR_FLAG(DMA_FLAG));
|
||||
|
||||
/* Clear the selected DMA flags */
|
||||
DMA->IFCR = DMA_FLAG;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : DMA_GetITStatus
|
||||
* Description : Checks whether the specified DMA interrupt has occurred or not.
|
||||
* Input : - DMA_IT: specifies the DMA interrupt source to check.
|
||||
* This parameter can be one of the following values:
|
||||
* - DMA_IT_GL1: Channel1 global interrupt.
|
||||
* - DMA_IT_TC1: Channel1 transfer complete interrupt.
|
||||
* - DMA_IT_HT1: Channel1 half transfer interrupt.
|
||||
* - DMA_IT_TE1: Channel1 transfer error interrupt.
|
||||
* - DMA_IT_GL2: Channel2 global interrupt.
|
||||
* - DMA_IT_TC2: Channel2 transfer complete interrupt.
|
||||
* - DMA_IT_HT2: Channel2 half transfer interrupt.
|
||||
* - DMA_IT_TE2: Channel2 transfer error interrupt.
|
||||
* - DMA_IT_GL3: Channel3 global interrupt.
|
||||
* - DMA_IT_TC3: Channel3 transfer complete interrupt.
|
||||
* - DMA_IT_HT3: Channel3 half transfer interrupt.
|
||||
* - DMA_IT_TE3: Channel3 transfer error interrupt.
|
||||
* - DMA_IT_GL4: Channel4 global interrupt.
|
||||
* - DMA_IT_TC4: Channel4 transfer complete interrupt.
|
||||
* - DMA_IT_HT4: Channel4 half transfer interrupt.
|
||||
* - DMA_IT_TE4: Channel4 transfer error interrupt.
|
||||
* - DMA_IT_GL5: Channel5 global interrupt.
|
||||
* - DMA_IT_TC5: Channel5 transfer complete interrupt.
|
||||
* - DMA_IT_HT5: Channel5 half transfer interrupt.
|
||||
* - DMA_IT_TE5: Channel5 transfer error interrupt.
|
||||
* - DMA_IT_GL6: Channel6 global interrupt.
|
||||
* - DMA_IT_TC6: Channel6 transfer complete interrupt.
|
||||
* - DMA_IT_HT6: Channel6 half transfer interrupt.
|
||||
* - DMA_IT_TE6: Channel6 transfer error interrupt.
|
||||
* - DMA_IT_GL7: Channel7 global interrupt.
|
||||
* - DMA_IT_TC7: Channel7 transfer complete interrupt.
|
||||
* - DMA_IT_HT7: Channel7 half transfer interrupt.
|
||||
* - DMA_IT_TE7: Channel7 transfer error interrupt.
|
||||
* Output : None
|
||||
* Return : The new state of DMA_IT (SET or RESET).
|
||||
*******************************************************************************/
|
||||
ITStatus DMA_GetITStatus(u32 DMA_IT)
|
||||
{
|
||||
ITStatus bitstatus = RESET;
|
||||
|
||||
/* Check the parameters */
|
||||
assert(IS_DMA_GET_IT(DMA_IT));
|
||||
|
||||
/* Check the status of the specified DMA interrupt */
|
||||
if ((DMA->ISR & DMA_IT) != (u32)RESET)
|
||||
{
|
||||
/* DMA_IT is set */
|
||||
bitstatus = SET;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* DMA_IT is reset */
|
||||
bitstatus = RESET;
|
||||
}
|
||||
/* Return the DMA_IT status */
|
||||
return bitstatus;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : DMA_ClearITPendingBit
|
||||
* Description : Clears the DMA’s interrupt pending bits.
|
||||
* Input : - DMA_IT: specifies the DMA interrupt pending bit to clear.
|
||||
* This parameter can be any combination of the following values:
|
||||
* - DMA_IT_GL1: Channel1 global interrupt.
|
||||
* - DMA_IT_TC1: Channel1 transfer complete interrupt.
|
||||
* - DMA_IT_HT1: Channel1 half transfer interrupt.
|
||||
* - DMA_IT_TE1: Channel1 transfer error interrupt.
|
||||
* - DMA_IT_GL2: Channel2 global interrupt.
|
||||
* - DMA_IT_TC2: Channel2 transfer complete interrupt.
|
||||
* - DMA_IT_HT2: Channel2 half transfer interrupt.
|
||||
* - DMA_IT_TE2: Channel2 transfer error interrupt.
|
||||
* - DMA_IT_GL3: Channel3 global interrupt.
|
||||
* - DMA_IT_TC3: Channel3 transfer complete interrupt.
|
||||
* - DMA_IT_HT3: Channel3 half transfer interrupt.
|
||||
* - DMA_IT_TE3: Channel3 transfer error interrupt.
|
||||
* - DMA_IT_GL4: Channel4 global interrupt.
|
||||
* - DMA_IT_TC4: Channel4 transfer complete interrupt.
|
||||
* - DMA_IT_HT4: Channel4 half transfer interrupt.
|
||||
* - DMA_IT_TE4: Channel4 transfer error interrupt.
|
||||
* - DMA_IT_GL5: Channel5 global interrupt.
|
||||
* - DMA_IT_TC5: Channel5 transfer complete interrupt.
|
||||
* - DMA_IT_HT5: Channel5 half transfer interrupt.
|
||||
* - DMA_IT_TE5: Channel5 transfer error interrupt.
|
||||
* - DMA_IT_GL6: Channel6 global interrupt.
|
||||
* - DMA_IT_TC6: Channel6 transfer complete interrupt.
|
||||
* - DMA_IT_HT6: Channel6 half transfer interrupt.
|
||||
* - DMA_IT_TE6: Channel6 transfer error interrupt.
|
||||
* - DMA_IT_GL7: Channel7 global interrupt.
|
||||
* - DMA_IT_TC7: Channel7 transfer complete interrupt.
|
||||
* - DMA_IT_HT7: Channel7 half transfer interrupt.
|
||||
* - DMA_IT_TE7: Channel7 transfer error interrupt.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void DMA_ClearITPendingBit(u32 DMA_IT)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert(IS_DMA_CLEAR_IT(DMA_IT));
|
||||
|
||||
/* Clear the selected DMA interrupt pending bits */
|
||||
DMA->IFCR = DMA_IT;
|
||||
}
|
||||
|
||||
/******************* (C) COPYRIGHT 2007 STMicroelectronics *****END OF FILE****/
|
||||
|
|
@ -0,0 +1,219 @@
|
|||
/******************** (C) COPYRIGHT 2007 STMicroelectronics ********************
|
||||
* File Name : stm32f10x_exti.c
|
||||
* Author : MCD Application Team
|
||||
* Date First Issued : 09/29/2006
|
||||
* Description : This file provides all the EXTI firmware functions.
|
||||
********************************************************************************
|
||||
* History:
|
||||
* 04/02/2007: V0.2
|
||||
* 02/05/2007: V0.1
|
||||
* 09/29/2006: V0.01
|
||||
********************************************************************************
|
||||
* THE PRESENT SOFTWARE 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 SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
|
||||
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
|
||||
*******************************************************************************/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32f10x_exti.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
#define EXTI_LineNone ((u32)0x00000) /* No interrupt selected */
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : EXTI_DeInit
|
||||
* Description : Deinitializes the EXTI peripheral registers to their default
|
||||
* reset values.
|
||||
* Input : None
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void EXTI_DeInit(void)
|
||||
{
|
||||
EXTI->IMR = 0x00000000;
|
||||
EXTI->EMR = 0x00000000;
|
||||
EXTI->RTSR = 0x00000000;
|
||||
EXTI->FTSR = 0x00000000;
|
||||
EXTI->PR = 0x0007FFFF;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : EXTI_Init
|
||||
* Description : Initializes the EXTI peripheral according to the specified
|
||||
* parameters in the EXTI_InitStruct.
|
||||
* Input : - EXTI_InitStruct: pointer to a EXTI_InitTypeDef structure
|
||||
* that contains the configuration information for the EXTI
|
||||
* peripheral.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void EXTI_Init(EXTI_InitTypeDef* EXTI_InitStruct)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert(IS_EXTI_MODE(EXTI_InitStruct->EXTI_Mode));
|
||||
assert(IS_EXTI_TRIGGER(EXTI_InitStruct->EXTI_Trigger));
|
||||
assert(IS_EXTI_LINE(EXTI_InitStruct->EXTI_Line));
|
||||
assert(IS_FUNCTIONAL_STATE(EXTI_InitStruct->EXTI_LineCmd));
|
||||
|
||||
if (EXTI_InitStruct->EXTI_LineCmd != DISABLE)
|
||||
{
|
||||
*(u32 *)(EXTI_BASE + (u32)EXTI_InitStruct->EXTI_Mode)|= EXTI_InitStruct->EXTI_Line;
|
||||
|
||||
/* Clear Rising Falling edge configuration */
|
||||
EXTI->RTSR &= ~EXTI_InitStruct->EXTI_Line;
|
||||
EXTI->FTSR &= ~EXTI_InitStruct->EXTI_Line;
|
||||
|
||||
/* Select the trigger for the selected external interrupts */
|
||||
if (EXTI_InitStruct->EXTI_Trigger == EXTI_Trigger_Rising_Falling)
|
||||
{
|
||||
/* Rising Falling edge */
|
||||
EXTI->RTSR |= EXTI_InitStruct->EXTI_Line;
|
||||
EXTI->FTSR |= EXTI_InitStruct->EXTI_Line;
|
||||
}
|
||||
else
|
||||
{
|
||||
*(u32 *)(EXTI_BASE + (u32)EXTI_InitStruct->EXTI_Trigger)|= EXTI_InitStruct->EXTI_Line;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Disable the selected external lines */
|
||||
*(u32 *)(EXTI_BASE + (u32)EXTI_InitStruct->EXTI_Mode)&= ~EXTI_InitStruct->EXTI_Line;
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : EXTI_StructInit
|
||||
* Description : Fills each EXTI_InitStruct member with its reset value.
|
||||
* Input : - EXTI_InitStruct: pointer to a EXTI_InitTypeDef structure
|
||||
* which will be initialized.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void EXTI_StructInit(EXTI_InitTypeDef* EXTI_InitStruct)
|
||||
{
|
||||
EXTI_InitStruct->EXTI_Line = EXTI_LineNone;
|
||||
EXTI_InitStruct->EXTI_Mode = EXTI_Mode_Interrupt;
|
||||
EXTI_InitStruct->EXTI_Trigger = EXTI_Trigger_Falling;
|
||||
EXTI_InitStruct->EXTI_LineCmd = DISABLE;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : EXTI_GenerateSWInterrupt
|
||||
* Description : Generates a Software interrupt.
|
||||
* Input : - EXTI_Line: specifies the EXTI lines to be enabled or
|
||||
* disabled.
|
||||
* This parameter can be:
|
||||
* - EXTI_Linex: External interrupt line x where x(0..18)
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void EXTI_GenerateSWInterrupt(u32 EXTI_Line)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert(IS_EXTI_LINE(EXTI_Line));
|
||||
|
||||
EXTI->SWIER |= EXTI_Line;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : EXTI_GetFlagStatus
|
||||
* Description : Checks whether the specified EXTI line flag is set or not.
|
||||
* Input : - EXTI_Line: specifies the EXTI lines flag to check.
|
||||
* This parameter can be:
|
||||
* - EXTI_Linex: External interrupt line x where x(0..18)
|
||||
* Output : None
|
||||
* Return : The new state of EXTI_Line (SET or RESET).
|
||||
*******************************************************************************/
|
||||
FlagStatus EXTI_GetFlagStatus(u32 EXTI_Line)
|
||||
{
|
||||
FlagStatus bitstatus = RESET;
|
||||
|
||||
/* Check the parameters */
|
||||
assert(IS_GET_EXTI_LINE(EXTI_Line));
|
||||
|
||||
if ((EXTI->PR & EXTI_Line) != (u32)RESET)
|
||||
{
|
||||
bitstatus = SET;
|
||||
}
|
||||
else
|
||||
{
|
||||
bitstatus = RESET;
|
||||
}
|
||||
return bitstatus;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : EXTI_ClearFlag
|
||||
* Description : Clears the EXTI’s line pending flags.
|
||||
* Input : - EXTI_Line: specifies the EXTI lines flags to clear.
|
||||
* This parameter can be:
|
||||
* - EXTI_Linex: External interrupt line x where x(0..18)
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void EXTI_ClearFlag(u32 EXTI_Line)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert(IS_EXTI_LINE(EXTI_Line));
|
||||
|
||||
EXTI->PR = EXTI_Line;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : EXTI_GetITStatus
|
||||
* Description : Checks whether the specified EXTI line is asserted or not.
|
||||
* Input : - EXTI_Line: specifies the EXTI lines to check.
|
||||
* This parameter can be:
|
||||
* - EXTI_Linex: External interrupt line x where x(0..18)
|
||||
* Output : None
|
||||
* Return : The new state of EXTI_Line (SET or RESET).
|
||||
*******************************************************************************/
|
||||
ITStatus EXTI_GetITStatus(u32 EXTI_Line)
|
||||
{
|
||||
ITStatus bitstatus = RESET;
|
||||
u32 enablestatus = 0;
|
||||
|
||||
/* Check the parameters */
|
||||
assert(IS_GET_EXTI_LINE(EXTI_Line));
|
||||
|
||||
enablestatus = EXTI->IMR & EXTI_Line;
|
||||
|
||||
if (((EXTI->PR & EXTI_Line) != (u32)RESET) && enablestatus)
|
||||
{
|
||||
bitstatus = SET;
|
||||
}
|
||||
else
|
||||
{
|
||||
bitstatus = RESET;
|
||||
}
|
||||
return bitstatus;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : EXTI_ClearITPendingBit
|
||||
* Description : Clears the EXTI’s line pending bits.
|
||||
* Input : - EXTI_Line: specifies the EXTI lines to clear.
|
||||
* This parameter can be:
|
||||
* - EXTI_Linex: External interrupt line x where x(0..18)
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void EXTI_ClearITPendingBit(u32 EXTI_Line)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert(IS_EXTI_LINE(EXTI_Line));
|
||||
|
||||
EXTI->PR = EXTI_Line;
|
||||
}
|
||||
|
||||
/******************* (C) COPYRIGHT 2007 STMicroelectronics *****END OF FILE****/
|
|
@ -0,0 +1,515 @@
|
|||
/******************** (C) COPYRIGHT 2007 STMicroelectronics ********************
|
||||
* File Name : stm32f10x_gpio.c
|
||||
* Author : MCD Application Team
|
||||
* Date First Issued : 09/29/2006
|
||||
* Description : This file provides all the GPIO firmware functions.
|
||||
********************************************************************************
|
||||
* History:
|
||||
* 04/02/2007: V0.2
|
||||
* 02/05/2007: V0.1
|
||||
* 09/29/2006: V0.01
|
||||
********************************************************************************
|
||||
* THE PRESENT SOFTWARE 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 SOFTWARE 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)0xF8FFFFFF)
|
||||
#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..E) to select the GPIO peripheral.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void GPIO_DeInit(GPIO_TypeDef* 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;
|
||||
|
||||
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..E) 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(IS_GPIO_MODE(GPIO_InitStruct->GPIO_Mode));
|
||||
assert(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(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;
|
||||
tmpreg = 0;
|
||||
}
|
||||
|
||||
/*---------------------------- 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..E) 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(IS_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..E) to select the GPIO peripheral.
|
||||
* Output : None
|
||||
* Return : GPIO input data port value.
|
||||
*******************************************************************************/
|
||||
u16 GPIO_ReadInputData(GPIO_TypeDef* GPIOx)
|
||||
{
|
||||
return ((u16)GPIOx->IDR);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : GPIO_ReadOutputDataBit
|
||||
* Description : Reads the specified output data port bit.
|
||||
* Input : - GPIOx: where x can be (A..E) 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(IS_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..E) to select the GPIO peripheral.
|
||||
* Output : None
|
||||
* Return : GPIO output data port value.
|
||||
*******************************************************************************/
|
||||
u16 GPIO_ReadOutputData(GPIO_TypeDef* GPIOx)
|
||||
{
|
||||
return ((u16)GPIOx->ODR);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : GPIO_WriteBit
|
||||
* Description : Sets or clears the selected data port bit.
|
||||
* Input : - GPIOx: where x can be (A..E) to select the GPIO peripheral.
|
||||
* - GPIO_Pin: specifies the port bit to be written.
|
||||
* This parameter can be 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(IS_GPIO_PIN(GPIO_Pin));
|
||||
assert(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..E) 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)
|
||||
{
|
||||
GPIOx->ODR = PortVal;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : GPIO_PinLockConfig
|
||||
* Description : Locks GPIO Pins configuration registers.
|
||||
* Input : - GPIOx: where x can be (A..E) to select the GPIO peripheral.
|
||||
* - GPIO_Pin: specifies the port bit to be written.
|
||||
* This parameter can be 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(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(IS_GPIO_PORT_SOURCE(GPIO_PortSource));
|
||||
assert(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(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_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(IS_GPIO_REMAP(GPIO_Remap));
|
||||
assert(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_LOCATION_MASK)
|
||||
{
|
||||
tmpreg &= DBGAFR_SWJCFG_MASK;
|
||||
}
|
||||
else if ((GPIO_Remap & DBGAFR_NUMBITS_MASK) == DBGAFR_NUMBITS_MASK)
|
||||
{
|
||||
tmp1 = ((u32)0x03) << tmpmask;
|
||||
tmpreg &= ~tmp1;
|
||||
}
|
||||
else
|
||||
{
|
||||
tmpreg &= ~tmp;
|
||||
}
|
||||
|
||||
if (NewState != DISABLE)
|
||||
{
|
||||
if ((GPIO_Remap & DBGAFR_LOCATION_MASK) == DBGAFR_LOCATION_MASK)
|
||||
{
|
||||
tmpreg |= (tmp << 0x10);
|
||||
}
|
||||
else
|
||||
{
|
||||
tmpreg |= tmp;
|
||||
}
|
||||
}
|
||||
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.
|
||||
* - 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(IS_GPIO_PORT_SOURCE(GPIO_PortSource));
|
||||
assert(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 2007 STMicroelectronics *****END OF FILE****/
|
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,152 @@
|
|||
/******************** (C) COPYRIGHT 2007 STMicroelectronics ********************
|
||||
* File Name : stm32f10x_iwdg.c
|
||||
* Author : MCD Application Team
|
||||
* Date First Issued : 09/29/2006
|
||||
* Description : This file provides all the IWDG firmware functions.
|
||||
********************************************************************************
|
||||
* History:
|
||||
* 04/02/2007: V0.2
|
||||
* 02/05/2007: V0.1
|
||||
* 09/29/2006: V0.01
|
||||
********************************************************************************
|
||||
* THE PRESENT SOFTWARE 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 SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
|
||||
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
|
||||
*******************************************************************************/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32f10x_iwdg.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* ---------------------- IWDG registers bit mask ------------------------ */
|
||||
/* KR register bit mask */
|
||||
#define KR_Reload ((u16)0xAAAA)
|
||||
#define KR_Enable ((u16)0xCCCC)
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : IWDG_WriteAccessCmd
|
||||
* Description : Enables or disables write access to IWDG_PR and IWDG_RLR
|
||||
* registers.
|
||||
* Input : - IWDG_WriteAccess: new state of write access to IWDG_PR and
|
||||
* IWDG_RLR registers.
|
||||
* This parameter can be one of the following values:
|
||||
* - IWDG_WriteAccess_Enable: Enable write access to
|
||||
* IWDG_PR and IWDG_RLR registers
|
||||
* - IWDG_WriteAccess_Disable: Disable write access to
|
||||
* IWDG_PR and IWDG_RLR registers
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void IWDG_WriteAccessCmd(u16 IWDG_WriteAccess)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert(IS_IWDG_WRITE_ACCESS(IWDG_WriteAccess));
|
||||
|
||||
IWDG->KR = IWDG_WriteAccess;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : IWDG_SetPrescaler
|
||||
* Description : Sets IWDG Prescaler value.
|
||||
* Input : - IWDG_Prescaler: specifies the IWDG Prescaler value.
|
||||
* This parameter can be one of the following values:
|
||||
* - IWDG_Prescaler_4: IWDG prescaler set to 4
|
||||
* - IWDG_Prescaler_8: IWDG prescaler set to 8
|
||||
* - IWDG_Prescaler_16: IWDG prescaler set to 16
|
||||
* - IWDG_Prescaler_32: IWDG prescaler set to 32
|
||||
* - IWDG_Prescaler_64: IWDG prescaler set to 64
|
||||
* - IWDG_Prescaler_128: IWDG prescaler set to 128
|
||||
* - IWDG_Prescaler_256: IWDG prescaler set to 256
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void IWDG_SetPrescaler(u8 IWDG_Prescaler)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert(IS_IWDG_PRESCALER(IWDG_Prescaler));
|
||||
|
||||
IWDG->PR = IWDG_Prescaler;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : IWDG_SetReload
|
||||
* Description : Sets IWDG Reload value.
|
||||
* Input : - Reload: specifies the IWDG Reload value.
|
||||
* This parameter must be a number between 0 and 0x0FFF.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void IWDG_SetReload(u16 Reload)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert(IS_IWDG_RELOAD(Reload));
|
||||
|
||||
IWDG->RLR = Reload;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : IWDG_ReloadCounter
|
||||
* Description : Reloads IWDG counter with value defined in the reload register
|
||||
* (write access to IWDG_PR and IWDG_RLR registers disabled).
|
||||
* Input : None
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void IWDG_ReloadCounter(void)
|
||||
{
|
||||
IWDG->KR = KR_Reload;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : IWDG_Enable
|
||||
* Description : Enables IWDG (write access to IWDG_PR and IWDG_RLR registers
|
||||
* disabled).
|
||||
* Input : None
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void IWDG_Enable(void)
|
||||
{
|
||||
IWDG->KR = KR_Enable;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : IWDG_GetFlagStatus
|
||||
* Description : Checks whether the specified IWDG flag is set or not.
|
||||
* Input : - IWDG_FLAG: specifies the flag to check.
|
||||
* This parameter can be one of the following values:
|
||||
* - IWDG_FLAG_PVU: Prescaler Value Update on going
|
||||
* - IWDG_FLAG_RVU: Reload Value Update on going
|
||||
* Output : None
|
||||
* Return : The new state of IWDG_FLAG (SET or RESET).
|
||||
*******************************************************************************/
|
||||
FlagStatus IWDG_GetFlagStatus(u16 IWDG_FLAG)
|
||||
{
|
||||
FlagStatus bitstatus = RESET;
|
||||
|
||||
/* Check the parameters */
|
||||
assert(IS_IWDG_FLAG(IWDG_FLAG));
|
||||
|
||||
if ((IWDG->SR & IWDG_FLAG) != (u32)RESET)
|
||||
{
|
||||
bitstatus = SET;
|
||||
}
|
||||
else
|
||||
{
|
||||
bitstatus = RESET;
|
||||
}
|
||||
|
||||
/* Return the flag status */
|
||||
return bitstatus;
|
||||
}
|
||||
|
||||
/******************* (C) COPYRIGHT 2007 STMicroelectronics *****END OF FILE****/
|
|
@ -0,0 +1,221 @@
|
|||
/******************** (C) COPYRIGHT 2007 STMicroelectronics ********************
|
||||
* File Name : stm32f10x_lib.c
|
||||
* Author : MCD Application Team
|
||||
* Date First Issued : 09/29/2006
|
||||
* Description : This file provides all peripherals pointers initialization.
|
||||
********************************************************************************
|
||||
* History:
|
||||
* 04/02/2007: V0.2
|
||||
* 02/05/2007: V0.1
|
||||
* 09/29/2006: V0.01
|
||||
********************************************************************************
|
||||
* THE PRESENT SOFTWARE 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 SOFTWARE 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 */
|
||||
|
||||
/************************************* BKP ************************************/
|
||||
#ifdef _BKP
|
||||
BKP = (BKP_TypeDef *) BKP_BASE;
|
||||
#endif /*_BKP */
|
||||
|
||||
/************************************* CAN ************************************/
|
||||
#ifdef _CAN
|
||||
CAN = (CAN_TypeDef *) CAN_BASE;
|
||||
#endif /*_CAN */
|
||||
|
||||
/************************************* DMA ************************************/
|
||||
#ifdef _DMA
|
||||
DMA = (DMA_TypeDef *) DMA_BASE;
|
||||
#endif /*_DMA */
|
||||
|
||||
#ifdef _DMA_Channel1
|
||||
DMA_Channel1 = (DMA_Channel_TypeDef *) DMA_Channel1_BASE;
|
||||
#endif /*_DMA_Channel1 */
|
||||
|
||||
#ifdef _DMA_Channel2
|
||||
DMA_Channel2 = (DMA_Channel_TypeDef *) DMA_Channel2_BASE;
|
||||
#endif /*_DMA_Channel2 */
|
||||
|
||||
#ifdef _DMA_Channel3
|
||||
DMA_Channel3 = (DMA_Channel_TypeDef *) DMA_Channel3_BASE;
|
||||
#endif /*_DMA_Channel3 */
|
||||
|
||||
#ifdef _DMA_Channel4
|
||||
DMA_Channel4 = (DMA_Channel_TypeDef *) DMA_Channel4_BASE;
|
||||
#endif /*_DMA_Channel4 */
|
||||
|
||||
#ifdef _DMA_Channel5
|
||||
DMA_Channel5 = (DMA_Channel_TypeDef *) DMA_Channel5_BASE;
|
||||
#endif /*_DMA_Channel5 */
|
||||
|
||||
#ifdef _DMA_Channel6
|
||||
DMA_Channel6 = (DMA_Channel_TypeDef *) DMA_Channel6_BASE;
|
||||
#endif /*_DMA_Channel6 */
|
||||
|
||||
#ifdef _DMA_Channel7
|
||||
DMA_Channel7 = (DMA_Channel_TypeDef *) DMA_Channel7_BASE;
|
||||
#endif /*_DMA_Channel7 */
|
||||
|
||||
/************************************* EXTI ***********************************/
|
||||
#ifdef _EXTI
|
||||
EXTI = (EXTI_TypeDef *) EXTI_BASE;
|
||||
#endif /*_EXTI */
|
||||
|
||||
/************************************* FLASH and Option Bytes *****************/
|
||||
#ifdef _FLASH
|
||||
FLASH = (FLASH_TypeDef *) FLASH_BASE;
|
||||
OB = (OB_TypeDef *) OB_BASE;
|
||||
#endif /*_FLASH */
|
||||
|
||||
/************************************* 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 _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;
|
||||
#endif /*_NVIC */
|
||||
|
||||
#ifdef _SCB
|
||||
SCB = (SCB_TypeDef *) SCB_BASE;
|
||||
#endif /*_SCB */
|
||||
|
||||
/************************************* 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 */
|
||||
|
||||
/************************************* SPI ************************************/
|
||||
#ifdef _SPI1
|
||||
SPI1 = (SPI_TypeDef *) SPI1_BASE;
|
||||
#endif /*_SPI1 */
|
||||
|
||||
#ifdef _SPI2
|
||||
SPI2 = (SPI_TypeDef *) SPI2_BASE;
|
||||
#endif /*_SPI2 */
|
||||
|
||||
/************************************* SysTick ********************************/
|
||||
#ifdef _SysTick
|
||||
SysTick = (SysTick_TypeDef *) SysTick_BASE;
|
||||
#endif /*_SysTick */
|
||||
|
||||
/************************************* TIM1 ***********************************/
|
||||
#ifdef _TIM1
|
||||
TIM1 = (TIM1_TypeDef *) TIM1_BASE;
|
||||
#endif /*_TIM1 */
|
||||
|
||||
/************************************* TIM ************************************/
|
||||
#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 */
|
||||
|
||||
/************************************* 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 */
|
||||
|
||||
/************************************* WWDG ***********************************/
|
||||
#ifdef _WWDG
|
||||
WWDG = (WWDG_TypeDef *) WWDG_BASE;
|
||||
#endif /*_WWDG */
|
||||
}
|
||||
#endif
|
||||
|
||||
/******************* (C) COPYRIGHT 2007 STMicroelectronics *****END OF FILE****/
|
|
@ -0,0 +1,755 @@
|
|||
/******************** (C) COPYRIGHT 2007 STMicroelectronics ********************
|
||||
* File Name : stm32f10x_nvic.c
|
||||
* Author : MCD Application Team
|
||||
* Date First Issued : 09/29/2006
|
||||
* Description : This file provides all the NVIC firmware functions.
|
||||
********************************************************************************
|
||||
* History:
|
||||
* 04/02/2007: V0.2
|
||||
* 02/05/2007: V0.1
|
||||
* 09/29/2006: V0.01
|
||||
********************************************************************************
|
||||
* THE PRESENT SOFTWARE 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 SOFTWARE 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 AIRC_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->Disable[0] = 0xFFFFFFFF;
|
||||
NVIC->Disable[1] = 0x000007FF;
|
||||
NVIC->Clear[0] = 0xFFFFFFFF;
|
||||
NVIC->Clear[1] = 0x000007FF;
|
||||
|
||||
for(index = 0; index < 0x0B; index++)
|
||||
{
|
||||
NVIC->Priority[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->IRQControlState = 0x0A000000;
|
||||
SCB->ExceptionTableOffset = 0x00000000;
|
||||
SCB->AIRC = AIRC_VECTKEY_MASK;
|
||||
SCB->SysCtrl = 0x00000000;
|
||||
SCB->ConfigCtrl = 0x00000000;
|
||||
for(index = 0; index < 0x03; index++)
|
||||
{
|
||||
SCB->SystemPriority[index] = 0;
|
||||
}
|
||||
SCB->SysHandlerCtrl = 0x00000000;
|
||||
SCB->ConfigFaultStatus = 0xFFFFFFFF;
|
||||
SCB->HardFaultStatus = 0xFFFFFFFF;
|
||||
SCB->DebugFaultStatus = 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(IS_NVIC_PRIORITY_GROUP(NVIC_PriorityGroup));
|
||||
|
||||
/* Set the PRIGROUP[10:8] bits according to NVIC_PriorityGroup value */
|
||||
SCB->AIRC = AIRC_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(IS_FUNCTIONAL_STATE(NVIC_InitStruct->NVIC_IRQChannelCmd));
|
||||
assert(IS_NVIC_IRQ_CHANNEL(NVIC_InitStruct->NVIC_IRQChannel));
|
||||
assert(IS_NVIC_PREEMPTION_PRIORITY(NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority));
|
||||
assert(IS_NVIC_SUB_PRIORITY(NVIC_InitStruct->NVIC_IRQChannelSubPriority));
|
||||
|
||||
if (NVIC_InitStruct->NVIC_IRQChannelCmd != DISABLE)
|
||||
{
|
||||
/* Compute the Corresponding IRQ Priority --------------------------------*/
|
||||
tmppriority = (0x700 - (SCB->AIRC & (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->Priority[(NVIC_InitStruct->NVIC_IRQChannel >> 0x02)];
|
||||
tmpmask = (u32)0xFF << ((NVIC_InitStruct->NVIC_IRQChannel & (u8)0x03) * 0x08);
|
||||
tmpreg &= ~tmpmask;
|
||||
tmppriority &= tmpmask;
|
||||
tmpreg |= tmppriority;
|
||||
|
||||
NVIC->Priority[(NVIC_InitStruct->NVIC_IRQChannel >> 0x02)] = tmpreg;
|
||||
|
||||
/* Enable the Selected IRQ Channels --------------------------------------*/
|
||||
NVIC->Enable[(NVIC_InitStruct->NVIC_IRQChannel >> 0x05)] =
|
||||
(u32)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (u8)0x1F);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Disable the Selected IRQ Channels -------------------------------------*/
|
||||
NVIC->Disable[(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.
|
||||
* Input : None
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void NVIC_BASEPRICONFIG(u32 NewPriority)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert(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->IRQControlState & (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(IS_NVIC_IRQ_CHANNEL(NVIC_IRQChannel));
|
||||
|
||||
tmp = ((u32)0x01 << (NVIC_IRQChannel & (u32)0x1F));
|
||||
|
||||
if (((NVIC->Set[(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(IS_NVIC_IRQ_CHANNEL(NVIC_IRQChannel));
|
||||
|
||||
*(u32*)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(IS_NVIC_IRQ_CHANNEL(NVIC_IRQChannel));
|
||||
|
||||
NVIC->Clear[(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->IRQControlState & (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(IS_NVIC_IRQ_CHANNEL(NVIC_IRQChannel));
|
||||
|
||||
tmp = ((u32)0x01 << (NVIC_IRQChannel & (u32)0x1F));
|
||||
|
||||
if (((NVIC->Active[(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
|
||||
* code memory.
|
||||
* This parameter can be one of the following values:
|
||||
* - NVIC_VectTab_RAM
|
||||
* - NVIC_VectTab_FLASH
|
||||
* - Offset: Vector Table base offset field.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void NVIC_SetVectorTable(u32 NVIC_VectTab, u32 Offset)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert(IS_NVIC_VECTTAB(NVIC_VectTab));
|
||||
assert(IS_NVIC_OFFSET(Offset));
|
||||
|
||||
SCB->ExceptionTableOffset = (((u32)Offset << 0x07) & (u32)0x1FFFFF80);
|
||||
|
||||
SCB->ExceptionTableOffset |= NVIC_VectTab;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : NVIC_GenerateSystemReset
|
||||
* Description : Generates a system reset.
|
||||
* Input : None
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void NVIC_GenerateSystemReset(void)
|
||||
{
|
||||
SCB->AIRC = AIRC_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->AIRC = AIRC_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(IS_NVIC_LP(LowPowerMode));
|
||||
assert(IS_FUNCTIONAL_STATE(NewState));
|
||||
|
||||
if (NewState != DISABLE)
|
||||
{
|
||||
SCB->SysCtrl |= LowPowerMode;
|
||||
}
|
||||
else
|
||||
{
|
||||
SCB->SysCtrl &= (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(IS_CONFIG_SYSTEM_HANDLER(SystemHandler));
|
||||
assert(IS_FUNCTIONAL_STATE(NewState));
|
||||
|
||||
tmpreg = (u32)0x01 << (SystemHandler & (u32)0x1F);
|
||||
|
||||
if (NewState != DISABLE)
|
||||
{
|
||||
SCB->SysHandlerCtrl |= tmpreg;
|
||||
}
|
||||
else
|
||||
{
|
||||
SCB->SysHandlerCtrl &= ~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(IS_PRIORITY_SYSTEM_HANDLER(SystemHandler));
|
||||
assert(IS_NVIC_PREEMPTION_PRIORITY(SystemHandlerPreemptionPriority));
|
||||
assert(IS_NVIC_SUB_PRIORITY(SystemHandlerSubPriority));
|
||||
|
||||
tmppriority = (0x700 - (SCB->AIRC & (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->SystemPriority[tmp1] &= ~handlermask;
|
||||
SCB->SystemPriority[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(IS_GET_PENDING_SYSTEM_HANDLER(SystemHandler));
|
||||
|
||||
tmppos = (SystemHandler >> 0x0A);
|
||||
tmppos &= (u32)0x0F;
|
||||
|
||||
tmppos = (u32)0x01 << tmppos;
|
||||
|
||||
tmp = SCB->SysHandlerCtrl & 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(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->IRQControlState |= ((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(IS_CLEAR_SYSTEM_HANDLER(SystemHandler));
|
||||
|
||||
/* Get the System Handler pending bit position */
|
||||
tmp = SystemHandler & (u32)0x1F;
|
||||
/* Clear the corresponding System Handler pending bit */
|
||||
SCB->IRQControlState |= ((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(IS_GET_ACTIVE_SYSTEM_HANDLER(SystemHandler));
|
||||
|
||||
tmppos = (SystemHandler >> 0x0E) & (u32)0x0F;
|
||||
|
||||
tmppos = (u32)0x01 << tmppos;
|
||||
|
||||
tmp = SCB->SysHandlerCtrl & 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(IS_FAULT_SOURCE_SYSTEM_HANDLER(SystemHandler));
|
||||
|
||||
tmpreg = (SystemHandler >> 0x12) & (u32)0x03;
|
||||
tmppos = (SystemHandler >> 0x14) & (u32)0x03;
|
||||
|
||||
if (tmpreg == 0x00)
|
||||
{
|
||||
faultsources = SCB->HardFaultStatus;
|
||||
}
|
||||
else if (tmpreg == 0x01)
|
||||
{
|
||||
faultsources = SCB->ConfigFaultStatus >> (tmppos * 0x08);
|
||||
if (tmppos != 0x02)
|
||||
{
|
||||
faultsources &= (u32)0x0F;
|
||||
}
|
||||
else
|
||||
{
|
||||
faultsources &= (u32)0xFF;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
faultsources = SCB->DebugFaultStatus;
|
||||
}
|
||||
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(IS_FAULT_ADDRESS_SYSTEM_HANDLER(SystemHandler));
|
||||
|
||||
tmp = (SystemHandler >> 0x16) & (u32)0x01;
|
||||
|
||||
if (tmp == 0x00)
|
||||
{
|
||||
faultaddress = SCB->MemoryManageFaultAddr;
|
||||
}
|
||||
else
|
||||
{
|
||||
faultaddress = SCB->BusFaultAddr;
|
||||
}
|
||||
return faultaddress;
|
||||
}
|
||||
|
||||
/******************* (C) COPYRIGHT 2007 STMicroelectronics *****END OF FILE****/
|
|
@ -0,0 +1,283 @@
|
|||
/******************** (C) COPYRIGHT 2007 STMicroelectronics ********************
|
||||
* File Name : stm32f10x_pwr.c
|
||||
* Author : MCD Application Team
|
||||
* Date First Issued : 09/29/2006
|
||||
* Description : This file provides all the PWR firmware functions.
|
||||
********************************************************************************
|
||||
* History:
|
||||
* 04/02/2007: V0.2
|
||||
* 02/05/2007: V0.1
|
||||
* 09/29/2006: V0.01
|
||||
********************************************************************************
|
||||
* THE PRESENT SOFTWARE 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 SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
|
||||
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
|
||||
*******************************************************************************/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32f10x_pwr.h"
|
||||
#include "stm32f10x_rcc.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* --------- PWR registers bit address in the alias region ---------- */
|
||||
#define PWR_OFFSET (PWR_BASE - PERIPH_BASE)
|
||||
|
||||
/* --- CR Register ---*/
|
||||
/* Alias word address of DBP bit */
|
||||
#define CR_OFFSET (PWR_OFFSET + 0x00)
|
||||
#define DBP_BitNumber 0x08
|
||||
#define CR_DBP_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (DBP_BitNumber * 4))
|
||||
|
||||
/* Alias word address of PVDE bit */
|
||||
#define PVDE_BitNumber 0x04
|
||||
#define CR_PVDE_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (PVDE_BitNumber * 4))
|
||||
|
||||
/* --- CSR Register ---*/
|
||||
/* Alias word address of EWUP bit */
|
||||
#define CSR_OFFSET (PWR_OFFSET + 0x04)
|
||||
#define EWUP_BitNumber 0x08
|
||||
#define CSR_EWUP_BB (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (EWUP_BitNumber * 4))
|
||||
|
||||
/* ------------------ PWR registers bit mask ------------------------ */
|
||||
/* CR register bit mask */
|
||||
#define CR_PDDS_Set ((u32)0x00000002)
|
||||
#define CR_DS_Mask ((u32)0xFFFFFFFC)
|
||||
#define CR_CWUF_Set ((u32)0x00000004)
|
||||
#define CR_PLS_Mask ((u32)0xFFFFFF1F)
|
||||
|
||||
/* --------- Cortex System Control register bit mask ---------------- */
|
||||
/* Cortex System Control register address */
|
||||
#define SCB_SysCtrl ((u32)0xE000ED10)
|
||||
/* SLEEPDEEP bit mask */
|
||||
#define SysCtrl_SLEEPDEEP_Set ((u32)0x00000004)
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : PWR_DeInit
|
||||
* Description : Deinitializes the PWR peripheral registers to their default
|
||||
* reset values.
|
||||
* Input : None
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void PWR_DeInit(void)
|
||||
{
|
||||
RCC_APB1PeriphResetCmd(RCC_APB1Periph_PWR, ENABLE);
|
||||
RCC_APB1PeriphResetCmd(RCC_APB1Periph_PWR, DISABLE);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : PWR_BackupAccessCmd
|
||||
* Description : Enables or disables access to the RTC and backup registers.
|
||||
* Input : - NewState: new state of the access to the RTC and backup
|
||||
* registers. This parameter can be: ENABLE or DISABLE.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void PWR_BackupAccessCmd(FunctionalState NewState)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert(IS_FUNCTIONAL_STATE(NewState));
|
||||
|
||||
*(vu32 *) CR_DBP_BB = (u32)NewState;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : PWR_PVDCmd
|
||||
* Description : Enables or disables the Power Voltage Detector(PVD).
|
||||
* Input : - NewState: new state of the PVD.
|
||||
* This parameter can be: ENABLE or DISABLE.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void PWR_PVDCmd(FunctionalState NewState)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert(IS_FUNCTIONAL_STATE(NewState));
|
||||
|
||||
*(vu32 *) CR_PVDE_BB = (u32)NewState;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : PWR_PVDLevelConfig
|
||||
* Description : Configures the value detected by the Power Voltage Detector(PVD).
|
||||
* Input : - PWR_PVDLevel: specifies the PVD detection level
|
||||
* This parameter can be one of the following values:
|
||||
* - PWR_PVDLevel_2V2: PVD detection level set to 2.2V
|
||||
* - PWR_PVDLevel_2V3: PVD detection level set to 2.3V
|
||||
* - PWR_PVDLevel_2V4: PVD detection level set to 2.4V
|
||||
* - PWR_PVDLevel_2V5: PVD detection level set to 2.5V
|
||||
* - PWR_PVDLevel_2V6: PVD detection level set to 2.6V
|
||||
* - PWR_PVDLevel_2V7: PVD detection level set to 2.7V
|
||||
* - PWR_PVDLevel_2V8: PVD detection level set to 2.8V
|
||||
* - PWR_PVDLevel_2V9: PVD detection level set to 2.9V
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void PWR_PVDLevelConfig(u32 PWR_PVDLevel)
|
||||
{
|
||||
u32 tmpreg = 0;
|
||||
|
||||
/* Check the parameters */
|
||||
assert(IS_PWR_PVD_LEVEL(PWR_PVDLevel));
|
||||
|
||||
tmpreg = PWR->CR;
|
||||
|
||||
/* Clear PLS[7:5] bits */
|
||||
tmpreg &= CR_PLS_Mask;
|
||||
|
||||
/* Set PLS[7:5] bits according to PWR_PVDLevel value */
|
||||
tmpreg |= PWR_PVDLevel;
|
||||
|
||||
/* Store the new value */
|
||||
PWR->CR = tmpreg;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : PWR_WakeUpPinCmd
|
||||
* Description : Enables or disables the WakeUp Pin functionality.
|
||||
* Input : - NewState: new state of the WakeUp Pin functionality.
|
||||
* This parameter can be: ENABLE or DISABLE.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void PWR_WakeUpPinCmd(FunctionalState NewState)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert(IS_FUNCTIONAL_STATE(NewState));
|
||||
|
||||
*(vu32 *) CSR_EWUP_BB = (u32)NewState;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : PWR_EnterSTOPMode
|
||||
* Description : Enters STOP mode.
|
||||
* Input : - PWR_Regulator: specifies the regulator state in STOP mode.
|
||||
* This parameter can be one of the following values:
|
||||
* - PWR_Regulator_ON: STOP mode with regulator ON
|
||||
* - PWR_Regulator_LowPower: STOP mode with
|
||||
* regulator in low power mode
|
||||
* - PWR_STOPEntry: specifies if STOP mode in entered with WFI or
|
||||
* WFE instruction.
|
||||
* This parameter can be one of the following values:
|
||||
* - PWR_STOPEntry_WFI: enter STOP mode with WFI instruction
|
||||
* - PWR_STOPEntry_WFE: enter STOP mode with WFE instruction
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void PWR_EnterSTOPMode(u32 PWR_Regulator, u8 PWR_STOPEntry)
|
||||
{
|
||||
u32 tmpreg = 0;
|
||||
|
||||
/* Check the parameters */
|
||||
assert(IS_PWR_REGULATOR(PWR_Regulator));
|
||||
assert(IS_PWR_STOP_ENTRY(PWR_STOPEntry));
|
||||
|
||||
/* Select the regulator state in STOP mode ---------------------------------*/
|
||||
tmpreg = PWR->CR;
|
||||
|
||||
/* Clear PDDS and LPDS bits */
|
||||
tmpreg &= CR_DS_Mask;
|
||||
|
||||
/* Set LPDS bit according to PWR_Regulator value */
|
||||
tmpreg |= PWR_Regulator;
|
||||
|
||||
/* Store the new value */
|
||||
PWR->CR = tmpreg;
|
||||
|
||||
/* Set SLEEPDEEP bit of Cortex System Control Register */
|
||||
*(vu32 *) SCB_SysCtrl |= SysCtrl_SLEEPDEEP_Set;
|
||||
|
||||
/* Select STOP mode entry --------------------------------------------------*/
|
||||
if(PWR_STOPEntry == PWR_STOPEntry_WFI)
|
||||
{
|
||||
/* Request Wait For Interrupt */
|
||||
__WFI();
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Request Wait For Event */
|
||||
__WFE();
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : PWR_EnterSTANDBYMode
|
||||
* Description : Enters STANDBY mode.
|
||||
* Input : None
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void PWR_EnterSTANDBYMode(void)
|
||||
{
|
||||
/* Clear Wake-up flag */
|
||||
PWR->CR |= CR_CWUF_Set;
|
||||
|
||||
/* Select STANDBY mode */
|
||||
PWR->CR |= CR_PDDS_Set;
|
||||
|
||||
/* Set SLEEPDEEP bit of Cortex System Control Register */
|
||||
*(vu32 *) SCB_SysCtrl |= SysCtrl_SLEEPDEEP_Set;
|
||||
|
||||
/* Request Wait For Interrupt */
|
||||
__WFI();
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : PWR_GetFlagStatus
|
||||
* Description : Checks whether the specified PWR flag is set or not.
|
||||
* Input : - PWR_FLAG: specifies the flag to check.
|
||||
* This parameter can be one of the following values:
|
||||
* - PWR_FLAG_WU: Wake Up flag
|
||||
* - PWR_FLAG_SB: StandBy flag
|
||||
* - PWR_FLAG_PVDO: PVD Output
|
||||
* Output : None
|
||||
* Return : The new state of PWR_FLAG (SET or RESET).
|
||||
*******************************************************************************/
|
||||
FlagStatus PWR_GetFlagStatus(u32 PWR_FLAG)
|
||||
{
|
||||
FlagStatus bitstatus = RESET;
|
||||
|
||||
/* Check the parameters */
|
||||
assert(IS_PWR_GET_FLAG(PWR_FLAG));
|
||||
|
||||
if ((PWR->CSR & PWR_FLAG) != (u32)RESET)
|
||||
{
|
||||
bitstatus = SET;
|
||||
}
|
||||
else
|
||||
{
|
||||
bitstatus = RESET;
|
||||
}
|
||||
|
||||
/* Return the flag status */
|
||||
return bitstatus;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : PWR_ClearFlag
|
||||
* Description : Clears the PWR's pending flags.
|
||||
* Input : - PWR_FLAG: specifies the flag to clear.
|
||||
* This parameter can be one of the following values:
|
||||
* - PWR_FLAG_WU: Wake Up flag
|
||||
* - PWR_FLAG_SB: StandBy flag
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void PWR_ClearFlag(u32 PWR_FLAG)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert(IS_PWR_CLEAR_FLAG(PWR_FLAG));
|
||||
|
||||
PWR->CR |= PWR_FLAG << 2;
|
||||
}
|
||||
|
||||
/******************* (C) COPYRIGHT 2007 STMicroelectronics *****END OF FILE****/
|
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,342 @@
|
|||
/******************** (C) COPYRIGHT 2007 STMicroelectronics ********************
|
||||
* File Name : stm32f10x_rtc.c
|
||||
* Author : MCD Application Team
|
||||
* Date First Issued : 09/29/2006
|
||||
* Description : This file provides all the RTC firmware functions.
|
||||
********************************************************************************
|
||||
* History:
|
||||
* 04/02/2007: V0.2
|
||||
* 02/05/2007: V0.1
|
||||
* 09/29/2006: V0.01
|
||||
********************************************************************************
|
||||
* THE PRESENT SOFTWARE 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 SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
|
||||
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
|
||||
*******************************************************************************/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32f10x_rtc.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
#define CRL_CNF_Set ((u16)0x0010) /* Configuration Flag Enable Mask */
|
||||
#define CRL_CNF_Reset ((u16)0xFFEF) /* Configuration Flag Disable Mask */
|
||||
#define RTC_LSB_Mask ((u32)0x0000FFFF) /* RTC LSB Mask */
|
||||
#define RTC_MSB_Mask ((u32)0xFFFF0000) /* RTC MSB Mask */
|
||||
#define PRLH_MSB_Mask ((u32)0x000F0000) /* RTC Prescaler MSB Mask */
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : RTC_ITConfig
|
||||
* Description : Enables or disables the specified RTC interrupts.
|
||||
* Input : - RTC_IT: specifies the RTC interrupts sources to be enabled
|
||||
* or disabled.
|
||||
* This parameter can be any combination of the following values:
|
||||
* - RTC_IT_OW: Overflow interrupt
|
||||
* - RTC_IT_ALR: Alarm interrupt
|
||||
* - RTC_IT_SEC: Second interrupt
|
||||
* - NewState: new state of the specified RTC interrupts.
|
||||
* This parameter can be: ENABLE or DISABLE.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void RTC_ITConfig(u16 RTC_IT, FunctionalState NewState)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert(IS_RTC_IT(RTC_IT));
|
||||
assert(IS_FUNCTIONAL_STATE(NewState));
|
||||
|
||||
if (NewState != DISABLE)
|
||||
{
|
||||
RTC->CRH |= RTC_IT;
|
||||
}
|
||||
else
|
||||
{
|
||||
RTC->CRH &= (u16)~RTC_IT;
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : RTC_EnterConfigMode
|
||||
* Description : Enters the RTC configuration mode.
|
||||
* Input : None
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void RTC_EnterConfigMode(void)
|
||||
{
|
||||
/* Set the CNF flag to enter in the Configuration Mode */
|
||||
RTC->CRL |= CRL_CNF_Set;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : RTC_ExitConfigMode
|
||||
* Description : Exits from the RTC configuration mode.
|
||||
* Input : None
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void RTC_ExitConfigMode(void)
|
||||
{
|
||||
/* Reset the CNF flag to exit from the Configuration Mode */
|
||||
RTC->CRL &= CRL_CNF_Reset;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : RTC_GetCounter
|
||||
* Description : Gets the RTC counter value.
|
||||
* Input : None
|
||||
* Output : None
|
||||
* Return : RTC counter value.
|
||||
*******************************************************************************/
|
||||
u32 RTC_GetCounter(void)
|
||||
{
|
||||
u16 tmp = 0;
|
||||
tmp = RTC->CNTL;
|
||||
|
||||
return (((u32)RTC->CNTH << 16 ) | tmp) ;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : RTC_SetCounter
|
||||
* Description : Sets the RTC counter value.
|
||||
* Input : - CounterValue: RTC counter new value.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void RTC_SetCounter(u32 CounterValue)
|
||||
{
|
||||
RTC_EnterConfigMode();
|
||||
|
||||
/* Set RTC COUNTER MSB word */
|
||||
RTC->CNTH = (CounterValue & RTC_MSB_Mask) >> 16;
|
||||
/* Set RTC COUNTER LSB word */
|
||||
RTC->CNTL = (CounterValue & RTC_LSB_Mask);
|
||||
|
||||
RTC_ExitConfigMode();
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : RTC_GetPrescaler
|
||||
* Description : Gets the RTC prescaler value.
|
||||
* Input : None
|
||||
* Output : None
|
||||
* Return : RTC prescaler value.
|
||||
*******************************************************************************/
|
||||
u32 RTC_GetPrescaler(void)
|
||||
{
|
||||
u32 tmp = 0x00;
|
||||
|
||||
tmp = ((u32)RTC->PRLH & (u32)0x000F) << 0x10;
|
||||
tmp |= RTC->PRLL;
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : RTC_SetPrescaler
|
||||
* Description : Sets the RTC prescaler value.
|
||||
* Input : - PrescalerValue: RTC prescaler new value.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void RTC_SetPrescaler(u32 PrescalerValue)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert(IS_RTC_PRESCALER(PrescalerValue));
|
||||
|
||||
RTC_EnterConfigMode();
|
||||
|
||||
/* Set RTC PRESCALER MSB word */
|
||||
RTC->PRLH = (PrescalerValue & PRLH_MSB_Mask) >> 0x10;
|
||||
/* Set RTC PRESCALER LSB word */
|
||||
RTC->PRLL = (PrescalerValue & RTC_LSB_Mask);
|
||||
|
||||
RTC_ExitConfigMode();
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : RTC_SetAlarm
|
||||
* Description : Sets the RTC alarm value.
|
||||
* Input : - AlarmValue: RTC alarm new value.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void RTC_SetAlarm(u32 AlarmValue)
|
||||
{
|
||||
RTC_EnterConfigMode();
|
||||
|
||||
/* Set the ALARM MSB word */
|
||||
RTC->ALRH = (AlarmValue & RTC_MSB_Mask) >> 16;
|
||||
/* Set the ALARM LSB word */
|
||||
RTC->ALRL = (AlarmValue & RTC_LSB_Mask);
|
||||
|
||||
RTC_ExitConfigMode();
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : RTC_GetDivider
|
||||
* Description : Gets the RTC divider value.
|
||||
* Input : None
|
||||
* Output : None
|
||||
* Return : RTC Divider value.
|
||||
*******************************************************************************/
|
||||
u32 RTC_GetDivider(void)
|
||||
{
|
||||
u32 tmp = 0x00;
|
||||
|
||||
tmp = ((u32)RTC->DIVH & (u32)0x000F) << 0x10;
|
||||
tmp |= RTC->DIVL;
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : RTC_WaitForLastTask
|
||||
* Description : Waits until last write operation on RTC registers has finished.
|
||||
* This function must be called before any write to RTC registers.
|
||||
* Input : None
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void RTC_WaitForLastTask(void)
|
||||
{
|
||||
/* Loop until RTOFF flag is set */
|
||||
while ((RTC->CRL & RTC_FLAG_RTOFF) == (u16)RESET)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : RTC_WaitForSynchro
|
||||
* Description : Waits until the RTC registers (RTC_CNT, RTC_ALR and RTC_PRL)
|
||||
* are synchronized with RTC APB clock.
|
||||
* This function must be called before any read operation after
|
||||
* an APB reset or an APB clock stop.
|
||||
* Input : None
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void RTC_WaitForSynchro(void)
|
||||
{
|
||||
/* Clear RSF flag */
|
||||
RTC->CRL &= (u16)~RTC_FLAG_RSF;
|
||||
|
||||
/* Loop until RSF flag is set */
|
||||
while ((RTC->CRL & RTC_FLAG_RSF) == (u16)RESET)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : RTC_GetFlagStatus
|
||||
* Description : Checks whether the specified RTC flag is set or not.
|
||||
* Input : - RTC_FLAG: specifies the flag to check.
|
||||
* This parameter can be one the following values:
|
||||
* - RTC_FLAG_RTOFF: RTC Operation OFF flag
|
||||
* - RTC_FLAG_RSF: Registers Synchronized flag
|
||||
* - RTC_FLAG_OW: Overflow flag
|
||||
* - RTC_FLAG_ALR: Alarm flag
|
||||
* - RTC_FLAG_SEC: Second flag
|
||||
* Output : None
|
||||
* Return : The new state of RTC_FLAG (SET or RESET).
|
||||
*******************************************************************************/
|
||||
FlagStatus RTC_GetFlagStatus(u16 RTC_FLAG)
|
||||
{
|
||||
FlagStatus bitstatus = RESET;
|
||||
|
||||
/* Check the parameters */
|
||||
assert(IS_RTC_GET_FLAG(RTC_FLAG));
|
||||
|
||||
if ((RTC->CRL & RTC_FLAG) != (u16)RESET)
|
||||
{
|
||||
bitstatus = SET;
|
||||
}
|
||||
else
|
||||
{
|
||||
bitstatus = RESET;
|
||||
}
|
||||
return bitstatus;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : RTC_ClearFlag
|
||||
* Description : Clears the RTC’s pending flags.
|
||||
* Input : - RTC_FLAG: specifies the flag to clear.
|
||||
* This parameter can be any combination of the following values:
|
||||
* - RTC_FLAG_RSF: Registers Synchronized flag. This flag
|
||||
* is cleared only after an APB reset or an APB Clock stop.
|
||||
* - RTC_FLAG_OW: Overflow flag
|
||||
* - RTC_FLAG_ALR: Alarm flag
|
||||
* - RTC_FLAG_SEC: Second flag
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void RTC_ClearFlag(u16 RTC_FLAG)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert(IS_RTC_CLEAR_FLAG(RTC_FLAG));
|
||||
|
||||
/* Clear the coressponding RTC flag */
|
||||
RTC->CRL &= (u16)~RTC_FLAG;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : RTC_GetITStatus
|
||||
* Description : Checks whether the specified RTC interrupt has occured or not.
|
||||
* Input : - RTC_IT: specifies the RTC interrupts sources to check.
|
||||
* This parameter can be one of the following values:
|
||||
* - RTC_IT_OW: Overflow interrupt
|
||||
* - RTC_IT_ALR: Alarm interrupt
|
||||
* - RTC_IT_SEC: Second interrupt
|
||||
* Output : None
|
||||
* Return : The new state of the RTC_IT (SET or RESET).
|
||||
*******************************************************************************/
|
||||
ITStatus RTC_GetITStatus(u16 RTC_IT)
|
||||
{
|
||||
ITStatus bitstatus = RESET;
|
||||
|
||||
/* Check the parameters */
|
||||
assert(IS_RTC_GET_IT(RTC_IT));
|
||||
|
||||
bitstatus = (ITStatus)((RTC->CRL & RTC_IT) != (u16)RESET);
|
||||
|
||||
if (((RTC->CRH & RTC_IT) != (u16)RESET) && bitstatus)
|
||||
{
|
||||
bitstatus = SET;
|
||||
}
|
||||
else
|
||||
{
|
||||
bitstatus = RESET;
|
||||
}
|
||||
return bitstatus;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : RTC_ClearITPendingBit
|
||||
* Description : Clears the RTC’s interrupt pending bits.
|
||||
* Input : - RTC_IT: specifies the interrupt pending bit to clear.
|
||||
* This parameter can be any combination of the following values:
|
||||
* - RTC_IT_OW: Overflow interrupt
|
||||
* - RTC_IT_ALR: Alarm interrupt
|
||||
* - RTC_IT_SEC: Second interrupt
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void RTC_ClearITPendingBit(u16 RTC_IT)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert(IS_RTC_IT(RTC_IT));
|
||||
|
||||
/* Clear the coressponding RTC pending bit */
|
||||
RTC->CRL &= (u16)~RTC_IT;
|
||||
}
|
||||
|
||||
/******************* (C) COPYRIGHT 2007 STMicroelectronics *****END OF FILE****/
|
|
@ -0,0 +1,658 @@
|
|||
/******************** (C) COPYRIGHT 2007 STMicroelectronics ********************
|
||||
* File Name : stm32f10x_spi.c
|
||||
* Author : MCD Application Team
|
||||
* Date First Issued : 09/29/2006
|
||||
* Description : This file provides all the SPI firmware functions.
|
||||
********************************************************************************
|
||||
* History:
|
||||
* 04/02/2007: V0.2
|
||||
* 02/05/2007: V0.1
|
||||
* 09/29/2006: V0.01
|
||||
********************************************************************************
|
||||
* THE PRESENT SOFTWARE 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 SOFTWARE 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)
|
||||
|
||||
/* 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)
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SPI_DeInit
|
||||
* Description : Deinitializes the SPIx peripheral registers to their default
|
||||
* reset values.
|
||||
* Input : - SPIx: where x can be 1 or 2 to select the SPI peripheral.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void SPI_DeInit(SPI_TypeDef* 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;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SPI_Init
|
||||
* Description : Initializes the SPIx according to the specified parameters
|
||||
* in the SPI_InitStruct.
|
||||
* Input : - SPIx: where x can be 1 or 2 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(IS_SPI_DIRECTION_MODE(SPI_InitStruct->SPI_Direction));
|
||||
assert(IS_SPI_MODE(SPI_InitStruct->SPI_Mode));
|
||||
assert(IS_SPI_DATASIZE(SPI_InitStruct->SPI_DataSize));
|
||||
assert(IS_SPI_CPOL(SPI_InitStruct->SPI_CPOL));
|
||||
assert(IS_SPI_CPHA(SPI_InitStruct->SPI_CPHA));
|
||||
assert(IS_SPI_NSS(SPI_InitStruct->SPI_NSS));
|
||||
assert(IS_SPI_BAUDRATE_PRESCALER(SPI_InitStruct->SPI_BaudRatePrescaler));
|
||||
assert(IS_SPI_FIRST_BIT(SPI_InitStruct->SPI_FirstBit));
|
||||
assert(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;
|
||||
|
||||
/*---------------------------- SPIx CRCPOLY Configuration --------------------*/
|
||||
/* Write to SPIx CRCPOLY */
|
||||
SPIx->CRCPR = SPI_InitStruct->SPI_CRCPolynomial;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* 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 : SPI_Cmd
|
||||
* Description : Enables or disables the specified SPI peripheral.
|
||||
* Input : - SPIx: where x can be 1 or 2 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(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 : SPI_ITConfig
|
||||
* Description : Enables or disables the specified SPI interrupts.
|
||||
* Input : - SPIx: where x can be 1 or 2 to select the SPI peripheral.
|
||||
* - SPI_IT: specifies the SPI interrupts sources to be enabled
|
||||
* or disabled.
|
||||
* This parameter can be one of the following values:
|
||||
* - SPI_IT_TXE: Tx buffer empty interrupt mask
|
||||
* - SPI_IT_RXNE: Rx buffer not empty interrupt mask
|
||||
* - SPI_IT_ERR: Error interrupt mask
|
||||
* - NewState: new state of the specified SPI interrupts.
|
||||
* This parameter can be: ENABLE or DISABLE.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void SPI_ITConfig(SPI_TypeDef* SPIx, u8 SPI_IT, FunctionalState NewState)
|
||||
{
|
||||
u16 itpos = 0, itmask = 0 ;
|
||||
|
||||
/* Check the parameters */
|
||||
assert(IS_FUNCTIONAL_STATE(NewState));
|
||||
assert(IS_SPI_CONFIG_IT(SPI_IT));
|
||||
|
||||
/* Get the SPI IT index */
|
||||
itpos = SPI_IT >> 4;
|
||||
/* Set the IT mask */
|
||||
itmask = (u16)((u16)1 << itpos);
|
||||
|
||||
if (NewState != DISABLE)
|
||||
{
|
||||
/* Enable the selected SPI interrupt */
|
||||
SPIx->CR2 |= itmask;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Disable the selected SPI interrupt */
|
||||
SPIx->CR2 &= (u16)~itmask;
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SPI_DMACmd
|
||||
* Description : Enables or disables the SPIx’s DMA interface.
|
||||
* Input : - SPIx: where x can be 1 or 2 to select the SPI peripheral.
|
||||
* - SPI_DMAReq: specifies the SPI DMA transfer request to be
|
||||
* enabled or disabled.
|
||||
* This parameter can be any combination of the following values:
|
||||
* - SPI_DMAReq_Tx: Tx buffer DMA transfer request
|
||||
* - SPI_DMAReq_Rx: Rx buffer DMA transfer request
|
||||
* - NewState: new state of the selected SPI DMA transfer request.
|
||||
* This parameter can be: ENABLE or DISABLE.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void SPI_DMACmd(SPI_TypeDef* SPIx, u16 SPI_DMAReq, FunctionalState NewState)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert(IS_FUNCTIONAL_STATE(NewState));
|
||||
assert(IS_SPI_DMA_REQ(SPI_DMAReq));
|
||||
|
||||
if (NewState != DISABLE)
|
||||
{
|
||||
/* Enable the selected SPI DMA requests */
|
||||
SPIx->CR2 |= SPI_DMAReq;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Disable the selected SPI DMA requests */
|
||||
SPIx->CR2 &= (u16)~SPI_DMAReq;
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SPI_SendData
|
||||
* Description : Transmits a Data through the SPIx peripheral.
|
||||
* Input : - SPIx: where x can be 1 or 2 to select the SPI peripheral.
|
||||
* - Data : Data to be transmitted..
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void SPI_SendData(SPI_TypeDef* SPIx, u16 Data)
|
||||
{
|
||||
/* Write in the DR register the data to be sent */
|
||||
SPIx->DR = Data;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SPI_ReceiveData
|
||||
* Description : Returns the most recent received data by the SPIx peripheral.
|
||||
* Input : - SPIx: where x can be 1 or 2 to select the SPI peripheral.
|
||||
* Output : None
|
||||
* Return : The value of the received data.
|
||||
*******************************************************************************/
|
||||
u16 SPI_ReceiveData(SPI_TypeDef* 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 or 2 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(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 or 2 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(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 or 2 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(IS_SPI_DATASIZE(SPI_DataSize));
|
||||
|
||||
if (SPI_DataSize != SPI_DataSize_8b)
|
||||
{
|
||||
/* Set data frame format to 16bit */
|
||||
SPIx->CR1 |= SPI_DataSize_16b;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Set data frame format to 8bit */
|
||||
SPIx->CR1 &= SPI_DataSize_8b;
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SPI_TransmitCRC
|
||||
* Description : Transmit the SPIx CRC value.
|
||||
* Input : - SPIx: where x can be 1 or 2 to select the SPI peripheral.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void SPI_TransmitCRC(SPI_TypeDef* 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 or 2 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(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 or 2 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(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 or 2 to select the SPI peripheral.
|
||||
* Output : None
|
||||
* Return : The CRC Polynomial register value.
|
||||
*******************************************************************************/
|
||||
u16 SPI_GetCRCPolynomial(SPI_TypeDef* 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 or 2 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(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_GetFlagStatus
|
||||
* Description : Checks whether the specified SPI flag is set or not.
|
||||
* Input : - SPIx: where x can be 1 or 2 to select the SPI peripheral.
|
||||
* - SPI_FLAG: specifies the flag to check.
|
||||
* This parameter can be one of the following values:
|
||||
* - SPI_FLAG_BSY: Busy flag.
|
||||
* - SPI_FLAG_OVR: Overrun flag.
|
||||
* - SPI_FLAG_MODF: Mode Fault flag.
|
||||
* - SPI_FLAG_CRCERR: CRC Error flag.
|
||||
* - SPI_FLAG_TXE: Transmit buffer empty flag.
|
||||
* - SPI_FLAG_RXNE: Receive buffer not empty flag.
|
||||
* Output : None
|
||||
* Return : The new state of SPI_FLAG (SET or RESET).
|
||||
*******************************************************************************/
|
||||
FlagStatus SPI_GetFlagStatus(SPI_TypeDef* SPIx, u16 SPI_FLAG)
|
||||
{
|
||||
FlagStatus bitstatus = RESET;
|
||||
|
||||
/* Check the parameters */
|
||||
assert(IS_SPI_GET_FLAG(SPI_FLAG));
|
||||
|
||||
/* Check the status of the specified SPI flag */
|
||||
if ((SPIx->SR & SPI_FLAG) != (u16)RESET)
|
||||
{
|
||||
/* SPI_FLAG is set */
|
||||
bitstatus = SET;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* SPI_FLAG is reset */
|
||||
bitstatus = RESET;
|
||||
}
|
||||
/* Return the SPI_FLAG status */
|
||||
return bitstatus;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SPI_ClearFlag
|
||||
* Description : Clears the SPIx's pending flags.
|
||||
* Input : - SPIx: where x can be 1 or 2 to select the SPI peripheral.
|
||||
* - SPI_FLAG: specifies the flag to clear.
|
||||
* This parameter can be any combination of the following values:
|
||||
* - SPI_FLAG_OVR: Overrun flag.
|
||||
* - SPI_FLAG_MODF: Mode Fault flag.
|
||||
* - SPI_FLAG_CRCERR: CRC Error flag.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void SPI_ClearFlag(SPI_TypeDef* SPIx, u16 SPI_FLAG)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert(IS_SPI_CLEAR_FLAG(SPI_FLAG));
|
||||
|
||||
/* SPI_FLAG_MODF flag clear */
|
||||
if(SPI_FLAG == SPI_FLAG_MODF)
|
||||
{
|
||||
/* Read SR register */
|
||||
(void)SPIx->SR;
|
||||
/* Write on CR1 register */
|
||||
SPIx->CR1 |= CR1_SPE_Set;
|
||||
}
|
||||
/* SPI_FLAG_OVR flag clear */
|
||||
else if(SPI_FLAG == SPI_FLAG_OVR)
|
||||
{
|
||||
/* Read SR register */
|
||||
(void)SPIx->SR;
|
||||
}
|
||||
else /* SPI_FLAG_CRCERR flag clear */
|
||||
{
|
||||
/* Clear the selected SPI flag */
|
||||
SPIx->SR &= (u16)~SPI_FLAG;
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SPI_GetITStatus
|
||||
* Description : Checks whether the specified SPI interrupt has occurred or not.
|
||||
* Input : - SPIx: where x can be 1 or 2 to select the SPI peripheral.
|
||||
* - SPI_IT: specifies the SPI interrupt source to check.
|
||||
* This parameter can be one of the following values:
|
||||
* - SPI_IT_OVR: Overrun interrupt.
|
||||
* - SPI_IT_MODF: Mode Fault interrupt.
|
||||
* - SPI_IT_CRCERR: CRC Error interrupt.
|
||||
* - SPI_IT_TXE: Transmit buffer empty interrupt.
|
||||
* - SPI_IT_RXNE: Receive buffer not empty interrupt.
|
||||
* Output : None
|
||||
* Return : The new state of SPI_IT (SET or RESET).
|
||||
*******************************************************************************/
|
||||
ITStatus SPI_GetITStatus(SPI_TypeDef* SPIx, u8 SPI_IT)
|
||||
{
|
||||
ITStatus bitstatus = RESET;
|
||||
u16 itpos = 0, itmask = 0, enablestatus = 0;
|
||||
|
||||
/* Check the parameters */
|
||||
assert(IS_SPI_GET_IT(SPI_IT));
|
||||
|
||||
/* Get the SPI IT index */
|
||||
itpos = (u16)((u16)0x01 << (SPI_IT & (u8)0x0F));
|
||||
|
||||
/* Get the SPI IT index */
|
||||
itmask = SPI_IT >> 4;
|
||||
/* Set the IT mask */
|
||||
itmask = (u16)((u16)0x01 << itmask);
|
||||
/* Get the SPI_IT enable bit status */
|
||||
enablestatus = (SPIx->CR2 & itmask) ;
|
||||
|
||||
/* Check the status of the specified SPI interrupt */
|
||||
if (((SPIx->SR & itpos) != (u16)RESET) && enablestatus)
|
||||
{
|
||||
/* SPI_IT is set */
|
||||
bitstatus = SET;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* SPI_IT is reset */
|
||||
bitstatus = RESET;
|
||||
}
|
||||
/* Return the SPI_IT status */
|
||||
return bitstatus;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SPI_ClearITPendingBit
|
||||
* Description : Clears the SPI’s interrupt pending bits.
|
||||
* Input : - SPIx: where x can be 1 or 2 to select the SPI peripheral.
|
||||
* - SPI_IT: specifies the SPI interrupt pending bit to clear.
|
||||
* This parameter can be one of the following values:
|
||||
* - SPI_IT_OVR: Overrun interrupt.
|
||||
* - SPI_IT_MODF: Mode Fault interrupt.
|
||||
* - SPI_IT_CRCERR: CRC Error interrupt.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void SPI_ClearITPendingBit(SPI_TypeDef* SPIx, u8 SPI_IT)
|
||||
{
|
||||
u16 itpos = 0;
|
||||
|
||||
/* Check the parameters */
|
||||
assert(IS_SPI_CLEAR_IT(SPI_IT));
|
||||
|
||||
/* SPI_IT_MODF pending bit clear */
|
||||
if(SPI_IT == SPI_IT_MODF)
|
||||
{
|
||||
/* Read SR register */
|
||||
(void)SPIx->SR;
|
||||
/* Write on CR1 register */
|
||||
SPIx->CR1 |= CR1_SPE_Set;
|
||||
}
|
||||
else if(SPI_IT == SPI_IT_OVR) /* SPI_IT_OVR pending bit clear */
|
||||
{
|
||||
/* Read SR register */
|
||||
(void)(SPIx->SR);
|
||||
}
|
||||
else /* SPI_IT_CRCERR pending bit clear */
|
||||
{
|
||||
/* Get the SPI IT index */
|
||||
itpos = (u16)((u16)0x01 << (SPI_IT & (u8)0x0F));
|
||||
/* Clear the selected SPI interrupt pending bits */
|
||||
SPIx->SR &= (u16)~itpos;
|
||||
}
|
||||
}
|
||||
|
||||
/******************* (C) COPYRIGHT 2007 STMicroelectronics *****END OF FILE****/
|
|
@ -0,0 +1,195 @@
|
|||
/******************** (C) COPYRIGHT 2007 STMicroelectronics ********************
|
||||
* File Name : stm32f10x_systick.c
|
||||
* Author : MCD Application Team
|
||||
* Date First Issued : 09/29/2006
|
||||
* Description : This file provides all the SysTick firmware functions.
|
||||
********************************************************************************
|
||||
* History:
|
||||
* 04/02/2007: V0.2
|
||||
* 02/05/2007: V0.1
|
||||
* 09/29/2006: V0.01
|
||||
********************************************************************************
|
||||
* THE PRESENT SOFTWARE 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 SOFTWARE 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)
|
||||
|
||||
/* SysTick Flag Mask */
|
||||
#define FLAG_Mask ((u8)0x1F)
|
||||
|
||||
/* 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(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(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(IS_SYSTICK_COUNTER(SysTick_Counter));
|
||||
|
||||
if (SysTick_Counter == SysTick_Counter_Clear)
|
||||
{
|
||||
SysTick->VAL = SysTick_Counter_Clear;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (SysTick_Counter == SysTick_Counter_Enable)
|
||||
{
|
||||
SysTick->CTRL |= SysTick_Counter_Enable;
|
||||
}
|
||||
else
|
||||
{
|
||||
SysTick->CTRL &= SysTick_Counter_Disable;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* 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(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 tmp = 0;
|
||||
u32 statusreg = 0;
|
||||
FlagStatus bitstatus = RESET;
|
||||
|
||||
/* Check the parameters */
|
||||
assert(IS_SYSTICK_FLAG(SysTick_FLAG));
|
||||
|
||||
/* Get the SysTick register index */
|
||||
tmp = SysTick_FLAG >> 5;
|
||||
|
||||
if (tmp == 1) /* The flag to check is in CTRL register */
|
||||
{
|
||||
statusreg = SysTick->CTRL;
|
||||
}
|
||||
else /* The flag to check is in CALIB register */
|
||||
{
|
||||
statusreg = SysTick->CALIB;
|
||||
}
|
||||
|
||||
/* Get the flag position */
|
||||
tmp = SysTick_FLAG & FLAG_Mask;
|
||||
|
||||
if ((statusreg & ((u32)1 << tmp)) != (u32)RESET)
|
||||
{
|
||||
bitstatus = SET;
|
||||
}
|
||||
else
|
||||
{
|
||||
bitstatus = RESET;
|
||||
}
|
||||
return bitstatus;
|
||||
}
|
||||
|
||||
/******************* (C) COPYRIGHT 2007 STMicroelectronics *****END OF FILE****/
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,852 @@
|
|||
/******************** (C) COPYRIGHT 2007 STMicroelectronics ********************
|
||||
* File Name : stm32f10x_usart.c
|
||||
* Author : MCD Application Team
|
||||
* Date First Issued : 09/29/2006
|
||||
* Description : This file provides all the USART firmware functions.
|
||||
********************************************************************************
|
||||
* History:
|
||||
* 04/02/2007: V0.2
|
||||
* 02/05/2007: V0.1
|
||||
* 09/29/2006: V0.01
|
||||
********************************************************************************
|
||||
* THE PRESENT SOFTWARE 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 SOFTWARE 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 RUN Mask */
|
||||
#define CR1_RUN_Set ((u16)0x2000) /* USART Enable Mask */
|
||||
#define CR1_RUN_Reset ((u16)0xDFFF) /* USART Disable Mask */
|
||||
|
||||
#define CR2_Address_Mask ((u16)0xFFF0) /* USART address 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 USART_IT_Mask ((u16)0x001F) /* USART Interrupt Mask */
|
||||
|
||||
/* USART LIN Mask */
|
||||
#define CR2_LINE_Set ((u16)0x4000) /* USART LIN Enable Mask */
|
||||
#define CR2_LINE_Reset ((u16)0xBFFF) /* USART LIN Disable Mask */
|
||||
|
||||
#define CR1_SBK_Set ((u16)0x0001) /* USART Break Character send 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 */
|
||||
|
||||
/* USART LIN Break detection */
|
||||
#define CR3_LBDL_Mask ((u16)0xFFDF) /* USART LIN Break detection Mask */
|
||||
|
||||
/* USART WakeUp Method */
|
||||
#define CR3_WAKE_Mask ((u16)0xF7FF) /* USART WakeUp Method 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 CR1_CLEAR_Mask ((u16)0xE9F3) /* USART CR1 Mask */
|
||||
#define CR2_CLEAR_Mask ((u16)0xC0FF) /* USART CR2 Mask */
|
||||
#define CR3_CLEAR_Mask ((u16)0xFCFF) /* USART CR3 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: where x can be 1, 2 or 3 to select the USART
|
||||
* peripheral.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void USART_DeInit(USART_TypeDef* 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;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : USART_Init
|
||||
* Description : Initializes the USARTx peripheral according to the specified
|
||||
* parameters in the USART_InitStruct .
|
||||
* Input : - USARTx: where x can be 1, 2 or 3 to select the USART peripheral.
|
||||
* - 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;
|
||||
RCC_ClocksTypeDef RCC_ClocksStatus;
|
||||
|
||||
/* Check the parameters */
|
||||
assert(IS_USART_WORD_LENGTH(USART_InitStruct->USART_WordLength));
|
||||
assert(IS_USART_STOPBITS(USART_InitStruct->USART_StopBits));
|
||||
assert(IS_USART_PARITY(USART_InitStruct->USART_Parity));
|
||||
assert(IS_USART_HARDWARE_FLOW_CONTROL(USART_InitStruct->USART_HardwareFlowControl));
|
||||
assert(IS_USART_MODE(USART_InitStruct->USART_Mode));
|
||||
assert(IS_USART_CLOCK(USART_InitStruct->USART_Clock));
|
||||
assert(IS_USART_CPOL(USART_InitStruct->USART_CPOL));
|
||||
assert(IS_USART_CPHA(USART_InitStruct->USART_CPHA));
|
||||
assert(IS_USART_LASTBIT(USART_InitStruct->USART_LastBit));
|
||||
|
||||
/*---------------------------- USART CR2 Configuration -----------------------*/
|
||||
tmpreg = USARTx->CR2;
|
||||
/* Clear STOP[13:12], CLKEN, CPOL, CPHA and LBCL bits */
|
||||
tmpreg &= CR2_CLEAR_Mask;
|
||||
|
||||
/* Configure the USART Stop Bits, Clock, CPOL, CPHA and LastBit ------------*/
|
||||
/* Set STOP[13:12] bits according to USART_Mode 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_InitStruct->USART_StopBits | USART_InitStruct->USART_Clock |
|
||||
USART_InitStruct->USART_CPOL | USART_InitStruct->USART_CPHA |
|
||||
USART_InitStruct->USART_LastBit;
|
||||
|
||||
/* Write to USART CR2 */
|
||||
USARTx->CR2 = (u16)tmpreg;
|
||||
|
||||
/*---------------------------- USART CR1 Configuration -----------------------*/
|
||||
tmpreg = 0x00;
|
||||
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 = 0x00;
|
||||
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 -----------------------*/
|
||||
tmpreg = 0x00;
|
||||
|
||||
/* Configure the USART Baud Rate -------------------------------------------*/
|
||||
RCC_GetClocksFreq(&RCC_ClocksStatus);
|
||||
if ((*(u32*)&USARTx) == 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 = 0x2580; /* 9600 Baud */
|
||||
USART_InitStruct->USART_WordLength = USART_WordLength_8b;
|
||||
USART_InitStruct->USART_StopBits = USART_StopBits_1;
|
||||
USART_InitStruct->USART_Parity = USART_Parity_No ;
|
||||
USART_InitStruct->USART_HardwareFlowControl = USART_HardwareFlowControl_None;
|
||||
USART_InitStruct->USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
|
||||
USART_InitStruct->USART_Clock = USART_Clock_Disable;
|
||||
USART_InitStruct->USART_CPOL = USART_CPOL_Low;
|
||||
USART_InitStruct->USART_CPHA = USART_CPHA_1Edge;
|
||||
USART_InitStruct->USART_LastBit = USART_LastBit_Disable;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : USART_Cmd
|
||||
* Description : Enables or disables the specified USART peripheral.
|
||||
* Input : - USARTx: where x can be 1, 2 or 3 to select the USART
|
||||
* peripheral.
|
||||
* : - 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(IS_FUNCTIONAL_STATE(NewState));
|
||||
|
||||
if (NewState != DISABLE)
|
||||
{
|
||||
/* Enable the selected USART by setting the RUN bit in the CR1 register */
|
||||
USARTx->CR1 |= CR1_RUN_Set;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Disable the selected USART by clearing the RUN bit in the CR1 register */
|
||||
USARTx->CR1 &= CR1_RUN_Reset;
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : USART_ITConfig
|
||||
* Description : Enables or disables the specified USART interrupts.
|
||||
* Input : - USARTx: where x can be 1, 2 or 3 to select the USART
|
||||
* peripheral.
|
||||
* - USART_IT: specifies the USART interrupt sources to be
|
||||
* enabled or disabled.
|
||||
* This parameter can be one of the following values:
|
||||
* - USART_IT_PE
|
||||
* - USART_IT_TXE
|
||||
* - USART_IT_TC
|
||||
* - USART_IT_RXNE
|
||||
* - USART_IT_IDLE
|
||||
* - USART_IT_LBD
|
||||
* - USART_IT_CTS
|
||||
* - USART_IT_ERR
|
||||
* - 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 address = 0x00;
|
||||
|
||||
/* Check the parameters */
|
||||
assert(IS_USART_CONFIG_IT(USART_IT));
|
||||
assert(IS_FUNCTIONAL_STATE(NewState));
|
||||
|
||||
/* Get the USART register index */
|
||||
usartreg = (((u8)USART_IT) >> 0x05);
|
||||
|
||||
/* Get the interrupt position */
|
||||
itpos = USART_IT & USART_IT_Mask;
|
||||
|
||||
itmask = (((u32)0x01) << itpos);
|
||||
address = *(u32*)&(USARTx);
|
||||
|
||||
if (usartreg == 0x01) /* The IT is in CR1 register */
|
||||
{
|
||||
address += 0x0C;
|
||||
}
|
||||
else if (usartreg == 0x02) /* The IT is in CR2 register */
|
||||
{
|
||||
address += 0x10;
|
||||
}
|
||||
else /* The IT is in CR3 register */
|
||||
{
|
||||
address += 0x14;
|
||||
}
|
||||
if (NewState != DISABLE)
|
||||
{
|
||||
*(u32*)address |= itmask;
|
||||
}
|
||||
else
|
||||
{
|
||||
*(u32*)address &= ~itmask;
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : USART_DMACmd
|
||||
* Description : Enables or disables the USART’s DMA interface.
|
||||
* Input : - USARTx: where x can be 1, 2 or 3 to select the USART
|
||||
* peripheral.
|
||||
* - USART_DMAReq: specifies the DMA request.
|
||||
* This parameter can be any combination of the following values:
|
||||
* - USART_DMAReq_Tx
|
||||
* - USART_DMAReq_Rx
|
||||
* - 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(IS_USART_DMAREQ(USART_DMAReq));
|
||||
assert(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: where x can be 1, 2 or 3 to select the USART
|
||||
* peripheral.
|
||||
* - 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(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: where x can be 1, 2 or 3 to select the USART
|
||||
* peripheral.
|
||||
* - USART_WakeUp: specifies the USART wakeup method.
|
||||
* This parameter can be one of the following values:
|
||||
* - USART_WakeUp_IdleLine
|
||||
* - USART_WakeUp_AddressMark
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void USART_WakeUpConfig(USART_TypeDef* USARTx, u16 USART_WakeUp)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert(IS_USART_WAKEUP(USART_WakeUp));
|
||||
|
||||
USARTx->CR1 &= CR3_WAKE_Mask;
|
||||
USARTx->CR1 |= USART_WakeUp;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : USART_ReceiverWakeUpCmd
|
||||
* Description : Determines if the USART is in mute mode or not.
|
||||
* Input : - USARTx: where x can be 1, 2 or 3 to select the USART
|
||||
* peripheral.
|
||||
* - NewState: new state of the USART mode.
|
||||
* This parameter can be: ENABLE or DISABLE.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void USART_ReceiverWakeUpCmd(USART_TypeDef* USARTx, FunctionalState NewState)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert(IS_FUNCTIONAL_STATE(NewState));
|
||||
|
||||
if (NewState != DISABLE)
|
||||
{
|
||||
/* Enable the mute mode USART by setting the RWU bit in the CR1 register */
|
||||
USARTx->CR1 |= CR1_RWU_Set;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Disable the mute mode USART 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: where x can be 1, 2 or 3 to select the USART
|
||||
* peripheral.
|
||||
* - USART_LINBreakDetectLength: specifies the LIN break
|
||||
* detection length.
|
||||
* This parameter can be one of the following values:
|
||||
* - USART_LINBreakDetectLength_10b
|
||||
* - USART_LINBreakDetectLength_11b
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void USART_LINBreakDetectLengthConfig(USART_TypeDef* USARTx, u16 USART_LINBreakDetectLength)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert(IS_USART_LIN_BREAK_DETECT_LENGTH(USART_LINBreakDetectLength));
|
||||
|
||||
USARTx->CR2 &= CR3_LBDL_Mask;
|
||||
USARTx->CR2 |= USART_LINBreakDetectLength;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : USART_LINCmd
|
||||
* Description : Enables or disables the USART’s LIN mode.
|
||||
* Input : - USARTx: where x can be 1, 2 or 3 to select the USART
|
||||
* peripheral.
|
||||
* - 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(IS_FUNCTIONAL_STATE(NewState));
|
||||
|
||||
if (NewState != DISABLE)
|
||||
{
|
||||
/* Enable the LIN mode by setting the LINE bit in the CR2 register */
|
||||
USARTx->CR2 |= CR2_LINE_Set;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Disable the LIN mode by clearing the LINE bit in the CR2 register */
|
||||
USARTx->CR2 &= CR2_LINE_Reset;
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : USART_SendData
|
||||
* Description : Transmits signle data through the USARTx peripheral.
|
||||
* Input : - USARTx: where x can be 1, 2 or 3 to select the USART
|
||||
* peripheral.
|
||||
* - Data: the data to transmit.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void USART_SendData(USART_TypeDef* USARTx, u16 Data)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert(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: where x can be 1, 2 or 3 to select the USART
|
||||
* peripheral.
|
||||
* Output : None
|
||||
* Return : The received data.
|
||||
*******************************************************************************/
|
||||
u16 USART_ReceiveData(USART_TypeDef* USARTx)
|
||||
{
|
||||
/* Receive Data */
|
||||
return (u16)(USARTx->DR & (u16)0x01FF);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : USART_SendBreak
|
||||
* Description : Transmits break characters.
|
||||
* Input : - USARTx: where x can be 1, 2 or 3 to select the USART
|
||||
* peripheral.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void USART_SendBreak(USART_TypeDef* 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.
|
||||
* - USART_GuardTime: specifies the guard time.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void USART_SetGuardTime(USART_TypeDef* USARTx, u8 USART_GuardTime)
|
||||
{
|
||||
/* 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: where x can be 1, 2 or 3 to select the USART
|
||||
* peripheral.
|
||||
* - USART_Prescaler: specifies the prescaler clock.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void USART_SetPrescaler(USART_TypeDef* USARTx, u8 USART_Prescaler)
|
||||
{
|
||||
/* 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.
|
||||
* - 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(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.
|
||||
* - 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(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: where x can be 1, 2 or 3 to select the USART
|
||||
* peripheral.
|
||||
* - 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(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: where x can be 1, 2 or 3 to select the USART
|
||||
* peripheral.
|
||||
* - 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(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: where x can be 1, 2 or 3 to select the USART
|
||||
* peripheral.
|
||||
* - 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(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: where x can be 1, 2 or 3 to select the USART
|
||||
* peripheral.
|
||||
* - USART_FLAG: specifies the flag to check.
|
||||
* This parameter can be one of the following values:
|
||||
* - USART_FLAG_CTS
|
||||
* - USART_FLAG_LBD
|
||||
* - USART_FLAG_TXE
|
||||
* - USART_FLAG_TC
|
||||
* - USART_FLAG_RXNE
|
||||
* - USART_FLAG_IDLE
|
||||
* - USART_FLAG_ORE
|
||||
* - USART_FLAG_NE
|
||||
* - USART_FLAG_FE
|
||||
* - USART_FLAG_PE
|
||||
* 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(IS_USART_FLAG(USART_FLAG));
|
||||
|
||||
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: where x can be 1, 2 or 3 to select the USART
|
||||
* peripheral.
|
||||
* - USART_FLAG: specifies the flag to clear.
|
||||
* This parameter can be any combination of the following values:
|
||||
* - USART_FLAG_CTS
|
||||
* - USART_FLAG_LBD
|
||||
* - USART_FLAG_TXE
|
||||
* - USART_FLAG_TC
|
||||
* - USART_FLAG_RXNE
|
||||
* - USART_FLAG_IDLE
|
||||
* - USART_FLAG_ORE
|
||||
* - USART_FLAG_NE
|
||||
* - USART_FLAG_FE
|
||||
* - USART_FLAG_PE
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void USART_ClearFlag(USART_TypeDef* USARTx, u16 USART_FLAG)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert(IS_USART_CLEAR_FLAG(USART_FLAG));
|
||||
|
||||
USARTx->SR &= (u16)~USART_FLAG;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : USART_GetITStatus
|
||||
* Description : Checks whether the specified USART interrupt has occurred or not.
|
||||
* Input : - USARTx: where x can be 1, 2 or 3 to select the USART
|
||||
* peripheral.
|
||||
* - USART_IT: specifies the USART interrupt source to check.
|
||||
* This parameter can be one of the following values:
|
||||
* - USART_IT_PE
|
||||
* - USART_IT_TXE
|
||||
* - USART_IT_TC
|
||||
* - USART_IT_RXNE
|
||||
* - USART_IT_IDLE
|
||||
* - USART_IT_LBD
|
||||
* - USART_IT_CTS
|
||||
* - USART_IT_ORE
|
||||
* - USART_IT_NE
|
||||
* - USART_IT_FE
|
||||
* 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 = 0;
|
||||
ITStatus bitstatus = RESET;
|
||||
|
||||
/* Check the parameters */
|
||||
assert(IS_USART_IT(USART_IT));
|
||||
|
||||
/* Get the USART register index */
|
||||
usartreg = (((u8)USART_IT) >> 0x05);
|
||||
|
||||
/* Get the interrupt position */
|
||||
itmask = USART_IT & USART_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: where x can be 1, 2 or 3 to select the USART
|
||||
* peripheral.
|
||||
* - USART_IT: specifies the interrupt pending bit to clear.
|
||||
* This parameter can be one of the following values:
|
||||
* - USART_IT_PE
|
||||
* - USART_IT_TXE
|
||||
* - USART_IT_TC
|
||||
* - USART_IT_RXNE
|
||||
* - USART_IT_IDLE
|
||||
* - USART_IT_LBD
|
||||
* - USART_IT_CTS
|
||||
* - USART_IT_ORE
|
||||
* - USART_IT_NE
|
||||
* - USART_IT_FE
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void USART_ClearITPendingBit(USART_TypeDef* USARTx, u16 USART_IT)
|
||||
{
|
||||
u32 bitpos = 0x00, itmask = 0x00;
|
||||
|
||||
/* Check the parameters */
|
||||
assert(IS_USART_IT(USART_IT));
|
||||
|
||||
bitpos = USART_IT >> 0x08;
|
||||
|
||||
itmask = (u32)0x01 << bitpos;
|
||||
USARTx->SR &= ~itmask;
|
||||
}
|
||||
|
||||
/******************* (C) COPYRIGHT 2007 STMicroelectronics *****END OF FILE****/
|
|
@ -0,0 +1,194 @@
|
|||
/******************** (C) COPYRIGHT 2007 STMicroelectronics ********************
|
||||
* File Name : stm32f10x_wwdg.c
|
||||
* Author : MCD Application Team
|
||||
* Date First Issued : 09/29/2006
|
||||
* Description : This file provides all the WWDG firmware functions.
|
||||
********************************************************************************
|
||||
* History:
|
||||
* 04/02/2007: V0.2
|
||||
* 02/05/2007: V0.1
|
||||
* 09/29/2006: V0.01
|
||||
********************************************************************************
|
||||
* THE PRESENT SOFTWARE 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 SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
|
||||
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
|
||||
*******************************************************************************/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32f10x_wwdg.h"
|
||||
#include "stm32f10x_rcc.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* ----------- WWDG registers bit address in the alias region ----------- */
|
||||
#define WWDG_OFFSET (WWDG_BASE - PERIPH_BASE)
|
||||
|
||||
/* Alias word address of EWI bit */
|
||||
#define CFR_OFFSET (WWDG_OFFSET + 0x04)
|
||||
#define EWI_BitNumber 0x09
|
||||
#define CFR_EWI_BB (PERIPH_BB_BASE + (CFR_OFFSET * 32) + (EWI_BitNumber * 4))
|
||||
|
||||
/* Alias word address of EWIF bit */
|
||||
#define SR_OFFSET (WWDG_OFFSET + 0x08)
|
||||
#define EWIF_BitNumber 0x00
|
||||
#define SR_EWIF_BB (PERIPH_BB_BASE + (SR_OFFSET * 32) + (EWIF_BitNumber * 4))
|
||||
|
||||
/* --------------------- WWDG registers bit mask ------------------------ */
|
||||
/* CR register bit mask */
|
||||
#define CR_WDGA_Set ((u32)0x00000080)
|
||||
|
||||
/* CFR register bit mask */
|
||||
#define CFR_WDGTB_Mask ((u32)0xFFFFFE7F)
|
||||
#define CFR_W_Mask ((u32)0xFFFFFF80)
|
||||
|
||||
#define BIT_Mask ((u8)0x7F)
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : WWDG_DeInit
|
||||
* Description : Deinitializes the WWDG peripheral registers to their default
|
||||
* reset values.
|
||||
* Input : None
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void WWDG_DeInit(void)
|
||||
{
|
||||
RCC_APB1PeriphResetCmd(RCC_APB1Periph_WWDG, ENABLE);
|
||||
RCC_APB1PeriphResetCmd(RCC_APB1Periph_WWDG, DISABLE);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : WWDG_SetPrescaler
|
||||
* Description : Sets the WWDG Prescaler.
|
||||
* Input : - WWDG_Prescaler: specifies the WWDG Prescaler.
|
||||
* This parameter can be one of the following values:
|
||||
* - WWDG_Prescaler_1: WWDG counter clock = (PCLK1/4096)/1
|
||||
* - WWDG_Prescaler_2: WWDG counter clock = (PCLK1/4096)/2
|
||||
* - WWDG_Prescaler_4: WWDG counter clock = (PCLK1/4096)/4
|
||||
* - WWDG_Prescaler_8: WWDG counter clock = (PCLK1/4096)/8
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void WWDG_SetPrescaler(u32 WWDG_Prescaler)
|
||||
{
|
||||
u32 tmpreg = 0;
|
||||
|
||||
/* Check the parameters */
|
||||
assert(IS_WWDG_PRESCALER(WWDG_Prescaler));
|
||||
|
||||
/* Clear WDGTB[8:7] bits */
|
||||
tmpreg = WWDG->CFR & CFR_WDGTB_Mask;
|
||||
|
||||
/* Set WDGTB[8:7] bits according to WWDG_Prescaler value */
|
||||
tmpreg |= WWDG_Prescaler;
|
||||
|
||||
/* Store the new value */
|
||||
WWDG->CFR = tmpreg;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : WWDG_SetWindowValue
|
||||
* Description : Sets the WWDG window value.
|
||||
* Input : - WindowValue: specifies the window value to be compared to
|
||||
* the downcounter.
|
||||
* This parameter value must be lower than 0x80.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void WWDG_SetWindowValue(u8 WindowValue)
|
||||
{
|
||||
u32 tmpreg = 0;
|
||||
|
||||
/* Check the parameters */
|
||||
assert(IS_WWDG_WINDOW_VALUE(WindowValue));
|
||||
|
||||
/* Clear W[6:0] bits */
|
||||
tmpreg = WWDG->CFR & CFR_W_Mask;
|
||||
|
||||
/* Set W[6:0] bits according to WindowValue value */
|
||||
tmpreg |= WindowValue & BIT_Mask;
|
||||
|
||||
/* Store the new value */
|
||||
WWDG->CFR = tmpreg;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : WWDG_EnableIT
|
||||
* Description : Enables the WWDG Early Wakeup interrupt(EWI).
|
||||
* Input : None
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void WWDG_EnableIT(void)
|
||||
{
|
||||
*(vu32 *) CFR_EWI_BB = (u32)ENABLE;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : WWDG_SetCounter
|
||||
* Description : Sets the WWDG counter value.
|
||||
* Input : - Counter: specifies the watchdog counter value.
|
||||
* This parameter must be a number between 0x40 and 0x7F.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void WWDG_SetCounter(u8 Counter)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert(IS_WWDG_COUNTER(Counter));
|
||||
|
||||
/* Write to T[6:0] bits to configure the counter value, no need to do
|
||||
a read-modify-write; writing a 0 to WDGA bit does nothing */
|
||||
WWDG->CR = Counter & BIT_Mask;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : WWDG_Enable
|
||||
* Description : Enables WWDG and load the counter value.
|
||||
* - Counter: specifies the watchdog counter value.
|
||||
* This parameter must be a number between 0x40 and 0x7F.
|
||||
* Input : None
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void WWDG_Enable(u8 Counter)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert(IS_WWDG_COUNTER(Counter));
|
||||
|
||||
WWDG->CR = CR_WDGA_Set | Counter;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : WWDG_GetFlagStatus
|
||||
* Description : Checks whether the Early Wakeup interrupt flag is set or not.
|
||||
* Input : None
|
||||
* Output : None
|
||||
* Return : The new state of the Early Wakeup interrupt flag (SET or RESET)
|
||||
*******************************************************************************/
|
||||
FlagStatus WWDG_GetFlagStatus(void)
|
||||
{
|
||||
return (FlagStatus)(*(vu32 *) SR_EWIF_BB);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : WWDG_ClearFlag
|
||||
* Description : Clears Early Wakeup interrupt flag.
|
||||
* Input : None
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void WWDG_ClearFlag(void)
|
||||
{
|
||||
WWDG->SR = (u32)RESET;
|
||||
}
|
||||
|
||||
/******************* (C) COPYRIGHT 2007 STMicroelectronics *****END OF FILE****/
|
Loading…
Add table
Add a link
Reference in a new issue