Subversion Repositories DashDisplay

Rev

Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2 Rev 5
Line 1... Line 1...
1
/**
1
/**
2
  ******************************************************************************
2
  ******************************************************************************
3
  * @file    stm32f1xx_hal_spi.c
3
  * @file    stm32f1xx_hal_spi.c
4
  * @author  MCD Application Team
4
  * @author  MCD Application Team
5
  * @version V1.0.1
5
  * @version V1.0.4
6
  * @date    31-July-2015
6
  * @date    29-April-2016
7
  * @brief   SPI HAL module driver.
7
  * @brief   SPI HAL module driver.
8
  *    
8
  *    
9
  *          This file provides firmware functions to manage the following
9
  *          This file provides firmware functions to manage the following
10
  *          functionalities of the Serial Peripheral Interface (SPI) peripheral:
10
  *          functionalities of the Serial Peripheral Interface (SPI) peripheral:
11
  *           + Initialization and de-initialization functions
11
  *           + Initialization and de-initialization functions
Line 51... Line 51...
51
          (##) Master 1Line Rx
51
          (##) Master 1Line Rx
52
      (#) The CRC feature is not managed when the DMA circular mode is enabled
52
      (#) The CRC feature is not managed when the DMA circular mode is enabled
53
      (#) When the SPI DMA Pause/Stop features are used, we must use the following APIs
53
      (#) When the SPI DMA Pause/Stop features are used, we must use the following APIs
54
          the HAL_SPI_DMAPause()/ HAL_SPI_DMAStop() only under the SPI callbacks
54
          the HAL_SPI_DMAPause()/ HAL_SPI_DMAStop() only under the SPI callbacks
55
 
55
 
-
 
56
  @endverbatim
-
 
57
  ******************************************************************************
-
 
58
  * @attention
-
 
59
  *
-
 
60
  * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
-
 
61
  *
-
 
62
  * Redistribution and use in source and binary forms, with or without modification,
-
 
63
  * are permitted provided that the following conditions are met:
-
 
64
  *   1. Redistributions of source code must retain the above copyright notice,
-
 
65
  *      this list of conditions and the following disclaimer.
-
 
66
  *   2. Redistributions in binary form must reproduce the above copyright notice,
-
 
67
  *      this list of conditions and the following disclaimer in the documentation
-
 
68
  *      and/or other materials provided with the distribution.
-
 
69
  *   3. Neither the name of STMicroelectronics nor the names of its contributors
-
 
70
  *      may be used to endorse or promote products derived from this software
-
 
71
  *      without specific prior written permission.
-
 
72
  *
-
 
73
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-
 
74
  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-
 
75
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-
 
76
  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-
 
77
  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-
 
78
  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-
 
79
  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-
 
80
  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-
 
81
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-
 
82
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
 
83
  *
-
 
84
  ******************************************************************************
56
    [..]
85
  */
-
 
86
 
-
 
