📄 stm32f10x_spi.lst
字号:
##############################################################################
# #
# IAR ARM ANSI C/C++ Compiler V4.42A/W32 15/May/2008 12:06:32 #
# Copyright 1999-2005 IAR Systems. All rights reserved. #
# #
# Cpu mode = thumb #
# Endian = little #
# Stack alignment = 4 #
# Source file = C:\David JIANG\ST MCU\Docs\STM32\AN_JIANG\TIM #
# Encoder\example\FWLib\src\stm32f10x_spi.c #
# Command line = "C:\David JIANG\ST MCU\Docs\STM32\AN_JIANG\TIM #
# Encoder\example\FWLib\src\stm32f10x_spi.c" -D #
# VECT_TAB_FLASH -lcN "C:\David JIANG\ST #
# MCU\Docs\STM32\AN_JIANG\TIM #
# Encoder\example\project\EWARM\BOOT_FLASH\List\" -lb #
# "C:\David JIANG\ST MCU\Docs\STM32\AN_JIANG\TIM #
# Encoder\example\project\EWARM\BOOT_FLASH\List\" -o #
# "C:\David JIANG\ST MCU\Docs\STM32\AN_JIANG\TIM #
# Encoder\example\project\EWARM\BOOT_FLASH\Obj\" -z3 #
# --no_cse --no_unroll --no_inline --no_code_motion #
# --no_tbaa --no_clustering --no_scheduling --debug #
# --cpu_mode thumb --endian little --cpu cortex-M3 #
# --stack_align 4 --require_prototypes --fpu None #
# --dlib_config "C:\Program Files\IAR #
# Systems\Embedded Workbench #
# 4.0\arm\LIB\dl7mptnnl8f.h" -I "C:\David JIANG\ST #
# MCU\Docs\STM32\AN_JIANG\TIM #
# Encoder\example\project\EWARM\" -I "C:\David #
# JIANG\ST MCU\Docs\STM32\AN_JIANG\TIM #
# Encoder\example\project\EWARM\..\include\" -I #
# "C:\David JIANG\ST MCU\Docs\STM32\AN_JIANG\TIM #
# Encoder\example\project\EWARM\..\..\FWLib\inc\" -I #
# "C:\Program Files\IAR Systems\Embedded Workbench #
# 4.0\arm\INC\" #
# List file = C:\David JIANG\ST MCU\Docs\STM32\AN_JIANG\TIM #
# Encoder\example\project\EWARM\BOOT_FLASH\List\stm32f #
# 10x_spi.lst #
# Object file = C:\David JIANG\ST MCU\Docs\STM32\AN_JIANG\TIM #
# Encoder\example\project\EWARM\BOOT_FLASH\Obj\stm32f1 #
# 0x_spi.r79 #
# #
# #
##############################################################################
C:\David JIANG\ST MCU\Docs\STM32\AN_JIANG\TIM Encoder\example\FWLib\src\stm32f10x_spi.c
1 /******************** (C) COPYRIGHT 2007 STMicroelectronics ********************
2 * File Name : stm32f10x_spi.c
3 * Author : MCD Application Team
4 * Date First Issued : 09/29/2006
5 * Description : This file provides all the SPI firmware functions.
6 ********************************************************************************
7 * History:
8 * 05/21/2007: V0.3
9 * 04/02/2007: V0.2
10 * 02/05/2007: V0.1
11 * 09/29/2006: V0.01
12 ********************************************************************************
13 * THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
14 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
15 * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
16 * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
17 * CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
18 * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
19 *******************************************************************************/
20
21 /* Includes ------------------------------------------------------------------*/
22 #include "stm32f10x_spi.h"
23 #include "stm32f10x_rcc.h"
24
25 /* Private typedef -----------------------------------------------------------*/
26 /* Private define ------------------------------------------------------------*/
27 /* SPI SPE mask */
28 #define CR1_SPE_Set ((u16)0x0040)
29 #define CR1_SPE_Reset ((u16)0xFFBF)
30
31 /* SPI CRCNext mask */
32 #define CR1_CRCNext_Set ((u16)0x1000)
33
34 /* SPI CRCEN mask */
35 #define CR1_CRCEN_Set ((u16)0x2000)
36 #define CR1_CRCEN_Reset ((u16)0xDFFF)
37
38 /* SPI SSOE mask */
39 #define CR2_SSOE_Set ((u16)0x0004)
40 #define CR2_SSOE_Reset ((u16)0xFFFB)
41
42 /* SPI registers Masks */
43 #define CR1_CLEAR_Mask ((u16)0x3040)
44
45 /* Private macro -------------------------------------------------------------*/
46 /* Private variables ---------------------------------------------------------*/
47 /* Private function prototypes -----------------------------------------------*/
48 /* Private functions ---------------------------------------------------------*/
49
50 /*******************************************************************************
51 * Function Name : SPI_DeInit
52 * Description : Deinitializes the SPIx peripheral registers to their default
53 * reset values.
54 * Input : - SPIx: where x can be 1 or 2 to select the SPI peripheral.
55 * Output : None
56 * Return : None
57 *******************************************************************************/
58 void SPI_DeInit(SPI_TypeDef* SPIx)
59 {
60 switch (*(u32*)&SPIx)
61 {
62 case SPI1_BASE:
63 /* Enable SPI1 reset state */
64 RCC_APB2PeriphResetCmd(RCC_APB2Periph_SPI1, ENABLE);
65 /* Release SPI1 from reset state */
66 RCC_APB2PeriphResetCmd(RCC_APB2Periph_SPI1, DISABLE);
67 break;
68
69 case SPI2_BASE:
70 /* Enable SPI2 reset state */
71 RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI2, ENABLE);
72 /* Release SPI2 from reset state */
73 RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI2, DISABLE);
74 break;
75
76 default:
77 break;
78 }
79 }
80
81 /*******************************************************************************
82 * Function Name : SPI_Init
83 * Description : Initializes the SPIx peripheral according to the specified
84 * parameters in the SPI_InitStruct.
85 * Input : - SPIx: where x can be 1 or 2 to select the SPI peripheral.
86 * - SPI_InitStruct: pointer to a SPI_InitTypeDef structure that
87 * contains the configuration information for the specified
88 * SPI peripheral.
89 * Output : None
90 * Return : None
91 ******************************************************************************/
92 void SPI_Init(SPI_TypeDef* SPIx, SPI_InitTypeDef* SPI_InitStruct)
93 {
94 u16 tmpreg = 0;
95
96 /* Check the parameters */
97 assert(IS_SPI_DIRECTION_MODE(SPI_InitStruct->SPI_Direction));
98 assert(IS_SPI_MODE(SPI_InitStruct->SPI_Mode));
99 assert(IS_SPI_DATASIZE(SPI_InitStruct->SPI_DataSize));
100 assert(IS_SPI_CPOL(SPI_InitStruct->SPI_CPOL));
101 assert(IS_SPI_CPHA(SPI_InitStruct->SPI_CPHA));
102 assert(IS_SPI_NSS(SPI_InitStruct->SPI_NSS));
103 assert(IS_SPI_BAUDRATE_PRESCALER(SPI_InitStruct->SPI_BaudRatePrescaler));
104 assert(IS_SPI_FIRST_BIT(SPI_InitStruct->SPI_FirstBit));
105 assert(IS_SPI_CRC_POLYNOMIAL(SPI_InitStruct->SPI_CRCPolynomial));
106
107 /*---------------------------- SPIx CR1 Configuration ------------------------*/
108 /* Get the SPIx CR1 value */
109 tmpreg = SPIx->CR1;
110 /* Clear BIDIMode, BIDIOE, RxONLY, SSM, SSI, LSBFirst, BR, MSTR, CPOL and CPHA bits */
111 tmpreg &= CR1_CLEAR_Mask;
112 /* Configure SPIx: direction, NSS management, first transmitted bit, BaudRate prescaler
113 master/salve mode, CPOL and CPHA */
114 /* Set BIDImode, BIDIOE and RxONLY bits according to SPI_Direction value */
115 /* Set SSM, SSI and MSTR bits according to SPI_Mode and SPI_NSS values */
116 /* Set LSBFirst bit according to SPI_FirstBit value */
117 /* Set BR bits according to SPI_BaudRatePrescaler value */
118 /* Set CPOL bit according to SPI_CPOL value */
119 /* Set CPHA bit according to SPI_CPHA value */
120 tmpreg |= (u16)((u32)SPI_InitStruct->SPI_Direction | SPI_InitStruct->SPI_Mode |
121 SPI_InitStruct->SPI_DataSize | SPI_InitStruct->SPI_CPOL |
122 SPI_InitStruct->SPI_CPHA | SPI_InitStruct->SPI_NSS |
123 SPI_InitStruct->SPI_BaudRatePrescaler | SPI_InitStruct->SPI_FirstBit);
124 /* Write to SPIx CR1 */
125 SPIx->CR1 = tmpreg;
126
127 /*---------------------------- SPIx CRCPOLY Configuration --------------------*/
128 /* Write to SPIx CRCPOLY */
129 SPIx->CRCPR = SPI_InitStruct->SPI_CRCPolynomial;
130 }
131
132 /*******************************************************************************
133 * Function Name : SPI_StructInit
134 * Description : Fills each SPI_InitStruct member with its default value.
135 * Input : - SPI_InitStruct : pointer to a SPI_InitTypeDef structure
136 * which will be initialized.
137 * Output : None
138 * Return : None
139 *******************************************************************************/
140 void SPI_StructInit(SPI_InitTypeDef* SPI_InitStruct)
141 {
142 /*--------------- Reset SPI init structure parameters values -----------------*/
143 /* Initialize the SPI_Direction member */
144 SPI_InitStruct->SPI_Direction = SPI_Direction_2Lines_FullDuplex;
145
146 /* initialize the SPI_Mode member */
147 SPI_InitStruct->SPI_Mode = SPI_Mode_Slave;
148
149 /* initialize the SPI_DataSize member */
150 SPI_InitStruct->SPI_DataSize = SPI_DataSize_8b;
151
152 /* Initialize the SPI_CPOL member */
153 SPI_InitStruct->SPI_CPOL = SPI_CPOL_Low;
154
155 /* Initialize the SPI_CPHA member */
156 SPI_InitStruct->SPI_CPHA = SPI_CPHA_1Edge;
157
158 /* Initialize the SPI_NSS member */
159 SPI_InitStruct->SPI_NSS = SPI_NSS_Hard;
160
161 /* Initialize the SPI_BaudRatePrescaler member */
162 SPI_InitStruct->SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2;
163
164 /* Initialize the SPI_FirstBit member */
165 SPI_InitStruct->SPI_FirstBit = SPI_FirstBit_MSB;
166
167 /* Initialize the SPI_CRCPolynomial member */
168 SPI_InitStruct->SPI_CRCPolynomial = 7;
169 }
170
171 /*******************************************************************************
172 * Function Name : SPI_Cmd
173 * Description : Enables or disables the specified SPI peripheral.
174 * Input : - SPIx: where x can be 1 or 2 to select the SPI peripheral.
175 * - NewState: new state of the SPIx peripheral.
176 * This parameter can be: ENABLE or DISABLE.
177 * Output : None
178 * Return : None
179 *******************************************************************************/
180 void SPI_Cmd(SPI_TypeDef* SPIx, FunctionalState NewState)
181 {
182 /* Check the parameters */
183 assert(IS_FUNCTIONAL_STATE(NewState));
184
185 if (NewState != DISABLE)
186 {
187 /* Enable the selected SPI peripheral */
188 SPIx->CR1 |= CR1_SPE_Set;
189 }
190 else
191 {
192 /* Disable the selected SPI peripheral */
193 SPIx->CR1 &= CR1_SPE_Reset;
194 }
195 }
196
197 /*******************************************************************************
198 * Function Name : SPI_ITConfig
199 * Description : Enables or disables the specified SPI interrupts.
200 * Input : - SPIx: where x can be 1 or 2 to select the SPI peripheral.
201 * - SPI_IT: specifies the SPI interrupt source to be enabled
202 * or disabled.
203 * This parameter can be one of the following values:
204 * - SPI_IT_TXE: Tx buffer empty interrupt mask
205 * - SPI_IT_RXNE: Rx buffer not empty interrupt mask
206 * - SPI_IT_ERR: Error interrupt mask
207 * - NewState: new state of the specified SPI interrupt.
208 * This parameter can be: ENABLE or DISABLE.
209 * Output : None
210 * Return : None
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -