mbed library with additional peripherals for ST F401 board

Fork of mbed-src by mbed official

This mbed LIB has additional peripherals for ST F401 board

  • UART2 : PA_3 rx, PA_2 tx
  • UART3 : PC_7 rx, PC_6 tx
  • I2C2 : PB_3 SDA, PB_10 SCL
  • I2C3 : PB_4 SDA, PA_8 SCL
Committer:
mbed_official
Date:
Wed Feb 26 09:45:12 2014 +0000
Revision:
106:ced8cbb51063
Parent:
80:66393a7b209d
Synchronized with git revision 4222735eff5868389433f0e9271976b39c8115cd

Full URL: https://github.com/mbedmicro/mbed/commit/4222735eff5868389433f0e9271976b39c8115cd/

[NUCLEO_xxx] Update STM32CubeF4 driver V1.0.0 + update license

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 76:aeb1df146756 1 /**
mbed_official 76:aeb1df146756 2 ******************************************************************************
mbed_official 76:aeb1df146756 3 * @file stm32l1xx_flash_ramfunc.c
mbed_official 76:aeb1df146756 4 * @author MCD Application Team
mbed_official 80:66393a7b209d 5 * @version V1.3.0
mbed_official 80:66393a7b209d 6 * @date 31-January-2014
mbed_official 76:aeb1df146756 7 * @brief This file provides all the Flash firmware functions which should be
mbed_official 76:aeb1df146756 8 * executed from the internal SRAM. This file should be placed in
mbed_official 76:aeb1df146756 9 * internal SRAM.
mbed_official 76:aeb1df146756 10 * Other FLASH memory functions that can be used from the FLASH are
mbed_official 76:aeb1df146756 11 * defined in the "stm32l1xx_flash.c" file.
mbed_official 76:aeb1df146756 12 @verbatim
mbed_official 76:aeb1df146756 13
mbed_official 76:aeb1df146756 14 *** ARM Compiler ***
mbed_official 76:aeb1df146756 15 --------------------
mbed_official 76:aeb1df146756 16 [..] RAM functions are defined using the toolchain options.
mbed_official 76:aeb1df146756 17 Functions that are be executed in RAM should reside in a separate
mbed_official 76:aeb1df146756 18 source module. Using the 'Options for File' dialog you can simply change
mbed_official 76:aeb1df146756 19 the 'Code / Const' area of a module to a memory space in physical RAM.
mbed_official 76:aeb1df146756 20 Available memory areas are declared in the 'Target' tab of the
mbed_official 76:aeb1df146756 21 Options for Target' dialog.
mbed_official 76:aeb1df146756 22
mbed_official 76:aeb1df146756 23 *** ICCARM Compiler ***
mbed_official 76:aeb1df146756 24 -----------------------
mbed_official 76:aeb1df146756 25 [..] RAM functions are defined using a specific toolchain keyword "__ramfunc".
mbed_official 76:aeb1df146756 26
mbed_official 76:aeb1df146756 27 *** GNU Compiler ***
mbed_official 76:aeb1df146756 28 --------------------
mbed_official 76:aeb1df146756 29 [..] RAM functions are defined using a specific toolchain attribute
mbed_official 76:aeb1df146756 30 "__attribute__((section(".data")))".
mbed_official 76:aeb1df146756 31
mbed_official 76:aeb1df146756 32 *** TASKING Compiler ***
mbed_official 76:aeb1df146756 33 ------------------------
mbed_official 76:aeb1df146756 34 [..] RAM functions are defined using a specific toolchain pragma. This
mbed_official 76:aeb1df146756 35 pragma is defined inside this file.
mbed_official 76:aeb1df146756 36
mbed_official 76:aeb1df146756 37 @endverbatim
mbed_official 76:aeb1df146756 38 *
mbed_official 76:aeb1df146756 39 ******************************************************************************
mbed_official 76:aeb1df146756 40 * @attention
mbed_official 76:aeb1df146756 41 *
mbed_official 106:ced8cbb51063 42 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
mbed_official 76:aeb1df146756 43 *
mbed_official 106:ced8cbb51063 44 * Redistribution and use in source and binary forms, with or without modification,
mbed_official 106:ced8cbb51063 45 * are permitted provided that the following conditions are met:
mbed_official 106:ced8cbb51063 46 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 106:ced8cbb51063 47 * this list of conditions and the following disclaimer.
mbed_official 106:ced8cbb51063 48 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 106:ced8cbb51063 49 * this list of conditions and the following disclaimer in the documentation
mbed_official 106:ced8cbb51063 50 * and/or other materials provided with the distribution.
mbed_official 106:ced8cbb51063 51 * 3. Neither the name of STMicroelectronics nor the names of its contributors
mbed_official 106:ced8cbb51063 52 * may be used to endorse or promote products derived from this software
mbed_official 106:ced8cbb51063 53 * without specific prior written permission.
mbed_official 76:aeb1df146756 54 *
mbed_official 106:ced8cbb51063 55 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 106:ced8cbb51063 56 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 106:ced8cbb51063 57 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 106:ced8cbb51063 58 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mbed_official 106:ced8cbb51063 59 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 106:ced8cbb51063 60 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mbed_official 106:ced8cbb51063 61 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 106:ced8cbb51063 62 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbed_official 106:ced8cbb51063 63 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbed_official 106:ced8cbb51063 64 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 76:aeb1df146756 65 *
mbed_official 76:aeb1df146756 66 ******************************************************************************
mbed_official 76:aeb1df146756 67 */
mbed_official 76:aeb1df146756 68
mbed_official 76:aeb1df146756 69 /* Includes ------------------------------------------------------------------*/
mbed_official 76:aeb1df146756 70 #include "stm32l1xx_flash.h"
mbed_official 76:aeb1df146756 71
mbed_official 76:aeb1df146756 72 /** @addtogroup STM32L1xx_StdPeriph_Driver
mbed_official 76:aeb1df146756 73 * @{
mbed_official 76:aeb1df146756 74 */
mbed_official 76:aeb1df146756 75
mbed_official 76:aeb1df146756 76 /** @defgroup FLASH
mbed_official 76:aeb1df146756 77 * @brief FLASH driver modules
mbed_official 76:aeb1df146756 78 * @{
mbed_official 76:aeb1df146756 79 */
mbed_official 76:aeb1df146756 80
mbed_official 76:aeb1df146756 81 /* Private typedef -----------------------------------------------------------*/
mbed_official 76:aeb1df146756 82 /* Private define ------------------------------------------------------------*/
mbed_official 76:aeb1df146756 83 /* Private macro -------------------------------------------------------------*/
mbed_official 76:aeb1df146756 84 /* Private variables ---------------------------------------------------------*/
mbed_official 76:aeb1df146756 85 /* Private function prototypes -----------------------------------------------*/
mbed_official 76:aeb1df146756 86 static __RAM_FUNC GetStatus(void);
mbed_official 76:aeb1df146756 87 static __RAM_FUNC WaitForLastOperation(uint32_t Timeout);
mbed_official 76:aeb1df146756 88
mbed_official 76:aeb1df146756 89 /* Private functions ---------------------------------------------------------*/
mbed_official 76:aeb1df146756 90
mbed_official 76:aeb1df146756 91 /** @defgroup FLASH_Private_Functions
mbed_official 76:aeb1df146756 92 * @{
mbed_official 76:aeb1df146756 93 */
mbed_official 76:aeb1df146756 94
mbed_official 76:aeb1df146756 95 /** @addtogroup FLASH_Group1
mbed_official 76:aeb1df146756 96 *
mbed_official 76:aeb1df146756 97 @verbatim
mbed_official 76:aeb1df146756 98 @endverbatim
mbed_official 76:aeb1df146756 99 * @{
mbed_official 76:aeb1df146756 100 */
mbed_official 76:aeb1df146756 101 #if defined ( __TASKING__ )
mbed_official 76:aeb1df146756 102 #pragma section_code_init on
mbed_official 76:aeb1df146756 103 #endif
mbed_official 76:aeb1df146756 104
mbed_official 76:aeb1df146756 105 /**
mbed_official 76:aeb1df146756 106 * @brief Enable or disable the power down mode during RUN mode.
mbed_official 76:aeb1df146756 107 * @note This function can be used only when the user code is running from Internal SRAM.
mbed_official 76:aeb1df146756 108 * @param NewState: new state of the power down mode during RUN mode.
mbed_official 76:aeb1df146756 109 * This parameter can be: ENABLE or DISABLE.
mbed_official 76:aeb1df146756 110 * @retval None
mbed_official 76:aeb1df146756 111 */
mbed_official 76:aeb1df146756 112 __RAM_FUNC FLASH_RUNPowerDownCmd(FunctionalState NewState)
mbed_official 76:aeb1df146756 113 {
mbed_official 76:aeb1df146756 114 FLASH_Status status = FLASH_COMPLETE;
mbed_official 76:aeb1df146756 115
mbed_official 76:aeb1df146756 116 if (NewState != DISABLE)
mbed_official 76:aeb1df146756 117 {
mbed_official 76:aeb1df146756 118 /* Unlock the RUN_PD bit */
mbed_official 76:aeb1df146756 119 FLASH->PDKEYR = FLASH_PDKEY1;
mbed_official 76:aeb1df146756 120 FLASH->PDKEYR = FLASH_PDKEY2;
mbed_official 76:aeb1df146756 121
mbed_official 76:aeb1df146756 122 /* Set the RUN_PD bit in FLASH_ACR register to put Flash in power down mode */
mbed_official 76:aeb1df146756 123 FLASH->ACR |= (uint32_t)FLASH_ACR_RUN_PD;
mbed_official 76:aeb1df146756 124
mbed_official 76:aeb1df146756 125 if((FLASH->ACR & FLASH_ACR_RUN_PD) != FLASH_ACR_RUN_PD)
mbed_official 76:aeb1df146756 126 {
mbed_official 76:aeb1df146756 127 status = FLASH_ERROR_PROGRAM;
mbed_official 76:aeb1df146756 128 }
mbed_official 76:aeb1df146756 129 }
mbed_official 76:aeb1df146756 130 else
mbed_official 76:aeb1df146756 131 {
mbed_official 76:aeb1df146756 132 /* Clear the RUN_PD bit in FLASH_ACR register to put Flash in idle mode */
mbed_official 76:aeb1df146756 133 FLASH->ACR &= (uint32_t)(~(uint32_t)FLASH_ACR_RUN_PD);
mbed_official 76:aeb1df146756 134 }
mbed_official 76:aeb1df146756 135
mbed_official 76:aeb1df146756 136 /* Return the Write Status */
mbed_official 76:aeb1df146756 137 return status;
mbed_official 76:aeb1df146756 138 }
mbed_official 76:aeb1df146756 139
mbed_official 76:aeb1df146756 140 /**
mbed_official 76:aeb1df146756 141 * @}
mbed_official 76:aeb1df146756 142 */
mbed_official 76:aeb1df146756 143
mbed_official 76:aeb1df146756 144 /** @addtogroup FLASH_Group2
mbed_official 76:aeb1df146756 145 *
mbed_official 76:aeb1df146756 146 @verbatim
mbed_official 76:aeb1df146756 147 @endverbatim
mbed_official 76:aeb1df146756 148 * @{
mbed_official 76:aeb1df146756 149 */
mbed_official 76:aeb1df146756 150
mbed_official 76:aeb1df146756 151 /**
mbed_official 76:aeb1df146756 152 * @brief Erases a specified 2 page in program memory in parallel.
mbed_official 80:66393a7b209d 153 * @note This function can be used only for STM32L1XX_HD and STM32L1XX_XL devices.
mbed_official 76:aeb1df146756 154 * To correctly run this function, the FLASH_Unlock() function
mbed_official 76:aeb1df146756 155 * must be called before.
mbed_official 76:aeb1df146756 156 * Call the FLASH_Lock() to disable the flash memory access
mbed_official 76:aeb1df146756 157 * (recommended to protect the FLASH memory against possible unwanted operation).
mbed_official 76:aeb1df146756 158 * @param Page_Address1: The page address in program memory to be erased in
mbed_official 80:66393a7b209d 159 * the first Bank (BANK1). This parameter should be:
mbed_official 80:66393a7b209d 160 * - between 0x08000000 and 0x0802FF00 for STM32L1XX_HD devices
mbed_official 80:66393a7b209d 161 * - between 0x08000000 and 0x0803FF00 for STM32L1XX_XL devices
mbed_official 76:aeb1df146756 162 * @param Page_Address2: The page address in program memory to be erased in
mbed_official 80:66393a7b209d 163 * the second Bank (BANK2). This parameter should be:
mbed_official 80:66393a7b209d 164 * - between 0x08030000 and 0x0805FF00 for STM32L1XX_HD devices
mbed_official 80:66393a7b209d 165 * - between 0x08040000 and 0x0807FF00 for STM32L1XX_XL devices
mbed_official 76:aeb1df146756 166 * @note A Page is erased in the Program memory only if the address to load
mbed_official 76:aeb1df146756 167 * is the start address of a page (multiple of 256 bytes).
mbed_official 76:aeb1df146756 168 * @retval FLASH Status: The returned value can be:
mbed_official 76:aeb1df146756 169 * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
mbed_official 76:aeb1df146756 170 */
mbed_official 76:aeb1df146756 171 FLASH_Status FLASH_EraseParallelPage(uint32_t Page_Address1, uint32_t Page_Address2)
mbed_official 76:aeb1df146756 172 {
mbed_official 76:aeb1df146756 173 FLASH_Status status = FLASH_COMPLETE;
mbed_official 76:aeb1df146756 174
mbed_official 76:aeb1df146756 175 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 176 status = WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 177
mbed_official 76:aeb1df146756 178 if(status == FLASH_COMPLETE)
mbed_official 76:aeb1df146756 179 {
mbed_official 76:aeb1df146756 180 /* If the previous operation is completed, proceed to erase the page */
mbed_official 76:aeb1df146756 181
mbed_official 76:aeb1df146756 182 /* Set the PARALLBANK bit */
mbed_official 76:aeb1df146756 183 FLASH->PECR |= FLASH_PECR_PARALLBANK;
mbed_official 76:aeb1df146756 184
mbed_official 76:aeb1df146756 185 /* Set the ERASE bit */
mbed_official 76:aeb1df146756 186 FLASH->PECR |= FLASH_PECR_ERASE;
mbed_official 76:aeb1df146756 187
mbed_official 76:aeb1df146756 188 /* Set PROG bit */
mbed_official 76:aeb1df146756 189 FLASH->PECR |= FLASH_PECR_PROG;
mbed_official 76:aeb1df146756 190
mbed_official 76:aeb1df146756 191 /* Write 00000000h to the first word of the first program page to erase */
mbed_official 76:aeb1df146756 192 *(__IO uint32_t *)Page_Address1 = 0x00000000;
mbed_official 76:aeb1df146756 193 /* Write 00000000h to the first word of the second program page to erase */
mbed_official 76:aeb1df146756 194 *(__IO uint32_t *)Page_Address2 = 0x00000000;
mbed_official 76:aeb1df146756 195
mbed_official 76:aeb1df146756 196 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 197 status = WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 198
mbed_official 76:aeb1df146756 199 /* If the erase operation is completed, disable the ERASE, PROG and PARALLBANK bits */
mbed_official 76:aeb1df146756 200 FLASH->PECR &= (uint32_t)(~FLASH_PECR_PROG);
mbed_official 76:aeb1df146756 201 FLASH->PECR &= (uint32_t)(~FLASH_PECR_ERASE);
mbed_official 76:aeb1df146756 202 FLASH->PECR &= (uint32_t)(~FLASH_PECR_PARALLBANK);
mbed_official 76:aeb1df146756 203 }
mbed_official 76:aeb1df146756 204 /* Return the Erase Status */
mbed_official 76:aeb1df146756 205 return status;
mbed_official 76:aeb1df146756 206 }
mbed_official 76:aeb1df146756 207
mbed_official 76:aeb1df146756 208 /**
mbed_official 76:aeb1df146756 209 * @brief Programs a half page in program memory.
mbed_official 76:aeb1df146756 210 * @param Address: specifies the address to be written.
mbed_official 76:aeb1df146756 211 * @param pBuffer: pointer to the buffer containing the data to be written to
mbed_official 76:aeb1df146756 212 * the half page.
mbed_official 76:aeb1df146756 213 * @note To correctly run this function, the FLASH_Unlock() function
mbed_official 76:aeb1df146756 214 * must be called before.
mbed_official 76:aeb1df146756 215 * Call the FLASH_Lock() to disable the flash memory access
mbed_official 76:aeb1df146756 216 * (recommended to protect the FLASH memory against possible unwanted operation)
mbed_official 76:aeb1df146756 217 * @note Half page write is possible only from SRAM.
mbed_official 76:aeb1df146756 218 * @note If there are more than 32 words to write, after 32 words another
mbed_official 76:aeb1df146756 219 * Half Page programming operation starts and has to be finished.
mbed_official 76:aeb1df146756 220 * @note A half page is written to the program memory only if the first
mbed_official 76:aeb1df146756 221 * address to load is the start address of a half page (multiple of 128
mbed_official 76:aeb1df146756 222 * bytes) and the 31 remaining words to load are in the same half page.
mbed_official 76:aeb1df146756 223 * @note During the Program memory half page write all read operations are
mbed_official 76:aeb1df146756 224 * forbidden (this includes DMA read operations and debugger read
mbed_official 76:aeb1df146756 225 * operations such as breakpoints, periodic updates, etc.).
mbed_official 76:aeb1df146756 226 * @note If a PGAERR is set during a Program memory half page write, the
mbed_official 76:aeb1df146756 227 * complete write operation is aborted. Software should then reset the
mbed_official 76:aeb1df146756 228 * FPRG and PROG/DATA bits and restart the write operation from the
mbed_official 76:aeb1df146756 229 * beginning.
mbed_official 76:aeb1df146756 230 * @retval FLASH Status: The returned value can be:
mbed_official 76:aeb1df146756 231 * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
mbed_official 76:aeb1df146756 232 */
mbed_official 76:aeb1df146756 233 __RAM_FUNC FLASH_ProgramHalfPage(uint32_t Address, uint32_t* pBuffer)
mbed_official 76:aeb1df146756 234 {
mbed_official 76:aeb1df146756 235 uint32_t count = 0;
mbed_official 76:aeb1df146756 236
mbed_official 76:aeb1df146756 237 FLASH_Status status = FLASH_COMPLETE;
mbed_official 76:aeb1df146756 238
mbed_official 76:aeb1df146756 239 /* Set the DISMCYCINT[0] bit in the Auxillary Control Register (0xE000E008)
mbed_official 76:aeb1df146756 240 This bit prevents the interruption of multicycle instructions and therefore
mbed_official 76:aeb1df146756 241 will increase the interrupt latency. of Cortex-M3. */
mbed_official 76:aeb1df146756 242 SCnSCB->ACTLR |= SCnSCB_ACTLR_DISMCYCINT_Msk;
mbed_official 76:aeb1df146756 243
mbed_official 76:aeb1df146756 244 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 245 status = WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 246
mbed_official 76:aeb1df146756 247 if(status == FLASH_COMPLETE)
mbed_official 76:aeb1df146756 248 {
mbed_official 76:aeb1df146756 249 /* if the previous operation is completed, proceed to program the new
mbed_official 76:aeb1df146756 250 half page */
mbed_official 76:aeb1df146756 251 FLASH->PECR |= FLASH_PECR_FPRG;
mbed_official 76:aeb1df146756 252 FLASH->PECR |= FLASH_PECR_PROG;
mbed_official 76:aeb1df146756 253
mbed_official 76:aeb1df146756 254 /* Write one half page directly with 32 different words */
mbed_official 76:aeb1df146756 255 while(count < 32)
mbed_official 76:aeb1df146756 256 {
mbed_official 76:aeb1df146756 257 *(__IO uint32_t*) (Address + (4 * count)) = *(pBuffer++);
mbed_official 76:aeb1df146756 258 count ++;
mbed_official 76:aeb1df146756 259 }
mbed_official 76:aeb1df146756 260 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 261 status = WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 262
mbed_official 76:aeb1df146756 263 /* if the write operation is completed, disable the PROG and FPRG bits */
mbed_official 76:aeb1df146756 264 FLASH->PECR &= (uint32_t)(~FLASH_PECR_PROG);
mbed_official 76:aeb1df146756 265 FLASH->PECR &= (uint32_t)(~FLASH_PECR_FPRG);
mbed_official 76:aeb1df146756 266 }
mbed_official 76:aeb1df146756 267
mbed_official 76:aeb1df146756 268 SCnSCB->ACTLR &= ~SCnSCB_ACTLR_DISMCYCINT_Msk;
mbed_official 76:aeb1df146756 269
mbed_official 76:aeb1df146756 270 /* Return the Write Status */
mbed_official 76:aeb1df146756 271 return status;
mbed_official 76:aeb1df146756 272 }
mbed_official 76:aeb1df146756 273
mbed_official 76:aeb1df146756 274 /**
mbed_official 76:aeb1df146756 275 * @brief Programs 2 half page in program memory in parallel.
mbed_official 76:aeb1df146756 276 * @param Address1: specifies the first address to be written in the first bank
mbed_official 80:66393a7b209d 277 * (BANK1).This parameter should be:
mbed_official 80:66393a7b209d 278 * - between 0x08000000 and 0x0802FF80 for STM32L1XX_HD devices
mbed_official 80:66393a7b209d 279 * - between 0x08000000 and 0x0803FF80 for STM32L1XX_XL devices
mbed_official 76:aeb1df146756 280 * @param pBuffer1: pointer to the buffer containing the data to be written
mbed_official 76:aeb1df146756 281 * to the first half page in the first bank.
mbed_official 76:aeb1df146756 282 * @param Address2: specifies the second address to be written in the second bank
mbed_official 80:66393a7b209d 283 * (BANK2). This parameter should be:
mbed_official 80:66393a7b209d 284 * - between 0x08030000 and 0x0805FF80 for STM32L1XX_HD devices
mbed_official 80:66393a7b209d 285 * - between 0x08040000 and 0x0807FF80 for STM32L1XX_XL devices
mbed_official 76:aeb1df146756 286 * @param pBuffer2: pointer to the buffer containing the data to be written
mbed_official 76:aeb1df146756 287 * to the second half page in the second bank.
mbed_official 80:66393a7b209d 288 * @note This function can be used only for STM32L1XX_HD and STM32L1XX_XL devices.
mbed_official 76:aeb1df146756 289 * @note To correctly run this function, the FLASH_Unlock() function
mbed_official 76:aeb1df146756 290 * must be called before.
mbed_official 76:aeb1df146756 291 * Call the FLASH_Lock() to disable the flash memory access
mbed_official 76:aeb1df146756 292 * (recommended to protect the FLASH memory against possible unwanted operation).
mbed_official 76:aeb1df146756 293 * @note Half page write is possible only from SRAM.
mbed_official 76:aeb1df146756 294 * @note If there are more than 32 words to write, after 32 words another
mbed_official 76:aeb1df146756 295 * Half Page programming operation starts and has to be finished.
mbed_official 76:aeb1df146756 296 * @note A half page is written to the program memory only if the first
mbed_official 76:aeb1df146756 297 * address to load is the start address of a half page (multiple of 128
mbed_official 76:aeb1df146756 298 * bytes) and the 31 remaining words to load are in the same half page.
mbed_official 76:aeb1df146756 299 * @note During the Program memory half page write all read operations are
mbed_official 76:aeb1df146756 300 * forbidden (this includes DMA read operations and debugger read
mbed_official 76:aeb1df146756 301 * operations such as breakpoints, periodic updates, etc.).
mbed_official 76:aeb1df146756 302 * @note If a PGAERR is set during a Program memory half page write, the
mbed_official 76:aeb1df146756 303 * complete write operation is aborted. Software should then reset the
mbed_official 76:aeb1df146756 304 * FPRG and PROG/DATA bits and restart the write operation from the
mbed_official 76:aeb1df146756 305 * beginning.
mbed_official 76:aeb1df146756 306 * @retval FLASH Status: The returned value can be:
mbed_official 76:aeb1df146756 307 * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
mbed_official 76:aeb1df146756 308 */
mbed_official 76:aeb1df146756 309 __RAM_FUNC FLASH_ProgramParallelHalfPage(uint32_t Address1, uint32_t* pBuffer1, uint32_t Address2, uint32_t* pBuffer2)
mbed_official 76:aeb1df146756 310 {
mbed_official 76:aeb1df146756 311 uint32_t count = 0;
mbed_official 76:aeb1df146756 312
mbed_official 76:aeb1df146756 313 FLASH_Status status = FLASH_COMPLETE;
mbed_official 76:aeb1df146756 314
mbed_official 76:aeb1df146756 315 /* Set the DISMCYCINT[0] bit in the Auxillary Control Register (0xE000E008)
mbed_official 76:aeb1df146756 316 This bit prevents the interruption of multicycle instructions and therefore
mbed_official 76:aeb1df146756 317 will increase the interrupt latency. of Cortex-M3. */
mbed_official 76:aeb1df146756 318 SCnSCB->ACTLR |= SCnSCB_ACTLR_DISMCYCINT_Msk;
mbed_official 76:aeb1df146756 319
mbed_official 76:aeb1df146756 320 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 321 status = WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 322
mbed_official 76:aeb1df146756 323 if(status == FLASH_COMPLETE)
mbed_official 76:aeb1df146756 324 {
mbed_official 76:aeb1df146756 325 /* If the previous operation is completed, proceed to program the new
mbed_official 76:aeb1df146756 326 half page */
mbed_official 76:aeb1df146756 327 FLASH->PECR |= FLASH_PECR_PARALLBANK;
mbed_official 76:aeb1df146756 328 FLASH->PECR |= FLASH_PECR_FPRG;
mbed_official 76:aeb1df146756 329 FLASH->PECR |= FLASH_PECR_PROG;
mbed_official 76:aeb1df146756 330
mbed_official 76:aeb1df146756 331 /* Write the first half page directly with 32 different words */
mbed_official 76:aeb1df146756 332 while(count < 32)
mbed_official 76:aeb1df146756 333 {
mbed_official 76:aeb1df146756 334 *(__IO uint32_t*) (Address1 + (4 * count)) = *(pBuffer1++);
mbed_official 76:aeb1df146756 335 count ++;
mbed_official 76:aeb1df146756 336 }
mbed_official 76:aeb1df146756 337 count = 0;
mbed_official 76:aeb1df146756 338 /* Write the second half page directly with 32 different words */
mbed_official 76:aeb1df146756 339 while(count < 32)
mbed_official 76:aeb1df146756 340 {
mbed_official 76:aeb1df146756 341 *(__IO uint32_t*) (Address2 + (4 * count)) = *(pBuffer2++);
mbed_official 76:aeb1df146756 342 count ++;
mbed_official 76:aeb1df146756 343 }
mbed_official 76:aeb1df146756 344 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 345 status = WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 346
mbed_official 76:aeb1df146756 347 /* if the write operation is completed, disable the PROG, FPRG and PARALLBANK bits */
mbed_official 76:aeb1df146756 348 FLASH->PECR &= (uint32_t)(~FLASH_PECR_PROG);
mbed_official 76:aeb1df146756 349 FLASH->PECR &= (uint32_t)(~FLASH_PECR_FPRG);
mbed_official 76:aeb1df146756 350 FLASH->PECR &= (uint32_t)(~FLASH_PECR_PARALLBANK);
mbed_official 76:aeb1df146756 351 }
mbed_official 76:aeb1df146756 352
mbed_official 76:aeb1df146756 353 SCnSCB->ACTLR &= ~SCnSCB_ACTLR_DISMCYCINT_Msk;
mbed_official 76:aeb1df146756 354
mbed_official 76:aeb1df146756 355 /* Return the Write Status */
mbed_official 76:aeb1df146756 356 return status;
mbed_official 76:aeb1df146756 357 }
mbed_official 76:aeb1df146756 358
mbed_official 76:aeb1df146756 359 /**
mbed_official 76:aeb1df146756 360 * @}
mbed_official 76:aeb1df146756 361 */
mbed_official 76:aeb1df146756 362
mbed_official 76:aeb1df146756 363 /** @addtogroup FLASH_Group3
mbed_official 76:aeb1df146756 364 *
mbed_official 76:aeb1df146756 365 @verbatim
mbed_official 76:aeb1df146756 366 @endverbatim
mbed_official 76:aeb1df146756 367 * @{
mbed_official 76:aeb1df146756 368 */
mbed_official 76:aeb1df146756 369
mbed_official 76:aeb1df146756 370 /**
mbed_official 76:aeb1df146756 371 * @brief Erase a double word in data memory.
mbed_official 76:aeb1df146756 372 * @param Address: specifies the address to be erased.
mbed_official 76:aeb1df146756 373 * @note To correctly run this function, the DATA_EEPROM_Unlock() function
mbed_official 76:aeb1df146756 374 * must be called before.
mbed_official 76:aeb1df146756 375 * Call the DATA_EEPROM_Lock() to he data EEPROM access
mbed_official 76:aeb1df146756 376 * and Flash program erase control register access(recommended to protect
mbed_official 76:aeb1df146756 377 * the DATA_EEPROM against possible unwanted operation).
mbed_official 76:aeb1df146756 378 * @note Data memory double word erase is possible only from SRAM.
mbed_official 76:aeb1df146756 379 * @note A double word is erased to the data memory only if the first address
mbed_official 76:aeb1df146756 380 * to load is the start address of a double word (multiple of 8 bytes).
mbed_official 76:aeb1df146756 381 * @note During the Data memory double word erase, all read operations are
mbed_official 76:aeb1df146756 382 * forbidden (this includes DMA read operations and debugger read
mbed_official 76:aeb1df146756 383 * operations such as breakpoints, periodic updates, etc.).
mbed_official 76:aeb1df146756 384 * @retval FLASH Status: The returned value can be:
mbed_official 76:aeb1df146756 385 * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
mbed_official 76:aeb1df146756 386 */
mbed_official 76:aeb1df146756 387
mbed_official 76:aeb1df146756 388 __RAM_FUNC DATA_EEPROM_EraseDoubleWord(uint32_t Address)
mbed_official 76:aeb1df146756 389 {
mbed_official 76:aeb1df146756 390 FLASH_Status status = FLASH_COMPLETE;
mbed_official 76:aeb1df146756 391
mbed_official 76:aeb1df146756 392 /* Set the DISMCYCINT[0] bit in the Auxillary Control Register (0xE000E008)
mbed_official 76:aeb1df146756 393 This bit prevents the interruption of multicycle instructions and therefore
mbed_official 76:aeb1df146756 394 will increase the interrupt latency. of Cortex-M3. */
mbed_official 76:aeb1df146756 395 SCnSCB->ACTLR |= SCnSCB_ACTLR_DISMCYCINT_Msk;
mbed_official 76:aeb1df146756 396
mbed_official 76:aeb1df146756 397 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 398 status = WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 399
mbed_official 76:aeb1df146756 400 if(status == FLASH_COMPLETE)
mbed_official 76:aeb1df146756 401 {
mbed_official 76:aeb1df146756 402 /* If the previous operation is completed, proceed to erase the next double word */
mbed_official 76:aeb1df146756 403 /* Set the ERASE bit */
mbed_official 76:aeb1df146756 404 FLASH->PECR |= FLASH_PECR_ERASE;
mbed_official 76:aeb1df146756 405
mbed_official 76:aeb1df146756 406 /* Set DATA bit */
mbed_official 76:aeb1df146756 407 FLASH->PECR |= FLASH_PECR_DATA;
mbed_official 76:aeb1df146756 408
mbed_official 76:aeb1df146756 409 /* Write 00000000h to the 2 words to erase */
mbed_official 76:aeb1df146756 410 *(__IO uint32_t *)Address = 0x00000000;
mbed_official 76:aeb1df146756 411 Address += 4;
mbed_official 76:aeb1df146756 412 *(__IO uint32_t *)Address = 0x00000000;
mbed_official 76:aeb1df146756 413
mbed_official 76:aeb1df146756 414 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 415 status = WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 416
mbed_official 76:aeb1df146756 417 /* If the erase operation is completed, disable the ERASE and DATA bits */
mbed_official 76:aeb1df146756 418 FLASH->PECR &= (uint32_t)(~FLASH_PECR_ERASE);
mbed_official 76:aeb1df146756 419 FLASH->PECR &= (uint32_t)(~FLASH_PECR_DATA);
mbed_official 76:aeb1df146756 420 }
mbed_official 76:aeb1df146756 421
mbed_official 76:aeb1df146756 422 SCnSCB->ACTLR &= ~SCnSCB_ACTLR_DISMCYCINT_Msk;
mbed_official 76:aeb1df146756 423
mbed_official 76:aeb1df146756 424 /* Return the erase status */
mbed_official 76:aeb1df146756 425 return status;
mbed_official 76:aeb1df146756 426 }
mbed_official 76:aeb1df146756 427
mbed_official 76:aeb1df146756 428 /**
mbed_official 76:aeb1df146756 429 * @brief Write a double word in data memory without erase.
mbed_official 76:aeb1df146756 430 * @param Address: specifies the address to be written.
mbed_official 76:aeb1df146756 431 * @param Data: specifies the data to be written.
mbed_official 76:aeb1df146756 432 * @note To correctly run this function, the DATA_EEPROM_Unlock() function
mbed_official 76:aeb1df146756 433 * must be called before.
mbed_official 76:aeb1df146756 434 * Call the DATA_EEPROM_Lock() to he data EEPROM access
mbed_official 76:aeb1df146756 435 * and Flash program erase control register access(recommended to protect
mbed_official 76:aeb1df146756 436 * the DATA_EEPROM against possible unwanted operation).
mbed_official 76:aeb1df146756 437 * @note Data memory double word write is possible only from SRAM.
mbed_official 76:aeb1df146756 438 * @note A data memory double word is written to the data memory only if the
mbed_official 76:aeb1df146756 439 * first address to load is the start address of a double word (multiple
mbed_official 76:aeb1df146756 440 * of double word).
mbed_official 76:aeb1df146756 441 * @note During the Data memory double word write, all read operations are
mbed_official 76:aeb1df146756 442 * forbidden (this includes DMA read operations and debugger read
mbed_official 76:aeb1df146756 443 * operations such as breakpoints, periodic updates, etc.).
mbed_official 76:aeb1df146756 444 * @retval FLASH Status: The returned value can be:
mbed_official 76:aeb1df146756 445 * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
mbed_official 76:aeb1df146756 446 */
mbed_official 76:aeb1df146756 447 __RAM_FUNC DATA_EEPROM_ProgramDoubleWord(uint32_t Address, uint64_t Data)
mbed_official 76:aeb1df146756 448 {
mbed_official 76:aeb1df146756 449 FLASH_Status status = FLASH_COMPLETE;
mbed_official 76:aeb1df146756 450
mbed_official 76:aeb1df146756 451 /* Set the DISMCYCINT[0] bit in the Auxillary Control Register (0xE000E008)
mbed_official 76:aeb1df146756 452 This bit prevents the interruption of multicycle instructions and therefore
mbed_official 76:aeb1df146756 453 will increase the interrupt latency. of Cortex-M3. */
mbed_official 76:aeb1df146756 454 SCnSCB->ACTLR |= SCnSCB_ACTLR_DISMCYCINT_Msk;
mbed_official 76:aeb1df146756 455
mbed_official 76:aeb1df146756 456 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 457 status = WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 458
mbed_official 76:aeb1df146756 459 if(status == FLASH_COMPLETE)
mbed_official 76:aeb1df146756 460 {
mbed_official 76:aeb1df146756 461 /* If the previous operation is completed, proceed to program the new data*/
mbed_official 76:aeb1df146756 462 FLASH->PECR |= FLASH_PECR_FPRG;
mbed_official 76:aeb1df146756 463 FLASH->PECR |= FLASH_PECR_DATA;
mbed_official 76:aeb1df146756 464
mbed_official 76:aeb1df146756 465 /* Write the 2 words */
mbed_official 76:aeb1df146756 466 *(__IO uint32_t *)Address = (uint32_t) Data;
mbed_official 76:aeb1df146756 467 Address += 4;
mbed_official 76:aeb1df146756 468 *(__IO uint32_t *)Address = (uint32_t) (Data >> 32);
mbed_official 76:aeb1df146756 469
mbed_official 76:aeb1df146756 470 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 471 status = WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 472
mbed_official 76:aeb1df146756 473 /* If the write operation is completed, disable the FPRG and DATA bits */
mbed_official 76:aeb1df146756 474 FLASH->PECR &= (uint32_t)(~FLASH_PECR_FPRG);
mbed_official 76:aeb1df146756 475 FLASH->PECR &= (uint32_t)(~FLASH_PECR_DATA);
mbed_official 76:aeb1df146756 476 }
mbed_official 76:aeb1df146756 477
mbed_official 76:aeb1df146756 478 SCnSCB->ACTLR &= ~SCnSCB_ACTLR_DISMCYCINT_Msk;
mbed_official 76:aeb1df146756 479
mbed_official 76:aeb1df146756 480 /* Return the Write Status */
mbed_official 76:aeb1df146756 481 return status;
mbed_official 76:aeb1df146756 482 }
mbed_official 76:aeb1df146756 483
mbed_official 76:aeb1df146756 484 /**
mbed_official 76:aeb1df146756 485 * @}
mbed_official 76:aeb1df146756 486 */
mbed_official 76:aeb1df146756 487
mbed_official 76:aeb1df146756 488 /**
mbed_official 76:aeb1df146756 489 * @brief Returns the FLASH Status.
mbed_official 76:aeb1df146756 490 * @param None
mbed_official 76:aeb1df146756 491 * @retval FLASH Status: The returned value can be: FLASH_BUSY,
mbed_official 76:aeb1df146756 492 * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP or FLASH_COMPLETE
mbed_official 76:aeb1df146756 493 */
mbed_official 76:aeb1df146756 494 static __RAM_FUNC GetStatus(void)
mbed_official 76:aeb1df146756 495 {
mbed_official 76:aeb1df146756 496 FLASH_Status FLASHstatus = FLASH_COMPLETE;
mbed_official 76:aeb1df146756 497
mbed_official 76:aeb1df146756 498 if((FLASH->SR & FLASH_FLAG_BSY) == FLASH_FLAG_BSY)
mbed_official 76:aeb1df146756 499 {
mbed_official 76:aeb1df146756 500 FLASHstatus = FLASH_BUSY;
mbed_official 76:aeb1df146756 501 }
mbed_official 76:aeb1df146756 502 else
mbed_official 76:aeb1df146756 503 {
mbed_official 76:aeb1df146756 504 if((FLASH->SR & (uint32_t)FLASH_FLAG_WRPERR)!= (uint32_t)0x00)
mbed_official 76:aeb1df146756 505 {
mbed_official 76:aeb1df146756 506 FLASHstatus = FLASH_ERROR_WRP;
mbed_official 76:aeb1df146756 507 }
mbed_official 76:aeb1df146756 508 else
mbed_official 76:aeb1df146756 509 {
mbed_official 76:aeb1df146756 510 if((FLASH->SR & (uint32_t)0x1E00) != (uint32_t)0x00)
mbed_official 76:aeb1df146756 511 {
mbed_official 76:aeb1df146756 512 FLASHstatus = FLASH_ERROR_PROGRAM;
mbed_official 76:aeb1df146756 513 }
mbed_official 76:aeb1df146756 514 else
mbed_official 76:aeb1df146756 515 {
mbed_official 76:aeb1df146756 516 FLASHstatus = FLASH_COMPLETE;
mbed_official 76:aeb1df146756 517 }
mbed_official 76:aeb1df146756 518 }
mbed_official 76:aeb1df146756 519 }
mbed_official 76:aeb1df146756 520 /* Return the FLASH Status */
mbed_official 76:aeb1df146756 521 return FLASHstatus;
mbed_official 76:aeb1df146756 522 }
mbed_official 76:aeb1df146756 523
mbed_official 76:aeb1df146756 524 /**
mbed_official 76:aeb1df146756 525 * @brief Waits for a FLASH operation to complete or a TIMEOUT to occur.
mbed_official 76:aeb1df146756 526 * @param Timeout: FLASH programming Timeout
mbed_official 76:aeb1df146756 527 * @retval FLASH Status: The returned value can be: FLASH_BUSY,
mbed_official 76:aeb1df146756 528 * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or
mbed_official 76:aeb1df146756 529 * FLASH_TIMEOUT.
mbed_official 76:aeb1df146756 530 */
mbed_official 76:aeb1df146756 531 static __RAM_FUNC WaitForLastOperation(uint32_t Timeout)
mbed_official 76:aeb1df146756 532 {
mbed_official 76:aeb1df146756 533 __IO FLASH_Status status = FLASH_COMPLETE;
mbed_official 76:aeb1df146756 534
mbed_official 76:aeb1df146756 535 /* Check for the FLASH Status */
mbed_official 76:aeb1df146756 536 status = GetStatus();
mbed_official 76:aeb1df146756 537
mbed_official 76:aeb1df146756 538 /* Wait for a FLASH operation to complete or a TIMEOUT to occur */
mbed_official 76:aeb1df146756 539 while((status == FLASH_BUSY) && (Timeout != 0x00))
mbed_official 76:aeb1df146756 540 {
mbed_official 76:aeb1df146756 541 status = GetStatus();
mbed_official 76:aeb1df146756 542 Timeout--;
mbed_official 76:aeb1df146756 543 }
mbed_official 76:aeb1df146756 544
mbed_official 76:aeb1df146756 545 if(Timeout == 0x00 )
mbed_official 76:aeb1df146756 546 {
mbed_official 76:aeb1df146756 547 status = FLASH_TIMEOUT;
mbed_official 76:aeb1df146756 548 }
mbed_official 76:aeb1df146756 549 /* Return the operation status */
mbed_official 76:aeb1df146756 550 return status;
mbed_official 76:aeb1df146756 551 }
mbed_official 76:aeb1df146756 552
mbed_official 76:aeb1df146756 553 #if defined ( __TASKING__ )
mbed_official 76:aeb1df146756 554 #pragma section_code_init restore
mbed_official 76:aeb1df146756 555 #endif
mbed_official 76:aeb1df146756 556
mbed_official 76:aeb1df146756 557 /**
mbed_official 76:aeb1df146756 558 * @}
mbed_official 76:aeb1df146756 559 */
mbed_official 76:aeb1df146756 560
mbed_official 76:aeb1df146756 561 /**
mbed_official 76:aeb1df146756 562 * @}
mbed_official 76:aeb1df146756 563 */
mbed_official 76:aeb1df146756 564
mbed_official 76:aeb1df146756 565 /**
mbed_official 76:aeb1df146756 566 * @}
mbed_official 76:aeb1df146756 567 */
mbed_official 76:aeb1df146756 568
mbed_official 76:aeb1df146756 569 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/