87
/*
57
    Using the HAL it is not possible to reach all supported SPI frequency with the differents SPI Modes,
88
    Using the HAL it is not possible to reach all supported SPI frequency with the differents SPI Modes,
58
    the following table resume the max SPI frequency reached with data size 8bits/16bits,
89
    the following table resume the max SPI frequency reached with data size 8bits/16bits,
59
    according to frequency used on APBx Peripheral Clock (fPCLK) used by the SPI instance :
90
    according to frequency used on APBx Peripheral Clock (fPCLK) used by the SPI instance :
60
 
91
 
61
    For 8 bits SPI data size transfers :
92
    For 8 bits SPI data size transfers :
Line 106... Line 137...
106
   |    T    |     Interrupt  |  fPCLK/4  |  fPCLK/8  |    NA     |    NA     |  fPCLK/4  | fPCLK/256 |
137
   |    T    |     Interrupt  |  fPCLK/4  |  fPCLK/8  |    NA     |    NA     |  fPCLK/4  | fPCLK/256 |
107
   |    X    |----------------|-----------|-----------|-----------|-----------|-----------|-----------|
138
   |    X    |----------------|-----------|-----------|-----------|-----------|-----------|-----------|
108
   |         |       DMA      |  fPCLK/2  |  fPCLK/4  |    NA     |    NA     |  fPCLK/2  | fPCLK/32  |
139
   |         |       DMA      |  fPCLK/2  |  fPCLK/4  |    NA     |    NA     |  fPCLK/2  | fPCLK/32  |
109
   +--------------------------------------------------------------------------------------------------+
140
   +--------------------------------------------------------------------------------------------------+
110
 
141
 
-
 
142
  note:
111
  @note The max SPI frequency depend on SPI data size (8bits, 16bits),
143
    The max SPI frequency depend on SPI data size (8bits, 16bits),
112
        SPI mode(2 Lines fullduplex, 2 lines RxOnly, 1 line TX/RX) and Process mode (Polling, IT, DMA).
144
    SPI mode(2 Lines fullduplex, 2 lines RxOnly, 1 line TX/RX) and Process mode (Polling, IT, DMA).
-
 
145
 
113
  @note
146
  note:
114
   (#) TX/RX processes are HAL_SPI_TransmitReceive(), HAL_SPI_TransmitReceive_IT() and HAL_SPI_TransmitReceive_DMA()
147
    TX/RX processes are HAL_SPI_TransmitReceive(), HAL_SPI_TransmitReceive_IT() and HAL_SPI_TransmitReceive_DMA()
115
   (#) RX processes are HAL_SPI_Receive(), HAL_SPI_Receive_IT() and HAL_SPI_Receive_DMA()
148
    RX processes are HAL_SPI_Receive(), HAL_SPI_Receive_IT() and HAL_SPI_Receive_DMA()
116
   (#) TX processes are HAL_SPI_Transmit(), HAL_SPI_Transmit_IT() and HAL_SPI_Transmit_DMA()
149
    TX processes are HAL_SPI_Transmit(), HAL_SPI_Transmit_IT() and HAL_SPI_Transmit_DMA()
117
 
150
 
118
  @endverbatim
-
 
119
  ******************************************************************************
-
 
120
  * @attention
-
 
121
  *
-
 
122
  * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
-
 
123
  *
-
 
124
  * Redistribution and use in source and binary forms, with or without modification,
-
 
125
  * are permitted provided that the following conditions are met:
-
 
126
  *   1. Redistributions of source code must retain the above copyright notice,
-
 
127
  *      this list of conditions and the following disclaimer.
-
 
128
  *   2. Redistributions in binary form must reproduce the above copyright notice,
-
 
129
  *      this list of conditions and the following disclaimer in the documentation
-
 
130
  *      and/or other materials provided with the distribution.
-
 
131
  *   3. Neither the name of STMicroelectronics nor the names of its contributors
-
 
132
  *      may be used to endorse or promote products derived from this software
-
 
133
  *      without specific prior written permission.
-
 
134
  *
-
 
135
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-
 
136
  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-
 
137
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-
 
138
  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-
 
139
  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-
 
140
  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-
 
141
  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-
 
142
  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-
 
143
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-
 
144
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
 
145
  *
-
 
146
  ******************************************************************************
-
 
147
  */
151
*/
148
 
152
 
149
/* Includes ------------------------------------------------------------------*/
153
/* Includes ------------------------------------------------------------------*/
150
#include "stm32f1xx_hal.h"
154
#include "stm32f1xx_hal.h"
151
 
155
 
152
/** @addtogroup STM32F1xx_HAL_Driver
156
/** @addtogroup STM32F1xx_HAL_Driver
Line 332... Line 336...
332
  *               the configuration information for SPI module.
336
  *               the configuration information for SPI module.
333
  * @retval None
337
  * @retval None
334
  */
