]> git.donarmstrong.com Git - qmk_firmware.git/blob - tool/mbed/mbed-sdk/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32L1/stm32l1xx_hal_spi_ex.c
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[qmk_firmware.git] / tool / mbed / mbed-sdk / libraries / mbed / targets / cmsis / TARGET_STM / TARGET_STM32L1 / stm32l1xx_hal_spi_ex.c
1 /**
2   ******************************************************************************
3   * @file    stm32l1xx_hal_spi_ex.c
4   * @author  MCD Application Team
5   * @version V1.0.0
6   * @date    5-September-2014
7   * @brief   Extended SPI HAL module driver.
8   *    
9   *          This file provides firmware functions to manage the following 
10   *          functionalities SPI extension peripheral:
11   *           + Extended Peripheral Control functions
12   *  
13   ******************************************************************************
14   * @attention
15   *
16   * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
17   *
18   * Redistribution and use in source and binary forms, with or without modification,
19   * are permitted provided that the following conditions are met:
20   *   1. Redistributions of source code must retain the above copyright notice,
21   *      this list of conditions and the following disclaimer.
22   *   2. Redistributions in binary form must reproduce the above copyright notice,
23   *      this list of conditions and the following disclaimer in the documentation
24   *      and/or other materials provided with the distribution.
25   *   3. Neither the name of STMicroelectronics nor the names of its contributors
26   *      may be used to endorse or promote products derived from this software
27   *      without specific prior written permission.
28   *
29   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
30   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
32   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
33   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
36   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
37   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39   *
40   ******************************************************************************
41   */
42
43 /* Includes ------------------------------------------------------------------*/
44 #include "stm32l1xx_hal.h"
45
46 /** @addtogroup STM32L1xx_HAL_Driver
47   * @{
48   */
49
50 /** @addtogroup SPI
51   * @{
52   */
53 #ifdef HAL_SPI_MODULE_ENABLED
54
55 /* Private typedef -----------------------------------------------------------*/
56 /* Private define ------------------------------------------------------------*/
57 /* Private macro -------------------------------------------------------------*/
58 /* Private variables ---------------------------------------------------------*/
59 /* Private function prototypes -----------------------------------------------*/
60 /* Private functions ---------------------------------------------------------*/
61
62 /** @addtogroup SPI_Exported_Functions
63   * @{
64   */
65
66 /** @addtogroup SPI_Exported_Functions_Group1
67  *
68   * @{
69   */
70
71 /**
72   * @brief  Initializes the SPI according to the specified parameters 
73   *         in the SPI_InitTypeDef and create the associated handle.
74   * @param  hspi: pointer to a SPI_HandleTypeDef structure that contains
75   *                the configuration information for SPI module.
76   * @retval HAL status
77   */
78 HAL_StatusTypeDef HAL_SPI_Init(SPI_HandleTypeDef *hspi)
79 {
80   /* Check the SPI handle allocation */
81   if(hspi == HAL_NULL)
82   {
83     return HAL_ERROR;
84   }
85
86   /* Check the parameters */
87   assert_param(IS_SPI_ALL_INSTANCE(hspi->Instance));
88   assert_param(IS_SPI_MODE(hspi->Init.Mode));
89   assert_param(IS_SPI_DIRECTION_MODE(hspi->Init.Direction));
90   assert_param(IS_SPI_DATASIZE(hspi->Init.DataSize));
91   assert_param(IS_SPI_CPOL(hspi->Init.CLKPolarity));
92   assert_param(IS_SPI_CPHA(hspi->Init.CLKPhase));
93   assert_param(IS_SPI_NSS(hspi->Init.NSS));
94   assert_param(IS_SPI_BAUDRATE_PRESCALER(hspi->Init.BaudRatePrescaler));
95   assert_param(IS_SPI_FIRST_BIT(hspi->Init.FirstBit));
96   assert_param(IS_SPI_TIMODE(hspi->Init.TIMode));
97   assert_param(IS_SPI_CRC_CALCULATION(hspi->Init.CRCCalculation));
98   assert_param(IS_SPI_CRC_POLYNOMIAL(hspi->Init.CRCPolynomial));
99
100   if(hspi->State == HAL_SPI_STATE_RESET)
101   {
102     /* Init the low level hardware : GPIO, CLOCK, NVIC... */
103     HAL_SPI_MspInit(hspi);
104   }
105   
106   hspi->State = HAL_SPI_STATE_BUSY;
107
108   /* Disble the selected SPI peripheral */
109   __HAL_SPI_DISABLE(hspi);
110
111   /*----------------------- SPIx CR1 & CR2 Configuration ---------------------*/
112   /* Configure : SPI Mode, Communication Mode, Data size, Clock polarity and phase, NSS management,
113   Communication speed, First bit and CRC calculation state */
114   hspi->Instance->CR1 = (hspi->Init.Mode | hspi->Init.Direction | hspi->Init.DataSize |
115                          hspi->Init.CLKPolarity | hspi->Init.CLKPhase | (hspi->Init.NSS & SPI_CR1_SSM) |
116                          hspi->Init.BaudRatePrescaler | hspi->Init.FirstBit  | hspi->Init.CRCCalculation);
117
118   /* Configure : NSS management */
119   hspi->Instance->CR2 = (((hspi->Init.NSS >> 16) & SPI_CR2_SSOE) | hspi->Init.TIMode);
120
121   /*---------------------------- SPIx CRCPOLY Configuration ------------------*/
122   /* Configure : CRC Polynomial */
123   hspi->Instance->CRCPR = hspi->Init.CRCPolynomial;
124
125 #if defined (STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined (STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined (STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE)
126   /* Activate the SPI mode (Make sure that I2SMOD bit in I2SCFGR register is reset) */
127   CLEAR_BIT(hspi->Instance->I2SCFGR, SPI_I2SCFGR_I2SMOD);
128 #endif
129
130   hspi->ErrorCode = HAL_SPI_ERROR_NONE;
131   hspi->State = HAL_SPI_STATE_READY;
132   
133   return HAL_OK;
134 }
135
136 /**
137   * @}
138   */
139
140 /**
141   * @}
142   */
143
144 #endif /* HAL_SPI_MODULE_ENABLED */
145 /**
146   * @}
147   */
148
149 /**
150   * @}
151   */
152
153 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/