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:
Wed Jul 01 09:45:11 2015 +0100
Revision:
579:53297373a894
Parent:
489:119543c9f674
Synchronized with git revision d5b4d2ab9c47edb4dc5776e7177b0c2263459081

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

Initial version of drivers for SAMR21

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 376:cb4d9db17537 1 /**
mbed_official 376:cb4d9db17537 2 ******************************************************************************
mbed_official 376:cb4d9db17537 3 * @file stm32l0xx_hal_flash_ramfunc.c
mbed_official 376:cb4d9db17537 4 * @author MCD Application Team
mbed_official 489:119543c9f674 5 * @version V1.2.0
mbed_official 489:119543c9f674 6 * @date 06-February-2015
mbed_official 376:cb4d9db17537 7 * @brief FLASH RAMFUNC driver.
mbed_official 376:cb4d9db17537 8 * This file provides a Flash firmware functions which should be
mbed_official 376:cb4d9db17537 9 * executed from internal SRAM
mbed_official 376:cb4d9db17537 10 *
mbed_official 376:cb4d9db17537 11 * @verbatim
mbed_official 376:cb4d9db17537 12
mbed_official 376:cb4d9db17537 13 *** ARM Compiler ***
mbed_official 376:cb4d9db17537 14 --------------------
mbed_official 376:cb4d9db17537 15 [..] RAM functions are defined using the toolchain options.
mbed_official 376:cb4d9db17537 16 Functions that are be executed in RAM should reside in a separate
mbed_official 376:cb4d9db17537 17 source module. Using the 'Options for File' dialog you can simply change
mbed_official 376:cb4d9db17537 18 the 'Code / Const' area of a module to a memory space in physical RAM.
mbed_official 376:cb4d9db17537 19 Available memory areas are declared in the 'Target' tab of the
mbed_official 376:cb4d9db17537 20 Options for Target' dialog.
mbed_official 376:cb4d9db17537 21
mbed_official 376:cb4d9db17537 22 *** ICCARM Compiler ***
mbed_official 376:cb4d9db17537 23 -----------------------
mbed_official 376:cb4d9db17537 24 [..] RAM functions are defined using a specific toolchain keyword "__ramfunc".
mbed_official 376:cb4d9db17537 25
mbed_official 376:cb4d9db17537 26 *** GNU Compiler ***
mbed_official 376:cb4d9db17537 27 --------------------
mbed_official 376:cb4d9db17537 28 [..] RAM functions are defined using a specific toolchain attribute
mbed_official 376:cb4d9db17537 29 "__attribute__((section(".RamFunc")))".
mbed_official 489:119543c9f674 30
mbed_official 489:119543c9f674 31 @endverbatim
mbed_official 376:cb4d9db17537 32 ******************************************************************************
mbed_official 376:cb4d9db17537 33 * @attention
mbed_official 376:cb4d9db17537 34 *
mbed_official 489:119543c9f674 35 * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
mbed_official 376:cb4d9db17537 36 *
mbed_official 376:cb4d9db17537 37 * Redistribution and use in source and binary forms, with or without modification,
mbed_official 376:cb4d9db17537 38 * are permitted provided that the following conditions are met:
mbed_official 376:cb4d9db17537 39 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 376:cb4d9db17537 40 * this list of conditions and the following disclaimer.
mbed_official 376:cb4d9db17537 41 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 376:cb4d9db17537 42 * this list of conditions and the following disclaimer in the documentation
mbed_official 376:cb4d9db17537 43 * and/or other materials provided with the distribution.
mbed_official 376:cb4d9db17537 44 * 3. Neither the name of STMicroelectronics nor the names of its contributors
mbed_official 376:cb4d9db17537 45 * may be used to endorse or promote products derived from this software
mbed_official 376:cb4d9db17537 46 * without specific prior written permission.
mbed_official 376:cb4d9db17537 47 *
mbed_official 376:cb4d9db17537 48 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 376:cb4d9db17537 49 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 376:cb4d9db17537 50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 376:cb4d9db17537 51 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mbed_official 376:cb4d9db17537 52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 376:cb4d9db17537 53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mbed_official 376:cb4d9db17537 54 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 376:cb4d9db17537 55 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbed_official 376:cb4d9db17537 56 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbed_official 376:cb4d9db17537 57 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 376:cb4d9db17537 58 *
mbed_official 376:cb4d9db17537 59 ******************************************************************************
mbed_official 376:cb4d9db17537 60 */
mbed_official 376:cb4d9db17537 61
mbed_official 376:cb4d9db17537 62 /* Includes ------------------------------------------------------------------*/
mbed_official 376:cb4d9db17537 63 #include "stm32l0xx_hal.h"
mbed_official 489:119543c9f674 64
mbed_official 489:119543c9f674 65 #ifdef HAL_FLASH_MODULE_ENABLED
mbed_official 489:119543c9f674 66 /** @addtogroup STM32L0xx_HAL_Driver
mbed_official 376:cb4d9db17537 67 * @{
mbed_official 376:cb4d9db17537 68 */
mbed_official 376:cb4d9db17537 69
mbed_official 489:119543c9f674 70 /** @addtogroup FLASHRamfunc
mbed_official 376:cb4d9db17537 71 * @brief FLASH functions executed from RAM
mbed_official 376:cb4d9db17537 72 * @{
mbed_official 376:cb4d9db17537 73 */
mbed_official 376:cb4d9db17537 74
mbed_official 376:cb4d9db17537 75 /* Private typedef -----------------------------------------------------------*/
mbed_official 376:cb4d9db17537 76 /* Private define ------------------------------------------------------------*/
mbed_official 376:cb4d9db17537 77 /* Private macro -------------------------------------------------------------*/
mbed_official 376:cb4d9db17537 78 /* Private variables ---------------------------------------------------------*/
mbed_official 376:cb4d9db17537 79 /* Private function prototypes -----------------------------------------------*/
mbed_official 489:119543c9f674 80 static __RAM_FUNC FLASHRAM_WaitForLastOperation(uint32_t Timeout);
mbed_official 489:119543c9f674 81 static __RAM_FUNC FLASHRAM_SetErrorCode(void);
mbed_official 376:cb4d9db17537 82
mbed_official 376:cb4d9db17537 83
mbed_official 489:119543c9f674 84 /** @addtogroup FLASHRamfunc_Exported_Functions
mbed_official 376:cb4d9db17537 85 *
mbed_official 376:cb4d9db17537 86 @verbatim
mbed_official 376:cb4d9db17537 87 ===============================================================================
mbed_official 376:cb4d9db17537 88 ##### ramfunc functions #####
mbed_official 376:cb4d9db17537 89 ===============================================================================
mbed_official 376:cb4d9db17537 90 [..]
mbed_official 376:cb4d9db17537 91 This subsection provides a set of functions that should be executed from RAM
mbed_official 376:cb4d9db17537 92 transfers.
mbed_official 376:cb4d9db17537 93
mbed_official 376:cb4d9db17537 94 @endverbatim
mbed_official 376:cb4d9db17537 95 * @{
mbed_official 376:cb4d9db17537 96 */
mbed_official 376:cb4d9db17537 97
mbed_official 489:119543c9f674 98 /** @addtogroup FLASHRamfunc_Exported_Functions_Group1
mbed_official 489:119543c9f674 99 * @{
mbed_official 489:119543c9f674 100 */
mbed_official 489:119543c9f674 101
mbed_official 376:cb4d9db17537 102 /**
mbed_official 489:119543c9f674 103 * @brief Enable the power down mode during RUN mode.
mbed_official 489:119543c9f674 104 * @note This function can be used only when the user code is running from Internal SRAM.
mbed_official 489:119543c9f674 105 * @param None
mbed_official 489:119543c9f674 106 * @retval None
mbed_official 376:cb4d9db17537 107 */
mbed_official 489:119543c9f674 108 __RAM_FUNC HAL_FLASHEx_EnableRunPowerDown(void)
mbed_official 376:cb4d9db17537 109 {
mbed_official 489:119543c9f674 110 /* Enable the Power Down in Run mode*/
mbed_official 489:119543c9f674 111 __HAL_FLASH_POWER_DOWN_ENABLE();
mbed_official 489:119543c9f674 112 return HAL_OK;
mbed_official 376:cb4d9db17537 113 }
mbed_official 376:cb4d9db17537 114
mbed_official 376:cb4d9db17537 115 /**
mbed_official 489:119543c9f674 116 * @brief Disable the power down mode during RUN mode.
mbed_official 489:119543c9f674 117 * @note This function can be used only when the user code is running from Internal SRAM.
mbed_official 376:cb4d9db17537 118 * @param None
mbed_official 376:cb4d9db17537 119 * @retval None
mbed_official 376:cb4d9db17537 120 */
mbed_official 489:119543c9f674 121 __RAM_FUNC HAL_FLASHEx_DisableRunPowerDown(void)
mbed_official 376:cb4d9db17537 122 {
mbed_official 376:cb4d9db17537 123 /* Disable the Power Down in Run mode*/
mbed_official 376:cb4d9db17537 124 __HAL_FLASH_POWER_DOWN_DISABLE();
mbed_official 376:cb4d9db17537 125 return HAL_OK;
mbed_official 376:cb4d9db17537 126 }
mbed_official 376:cb4d9db17537 127
mbed_official 376:cb4d9db17537 128 /**
mbed_official 376:cb4d9db17537 129 * @}
mbed_official 376:cb4d9db17537 130 */
mbed_official 376:cb4d9db17537 131
mbed_official 489:119543c9f674 132 /** @addtogroup FLASHRamfunc_Exported_Functions_Group2
mbed_official 489:119543c9f674 133 *
mbed_official 489:119543c9f674 134 @verbatim
mbed_official 489:119543c9f674 135 @endverbatim
mbed_official 489:119543c9f674 136 * @{
mbed_official 489:119543c9f674 137 */
mbed_official 489:119543c9f674 138
mbed_official 489:119543c9f674 139 #if defined(STM32L071xx) || defined(STM32L072xx) || defined(STM32L073xx) || defined(STM32L081xx) || defined(STM32L082xx) || defined(STM32L083xx)
mbed_official 376:cb4d9db17537 140 /**
mbed_official 489:119543c9f674 141 * @brief Erases a specified 2 pages in program memory in parallel.
mbed_official 489:119543c9f674 142 * @note This function can be used only for STM32L07xxx/STM32L08xxx devices.
mbed_official 489:119543c9f674 143 * To correctly run this function, the HAL_FLASH_Unlock() function
mbed_official 489:119543c9f674 144 * must be called before.
mbed_official 489:119543c9f674 145 * Call the HAL_FLASH_Lock() to disable the flash memory access
mbed_official 489:119543c9f674 146 * (recommended to protect the FLASH memory against possible unwanted operation).
mbed_official 489:119543c9f674 147 * @param Page_Address1: The page address in program memory to be erased in
mbed_official 489:119543c9f674 148 * the first Bank (BANK1). This parameter should be between FLASH_BASE
mbed_official 489:119543c9f674 149 * and FLASH_BANK1_END.
mbed_official 489:119543c9f674 150 * @param Page_Address2: The page address in program memory to be erased in
mbed_official 489:119543c9f674 151 * the second Bank (BANK2). This parameter should be between FLASH_BANK2_BASE
mbed_official 489:119543c9f674 152 * and FLASH_BANK2_END.
mbed_official 489:119543c9f674 153 * @note A Page is erased in the Program memory only if the address to load
mbed_official 489:119543c9f674 154 * is the start address of a page (multiple of 128 bytes).
mbed_official 489:119543c9f674 155 * @retval HAL Status: The returned value can be:
mbed_official 489:119543c9f674 156 * HAL_ERROR, HAL_OK or HAL_TIMEOUT.
mbed_official 376:cb4d9db17537 157 */
mbed_official 489:119543c9f674 158 __RAM_FUNC HAL_FLASHEx_EraseParallelPage(uint32_t Page_Address1, uint32_t Page_Address2)
mbed_official 376:cb4d9db17537 159 {
mbed_official 376:cb4d9db17537 160 HAL_StatusTypeDef status = HAL_OK;
mbed_official 489:119543c9f674 161
mbed_official 489:119543c9f674 162 /* Wait for last operation to be completed */
mbed_official 489:119543c9f674 163 status = FLASHRAM_WaitForLastOperation(FLASH_TIMEOUT_VALUE);
mbed_official 376:cb4d9db17537 164
mbed_official 489:119543c9f674 165 if(status == HAL_OK)
mbed_official 489:119543c9f674 166 {
mbed_official 489:119543c9f674 167 /* Proceed to erase the page */
mbed_official 489:119543c9f674 168 SET_BIT(FLASH->PECR, FLASH_PECR_PARALLBANK);
mbed_official 489:119543c9f674 169 SET_BIT(FLASH->PECR, FLASH_PECR_ERASE);
mbed_official 489:119543c9f674 170 SET_BIT(FLASH->PECR, FLASH_PECR_PROG);
mbed_official 376:cb4d9db17537 171
mbed_official 489:119543c9f674 172 /* Write 00000000h to the first word of the first program page to erase */
mbed_official 489:119543c9f674 173 *(__IO uint32_t *)Page_Address1 = 0x00000000;
mbed_official 489:119543c9f674 174 /* Write 00000000h to the first word of the second program page to erase */
mbed_official 489:119543c9f674 175 *(__IO uint32_t *)Page_Address2 = 0x00000000;
mbed_official 489:119543c9f674 176
mbed_official 489:119543c9f674 177 /* Wait for last operation to be completed */
mbed_official 489:119543c9f674 178 status = FLASHRAM_WaitForLastOperation(FLASH_TIMEOUT_VALUE);
mbed_official 376:cb4d9db17537 179
mbed_official 489:119543c9f674 180 /* If the erase operation is completed, disable the ERASE, PROG and PARALLBANK bits */
mbed_official 489:119543c9f674 181 CLEAR_BIT(FLASH->PECR, FLASH_PECR_PROG);
mbed_official 489:119543c9f674 182 CLEAR_BIT(FLASH->PECR, FLASH_PECR_ERASE);
mbed_official 489:119543c9f674 183 CLEAR_BIT(FLASH->PECR, FLASH_PECR_PARALLBANK);
mbed_official 489:119543c9f674 184 }
mbed_official 489:119543c9f674 185 /* Return the erasesStatus */
mbed_official 376:cb4d9db17537 186 return status;
mbed_official 376:cb4d9db17537 187 }
mbed_official 376:cb4d9db17537 188
mbed_official 376:cb4d9db17537 189 /**
mbed_official 489:119543c9f674 190 * @brief Programs 2 half pages in program memory in parallel. The half page size is 16 Words.
mbed_official 489:119543c9f674 191 * @note This function can be used only for STM32L07xxx/STM32L08xxx devices.
mbed_official 489:119543c9f674 192 * @param Address1: specifies the first address to be written in the first bank
mbed_official 489:119543c9f674 193 * (BANK1). This parameter should be between FLASH_BASE and (FLASH_BANK1_END - FLASH_PAGE_SIZE).
mbed_official 489:119543c9f674 194 * @param pBuffer1: pointer to the buffer containing the data to be written
mbed_official 489:119543c9f674 195 * to the first half page in the first bank.
mbed_official 489:119543c9f674 196 * @param Address2: specifies the second address to be written in the second bank
mbed_official 489:119543c9f674 197 * (BANK2). This parameter should be between FLASH_BANK2_BASE and (FLASH_BANK2_END - FLASH_PAGE_SIZE).
mbed_official 489:119543c9f674 198 * @param pBuffer2: pointer to the buffer containing the data to be written
mbed_official 489:119543c9f674 199 * to the second half page in the second bank.
mbed_official 489:119543c9f674 200 * @note To correctly run this function, the HAL_FLASH_Unlock() function
mbed_official 489:119543c9f674 201 * must be called before.
mbed_official 489:119543c9f674 202 * Call the HAL_FLASH_Lock() to disable the flash memory access
mbed_official 489:119543c9f674 203 * (recommended to protect the FLASH memory against possible unwanted operation).
mbed_official 489:119543c9f674 204 * @note Half page write is possible only from SRAM.
mbed_official 489:119543c9f674 205 * @note A half page is written to the program memory only if the first
mbed_official 489:119543c9f674 206 * address to load is the start address of a half page (multiple of 64
mbed_official 489:119543c9f674 207 * bytes) and the 15 remaining words to load are in the same half page.
mbed_official 489:119543c9f674 208 * @note During the Program memory half page write all read operations are
mbed_official 489:119543c9f674 209 * forbidden (this includes DMA read operations and debugger read
mbed_official 489:119543c9f674 210 * operations such as breakpoints, periodic updates, etc.).
mbed_official 489:119543c9f674 211 * @note If a PGAERR is set during a Program memory half page write, the
mbed_official 489:119543c9f674 212 * complete write operation is aborted. Software should then reset the
mbed_official 489:119543c9f674 213 * FPRG and PROG/DATA bits and restart the write operation from the
mbed_official 489:119543c9f674 214 * beginning.
mbed_official 489:119543c9f674 215 * @retval HAL Status: The returned value can be:
mbed_official 489:119543c9f674 216 * HAL_ERROR, HAL_OK or HAL_TIMEOUT.
mbed_official 489:119543c9f674 217 */
mbed_official 489:119543c9f674 218 __RAM_FUNC HAL_FLASHEx_ProgramParallelHalfPage(uint32_t Address1, uint32_t* pBuffer1, uint32_t Address2, uint32_t* pBuffer2)
mbed_official 489:119543c9f674 219 {
mbed_official 489:119543c9f674 220 uint32_t count;
mbed_official 489:119543c9f674 221 HAL_StatusTypeDef status;
mbed_official 489:119543c9f674 222
mbed_official 489:119543c9f674 223 /* Wait for last operation to be completed */
mbed_official 489:119543c9f674 224 status = FLASHRAM_WaitForLastOperation(FLASH_TIMEOUT_VALUE);
mbed_official 489:119543c9f674 225
mbed_official 489:119543c9f674 226 if(status == HAL_OK)
mbed_official 489:119543c9f674 227 {
mbed_official 489:119543c9f674 228 /* Proceed to program the new half page */
mbed_official 489:119543c9f674 229 SET_BIT(FLASH->PECR, FLASH_PECR_PARALLBANK);
mbed_official 489:119543c9f674 230 SET_BIT(FLASH->PECR, FLASH_PECR_FPRG);
mbed_official 489:119543c9f674 231 SET_BIT(FLASH->PECR, FLASH_PECR_PROG);
mbed_official 489:119543c9f674 232
mbed_official 489:119543c9f674 233
mbed_official 489:119543c9f674 234 /* Wait for last operation to be completed */
mbed_official 489:119543c9f674 235 status = FLASHRAM_WaitForLastOperation(FLASH_TIMEOUT_VALUE);
mbed_official 489:119543c9f674 236
mbed_official 489:119543c9f674 237 if(status == HAL_OK)
mbed_official 489:119543c9f674 238 {
mbed_official 489:119543c9f674 239 /* Write one half page,
mbed_official 489:119543c9f674 240 Address1 doesn't need to be increased */
mbed_official 489:119543c9f674 241 count = 0;
mbed_official 489:119543c9f674 242
mbed_official 489:119543c9f674 243 /* Disable all IRQs */
mbed_official 489:119543c9f674 244 __disable_irq();
mbed_official 489:119543c9f674 245
mbed_official 489:119543c9f674 246 while(count < 16)
mbed_official 489:119543c9f674 247 {
mbed_official 489:119543c9f674 248 *(__IO uint32_t*) Address1 = *pBuffer1;
mbed_official 489:119543c9f674 249 pBuffer1++;
mbed_official 489:119543c9f674 250 count++;
mbed_official 489:119543c9f674 251 }
mbed_official 489:119543c9f674 252
mbed_official 489:119543c9f674 253 /* Write the second half page,
mbed_official 489:119543c9f674 254 Address2 doesn't need to be increased */
mbed_official 489:119543c9f674 255 count = 0;
mbed_official 489:119543c9f674 256 while(count < 16)
mbed_official 489:119543c9f674 257 {
mbed_official 489:119543c9f674 258 *(__IO uint32_t*) Address2 = *pBuffer2;
mbed_official 489:119543c9f674 259 pBuffer2++;
mbed_official 489:119543c9f674 260 count++;
mbed_official 489:119543c9f674 261 }
mbed_official 489:119543c9f674 262
mbed_official 489:119543c9f674 263 /* Enable IRQs */
mbed_official 489:119543c9f674 264 __enable_irq();
mbed_official 489:119543c9f674 265
mbed_official 489:119543c9f674 266 /* Wait for last operation to be completed */
mbed_official 489:119543c9f674 267 status = FLASHRAM_WaitForLastOperation(FLASH_TIMEOUT_VALUE);
mbed_official 489:119543c9f674 268 }
mbed_official 489:119543c9f674 269 /* if the write operation is completed, disable the PROG, FPRG and PARALLBANK bits */
mbed_official 489:119543c9f674 270 CLEAR_BIT(FLASH->PECR, FLASH_PECR_PROG);
mbed_official 489:119543c9f674 271 CLEAR_BIT(FLASH->PECR, FLASH_PECR_FPRG);
mbed_official 489:119543c9f674 272 CLEAR_BIT(FLASH->PECR, FLASH_PECR_PARALLBANK);
mbed_official 489:119543c9f674 273 }
mbed_official 489:119543c9f674 274 /* Return the Write Status */
mbed_official 489:119543c9f674 275 return status;
mbed_official 489:119543c9f674 276 }
mbed_official 489:119543c9f674 277 #endif /* STM32L071xx || STM32L072xx || STM32L073xx || STM32L081xx || STM32L082xx || STM32L083xx */
mbed_official 489:119543c9f674 278
mbed_official 489:119543c9f674 279 /**
mbed_official 489:119543c9f674 280 * @brief Program a half page in program memory.
mbed_official 489:119543c9f674 281 * @param Address: specifies the address to be written.
mbed_official 489:119543c9f674 282 * @param pBuffer: pointer to the buffer containing the data to be written to
mbed_official 489:119543c9f674 283 * the half page.
mbed_official 489:119543c9f674 284 * @note To correctly run this function, the HAL_FLASH_Unlock() function
mbed_official 489:119543c9f674 285 * must be called before.
mbed_official 489:119543c9f674 286 * Call the HAL_FLASH_Lock() to disable the flash memory access
mbed_official 489:119543c9f674 287 * (recommended to protect the FLASH memory against possible unwanted operation)
mbed_official 489:119543c9f674 288 * @note Half page write is possible only from SRAM.
mbed_official 489:119543c9f674 289 * @note A half page is written to the program memory only if the first
mbed_official 489:119543c9f674 290 * address to load is the start address of a half page (multiple of 64
mbed_official 489:119543c9f674 291 * bytes) and the 15 remaining words to load are in the same half page.
mbed_official 489:119543c9f674 292 * @note During the Program memory half page write all read operations are
mbed_official 489:119543c9f674 293 * forbidden (this includes DMA read operations and debugger read
mbed_official 489:119543c9f674 294 * operations such as breakpoints, periodic updates, etc.).
mbed_official 489:119543c9f674 295 * @note If a PGAERR is set during a Program memory half page write, the
mbed_official 489:119543c9f674 296 * complete write operation is aborted. Software should then reset the
mbed_official 489:119543c9f674 297 * FPRG and PROG/DATA bits and restart the write operation from the
mbed_official 489:119543c9f674 298 * beginning.
mbed_official 489:119543c9f674 299 * @retval HAL Status: The returned value can be:
mbed_official 489:119543c9f674 300 * HAL_ERROR, HAL_OK or HAL_TIMEOUT.
mbed_official 489:119543c9f674 301 */
mbed_official 489:119543c9f674 302 __RAM_FUNC HAL_FLASHEx_HalfPageProgram(uint32_t Address, uint32_t *pBuffer)
mbed_official 489:119543c9f674 303 {
mbed_official 489:119543c9f674 304 uint32_t count;
mbed_official 489:119543c9f674 305 HAL_StatusTypeDef status;
mbed_official 489:119543c9f674 306
mbed_official 489:119543c9f674 307 /* Wait for last operation to be completed */
mbed_official 489:119543c9f674 308 status = FLASHRAM_WaitForLastOperation(FLASH_TIMEOUT_VALUE);
mbed_official 489:119543c9f674 309
mbed_official 489:119543c9f674 310 if(status == HAL_OK)
mbed_official 489:119543c9f674 311 {
mbed_official 489:119543c9f674 312 /* Proceed to program the new half page */
mbed_official 489:119543c9f674 313 SET_BIT(FLASH->PECR, FLASH_PECR_FPRG);
mbed_official 489:119543c9f674 314 SET_BIT(FLASH->PECR, FLASH_PECR_PROG);
mbed_official 376:cb4d9db17537 315
mbed_official 376:cb4d9db17537 316
mbed_official 489:119543c9f674 317 count = 0;
mbed_official 489:119543c9f674 318 /* Write one half page,
mbed_official 489:119543c9f674 319 Address doesn't need to be increased */
mbed_official 489:119543c9f674 320
mbed_official 489:119543c9f674 321 /* Disable all IRQs */
mbed_official 489:119543c9f674 322 __disable_irq();
mbed_official 489:119543c9f674 323
mbed_official 489:119543c9f674 324 while(count < 16)
mbed_official 489:119543c9f674 325 {
mbed_official 489:119543c9f674 326 *(__IO uint32_t*) Address = *pBuffer;
mbed_official 489:119543c9f674 327 pBuffer++;
mbed_official 489:119543c9f674 328 count++;
mbed_official 489:119543c9f674 329 }
mbed_official 489:119543c9f674 330
mbed_official 489:119543c9f674 331 /* Enable IRQs */
mbed_official 489:119543c9f674 332 __enable_irq();
mbed_official 376:cb4d9db17537 333
mbed_official 489:119543c9f674 334 /* Wait for last operation to be completed */
mbed_official 489:119543c9f674 335 status = FLASHRAM_WaitForLastOperation(FLASH_TIMEOUT_VALUE);
mbed_official 489:119543c9f674 336
mbed_official 489:119543c9f674 337 /* If the write operation is completed, disable the PROG and FPRG bits */
mbed_official 489:119543c9f674 338 CLEAR_BIT(FLASH->PECR, FLASH_PECR_PROG);
mbed_official 489:119543c9f674 339 CLEAR_BIT(FLASH->PECR, FLASH_PECR_FPRG);
mbed_official 489:119543c9f674 340 }
mbed_official 489:119543c9f674 341 /* Return the write status */
mbed_official 489:119543c9f674 342 return status;
mbed_official 489:119543c9f674 343 }
mbed_official 489:119543c9f674 344
mbed_official 489:119543c9f674 345 /**
mbed_official 489:119543c9f674 346 * @brief Get the specific FLASH errors flag.
mbed_official 489:119543c9f674 347 * @param error pointer is the error value. It can be a mixed of :
mbed_official 489:119543c9f674 348 * @arg HAL_FLASH_ERROR_RD: FLASH Read Protection error flag (PCROP)
mbed_official 489:119543c9f674 349 * @arg HAL_FLASH_ERROR_SIZE: FLASH Programming Parallelism error flag
mbed_official 489:119543c9f674 350 * @arg HAL_FLASH_ERROR_PGA: FLASH Programming Alignment error flag
mbed_official 489:119543c9f674 351 * @arg HAL_FLASH_ERROR_WRP: FLASH Write protected error flag
mbed_official 489:119543c9f674 352 * @arg HAL_FLASH_ERROR_OPTV: FLASH Option valid error flag
mbed_official 489:119543c9f674 353 * @arg HAL_FLASH_ERROR_FWWERR: FLASH Write or Errase operation aborted
mbed_official 489:119543c9f674 354 * @arg HAL_FLASH_ERROR_NOTZERO: FLASH Write operation is done in a not-erased region
mbed_official 489:119543c9f674 355 */
mbed_official 489:119543c9f674 356 __RAM_FUNC HAL_FLASHRAM_GetError(uint32_t * error)
mbed_official 489:119543c9f674 357 {
mbed_official 489:119543c9f674 358 *error = ProcFlash.ErrorCode;
mbed_official 489:119543c9f674 359 return HAL_OK;
mbed_official 489:119543c9f674 360 }
mbed_official 489:119543c9f674 361
mbed_official 489:119543c9f674 362
mbed_official 489:119543c9f674 363
mbed_official 376:cb4d9db17537 364 /**
mbed_official 376:cb4d9db17537 365 * @}
mbed_official 376:cb4d9db17537 366 */
mbed_official 376:cb4d9db17537 367
mbed_official 376:cb4d9db17537 368 /**
mbed_official 376:cb4d9db17537 369 * @}
mbed_official 376:cb4d9db17537 370 */
mbed_official 376:cb4d9db17537 371
mbed_official 489:119543c9f674 372 /** @defgroup FLASHRamfunc_Private_Functions FLASH RAM Private Functions
mbed_official 489:119543c9f674 373 * @{
mbed_official 489:119543c9f674 374 */
mbed_official 489:119543c9f674 375
mbed_official 489:119543c9f674 376 /**
mbed_official 489:119543c9f674 377 * @brief Set the specific FLASH error flag.
mbed_official 489:119543c9f674 378 * @param None
mbed_official 489:119543c9f674 379 * @retval None
mbed_official 489:119543c9f674 380 */
mbed_official 489:119543c9f674 381 static __RAM_FUNC FLASHRAM_SetErrorCode(void)
mbed_official 489:119543c9f674 382 {
mbed_official 489:119543c9f674 383 if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR))
mbed_official 489:119543c9f674 384 {
mbed_official 489:119543c9f674 385 ProcFlash.ErrorCode |= HAL_FLASH_ERROR_WRP;
mbed_official 489:119543c9f674 386 }
mbed_official 489:119543c9f674 387 if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_PGAERR))
mbed_official 489:119543c9f674 388 {
mbed_official 489:119543c9f674 389 ProcFlash.ErrorCode |= HAL_FLASH_ERROR_PGA;
mbed_official 489:119543c9f674 390 }
mbed_official 489:119543c9f674 391 if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_SIZERR))
mbed_official 489:119543c9f674 392 {
mbed_official 489:119543c9f674 393 ProcFlash.ErrorCode |= HAL_FLASH_ERROR_SIZE;
mbed_official 489:119543c9f674 394 }
mbed_official 489:119543c9f674 395 if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_OPTVERR))
mbed_official 489:119543c9f674 396 {
mbed_official 489:119543c9f674 397 ProcFlash.ErrorCode |= HAL_FLASH_ERROR_OPTV;
mbed_official 489:119543c9f674 398 }
mbed_official 489:119543c9f674 399 if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_RDERR))
mbed_official 489:119543c9f674 400 {
mbed_official 489:119543c9f674 401 ProcFlash.ErrorCode |= HAL_FLASH_ERROR_RD;
mbed_official 489:119543c9f674 402 }
mbed_official 489:119543c9f674 403 if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_FWWERR))
mbed_official 489:119543c9f674 404 {
mbed_official 489:119543c9f674 405 ProcFlash.ErrorCode |= HAL_FLASH_ERROR_FWWERR;
mbed_official 489:119543c9f674 406 }
mbed_official 489:119543c9f674 407 if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_NOTZEROERR))
mbed_official 489:119543c9f674 408 {
mbed_official 489:119543c9f674 409 ProcFlash.ErrorCode |= HAL_FLASH_ERROR_NOTZERO;
mbed_official 489:119543c9f674 410 }
mbed_official 489:119543c9f674 411
mbed_official 489:119543c9f674 412 /* Errors are now stored, clear errors flags */
mbed_official 489:119543c9f674 413 __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_SIZERR |
mbed_official 489:119543c9f674 414 FLASH_FLAG_OPTVERR | FLASH_FLAG_RDERR | FLASH_FLAG_FWWERR |
mbed_official 489:119543c9f674 415 FLASH_FLAG_NOTZEROERR);
mbed_official 489:119543c9f674 416 return HAL_OK;
mbed_official 489:119543c9f674 417 }
mbed_official 489:119543c9f674 418
mbed_official 489:119543c9f674 419
mbed_official 489:119543c9f674 420 /**
mbed_official 489:119543c9f674 421 * @brief Wait for a FLASH operation to complete.
mbed_official 489:119543c9f674 422 * @param Timeout: maximum flash operationtimeout
mbed_official 489:119543c9f674 423 * @retval HAL status
mbed_official 489:119543c9f674 424 */
mbed_official 489:119543c9f674 425 static __RAM_FUNC FLASHRAM_WaitForLastOperation(uint32_t Timeout)
mbed_official 489:119543c9f674 426 {
mbed_official 489:119543c9f674 427 /* Wait for the FLASH operation to complete by polling on BUSY flag to be reset.
mbed_official 489:119543c9f674 428 Even if the FLASH operation fails, the BUSY flag will be reset and an error
mbed_official 489:119543c9f674 429 flag will be set */
mbed_official 489:119543c9f674 430
mbed_official 489:119543c9f674 431 while(__HAL_FLASH_GET_FLAG(FLASH_FLAG_BSY) && (Timeout != 0x00))
mbed_official 489:119543c9f674 432 {
mbed_official 489:119543c9f674 433 Timeout--;
mbed_official 489:119543c9f674 434 }
mbed_official 489:119543c9f674 435
mbed_official 489:119543c9f674 436 if(Timeout == 0x00 )
mbed_official 489:119543c9f674 437 {
mbed_official 489:119543c9f674 438 return HAL_TIMEOUT;
mbed_official 489:119543c9f674 439 }
mbed_official 489:119543c9f674 440
mbed_official 489:119543c9f674 441 if( (__HAL_FLASH_GET_FLAG(FLASH_FLAG_RDERR) != RESET) ||
mbed_official 489:119543c9f674 442 (__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR) != RESET) ||
mbed_official 489:119543c9f674 443 (__HAL_FLASH_GET_FLAG(FLASH_FLAG_PGAERR) != RESET) ||
mbed_official 489:119543c9f674 444 (__HAL_FLASH_GET_FLAG(FLASH_FLAG_OPTVERR) != RESET) ||
mbed_official 489:119543c9f674 445 (__HAL_FLASH_GET_FLAG(FLASH_FLAG_SIZERR) != RESET) ||
mbed_official 489:119543c9f674 446 (__HAL_FLASH_GET_FLAG(FLASH_FLAG_FWWERR) != RESET) ||
mbed_official 489:119543c9f674 447 (__HAL_FLASH_GET_FLAG(FLASH_FLAG_NOTZEROERR) != RESET) )
mbed_official 489:119543c9f674 448 {
mbed_official 489:119543c9f674 449 /*Save the error code*/
mbed_official 489:119543c9f674 450 FLASHRAM_SetErrorCode();
mbed_official 489:119543c9f674 451 return HAL_ERROR;
mbed_official 489:119543c9f674 452 }
mbed_official 489:119543c9f674 453
mbed_official 489:119543c9f674 454 /* If there is an error flag set */
mbed_official 489:119543c9f674 455 return HAL_OK;
mbed_official 489:119543c9f674 456 }
mbed_official 489:119543c9f674 457
mbed_official 489:119543c9f674 458 /**
mbed_official 489:119543c9f674 459 * @}
mbed_official 489:119543c9f674 460 */
mbed_official 489:119543c9f674 461
mbed_official 489:119543c9f674 462 /**
mbed_official 489:119543c9f674 463 * @}
mbed_official 489:119543c9f674 464 */
mbed_official 489:119543c9f674 465
mbed_official 489:119543c9f674 466 /**
mbed_official 489:119543c9f674 467 * @}
mbed_official 489:119543c9f674 468 */
mbed_official 489:119543c9f674 469 #endif /* HAL_FLASH_MODULE_ENABLED */
mbed_official 489:119543c9f674 470
mbed_official 376:cb4d9db17537 471 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
mbed_official 376:cb4d9db17537 472