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