mbed library sources

Dependents:   frdm_kl05z_gpio_test

Fork of mbed-src by mbed official

Committer:
shaoziyang
Date:
Sat Sep 13 14:25:46 2014 +0000
Revision:
323:9e901b0a5aa1
Parent:
235:685d5f11838f
test with CLOCK_SETUP = 0

Who changed what in which revision?

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