338
  */
335
 __weak void HAL_SPI_MspInit(SPI_HandleTypeDef *hspi)
339
 __weak void HAL_SPI_MspInit(SPI_HandleTypeDef *hspi)
336
 {
340
 {
-
 
341
  /* Prevent unused argument(s) compilation warning */
-
 
342
  UNUSED(hspi);
337
   /* NOTE : This function Should not be modified, when the callback is needed,
343
   /* NOTE : This function Should not be modified, when the callback is needed,
338
             the HAL_SPI_MspInit could be implenetd in the user file
344
             the HAL_SPI_MspInit could be implenetd in the user file
339
   */
345
   */
340
}
346
}
341
 
347
 
Line 345... Line 351...
345
  *               the configuration information for SPI module.
351
  *               the configuration information for SPI module.
346
  * @retval None
352
  * @retval None
347
  */
353
  */
348
 __weak void HAL_SPI_MspDeInit(SPI_HandleTypeDef *hspi)
354
 __weak void HAL_SPI_MspDeInit(SPI_HandleTypeDef *hspi)
349
{
355
{
-
 
356
  /* Prevent unused argument(s) compilation warning */
-
 
357
  UNUSED(hspi);
350
  /* NOTE : This function Should not be modified, when the callback is needed,
358
  /* NOTE : This function Should not be modified, when the callback is needed,
351
            the HAL_SPI_MspDeInit could be implenetd in the user file
359
            the HAL_SPI_MspDeInit could be implenetd in the user file
352
   */
360
   */
353
}
361
}
354
 
362
 
Line 1249... Line 1257...
1249
    hspi->hdmatx->XferCpltCallback = SPI_DMATransmitCplt;
1257
    hspi->hdmatx->XferCpltCallback = SPI_DMATransmitCplt;
1250
 
1258
 
1251
    /* Set the DMA error callback */
1259
    /* Set the DMA error callback */
1252
    hspi->hdmatx->XferErrorCallback = SPI_DMAError;
1260
    hspi->hdmatx->XferErrorCallback = SPI_DMAError;
1253
 
1261
 
1254
    /* Reset content of SPI RxDMA descriptor */
-
 
1255
    hspi->hdmarx->XferHalfCpltCallback = 0;
-
 
1256
    hspi->hdmarx->XferCpltCallback     = 0;
-
 
1257
    hspi->hdmarx->XferErrorCallback    = 0;
-
 
1258
 
-
 
1259
    /* Enable the Tx DMA Channel */
1262
    /* Enable the Tx DMA Channel */
1260
    HAL_DMA_Start_IT(hspi->hdmatx, (uint32_t)hspi->pTxBuffPtr, (uint32_t)&hspi->Instance->DR, hspi->TxXferCount);
1263
    HAL_DMA_Start_IT(hspi->hdmatx, (uint32_t)hspi->pTxBuffPtr, (uint32_t)&hspi->Instance->DR, hspi->TxXferCount);
1261
 
1264
 
1262
    /* Enable Tx DMA Request */
1265
    /* Enable Tx DMA Request */
1263
    SET_BIT(hspi->Instance->CR2, SPI_CR2_TXDMAEN);
1266
    SET_BIT(hspi->Instance->CR2, SPI_CR2_TXDMAEN);
Line 1343... Line 1346...
1343
    hspi->hdmarx->XferCpltCallback = SPI_DMAReceiveCplt;
1346
    hspi->hdmarx->XferCpltCallback = SPI_DMAReceiveCplt;
1344
 
1347
 
1345
    /* Set the DMA error callback */
1348
    /* Set the DMA error callback */
1346
    hspi->hdmarx->XferErrorCallback = SPI_DMAError;
1349
    hspi->hdmarx->XferErrorCallback = SPI_DMAError;
1347
 
1350
 
1348
    /* Reset content of SPI TxDMA descriptor */
-
 
