mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Committer:
mbed_official
Date:
Thu Jul 02 16:30:08 2015 +0100
Revision:
581:39197bcd20f2
Parent:
532:fe11edbda85c
Child:
613:bc40b8d2aec4
Synchronized with git revision ae2d3cdffe70184eb8736d94f76c45c93f4b7724

Full URL: https://github.com/mbedmicro/mbed/commit/ae2d3cdffe70184eb8736d94f76c45c93f4b7724/

Make it possible to build the core mbed library with yotta

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 87:085cde657901 1 /**
mbed_official 87:085cde657901 2 ******************************************************************************
mbed_official 87:085cde657901 3 * @file stm32f4xx_hal_dma_ex.c
mbed_official 87:085cde657901 4 * @author MCD Application Team
mbed_official 532:fe11edbda85c 5 * @version V1.3.0
mbed_official 532:fe11edbda85c 6 * @date 09-March-2015
mbed_official 87:085cde657901 7 * @brief DMA Extension HAL module driver
mbed_official 87:085cde657901 8 * This file provides firmware functions to manage the following
mbed_official 87:085cde657901 9 * functionalities of the DMA Extension peripheral:
mbed_official 87:085cde657901 10 * + Extended features functions
mbed_official 87:085cde657901 11 *
mbed_official 87:085cde657901 12 @verbatim
mbed_official 87:085cde657901 13 ==============================================================================
mbed_official 87:085cde657901 14 ##### How to use this driver #####
mbed_official 87:085cde657901 15 ==============================================================================
mbed_official 87:085cde657901 16 [..]
mbed_official 87:085cde657901 17 The DMA Extension HAL driver can be used as follows:
mbed_official 87:085cde657901 18 (#) Start a multi buffer transfer using the HAL_DMA_MultiBufferStart() function
mbed_official 87:085cde657901 19 for polling mode or HAL_DMA_MultiBufferStart_IT() for interrupt mode.
mbed_official 87:085cde657901 20
mbed_official 87:085cde657901 21 -@- In Memory-to-Memory transfer mode, Multi (Double) Buffer mode is not allowed.
mbed_official 87:085cde657901 22 -@- When Multi (Double) Buffer mode is enabled the, transfer is circular by default.
mbed_official 87:085cde657901 23 -@- In Multi (Double) buffer mode, it is possible to update the base address for
mbed_official 226:b062af740e40 24 the AHB memory port on the fly (DMA_SxM0AR or DMA_SxM1AR) when the stream is enabled.
mbed_official 87:085cde657901 25
mbed_official 87:085cde657901 26 @endverbatim
mbed_official 87:085cde657901 27 ******************************************************************************
mbed_official 87:085cde657901 28 * @attention
mbed_official 87:085cde657901 29 *
mbed_official 532:fe11edbda85c 30 * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
mbed_official 87:085cde657901 31 *
mbed_official 87:085cde657901 32 * Redistribution and use in source and binary forms, with or without modification,
mbed_official 87:085cde657901 33 * are permitted provided that the following conditions are met:
mbed_official 87:085cde657901 34 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 87:085cde657901 35 * this list of conditions and the following disclaimer.
mbed_official 87:085cde657901 36 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 87:085cde657901 37 * this list of conditions and the following disclaimer in the documentation
mbed_official 87:085cde657901 38 * and/or other materials provided with the distribution.
mbed_official 87:085cde657901 39 * 3. Neither the name of STMicroelectronics nor the names of its contributors
mbed_official 87:085cde657901 40 * may be used to endorse or promote products derived from this software
mbed_official 87:085cde657901 41 * without specific prior written permission.
mbed_official 87:085cde657901 42 *
mbed_official 87:085cde657901 43 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 87:085cde657901 44 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 87:085cde657901 45 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 87:085cde657901 46 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mbed_official 87:085cde657901 47 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 87:085cde657901 48 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mbed_official 87:085cde657901 49 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 87:085cde657901 50 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbed_official 87:085cde657901 51 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbed_official 87:085cde657901 52 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 87:085cde657901 53 *
mbed_official 87:085cde657901 54 ******************************************************************************
mbed_official 87:085cde657901 55 */
mbed_official 87:085cde657901 56
mbed_official 87:085cde657901 57 /* Includes ------------------------------------------------------------------*/
mbed_official 87:085cde657901 58 #include "stm32f4xx_hal.h"
mbed_official 87:085cde657901 59
mbed_official 87:085cde657901 60 /** @addtogroup STM32F4xx_HAL_Driver
mbed_official 87:085cde657901 61 * @{
mbed_official 87:085cde657901 62 */
mbed_official 87:085cde657901 63
mbed_official 532:fe11edbda85c 64 /** @defgroup DMAEx DMAEx
mbed_official 87:085cde657901 65 * @brief DMA Extended HAL module driver
mbed_official 87:085cde657901 66 * @{
mbed_official 87:085cde657901 67 */
mbed_official 87:085cde657901 68
mbed_official 87:085cde657901 69 #ifdef HAL_DMA_MODULE_ENABLED
mbed_official 87:085cde657901 70
mbed_official 532:fe11edbda85c 71 /* Private types -------------------------------------------------------------*/
mbed_official 87:085cde657901 72 /* Private variables ---------------------------------------------------------*/
mbed_official 532:fe11edbda85c 73 /* Private Constants ---------------------------------------------------------*/
mbed_official 532:fe11edbda85c 74 /* Private macros ------------------------------------------------------------*/
mbed_official 532:fe11edbda85c 75 /* Private functions ---------------------------------------------------------*/
mbed_official 532:fe11edbda85c 76 /** @addtogroup DMAEx_Private_Functions
mbed_official 532:fe11edbda85c 77 * @{
mbed_official 532:fe11edbda85c 78 */
mbed_official 87:085cde657901 79 static void DMA_MultiBufferSetConfig(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength);
mbed_official 532:fe11edbda85c 80 /**
mbed_official 532:fe11edbda85c 81 * @}
mbed_official 532:fe11edbda85c 82 */
mbed_official 87:085cde657901 83
mbed_official 532:fe11edbda85c 84 /* Exported functions ---------------------------------------------------------*/
mbed_official 87:085cde657901 85
mbed_official 532:fe11edbda85c 86 /** @addtogroup DMAEx_Exported_Functions
mbed_official 87:085cde657901 87 * @{
mbed_official 87:085cde657901 88 */
mbed_official 87:085cde657901 89
mbed_official 87:085cde657901 90
mbed_official 532:fe11edbda85c 91 /** @addtogroup DMAEx_Exported_Functions_Group1
mbed_official 532:fe11edbda85c 92 *
mbed_official 87:085cde657901 93 @verbatim
mbed_official 87:085cde657901 94 ===============================================================================
mbed_official 87:085cde657901 95 ##### Extended features functions #####
mbed_official 87:085cde657901 96 ===============================================================================
mbed_official 87:085cde657901 97 [..] This section provides functions allowing to:
mbed_official 87:085cde657901 98 (+) Configure the source, destination address and data length and
mbed_official 87:085cde657901 99 Start MultiBuffer DMA transfer
mbed_official 87:085cde657901 100 (+) Configure the source, destination address and data length and
mbed_official 87:085cde657901 101 Start MultiBuffer DMA transfer with interrupt
mbed_official 87:085cde657901 102 (+) Change on the fly the memory0 or memory1 address.
mbed_official 87:085cde657901 103
mbed_official 87:085cde657901 104 @endverbatim
mbed_official 87:085cde657901 105 * @{
mbed_official 87:085cde657901 106 */
mbed_official 87:085cde657901 107
mbed_official 87:085cde657901 108
mbed_official 87:085cde657901 109 /**
mbed_official 87:085cde657901 110 * @brief Starts the multi_buffer DMA Transfer.
mbed_official 87:085cde657901 111 * @param hdma : pointer to a DMA_HandleTypeDef structure that contains
mbed_official 87:085cde657901 112 * the configuration information for the specified DMA Stream.
mbed_official 87:085cde657901 113 * @param SrcAddress: The source memory Buffer address
mbed_official 87:085cde657901 114 * @param DstAddress: The destination memory Buffer address
mbed_official 87:085cde657901 115 * @param SecondMemAddress: The second memory Buffer address in case of multi buffer Transfer
mbed_official 87:085cde657901 116 * @param DataLength: The length of data to be transferred from source to destination
mbed_official 87:085cde657901 117 * @retval HAL status
mbed_official 87:085cde657901 118 */
mbed_official 87:085cde657901 119 HAL_StatusTypeDef HAL_DMAEx_MultiBufferStart(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t SecondMemAddress, uint32_t DataLength)
mbed_official 87:085cde657901 120 {
mbed_official 87:085cde657901 121 /* Process Locked */
mbed_official 87:085cde657901 122 __HAL_LOCK(hdma);
mbed_official 87:085cde657901 123
mbed_official 87:085cde657901 124 /* Current memory buffer used is Memory 0 */
mbed_official 87:085cde657901 125 if((hdma->Instance->CR & DMA_SxCR_CT) == 0)
mbed_official 87:085cde657901 126 {
mbed_official 87:085cde657901 127 hdma->State = HAL_DMA_STATE_BUSY_MEM0;
mbed_official 87:085cde657901 128 }
mbed_official 87:085cde657901 129 /* Current memory buffer used is Memory 1 */
mbed_official 87:085cde657901 130 else if((hdma->Instance->CR & DMA_SxCR_CT) != 0)
mbed_official 87:085cde657901 131 {
mbed_official 87:085cde657901 132 hdma->State = HAL_DMA_STATE_BUSY_MEM1;
mbed_official 87:085cde657901 133 }
mbed_official 87:085cde657901 134
mbed_official 87:085cde657901 135 /* Check the parameters */
mbed_official 87:085cde657901 136 assert_param(IS_DMA_BUFFER_SIZE(DataLength));
mbed_official 87:085cde657901 137
mbed_official 87:085cde657901 138 /* Disable the peripheral */
mbed_official 87:085cde657901 139 __HAL_DMA_DISABLE(hdma);
mbed_official 87:085cde657901 140
mbed_official 87:085cde657901 141 /* Enable the double buffer mode */
mbed_official 87:085cde657901 142 hdma->Instance->CR |= (uint32_t)DMA_SxCR_DBM;
mbed_official 87:085cde657901 143
mbed_official 87:085cde657901 144 /* Configure DMA Stream destination address */
mbed_official 87:085cde657901 145 hdma->Instance->M1AR = SecondMemAddress;
mbed_official 87:085cde657901 146
mbed_official 87:085cde657901 147 /* Configure the source, destination address and the data length */
mbed_official 87:085cde657901 148 DMA_MultiBufferSetConfig(hdma, SrcAddress, DstAddress, DataLength);
mbed_official 87:085cde657901 149
mbed_official 87:085cde657901 150 /* Enable the peripheral */
mbed_official 87:085cde657901 151 __HAL_DMA_ENABLE(hdma);
mbed_official 87:085cde657901 152
mbed_official 87:085cde657901 153 return HAL_OK;
mbed_official 87:085cde657901 154 }
mbed_official 87:085cde657901 155
mbed_official 87:085cde657901 156 /**
mbed_official 87:085cde657901 157 * @brief Starts the multi_buffer DMA Transfer with interrupt enabled.
mbed_official 87:085cde657901 158 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
mbed_official 87:085cde657901 159 * the configuration information for the specified DMA Stream.
mbed_official 87:085cde657901 160 * @param SrcAddress: The source memory Buffer address
mbed_official 87:085cde657901 161 * @param DstAddress: The destination memory Buffer address
mbed_official 87:085cde657901 162 * @param SecondMemAddress: The second memory Buffer address in case of multi buffer Transfer
mbed_official 87:085cde657901 163 * @param DataLength: The length of data to be transferred from source to destination
mbed_official 87:085cde657901 164 * @retval HAL status
mbed_official 87:085cde657901 165 */
mbed_official 87:085cde657901 166 HAL_StatusTypeDef HAL_DMAEx_MultiBufferStart_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t SecondMemAddress, uint32_t DataLength)
mbed_official 87:085cde657901 167 {
mbed_official 87:085cde657901 168 /* Process Locked */
mbed_official 87:085cde657901 169 __HAL_LOCK(hdma);
mbed_official 87:085cde657901 170
mbed_official 87:085cde657901 171 /* Current memory buffer used is Memory 0 */
mbed_official 87:085cde657901 172 if((hdma->Instance->CR & DMA_SxCR_CT) == 0)
mbed_official 87:085cde657901 173 {
mbed_official 87:085cde657901 174 hdma->State = HAL_DMA_STATE_BUSY_MEM0;
mbed_official 87:085cde657901 175 }
mbed_official 87:085cde657901 176 /* Current memory buffer used is Memory 1 */
mbed_official 87:085cde657901 177 else if((hdma->Instance->CR & DMA_SxCR_CT) != 0)
mbed_official 87:085cde657901 178 {
mbed_official 87:085cde657901 179 hdma->State = HAL_DMA_STATE_BUSY_MEM1;
mbed_official 87:085cde657901 180 }
mbed_official 87:085cde657901 181
mbed_official 87:085cde657901 182 /* Check the parameters */
mbed_official 87:085cde657901 183 assert_param(IS_DMA_BUFFER_SIZE(DataLength));
mbed_official 87:085cde657901 184
mbed_official 87:085cde657901 185 /* Disable the peripheral */
mbed_official 87:085cde657901 186 __HAL_DMA_DISABLE(hdma);
mbed_official 87:085cde657901 187
mbed_official 87:085cde657901 188 /* Enable the Double buffer mode */
mbed_official 87:085cde657901 189 hdma->Instance->CR |= (uint32_t)DMA_SxCR_DBM;
mbed_official 87:085cde657901 190
mbed_official 87:085cde657901 191 /* Configure DMA Stream destination address */
mbed_official 87:085cde657901 192 hdma->Instance->M1AR = SecondMemAddress;
mbed_official 87:085cde657901 193
mbed_official 87:085cde657901 194 /* Configure the source, destination address and the data length */
mbed_official 87:085cde657901 195 DMA_MultiBufferSetConfig(hdma, SrcAddress, DstAddress, DataLength);
mbed_official 87:085cde657901 196
mbed_official 87:085cde657901 197 /* Enable the transfer complete interrupt */
mbed_official 87:085cde657901 198 __HAL_DMA_ENABLE_IT(hdma, DMA_IT_TC);
mbed_official 87:085cde657901 199
mbed_official 87:085cde657901 200 /* Enable the Half transfer interrupt */
mbed_official 87:085cde657901 201 __HAL_DMA_ENABLE_IT(hdma, DMA_IT_HT);
mbed_official 87:085cde657901 202
mbed_official 87:085cde657901 203 /* Enable the transfer Error interrupt */
mbed_official 87:085cde657901 204 __HAL_DMA_ENABLE_IT(hdma, DMA_IT_TE);
mbed_official 87:085cde657901 205
mbed_official 87:085cde657901 206 /* Enable the fifo Error interrupt */
mbed_official 87:085cde657901 207 __HAL_DMA_ENABLE_IT(hdma, DMA_IT_FE);
mbed_official 87:085cde657901 208
mbed_official 87:085cde657901 209 /* Enable the direct mode Error interrupt */
mbed_official 87:085cde657901 210 __HAL_DMA_ENABLE_IT(hdma, DMA_IT_DME);
mbed_official 87:085cde657901 211
mbed_official 87:085cde657901 212 /* Enable the peripheral */
mbed_official 87:085cde657901 213 __HAL_DMA_ENABLE(hdma);
mbed_official 87:085cde657901 214
mbed_official 87:085cde657901 215 return HAL_OK;
mbed_official 87:085cde657901 216 }
mbed_official 87:085cde657901 217
mbed_official 87:085cde657901 218 /**
mbed_official 87:085cde657901 219 * @brief Change the memory0 or memory1 address on the fly.
mbed_official 87:085cde657901 220 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
mbed_official 87:085cde657901 221 * the configuration information for the specified DMA Stream.
mbed_official 87:085cde657901 222 * @param Address: The new address
mbed_official 87:085cde657901 223 * @param memory: the memory to be changed, This parameter can be one of
mbed_official 87:085cde657901 224 * the following values:
mbed_official 226:b062af740e40 225 * MEMORY0 /
mbed_official 226:b062af740e40 226 * MEMORY1
mbed_official 87:085cde657901 227 * @note The MEMORY0 address can be changed only when the current transfer use
mbed_official 87:085cde657901 228 * MEMORY1 and the MEMORY1 address can be changed only when the current
mbed_official 87:085cde657901 229 * transfer use MEMORY0.
mbed_official 87:085cde657901 230 * @retval HAL status
mbed_official 87:085cde657901 231 */
mbed_official 87:085cde657901 232 HAL_StatusTypeDef HAL_DMAEx_ChangeMemory(DMA_HandleTypeDef *hdma, uint32_t Address, HAL_DMA_MemoryTypeDef memory)
mbed_official 87:085cde657901 233 {
mbed_official 87:085cde657901 234 if(memory == MEMORY0)
mbed_official 87:085cde657901 235 {
mbed_official 87:085cde657901 236 /* change the memory0 address */
mbed_official 87:085cde657901 237 hdma->Instance->M0AR = Address;
mbed_official 87:085cde657901 238 }
mbed_official 87:085cde657901 239 else
mbed_official 87:085cde657901 240 {
mbed_official 87:085cde657901 241 /* change the memory1 address */
mbed_official 87:085cde657901 242 hdma->Instance->M1AR = Address;
mbed_official 87:085cde657901 243 }
mbed_official 87:085cde657901 244
mbed_official 87:085cde657901 245 return HAL_OK;
mbed_official 87:085cde657901 246 }
mbed_official 87:085cde657901 247
mbed_official 87:085cde657901 248 /**
mbed_official 87:085cde657901 249 * @}
mbed_official 87:085cde657901 250 */
mbed_official 87:085cde657901 251
mbed_official 87:085cde657901 252 /**
mbed_official 532:fe11edbda85c 253 * @}
mbed_official 532:fe11edbda85c 254 */
mbed_official 532:fe11edbda85c 255
mbed_official 532:fe11edbda85c 256 /** @addtogroup DMAEx_Private_Functions
mbed_official 532:fe11edbda85c 257 * @{
mbed_official 532:fe11edbda85c 258 */
mbed_official 532:fe11edbda85c 259
mbed_official 532:fe11edbda85c 260 /**
mbed_official 87:085cde657901 261 * @brief Set the DMA Transfer parameter.
mbed_official 87:085cde657901 262 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
mbed_official 87:085cde657901 263 * the configuration information for the specified DMA Stream.
mbed_official 87:085cde657901 264 * @param SrcAddress: The source memory Buffer address
mbed_official 87:085cde657901 265 * @param DstAddress: The destination memory Buffer address
mbed_official 87:085cde657901 266 * @param DataLength: The length of data to be transferred from source to destination
mbed_official 87:085cde657901 267 * @retval HAL status
mbed_official 87:085cde657901 268 */
mbed_official 87:085cde657901 269 static void DMA_MultiBufferSetConfig(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
mbed_official 87:085cde657901 270 {
mbed_official 87:085cde657901 271 /* Configure DMA Stream data length */
mbed_official 87:085cde657901 272 hdma->Instance->NDTR = DataLength;
mbed_official 87:085cde657901 273
mbed_official 87:085cde657901 274 /* Peripheral to Memory */
mbed_official 87:085cde657901 275 if((hdma->Init.Direction) == DMA_MEMORY_TO_PERIPH)
mbed_official 87:085cde657901 276 {
mbed_official 87:085cde657901 277 /* Configure DMA Stream destination address */
mbed_official 87:085cde657901 278 hdma->Instance->PAR = DstAddress;
mbed_official 87:085cde657901 279
mbed_official 87:085cde657901 280 /* Configure DMA Stream source address */
mbed_official 87:085cde657901 281 hdma->Instance->M0AR = SrcAddress;
mbed_official 87:085cde657901 282 }
mbed_official 87:085cde657901 283 /* Memory to Peripheral */
mbed_official 87:085cde657901 284 else
mbed_official 87:085cde657901 285 {
mbed_official 87:085cde657901 286 /* Configure DMA Stream source address */
mbed_official 87:085cde657901 287 hdma->Instance->PAR = SrcAddress;
mbed_official 87:085cde657901 288
mbed_official 87:085cde657901 289 /* Configure DMA Stream destination address */
mbed_official 87:085cde657901 290 hdma->Instance->M0AR = DstAddress;
mbed_official 87:085cde657901 291 }
mbed_official 87:085cde657901 292 }
mbed_official 87:085cde657901 293
mbed_official 87:085cde657901 294 /**
mbed_official 87:085cde657901 295 * @}
mbed_official 87:085cde657901 296 */
mbed_official 87:085cde657901 297
mbed_official 87:085cde657901 298 #endif /* HAL_DMA_MODULE_ENABLED */
mbed_official 87:085cde657901 299 /**
mbed_official 87:085cde657901 300 * @}
mbed_official 87:085cde657901 301 */
mbed_official 87:085cde657901 302
mbed_official 87:085cde657901 303 /**
mbed_official 87:085cde657901 304 * @}
mbed_official 87:085cde657901 305 */
mbed_official 87:085cde657901 306
mbed_official 87:085cde657901 307 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/