1349
    hspi->hdmatx->XferHalfCpltCallback = 0;
-
 
1350
    hspi->hdmatx->XferCpltCallback     = 0;
-
 
1351
    hspi->hdmatx->XferErrorCallback    = 0;
-
 
1352
 
-
 
1353
    /* Enable the Rx DMA Channel */
1351
    /* Enable the Rx DMA Channel */
1354
    HAL_DMA_Start_IT(hspi->hdmarx, (uint32_t)&hspi->Instance->DR, (uint32_t)hspi->pRxBuffPtr, hspi->RxXferCount);
1352
    HAL_DMA_Start_IT(hspi->hdmarx, (uint32_t)&hspi->Instance->DR, (uint32_t)hspi->pRxBuffPtr, hspi->RxXferCount);
1355
 
1353
 
1356
    /* Enable Rx DMA Request */  
1354
    /* Enable Rx DMA Request */  
1357
    SET_BIT(hspi->Instance->CR2, SPI_CR2_RXDMAEN);
1355
    SET_BIT(hspi->Instance->CR2, SPI_CR2_RXDMAEN);
Line 1628... Line 1626...
1628
  *                the configuration information for SPI module.
1626
  *                the configuration information for SPI module.
1629
  * @retval None
1627
  * @retval None
1630
  */
1628
  */
1631
__weak void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef *hspi)
1629
__weak void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef *hspi)
1632
{
1630
{
-
 
1631
  /* Prevent unused argument(s) compilation warning */
-
 
1632
  UNUSED(hspi);
1633
  /* NOTE : This function Should not be modified, when the callback is needed,
1633
  /* NOTE : This function Should not be modified, when the callback is needed,
1634
            the HAL_SPI_TxCpltCallback could be implenetd in the user file
1634
            the HAL_SPI_TxCpltCallback could be implenetd in the user file
1635
   */
1635
   */
1636
}
1636
}
1637
 
1637
 
Line 1641... Line 1641...
1641
  *                the configuration information for SPI module.
1641
  *                the configuration information for SPI module.
1642
  * @retval None
1642
  * @retval None
1643
  */
1643
  */
1644
__weak void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef *hspi)
1644
__weak void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef *hspi)
1645
{
1645
{
-
 
1646
  /* Prevent unused argument(s) compilation warning */
-
 
1647
  UNUSED(hspi);
1646
  /* NOTE : This function Should not be modified, when the callback is needed,
1648
  /* NOTE : This function Should not be modified, when the callback is needed,
1647
            the HAL_SPI_RxCpltCallback() could be implenetd in the user file
1649
            the HAL_SPI_RxCpltCallback() could be implenetd in the user file
1648
   */
1650
   */
1649
}
1651
}
1650
 
1652
 
Line 1654... Line 1656...
1654
  *                the configuration information for SPI module.
1656
  *                the configuration information for SPI module.
1655
  * @retval None
1657
  * @retval None
1656
  */
1658
  */
1657
__weak void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef *hspi)
1659
__weak void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef *hspi)
1658
{
1660
{
-
 
1661
  /* Prevent unused argument(s) compilation warning */
-
 
1662
  UNUSED(hspi);
1659
  /* NOTE : This function Should not be modified, when the callback is needed,
1663
  /* NOTE : This function Should not be modified, when the callback is needed,
1660
            the HAL_SPI_TxRxCpltCallback() could be implenetd in the user file
1664
            the HAL_SPI_TxRxCpltCallback() could be implenetd in the user file
1661
   */
1665
   */
1662
}
1666
}
1663
 
1667
 
Line 1667... Line 1671...
1667
  *                the configuration information for SPI module.
1671
  *                the configuration information for SPI module.
1668
  * @retval None
1672
  * @retval None
1669
  */
1673
  */
1670
__weak void HAL_SPI_TxHalfCpltCallback(SPI_HandleTypeDef *hspi)
1674
__weak void HAL_SPI_TxHalfCpltCallback(SPI_HandleTypeDef *hspi)
1671
{
1675
{
-
 
1676
  /* Prevent unused argument(s) compilation warning */
-
 
1677
  UNUSED(hspi);
1672
  /* NOTE : This function Should not be modified, when the callback is needed,
1678
  /* NOTE : This function Should not be modified, when the callback is needed,
1673
            the HAL_SPI_TxHalfCpltCallback could be implenetd in the user file
1679
            the HAL_SPI_TxHalfCpltCallback could be implenetd in the user file
1674
   */
1680
   */
1675
}
1681
}
1676
 
1682
 
Line 1680... Line 1686...
1680
  *                the configuration information for SPI module.
1686
  *                the configuration information for SPI module.
1681
  * @retval None
1687
  * @retval None
1682
  */
1688
  */
1683
__weak void HAL_SPI_RxHalfCpltCallback(SPI_HandleTypeDef *hspi)
1689
__weak void HAL_SPI_RxHalfCpltCallback(SPI_HandleTypeDef *hspi)
1684
{
1690
{
-
 
1691
  /* Prevent unused argument(s) compilation warning */
-
 
1692
  UNUSED(hspi);
1685
  /* NOTE : This function Should not be modified, when the callback is needed,
1693
  /* NOTE : This function Should not be modified, when the callback is needed,
1686
            the HAL_SPI_RxHalfCpltCallback() could be implenetd in the user file
1694
            the HAL_SPI_RxHalfCpltCallback() could be implenetd in the user file
1687
   */
1695
   */
1688
}
1696
}
1689
 
1697
 
Line 1693... Line 1701...
1693
  *                the configuration information for SPI module.
1701
  *                the configuration information for SPI module.
1694
  * @retval None
1702
  * @retval None
1695
  */
1703
  */
1696
__weak void HAL_SPI_TxRxHalfCpltCallback(SPI_HandleTypeDef *hspi)
1704
__weak void HAL_SPI_TxRxHalfCpltCallback(SPI_HandleTypeDef *hspi)
1697
{
1705
{
-
 
1706
  /* Prevent unused argument(s) compilation warning */
-
 
1707
  UNUSED(hspi);
1698
  /* NOTE : This function Should not be modified, when the callback is needed,
1708
  /* NOTE : This function Should not be modified, when the callback is needed,
1699
            the HAL_SPI_TxRxHalfCpltCallback() could be implenetd in the user file
1709
            the HAL_SPI_TxRxHalfCpltCallback() could be implenetd in the user file
1700
   */
1710
   */
1701
}
1711
}
1702
 
1712
 
Line 1706... Line 1716...
1706
  *                the configuration information for SPI module.
1716
  *                the configuration information for SPI module.
1707
  * @retval None
1717
  * @retval None
1708
  */
1718
  */
1709
 __weak void HAL_SPI_ErrorCallback(SPI_HandleTypeDef *hspi)
1719
 __weak void HAL_SPI_ErrorCallback(SPI_HandleTypeDef *hspi)
1710
{
1720
{
-
 
1721
  /* Prevent unused argument(s) compilation warning */
-
 
1722
  UNUSED(hspi);
1711
  /* NOTE : - This function Should not be modified, when the callback is needed,
1723
  /* NOTE : - This function Should not be modified, when the callback is needed,
1712
            the HAL_SPI_ErrorCallback() could be implenetd in the user file.
1724
            the HAL_SPI_ErrorCallback() could be implenetd in the user file.
1713
            - The ErrorCode parameter in the hspi handle is updated by the SPI processes
1725
            - The ErrorCode parameter in the hspi handle is updated by the SPI processes
1714
            and user can use HAL_SPI_GetError() API to check the latest error occurred.
1726
            and user can use HAL_SPI_GetError() API to check the latest error occurred.
1715
   */
1727
   */