added prescaler for 16 bit pwm in LPC1347 target

Fork of mbed-dev by mbed official

Committer:
<>
Date:
Fri Sep 02 15:07:44 2016 +0100
Revision:
144:ef7eb2e8f9f7
This updates the lib to the mbed lib v125

Who changed what in which revision?

UserRevisionLine numberNew contents of line
<> 144:ef7eb2e8f9f7 1 /*
<> 144:ef7eb2e8f9f7 2 * Copyright (c) 2015-2016, Freescale Semiconductor, Inc.
<> 144:ef7eb2e8f9f7 3 * All rights reserved.
<> 144:ef7eb2e8f9f7 4 *
<> 144:ef7eb2e8f9f7 5 * Redistribution and use in source and binary forms, with or without modification,
<> 144:ef7eb2e8f9f7 6 * are permitted provided that the following conditions are met:
<> 144:ef7eb2e8f9f7 7 *
<> 144:ef7eb2e8f9f7 8 * o Redistributions of source code must retain the above copyright notice, this list
<> 144:ef7eb2e8f9f7 9 * of conditions and the following disclaimer.
<> 144:ef7eb2e8f9f7 10 *
<> 144:ef7eb2e8f9f7 11 * o Redistributions in binary form must reproduce the above copyright notice, this
<> 144:ef7eb2e8f9f7 12 * list of conditions and the following disclaimer in the documentation and/or
<> 144:ef7eb2e8f9f7 13 * other materials provided with the distribution.
<> 144:ef7eb2e8f9f7 14 *
<> 144:ef7eb2e8f9f7 15 * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
<> 144:ef7eb2e8f9f7 16 * contributors may be used to endorse or promote products derived from this
<> 144:ef7eb2e8f9f7 17 * software without specific prior written permission.
<> 144:ef7eb2e8f9f7 18 *
<> 144:ef7eb2e8f9f7 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
<> 144:ef7eb2e8f9f7 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
<> 144:ef7eb2e8f9f7 21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
<> 144:ef7eb2e8f9f7 22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
<> 144:ef7eb2e8f9f7 23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
<> 144:ef7eb2e8f9f7 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
<> 144:ef7eb2e8f9f7 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
<> 144:ef7eb2e8f9f7 26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
<> 144:ef7eb2e8f9f7 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
<> 144:ef7eb2e8f9f7 28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<> 144:ef7eb2e8f9f7 29 */
<> 144:ef7eb2e8f9f7 30
<> 144:ef7eb2e8f9f7 31 #include "fsl_flash.h"
<> 144:ef7eb2e8f9f7 32
<> 144:ef7eb2e8f9f7 33 /*******************************************************************************
<> 144:ef7eb2e8f9f7 34 * Definitions
<> 144:ef7eb2e8f9f7 35 ******************************************************************************/
<> 144:ef7eb2e8f9f7 36
<> 144:ef7eb2e8f9f7 37 /*!
<> 144:ef7eb2e8f9f7 38 * @name Misc utility defines
<> 144:ef7eb2e8f9f7 39 * @{
<> 144:ef7eb2e8f9f7 40 */
<> 144:ef7eb2e8f9f7 41 #ifndef ALIGN_DOWN
<> 144:ef7eb2e8f9f7 42 #define ALIGN_DOWN(x, a) ((x) & (uint32_t)(-((int32_t)(a))))
<> 144:ef7eb2e8f9f7 43 #endif
<> 144:ef7eb2e8f9f7 44 #ifndef ALIGN_UP
<> 144:ef7eb2e8f9f7 45 #define ALIGN_UP(x, a) (-((int32_t)((uint32_t)(-((int32_t)(x))) & (uint32_t)(-((int32_t)(a))))))
<> 144:ef7eb2e8f9f7 46 #endif
<> 144:ef7eb2e8f9f7 47
<> 144:ef7eb2e8f9f7 48 #define BYTES_JOIN_TO_WORD_1_3(x, y) ((((uint32_t)(x)&0xFFU) << 24) | ((uint32_t)(y)&0xFFFFFFU))
<> 144:ef7eb2e8f9f7 49 #define BYTES_JOIN_TO_WORD_2_2(x, y) ((((uint32_t)(x)&0xFFFFU) << 16) | ((uint32_t)(y)&0xFFFFU))
<> 144:ef7eb2e8f9f7 50 #define BYTES_JOIN_TO_WORD_3_1(x, y) ((((uint32_t)(x)&0xFFFFFFU) << 8) | ((uint32_t)(y)&0xFFU))
<> 144:ef7eb2e8f9f7 51 #define BYTES_JOIN_TO_WORD_1_1_2(x, y, z) \
<> 144:ef7eb2e8f9f7 52 ((((uint32_t)(x)&0xFFU) << 24) | (((uint32_t)(y)&0xFFU) << 16) | ((uint32_t)(z)&0xFFFFU))
<> 144:ef7eb2e8f9f7 53 #define BYTES_JOIN_TO_WORD_1_2_1(x, y, z) \
<> 144:ef7eb2e8f9f7 54 ((((uint32_t)(x)&0xFFU) << 24) | (((uint32_t)(y)&0xFFFFU) << 8) | ((uint32_t)(z)&0xFFU))
<> 144:ef7eb2e8f9f7 55 #define BYTES_JOIN_TO_WORD_2_1_1(x, y, z) \
<> 144:ef7eb2e8f9f7 56 ((((uint32_t)(x)&0xFFFFU) << 16) | (((uint32_t)(y)&0xFFU) << 8) | ((uint32_t)(z)&0xFFU))
<> 144:ef7eb2e8f9f7 57 #define BYTES_JOIN_TO_WORD_1_1_1_1(x, y, z, w) \
<> 144:ef7eb2e8f9f7 58 ((((uint32_t)(x)&0xFFU) << 24) | (((uint32_t)(y)&0xFFU) << 16) | (((uint32_t)(z)&0xFFU) << 8) | \
<> 144:ef7eb2e8f9f7 59 ((uint32_t)(w)&0xFFU))
<> 144:ef7eb2e8f9f7 60 /*@}*/
<> 144:ef7eb2e8f9f7 61
<> 144:ef7eb2e8f9f7 62 /*! @brief Data flash IFR map Field*/
<> 144:ef7eb2e8f9f7 63 #if defined(FSL_FEATURE_FLASH_IS_FTFE) && FSL_FEATURE_FLASH_IS_FTFE
<> 144:ef7eb2e8f9f7 64 #define DFLASH_IFR_READRESOURCE_START_ADDRESS 0x8003F8U
<> 144:ef7eb2e8f9f7 65 #else /* FSL_FEATURE_FLASH_IS_FTFL == 1 or FSL_FEATURE_FLASH_IS_FTFA = =1 */
<> 144:ef7eb2e8f9f7 66 #define DFLASH_IFR_READRESOURCE_START_ADDRESS 0x8000F8U
<> 144:ef7eb2e8f9f7 67 #endif
<> 144:ef7eb2e8f9f7 68
<> 144:ef7eb2e8f9f7 69 /*!
<> 144:ef7eb2e8f9f7 70 * @name Reserved FlexNVM size (For a variety of purposes) defines
<> 144:ef7eb2e8f9f7 71 * @{
<> 144:ef7eb2e8f9f7 72 */
<> 144:ef7eb2e8f9f7 73 #define FLEX_NVM_DFLASH_SIZE_FOR_DEPART_RESERVED 0xFFFFFFFFU
<> 144:ef7eb2e8f9f7 74 #define FLEX_NVM_EEPROM_SIZE_FOR_EEESIZE_RESERVED 0xFFFFU
<> 144:ef7eb2e8f9f7 75 /*@}*/
<> 144:ef7eb2e8f9f7 76
<> 144:ef7eb2e8f9f7 77 /*!
<> 144:ef7eb2e8f9f7 78 * @name Flash Program Once Field defines
<> 144:ef7eb2e8f9f7 79 * @{
<> 144:ef7eb2e8f9f7 80 */
<> 144:ef7eb2e8f9f7 81 #if defined(FSL_FEATURE_FLASH_IS_FTFA) && FSL_FEATURE_FLASH_IS_FTFA
<> 144:ef7eb2e8f9f7 82 /* FTFA parts(eg. K80, KL80, L5K) support both 4-bytes and 8-bytes unit size */
<> 144:ef7eb2e8f9f7 83 #define FLASH_PROGRAM_ONCE_MIN_ID_8BYTES \
<> 144:ef7eb2e8f9f7 84 0x10U /* Minimum Index indcating one of Progam Once Fields which is accessed in 8-byte records */
<> 144:ef7eb2e8f9f7 85 #define FLASH_PROGRAM_ONCE_MAX_ID_8BYTES \
<> 144:ef7eb2e8f9f7 86 0x13U /* Maximum Index indcating one of Progam Once Fields which is accessed in 8-byte records */
<> 144:ef7eb2e8f9f7 87 #define FLASH_PROGRAM_ONCE_IS_4BYTES_UNIT_SUPPORT 1
<> 144:ef7eb2e8f9f7 88 #define FLASH_PROGRAM_ONCE_IS_8BYTES_UNIT_SUPPORT 1
<> 144:ef7eb2e8f9f7 89 #elif defined(FSL_FEATURE_FLASH_IS_FTFE) && FSL_FEATURE_FLASH_IS_FTFE
<> 144:ef7eb2e8f9f7 90 /* FTFE parts(eg. K65, KE18) only support 8-bytes unit size */
<> 144:ef7eb2e8f9f7 91 #define FLASH_PROGRAM_ONCE_IS_4BYTES_UNIT_SUPPORT 0
<> 144:ef7eb2e8f9f7 92 #define FLASH_PROGRAM_ONCE_IS_8BYTES_UNIT_SUPPORT 1
<> 144:ef7eb2e8f9f7 93 #elif defined(FSL_FEATURE_FLASH_IS_FTFL) && FSL_FEATURE_FLASH_IS_FTFL
<> 144:ef7eb2e8f9f7 94 /* FTFL parts(eg. K20) only support 4-bytes unit size */
<> 144:ef7eb2e8f9f7 95 #define FLASH_PROGRAM_ONCE_IS_4BYTES_UNIT_SUPPORT 1
<> 144:ef7eb2e8f9f7 96 #define FLASH_PROGRAM_ONCE_IS_8BYTES_UNIT_SUPPORT 0
<> 144:ef7eb2e8f9f7 97 #endif
<> 144:ef7eb2e8f9f7 98 /*@}*/
<> 144:ef7eb2e8f9f7 99
<> 144:ef7eb2e8f9f7 100 /*!
<> 144:ef7eb2e8f9f7 101 * @name Flash security status defines
<> 144:ef7eb2e8f9f7 102 * @{
<> 144:ef7eb2e8f9f7 103 */
<> 144:ef7eb2e8f9f7 104 #define FLASH_SECURITY_STATE_KEYEN 0x80U
<> 144:ef7eb2e8f9f7 105 #define FLASH_SECURITY_STATE_UNSECURED 0x02U
<> 144:ef7eb2e8f9f7 106 #define FLASH_NOT_SECURE 0x01U
<> 144:ef7eb2e8f9f7 107 #define FLASH_SECURE_BACKDOOR_ENABLED 0x02U
<> 144:ef7eb2e8f9f7 108 #define FLASH_SECURE_BACKDOOR_DISABLED 0x04U
<> 144:ef7eb2e8f9f7 109 /*@}*/
<> 144:ef7eb2e8f9f7 110
<> 144:ef7eb2e8f9f7 111 /*!
<> 144:ef7eb2e8f9f7 112 * @name Flash controller command numbers
<> 144:ef7eb2e8f9f7 113 * @{
<> 144:ef7eb2e8f9f7 114 */
<> 144:ef7eb2e8f9f7 115 #define FTFx_VERIFY_BLOCK 0x00U /*!< RD1BLK*/
<> 144:ef7eb2e8f9f7 116 #define FTFx_VERIFY_SECTION 0x01U /*!< RD1SEC*/
<> 144:ef7eb2e8f9f7 117 #define FTFx_PROGRAM_CHECK 0x02U /*!< PGMCHK*/
<> 144:ef7eb2e8f9f7 118 #define FTFx_READ_RESOURCE 0x03U /*!< RDRSRC*/
<> 144:ef7eb2e8f9f7 119 #define FTFx_PROGRAM_LONGWORD 0x06U /*!< PGM4*/
<> 144:ef7eb2e8f9f7 120 #define FTFx_PROGRAM_PHRASE 0x07U /*!< PGM8*/
<> 144:ef7eb2e8f9f7 121 #define FTFx_ERASE_BLOCK 0x08U /*!< ERSBLK*/
<> 144:ef7eb2e8f9f7 122 #define FTFx_ERASE_SECTOR 0x09U /*!< ERSSCR*/
<> 144:ef7eb2e8f9f7 123 #define FTFx_PROGRAM_SECTION 0x0BU /*!< PGMSEC*/
<> 144:ef7eb2e8f9f7 124 #define FTFx_VERIFY_ALL_BLOCK 0x40U /*!< RD1ALL*/
<> 144:ef7eb2e8f9f7 125 #define FTFx_READ_ONCE 0x41U /*!< RDONCE or RDINDEX*/
<> 144:ef7eb2e8f9f7 126 #define FTFx_PROGRAM_ONCE 0x43U /*!< PGMONCE or PGMINDEX*/
<> 144:ef7eb2e8f9f7 127 #define FTFx_ERASE_ALL_BLOCK 0x44U /*!< ERSALL*/
<> 144:ef7eb2e8f9f7 128 #define FTFx_SECURITY_BY_PASS 0x45U /*!< VFYKEY*/
<> 144:ef7eb2e8f9f7 129 #define FTFx_SWAP_CONTROL 0x46U /*!< SWAP*/
<> 144:ef7eb2e8f9f7 130 #define FTFx_ERASE_ALL_BLOCK_UNSECURE 0x49U /*!< ERSALLU*/
<> 144:ef7eb2e8f9f7 131 #define FTFx_VERIFY_ALL_EXECUTE_ONLY_SEGMENT 0x4AU /*!< RD1XA*/
<> 144:ef7eb2e8f9f7 132 #define FTFx_ERASE_ALL_EXECUTE_ONLY_SEGMENT 0x4BU /*!< ERSXA*/
<> 144:ef7eb2e8f9f7 133 #define FTFx_PROGRAM_PARTITION 0x80U /*!< PGMPART)*/
<> 144:ef7eb2e8f9f7 134 #define FTFx_SET_FLEXRAM_FUNCTION 0x81U /*!< SETRAM*/
<> 144:ef7eb2e8f9f7 135 /*@}*/
<> 144:ef7eb2e8f9f7 136
<> 144:ef7eb2e8f9f7 137 /*!
<> 144:ef7eb2e8f9f7 138 * @name Common flash register info defines
<> 144:ef7eb2e8f9f7 139 * @{
<> 144:ef7eb2e8f9f7 140 */
<> 144:ef7eb2e8f9f7 141 #if defined(FTFA)
<> 144:ef7eb2e8f9f7 142 #define FTFx FTFA
<> 144:ef7eb2e8f9f7 143 #define FTFx_BASE FTFA_BASE
<> 144:ef7eb2e8f9f7 144 #define FTFx_FSTAT_CCIF_MASK FTFA_FSTAT_CCIF_MASK
<> 144:ef7eb2e8f9f7 145 #define FTFx_FSTAT_RDCOLERR_MASK FTFA_FSTAT_RDCOLERR_MASK
<> 144:ef7eb2e8f9f7 146 #define FTFx_FSTAT_ACCERR_MASK FTFA_FSTAT_ACCERR_MASK
<> 144:ef7eb2e8f9f7 147 #define FTFx_FSTAT_FPVIOL_MASK FTFA_FSTAT_FPVIOL_MASK
<> 144:ef7eb2e8f9f7 148 #define FTFx_FSTAT_MGSTAT0_MASK FTFA_FSTAT_MGSTAT0_MASK
<> 144:ef7eb2e8f9f7 149 #define FTFx_FSEC_SEC_MASK FTFA_FSEC_SEC_MASK
<> 144:ef7eb2e8f9f7 150 #define FTFx_FSEC_KEYEN_MASK FTFA_FSEC_KEYEN_MASK
<> 144:ef7eb2e8f9f7 151 #if defined(FSL_FEATURE_FLASH_HAS_FLEX_RAM) && FSL_FEATURE_FLASH_HAS_FLEX_RAM
<> 144:ef7eb2e8f9f7 152 #define FTFx_FCNFG_RAMRDY_MASK FTFA_FCNFG_RAMRDY_MASK
<> 144:ef7eb2e8f9f7 153 #endif /* FSL_FEATURE_FLASH_HAS_FLEX_RAM */
<> 144:ef7eb2e8f9f7 154 #if defined(FSL_FEATURE_FLASH_HAS_FLEX_NVM) && FSL_FEATURE_FLASH_HAS_FLEX_NVM
<> 144:ef7eb2e8f9f7 155 #define FTFx_FCNFG_EEERDY_MASK FTFA_FCNFG_EEERDY_MASK
<> 144:ef7eb2e8f9f7 156 #endif /* FSL_FEATURE_FLASH_HAS_FLEX_NVM */
<> 144:ef7eb2e8f9f7 157 #elif defined(FTFE)
<> 144:ef7eb2e8f9f7 158 #define FTFx FTFE
<> 144:ef7eb2e8f9f7 159 #define FTFx_BASE FTFE_BASE
<> 144:ef7eb2e8f9f7 160 #define FTFx_FSTAT_CCIF_MASK FTFE_FSTAT_CCIF_MASK
<> 144:ef7eb2e8f9f7 161 #define FTFx_FSTAT_RDCOLERR_MASK FTFE_FSTAT_RDCOLERR_MASK
<> 144:ef7eb2e8f9f7 162 #define FTFx_FSTAT_ACCERR_MASK FTFE_FSTAT_ACCERR_MASK
<> 144:ef7eb2e8f9f7 163 #define FTFx_FSTAT_FPVIOL_MASK FTFE_FSTAT_FPVIOL_MASK
<> 144:ef7eb2e8f9f7 164 #define FTFx_FSTAT_MGSTAT0_MASK FTFE_FSTAT_MGSTAT0_MASK
<> 144:ef7eb2e8f9f7 165 #define FTFx_FSEC_SEC_MASK FTFE_FSEC_SEC_MASK
<> 144:ef7eb2e8f9f7 166 #define FTFx_FSEC_KEYEN_MASK FTFE_FSEC_KEYEN_MASK
<> 144:ef7eb2e8f9f7 167 #if defined(FSL_FEATURE_FLASH_HAS_FLEX_RAM) && FSL_FEATURE_FLASH_HAS_FLEX_RAM
<> 144:ef7eb2e8f9f7 168 #define FTFx_FCNFG_RAMRDY_MASK FTFE_FCNFG_RAMRDY_MASK
<> 144:ef7eb2e8f9f7 169 #endif /* FSL_FEATURE_FLASH_HAS_FLEX_RAM */
<> 144:ef7eb2e8f9f7 170 #if defined(FSL_FEATURE_FLASH_HAS_FLEX_NVM) && FSL_FEATURE_FLASH_HAS_FLEX_NVM
<> 144:ef7eb2e8f9f7 171 #define FTFx_FCNFG_EEERDY_MASK FTFE_FCNFG_EEERDY_MASK
<> 144:ef7eb2e8f9f7 172 #endif /* FSL_FEATURE_FLASH_HAS_FLEX_NVM */
<> 144:ef7eb2e8f9f7 173 #elif defined(FTFL)
<> 144:ef7eb2e8f9f7 174 #define FTFx FTFL
<> 144:ef7eb2e8f9f7 175 #define FTFx_BASE FTFL_BASE
<> 144:ef7eb2e8f9f7 176 #define FTFx_FSTAT_CCIF_MASK FTFL_FSTAT_CCIF_MASK
<> 144:ef7eb2e8f9f7 177 #define FTFx_FSTAT_RDCOLERR_MASK FTFL_FSTAT_RDCOLERR_MASK
<> 144:ef7eb2e8f9f7 178 #define FTFx_FSTAT_ACCERR_MASK FTFL_FSTAT_ACCERR_MASK
<> 144:ef7eb2e8f9f7 179 #define FTFx_FSTAT_FPVIOL_MASK FTFL_FSTAT_FPVIOL_MASK
<> 144:ef7eb2e8f9f7 180 #define FTFx_FSTAT_MGSTAT0_MASK FTFL_FSTAT_MGSTAT0_MASK
<> 144:ef7eb2e8f9f7 181 #define FTFx_FSEC_SEC_MASK FTFL_FSEC_SEC_MASK
<> 144:ef7eb2e8f9f7 182 #define FTFx_FSEC_KEYEN_MASK FTFL_FSEC_KEYEN_MASK
<> 144:ef7eb2e8f9f7 183 #if defined(FSL_FEATURE_FLASH_HAS_FLEX_RAM) && FSL_FEATURE_FLASH_HAS_FLEX_RAM
<> 144:ef7eb2e8f9f7 184 #define FTFx_FCNFG_RAMRDY_MASK FTFL_FCNFG_RAMRDY_MASK
<> 144:ef7eb2e8f9f7 185 #endif /* FSL_FEATURE_FLASH_HAS_FLEX_RAM */
<> 144:ef7eb2e8f9f7 186 #if defined(FSL_FEATURE_FLASH_HAS_FLEX_NVM) && FSL_FEATURE_FLASH_HAS_FLEX_NVM
<> 144:ef7eb2e8f9f7 187 #define FTFx_FCNFG_EEERDY_MASK FTFL_FCNFG_EEERDY_MASK
<> 144:ef7eb2e8f9f7 188 #endif /* FSL_FEATURE_FLASH_HAS_FLEX_NVM */
<> 144:ef7eb2e8f9f7 189 #else
<> 144:ef7eb2e8f9f7 190 #error "Unknown flash controller"
<> 144:ef7eb2e8f9f7 191 #endif
<> 144:ef7eb2e8f9f7 192 /*@}*/
<> 144:ef7eb2e8f9f7 193
<> 144:ef7eb2e8f9f7 194 /*!
<> 144:ef7eb2e8f9f7 195 * @brief Enumeration for access segment property.
<> 144:ef7eb2e8f9f7 196 */
<> 144:ef7eb2e8f9f7 197 enum _flash_access_segment_property
<> 144:ef7eb2e8f9f7 198 {
<> 144:ef7eb2e8f9f7 199 kFLASH_accessSegmentBase = 256UL,
<> 144:ef7eb2e8f9f7 200 };
<> 144:ef7eb2e8f9f7 201
<> 144:ef7eb2e8f9f7 202 /*!
<> 144:ef7eb2e8f9f7 203 * @brief Enumeration for acceleration ram property.
<> 144:ef7eb2e8f9f7 204 */
<> 144:ef7eb2e8f9f7 205 enum _flash_acceleration_ram_property
<> 144:ef7eb2e8f9f7 206 {
<> 144:ef7eb2e8f9f7 207 kFLASH_accelerationRamSize = 0x400U
<> 144:ef7eb2e8f9f7 208 };
<> 144:ef7eb2e8f9f7 209
<> 144:ef7eb2e8f9f7 210 /*!
<> 144:ef7eb2e8f9f7 211 * @brief Enumeration for flash config area.
<> 144:ef7eb2e8f9f7 212 */
<> 144:ef7eb2e8f9f7 213 enum _flash_config_area_range
<> 144:ef7eb2e8f9f7 214 {
<> 144:ef7eb2e8f9f7 215 kFLASH_configAreaStart = 0x400U,
<> 144:ef7eb2e8f9f7 216 kFLASH_configAreaEnd = 0x40FU
<> 144:ef7eb2e8f9f7 217 };
<> 144:ef7eb2e8f9f7 218
<> 144:ef7eb2e8f9f7 219 /*! @brief program Flash block base address*/
<> 144:ef7eb2e8f9f7 220 #define PFLASH_BLOCK_BASE 0x00U
<> 144:ef7eb2e8f9f7 221
<> 144:ef7eb2e8f9f7 222 /*! @brief Total flash region count*/
<> 144:ef7eb2e8f9f7 223 #define FSL_FEATURE_FTFx_REGION_COUNT (32U)
<> 144:ef7eb2e8f9f7 224
<> 144:ef7eb2e8f9f7 225 /*!
<> 144:ef7eb2e8f9f7 226 * @name Flash register access type defines
<> 144:ef7eb2e8f9f7 227 * @{
<> 144:ef7eb2e8f9f7 228 */
<> 144:ef7eb2e8f9f7 229 #if FLASH_DRIVER_IS_FLASH_RESIDENT
<> 144:ef7eb2e8f9f7 230 #define FTFx_REG_ACCESS_TYPE volatile uint8_t *
<> 144:ef7eb2e8f9f7 231 #define FTFx_REG32_ACCESS_TYPE volatile uint32_t *
<> 144:ef7eb2e8f9f7 232 #endif /* FLASH_DRIVER_IS_FLASH_RESIDENT */
<> 144:ef7eb2e8f9f7 233 /*@}*/
<> 144:ef7eb2e8f9f7 234
<> 144:ef7eb2e8f9f7 235 /*******************************************************************************
<> 144:ef7eb2e8f9f7 236 * Prototypes
<> 144:ef7eb2e8f9f7 237 ******************************************************************************/
<> 144:ef7eb2e8f9f7 238
<> 144:ef7eb2e8f9f7 239 #if FLASH_DRIVER_IS_FLASH_RESIDENT
<> 144:ef7eb2e8f9f7 240 /*! @brief Copy flash_run_command() to RAM*/
<> 144:ef7eb2e8f9f7 241 static void copy_flash_run_command(uint8_t *flashRunCommand);
<> 144:ef7eb2e8f9f7 242 /*! @brief Copy flash_cache_clear_command() to RAM*/
<> 144:ef7eb2e8f9f7 243 static void copy_flash_cache_clear_command(uint8_t *flashCacheClearCommand);
<> 144:ef7eb2e8f9f7 244 /*! @brief Check whether flash execute-in-ram functions are ready*/
<> 144:ef7eb2e8f9f7 245 static status_t flash_check_execute_in_ram_function_info(flash_config_t *config);
<> 144:ef7eb2e8f9f7 246 #endif /* FLASH_DRIVER_IS_FLASH_RESIDENT */
<> 144:ef7eb2e8f9f7 247
<> 144:ef7eb2e8f9f7 248 /*! @brief Internal function Flash command sequence. Called by driver APIs only*/
<> 144:ef7eb2e8f9f7 249 static status_t flash_command_sequence(flash_config_t *config);
<> 144:ef7eb2e8f9f7 250
<> 144:ef7eb2e8f9f7 251 /*! @brief Perform the cache clear to the flash*/
<> 144:ef7eb2e8f9f7 252 void flash_cache_clear(flash_config_t *config);
<> 144:ef7eb2e8f9f7 253
<> 144:ef7eb2e8f9f7 254 /*! @brief Validates the range and alignment of the given address range.*/
<> 144:ef7eb2e8f9f7 255 static status_t flash_check_range(flash_config_t *config,
<> 144:ef7eb2e8f9f7 256 uint32_t startAddress,
<> 144:ef7eb2e8f9f7 257 uint32_t lengthInBytes,
<> 144:ef7eb2e8f9f7 258 uint32_t alignmentBaseline);
<> 144:ef7eb2e8f9f7 259 /*! @brief Gets the right address, sector and block size of current flash type which is indicated by address.*/
<> 144:ef7eb2e8f9f7 260 static status_t flash_get_matched_operation_info(flash_config_t *config,
<> 144:ef7eb2e8f9f7 261 uint32_t address,
<> 144:ef7eb2e8f9f7 262 flash_operation_config_t *info);
<> 144:ef7eb2e8f9f7 263 /*! @brief Validates the given user key for flash erase APIs.*/
<> 144:ef7eb2e8f9f7 264 static status_t flash_check_user_key(uint32_t key);
<> 144:ef7eb2e8f9f7 265
<> 144:ef7eb2e8f9f7 266 #if FLASH_SSD_IS_FLEXNVM_ENABLED
<> 144:ef7eb2e8f9f7 267 /*! @brief Updates FlexNVM memory partition status according to data flash 0 IFR.*/
<> 144:ef7eb2e8f9f7 268 static status_t flash_update_flexnvm_memory_partition_status(flash_config_t *config);
<> 144:ef7eb2e8f9f7 269 #endif /* FLASH_SSD_IS_FLEXNVM_ENABLED */
<> 144:ef7eb2e8f9f7 270
<> 144:ef7eb2e8f9f7 271 #if defined(FSL_FEATURE_FLASH_HAS_READ_RESOURCE_CMD) && FSL_FEATURE_FLASH_HAS_READ_RESOURCE_CMD
<> 144:ef7eb2e8f9f7 272 /*! @brief Validates the range of the given resource address.*/
<> 144:ef7eb2e8f9f7 273 static status_t flash_check_resource_range(uint32_t start,
<> 144:ef7eb2e8f9f7 274 uint32_t lengthInBytes,
<> 144:ef7eb2e8f9f7 275 uint32_t alignmentBaseline,
<> 144:ef7eb2e8f9f7 276 flash_read_resource_option_t option);
<> 144:ef7eb2e8f9f7 277 #endif /* FSL_FEATURE_FLASH_HAS_READ_RESOURCE_CMD */
<> 144:ef7eb2e8f9f7 278
<> 144:ef7eb2e8f9f7 279 #if defined(FSL_FEATURE_FLASH_HAS_SWAP_CONTROL_CMD) && FSL_FEATURE_FLASH_HAS_SWAP_CONTROL_CMD
<> 144:ef7eb2e8f9f7 280 /*! @brief Validates the gived swap control option.*/
<> 144:ef7eb2e8f9f7 281 static status_t flash_check_swap_control_option(flash_swap_control_option_t option);
<> 144:ef7eb2e8f9f7 282 #endif /* FSL_FEATURE_FLASH_HAS_SWAP_CONTROL_CMD */
<> 144:ef7eb2e8f9f7 283
<> 144:ef7eb2e8f9f7 284 #if defined(FSL_FEATURE_FLASH_HAS_PFLASH_BLOCK_SWAP) && FSL_FEATURE_FLASH_HAS_PFLASH_BLOCK_SWAP
<> 144:ef7eb2e8f9f7 285 /*! @brief Validates the gived address to see if it is equal to swap indicator address in pflash swap IFR.*/
<> 144:ef7eb2e8f9f7 286 static status_t flash_validate_swap_indicator_address(flash_config_t *config, uint32_t address);
<> 144:ef7eb2e8f9f7 287 #endif /* FSL_FEATURE_FLASH_HAS_PFLASH_BLOCK_SWAP */
<> 144:ef7eb2e8f9f7 288
<> 144:ef7eb2e8f9f7 289 #if defined(FSL_FEATURE_FLASH_HAS_SET_FLEXRAM_FUNCTION_CMD) && FSL_FEATURE_FLASH_HAS_SET_FLEXRAM_FUNCTION_CMD
<> 144:ef7eb2e8f9f7 290 /*! @brief Validates the gived flexram function option.*/
<> 144:ef7eb2e8f9f7 291 static inline status_t flasn_check_flexram_function_option_range(flash_flexram_function_option_t option);
<> 144:ef7eb2e8f9f7 292 #endif /* FSL_FEATURE_FLASH_HAS_SET_FLEXRAM_FUNCTION_CMD */
<> 144:ef7eb2e8f9f7 293
<> 144:ef7eb2e8f9f7 294 /*******************************************************************************
<> 144:ef7eb2e8f9f7 295 * Variables
<> 144:ef7eb2e8f9f7 296 ******************************************************************************/
<> 144:ef7eb2e8f9f7 297
<> 144:ef7eb2e8f9f7 298 /*! @brief Access to FTFx->FCCOB */
<> 144:ef7eb2e8f9f7 299 #if defined(FSL_FEATURE_FLASH_IS_FTFA) && FSL_FEATURE_FLASH_IS_FTFA
<> 144:ef7eb2e8f9f7 300 volatile uint32_t *const kFCCOBx = (volatile uint32_t *)&FTFA->FCCOB3;
<> 144:ef7eb2e8f9f7 301 #elif defined(FSL_FEATURE_FLASH_IS_FTFE) && FSL_FEATURE_FLASH_IS_FTFE
<> 144:ef7eb2e8f9f7 302 volatile uint32_t *const kFCCOBx = (volatile uint32_t *)&FTFE->FCCOB3;
<> 144:ef7eb2e8f9f7 303 #elif defined(FSL_FEATURE_FLASH_IS_FTFL) && FSL_FEATURE_FLASH_IS_FTFL
<> 144:ef7eb2e8f9f7 304 volatile uint32_t *const kFCCOBx = (volatile uint32_t *)&FTFL->FCCOB3;
<> 144:ef7eb2e8f9f7 305 #else
<> 144:ef7eb2e8f9f7 306 #error "Unknown flash controller"
<> 144:ef7eb2e8f9f7 307 #endif
<> 144:ef7eb2e8f9f7 308
<> 144:ef7eb2e8f9f7 309 /*! @brief Access to FTFx->FPROT */
<> 144:ef7eb2e8f9f7 310 #if defined(FSL_FEATURE_FLASH_IS_FTFA) && FSL_FEATURE_FLASH_IS_FTFA
<> 144:ef7eb2e8f9f7 311 volatile uint32_t *const kFPROT = (volatile uint32_t *)&FTFA->FPROT3;
<> 144:ef7eb2e8f9f7 312 #elif defined(FSL_FEATURE_FLASH_IS_FTFE) && FSL_FEATURE_FLASH_IS_FTFE
<> 144:ef7eb2e8f9f7 313 volatile uint32_t *const kFPROT = (volatile uint32_t *)&FTFE->FPROT3;
<> 144:ef7eb2e8f9f7 314 #elif defined(FSL_FEATURE_FLASH_IS_FTFL) && FSL_FEATURE_FLASH_IS_FTFL
<> 144:ef7eb2e8f9f7 315 volatile uint32_t *const kFPROT = (volatile uint32_t *)&FTFL->FPROT3;
<> 144:ef7eb2e8f9f7 316 #else
<> 144:ef7eb2e8f9f7 317 #error "Unknown flash controller"
<> 144:ef7eb2e8f9f7 318 #endif
<> 144:ef7eb2e8f9f7 319
<> 144:ef7eb2e8f9f7 320 #if FLASH_DRIVER_IS_FLASH_RESIDENT
<> 144:ef7eb2e8f9f7 321 /*! @brief A function pointer used to point to relocated flash_run_command() */
<> 144:ef7eb2e8f9f7 322 static void (*callFlashRunCommand)(FTFx_REG_ACCESS_TYPE ftfx_fstat);
<> 144:ef7eb2e8f9f7 323 /*! @brief A function pointer used to point to relocated flash_cache_clear_command() */
<> 144:ef7eb2e8f9f7 324 static void (*callFlashCacheClearCommand)(FTFx_REG32_ACCESS_TYPE ftfx_reg);
<> 144:ef7eb2e8f9f7 325 #endif /* FLASH_DRIVER_IS_FLASH_RESIDENT */
<> 144:ef7eb2e8f9f7 326
<> 144:ef7eb2e8f9f7 327 #if (FLASH_DRIVER_IS_FLASH_RESIDENT && !FLASH_DRIVER_IS_EXPORTED)
<> 144:ef7eb2e8f9f7 328 /*! @brief A static buffer used to hold flash_run_command() */
<> 144:ef7eb2e8f9f7 329 static uint8_t s_flashRunCommand[kFLASH_executeInRamFunctionMaxSize];
<> 144:ef7eb2e8f9f7 330 /*! @brief A static buffer used to hold flash_cache_clear_command() */
<> 144:ef7eb2e8f9f7 331 static uint8_t s_flashCacheClearCommand[kFLASH_executeInRamFunctionMaxSize];
<> 144:ef7eb2e8f9f7 332 /*! @brief Flash execute-in-ram function information */
<> 144:ef7eb2e8f9f7 333 static flash_execute_in_ram_function_config_t s_flashExecuteInRamFunctionInfo;
<> 144:ef7eb2e8f9f7 334 #endif
<> 144:ef7eb2e8f9f7 335
<> 144:ef7eb2e8f9f7 336 /*!
<> 144:ef7eb2e8f9f7 337 * @brief Table of pflash sizes.
<> 144:ef7eb2e8f9f7 338 *
<> 144:ef7eb2e8f9f7 339 * The index into this table is the value of the SIM_FCFG1.PFSIZE bitfield.
<> 144:ef7eb2e8f9f7 340 *
<> 144:ef7eb2e8f9f7 341 * The values in this table have been right shifted 10 bits so that they will all fit within
<> 144:ef7eb2e8f9f7 342 * an 16-bit integer. To get the actual flash density, you must left shift the looked up value
<> 144:ef7eb2e8f9f7 343 * by 10 bits.
<> 144:ef7eb2e8f9f7 344 *
<> 144:ef7eb2e8f9f7 345 * Elements of this table have a value of 0 in cases where the PFSIZE bitfield value is
<> 144:ef7eb2e8f9f7 346 * reserved.
<> 144:ef7eb2e8f9f7 347 *
<> 144:ef7eb2e8f9f7 348 * Code to use the table:
<> 144:ef7eb2e8f9f7 349 * @code
<> 144:ef7eb2e8f9f7 350 * uint8_t pfsize = (SIM->FCFG1 & SIM_FCFG1_PFSIZE_MASK) >> SIM_FCFG1_PFSIZE_SHIFT;
<> 144:ef7eb2e8f9f7 351 * flashDensity = ((uint32_t)kPFlashDensities[pfsize]) << 10;
<> 144:ef7eb2e8f9f7 352 * @endcode
<> 144:ef7eb2e8f9f7 353 */
<> 144:ef7eb2e8f9f7 354 const uint16_t kPFlashDensities[] = {
<> 144:ef7eb2e8f9f7 355 8, /* 0x0 - 8192, 8KB */
<> 144:ef7eb2e8f9f7 356 16, /* 0x1 - 16384, 16KB */
<> 144:ef7eb2e8f9f7 357 24, /* 0x2 - 24576, 24KB */
<> 144:ef7eb2e8f9f7 358 32, /* 0x3 - 32768, 32KB */
<> 144:ef7eb2e8f9f7 359 48, /* 0x4 - 49152, 48KB */
<> 144:ef7eb2e8f9f7 360 64, /* 0x5 - 65536, 64KB */
<> 144:ef7eb2e8f9f7 361 96, /* 0x6 - 98304, 96KB */
<> 144:ef7eb2e8f9f7 362 128, /* 0x7 - 131072, 128KB */
<> 144:ef7eb2e8f9f7 363 192, /* 0x8 - 196608, 192KB */
<> 144:ef7eb2e8f9f7 364 256, /* 0x9 - 262144, 256KB */
<> 144:ef7eb2e8f9f7 365 384, /* 0xa - 393216, 384KB */
<> 144:ef7eb2e8f9f7 366 512, /* 0xb - 524288, 512KB */
<> 144:ef7eb2e8f9f7 367 768, /* 0xc - 786432, 768KB */
<> 144:ef7eb2e8f9f7 368 1024, /* 0xd - 1048576, 1MB */
<> 144:ef7eb2e8f9f7 369 1536, /* 0xe - 1572864, 1.5MB */
<> 144:ef7eb2e8f9f7 370 /* 2048, 0xf - 2097152, 2MB */
<> 144:ef7eb2e8f9f7 371 };
<> 144:ef7eb2e8f9f7 372
<> 144:ef7eb2e8f9f7 373 /*******************************************************************************
<> 144:ef7eb2e8f9f7 374 * Code
<> 144:ef7eb2e8f9f7 375 ******************************************************************************/
<> 144:ef7eb2e8f9f7 376
<> 144:ef7eb2e8f9f7 377 status_t FLASH_Init(flash_config_t *config)
<> 144:ef7eb2e8f9f7 378 {
<> 144:ef7eb2e8f9f7 379 uint32_t flashDensity;
<> 144:ef7eb2e8f9f7 380
<> 144:ef7eb2e8f9f7 381 if (config == NULL)
<> 144:ef7eb2e8f9f7 382 {
<> 144:ef7eb2e8f9f7 383 return kStatus_FLASH_InvalidArgument;
<> 144:ef7eb2e8f9f7 384 }
<> 144:ef7eb2e8f9f7 385
<> 144:ef7eb2e8f9f7 386 /* calculate the flash density from SIM_FCFG1.PFSIZE */
<> 144:ef7eb2e8f9f7 387 uint8_t pfsize = (SIM->FCFG1 & SIM_FCFG1_PFSIZE_MASK) >> SIM_FCFG1_PFSIZE_SHIFT;
<> 144:ef7eb2e8f9f7 388 /* PFSIZE=0xf means that on customer parts the IFR was not correctly programmed.
<> 144:ef7eb2e8f9f7 389 * We just use the pre-defined flash size in feature file here to support pre-production parts */
<> 144:ef7eb2e8f9f7 390 if (pfsize == 0xf)
<> 144:ef7eb2e8f9f7 391 {
<> 144:ef7eb2e8f9f7 392 flashDensity = FSL_FEATURE_FLASH_PFLASH_BLOCK_COUNT * FSL_FEATURE_FLASH_PFLASH_BLOCK_SIZE;
<> 144:ef7eb2e8f9f7 393 }
<> 144:ef7eb2e8f9f7 394 else
<> 144:ef7eb2e8f9f7 395 {
<> 144:ef7eb2e8f9f7 396 flashDensity = ((uint32_t)kPFlashDensities[pfsize]) << 10;
<> 144:ef7eb2e8f9f7 397 }
<> 144:ef7eb2e8f9f7 398
<> 144:ef7eb2e8f9f7 399 /* fill out a few of the structure members */
<> 144:ef7eb2e8f9f7 400 config->PFlashBlockBase = PFLASH_BLOCK_BASE;
<> 144:ef7eb2e8f9f7 401 config->PFlashTotalSize = flashDensity;
<> 144:ef7eb2e8f9f7 402 config->PFlashBlockCount = FSL_FEATURE_FLASH_PFLASH_BLOCK_COUNT;
<> 144:ef7eb2e8f9f7 403 config->PFlashSectorSize = FSL_FEATURE_FLASH_PFLASH_BLOCK_SECTOR_SIZE;
<> 144:ef7eb2e8f9f7 404
<> 144:ef7eb2e8f9f7 405 #if defined(FSL_FEATURE_FLASH_HAS_ACCESS_CONTROL) && FSL_FEATURE_FLASH_HAS_ACCESS_CONTROL
<> 144:ef7eb2e8f9f7 406 config->PFlashAccessSegmentSize = kFLASH_accessSegmentBase << FTFx->FACSS;
<> 144:ef7eb2e8f9f7 407 config->PFlashAccessSegmentCount = FTFx->FACSN;
<> 144:ef7eb2e8f9f7 408 #else
<> 144:ef7eb2e8f9f7 409 config->PFlashAccessSegmentSize = 0;
<> 144:ef7eb2e8f9f7 410 config->PFlashAccessSegmentCount = 0;
<> 144:ef7eb2e8f9f7 411 #endif /* FSL_FEATURE_FLASH_HAS_ACCESS_CONTROL */
<> 144:ef7eb2e8f9f7 412
<> 144:ef7eb2e8f9f7 413 config->PFlashCallback = NULL;
<> 144:ef7eb2e8f9f7 414
<> 144:ef7eb2e8f9f7 415 /* copy required flash commands to RAM */
<> 144:ef7eb2e8f9f7 416 #if (FLASH_DRIVER_IS_FLASH_RESIDENT && !FLASH_DRIVER_IS_EXPORTED)
<> 144:ef7eb2e8f9f7 417 if (kStatus_FLASH_Success != flash_check_execute_in_ram_function_info(config))
<> 144:ef7eb2e8f9f7 418 {
<> 144:ef7eb2e8f9f7 419 s_flashExecuteInRamFunctionInfo.activeFunctionCount = 0;
<> 144:ef7eb2e8f9f7 420 s_flashExecuteInRamFunctionInfo.flashRunCommand = s_flashRunCommand;
<> 144:ef7eb2e8f9f7 421 s_flashExecuteInRamFunctionInfo.flashCacheClearCommand = s_flashCacheClearCommand;
<> 144:ef7eb2e8f9f7 422 config->flashExecuteInRamFunctionInfo = &s_flashExecuteInRamFunctionInfo.activeFunctionCount;
<> 144:ef7eb2e8f9f7 423 FLASH_PrepareExecuteInRamFunctions(config);
<> 144:ef7eb2e8f9f7 424 }
<> 144:ef7eb2e8f9f7 425 #endif
<> 144:ef7eb2e8f9f7 426
<> 144:ef7eb2e8f9f7 427 config->FlexRAMBlockBase = FSL_FEATURE_FLASH_FLEX_RAM_START_ADDRESS;
<> 144:ef7eb2e8f9f7 428 config->FlexRAMTotalSize = FSL_FEATURE_FLASH_FLEX_RAM_SIZE;
<> 144:ef7eb2e8f9f7 429
<> 144:ef7eb2e8f9f7 430 #if FLASH_SSD_IS_FLEXNVM_ENABLED
<> 144:ef7eb2e8f9f7 431 {
<> 144:ef7eb2e8f9f7 432 status_t returnCode;
<> 144:ef7eb2e8f9f7 433 config->DFlashBlockBase = FSL_FEATURE_FLASH_FLEX_NVM_START_ADDRESS;
<> 144:ef7eb2e8f9f7 434 returnCode = flash_update_flexnvm_memory_partition_status(config);
<> 144:ef7eb2e8f9f7 435 if (returnCode != kStatus_FLASH_Success)
<> 144:ef7eb2e8f9f7 436 {
<> 144:ef7eb2e8f9f7 437 return returnCode;
<> 144:ef7eb2e8f9f7 438 }
<> 144:ef7eb2e8f9f7 439 }
<> 144:ef7eb2e8f9f7 440 #endif
<> 144:ef7eb2e8f9f7 441
<> 144:ef7eb2e8f9f7 442 return kStatus_FLASH_Success;
<> 144:ef7eb2e8f9f7 443 }
<> 144:ef7eb2e8f9f7 444
<> 144:ef7eb2e8f9f7 445 status_t FLASH_SetCallback(flash_config_t *config, flash_callback_t callback)
<> 144:ef7eb2e8f9f7 446 {
<> 144:ef7eb2e8f9f7 447 if (config == NULL)
<> 144:ef7eb2e8f9f7 448 {
<> 144:ef7eb2e8f9f7 449 return kStatus_FLASH_InvalidArgument;
<> 144:ef7eb2e8f9f7 450 }
<> 144:ef7eb2e8f9f7 451
<> 144:ef7eb2e8f9f7 452 config->PFlashCallback = callback;
<> 144:ef7eb2e8f9f7 453
<> 144:ef7eb2e8f9f7 454 return kStatus_FLASH_Success;
<> 144:ef7eb2e8f9f7 455 }
<> 144:ef7eb2e8f9f7 456
<> 144:ef7eb2e8f9f7 457 #if FLASH_DRIVER_IS_FLASH_RESIDENT
<> 144:ef7eb2e8f9f7 458 status_t FLASH_PrepareExecuteInRamFunctions(flash_config_t *config)
<> 144:ef7eb2e8f9f7 459 {
<> 144:ef7eb2e8f9f7 460 flash_execute_in_ram_function_config_t *flashExecuteInRamFunctionInfo;
<> 144:ef7eb2e8f9f7 461
<> 144:ef7eb2e8f9f7 462 if (config == NULL)
<> 144:ef7eb2e8f9f7 463 {
<> 144:ef7eb2e8f9f7 464 return kStatus_FLASH_InvalidArgument;
<> 144:ef7eb2e8f9f7 465 }
<> 144:ef7eb2e8f9f7 466
<> 144:ef7eb2e8f9f7 467 flashExecuteInRamFunctionInfo = (flash_execute_in_ram_function_config_t *)config->flashExecuteInRamFunctionInfo;
<> 144:ef7eb2e8f9f7 468
<> 144:ef7eb2e8f9f7 469 copy_flash_run_command(flashExecuteInRamFunctionInfo->flashRunCommand);
<> 144:ef7eb2e8f9f7 470 copy_flash_cache_clear_command(flashExecuteInRamFunctionInfo->flashCacheClearCommand);
<> 144:ef7eb2e8f9f7 471 flashExecuteInRamFunctionInfo->activeFunctionCount = kFLASH_executeInRamFunctionTotalNum;
<> 144:ef7eb2e8f9f7 472
<> 144:ef7eb2e8f9f7 473 return kStatus_FLASH_Success;
<> 144:ef7eb2e8f9f7 474 }
<> 144:ef7eb2e8f9f7 475 #endif /* FLASH_DRIVER_IS_FLASH_RESIDENT */
<> 144:ef7eb2e8f9f7 476
<> 144:ef7eb2e8f9f7 477 status_t FLASH_EraseAll(flash_config_t *config, uint32_t key)
<> 144:ef7eb2e8f9f7 478 {
<> 144:ef7eb2e8f9f7 479 status_t returnCode;
<> 144:ef7eb2e8f9f7 480
<> 144:ef7eb2e8f9f7 481 if (config == NULL)
<> 144:ef7eb2e8f9f7 482 {
<> 144:ef7eb2e8f9f7 483 return kStatus_FLASH_InvalidArgument;
<> 144:ef7eb2e8f9f7 484 }
<> 144:ef7eb2e8f9f7 485
<> 144:ef7eb2e8f9f7 486 /* preparing passing parameter to erase all flash blocks */
<> 144:ef7eb2e8f9f7 487 kFCCOBx[0] = BYTES_JOIN_TO_WORD_1_3(FTFx_ERASE_ALL_BLOCK, 0xFFFFFFU);
<> 144:ef7eb2e8f9f7 488
<> 144:ef7eb2e8f9f7 489 /* Validate the user key */
<> 144:ef7eb2e8f9f7 490 returnCode = flash_check_user_key(key);
<> 144:ef7eb2e8f9f7 491 if (returnCode)
<> 144:ef7eb2e8f9f7 492 {
<> 144:ef7eb2e8f9f7 493 return returnCode;
<> 144:ef7eb2e8f9f7 494 }
<> 144:ef7eb2e8f9f7 495
<> 144:ef7eb2e8f9f7 496 /* calling flash command sequence function to execute the command */
<> 144:ef7eb2e8f9f7 497 returnCode = flash_command_sequence(config);
<> 144:ef7eb2e8f9f7 498
<> 144:ef7eb2e8f9f7 499 flash_cache_clear(config);
<> 144:ef7eb2e8f9f7 500
<> 144:ef7eb2e8f9f7 501 #if FLASH_SSD_IS_FLEXNVM_ENABLED
<> 144:ef7eb2e8f9f7 502 /* Data flash IFR will be erased by erase all command, so we need to
<> 144:ef7eb2e8f9f7 503 * update FlexNVM memory partition status synchronously */
<> 144:ef7eb2e8f9f7 504 if (returnCode == kStatus_FLASH_Success)
<> 144:ef7eb2e8f9f7 505 {
<> 144:ef7eb2e8f9f7 506 returnCode = flash_update_flexnvm_memory_partition_status(config);
<> 144:ef7eb2e8f9f7 507 }
<> 144:ef7eb2e8f9f7 508 #endif
<> 144:ef7eb2e8f9f7 509
<> 144:ef7eb2e8f9f7 510 return returnCode;
<> 144:ef7eb2e8f9f7 511 }
<> 144:ef7eb2e8f9f7 512
<> 144:ef7eb2e8f9f7 513 status_t FLASH_Erase(flash_config_t *config, uint32_t start, uint32_t lengthInBytes, uint32_t key)
<> 144:ef7eb2e8f9f7 514 {
<> 144:ef7eb2e8f9f7 515 uint32_t sectorSize;
<> 144:ef7eb2e8f9f7 516 flash_operation_config_t flashInfo;
<> 144:ef7eb2e8f9f7 517 uint32_t endAddress; /* storing end address */
<> 144:ef7eb2e8f9f7 518 uint32_t numberOfSectors; /* number of sectors calculated by endAddress */
<> 144:ef7eb2e8f9f7 519 status_t returnCode;
<> 144:ef7eb2e8f9f7 520
<> 144:ef7eb2e8f9f7 521 flash_get_matched_operation_info(config, start, &flashInfo);
<> 144:ef7eb2e8f9f7 522
<> 144:ef7eb2e8f9f7 523 /* Check the supplied address range. */
<> 144:ef7eb2e8f9f7 524 returnCode = flash_check_range(config, start, lengthInBytes, flashInfo.sectorCmdAddressAligment);
<> 144:ef7eb2e8f9f7 525 if (returnCode)
<> 144:ef7eb2e8f9f7 526 {
<> 144:ef7eb2e8f9f7 527 return returnCode;
<> 144:ef7eb2e8f9f7 528 }
<> 144:ef7eb2e8f9f7 529
<> 144:ef7eb2e8f9f7 530 start = flashInfo.convertedAddress;
<> 144:ef7eb2e8f9f7 531 sectorSize = flashInfo.activeSectorSize;
<> 144:ef7eb2e8f9f7 532
<> 144:ef7eb2e8f9f7 533 /* calculating Flash end address */
<> 144:ef7eb2e8f9f7 534 endAddress = start + lengthInBytes - 1;
<> 144:ef7eb2e8f9f7 535
<> 144:ef7eb2e8f9f7 536 /* re-calculate the endAddress and align it to the start of the next sector
<> 144:ef7eb2e8f9f7 537 * which will be used in the comparison below */
<> 144:ef7eb2e8f9f7 538 if (endAddress % sectorSize)
<> 144:ef7eb2e8f9f7 539 {
<> 144:ef7eb2e8f9f7 540 numberOfSectors = endAddress / sectorSize + 1;
<> 144:ef7eb2e8f9f7 541 endAddress = numberOfSectors * sectorSize - 1;
<> 144:ef7eb2e8f9f7 542 }
<> 144:ef7eb2e8f9f7 543
<> 144:ef7eb2e8f9f7 544 /* the start address will increment to the next sector address
<> 144:ef7eb2e8f9f7 545 * until it reaches the endAdddress */
<> 144:ef7eb2e8f9f7 546 while (start <= endAddress)
<> 144:ef7eb2e8f9f7 547 {
<> 144:ef7eb2e8f9f7 548 /* preparing passing parameter to erase a flash block */
<> 144:ef7eb2e8f9f7 549 kFCCOBx[0] = BYTES_JOIN_TO_WORD_1_3(FTFx_ERASE_SECTOR, start);
<> 144:ef7eb2e8f9f7 550
<> 144:ef7eb2e8f9f7 551 /* Validate the user key */
<> 144:ef7eb2e8f9f7 552 returnCode = flash_check_user_key(key);
<> 144:ef7eb2e8f9f7 553 if (returnCode)
<> 144:ef7eb2e8f9f7 554 {
<> 144:ef7eb2e8f9f7 555 return returnCode;
<> 144:ef7eb2e8f9f7 556 }
<> 144:ef7eb2e8f9f7 557
<> 144:ef7eb2e8f9f7 558 /* calling flash command sequence function to execute the command */
<> 144:ef7eb2e8f9f7 559 returnCode = flash_command_sequence(config);
<> 144:ef7eb2e8f9f7 560
<> 144:ef7eb2e8f9f7 561 /* calling flash callback function if it is available */
<> 144:ef7eb2e8f9f7 562 if (config->PFlashCallback)
<> 144:ef7eb2e8f9f7 563 {
<> 144:ef7eb2e8f9f7 564 config->PFlashCallback();
<> 144:ef7eb2e8f9f7 565 }
<> 144:ef7eb2e8f9f7 566
<> 144:ef7eb2e8f9f7 567 /* checking the success of command execution */
<> 144:ef7eb2e8f9f7 568 if (kStatus_FLASH_Success != returnCode)
<> 144:ef7eb2e8f9f7 569 {
<> 144:ef7eb2e8f9f7 570 break;
<> 144:ef7eb2e8f9f7 571 }
<> 144:ef7eb2e8f9f7 572 else
<> 144:ef7eb2e8f9f7 573 {
<> 144:ef7eb2e8f9f7 574 /* Increment to the next sector */
<> 144:ef7eb2e8f9f7 575 start += sectorSize;
<> 144:ef7eb2e8f9f7 576 }
<> 144:ef7eb2e8f9f7 577 }
<> 144:ef7eb2e8f9f7 578
<> 144:ef7eb2e8f9f7 579 flash_cache_clear(config);
<> 144:ef7eb2e8f9f7 580
<> 144:ef7eb2e8f9f7 581 return (returnCode);
<> 144:ef7eb2e8f9f7 582 }
<> 144:ef7eb2e8f9f7 583
<> 144:ef7eb2e8f9f7 584 #if defined(FSL_FEATURE_FLASH_HAS_ERASE_ALL_BLOCKS_UNSECURE_CMD) && FSL_FEATURE_FLASH_HAS_ERASE_ALL_BLOCKS_UNSECURE_CMD
<> 144:ef7eb2e8f9f7 585 status_t FLASH_EraseAllUnsecure(flash_config_t *config, uint32_t key)
<> 144:ef7eb2e8f9f7 586 {
<> 144:ef7eb2e8f9f7 587 status_t returnCode;
<> 144:ef7eb2e8f9f7 588
<> 144:ef7eb2e8f9f7 589 if (config == NULL)
<> 144:ef7eb2e8f9f7 590 {
<> 144:ef7eb2e8f9f7 591 return kStatus_FLASH_InvalidArgument;
<> 144:ef7eb2e8f9f7 592 }
<> 144:ef7eb2e8f9f7 593
<> 144:ef7eb2e8f9f7 594 /* Prepare passing parameter to erase all flash blocks (unsecure). */
<> 144:ef7eb2e8f9f7 595 kFCCOBx[0] = BYTES_JOIN_TO_WORD_1_3(FTFx_ERASE_ALL_BLOCK_UNSECURE, 0xFFFFFFU);
<> 144:ef7eb2e8f9f7 596
<> 144:ef7eb2e8f9f7 597 /* Validate the user key */
<> 144:ef7eb2e8f9f7 598 returnCode = flash_check_user_key(key);
<> 144:ef7eb2e8f9f7 599 if (returnCode)
<> 144:ef7eb2e8f9f7 600 {
<> 144:ef7eb2e8f9f7 601 return returnCode;
<> 144:ef7eb2e8f9f7 602 }
<> 144:ef7eb2e8f9f7 603
<> 144:ef7eb2e8f9f7 604 /* calling flash command sequence function to execute the command */
<> 144:ef7eb2e8f9f7 605 returnCode = flash_command_sequence(config);
<> 144:ef7eb2e8f9f7 606
<> 144:ef7eb2e8f9f7 607 flash_cache_clear(config);
<> 144:ef7eb2e8f9f7 608
<> 144:ef7eb2e8f9f7 609 #if FLASH_SSD_IS_FLEXNVM_ENABLED
<> 144:ef7eb2e8f9f7 610 /* Data flash IFR will be erased by erase all unsecure command, so we need to
<> 144:ef7eb2e8f9f7 611 * update FlexNVM memory partition status synchronously */
<> 144:ef7eb2e8f9f7 612 if (returnCode == kStatus_FLASH_Success)
<> 144:ef7eb2e8f9f7 613 {
<> 144:ef7eb2e8f9f7 614 returnCode = flash_update_flexnvm_memory_partition_status(config);
<> 144:ef7eb2e8f9f7 615 }
<> 144:ef7eb2e8f9f7 616 #endif
<> 144:ef7eb2e8f9f7 617
<> 144:ef7eb2e8f9f7 618 return returnCode;
<> 144:ef7eb2e8f9f7 619 }
<> 144:ef7eb2e8f9f7 620 #endif /* FSL_FEATURE_FLASH_HAS_ERASE_ALL_BLOCKS_UNSECURE_CMD */
<> 144:ef7eb2e8f9f7 621
<> 144:ef7eb2e8f9f7 622 status_t FLASH_EraseAllExecuteOnlySegments(flash_config_t *config, uint32_t key)
<> 144:ef7eb2e8f9f7 623 {
<> 144:ef7eb2e8f9f7 624 status_t returnCode;
<> 144:ef7eb2e8f9f7 625
<> 144:ef7eb2e8f9f7 626 if (config == NULL)
<> 144:ef7eb2e8f9f7 627 {
<> 144:ef7eb2e8f9f7 628 return kStatus_FLASH_InvalidArgument;
<> 144:ef7eb2e8f9f7 629 }
<> 144:ef7eb2e8f9f7 630
<> 144:ef7eb2e8f9f7 631 /* preparing passing parameter to erase all execute-only segments
<> 144:ef7eb2e8f9f7 632 * 1st element for the FCCOB register */
<> 144:ef7eb2e8f9f7 633 kFCCOBx[0] = BYTES_JOIN_TO_WORD_1_3(FTFx_ERASE_ALL_EXECUTE_ONLY_SEGMENT, 0xFFFFFFU);
<> 144:ef7eb2e8f9f7 634
<> 144:ef7eb2e8f9f7 635 /* Validate the user key */
<> 144:ef7eb2e8f9f7 636 returnCode = flash_check_user_key(key);
<> 144:ef7eb2e8f9f7 637 if (returnCode)
<> 144:ef7eb2e8f9f7 638 {
<> 144:ef7eb2e8f9f7 639 return returnCode;
<> 144:ef7eb2e8f9f7 640 }
<> 144:ef7eb2e8f9f7 641
<> 144:ef7eb2e8f9f7 642 /* calling flash command sequence function to execute the command */
<> 144:ef7eb2e8f9f7 643 returnCode = flash_command_sequence(config);
<> 144:ef7eb2e8f9f7 644
<> 144:ef7eb2e8f9f7 645 flash_cache_clear(config);
<> 144:ef7eb2e8f9f7 646
<> 144:ef7eb2e8f9f7 647 return returnCode;
<> 144:ef7eb2e8f9f7 648 }
<> 144:ef7eb2e8f9f7 649
<> 144:ef7eb2e8f9f7 650 status_t FLASH_Program(flash_config_t *config, uint32_t start, uint32_t *src, uint32_t lengthInBytes)
<> 144:ef7eb2e8f9f7 651 {
<> 144:ef7eb2e8f9f7 652 status_t returnCode;
<> 144:ef7eb2e8f9f7 653 flash_operation_config_t flashInfo;
<> 144:ef7eb2e8f9f7 654
<> 144:ef7eb2e8f9f7 655 if (src == NULL)
<> 144:ef7eb2e8f9f7 656 {
<> 144:ef7eb2e8f9f7 657 return kStatus_FLASH_InvalidArgument;
<> 144:ef7eb2e8f9f7 658 }
<> 144:ef7eb2e8f9f7 659
<> 144:ef7eb2e8f9f7 660 flash_get_matched_operation_info(config, start, &flashInfo);
<> 144:ef7eb2e8f9f7 661
<> 144:ef7eb2e8f9f7 662 /* Check the supplied address range. */
<> 144:ef7eb2e8f9f7 663 returnCode = flash_check_range(config, start, lengthInBytes, flashInfo.blockWriteUnitSize);
<> 144:ef7eb2e8f9f7 664 if (returnCode)
<> 144:ef7eb2e8f9f7 665 {
<> 144:ef7eb2e8f9f7 666 return returnCode;
<> 144:ef7eb2e8f9f7 667 }
<> 144:ef7eb2e8f9f7 668
<> 144:ef7eb2e8f9f7 669 start = flashInfo.convertedAddress;
<> 144:ef7eb2e8f9f7 670
<> 144:ef7eb2e8f9f7 671 while (lengthInBytes > 0)
<> 144:ef7eb2e8f9f7 672 {
<> 144:ef7eb2e8f9f7 673 /* preparing passing parameter to program the flash block */
<> 144:ef7eb2e8f9f7 674 kFCCOBx[1] = *src++;
<> 144:ef7eb2e8f9f7 675 if (4 == flashInfo.blockWriteUnitSize)
<> 144:ef7eb2e8f9f7 676 {
<> 144:ef7eb2e8f9f7 677 kFCCOBx[0] = BYTES_JOIN_TO_WORD_1_3(FTFx_PROGRAM_LONGWORD, start);
<> 144:ef7eb2e8f9f7 678 }
<> 144:ef7eb2e8f9f7 679 else if (8 == flashInfo.blockWriteUnitSize)
<> 144:ef7eb2e8f9f7 680 {
<> 144:ef7eb2e8f9f7 681 kFCCOBx[2] = *src++;
<> 144:ef7eb2e8f9f7 682 kFCCOBx[0] = BYTES_JOIN_TO_WORD_1_3(FTFx_PROGRAM_PHRASE, start);
<> 144:ef7eb2e8f9f7 683 }
<> 144:ef7eb2e8f9f7 684 else
<> 144:ef7eb2e8f9f7 685 {
<> 144:ef7eb2e8f9f7 686 }
<> 144:ef7eb2e8f9f7 687
<> 144:ef7eb2e8f9f7 688 /* calling flash command sequence function to execute the command */
<> 144:ef7eb2e8f9f7 689 returnCode = flash_command_sequence(config);
<> 144:ef7eb2e8f9f7 690
<> 144:ef7eb2e8f9f7 691 /* calling flash callback function if it is available */
<> 144:ef7eb2e8f9f7 692 if (config->PFlashCallback)
<> 144:ef7eb2e8f9f7 693 {
<> 144:ef7eb2e8f9f7 694 config->PFlashCallback();
<> 144:ef7eb2e8f9f7 695 }
<> 144:ef7eb2e8f9f7 696
<> 144:ef7eb2e8f9f7 697 /* checking for the success of command execution */
<> 144:ef7eb2e8f9f7 698 if (kStatus_FLASH_Success != returnCode)
<> 144:ef7eb2e8f9f7 699 {
<> 144:ef7eb2e8f9f7 700 break;
<> 144:ef7eb2e8f9f7 701 }
<> 144:ef7eb2e8f9f7 702 else
<> 144:ef7eb2e8f9f7 703 {
<> 144:ef7eb2e8f9f7 704 /* update start address for next iteration */
<> 144:ef7eb2e8f9f7 705 start += flashInfo.blockWriteUnitSize;
<> 144:ef7eb2e8f9f7 706
<> 144:ef7eb2e8f9f7 707 /* update lengthInBytes for next iteration */
<> 144:ef7eb2e8f9f7 708 lengthInBytes -= flashInfo.blockWriteUnitSize;
<> 144:ef7eb2e8f9f7 709 }
<> 144:ef7eb2e8f9f7 710 }
<> 144:ef7eb2e8f9f7 711
<> 144:ef7eb2e8f9f7 712 flash_cache_clear(config);
<> 144:ef7eb2e8f9f7 713
<> 144:ef7eb2e8f9f7 714 return (returnCode);
<> 144:ef7eb2e8f9f7 715 }
<> 144:ef7eb2e8f9f7 716
<> 144:ef7eb2e8f9f7 717 status_t FLASH_ProgramOnce(flash_config_t *config, uint32_t index, uint32_t *src, uint32_t lengthInBytes)
<> 144:ef7eb2e8f9f7 718 {
<> 144:ef7eb2e8f9f7 719 status_t returnCode;
<> 144:ef7eb2e8f9f7 720
<> 144:ef7eb2e8f9f7 721 if ((config == NULL) || (src == NULL))
<> 144:ef7eb2e8f9f7 722 {
<> 144:ef7eb2e8f9f7 723 return kStatus_FLASH_InvalidArgument;
<> 144:ef7eb2e8f9f7 724 }
<> 144:ef7eb2e8f9f7 725
<> 144:ef7eb2e8f9f7 726 /* pass paramters to FTFx */
<> 144:ef7eb2e8f9f7 727 kFCCOBx[0] = BYTES_JOIN_TO_WORD_1_1_2(FTFx_PROGRAM_ONCE, index, 0xFFFFU);
<> 144:ef7eb2e8f9f7 728
<> 144:ef7eb2e8f9f7 729 kFCCOBx[1] = *src;
<> 144:ef7eb2e8f9f7 730
<> 144:ef7eb2e8f9f7 731 /* Note: Have to seperate the first index from the rest if it equals 0
<> 144:ef7eb2e8f9f7 732 * to avoid a pointless comparison of unsigned int to 0 compiler warning */
<> 144:ef7eb2e8f9f7 733 #if FLASH_PROGRAM_ONCE_IS_8BYTES_UNIT_SUPPORT
<> 144:ef7eb2e8f9f7 734 #if FLASH_PROGRAM_ONCE_IS_4BYTES_UNIT_SUPPORT
<> 144:ef7eb2e8f9f7 735 if (((index == FLASH_PROGRAM_ONCE_MIN_ID_8BYTES) ||
<> 144:ef7eb2e8f9f7 736 /* Range check */
<> 144:ef7eb2e8f9f7 737 ((index >= FLASH_PROGRAM_ONCE_MIN_ID_8BYTES + 1) && (index <= FLASH_PROGRAM_ONCE_MAX_ID_8BYTES))) &&
<> 144:ef7eb2e8f9f7 738 (lengthInBytes == 8))
<> 144:ef7eb2e8f9f7 739 #endif /* FLASH_PROGRAM_ONCE_IS_4BYTES_UNIT_SUPPORT */
<> 144:ef7eb2e8f9f7 740 {
<> 144:ef7eb2e8f9f7 741 kFCCOBx[2] = *(src + 1);
<> 144:ef7eb2e8f9f7 742 }
<> 144:ef7eb2e8f9f7 743 #endif /* FLASH_PROGRAM_ONCE_IS_8BYTES_UNIT_SUPPORT */
<> 144:ef7eb2e8f9f7 744
<> 144:ef7eb2e8f9f7 745 /* calling flash command sequence function to execute the command */
<> 144:ef7eb2e8f9f7 746 returnCode = flash_command_sequence(config);
<> 144:ef7eb2e8f9f7 747
<> 144:ef7eb2e8f9f7 748 flash_cache_clear(config);
<> 144:ef7eb2e8f9f7 749
<> 144:ef7eb2e8f9f7 750 return returnCode;
<> 144:ef7eb2e8f9f7 751 }
<> 144:ef7eb2e8f9f7 752
<> 144:ef7eb2e8f9f7 753 #if defined(FSL_FEATURE_FLASH_HAS_PROGRAM_SECTION_CMD) && FSL_FEATURE_FLASH_HAS_PROGRAM_SECTION_CMD
<> 144:ef7eb2e8f9f7 754 status_t FLASH_ProgramSection(flash_config_t *config, uint32_t start, uint32_t *src, uint32_t lengthInBytes)
<> 144:ef7eb2e8f9f7 755 {
<> 144:ef7eb2e8f9f7 756 status_t returnCode;
<> 144:ef7eb2e8f9f7 757 uint32_t sectorSize;
<> 144:ef7eb2e8f9f7 758 flash_operation_config_t flashInfo;
<> 144:ef7eb2e8f9f7 759 #if defined(FSL_FEATURE_FLASH_HAS_SET_FLEXRAM_FUNCTION_CMD) && FSL_FEATURE_FLASH_HAS_SET_FLEXRAM_FUNCTION_CMD
<> 144:ef7eb2e8f9f7 760 bool needSwitchFlexRamMode = false;
<> 144:ef7eb2e8f9f7 761 #endif /* FSL_FEATURE_FLASH_HAS_SET_FLEXRAM_FUNCTION_CMD */
<> 144:ef7eb2e8f9f7 762
<> 144:ef7eb2e8f9f7 763 if (src == NULL)
<> 144:ef7eb2e8f9f7 764 {
<> 144:ef7eb2e8f9f7 765 return kStatus_FLASH_InvalidArgument;
<> 144:ef7eb2e8f9f7 766 }
<> 144:ef7eb2e8f9f7 767
<> 144:ef7eb2e8f9f7 768 flash_get_matched_operation_info(config, start, &flashInfo);
<> 144:ef7eb2e8f9f7 769
<> 144:ef7eb2e8f9f7 770 /* Check the supplied address range. */
<> 144:ef7eb2e8f9f7 771 returnCode = flash_check_range(config, start, lengthInBytes, flashInfo.sectionCmdAddressAligment);
<> 144:ef7eb2e8f9f7 772 if (returnCode)
<> 144:ef7eb2e8f9f7 773 {
<> 144:ef7eb2e8f9f7 774 return returnCode;
<> 144:ef7eb2e8f9f7 775 }
<> 144:ef7eb2e8f9f7 776
<> 144:ef7eb2e8f9f7 777 start = flashInfo.convertedAddress;
<> 144:ef7eb2e8f9f7 778 sectorSize = flashInfo.activeSectorSize;
<> 144:ef7eb2e8f9f7 779
<> 144:ef7eb2e8f9f7 780 #if defined(FSL_FEATURE_FLASH_HAS_SET_FLEXRAM_FUNCTION_CMD) && FSL_FEATURE_FLASH_HAS_SET_FLEXRAM_FUNCTION_CMD
<> 144:ef7eb2e8f9f7 781 /* Switch function of FlexRAM if needed */
<> 144:ef7eb2e8f9f7 782 if (!(FTFx->FCNFG & FTFx_FCNFG_RAMRDY_MASK))
<> 144:ef7eb2e8f9f7 783 {
<> 144:ef7eb2e8f9f7 784 needSwitchFlexRamMode = true;
<> 144:ef7eb2e8f9f7 785
<> 144:ef7eb2e8f9f7 786 returnCode = FLASH_SetFlexramFunction(config, kFLASH_flexramFunctionOptionAvailableAsRam);
<> 144:ef7eb2e8f9f7 787 if (returnCode != kStatus_FLASH_Success)
<> 144:ef7eb2e8f9f7 788 {
<> 144:ef7eb2e8f9f7 789 return kStatus_FLASH_SetFlexramAsRamError;
<> 144:ef7eb2e8f9f7 790 }
<> 144:ef7eb2e8f9f7 791 }
<> 144:ef7eb2e8f9f7 792 #endif /* FSL_FEATURE_FLASH_HAS_SET_FLEXRAM_FUNCTION_CMD */
<> 144:ef7eb2e8f9f7 793
<> 144:ef7eb2e8f9f7 794 while (lengthInBytes > 0)
<> 144:ef7eb2e8f9f7 795 {
<> 144:ef7eb2e8f9f7 796 /* Make sure the write operation doesn't span two sectors */
<> 144:ef7eb2e8f9f7 797 uint32_t endAddressOfCurrentSector = ALIGN_UP(start, sectorSize);
<> 144:ef7eb2e8f9f7 798 uint32_t lengthTobeProgrammedOfCurrentSector;
<> 144:ef7eb2e8f9f7 799 uint32_t currentOffset = 0;
<> 144:ef7eb2e8f9f7 800
<> 144:ef7eb2e8f9f7 801 if (endAddressOfCurrentSector == start)
<> 144:ef7eb2e8f9f7 802 {
<> 144:ef7eb2e8f9f7 803 endAddressOfCurrentSector += sectorSize;
<> 144:ef7eb2e8f9f7 804 }
<> 144:ef7eb2e8f9f7 805
<> 144:ef7eb2e8f9f7 806 if (lengthInBytes + start > endAddressOfCurrentSector)
<> 144:ef7eb2e8f9f7 807 {
<> 144:ef7eb2e8f9f7 808 lengthTobeProgrammedOfCurrentSector = endAddressOfCurrentSector - start;
<> 144:ef7eb2e8f9f7 809 }
<> 144:ef7eb2e8f9f7 810 else
<> 144:ef7eb2e8f9f7 811 {
<> 144:ef7eb2e8f9f7 812 lengthTobeProgrammedOfCurrentSector = lengthInBytes;
<> 144:ef7eb2e8f9f7 813 }
<> 144:ef7eb2e8f9f7 814
<> 144:ef7eb2e8f9f7 815 /* Program Current Sector */
<> 144:ef7eb2e8f9f7 816 while (lengthTobeProgrammedOfCurrentSector > 0)
<> 144:ef7eb2e8f9f7 817 {
<> 144:ef7eb2e8f9f7 818 /* Make sure the program size doesn't exceeds Acceleration RAM size */
<> 144:ef7eb2e8f9f7 819 uint32_t programSizeOfCurrentPass;
<> 144:ef7eb2e8f9f7 820 uint32_t numberOfPhases;
<> 144:ef7eb2e8f9f7 821
<> 144:ef7eb2e8f9f7 822 if (lengthTobeProgrammedOfCurrentSector > kFLASH_accelerationRamSize)
<> 144:ef7eb2e8f9f7 823 {
<> 144:ef7eb2e8f9f7 824 programSizeOfCurrentPass = kFLASH_accelerationRamSize;
<> 144:ef7eb2e8f9f7 825 }
<> 144:ef7eb2e8f9f7 826 else
<> 144:ef7eb2e8f9f7 827 {
<> 144:ef7eb2e8f9f7 828 programSizeOfCurrentPass = lengthTobeProgrammedOfCurrentSector;
<> 144:ef7eb2e8f9f7 829 }
<> 144:ef7eb2e8f9f7 830
<> 144:ef7eb2e8f9f7 831 /* Copy data to FlexRAM */
<> 144:ef7eb2e8f9f7 832 memcpy((void *)FSL_FEATURE_FLASH_FLEX_RAM_START_ADDRESS, src + currentOffset / 4, programSizeOfCurrentPass);
<> 144:ef7eb2e8f9f7 833 /* Set start address of the data to be programmed */
<> 144:ef7eb2e8f9f7 834 kFCCOBx[0] = BYTES_JOIN_TO_WORD_1_3(FTFx_PROGRAM_SECTION, start + currentOffset);
<> 144:ef7eb2e8f9f7 835 /* Set program size in terms of FEATURE_FLASH_SECTION_CMD_ADDRESS_ALIGMENT */
<> 144:ef7eb2e8f9f7 836 numberOfPhases = programSizeOfCurrentPass / flashInfo.sectionCmdAddressAligment;
<> 144:ef7eb2e8f9f7 837
<> 144:ef7eb2e8f9f7 838 kFCCOBx[1] = BYTES_JOIN_TO_WORD_2_2(numberOfPhases, 0xFFFFU);
<> 144:ef7eb2e8f9f7 839
<> 144:ef7eb2e8f9f7 840 /* Peform command sequence */
<> 144:ef7eb2e8f9f7 841 returnCode = flash_command_sequence(config);
<> 144:ef7eb2e8f9f7 842
<> 144:ef7eb2e8f9f7 843 /* calling flash callback function if it is available */
<> 144:ef7eb2e8f9f7 844 if (config->PFlashCallback)
<> 144:ef7eb2e8f9f7 845 {
<> 144:ef7eb2e8f9f7 846 config->PFlashCallback();
<> 144:ef7eb2e8f9f7 847 }
<> 144:ef7eb2e8f9f7 848
<> 144:ef7eb2e8f9f7 849 if (returnCode != kStatus_FLASH_Success)
<> 144:ef7eb2e8f9f7 850 {
<> 144:ef7eb2e8f9f7 851 flash_cache_clear(config);
<> 144:ef7eb2e8f9f7 852 return returnCode;
<> 144:ef7eb2e8f9f7 853 }
<> 144:ef7eb2e8f9f7 854
<> 144:ef7eb2e8f9f7 855 lengthTobeProgrammedOfCurrentSector -= programSizeOfCurrentPass;
<> 144:ef7eb2e8f9f7 856 currentOffset += programSizeOfCurrentPass;
<> 144:ef7eb2e8f9f7 857 }
<> 144:ef7eb2e8f9f7 858
<> 144:ef7eb2e8f9f7 859 src += currentOffset / 4;
<> 144:ef7eb2e8f9f7 860 start += currentOffset;
<> 144:ef7eb2e8f9f7 861 lengthInBytes -= currentOffset;
<> 144:ef7eb2e8f9f7 862 }
<> 144:ef7eb2e8f9f7 863
<> 144:ef7eb2e8f9f7 864 flash_cache_clear(config);
<> 144:ef7eb2e8f9f7 865
<> 144:ef7eb2e8f9f7 866 #if defined(FSL_FEATURE_FLASH_HAS_SET_FLEXRAM_FUNCTION_CMD) && FSL_FEATURE_FLASH_HAS_SET_FLEXRAM_FUNCTION_CMD
<> 144:ef7eb2e8f9f7 867 /* Restore function of FlexRAM if needed. */
<> 144:ef7eb2e8f9f7 868 if (needSwitchFlexRamMode)
<> 144:ef7eb2e8f9f7 869 {
<> 144:ef7eb2e8f9f7 870 returnCode = FLASH_SetFlexramFunction(config, kFLASH_flexramFunctionOptionAvailableForEeprom);
<> 144:ef7eb2e8f9f7 871 if (returnCode != kStatus_FLASH_Success)
<> 144:ef7eb2e8f9f7 872 {
<> 144:ef7eb2e8f9f7 873 return kStatus_FLASH_RecoverFlexramAsEepromError;
<> 144:ef7eb2e8f9f7 874 }
<> 144:ef7eb2e8f9f7 875 }
<> 144:ef7eb2e8f9f7 876 #endif /* FSL_FEATURE_FLASH_HAS_SET_FLEXRAM_FUNCTION_CMD */
<> 144:ef7eb2e8f9f7 877
<> 144:ef7eb2e8f9f7 878 return returnCode;
<> 144:ef7eb2e8f9f7 879 }
<> 144:ef7eb2e8f9f7 880 #endif /* FSL_FEATURE_FLASH_HAS_PROGRAM_SECTION_CMD */
<> 144:ef7eb2e8f9f7 881
<> 144:ef7eb2e8f9f7 882 #if FLASH_SSD_IS_FLEXNVM_ENABLED
<> 144:ef7eb2e8f9f7 883 status_t FLASH_EepromWrite(flash_config_t *config, uint32_t start, uint8_t *src, uint32_t lengthInBytes)
<> 144:ef7eb2e8f9f7 884 {
<> 144:ef7eb2e8f9f7 885 status_t returnCode;
<> 144:ef7eb2e8f9f7 886 bool needSwitchFlexRamMode = false;
<> 144:ef7eb2e8f9f7 887
<> 144:ef7eb2e8f9f7 888 if (config == NULL)
<> 144:ef7eb2e8f9f7 889 {
<> 144:ef7eb2e8f9f7 890 return kStatus_FLASH_InvalidArgument;
<> 144:ef7eb2e8f9f7 891 }
<> 144:ef7eb2e8f9f7 892
<> 144:ef7eb2e8f9f7 893 /* Validates the range of the given address */
<> 144:ef7eb2e8f9f7 894 if ((start < config->FlexRAMBlockBase) ||
<> 144:ef7eb2e8f9f7 895 ((start + lengthInBytes) > (config->FlexRAMBlockBase + config->EEpromTotalSize)))
<> 144:ef7eb2e8f9f7 896 {
<> 144:ef7eb2e8f9f7 897 return kStatus_FLASH_AddressError;
<> 144:ef7eb2e8f9f7 898 }
<> 144:ef7eb2e8f9f7 899
<> 144:ef7eb2e8f9f7 900 returnCode = kStatus_FLASH_Success;
<> 144:ef7eb2e8f9f7 901
<> 144:ef7eb2e8f9f7 902 /* Switch function of FlexRAM if needed */
<> 144:ef7eb2e8f9f7 903 if (!(FTFx->FCNFG & FTFx_FCNFG_EEERDY_MASK))
<> 144:ef7eb2e8f9f7 904 {
<> 144:ef7eb2e8f9f7 905 needSwitchFlexRamMode = true;
<> 144:ef7eb2e8f9f7 906
<> 144:ef7eb2e8f9f7 907 returnCode = FLASH_SetFlexramFunction(config, kFLASH_flexramFunctionOptionAvailableForEeprom);
<> 144:ef7eb2e8f9f7 908 if (returnCode != kStatus_FLASH_Success)
<> 144:ef7eb2e8f9f7 909 {
<> 144:ef7eb2e8f9f7 910 return kStatus_FLASH_SetFlexramAsEepromError;
<> 144:ef7eb2e8f9f7 911 }
<> 144:ef7eb2e8f9f7 912 }
<> 144:ef7eb2e8f9f7 913
<> 144:ef7eb2e8f9f7 914 /* Write data to FlexRAM when it is used as EEPROM emulator */
<> 144:ef7eb2e8f9f7 915 while (lengthInBytes > 0)
<> 144:ef7eb2e8f9f7 916 {
<> 144:ef7eb2e8f9f7 917 if ((!(start & 0x3U)) && (lengthInBytes >= 4))
<> 144:ef7eb2e8f9f7 918 {
<> 144:ef7eb2e8f9f7 919 *(uint32_t *)start = *(uint32_t *)src;
<> 144:ef7eb2e8f9f7 920 start += 4;
<> 144:ef7eb2e8f9f7 921 src += 4;
<> 144:ef7eb2e8f9f7 922 lengthInBytes -= 4;
<> 144:ef7eb2e8f9f7 923 }
<> 144:ef7eb2e8f9f7 924 else if ((!(start & 0x1U)) && (lengthInBytes >= 2))
<> 144:ef7eb2e8f9f7 925 {
<> 144:ef7eb2e8f9f7 926 *(uint16_t *)start = *(uint16_t *)src;
<> 144:ef7eb2e8f9f7 927 start += 2;
<> 144:ef7eb2e8f9f7 928 src += 2;
<> 144:ef7eb2e8f9f7 929 lengthInBytes -= 2;
<> 144:ef7eb2e8f9f7 930 }
<> 144:ef7eb2e8f9f7 931 else
<> 144:ef7eb2e8f9f7 932 {
<> 144:ef7eb2e8f9f7 933 *(uint8_t *)start = *src;
<> 144:ef7eb2e8f9f7 934 start += 1;
<> 144:ef7eb2e8f9f7 935 src += 1;
<> 144:ef7eb2e8f9f7 936 lengthInBytes -= 1;
<> 144:ef7eb2e8f9f7 937 }
<> 144:ef7eb2e8f9f7 938 /* Wait till EEERDY bit is set */
<> 144:ef7eb2e8f9f7 939 while (!(FTFx->FCNFG & FTFx_FCNFG_EEERDY_MASK))
<> 144:ef7eb2e8f9f7 940 {
<> 144:ef7eb2e8f9f7 941 }
<> 144:ef7eb2e8f9f7 942
<> 144:ef7eb2e8f9f7 943 /* Check for protection violation error */
<> 144:ef7eb2e8f9f7 944 if (FTFx->FSTAT & FTFx_FSTAT_FPVIOL_MASK)
<> 144:ef7eb2e8f9f7 945 {
<> 144:ef7eb2e8f9f7 946 return kStatus_FLASH_ProtectionViolation;
<> 144:ef7eb2e8f9f7 947 }
<> 144:ef7eb2e8f9f7 948 }
<> 144:ef7eb2e8f9f7 949
<> 144:ef7eb2e8f9f7 950 /* Switch function of FlexRAM if needed */
<> 144:ef7eb2e8f9f7 951 if (needSwitchFlexRamMode)
<> 144:ef7eb2e8f9f7 952 {
<> 144:ef7eb2e8f9f7 953 returnCode = FLASH_SetFlexramFunction(config, kFLASH_flexramFunctionOptionAvailableAsRam);
<> 144:ef7eb2e8f9f7 954 if (returnCode != kStatus_FLASH_Success)
<> 144:ef7eb2e8f9f7 955 {
<> 144:ef7eb2e8f9f7 956 return kStatus_FLASH_RecoverFlexramAsRamError;
<> 144:ef7eb2e8f9f7 957 }
<> 144:ef7eb2e8f9f7 958 }
<> 144:ef7eb2e8f9f7 959
<> 144:ef7eb2e8f9f7 960 return returnCode;
<> 144:ef7eb2e8f9f7 961 }
<> 144:ef7eb2e8f9f7 962 #endif /* FLASH_SSD_IS_FLEXNVM_ENABLED */
<> 144:ef7eb2e8f9f7 963
<> 144:ef7eb2e8f9f7 964 #if defined(FSL_FEATURE_FLASH_HAS_READ_RESOURCE_CMD) && FSL_FEATURE_FLASH_HAS_READ_RESOURCE_CMD
<> 144:ef7eb2e8f9f7 965 status_t FLASH_ReadResource(
<> 144:ef7eb2e8f9f7 966 flash_config_t *config, uint32_t start, uint32_t *dst, uint32_t lengthInBytes, flash_read_resource_option_t option)
<> 144:ef7eb2e8f9f7 967 {
<> 144:ef7eb2e8f9f7 968 status_t returnCode;
<> 144:ef7eb2e8f9f7 969 flash_operation_config_t flashInfo;
<> 144:ef7eb2e8f9f7 970
<> 144:ef7eb2e8f9f7 971 if ((config == NULL) || (dst == NULL))
<> 144:ef7eb2e8f9f7 972 {
<> 144:ef7eb2e8f9f7 973 return kStatus_FLASH_InvalidArgument;
<> 144:ef7eb2e8f9f7 974 }
<> 144:ef7eb2e8f9f7 975
<> 144:ef7eb2e8f9f7 976 flash_get_matched_operation_info(config, start, &flashInfo);
<> 144:ef7eb2e8f9f7 977
<> 144:ef7eb2e8f9f7 978 /* Check the supplied address range. */
<> 144:ef7eb2e8f9f7 979 returnCode = flash_check_resource_range(start, lengthInBytes, flashInfo.resourceCmdAddressAligment, option);
<> 144:ef7eb2e8f9f7 980 if (returnCode != kStatus_FLASH_Success)
<> 144:ef7eb2e8f9f7 981 {
<> 144:ef7eb2e8f9f7 982 return returnCode;
<> 144:ef7eb2e8f9f7 983 }
<> 144:ef7eb2e8f9f7 984
<> 144:ef7eb2e8f9f7 985 while (lengthInBytes > 0)
<> 144:ef7eb2e8f9f7 986 {
<> 144:ef7eb2e8f9f7 987 /* preparing passing parameter */
<> 144:ef7eb2e8f9f7 988 kFCCOBx[0] = BYTES_JOIN_TO_WORD_1_3(FTFx_READ_RESOURCE, start);
<> 144:ef7eb2e8f9f7 989 if (flashInfo.resourceCmdAddressAligment == 4)
<> 144:ef7eb2e8f9f7 990 {
<> 144:ef7eb2e8f9f7 991 kFCCOBx[2] = BYTES_JOIN_TO_WORD_1_3(option, 0xFFFFFFU);
<> 144:ef7eb2e8f9f7 992 }
<> 144:ef7eb2e8f9f7 993 else if (flashInfo.resourceCmdAddressAligment == 8)
<> 144:ef7eb2e8f9f7 994 {
<> 144:ef7eb2e8f9f7 995 kFCCOBx[1] = BYTES_JOIN_TO_WORD_1_3(option, 0xFFFFFFU);
<> 144:ef7eb2e8f9f7 996 }
<> 144:ef7eb2e8f9f7 997 else
<> 144:ef7eb2e8f9f7 998 {
<> 144:ef7eb2e8f9f7 999 }
<> 144:ef7eb2e8f9f7 1000
<> 144:ef7eb2e8f9f7 1001 /* calling flash command sequence function to execute the command */
<> 144:ef7eb2e8f9f7 1002 returnCode = flash_command_sequence(config);
<> 144:ef7eb2e8f9f7 1003
<> 144:ef7eb2e8f9f7 1004 if (kStatus_FLASH_Success != returnCode)
<> 144:ef7eb2e8f9f7 1005 {
<> 144:ef7eb2e8f9f7 1006 break;
<> 144:ef7eb2e8f9f7 1007 }
<> 144:ef7eb2e8f9f7 1008
<> 144:ef7eb2e8f9f7 1009 /* fetch data */
<> 144:ef7eb2e8f9f7 1010 *dst++ = kFCCOBx[1];
<> 144:ef7eb2e8f9f7 1011 if (flashInfo.resourceCmdAddressAligment == 8)
<> 144:ef7eb2e8f9f7 1012 {
<> 144:ef7eb2e8f9f7 1013 *dst++ = kFCCOBx[2];
<> 144:ef7eb2e8f9f7 1014 }
<> 144:ef7eb2e8f9f7 1015 /* update start address for next iteration */
<> 144:ef7eb2e8f9f7 1016 start += flashInfo.resourceCmdAddressAligment;
<> 144:ef7eb2e8f9f7 1017 /* update lengthInBytes for next iteration */
<> 144:ef7eb2e8f9f7 1018 lengthInBytes -= flashInfo.resourceCmdAddressAligment;
<> 144:ef7eb2e8f9f7 1019 }
<> 144:ef7eb2e8f9f7 1020
<> 144:ef7eb2e8f9f7 1021 return (returnCode);
<> 144:ef7eb2e8f9f7 1022 }
<> 144:ef7eb2e8f9f7 1023 #endif /* FSL_FEATURE_FLASH_HAS_READ_RESOURCE_CMD */
<> 144:ef7eb2e8f9f7 1024
<> 144:ef7eb2e8f9f7 1025 status_t FLASH_ReadOnce(flash_config_t *config, uint32_t index, uint32_t *dst, uint32_t lengthInBytes)
<> 144:ef7eb2e8f9f7 1026 {
<> 144:ef7eb2e8f9f7 1027 status_t returnCode;
<> 144:ef7eb2e8f9f7 1028
<> 144:ef7eb2e8f9f7 1029 if ((config == NULL) || (dst == NULL))
<> 144:ef7eb2e8f9f7 1030 {
<> 144:ef7eb2e8f9f7 1031 return kStatus_FLASH_InvalidArgument;
<> 144:ef7eb2e8f9f7 1032 }
<> 144:ef7eb2e8f9f7 1033
<> 144:ef7eb2e8f9f7 1034 /* pass paramters to FTFx */
<> 144:ef7eb2e8f9f7 1035 kFCCOBx[0] = BYTES_JOIN_TO_WORD_1_1_2(FTFx_READ_ONCE, index, 0xFFFFU);
<> 144:ef7eb2e8f9f7 1036
<> 144:ef7eb2e8f9f7 1037 /* calling flash command sequence function to execute the command */
<> 144:ef7eb2e8f9f7 1038 returnCode = flash_command_sequence(config);
<> 144:ef7eb2e8f9f7 1039
<> 144:ef7eb2e8f9f7 1040 if (kStatus_FLASH_Success == returnCode)
<> 144:ef7eb2e8f9f7 1041 {
<> 144:ef7eb2e8f9f7 1042 *dst = kFCCOBx[1];
<> 144:ef7eb2e8f9f7 1043 /* Note: Have to seperate the first index from the rest if it equals 0
<> 144:ef7eb2e8f9f7 1044 * to avoid a pointless comparison of unsigned int to 0 compiler warning */
<> 144:ef7eb2e8f9f7 1045 #if FLASH_PROGRAM_ONCE_IS_8BYTES_UNIT_SUPPORT
<> 144:ef7eb2e8f9f7 1046 #if FLASH_PROGRAM_ONCE_IS_4BYTES_UNIT_SUPPORT
<> 144:ef7eb2e8f9f7 1047 if (((index == FLASH_PROGRAM_ONCE_MIN_ID_8BYTES) ||
<> 144:ef7eb2e8f9f7 1048 /* Range check */
<> 144:ef7eb2e8f9f7 1049 ((index >= FLASH_PROGRAM_ONCE_MIN_ID_8BYTES + 1) && (index <= FLASH_PROGRAM_ONCE_MAX_ID_8BYTES))) &&
<> 144:ef7eb2e8f9f7 1050 (lengthInBytes == 8))
<> 144:ef7eb2e8f9f7 1051 #endif /* FLASH_PROGRAM_ONCE_IS_4BYTES_UNIT_SUPPORT */
<> 144:ef7eb2e8f9f7 1052 {
<> 144:ef7eb2e8f9f7 1053 *(dst + 1) = kFCCOBx[2];
<> 144:ef7eb2e8f9f7 1054 }
<> 144:ef7eb2e8f9f7 1055 #endif /* FLASH_PROGRAM_ONCE_IS_8BYTES_UNIT_SUPPORT */
<> 144:ef7eb2e8f9f7 1056 }
<> 144:ef7eb2e8f9f7 1057
<> 144:ef7eb2e8f9f7 1058 return returnCode;
<> 144:ef7eb2e8f9f7 1059 }
<> 144:ef7eb2e8f9f7 1060
<> 144:ef7eb2e8f9f7 1061 status_t FLASH_GetSecurityState(flash_config_t *config, flash_security_state_t *state)
<> 144:ef7eb2e8f9f7 1062 {
<> 144:ef7eb2e8f9f7 1063 /* store data read from flash register */
<> 144:ef7eb2e8f9f7 1064 uint8_t registerValue;
<> 144:ef7eb2e8f9f7 1065
<> 144:ef7eb2e8f9f7 1066 if ((config == NULL) || (state == NULL))
<> 144:ef7eb2e8f9f7 1067 {
<> 144:ef7eb2e8f9f7 1068 return kStatus_FLASH_InvalidArgument;
<> 144:ef7eb2e8f9f7 1069 }
<> 144:ef7eb2e8f9f7 1070
<> 144:ef7eb2e8f9f7 1071 /* Get flash security register value */
<> 144:ef7eb2e8f9f7 1072 registerValue = FTFx->FSEC;
<> 144:ef7eb2e8f9f7 1073
<> 144:ef7eb2e8f9f7 1074 /* check the status of the flash security bits in the security register */
<> 144:ef7eb2e8f9f7 1075 if (FLASH_SECURITY_STATE_UNSECURED == (registerValue & FTFx_FSEC_SEC_MASK))
<> 144:ef7eb2e8f9f7 1076 {
<> 144:ef7eb2e8f9f7 1077 /* Flash in unsecured state */
<> 144:ef7eb2e8f9f7 1078 *state = kFLASH_securityStateNotSecure;
<> 144:ef7eb2e8f9f7 1079 }
<> 144:ef7eb2e8f9f7 1080 else
<> 144:ef7eb2e8f9f7 1081 {
<> 144:ef7eb2e8f9f7 1082 /* Flash in secured state
<> 144:ef7eb2e8f9f7 1083 * check for backdoor key security enable bit */
<> 144:ef7eb2e8f9f7 1084 if (FLASH_SECURITY_STATE_KEYEN == (registerValue & FTFx_FSEC_KEYEN_MASK))
<> 144:ef7eb2e8f9f7 1085 {
<> 144:ef7eb2e8f9f7 1086 /* Backdoor key security enabled */
<> 144:ef7eb2e8f9f7 1087 *state = kFLASH_securityStateBackdoorEnabled;
<> 144:ef7eb2e8f9f7 1088 }
<> 144:ef7eb2e8f9f7 1089 else
<> 144:ef7eb2e8f9f7 1090 {
<> 144:ef7eb2e8f9f7 1091 /* Backdoor key security disabled */
<> 144:ef7eb2e8f9f7 1092 *state = kFLASH_securityStateBackdoorDisabled;
<> 144:ef7eb2e8f9f7 1093 }
<> 144:ef7eb2e8f9f7 1094 }
<> 144:ef7eb2e8f9f7 1095
<> 144:ef7eb2e8f9f7 1096 return (kStatus_FLASH_Success);
<> 144:ef7eb2e8f9f7 1097 }
<> 144:ef7eb2e8f9f7 1098
<> 144:ef7eb2e8f9f7 1099 status_t FLASH_SecurityBypass(flash_config_t *config, const uint8_t *backdoorKey)
<> 144:ef7eb2e8f9f7 1100 {
<> 144:ef7eb2e8f9f7 1101 uint8_t registerValue; /* registerValue */
<> 144:ef7eb2e8f9f7 1102 status_t returnCode; /* return code variable */
<> 144:ef7eb2e8f9f7 1103
<> 144:ef7eb2e8f9f7 1104 if ((config == NULL) || (backdoorKey == NULL))
<> 144:ef7eb2e8f9f7 1105 {
<> 144:ef7eb2e8f9f7 1106 return kStatus_FLASH_InvalidArgument;
<> 144:ef7eb2e8f9f7 1107 }
<> 144:ef7eb2e8f9f7 1108
<> 144:ef7eb2e8f9f7 1109 /* set the default return code as kStatus_Success */
<> 144:ef7eb2e8f9f7 1110 returnCode = kStatus_FLASH_Success;
<> 144:ef7eb2e8f9f7 1111
<> 144:ef7eb2e8f9f7 1112 /* Get flash security register value */
<> 144:ef7eb2e8f9f7 1113 registerValue = FTFx->FSEC;
<> 144:ef7eb2e8f9f7 1114
<> 144:ef7eb2e8f9f7 1115 /* Check to see if flash is in secure state (any state other than 0x2)
<> 144:ef7eb2e8f9f7 1116 * If not, then skip this since flash is not secure */
<> 144:ef7eb2e8f9f7 1117 if (0x02 != (registerValue & 0x03))
<> 144:ef7eb2e8f9f7 1118 {
<> 144:ef7eb2e8f9f7 1119 /* preparing passing parameter to erase a flash block */
<> 144:ef7eb2e8f9f7 1120 kFCCOBx[0] = BYTES_JOIN_TO_WORD_1_3(FTFx_SECURITY_BY_PASS, 0xFFFFFFU);
<> 144:ef7eb2e8f9f7 1121 kFCCOBx[1] = BYTES_JOIN_TO_WORD_1_1_1_1(backdoorKey[0], backdoorKey[1], backdoorKey[2], backdoorKey[3]);
<> 144:ef7eb2e8f9f7 1122 kFCCOBx[2] = BYTES_JOIN_TO_WORD_1_1_1_1(backdoorKey[4], backdoorKey[5], backdoorKey[6], backdoorKey[7]);
<> 144:ef7eb2e8f9f7 1123
<> 144:ef7eb2e8f9f7 1124 /* calling flash command sequence function to execute the command */
<> 144:ef7eb2e8f9f7 1125 returnCode = flash_command_sequence(config);
<> 144:ef7eb2e8f9f7 1126 }
<> 144:ef7eb2e8f9f7 1127
<> 144:ef7eb2e8f9f7 1128 return (returnCode);
<> 144:ef7eb2e8f9f7 1129 }
<> 144:ef7eb2e8f9f7 1130
<> 144:ef7eb2e8f9f7 1131 status_t FLASH_VerifyEraseAll(flash_config_t *config, flash_margin_value_t margin)
<> 144:ef7eb2e8f9f7 1132 {
<> 144:ef7eb2e8f9f7 1133 if (config == NULL)
<> 144:ef7eb2e8f9f7 1134 {
<> 144:ef7eb2e8f9f7 1135 return kStatus_FLASH_InvalidArgument;
<> 144:ef7eb2e8f9f7 1136 }
<> 144:ef7eb2e8f9f7 1137
<> 144:ef7eb2e8f9f7 1138 /* preparing passing parameter to verify all block command */
<> 144:ef7eb2e8f9f7 1139 kFCCOBx[0] = BYTES_JOIN_TO_WORD_1_1_2(FTFx_VERIFY_ALL_BLOCK, margin, 0xFFFFU);
<> 144:ef7eb2e8f9f7 1140
<> 144:ef7eb2e8f9f7 1141 /* calling flash command sequence function to execute the command */
<> 144:ef7eb2e8f9f7 1142 return flash_command_sequence(config);
<> 144:ef7eb2e8f9f7 1143 }
<> 144:ef7eb2e8f9f7 1144
<> 144:ef7eb2e8f9f7 1145 status_t FLASH_VerifyErase(flash_config_t *config, uint32_t start, uint32_t lengthInBytes, flash_margin_value_t margin)
<> 144:ef7eb2e8f9f7 1146 {
<> 144:ef7eb2e8f9f7 1147 /* Check arguments. */
<> 144:ef7eb2e8f9f7 1148 uint32_t blockSize;
<> 144:ef7eb2e8f9f7 1149 flash_operation_config_t flashInfo;
<> 144:ef7eb2e8f9f7 1150 uint32_t nextBlockStartAddress;
<> 144:ef7eb2e8f9f7 1151 uint32_t remainingBytes;
<> 144:ef7eb2e8f9f7 1152 status_t returnCode;
<> 144:ef7eb2e8f9f7 1153
<> 144:ef7eb2e8f9f7 1154 flash_get_matched_operation_info(config, start, &flashInfo);
<> 144:ef7eb2e8f9f7 1155
<> 144:ef7eb2e8f9f7 1156 returnCode = flash_check_range(config, start, lengthInBytes, flashInfo.sectionCmdAddressAligment);
<> 144:ef7eb2e8f9f7 1157 if (returnCode)
<> 144:ef7eb2e8f9f7 1158 {
<> 144:ef7eb2e8f9f7 1159 return returnCode;
<> 144:ef7eb2e8f9f7 1160 }
<> 144:ef7eb2e8f9f7 1161
<> 144:ef7eb2e8f9f7 1162 flash_get_matched_operation_info(config, start, &flashInfo);
<> 144:ef7eb2e8f9f7 1163 start = flashInfo.convertedAddress;
<> 144:ef7eb2e8f9f7 1164 blockSize = flashInfo.activeBlockSize;
<> 144:ef7eb2e8f9f7 1165
<> 144:ef7eb2e8f9f7 1166 nextBlockStartAddress = ALIGN_UP(start, blockSize);
<> 144:ef7eb2e8f9f7 1167 if (nextBlockStartAddress == start)
<> 144:ef7eb2e8f9f7 1168 {
<> 144:ef7eb2e8f9f7 1169 nextBlockStartAddress += blockSize;
<> 144:ef7eb2e8f9f7 1170 }
<> 144:ef7eb2e8f9f7 1171
<> 144:ef7eb2e8f9f7 1172 remainingBytes = lengthInBytes;
<> 144:ef7eb2e8f9f7 1173
<> 144:ef7eb2e8f9f7 1174 while (remainingBytes)
<> 144:ef7eb2e8f9f7 1175 {
<> 144:ef7eb2e8f9f7 1176 uint32_t numberOfPhrases;
<> 144:ef7eb2e8f9f7 1177 uint32_t verifyLength = nextBlockStartAddress - start;
<> 144:ef7eb2e8f9f7 1178 if (verifyLength > remainingBytes)
<> 144:ef7eb2e8f9f7 1179 {
<> 144:ef7eb2e8f9f7 1180 verifyLength = remainingBytes;
<> 144:ef7eb2e8f9f7 1181 }
<> 144:ef7eb2e8f9f7 1182
<> 144:ef7eb2e8f9f7 1183 numberOfPhrases = verifyLength / flashInfo.sectionCmdAddressAligment;
<> 144:ef7eb2e8f9f7 1184
<> 144:ef7eb2e8f9f7 1185 /* Fill in verify section command parameters. */
<> 144:ef7eb2e8f9f7 1186 kFCCOBx[0] = BYTES_JOIN_TO_WORD_1_3(FTFx_VERIFY_SECTION, start);
<> 144:ef7eb2e8f9f7 1187 kFCCOBx[1] = BYTES_JOIN_TO_WORD_2_1_1(numberOfPhrases, margin, 0xFFU);
<> 144:ef7eb2e8f9f7 1188
<> 144:ef7eb2e8f9f7 1189 /* calling flash command sequence function to execute the command */
<> 144:ef7eb2e8f9f7 1190 returnCode = flash_command_sequence(config);
<> 144:ef7eb2e8f9f7 1191 if (returnCode)
<> 144:ef7eb2e8f9f7 1192 {
<> 144:ef7eb2e8f9f7 1193 return returnCode;
<> 144:ef7eb2e8f9f7 1194 }
<> 144:ef7eb2e8f9f7 1195
<> 144:ef7eb2e8f9f7 1196 remainingBytes -= verifyLength;
<> 144:ef7eb2e8f9f7 1197 start += verifyLength;
<> 144:ef7eb2e8f9f7 1198 nextBlockStartAddress += blockSize;
<> 144:ef7eb2e8f9f7 1199 }
<> 144:ef7eb2e8f9f7 1200
<> 144:ef7eb2e8f9f7 1201 return kStatus_FLASH_Success;
<> 144:ef7eb2e8f9f7 1202 }
<> 144:ef7eb2e8f9f7 1203
<> 144:ef7eb2e8f9f7 1204 status_t FLASH_VerifyProgram(flash_config_t *config,
<> 144:ef7eb2e8f9f7 1205 uint32_t start,
<> 144:ef7eb2e8f9f7 1206 uint32_t lengthInBytes,
<> 144:ef7eb2e8f9f7 1207 const uint32_t *expectedData,
<> 144:ef7eb2e8f9f7 1208 flash_margin_value_t margin,
<> 144:ef7eb2e8f9f7 1209 uint32_t *failedAddress,
<> 144:ef7eb2e8f9f7 1210 uint32_t *failedData)
<> 144:ef7eb2e8f9f7 1211 {
<> 144:ef7eb2e8f9f7 1212 status_t returnCode;
<> 144:ef7eb2e8f9f7 1213 flash_operation_config_t flashInfo;
<> 144:ef7eb2e8f9f7 1214
<> 144:ef7eb2e8f9f7 1215 if (expectedData == NULL)
<> 144:ef7eb2e8f9f7 1216 {
<> 144:ef7eb2e8f9f7 1217 return kStatus_FLASH_InvalidArgument;
<> 144:ef7eb2e8f9f7 1218 }
<> 144:ef7eb2e8f9f7 1219
<> 144:ef7eb2e8f9f7 1220 flash_get_matched_operation_info(config, start, &flashInfo);
<> 144:ef7eb2e8f9f7 1221
<> 144:ef7eb2e8f9f7 1222 returnCode = flash_check_range(config, start, lengthInBytes, flashInfo.checkCmdAddressAligment);
<> 144:ef7eb2e8f9f7 1223 if (returnCode)
<> 144:ef7eb2e8f9f7 1224 {
<> 144:ef7eb2e8f9f7 1225 return returnCode;
<> 144:ef7eb2e8f9f7 1226 }
<> 144:ef7eb2e8f9f7 1227
<> 144:ef7eb2e8f9f7 1228 start = flashInfo.convertedAddress;
<> 144:ef7eb2e8f9f7 1229
<> 144:ef7eb2e8f9f7 1230 while (lengthInBytes)
<> 144:ef7eb2e8f9f7 1231 {
<> 144:ef7eb2e8f9f7 1232 /* preparing passing parameter to program check the flash block */
<> 144:ef7eb2e8f9f7 1233 kFCCOBx[0] = BYTES_JOIN_TO_WORD_1_3(FTFx_PROGRAM_CHECK, start);
<> 144:ef7eb2e8f9f7 1234 kFCCOBx[1] = BYTES_JOIN_TO_WORD_1_3(margin, 0xFFFFFFU);
<> 144:ef7eb2e8f9f7 1235 kFCCOBx[2] = *expectedData;
<> 144:ef7eb2e8f9f7 1236
<> 144:ef7eb2e8f9f7 1237 /* calling flash command sequence function to execute the command */
<> 144:ef7eb2e8f9f7 1238 returnCode = flash_command_sequence(config);
<> 144:ef7eb2e8f9f7 1239
<> 144:ef7eb2e8f9f7 1240 /* checking for the success of command execution */
<> 144:ef7eb2e8f9f7 1241 if (kStatus_FLASH_Success != returnCode)
<> 144:ef7eb2e8f9f7 1242 {
<> 144:ef7eb2e8f9f7 1243 if (failedAddress)
<> 144:ef7eb2e8f9f7 1244 {
<> 144:ef7eb2e8f9f7 1245 *failedAddress = start;
<> 144:ef7eb2e8f9f7 1246 }
<> 144:ef7eb2e8f9f7 1247 if (failedData)
<> 144:ef7eb2e8f9f7 1248 {
<> 144:ef7eb2e8f9f7 1249 *failedData = 0;
<> 144:ef7eb2e8f9f7 1250 }
<> 144:ef7eb2e8f9f7 1251 break;
<> 144:ef7eb2e8f9f7 1252 }
<> 144:ef7eb2e8f9f7 1253
<> 144:ef7eb2e8f9f7 1254 lengthInBytes -= flashInfo.checkCmdAddressAligment;
<> 144:ef7eb2e8f9f7 1255 expectedData += flashInfo.checkCmdAddressAligment / sizeof(*expectedData);
<> 144:ef7eb2e8f9f7 1256 start += flashInfo.checkCmdAddressAligment;
<> 144:ef7eb2e8f9f7 1257 }
<> 144:ef7eb2e8f9f7 1258
<> 144:ef7eb2e8f9f7 1259 return (returnCode);
<> 144:ef7eb2e8f9f7 1260 }
<> 144:ef7eb2e8f9f7 1261
<> 144:ef7eb2e8f9f7 1262 status_t FLASH_VerifyEraseAllExecuteOnlySegments(flash_config_t *config, flash_margin_value_t margin)
<> 144:ef7eb2e8f9f7 1263 {
<> 144:ef7eb2e8f9f7 1264 if (config == NULL)
<> 144:ef7eb2e8f9f7 1265 {
<> 144:ef7eb2e8f9f7 1266 return kStatus_FLASH_InvalidArgument;
<> 144:ef7eb2e8f9f7 1267 }
<> 144:ef7eb2e8f9f7 1268
<> 144:ef7eb2e8f9f7 1269 /* preparing passing parameter to verify erase all execute-only segments command */
<> 144:ef7eb2e8f9f7 1270 kFCCOBx[0] = BYTES_JOIN_TO_WORD_1_1_2(FTFx_VERIFY_ALL_EXECUTE_ONLY_SEGMENT, margin, 0xFFFFU);
<> 144:ef7eb2e8f9f7 1271
<> 144:ef7eb2e8f9f7 1272 /* calling flash command sequence function to execute the command */
<> 144:ef7eb2e8f9f7 1273 return flash_command_sequence(config);
<> 144:ef7eb2e8f9f7 1274 }
<> 144:ef7eb2e8f9f7 1275
<> 144:ef7eb2e8f9f7 1276 status_t FLASH_IsProtected(flash_config_t *config,
<> 144:ef7eb2e8f9f7 1277 uint32_t start,
<> 144:ef7eb2e8f9f7 1278 uint32_t lengthInBytes,
<> 144:ef7eb2e8f9f7 1279 flash_protection_state_t *protection_state)
<> 144:ef7eb2e8f9f7 1280 {
<> 144:ef7eb2e8f9f7 1281 uint32_t endAddress; /* end address for protection check */
<> 144:ef7eb2e8f9f7 1282 uint32_t protectionRegionSize; /* size of flash protection region */
<> 144:ef7eb2e8f9f7 1283 uint32_t regionCheckedCounter; /* increments each time the flash address was checked for
<> 144:ef7eb2e8f9f7 1284 * protection status */
<> 144:ef7eb2e8f9f7 1285 uint32_t regionCounter; /* incrementing variable used to increment through the flash
<> 144:ef7eb2e8f9f7 1286 * protection regions */
<> 144:ef7eb2e8f9f7 1287 uint32_t protectStatusCounter; /* increments each time a flash region was detected as protected */
<> 144:ef7eb2e8f9f7 1288
<> 144:ef7eb2e8f9f7 1289 uint8_t flashRegionProtectStatus[FSL_FEATURE_FTFx_REGION_COUNT]; /* array of the protection status for each
<> 144:ef7eb2e8f9f7 1290 * protection region */
<> 144:ef7eb2e8f9f7 1291 uint32_t flashRegionAddress[FSL_FEATURE_FTFx_REGION_COUNT + 1]; /* array of the start addresses for each flash
<> 144:ef7eb2e8f9f7 1292 * protection region. Note this is REGION_COUNT+1
<> 144:ef7eb2e8f9f7 1293 * due to requiring the next start address after
<> 144:ef7eb2e8f9f7 1294 * the end of flash for loop-check purposes below */
<> 144:ef7eb2e8f9f7 1295 status_t returnCode;
<> 144:ef7eb2e8f9f7 1296
<> 144:ef7eb2e8f9f7 1297 if (protection_state == NULL)
<> 144:ef7eb2e8f9f7 1298 {
<> 144:ef7eb2e8f9f7 1299 return kStatus_FLASH_InvalidArgument;
<> 144:ef7eb2e8f9f7 1300 }
<> 144:ef7eb2e8f9f7 1301
<> 144:ef7eb2e8f9f7 1302 /* Check the supplied address range. */
<> 144:ef7eb2e8f9f7 1303 returnCode = flash_check_range(config, start, lengthInBytes, FSL_FEATURE_FLASH_PFLASH_BLOCK_WRITE_UNIT_SIZE);
<> 144:ef7eb2e8f9f7 1304 if (returnCode)
<> 144:ef7eb2e8f9f7 1305 {
<> 144:ef7eb2e8f9f7 1306 return returnCode;
<> 144:ef7eb2e8f9f7 1307 }
<> 144:ef7eb2e8f9f7 1308
<> 144:ef7eb2e8f9f7 1309 /* calculating Flash end address */
<> 144:ef7eb2e8f9f7 1310 endAddress = start + lengthInBytes;
<> 144:ef7eb2e8f9f7 1311
<> 144:ef7eb2e8f9f7 1312 /* Calculate the size of the flash protection region
<> 144:ef7eb2e8f9f7 1313 * If the flash density is > 32KB, then protection region is 1/32 of total flash density
<> 144:ef7eb2e8f9f7 1314 * Else if flash density is < 32KB, then flash protection region is set to 1KB */
<> 144:ef7eb2e8f9f7 1315 if (config->PFlashTotalSize > 32 * 1024)
<> 144:ef7eb2e8f9f7 1316 {
<> 144:ef7eb2e8f9f7 1317 protectionRegionSize = (config->PFlashTotalSize) / FSL_FEATURE_FTFx_REGION_COUNT;
<> 144:ef7eb2e8f9f7 1318 }
<> 144:ef7eb2e8f9f7 1319 else
<> 144:ef7eb2e8f9f7 1320 {
<> 144:ef7eb2e8f9f7 1321 protectionRegionSize = 1024;
<> 144:ef7eb2e8f9f7 1322 }
<> 144:ef7eb2e8f9f7 1323
<> 144:ef7eb2e8f9f7 1324 /* populate the flashRegionAddress array with the start address of each flash region */
<> 144:ef7eb2e8f9f7 1325 regionCounter = 0; /* make sure regionCounter is initialized to 0 first */
<> 144:ef7eb2e8f9f7 1326
<> 144:ef7eb2e8f9f7 1327 /* populate up to 33rd element of array, this is the next address after end of flash array */
<> 144:ef7eb2e8f9f7 1328 while (regionCounter <= FSL_FEATURE_FTFx_REGION_COUNT)
<> 144:ef7eb2e8f9f7 1329 {
<> 144:ef7eb2e8f9f7 1330 flashRegionAddress[regionCounter] = config->PFlashBlockBase + protectionRegionSize * regionCounter;
<> 144:ef7eb2e8f9f7 1331 regionCounter++;
<> 144:ef7eb2e8f9f7 1332 }
<> 144:ef7eb2e8f9f7 1333
<> 144:ef7eb2e8f9f7 1334 /* populate flashRegionProtectStatus array with status information
<> 144:ef7eb2e8f9f7 1335 * Protection status for each region is stored in the FPROT[3:0] registers
<> 144:ef7eb2e8f9f7 1336 * Each bit represents one region of flash
<> 144:ef7eb2e8f9f7 1337 * 4 registers * 8-bits-per-register = 32-bits (32-regions)
<> 144:ef7eb2e8f9f7 1338 * The convention is:
<> 144:ef7eb2e8f9f7 1339 * FPROT3[bit 0] is the first protection region (start of flash memory)
<> 144:ef7eb2e8f9f7 1340 * FPROT0[bit 7] is the last protection region (end of flash memory)
<> 144:ef7eb2e8f9f7 1341 * regionCounter is used to determine which FPROT[3:0] register to check for protection status
<> 144:ef7eb2e8f9f7 1342 * Note: FPROT=1 means NOT protected, FPROT=0 means protected */
<> 144:ef7eb2e8f9f7 1343 regionCounter = 0; /* make sure regionCounter is initialized to 0 first */
<> 144:ef7eb2e8f9f7 1344 while (regionCounter < FSL_FEATURE_FTFx_REGION_COUNT)
<> 144:ef7eb2e8f9f7 1345 {
<> 144:ef7eb2e8f9f7 1346 if (regionCounter < 8)
<> 144:ef7eb2e8f9f7 1347 {
<> 144:ef7eb2e8f9f7 1348 flashRegionProtectStatus[regionCounter] = ((FTFx->FPROT3) >> regionCounter) & (0x01u);
<> 144:ef7eb2e8f9f7 1349 }
<> 144:ef7eb2e8f9f7 1350 else if ((regionCounter >= 8) && (regionCounter < 16))
<> 144:ef7eb2e8f9f7 1351 {
<> 144:ef7eb2e8f9f7 1352 flashRegionProtectStatus[regionCounter] = ((FTFx->FPROT2) >> (regionCounter - 8)) & (0x01u);
<> 144:ef7eb2e8f9f7 1353 }
<> 144:ef7eb2e8f9f7 1354 else if ((regionCounter >= 16) && (regionCounter < 24))
<> 144:ef7eb2e8f9f7 1355 {
<> 144:ef7eb2e8f9f7 1356 flashRegionProtectStatus[regionCounter] = ((FTFx->FPROT1) >> (regionCounter - 16)) & (0x01u);
<> 144:ef7eb2e8f9f7 1357 }
<> 144:ef7eb2e8f9f7 1358 else
<> 144:ef7eb2e8f9f7 1359 {
<> 144:ef7eb2e8f9f7 1360 flashRegionProtectStatus[regionCounter] = ((FTFx->FPROT0) >> (regionCounter - 24)) & (0x01u);
<> 144:ef7eb2e8f9f7 1361 }
<> 144:ef7eb2e8f9f7 1362 regionCounter++;
<> 144:ef7eb2e8f9f7 1363 }
<> 144:ef7eb2e8f9f7 1364
<> 144:ef7eb2e8f9f7 1365 /* loop through the flash regions and check
<> 144:ef7eb2e8f9f7 1366 * desired flash address range for protection status
<> 144:ef7eb2e8f9f7 1367 * loop stops when it is detected that start has exceeded the endAddress */
<> 144:ef7eb2e8f9f7 1368 regionCounter = 0; /* make sure regionCounter is initialized to 0 first */
<> 144:ef7eb2e8f9f7 1369 regionCheckedCounter = 0;
<> 144:ef7eb2e8f9f7 1370 protectStatusCounter = 0; /* make sure protectStatusCounter is initialized to 0 first */
<> 144:ef7eb2e8f9f7 1371 while (start < endAddress)
<> 144:ef7eb2e8f9f7 1372 {
<> 144:ef7eb2e8f9f7 1373 /* check to see if the address falls within this protection region
<> 144:ef7eb2e8f9f7 1374 * Note that if the entire flash is to be checked, the last protection
<> 144:ef7eb2e8f9f7 1375 * region checked would consist of the last protection start address and
<> 144:ef7eb2e8f9f7 1376 * the start address following the end of flash */
<> 144:ef7eb2e8f9f7 1377 if ((start >= flashRegionAddress[regionCounter]) && (start < flashRegionAddress[regionCounter + 1]))
<> 144:ef7eb2e8f9f7 1378 {
<> 144:ef7eb2e8f9f7 1379 /* increment regionCheckedCounter to indicate this region was checked */
<> 144:ef7eb2e8f9f7 1380 regionCheckedCounter++;
<> 144:ef7eb2e8f9f7 1381
<> 144:ef7eb2e8f9f7 1382 /* check the protection status of this region
<> 144:ef7eb2e8f9f7 1383 * Note: FPROT=1 means NOT protected, FPROT=0 means protected */
<> 144:ef7eb2e8f9f7 1384 if (!flashRegionProtectStatus[regionCounter])
<> 144:ef7eb2e8f9f7 1385 {
<> 144:ef7eb2e8f9f7 1386 /* increment protectStatusCounter to indicate this region is protected */
<> 144:ef7eb2e8f9f7 1387 protectStatusCounter++;
<> 144:ef7eb2e8f9f7 1388 }
<> 144:ef7eb2e8f9f7 1389 start += protectionRegionSize; /* increment to an address within the next region */
<> 144:ef7eb2e8f9f7 1390 }
<> 144:ef7eb2e8f9f7 1391 regionCounter++; /* increment regionCounter to check for the next flash protection region */
<> 144:ef7eb2e8f9f7 1392 }
<> 144:ef7eb2e8f9f7 1393
<> 144:ef7eb2e8f9f7 1394 /* if protectStatusCounter == 0, then no region of the desired flash region is protected */
<> 144:ef7eb2e8f9f7 1395 if (protectStatusCounter == 0)
<> 144:ef7eb2e8f9f7 1396 {
<> 144:ef7eb2e8f9f7 1397 *protection_state = kFLASH_protectionStateUnprotected;
<> 144:ef7eb2e8f9f7 1398 }
<> 144:ef7eb2e8f9f7 1399 /* if protectStatusCounter == regionCheckedCounter, then each region checked was protected */
<> 144:ef7eb2e8f9f7 1400 else if (protectStatusCounter == regionCheckedCounter)
<> 144:ef7eb2e8f9f7 1401 {
<> 144:ef7eb2e8f9f7 1402 *protection_state = kFLASH_protectionStateProtected;
<> 144:ef7eb2e8f9f7 1403 }
<> 144:ef7eb2e8f9f7 1404 /* if protectStatusCounter != regionCheckedCounter, then protection status is mixed
<> 144:ef7eb2e8f9f7 1405 * In other words, some regions are protected while others are unprotected */
<> 144:ef7eb2e8f9f7 1406 else
<> 144:ef7eb2e8f9f7 1407 {
<> 144:ef7eb2e8f9f7 1408 *protection_state = kFLASH_protectionStateMixed;
<> 144:ef7eb2e8f9f7 1409 }
<> 144:ef7eb2e8f9f7 1410
<> 144:ef7eb2e8f9f7 1411 return (returnCode);
<> 144:ef7eb2e8f9f7 1412 }
<> 144:ef7eb2e8f9f7 1413
<> 144:ef7eb2e8f9f7 1414 status_t FLASH_IsExecuteOnly(flash_config_t *config,
<> 144:ef7eb2e8f9f7 1415 uint32_t start,
<> 144:ef7eb2e8f9f7 1416 uint32_t lengthInBytes,
<> 144:ef7eb2e8f9f7 1417 flash_execute_only_access_state_t *access_state)
<> 144:ef7eb2e8f9f7 1418 {
<> 144:ef7eb2e8f9f7 1419 status_t returnCode;
<> 144:ef7eb2e8f9f7 1420
<> 144:ef7eb2e8f9f7 1421 if (access_state == NULL)
<> 144:ef7eb2e8f9f7 1422 {
<> 144:ef7eb2e8f9f7 1423 return kStatus_FLASH_InvalidArgument;
<> 144:ef7eb2e8f9f7 1424 }
<> 144:ef7eb2e8f9f7 1425
<> 144:ef7eb2e8f9f7 1426 /* Check the supplied address range. */
<> 144:ef7eb2e8f9f7 1427 returnCode = flash_check_range(config, start, lengthInBytes, FSL_FEATURE_FLASH_PFLASH_BLOCK_WRITE_UNIT_SIZE);
<> 144:ef7eb2e8f9f7 1428 if (returnCode)
<> 144:ef7eb2e8f9f7 1429 {
<> 144:ef7eb2e8f9f7 1430 return returnCode;
<> 144:ef7eb2e8f9f7 1431 }
<> 144:ef7eb2e8f9f7 1432
<> 144:ef7eb2e8f9f7 1433 #if defined(FSL_FEATURE_FLASH_HAS_ACCESS_CONTROL) && FSL_FEATURE_FLASH_HAS_ACCESS_CONTROL
<> 144:ef7eb2e8f9f7 1434 {
<> 144:ef7eb2e8f9f7 1435 uint32_t executeOnlySegmentCounter = 0;
<> 144:ef7eb2e8f9f7 1436
<> 144:ef7eb2e8f9f7 1437 /* calculating end address */
<> 144:ef7eb2e8f9f7 1438 uint32_t endAddress = start + lengthInBytes;
<> 144:ef7eb2e8f9f7 1439
<> 144:ef7eb2e8f9f7 1440 /* Aligning start address and end address */
<> 144:ef7eb2e8f9f7 1441 uint32_t alignedStartAddress = ALIGN_DOWN(start, config->PFlashAccessSegmentSize);
<> 144:ef7eb2e8f9f7 1442 uint32_t alignedEndAddress = ALIGN_UP(endAddress, config->PFlashAccessSegmentSize);
<> 144:ef7eb2e8f9f7 1443
<> 144:ef7eb2e8f9f7 1444 uint32_t segmentIndex = 0;
<> 144:ef7eb2e8f9f7 1445 uint32_t maxSupportedExecuteOnlySegmentCount =
<> 144:ef7eb2e8f9f7 1446 (alignedEndAddress - alignedStartAddress) / config->PFlashAccessSegmentSize;
<> 144:ef7eb2e8f9f7 1447
<> 144:ef7eb2e8f9f7 1448 while (start < endAddress)
<> 144:ef7eb2e8f9f7 1449 {
<> 144:ef7eb2e8f9f7 1450 uint32_t xacc;
<> 144:ef7eb2e8f9f7 1451
<> 144:ef7eb2e8f9f7 1452 segmentIndex = start / config->PFlashAccessSegmentSize;
<> 144:ef7eb2e8f9f7 1453
<> 144:ef7eb2e8f9f7 1454 if (segmentIndex < 32)
<> 144:ef7eb2e8f9f7 1455 {
<> 144:ef7eb2e8f9f7 1456 xacc = *(const volatile uint32_t *)&FTFx->XACCL3;
<> 144:ef7eb2e8f9f7 1457 }
<> 144:ef7eb2e8f9f7 1458 else if (segmentIndex < config->PFlashAccessSegmentCount)
<> 144:ef7eb2e8f9f7 1459 {
<> 144:ef7eb2e8f9f7 1460 xacc = *(const volatile uint32_t *)&FTFx->XACCH3;
<> 144:ef7eb2e8f9f7 1461 segmentIndex -= 32;
<> 144:ef7eb2e8f9f7 1462 }
<> 144:ef7eb2e8f9f7 1463 else
<> 144:ef7eb2e8f9f7 1464 {
<> 144:ef7eb2e8f9f7 1465 break;
<> 144:ef7eb2e8f9f7 1466 }
<> 144:ef7eb2e8f9f7 1467
<> 144:ef7eb2e8f9f7 1468 /* Determine if this address range is in a execute-only protection flash segment. */
<> 144:ef7eb2e8f9f7 1469 if ((~xacc) & (1u << segmentIndex))
<> 144:ef7eb2e8f9f7 1470 {
<> 144:ef7eb2e8f9f7 1471 executeOnlySegmentCounter++;
<> 144:ef7eb2e8f9f7 1472 }
<> 144:ef7eb2e8f9f7 1473
<> 144:ef7eb2e8f9f7 1474 start += config->PFlashAccessSegmentSize;
<> 144:ef7eb2e8f9f7 1475 }
<> 144:ef7eb2e8f9f7 1476
<> 144:ef7eb2e8f9f7 1477 if (executeOnlySegmentCounter < 1u)
<> 144:ef7eb2e8f9f7 1478 {
<> 144:ef7eb2e8f9f7 1479 *access_state = kFLASH_accessStateUnLimited;
<> 144:ef7eb2e8f9f7 1480 }
<> 144:ef7eb2e8f9f7 1481 else if (executeOnlySegmentCounter < maxSupportedExecuteOnlySegmentCount)
<> 144:ef7eb2e8f9f7 1482 {
<> 144:ef7eb2e8f9f7 1483 *access_state = kFLASH_accessStateMixed;
<> 144:ef7eb2e8f9f7 1484 }
<> 144:ef7eb2e8f9f7 1485 else
<> 144:ef7eb2e8f9f7 1486 {
<> 144:ef7eb2e8f9f7 1487 *access_state = kFLASH_accessStateExecuteOnly;
<> 144:ef7eb2e8f9f7 1488 }
<> 144:ef7eb2e8f9f7 1489 }
<> 144:ef7eb2e8f9f7 1490 #else
<> 144:ef7eb2e8f9f7 1491 *access_state = kFLASH_accessStateUnLimited;
<> 144:ef7eb2e8f9f7 1492 #endif /* FSL_FEATURE_FLASH_HAS_ACCESS_CONTROL */
<> 144:ef7eb2e8f9f7 1493
<> 144:ef7eb2e8f9f7 1494 return (returnCode);
<> 144:ef7eb2e8f9f7 1495 }
<> 144:ef7eb2e8f9f7 1496
<> 144:ef7eb2e8f9f7 1497 status_t FLASH_GetProperty(flash_config_t *config, flash_property_tag_t whichProperty, uint32_t *value)
<> 144:ef7eb2e8f9f7 1498 {
<> 144:ef7eb2e8f9f7 1499 if ((config == NULL) || (value == NULL))
<> 144:ef7eb2e8f9f7 1500 {
<> 144:ef7eb2e8f9f7 1501 return kStatus_FLASH_InvalidArgument;
<> 144:ef7eb2e8f9f7 1502 }
<> 144:ef7eb2e8f9f7 1503
<> 144:ef7eb2e8f9f7 1504 switch (whichProperty)
<> 144:ef7eb2e8f9f7 1505 {
<> 144:ef7eb2e8f9f7 1506 case kFLASH_propertyPflashSectorSize:
<> 144:ef7eb2e8f9f7 1507 *value = config->PFlashSectorSize;
<> 144:ef7eb2e8f9f7 1508 break;
<> 144:ef7eb2e8f9f7 1509
<> 144:ef7eb2e8f9f7 1510 case kFLASH_propertyPflashTotalSize:
<> 144:ef7eb2e8f9f7 1511 *value = config->PFlashTotalSize;
<> 144:ef7eb2e8f9f7 1512 break;
<> 144:ef7eb2e8f9f7 1513
<> 144:ef7eb2e8f9f7 1514 case kFLASH_propertyPflashBlockSize:
<> 144:ef7eb2e8f9f7 1515 *value = config->PFlashTotalSize / FSL_FEATURE_FLASH_PFLASH_BLOCK_COUNT;
<> 144:ef7eb2e8f9f7 1516 break;
<> 144:ef7eb2e8f9f7 1517
<> 144:ef7eb2e8f9f7 1518 case kFLASH_propertyPflashBlockCount:
<> 144:ef7eb2e8f9f7 1519 *value = config->PFlashBlockCount;
<> 144:ef7eb2e8f9f7 1520 break;
<> 144:ef7eb2e8f9f7 1521
<> 144:ef7eb2e8f9f7 1522 case kFLASH_propertyPflashBlockBaseAddr:
<> 144:ef7eb2e8f9f7 1523 *value = config->PFlashBlockBase;
<> 144:ef7eb2e8f9f7 1524 break;
<> 144:ef7eb2e8f9f7 1525
<> 144:ef7eb2e8f9f7 1526 case kFLASH_propertyPflashFacSupport:
<> 144:ef7eb2e8f9f7 1527 #if defined(FSL_FEATURE_FLASH_HAS_ACCESS_CONTROL)
<> 144:ef7eb2e8f9f7 1528 *value = FSL_FEATURE_FLASH_HAS_ACCESS_CONTROL;
<> 144:ef7eb2e8f9f7 1529 #else
<> 144:ef7eb2e8f9f7 1530 *value = 0;
<> 144:ef7eb2e8f9f7 1531 #endif /* FSL_FEATURE_FLASH_HAS_ACCESS_CONTROL */
<> 144:ef7eb2e8f9f7 1532 break;
<> 144:ef7eb2e8f9f7 1533
<> 144:ef7eb2e8f9f7 1534 case kFLASH_propertyPflashAccessSegmentSize:
<> 144:ef7eb2e8f9f7 1535 *value = config->PFlashAccessSegmentSize;
<> 144:ef7eb2e8f9f7 1536 break;
<> 144:ef7eb2e8f9f7 1537
<> 144:ef7eb2e8f9f7 1538 case kFLASH_propertyPflashAccessSegmentCount:
<> 144:ef7eb2e8f9f7 1539 *value = config->PFlashAccessSegmentCount;
<> 144:ef7eb2e8f9f7 1540 break;
<> 144:ef7eb2e8f9f7 1541
<> 144:ef7eb2e8f9f7 1542 #if FLASH_SSD_IS_FLEXNVM_ENABLED
<> 144:ef7eb2e8f9f7 1543 case kFLASH_propertyDflashSectorSize:
<> 144:ef7eb2e8f9f7 1544 *value = FSL_FEATURE_FLASH_FLEX_NVM_BLOCK_SECTOR_SIZE;
<> 144:ef7eb2e8f9f7 1545 break;
<> 144:ef7eb2e8f9f7 1546 case kFLASH_propertyDflashTotalSize:
<> 144:ef7eb2e8f9f7 1547 *value = config->DFlashTotalSize;
<> 144:ef7eb2e8f9f7 1548 break;
<> 144:ef7eb2e8f9f7 1549 case kFLASH_propertyDflashBlockSize:
<> 144:ef7eb2e8f9f7 1550 *value = FSL_FEATURE_FLASH_FLEX_NVM_BLOCK_SIZE;
<> 144:ef7eb2e8f9f7 1551 break;
<> 144:ef7eb2e8f9f7 1552 case kFLASH_propertyDflashBlockCount:
<> 144:ef7eb2e8f9f7 1553 *value = FSL_FEATURE_FLASH_FLEX_NVM_BLOCK_COUNT;
<> 144:ef7eb2e8f9f7 1554 break;
<> 144:ef7eb2e8f9f7 1555 case kFLASH_propertyDflashBlockBaseAddr:
<> 144:ef7eb2e8f9f7 1556 *value = config->DFlashBlockBase;
<> 144:ef7eb2e8f9f7 1557 break;
<> 144:ef7eb2e8f9f7 1558 case kFLASH_propertyEepromTotalSize:
<> 144:ef7eb2e8f9f7 1559 *value = config->EEpromTotalSize;
<> 144:ef7eb2e8f9f7 1560 break;
<> 144:ef7eb2e8f9f7 1561 #endif /* FLASH_SSD_IS_FLEXNVM_ENABLED */
<> 144:ef7eb2e8f9f7 1562
<> 144:ef7eb2e8f9f7 1563 default: /* catch inputs that are not recognized */
<> 144:ef7eb2e8f9f7 1564 return kStatus_FLASH_UnknownProperty;
<> 144:ef7eb2e8f9f7 1565 }
<> 144:ef7eb2e8f9f7 1566
<> 144:ef7eb2e8f9f7 1567 return kStatus_FLASH_Success;
<> 144:ef7eb2e8f9f7 1568 }
<> 144:ef7eb2e8f9f7 1569
<> 144:ef7eb2e8f9f7 1570 #if defined(FSL_FEATURE_FLASH_HAS_SET_FLEXRAM_FUNCTION_CMD) && FSL_FEATURE_FLASH_HAS_SET_FLEXRAM_FUNCTION_CMD
<> 144:ef7eb2e8f9f7 1571 status_t FLASH_SetFlexramFunction(flash_config_t *config, flash_flexram_function_option_t option)
<> 144:ef7eb2e8f9f7 1572 {
<> 144:ef7eb2e8f9f7 1573 status_t status;
<> 144:ef7eb2e8f9f7 1574
<> 144:ef7eb2e8f9f7 1575 if (config == NULL)
<> 144:ef7eb2e8f9f7 1576 {
<> 144:ef7eb2e8f9f7 1577 return kStatus_FLASH_InvalidArgument;
<> 144:ef7eb2e8f9f7 1578 }
<> 144:ef7eb2e8f9f7 1579
<> 144:ef7eb2e8f9f7 1580 status = flasn_check_flexram_function_option_range(option);
<> 144:ef7eb2e8f9f7 1581 if (status != kStatus_FLASH_Success)
<> 144:ef7eb2e8f9f7 1582 {
<> 144:ef7eb2e8f9f7 1583 return status;
<> 144:ef7eb2e8f9f7 1584 }
<> 144:ef7eb2e8f9f7 1585
<> 144:ef7eb2e8f9f7 1586 /* preparing passing parameter to verify all block command */
<> 144:ef7eb2e8f9f7 1587 kFCCOBx[0] = BYTES_JOIN_TO_WORD_1_1_2(FTFx_SET_FLEXRAM_FUNCTION, option, 0xFFFFU);
<> 144:ef7eb2e8f9f7 1588
<> 144:ef7eb2e8f9f7 1589 /* calling flash command sequence function to execute the command */
<> 144:ef7eb2e8f9f7 1590 return flash_command_sequence(config);
<> 144:ef7eb2e8f9f7 1591 }
<> 144:ef7eb2e8f9f7 1592 #endif /* FSL_FEATURE_FLASH_HAS_SET_FLEXRAM_FUNCTION_CMD */
<> 144:ef7eb2e8f9f7 1593
<> 144:ef7eb2e8f9f7 1594 #if defined(FSL_FEATURE_FLASH_HAS_SWAP_CONTROL_CMD) && FSL_FEATURE_FLASH_HAS_SWAP_CONTROL_CMD
<> 144:ef7eb2e8f9f7 1595 status_t FLASH_SwapControl(flash_config_t *config,
<> 144:ef7eb2e8f9f7 1596 uint32_t address,
<> 144:ef7eb2e8f9f7 1597 flash_swap_control_option_t option,
<> 144:ef7eb2e8f9f7 1598 flash_swap_state_config_t *returnInfo)
<> 144:ef7eb2e8f9f7 1599 {
<> 144:ef7eb2e8f9f7 1600 status_t returnCode;
<> 144:ef7eb2e8f9f7 1601
<> 144:ef7eb2e8f9f7 1602 if ((config == NULL) || (returnInfo == NULL))
<> 144:ef7eb2e8f9f7 1603 {
<> 144:ef7eb2e8f9f7 1604 return kStatus_FLASH_InvalidArgument;
<> 144:ef7eb2e8f9f7 1605 }
<> 144:ef7eb2e8f9f7 1606
<> 144:ef7eb2e8f9f7 1607 if (address & (FSL_FEATURE_FLASH_PFLASH_SWAP_CONTROL_CMD_ADDRESS_ALIGMENT - 1))
<> 144:ef7eb2e8f9f7 1608 {
<> 144:ef7eb2e8f9f7 1609 return kStatus_FLASH_AlignmentError;
<> 144:ef7eb2e8f9f7 1610 }
<> 144:ef7eb2e8f9f7 1611
<> 144:ef7eb2e8f9f7 1612 /* Make sure address provided is in the lower half of Program flash but not in the Flash Configuration Field */
<> 144:ef7eb2e8f9f7 1613 if ((address >= (config->PFlashTotalSize / 2)) ||
<> 144:ef7eb2e8f9f7 1614 ((address >= kFLASH_configAreaStart) && (address <= kFLASH_configAreaEnd)))
<> 144:ef7eb2e8f9f7 1615 {
<> 144:ef7eb2e8f9f7 1616 return kStatus_FLASH_SwapIndicatorAddressError;
<> 144:ef7eb2e8f9f7 1617 }
<> 144:ef7eb2e8f9f7 1618
<> 144:ef7eb2e8f9f7 1619 /* Check the option. */
<> 144:ef7eb2e8f9f7 1620 returnCode = flash_check_swap_control_option(option);
<> 144:ef7eb2e8f9f7 1621 if (returnCode)
<> 144:ef7eb2e8f9f7 1622 {
<> 144:ef7eb2e8f9f7 1623 return returnCode;
<> 144:ef7eb2e8f9f7 1624 }
<> 144:ef7eb2e8f9f7 1625
<> 144:ef7eb2e8f9f7 1626 kFCCOBx[0] = BYTES_JOIN_TO_WORD_1_3(FTFx_SWAP_CONTROL, address);
<> 144:ef7eb2e8f9f7 1627 kFCCOBx[1] = BYTES_JOIN_TO_WORD_1_3(option, 0xFFFFFFU);
<> 144:ef7eb2e8f9f7 1628
<> 144:ef7eb2e8f9f7 1629 returnCode = flash_command_sequence(config);
<> 144:ef7eb2e8f9f7 1630
<> 144:ef7eb2e8f9f7 1631 returnInfo->flashSwapState = (flash_swap_state_t)FTFx->FCCOB5;
<> 144:ef7eb2e8f9f7 1632 returnInfo->currentSwapBlockStatus = (flash_swap_block_status_t)FTFx->FCCOB6;
<> 144:ef7eb2e8f9f7 1633 returnInfo->nextSwapBlockStatus = (flash_swap_block_status_t)FTFx->FCCOB7;
<> 144:ef7eb2e8f9f7 1634
<> 144:ef7eb2e8f9f7 1635 return returnCode;
<> 144:ef7eb2e8f9f7 1636 }
<> 144:ef7eb2e8f9f7 1637 #endif /* FSL_FEATURE_FLASH_HAS_SWAP_CONTROL_CMD */
<> 144:ef7eb2e8f9f7 1638
<> 144:ef7eb2e8f9f7 1639 #if defined(FSL_FEATURE_FLASH_HAS_PFLASH_BLOCK_SWAP) && FSL_FEATURE_FLASH_HAS_PFLASH_BLOCK_SWAP
<> 144:ef7eb2e8f9f7 1640 status_t FLASH_Swap(flash_config_t *config, uint32_t address, flash_swap_function_option_t option)
<> 144:ef7eb2e8f9f7 1641 {
<> 144:ef7eb2e8f9f7 1642 flash_swap_state_config_t returnInfo;
<> 144:ef7eb2e8f9f7 1643 status_t returnCode;
<> 144:ef7eb2e8f9f7 1644
<> 144:ef7eb2e8f9f7 1645 memset(&returnInfo, 0xFFU, sizeof(returnInfo));
<> 144:ef7eb2e8f9f7 1646
<> 144:ef7eb2e8f9f7 1647 do
<> 144:ef7eb2e8f9f7 1648 {
<> 144:ef7eb2e8f9f7 1649 returnCode = FLASH_SwapControl(config, address, kFLASH_swapControlOptionReportStatus, &returnInfo);
<> 144:ef7eb2e8f9f7 1650 if (returnCode != kStatus_FLASH_Success)
<> 144:ef7eb2e8f9f7 1651 {
<> 144:ef7eb2e8f9f7 1652 return returnCode;
<> 144:ef7eb2e8f9f7 1653 }
<> 144:ef7eb2e8f9f7 1654
<> 144:ef7eb2e8f9f7 1655 if (kFLASH_swapFunctionOptionDisable == option)
<> 144:ef7eb2e8f9f7 1656 {
<> 144:ef7eb2e8f9f7 1657 if (returnInfo.flashSwapState == kFLASH_swapStateDisabled)
<> 144:ef7eb2e8f9f7 1658 {
<> 144:ef7eb2e8f9f7 1659 return kStatus_FLASH_Success;
<> 144:ef7eb2e8f9f7 1660 }
<> 144:ef7eb2e8f9f7 1661 else if (returnInfo.flashSwapState == kFLASH_swapStateUninitialized)
<> 144:ef7eb2e8f9f7 1662 {
<> 144:ef7eb2e8f9f7 1663 /* The swap system changed to the DISABLED state with Program flash block 0
<> 144:ef7eb2e8f9f7 1664 * located at relative flash address 0x0_0000 */
<> 144:ef7eb2e8f9f7 1665 returnCode = FLASH_SwapControl(config, address, kFLASH_swapControlOptionDisableSystem, &returnInfo);
<> 144:ef7eb2e8f9f7 1666 }
<> 144:ef7eb2e8f9f7 1667 else
<> 144:ef7eb2e8f9f7 1668 {
<> 144:ef7eb2e8f9f7 1669 /* Swap disable should be requested only when swap system is in the uninitialized state */
<> 144:ef7eb2e8f9f7 1670 return kStatus_FLASH_SwapSystemNotInUninitialized;
<> 144:ef7eb2e8f9f7 1671 }
<> 144:ef7eb2e8f9f7 1672 }
<> 144:ef7eb2e8f9f7 1673 else
<> 144:ef7eb2e8f9f7 1674 {
<> 144:ef7eb2e8f9f7 1675 /* When first swap: the initial swap state is Uninitialized, flash swap inidicator address is unset,
<> 144:ef7eb2e8f9f7 1676 * the swap procedure should be Uninitialized -> Update-Erased -> Complete.
<> 144:ef7eb2e8f9f7 1677 * After the first swap has been completed, the flash swap inidicator address cannot be modified
<> 144:ef7eb2e8f9f7 1678 * unless EraseAllBlocks command is issued, the swap procedure is changed to Update -> Update-Erased ->
<> 144:ef7eb2e8f9f7 1679 * Complete. */
<> 144:ef7eb2e8f9f7 1680 switch (returnInfo.flashSwapState)
<> 144:ef7eb2e8f9f7 1681 {
<> 144:ef7eb2e8f9f7 1682 case kFLASH_swapStateUninitialized:
<> 144:ef7eb2e8f9f7 1683 /* If current swap mode is Uninitialized, Initialize Swap to Initialized/READY state. */
<> 144:ef7eb2e8f9f7 1684 returnCode =
<> 144:ef7eb2e8f9f7 1685 FLASH_SwapControl(config, address, kFLASH_swapControlOptionIntializeSystem, &returnInfo);
<> 144:ef7eb2e8f9f7 1686 break;
<> 144:ef7eb2e8f9f7 1687 case kFLASH_swapStateReady:
<> 144:ef7eb2e8f9f7 1688 /* Validate whether the address provided to the swap system is matched to
<> 144:ef7eb2e8f9f7 1689 * swap indicator address in the IFR */
<> 144:ef7eb2e8f9f7 1690 returnCode = flash_validate_swap_indicator_address(config, address);
<> 144:ef7eb2e8f9f7 1691 if (returnCode == kStatus_FLASH_Success)
<> 144:ef7eb2e8f9f7 1692 {
<> 144:ef7eb2e8f9f7 1693 /* If current swap mode is Initialized/Ready, Initialize Swap to UPDATE state. */
<> 144:ef7eb2e8f9f7 1694 returnCode =
<> 144:ef7eb2e8f9f7 1695 FLASH_SwapControl(config, address, kFLASH_swapControlOptionSetInUpdateState, &returnInfo);
<> 144:ef7eb2e8f9f7 1696 }
<> 144:ef7eb2e8f9f7 1697 break;
<> 144:ef7eb2e8f9f7 1698 case kFLASH_swapStateUpdate:
<> 144:ef7eb2e8f9f7 1699 /* If current swap mode is Update, Erase indicator sector in non active block
<> 144:ef7eb2e8f9f7 1700 * to proceed swap system to update-erased state */
<> 144:ef7eb2e8f9f7 1701 returnCode = FLASH_Erase(config, address + (config->PFlashTotalSize >> 1),
<> 144:ef7eb2e8f9f7 1702 FSL_FEATURE_FLASH_PFLASH_SECTOR_CMD_ADDRESS_ALIGMENT, kFLASH_apiEraseKey);
<> 144:ef7eb2e8f9f7 1703 break;
<> 144:ef7eb2e8f9f7 1704 case kFLASH_swapStateUpdateErased:
<> 144:ef7eb2e8f9f7 1705 /* If current swap mode is Update or Update-Erased, progress Swap to COMPLETE State */
<> 144:ef7eb2e8f9f7 1706 returnCode =
<> 144:ef7eb2e8f9f7 1707 FLASH_SwapControl(config, address, kFLASH_swapControlOptionSetInCompleteState, &returnInfo);
<> 144:ef7eb2e8f9f7 1708 break;
<> 144:ef7eb2e8f9f7 1709 case kFLASH_swapStateComplete:
<> 144:ef7eb2e8f9f7 1710 break;
<> 144:ef7eb2e8f9f7 1711 case kFLASH_swapStateDisabled:
<> 144:ef7eb2e8f9f7 1712 /* When swap system is in disabled state, We need to clear swap system back to uninitialized
<> 144:ef7eb2e8f9f7 1713 * by issuing EraseAllBlocks command */
<> 144:ef7eb2e8f9f7 1714 returnCode = kStatus_FLASH_SwapSystemNotInUninitialized;
<> 144:ef7eb2e8f9f7 1715 break;
<> 144:ef7eb2e8f9f7 1716 default:
<> 144:ef7eb2e8f9f7 1717 returnCode = kStatus_FLASH_InvalidArgument;
<> 144:ef7eb2e8f9f7 1718 break;
<> 144:ef7eb2e8f9f7 1719 }
<> 144:ef7eb2e8f9f7 1720 }
<> 144:ef7eb2e8f9f7 1721 if (returnCode != kStatus_FLASH_Success)
<> 144:ef7eb2e8f9f7 1722 {
<> 144:ef7eb2e8f9f7 1723 break;
<> 144:ef7eb2e8f9f7 1724 }
<> 144:ef7eb2e8f9f7 1725 } while (!((kFLASH_swapStateComplete == returnInfo.flashSwapState) && (kFLASH_swapFunctionOptionEnable == option)));
<> 144:ef7eb2e8f9f7 1726
<> 144:ef7eb2e8f9f7 1727 return returnCode;
<> 144:ef7eb2e8f9f7 1728 }
<> 144:ef7eb2e8f9f7 1729 #endif /* FSL_FEATURE_FLASH_HAS_PFLASH_BLOCK_SWAP */
<> 144:ef7eb2e8f9f7 1730
<> 144:ef7eb2e8f9f7 1731 #if defined(FSL_FEATURE_FLASH_HAS_PROGRAM_PARTITION_CMD) && FSL_FEATURE_FLASH_HAS_PROGRAM_PARTITION_CMD
<> 144:ef7eb2e8f9f7 1732 status_t FLASH_ProgramPartition(flash_config_t *config,
<> 144:ef7eb2e8f9f7 1733 flash_partition_flexram_load_option_t option,
<> 144:ef7eb2e8f9f7 1734 uint32_t eepromDataSizeCode,
<> 144:ef7eb2e8f9f7 1735 uint32_t flexnvmPartitionCode)
<> 144:ef7eb2e8f9f7 1736 {
<> 144:ef7eb2e8f9f7 1737 status_t returnCode;
<> 144:ef7eb2e8f9f7 1738
<> 144:ef7eb2e8f9f7 1739 if (config == NULL)
<> 144:ef7eb2e8f9f7 1740 {
<> 144:ef7eb2e8f9f7 1741 return kStatus_FLASH_InvalidArgument;
<> 144:ef7eb2e8f9f7 1742 }
<> 144:ef7eb2e8f9f7 1743
<> 144:ef7eb2e8f9f7 1744 /* eepromDataSizeCode[7:6], flexnvmPartitionCode[7:4] should be all 1'b0
<> 144:ef7eb2e8f9f7 1745 * or it will cause access error. */
<> 144:ef7eb2e8f9f7 1746 /* eepromDataSizeCode &= 0x3FU; */
<> 144:ef7eb2e8f9f7 1747 /* flexnvmPartitionCode &= 0x0FU; */
<> 144:ef7eb2e8f9f7 1748
<> 144:ef7eb2e8f9f7 1749 /* preparing passing parameter to program the flash block */
<> 144:ef7eb2e8f9f7 1750 kFCCOBx[0] = BYTES_JOIN_TO_WORD_1_2_1(FTFx_PROGRAM_PARTITION, 0xFFFFU, option);
<> 144:ef7eb2e8f9f7 1751 kFCCOBx[1] = BYTES_JOIN_TO_WORD_1_1_2(eepromDataSizeCode, flexnvmPartitionCode, 0xFFFFU);
<> 144:ef7eb2e8f9f7 1752
<> 144:ef7eb2e8f9f7 1753 /* calling flash command sequence function to execute the command */
<> 144:ef7eb2e8f9f7 1754 returnCode = flash_command_sequence(config);
<> 144:ef7eb2e8f9f7 1755
<> 144:ef7eb2e8f9f7 1756 flash_cache_clear(config);
<> 144:ef7eb2e8f9f7 1757
<> 144:ef7eb2e8f9f7 1758 #if FLASH_SSD_IS_FLEXNVM_ENABLED
<> 144:ef7eb2e8f9f7 1759 /* Data flash IFR will be updated by program partition command during reset sequence,
<> 144:ef7eb2e8f9f7 1760 * so we just set reserved values for partitioned FlexNVM size here */
<> 144:ef7eb2e8f9f7 1761 config->EEpromTotalSize = FLEX_NVM_EEPROM_SIZE_FOR_EEESIZE_RESERVED;
<> 144:ef7eb2e8f9f7 1762 config->DFlashTotalSize = FLEX_NVM_DFLASH_SIZE_FOR_DEPART_RESERVED;
<> 144:ef7eb2e8f9f7 1763 #endif
<> 144:ef7eb2e8f9f7 1764
<> 144:ef7eb2e8f9f7 1765 return (returnCode);
<> 144:ef7eb2e8f9f7 1766 }
<> 144:ef7eb2e8f9f7 1767 #endif /* FSL_FEATURE_FLASH_HAS_PROGRAM_PARTITION_CMD */
<> 144:ef7eb2e8f9f7 1768
<> 144:ef7eb2e8f9f7 1769 status_t FLASH_PflashSetProtection(flash_config_t *config, uint32_t protectStatus)
<> 144:ef7eb2e8f9f7 1770 {
<> 144:ef7eb2e8f9f7 1771 if (config == NULL)
<> 144:ef7eb2e8f9f7 1772 {
<> 144:ef7eb2e8f9f7 1773 return kStatus_FLASH_InvalidArgument;
<> 144:ef7eb2e8f9f7 1774 }
<> 144:ef7eb2e8f9f7 1775
<> 144:ef7eb2e8f9f7 1776 *kFPROT = protectStatus;
<> 144:ef7eb2e8f9f7 1777
<> 144:ef7eb2e8f9f7 1778 if (protectStatus != *kFPROT)
<> 144:ef7eb2e8f9f7 1779 {
<> 144:ef7eb2e8f9f7 1780 return kStatus_FLASH_CommandFailure;
<> 144:ef7eb2e8f9f7 1781 }
<> 144:ef7eb2e8f9f7 1782
<> 144:ef7eb2e8f9f7 1783 return kStatus_FLASH_Success;
<> 144:ef7eb2e8f9f7 1784 }
<> 144:ef7eb2e8f9f7 1785
<> 144:ef7eb2e8f9f7 1786 status_t FLASH_PflashGetProtection(flash_config_t *config, uint32_t *protectStatus)
<> 144:ef7eb2e8f9f7 1787 {
<> 144:ef7eb2e8f9f7 1788 if ((config == NULL) || (protectStatus == NULL))
<> 144:ef7eb2e8f9f7 1789 {
<> 144:ef7eb2e8f9f7 1790 return kStatus_FLASH_InvalidArgument;
<> 144:ef7eb2e8f9f7 1791 }
<> 144:ef7eb2e8f9f7 1792
<> 144:ef7eb2e8f9f7 1793 *protectStatus = *kFPROT;
<> 144:ef7eb2e8f9f7 1794
<> 144:ef7eb2e8f9f7 1795 return kStatus_FLASH_Success;
<> 144:ef7eb2e8f9f7 1796 }
<> 144:ef7eb2e8f9f7 1797
<> 144:ef7eb2e8f9f7 1798 #if FLASH_SSD_IS_FLEXNVM_ENABLED
<> 144:ef7eb2e8f9f7 1799 status_t FLASH_DflashSetProtection(flash_config_t *config, uint8_t protectStatus)
<> 144:ef7eb2e8f9f7 1800 {
<> 144:ef7eb2e8f9f7 1801 if (config == NULL)
<> 144:ef7eb2e8f9f7 1802 {
<> 144:ef7eb2e8f9f7 1803 return kStatus_FLASH_InvalidArgument;
<> 144:ef7eb2e8f9f7 1804 }
<> 144:ef7eb2e8f9f7 1805
<> 144:ef7eb2e8f9f7 1806 if ((config->DFlashTotalSize == 0) || (config->DFlashTotalSize == FLEX_NVM_DFLASH_SIZE_FOR_DEPART_RESERVED))
<> 144:ef7eb2e8f9f7 1807 {
<> 144:ef7eb2e8f9f7 1808 return kStatus_FLASH_CommandNotSupported;
<> 144:ef7eb2e8f9f7 1809 }
<> 144:ef7eb2e8f9f7 1810
<> 144:ef7eb2e8f9f7 1811 FTFx->FDPROT = protectStatus;
<> 144:ef7eb2e8f9f7 1812
<> 144:ef7eb2e8f9f7 1813 if (FTFx->FDPROT != protectStatus)
<> 144:ef7eb2e8f9f7 1814 {
<> 144:ef7eb2e8f9f7 1815 return kStatus_FLASH_CommandFailure;
<> 144:ef7eb2e8f9f7 1816 }
<> 144:ef7eb2e8f9f7 1817
<> 144:ef7eb2e8f9f7 1818 return kStatus_FLASH_Success;
<> 144:ef7eb2e8f9f7 1819 }
<> 144:ef7eb2e8f9f7 1820 #endif /* FLASH_SSD_IS_FLEXNVM_ENABLED */
<> 144:ef7eb2e8f9f7 1821
<> 144:ef7eb2e8f9f7 1822 #if FLASH_SSD_IS_FLEXNVM_ENABLED
<> 144:ef7eb2e8f9f7 1823 status_t FLASH_DflashGetProtection(flash_config_t *config, uint8_t *protectStatus)
<> 144:ef7eb2e8f9f7 1824 {
<> 144:ef7eb2e8f9f7 1825 if ((config == NULL) || (protectStatus == NULL))
<> 144:ef7eb2e8f9f7 1826 {
<> 144:ef7eb2e8f9f7 1827 return kStatus_FLASH_InvalidArgument;
<> 144:ef7eb2e8f9f7 1828 }
<> 144:ef7eb2e8f9f7 1829
<> 144:ef7eb2e8f9f7 1830 if ((config->DFlashTotalSize == 0) || (config->DFlashTotalSize == FLEX_NVM_DFLASH_SIZE_FOR_DEPART_RESERVED))
<> 144:ef7eb2e8f9f7 1831 {
<> 144:ef7eb2e8f9f7 1832 return kStatus_FLASH_CommandNotSupported;
<> 144:ef7eb2e8f9f7 1833 }
<> 144:ef7eb2e8f9f7 1834
<> 144:ef7eb2e8f9f7 1835 *protectStatus = FTFx->FDPROT;
<> 144:ef7eb2e8f9f7 1836
<> 144:ef7eb2e8f9f7 1837 return kStatus_FLASH_Success;
<> 144:ef7eb2e8f9f7 1838 }
<> 144:ef7eb2e8f9f7 1839 #endif /* FLASH_SSD_IS_FLEXNVM_ENABLED */
<> 144:ef7eb2e8f9f7 1840
<> 144:ef7eb2e8f9f7 1841 #if FLASH_SSD_IS_FLEXNVM_ENABLED
<> 144:ef7eb2e8f9f7 1842 status_t FLASH_EepromSetProtection(flash_config_t *config, uint8_t protectStatus)
<> 144:ef7eb2e8f9f7 1843 {
<> 144:ef7eb2e8f9f7 1844 if (config == NULL)
<> 144:ef7eb2e8f9f7 1845 {
<> 144:ef7eb2e8f9f7 1846 return kStatus_FLASH_InvalidArgument;
<> 144:ef7eb2e8f9f7 1847 }
<> 144:ef7eb2e8f9f7 1848
<> 144:ef7eb2e8f9f7 1849 if ((config->EEpromTotalSize == 0) || (config->EEpromTotalSize == FLEX_NVM_EEPROM_SIZE_FOR_EEESIZE_RESERVED))
<> 144:ef7eb2e8f9f7 1850 {
<> 144:ef7eb2e8f9f7 1851 return kStatus_FLASH_CommandNotSupported;
<> 144:ef7eb2e8f9f7 1852 }
<> 144:ef7eb2e8f9f7 1853
<> 144:ef7eb2e8f9f7 1854 FTFx->FEPROT = protectStatus;
<> 144:ef7eb2e8f9f7 1855
<> 144:ef7eb2e8f9f7 1856 if (FTFx->FEPROT != protectStatus)
<> 144:ef7eb2e8f9f7 1857 {
<> 144:ef7eb2e8f9f7 1858 return kStatus_FLASH_CommandFailure;
<> 144:ef7eb2e8f9f7 1859 }
<> 144:ef7eb2e8f9f7 1860
<> 144:ef7eb2e8f9f7 1861 return kStatus_FLASH_Success;
<> 144:ef7eb2e8f9f7 1862 }
<> 144:ef7eb2e8f9f7 1863 #endif /* FLASH_SSD_IS_FLEXNVM_ENABLED */
<> 144:ef7eb2e8f9f7 1864
<> 144:ef7eb2e8f9f7 1865 #if FLASH_SSD_IS_FLEXNVM_ENABLED
<> 144:ef7eb2e8f9f7 1866 status_t FLASH_EepromGetProtection(flash_config_t *config, uint8_t *protectStatus)
<> 144:ef7eb2e8f9f7 1867 {
<> 144:ef7eb2e8f9f7 1868 if ((config == NULL) || (protectStatus == NULL))
<> 144:ef7eb2e8f9f7 1869 {
<> 144:ef7eb2e8f9f7 1870 return kStatus_FLASH_InvalidArgument;
<> 144:ef7eb2e8f9f7 1871 }
<> 144:ef7eb2e8f9f7 1872
<> 144:ef7eb2e8f9f7 1873 if ((config->EEpromTotalSize == 0) || (config->EEpromTotalSize == FLEX_NVM_EEPROM_SIZE_FOR_EEESIZE_RESERVED))
<> 144:ef7eb2e8f9f7 1874 {
<> 144:ef7eb2e8f9f7 1875 return kStatus_FLASH_CommandNotSupported;
<> 144:ef7eb2e8f9f7 1876 }
<> 144:ef7eb2e8f9f7 1877
<> 144:ef7eb2e8f9f7 1878 *protectStatus = FTFx->FEPROT;
<> 144:ef7eb2e8f9f7 1879
<> 144:ef7eb2e8f9f7 1880 return kStatus_FLASH_Success;
<> 144:ef7eb2e8f9f7 1881 }
<> 144:ef7eb2e8f9f7 1882 #endif /* FLASH_SSD_IS_FLEXNVM_ENABLED */
<> 144:ef7eb2e8f9f7 1883
<> 144:ef7eb2e8f9f7 1884 #if FLASH_DRIVER_IS_FLASH_RESIDENT
<> 144:ef7eb2e8f9f7 1885 /*!
<> 144:ef7eb2e8f9f7 1886 * @brief Run flash command
<> 144:ef7eb2e8f9f7 1887 *
<> 144:ef7eb2e8f9f7 1888 * This function should be copied to RAM for execution to make sure that code works
<> 144:ef7eb2e8f9f7 1889 * properly even flash cache is disabled.
<> 144:ef7eb2e8f9f7 1890 * It is for flash-resident bootloader only, not technically required for ROM or
<> 144:ef7eb2e8f9f7 1891 * flashloader (RAM-resident bootloader).
<> 144:ef7eb2e8f9f7 1892 */
<> 144:ef7eb2e8f9f7 1893 void flash_run_command(FTFx_REG_ACCESS_TYPE ftfx_fstat)
<> 144:ef7eb2e8f9f7 1894 {
<> 144:ef7eb2e8f9f7 1895 /* clear CCIF bit */
<> 144:ef7eb2e8f9f7 1896 *ftfx_fstat = FTFx_FSTAT_CCIF_MASK;
<> 144:ef7eb2e8f9f7 1897
<> 144:ef7eb2e8f9f7 1898 /* Check CCIF bit of the flash status register, wait till it is set.
<> 144:ef7eb2e8f9f7 1899 * IP team indicates that this loop will always complete. */
<> 144:ef7eb2e8f9f7 1900 while (!((*ftfx_fstat) & FTFx_FSTAT_CCIF_MASK))
<> 144:ef7eb2e8f9f7 1901 {
<> 144:ef7eb2e8f9f7 1902 }
<> 144:ef7eb2e8f9f7 1903 }
<> 144:ef7eb2e8f9f7 1904
<> 144:ef7eb2e8f9f7 1905 /*!
<> 144:ef7eb2e8f9f7 1906 * @brief Be used for determining the size of flash_run_command()
<> 144:ef7eb2e8f9f7 1907 *
<> 144:ef7eb2e8f9f7 1908 * This function must be defined that lexically follows flash_run_command(),
<> 144:ef7eb2e8f9f7 1909 * so we can determine the size of flash_run_command() at runtime and not worry
<> 144:ef7eb2e8f9f7 1910 * about toolchain or code generation differences.
<> 144:ef7eb2e8f9f7 1911 */
<> 144:ef7eb2e8f9f7 1912 void flash_run_command_end(void)
<> 144:ef7eb2e8f9f7 1913 {
<> 144:ef7eb2e8f9f7 1914 }
<> 144:ef7eb2e8f9f7 1915
<> 144:ef7eb2e8f9f7 1916 /*!
<> 144:ef7eb2e8f9f7 1917 * @brief Copy flash_run_command() to RAM
<> 144:ef7eb2e8f9f7 1918 *
<> 144:ef7eb2e8f9f7 1919 * This function copys the memory between flash_run_command() and flash_run_command_end()
<> 144:ef7eb2e8f9f7 1920 * into the buffer which is also means that copying flash_run_command() to RAM.
<> 144:ef7eb2e8f9f7 1921 */
<> 144:ef7eb2e8f9f7 1922 static void copy_flash_run_command(uint8_t *flashRunCommand)
<> 144:ef7eb2e8f9f7 1923 {
<> 144:ef7eb2e8f9f7 1924 /* Calculate the valid length of flash_run_command() memory.
<> 144:ef7eb2e8f9f7 1925 * Set max size(64 bytes) as default function size, in case some compiler allocates
<> 144:ef7eb2e8f9f7 1926 * flash_run_command_end ahead of flash_run_command. */
<> 144:ef7eb2e8f9f7 1927 uint32_t funcLength = kFLASH_executeInRamFunctionMaxSize;
<> 144:ef7eb2e8f9f7 1928 uint32_t flash_run_command_start_addr = (uint32_t)flash_run_command & (~1U);
<> 144:ef7eb2e8f9f7 1929 uint32_t flash_run_command_end_addr = (uint32_t)flash_run_command_end & (~1U);
<> 144:ef7eb2e8f9f7 1930 if (flash_run_command_end_addr > flash_run_command_start_addr)
<> 144:ef7eb2e8f9f7 1931 {
<> 144:ef7eb2e8f9f7 1932 funcLength = flash_run_command_end_addr - flash_run_command_start_addr;
<> 144:ef7eb2e8f9f7 1933
<> 144:ef7eb2e8f9f7 1934 assert(funcLength <= kFLASH_executeInRamFunctionMaxSize);
<> 144:ef7eb2e8f9f7 1935
<> 144:ef7eb2e8f9f7 1936 /* In case some compiler allocates other function in the middle of flash_run_command
<> 144:ef7eb2e8f9f7 1937 * and flash_run_command_end. */
<> 144:ef7eb2e8f9f7 1938 if (funcLength > kFLASH_executeInRamFunctionMaxSize)
<> 144:ef7eb2e8f9f7 1939 {
<> 144:ef7eb2e8f9f7 1940 funcLength = kFLASH_executeInRamFunctionMaxSize;
<> 144:ef7eb2e8f9f7 1941 }
<> 144:ef7eb2e8f9f7 1942 }
<> 144:ef7eb2e8f9f7 1943
<> 144:ef7eb2e8f9f7 1944 /* Since the value of ARM function pointer is always odd, but the real start address
<> 144:ef7eb2e8f9f7 1945 * of function memory should be even, that's why -1 and +1 operation exist. */
<> 144:ef7eb2e8f9f7 1946 memcpy((void *)flashRunCommand, (void *)flash_run_command_start_addr, funcLength);
<> 144:ef7eb2e8f9f7 1947 callFlashRunCommand = (void (*)(FTFx_REG_ACCESS_TYPE ftfx_fstat))((uint32_t)flashRunCommand + 1);
<> 144:ef7eb2e8f9f7 1948 }
<> 144:ef7eb2e8f9f7 1949 #endif /* FLASH_DRIVER_IS_FLASH_RESIDENT */
<> 144:ef7eb2e8f9f7 1950
<> 144:ef7eb2e8f9f7 1951 /*!
<> 144:ef7eb2e8f9f7 1952 * @brief Flash Command Sequence
<> 144:ef7eb2e8f9f7 1953 *
<> 144:ef7eb2e8f9f7 1954 * This function is used to perform the command write sequence to the flash.
<> 144:ef7eb2e8f9f7 1955 *
<> 144:ef7eb2e8f9f7 1956 * @param driver Pointer to storage for the driver runtime state.
<> 144:ef7eb2e8f9f7 1957 * @return An error code or kStatus_FLASH_Success
<> 144:ef7eb2e8f9f7 1958 */
<> 144:ef7eb2e8f9f7 1959 static status_t flash_command_sequence(flash_config_t *config)
<> 144:ef7eb2e8f9f7 1960 {
<> 144:ef7eb2e8f9f7 1961 uint8_t registerValue;
<> 144:ef7eb2e8f9f7 1962
<> 144:ef7eb2e8f9f7 1963 #if FLASH_DRIVER_IS_FLASH_RESIDENT
<> 144:ef7eb2e8f9f7 1964 /* clear RDCOLERR & ACCERR & FPVIOL flag in flash status register */
<> 144:ef7eb2e8f9f7 1965 FTFx->FSTAT = FTFx_FSTAT_RDCOLERR_MASK | FTFx_FSTAT_ACCERR_MASK | FTFx_FSTAT_FPVIOL_MASK;
<> 144:ef7eb2e8f9f7 1966
<> 144:ef7eb2e8f9f7 1967 status_t returnCode = flash_check_execute_in_ram_function_info(config);
<> 144:ef7eb2e8f9f7 1968 if (kStatus_FLASH_Success != returnCode)
<> 144:ef7eb2e8f9f7 1969 {
<> 144:ef7eb2e8f9f7 1970 return returnCode;
<> 144:ef7eb2e8f9f7 1971 }
<> 144:ef7eb2e8f9f7 1972
<> 144:ef7eb2e8f9f7 1973 /* We pass the ftfx_fstat address as a parameter to flash_run_comamnd() instead of using
<> 144:ef7eb2e8f9f7 1974 * pre-processed MICRO sentences or operating global variable in flash_run_comamnd()
<> 144:ef7eb2e8f9f7 1975 * to make sure that flash_run_command() will be compiled into position-independent code (PIC). */
<> 144:ef7eb2e8f9f7 1976 callFlashRunCommand((FTFx_REG_ACCESS_TYPE)(&FTFx->FSTAT));
<> 144:ef7eb2e8f9f7 1977 #else
<> 144:ef7eb2e8f9f7 1978 /* clear RDCOLERR & ACCERR & FPVIOL flag in flash status register */
<> 144:ef7eb2e8f9f7 1979 FTFx->FSTAT = FTFx_FSTAT_RDCOLERR_MASK | FTFx_FSTAT_ACCERR_MASK | FTFx_FSTAT_FPVIOL_MASK;
<> 144:ef7eb2e8f9f7 1980
<> 144:ef7eb2e8f9f7 1981 /* clear CCIF bit */
<> 144:ef7eb2e8f9f7 1982 FTFx->FSTAT = FTFx_FSTAT_CCIF_MASK;
<> 144:ef7eb2e8f9f7 1983
<> 144:ef7eb2e8f9f7 1984 /* Check CCIF bit of the flash status register, wait till it is set.
<> 144:ef7eb2e8f9f7 1985 * IP team indicates that this loop will always complete. */
<> 144:ef7eb2e8f9f7 1986 while (!(FTFx->FSTAT & FTFx_FSTAT_CCIF_MASK))
<> 144:ef7eb2e8f9f7 1987 {
<> 144:ef7eb2e8f9f7 1988 }
<> 144:ef7eb2e8f9f7 1989 #endif /* FLASH_DRIVER_IS_FLASH_RESIDENT */
<> 144:ef7eb2e8f9f7 1990
<> 144:ef7eb2e8f9f7 1991 /* Check error bits */
<> 144:ef7eb2e8f9f7 1992 /* Get flash status register value */
<> 144:ef7eb2e8f9f7 1993 registerValue = FTFx->FSTAT;
<> 144:ef7eb2e8f9f7 1994
<> 144:ef7eb2e8f9f7 1995 /* checking access error */
<> 144:ef7eb2e8f9f7 1996 if (registerValue & FTFx_FSTAT_ACCERR_MASK)
<> 144:ef7eb2e8f9f7 1997 {
<> 144:ef7eb2e8f9f7 1998 return kStatus_FLASH_AccessError;
<> 144:ef7eb2e8f9f7 1999 }
<> 144:ef7eb2e8f9f7 2000 /* checking protection error */
<> 144:ef7eb2e8f9f7 2001 else if (registerValue & FTFx_FSTAT_FPVIOL_MASK)
<> 144:ef7eb2e8f9f7 2002 {
<> 144:ef7eb2e8f9f7 2003 return kStatus_FLASH_ProtectionViolation;
<> 144:ef7eb2e8f9f7 2004 }
<> 144:ef7eb2e8f9f7 2005 /* checking MGSTAT0 non-correctable error */
<> 144:ef7eb2e8f9f7 2006 else if (registerValue & FTFx_FSTAT_MGSTAT0_MASK)
<> 144:ef7eb2e8f9f7 2007 {
<> 144:ef7eb2e8f9f7 2008 return kStatus_FLASH_CommandFailure;
<> 144:ef7eb2e8f9f7 2009 }
<> 144:ef7eb2e8f9f7 2010 else
<> 144:ef7eb2e8f9f7 2011 {
<> 144:ef7eb2e8f9f7 2012 return kStatus_FLASH_Success;
<> 144:ef7eb2e8f9f7 2013 }
<> 144:ef7eb2e8f9f7 2014 }
<> 144:ef7eb2e8f9f7 2015
<> 144:ef7eb2e8f9f7 2016 #if FLASH_DRIVER_IS_FLASH_RESIDENT
<> 144:ef7eb2e8f9f7 2017 /*!
<> 144:ef7eb2e8f9f7 2018 * @brief Run flash cache clear command
<> 144:ef7eb2e8f9f7 2019 *
<> 144:ef7eb2e8f9f7 2020 * This function should be copied to RAM for execution to make sure that code works
<> 144:ef7eb2e8f9f7 2021 * properly even flash cache is disabled.
<> 144:ef7eb2e8f9f7 2022 * It is for flash-resident bootloader only, not technically required for ROM or
<> 144:ef7eb2e8f9f7 2023 * flashloader (RAM-resident bootloader).
<> 144:ef7eb2e8f9f7 2024 */
<> 144:ef7eb2e8f9f7 2025 void flash_cache_clear_command(FTFx_REG32_ACCESS_TYPE ftfx_reg)
<> 144:ef7eb2e8f9f7 2026 {
<> 144:ef7eb2e8f9f7 2027 #if defined(FSL_FEATURE_FLASH_HAS_MCM_FLASH_CACHE_CONTROLS) && FSL_FEATURE_FLASH_HAS_MCM_FLASH_CACHE_CONTROLS
<> 144:ef7eb2e8f9f7 2028 *ftfx_reg |= MCM_PLACR_CFCC_MASK;
<> 144:ef7eb2e8f9f7 2029 #elif defined(FSL_FEATURE_FLASH_HAS_FMC_FLASH_CACHE_CONTROLS) && FSL_FEATURE_FLASH_HAS_FMC_FLASH_CACHE_CONTROLS
<> 144:ef7eb2e8f9f7 2030 #if defined(FMC_PFB01CR_CINV_WAY_MASK)
<> 144:ef7eb2e8f9f7 2031 *ftfx_reg = (*ftfx_reg & ~FMC_PFB01CR_CINV_WAY_MASK) | FMC_PFB01CR_CINV_WAY(~0);
<> 144:ef7eb2e8f9f7 2032 #else
<> 144:ef7eb2e8f9f7 2033 *ftfx_reg = (*ftfx_reg & ~FMC_PFB0CR_CINV_WAY_MASK) | FMC_PFB0CR_CINV_WAY(~0);
<> 144:ef7eb2e8f9f7 2034 #endif
<> 144:ef7eb2e8f9f7 2035 #elif defined(FSL_FEATURE_FLASH_HAS_MSCM_FLASH_CACHE_CONTROLS) && FSL_FEATURE_FLASH_HAS_MSCM_FLASH_CACHE_CONTROLS
<> 144:ef7eb2e8f9f7 2036 *ftfx_reg |= MSCM_OCMDR_OCMC1(2);
<> 144:ef7eb2e8f9f7 2037 *ftfx_reg |= MSCM_OCMDR_OCMC1(1);
<> 144:ef7eb2e8f9f7 2038 #else
<> 144:ef7eb2e8f9f7 2039 /* #error "Unknown flash cache controller" */
<> 144:ef7eb2e8f9f7 2040 #endif /* FSL_FEATURE_FTFx_MCM_FLASH_CACHE_CONTROLS */
<> 144:ef7eb2e8f9f7 2041 /* Memory barriers for good measure.
<> 144:ef7eb2e8f9f7 2042 * All Cache, Branch predictor and TLB maintenance operations before this instruction complete */
<> 144:ef7eb2e8f9f7 2043 __ISB();
<> 144:ef7eb2e8f9f7 2044 __DSB();
<> 144:ef7eb2e8f9f7 2045 }
<> 144:ef7eb2e8f9f7 2046
<> 144:ef7eb2e8f9f7 2047 /*!
<> 144:ef7eb2e8f9f7 2048 * @brief Be used for determining the size of flash_cache_clear_command()
<> 144:ef7eb2e8f9f7 2049 *
<> 144:ef7eb2e8f9f7 2050 * This function must be defined that lexically follows flash_cache_clear_command(),
<> 144:ef7eb2e8f9f7 2051 * so we can determine the size of flash_cache_clear_command() at runtime and not worry
<> 144:ef7eb2e8f9f7 2052 * about toolchain or code generation differences.
<> 144:ef7eb2e8f9f7 2053 */
<> 144:ef7eb2e8f9f7 2054 void flash_cache_clear_command_end(void)
<> 144:ef7eb2e8f9f7 2055 {
<> 144:ef7eb2e8f9f7 2056 }
<> 144:ef7eb2e8f9f7 2057
<> 144:ef7eb2e8f9f7 2058 /*!
<> 144:ef7eb2e8f9f7 2059 * @brief Copy flash_cache_clear_command() to RAM
<> 144:ef7eb2e8f9f7 2060 *
<> 144:ef7eb2e8f9f7 2061 * This function copys the memory between flash_cache_clear_command() and flash_cache_clear_command_end()
<> 144:ef7eb2e8f9f7 2062 * into the buffer which is also means that copying flash_cache_clear_command() to RAM.
<> 144:ef7eb2e8f9f7 2063 */
<> 144:ef7eb2e8f9f7 2064 static void copy_flash_cache_clear_command(uint8_t *flashCacheClearCommand)
<> 144:ef7eb2e8f9f7 2065 {
<> 144:ef7eb2e8f9f7 2066 /* Calculate the valid length of flash_cache_clear_command() memory.
<> 144:ef7eb2e8f9f7 2067 * Set max size(64 bytes) as default function size, in case some compiler allocates
<> 144:ef7eb2e8f9f7 2068 * flash_cache_clear_command_end ahead of flash_cache_clear_command. */
<> 144:ef7eb2e8f9f7 2069 uint32_t funcLength = kFLASH_executeInRamFunctionMaxSize;
<> 144:ef7eb2e8f9f7 2070 uint32_t flash_cache_clear_command_start_addr = (uint32_t)flash_cache_clear_command & (~1U);
<> 144:ef7eb2e8f9f7 2071 uint32_t flash_cache_clear_command_end_addr = (uint32_t)flash_cache_clear_command_end & (~1U);
<> 144:ef7eb2e8f9f7 2072 if (flash_cache_clear_command_end_addr > flash_cache_clear_command_start_addr)
<> 144:ef7eb2e8f9f7 2073 {
<> 144:ef7eb2e8f9f7 2074 funcLength = flash_cache_clear_command_end_addr - flash_cache_clear_command_start_addr;
<> 144:ef7eb2e8f9f7 2075
<> 144:ef7eb2e8f9f7 2076 assert(funcLength <= kFLASH_executeInRamFunctionMaxSize);
<> 144:ef7eb2e8f9f7 2077
<> 144:ef7eb2e8f9f7 2078 /* In case some compiler allocates other function in the middle of flash_cache_clear_command
<> 144:ef7eb2e8f9f7 2079 * and flash_cache_clear_command_end. */
<> 144:ef7eb2e8f9f7 2080 if (funcLength > kFLASH_executeInRamFunctionMaxSize)
<> 144:ef7eb2e8f9f7 2081 {
<> 144:ef7eb2e8f9f7 2082 funcLength = kFLASH_executeInRamFunctionMaxSize;
<> 144:ef7eb2e8f9f7 2083 }
<> 144:ef7eb2e8f9f7 2084 }
<> 144:ef7eb2e8f9f7 2085
<> 144:ef7eb2e8f9f7 2086 /* Since the value of ARM function pointer is always odd, but the real start address
<> 144:ef7eb2e8f9f7 2087 * of function memory should be even, that's why -1 and +1 operation exist. */
<> 144:ef7eb2e8f9f7 2088 memcpy((void *)flashCacheClearCommand, (void *)flash_cache_clear_command_start_addr, funcLength);
<> 144:ef7eb2e8f9f7 2089 callFlashCacheClearCommand = (void (*)(FTFx_REG32_ACCESS_TYPE ftfx_reg))((uint32_t)flashCacheClearCommand + 1);
<> 144:ef7eb2e8f9f7 2090 }
<> 144:ef7eb2e8f9f7 2091 #endif /* FLASH_DRIVER_IS_FLASH_RESIDENT */
<> 144:ef7eb2e8f9f7 2092
<> 144:ef7eb2e8f9f7 2093 /*!
<> 144:ef7eb2e8f9f7 2094 * @brief Flash Cache Clear
<> 144:ef7eb2e8f9f7 2095 *
<> 144:ef7eb2e8f9f7 2096 * This function is used to perform the cache clear to the flash.
<> 144:ef7eb2e8f9f7 2097 */
<> 144:ef7eb2e8f9f7 2098 #if (defined(__GNUC__))
<> 144:ef7eb2e8f9f7 2099 /* #pragma GCC push_options */
<> 144:ef7eb2e8f9f7 2100 /* #pragma GCC optimize("O0") */
<> 144:ef7eb2e8f9f7 2101 void __attribute__((optimize("O0"))) flash_cache_clear(flash_config_t *config)
<> 144:ef7eb2e8f9f7 2102 #else
<> 144:ef7eb2e8f9f7 2103 #if (defined(__ICCARM__))
<> 144:ef7eb2e8f9f7 2104 #pragma optimize = none
<> 144:ef7eb2e8f9f7 2105 #endif
<> 144:ef7eb2e8f9f7 2106 #if (defined(__CC_ARM))
<> 144:ef7eb2e8f9f7 2107 #pragma push
<> 144:ef7eb2e8f9f7 2108 #pragma O0
<> 144:ef7eb2e8f9f7 2109 #endif
<> 144:ef7eb2e8f9f7 2110 void flash_cache_clear(flash_config_t *config)
<> 144:ef7eb2e8f9f7 2111 #endif
<> 144:ef7eb2e8f9f7 2112 {
<> 144:ef7eb2e8f9f7 2113 #if FLASH_DRIVER_IS_FLASH_RESIDENT
<> 144:ef7eb2e8f9f7 2114 status_t returnCode = flash_check_execute_in_ram_function_info(config);
<> 144:ef7eb2e8f9f7 2115 if (kStatus_FLASH_Success != returnCode)
<> 144:ef7eb2e8f9f7 2116 {
<> 144:ef7eb2e8f9f7 2117 return;
<> 144:ef7eb2e8f9f7 2118 }
<> 144:ef7eb2e8f9f7 2119
<> 144:ef7eb2e8f9f7 2120 /* We pass the ftfx register address as a parameter to flash_cache_clear_comamnd() instead of using
<> 144:ef7eb2e8f9f7 2121 * pre-processed MACROs or a global variable in flash_cache_clear_comamnd()
<> 144:ef7eb2e8f9f7 2122 * to make sure that flash_cache_clear_command() will be compiled into position-independent code (PIC). */
<> 144:ef7eb2e8f9f7 2123 #if defined(FSL_FEATURE_FLASH_HAS_MCM_FLASH_CACHE_CONTROLS) && FSL_FEATURE_FLASH_HAS_MCM_FLASH_CACHE_CONTROLS
<> 144:ef7eb2e8f9f7 2124 #if defined(MCM)
<> 144:ef7eb2e8f9f7 2125 callFlashCacheClearCommand((FTFx_REG32_ACCESS_TYPE)&MCM->PLACR);
<> 144:ef7eb2e8f9f7 2126 #endif
<> 144:ef7eb2e8f9f7 2127 #if defined(MCM0)
<> 144:ef7eb2e8f9f7 2128 callFlashCacheClearCommand((FTFx_REG32_ACCESS_TYPE)&MCM0->PLACR);
<> 144:ef7eb2e8f9f7 2129 #endif
<> 144:ef7eb2e8f9f7 2130 #if defined(MCM1)
<> 144:ef7eb2e8f9f7 2131 callFlashCacheClearCommand((FTFx_REG32_ACCESS_TYPE)&MCM1->PLACR);
<> 144:ef7eb2e8f9f7 2132 #endif
<> 144:ef7eb2e8f9f7 2133 #elif defined(FSL_FEATURE_FLASH_HAS_FMC_FLASH_CACHE_CONTROLS) && FSL_FEATURE_FLASH_HAS_FMC_FLASH_CACHE_CONTROLS
<> 144:ef7eb2e8f9f7 2134 #if defined(FMC_PFB01CR_CINV_WAY_MASK)
<> 144:ef7eb2e8f9f7 2135 callFlashCacheClearCommand((FTFx_REG32_ACCESS_TYPE)&FMC->PFB01CR);
<> 144:ef7eb2e8f9f7 2136 #else
<> 144:ef7eb2e8f9f7 2137 callFlashCacheClearCommand((FTFx_REG32_ACCESS_TYPE)&FMC->PFB0CR);
<> 144:ef7eb2e8f9f7 2138 #endif
<> 144:ef7eb2e8f9f7 2139 #elif defined(FSL_FEATURE_FLASH_HAS_MSCM_FLASH_CACHE_CONTROLS) && FSL_FEATURE_FLASH_HAS_MSCM_FLASH_CACHE_CONTROLS
<> 144:ef7eb2e8f9f7 2140 callFlashCacheClearCommand((FTFx_REG32_ACCESS_TYPE)&MSCM->OCMDR[0]);
<> 144:ef7eb2e8f9f7 2141 #else
<> 144:ef7eb2e8f9f7 2142 /* #error "Unknown flash cache controller" */
<> 144:ef7eb2e8f9f7 2143 /* meaningless code, just a workaround to solve warning*/
<> 144:ef7eb2e8f9f7 2144 callFlashCacheClearCommand((FTFx_REG32_ACCESS_TYPE)0);
<> 144:ef7eb2e8f9f7 2145 #endif /* FSL_FEATURE_FTFx_MCM_FLASH_CACHE_CONTROLS */
<> 144:ef7eb2e8f9f7 2146
<> 144:ef7eb2e8f9f7 2147 #else
<> 144:ef7eb2e8f9f7 2148
<> 144:ef7eb2e8f9f7 2149 #if defined(FSL_FEATURE_FLASH_HAS_MCM_FLASH_CACHE_CONTROLS) && FSL_FEATURE_FLASH_HAS_MCM_FLASH_CACHE_CONTROLS
<> 144:ef7eb2e8f9f7 2150 #if defined(MCM)
<> 144:ef7eb2e8f9f7 2151 MCM->PLACR |= MCM_PLACR_CFCC_MASK;
<> 144:ef7eb2e8f9f7 2152 #endif
<> 144:ef7eb2e8f9f7 2153 #if defined(MCM0)
<> 144:ef7eb2e8f9f7 2154 MCM0->PLACR |= MCM_PLACR_CFCC_MASK;
<> 144:ef7eb2e8f9f7 2155 #endif
<> 144:ef7eb2e8f9f7 2156 #if defined(MCM1)
<> 144:ef7eb2e8f9f7 2157 MCM1->PLACR |= MCM_PLACR_CFCC_MASK;
<> 144:ef7eb2e8f9f7 2158 #endif
<> 144:ef7eb2e8f9f7 2159 #elif defined(FSL_FEATURE_FLASH_HAS_FMC_FLASH_CACHE_CONTROLS) && FSL_FEATURE_FLASH_HAS_FMC_FLASH_CACHE_CONTROLS
<> 144:ef7eb2e8f9f7 2160 #if defined(FMC_PFB01CR_CINV_WAY_MASK)
<> 144:ef7eb2e8f9f7 2161 FMC->PFB01CR = (FMC->PFB01CR & ~FMC_PFB01CR_CINV_WAY_MASK) | FMC_PFB01CR_CINV_WAY(~0);
<> 144:ef7eb2e8f9f7 2162 #else
<> 144:ef7eb2e8f9f7 2163 FMC->PFB0CR = (FMC->PFB0CR & ~FMC_PFB0CR_CINV_WAY_MASK) | FMC_PFB0CR_CINV_WAY(~0);
<> 144:ef7eb2e8f9f7 2164 #endif
<> 144:ef7eb2e8f9f7 2165 #elif defined(FSL_FEATURE_FLASH_HAS_MSCM_FLASH_CACHE_CONTROLS) && FSL_FEATURE_FLASH_HAS_MSCM_FLASH_CACHE_CONTROLS
<> 144:ef7eb2e8f9f7 2166 MSCM->OCMDR[0] |= MSCM_OCMDR_OCMC1(2);
<> 144:ef7eb2e8f9f7 2167 MSCM->OCMDR[0] |= MSCM_OCMDR_OCMC1(1);
<> 144:ef7eb2e8f9f7 2168 #else
<> 144:ef7eb2e8f9f7 2169 /* #error "Unknown flash cache controller" */
<> 144:ef7eb2e8f9f7 2170 #endif /* FSL_FEATURE_FTFx_MCM_FLASH_CACHE_CONTROLS */
<> 144:ef7eb2e8f9f7 2171 #endif /* FLASH_DRIVER_IS_FLASH_RESIDENT */
<> 144:ef7eb2e8f9f7 2172 }
<> 144:ef7eb2e8f9f7 2173 #if (defined(__CC_ARM))
<> 144:ef7eb2e8f9f7 2174 #pragma pop
<> 144:ef7eb2e8f9f7 2175 #endif
<> 144:ef7eb2e8f9f7 2176 #if (defined(__GNUC__))
<> 144:ef7eb2e8f9f7 2177 /* #pragma GCC pop_options */
<> 144:ef7eb2e8f9f7 2178 #endif
<> 144:ef7eb2e8f9f7 2179
<> 144:ef7eb2e8f9f7 2180 #if FLASH_DRIVER_IS_FLASH_RESIDENT
<> 144:ef7eb2e8f9f7 2181 /*! @brief Check whether flash execute-in-ram functions are ready */
<> 144:ef7eb2e8f9f7 2182 static status_t flash_check_execute_in_ram_function_info(flash_config_t *config)
<> 144:ef7eb2e8f9f7 2183 {
<> 144:ef7eb2e8f9f7 2184 flash_execute_in_ram_function_config_t *flashExecuteInRamFunctionInfo;
<> 144:ef7eb2e8f9f7 2185
<> 144:ef7eb2e8f9f7 2186 if (config == NULL)
<> 144:ef7eb2e8f9f7 2187 {
<> 144:ef7eb2e8f9f7 2188 return kStatus_FLASH_InvalidArgument;
<> 144:ef7eb2e8f9f7 2189 }
<> 144:ef7eb2e8f9f7 2190
<> 144:ef7eb2e8f9f7 2191 flashExecuteInRamFunctionInfo = (flash_execute_in_ram_function_config_t *)config->flashExecuteInRamFunctionInfo;
<> 144:ef7eb2e8f9f7 2192
<> 144:ef7eb2e8f9f7 2193 if ((config->flashExecuteInRamFunctionInfo) &&
<> 144:ef7eb2e8f9f7 2194 (kFLASH_executeInRamFunctionTotalNum == flashExecuteInRamFunctionInfo->activeFunctionCount))
<> 144:ef7eb2e8f9f7 2195 {
<> 144:ef7eb2e8f9f7 2196 return kStatus_FLASH_Success;
<> 144:ef7eb2e8f9f7 2197 }
<> 144:ef7eb2e8f9f7 2198
<> 144:ef7eb2e8f9f7 2199 return kStatus_FLASH_ExecuteInRamFunctionNotReady;
<> 144:ef7eb2e8f9f7 2200 }
<> 144:ef7eb2e8f9f7 2201 #endif /* FLASH_DRIVER_IS_FLASH_RESIDENT */
<> 144:ef7eb2e8f9f7 2202
<> 144:ef7eb2e8f9f7 2203 /*! @brief Validates the range and alignment of the given address range.*/
<> 144:ef7eb2e8f9f7 2204 static status_t flash_check_range(flash_config_t *config,
<> 144:ef7eb2e8f9f7 2205 uint32_t startAddress,
<> 144:ef7eb2e8f9f7 2206 uint32_t lengthInBytes,
<> 144:ef7eb2e8f9f7 2207 uint32_t alignmentBaseline)
<> 144:ef7eb2e8f9f7 2208 {
<> 144:ef7eb2e8f9f7 2209 if (config == NULL)
<> 144:ef7eb2e8f9f7 2210 {
<> 144:ef7eb2e8f9f7 2211 return kStatus_FLASH_InvalidArgument;
<> 144:ef7eb2e8f9f7 2212 }
<> 144:ef7eb2e8f9f7 2213
<> 144:ef7eb2e8f9f7 2214 /* Verify the start and length are alignmentBaseline aligned. */
<> 144:ef7eb2e8f9f7 2215 if ((startAddress & (alignmentBaseline - 1)) || (lengthInBytes & (alignmentBaseline - 1)))
<> 144:ef7eb2e8f9f7 2216 {
<> 144:ef7eb2e8f9f7 2217 return kStatus_FLASH_AlignmentError;
<> 144:ef7eb2e8f9f7 2218 }
<> 144:ef7eb2e8f9f7 2219
<> 144:ef7eb2e8f9f7 2220 /* check for valid range of the target addresses */
<> 144:ef7eb2e8f9f7 2221 #if !FLASH_SSD_IS_FLEXNVM_ENABLED
<> 144:ef7eb2e8f9f7 2222 if ((startAddress < config->PFlashBlockBase) ||
<> 144:ef7eb2e8f9f7 2223 ((startAddress + lengthInBytes) > (config->PFlashBlockBase + config->PFlashTotalSize)))
<> 144:ef7eb2e8f9f7 2224 #else
<> 144:ef7eb2e8f9f7 2225 if (!(((startAddress >= config->PFlashBlockBase) &&
<> 144:ef7eb2e8f9f7 2226 ((startAddress + lengthInBytes) <= (config->PFlashBlockBase + config->PFlashTotalSize))) ||
<> 144:ef7eb2e8f9f7 2227 ((startAddress >= config->DFlashBlockBase) &&
<> 144:ef7eb2e8f9f7 2228 ((startAddress + lengthInBytes) <= (config->DFlashBlockBase + config->DFlashTotalSize)))))
<> 144:ef7eb2e8f9f7 2229 #endif
<> 144:ef7eb2e8f9f7 2230 {
<> 144:ef7eb2e8f9f7 2231 return kStatus_FLASH_AddressError;
<> 144:ef7eb2e8f9f7 2232 }
<> 144:ef7eb2e8f9f7 2233
<> 144:ef7eb2e8f9f7 2234 return kStatus_FLASH_Success;
<> 144:ef7eb2e8f9f7 2235 }
<> 144:ef7eb2e8f9f7 2236
<> 144:ef7eb2e8f9f7 2237 /*! @brief Gets the right address, sector and block size of current flash type which is indicated by address.*/
<> 144:ef7eb2e8f9f7 2238 static status_t flash_get_matched_operation_info(flash_config_t *config,
<> 144:ef7eb2e8f9f7 2239 uint32_t address,
<> 144:ef7eb2e8f9f7 2240 flash_operation_config_t *info)
<> 144:ef7eb2e8f9f7 2241 {
<> 144:ef7eb2e8f9f7 2242 if (config == NULL)
<> 144:ef7eb2e8f9f7 2243 {
<> 144:ef7eb2e8f9f7 2244 return kStatus_FLASH_InvalidArgument;
<> 144:ef7eb2e8f9f7 2245 }
<> 144:ef7eb2e8f9f7 2246
<> 144:ef7eb2e8f9f7 2247 /* Clean up info Structure*/
<> 144:ef7eb2e8f9f7 2248 memset(info, 0, sizeof(flash_operation_config_t));
<> 144:ef7eb2e8f9f7 2249
<> 144:ef7eb2e8f9f7 2250 #if FLASH_SSD_IS_FLEXNVM_ENABLED
<> 144:ef7eb2e8f9f7 2251 if ((address >= config->DFlashBlockBase) && (address <= (config->DFlashBlockBase + config->DFlashTotalSize)))
<> 144:ef7eb2e8f9f7 2252 {
<> 144:ef7eb2e8f9f7 2253 info->convertedAddress = address - config->DFlashBlockBase + 0x800000U;
<> 144:ef7eb2e8f9f7 2254 info->activeSectorSize = FSL_FEATURE_FLASH_FLEX_NVM_BLOCK_SECTOR_SIZE;
<> 144:ef7eb2e8f9f7 2255 info->activeBlockSize = config->DFlashTotalSize / FSL_FEATURE_FLASH_FLEX_NVM_BLOCK_COUNT;
<> 144:ef7eb2e8f9f7 2256
<> 144:ef7eb2e8f9f7 2257 info->blockWriteUnitSize = FSL_FEATURE_FLASH_FLEX_NVM_BLOCK_WRITE_UNIT_SIZE;
<> 144:ef7eb2e8f9f7 2258 info->sectorCmdAddressAligment = FSL_FEATURE_FLASH_FLEX_NVM_SECTOR_CMD_ADDRESS_ALIGMENT;
<> 144:ef7eb2e8f9f7 2259 info->sectionCmdAddressAligment = FSL_FEATURE_FLASH_FLEX_NVM_SECTION_CMD_ADDRESS_ALIGMENT;
<> 144:ef7eb2e8f9f7 2260 info->resourceCmdAddressAligment = FSL_FEATURE_FLASH_FLEX_NVM_RESOURCE_CMD_ADDRESS_ALIGMENT;
<> 144:ef7eb2e8f9f7 2261 info->checkCmdAddressAligment = FSL_FEATURE_FLASH_FLEX_NVM_CHECK_CMD_ADDRESS_ALIGMENT;
<> 144:ef7eb2e8f9f7 2262 }
<> 144:ef7eb2e8f9f7 2263 else
<> 144:ef7eb2e8f9f7 2264 #endif /* FLASH_SSD_IS_FLEXNVM_ENABLED */
<> 144:ef7eb2e8f9f7 2265 {
<> 144:ef7eb2e8f9f7 2266 info->convertedAddress = address;
<> 144:ef7eb2e8f9f7 2267 info->activeSectorSize = config->PFlashSectorSize;
<> 144:ef7eb2e8f9f7 2268 info->activeBlockSize = config->PFlashTotalSize / config->PFlashBlockCount;
<> 144:ef7eb2e8f9f7 2269
<> 144:ef7eb2e8f9f7 2270 info->blockWriteUnitSize = FSL_FEATURE_FLASH_PFLASH_BLOCK_WRITE_UNIT_SIZE;
<> 144:ef7eb2e8f9f7 2271 info->sectorCmdAddressAligment = FSL_FEATURE_FLASH_PFLASH_SECTOR_CMD_ADDRESS_ALIGMENT;
<> 144:ef7eb2e8f9f7 2272 info->sectionCmdAddressAligment = FSL_FEATURE_FLASH_PFLASH_SECTION_CMD_ADDRESS_ALIGMENT;
<> 144:ef7eb2e8f9f7 2273 info->resourceCmdAddressAligment = FSL_FEATURE_FLASH_PFLASH_RESOURCE_CMD_ADDRESS_ALIGMENT;
<> 144:ef7eb2e8f9f7 2274 info->checkCmdAddressAligment = FSL_FEATURE_FLASH_PFLASH_CHECK_CMD_ADDRESS_ALIGMENT;
<> 144:ef7eb2e8f9f7 2275 }
<> 144:ef7eb2e8f9f7 2276
<> 144:ef7eb2e8f9f7 2277 return kStatus_FLASH_Success;
<> 144:ef7eb2e8f9f7 2278 }
<> 144:ef7eb2e8f9f7 2279
<> 144:ef7eb2e8f9f7 2280 /*! @brief Validates the given user key for flash erase APIs.*/
<> 144:ef7eb2e8f9f7 2281 static status_t flash_check_user_key(uint32_t key)
<> 144:ef7eb2e8f9f7 2282 {
<> 144:ef7eb2e8f9f7 2283 /* Validate the user key */
<> 144:ef7eb2e8f9f7 2284 if (key != kFLASH_apiEraseKey)
<> 144:ef7eb2e8f9f7 2285 {
<> 144:ef7eb2e8f9f7 2286 return kStatus_FLASH_EraseKeyError;
<> 144:ef7eb2e8f9f7 2287 }
<> 144:ef7eb2e8f9f7 2288
<> 144:ef7eb2e8f9f7 2289 return kStatus_FLASH_Success;
<> 144:ef7eb2e8f9f7 2290 }
<> 144:ef7eb2e8f9f7 2291
<> 144:ef7eb2e8f9f7 2292 #if FLASH_SSD_IS_FLEXNVM_ENABLED
<> 144:ef7eb2e8f9f7 2293 /*! @brief Updates FlexNVM memory partition status according to data flash 0 IFR.*/
<> 144:ef7eb2e8f9f7 2294 static status_t flash_update_flexnvm_memory_partition_status(flash_config_t *config)
<> 144:ef7eb2e8f9f7 2295 {
<> 144:ef7eb2e8f9f7 2296 struct
<> 144:ef7eb2e8f9f7 2297 {
<> 144:ef7eb2e8f9f7 2298 uint32_t reserved0;
<> 144:ef7eb2e8f9f7 2299 uint8_t FlexNVMPartitionCode;
<> 144:ef7eb2e8f9f7 2300 uint8_t EEPROMDataSetSize;
<> 144:ef7eb2e8f9f7 2301 uint16_t reserved1;
<> 144:ef7eb2e8f9f7 2302 } dataIFRReadOut;
<> 144:ef7eb2e8f9f7 2303 status_t returnCode;
<> 144:ef7eb2e8f9f7 2304
<> 144:ef7eb2e8f9f7 2305 if (config == NULL)
<> 144:ef7eb2e8f9f7 2306 {
<> 144:ef7eb2e8f9f7 2307 return kStatus_FLASH_InvalidArgument;
<> 144:ef7eb2e8f9f7 2308 }
<> 144:ef7eb2e8f9f7 2309
<> 144:ef7eb2e8f9f7 2310 /* Get FlexNVM memory partition info from data flash IFR */
<> 144:ef7eb2e8f9f7 2311 returnCode = FLASH_ReadResource(config, DFLASH_IFR_READRESOURCE_START_ADDRESS, (uint32_t *)&dataIFRReadOut,
<> 144:ef7eb2e8f9f7 2312 sizeof(dataIFRReadOut), kFLASH_resourceOptionFlashIfr);
<> 144:ef7eb2e8f9f7 2313 if (returnCode != kStatus_FLASH_Success)
<> 144:ef7eb2e8f9f7 2314 {
<> 144:ef7eb2e8f9f7 2315 return kStatus_FLASH_PartitionStatusUpdateFailure;
<> 144:ef7eb2e8f9f7 2316 }
<> 144:ef7eb2e8f9f7 2317
<> 144:ef7eb2e8f9f7 2318 /* Fill out partitioned EEPROM size */
<> 144:ef7eb2e8f9f7 2319 dataIFRReadOut.EEPROMDataSetSize &= 0x0FU;
<> 144:ef7eb2e8f9f7 2320 switch (dataIFRReadOut.EEPROMDataSetSize)
<> 144:ef7eb2e8f9f7 2321 {
<> 144:ef7eb2e8f9f7 2322 case 0x00U:
<> 144:ef7eb2e8f9f7 2323 config->EEpromTotalSize = FSL_FEATURE_FLASH_FLEX_NVM_EEPROM_SIZE_FOR_EEESIZE_0000;
<> 144:ef7eb2e8f9f7 2324 break;
<> 144:ef7eb2e8f9f7 2325 case 0x01U:
<> 144:ef7eb2e8f9f7 2326 config->EEpromTotalSize = FSL_FEATURE_FLASH_FLEX_NVM_EEPROM_SIZE_FOR_EEESIZE_0001;
<> 144:ef7eb2e8f9f7 2327 break;
<> 144:ef7eb2e8f9f7 2328 case 0x02U:
<> 144:ef7eb2e8f9f7 2329 config->EEpromTotalSize = FSL_FEATURE_FLASH_FLEX_NVM_EEPROM_SIZE_FOR_EEESIZE_0010;
<> 144:ef7eb2e8f9f7 2330 break;
<> 144:ef7eb2e8f9f7 2331 case 0x03U:
<> 144:ef7eb2e8f9f7 2332 config->EEpromTotalSize = FSL_FEATURE_FLASH_FLEX_NVM_EEPROM_SIZE_FOR_EEESIZE_0011;
<> 144:ef7eb2e8f9f7 2333 break;
<> 144:ef7eb2e8f9f7 2334 case 0x04U:
<> 144:ef7eb2e8f9f7 2335 config->EEpromTotalSize = FSL_FEATURE_FLASH_FLEX_NVM_EEPROM_SIZE_FOR_EEESIZE_0100;
<> 144:ef7eb2e8f9f7 2336 break;
<> 144:ef7eb2e8f9f7 2337 case 0x05U:
<> 144:ef7eb2e8f9f7 2338 config->EEpromTotalSize = FSL_FEATURE_FLASH_FLEX_NVM_EEPROM_SIZE_FOR_EEESIZE_0101;
<> 144:ef7eb2e8f9f7 2339 break;
<> 144:ef7eb2e8f9f7 2340 case 0x06U:
<> 144:ef7eb2e8f9f7 2341 config->EEpromTotalSize = FSL_FEATURE_FLASH_FLEX_NVM_EEPROM_SIZE_FOR_EEESIZE_0110;
<> 144:ef7eb2e8f9f7 2342 break;
<> 144:ef7eb2e8f9f7 2343 case 0x07U:
<> 144:ef7eb2e8f9f7 2344 config->EEpromTotalSize = FSL_FEATURE_FLASH_FLEX_NVM_EEPROM_SIZE_FOR_EEESIZE_0111;
<> 144:ef7eb2e8f9f7 2345 break;
<> 144:ef7eb2e8f9f7 2346 case 0x08U:
<> 144:ef7eb2e8f9f7 2347 config->EEpromTotalSize = FSL_FEATURE_FLASH_FLEX_NVM_EEPROM_SIZE_FOR_EEESIZE_1000;
<> 144:ef7eb2e8f9f7 2348 break;
<> 144:ef7eb2e8f9f7 2349 case 0x09U:
<> 144:ef7eb2e8f9f7 2350 config->EEpromTotalSize = FSL_FEATURE_FLASH_FLEX_NVM_EEPROM_SIZE_FOR_EEESIZE_1001;
<> 144:ef7eb2e8f9f7 2351 break;
<> 144:ef7eb2e8f9f7 2352 case 0x0AU:
<> 144:ef7eb2e8f9f7 2353 config->EEpromTotalSize = FSL_FEATURE_FLASH_FLEX_NVM_EEPROM_SIZE_FOR_EEESIZE_1010;
<> 144:ef7eb2e8f9f7 2354 break;
<> 144:ef7eb2e8f9f7 2355 case 0x0BU:
<> 144:ef7eb2e8f9f7 2356 config->EEpromTotalSize = FSL_FEATURE_FLASH_FLEX_NVM_EEPROM_SIZE_FOR_EEESIZE_1011;
<> 144:ef7eb2e8f9f7 2357 break;
<> 144:ef7eb2e8f9f7 2358 case 0x0CU:
<> 144:ef7eb2e8f9f7 2359 config->EEpromTotalSize = FSL_FEATURE_FLASH_FLEX_NVM_EEPROM_SIZE_FOR_EEESIZE_1100;
<> 144:ef7eb2e8f9f7 2360 break;
<> 144:ef7eb2e8f9f7 2361 case 0x0DU:
<> 144:ef7eb2e8f9f7 2362 config->EEpromTotalSize = FSL_FEATURE_FLASH_FLEX_NVM_EEPROM_SIZE_FOR_EEESIZE_1101;
<> 144:ef7eb2e8f9f7 2363 break;
<> 144:ef7eb2e8f9f7 2364 case 0x0EU:
<> 144:ef7eb2e8f9f7 2365 config->EEpromTotalSize = FSL_FEATURE_FLASH_FLEX_NVM_EEPROM_SIZE_FOR_EEESIZE_1110;
<> 144:ef7eb2e8f9f7 2366 break;
<> 144:ef7eb2e8f9f7 2367 case 0x0FU:
<> 144:ef7eb2e8f9f7 2368 config->EEpromTotalSize = FSL_FEATURE_FLASH_FLEX_NVM_EEPROM_SIZE_FOR_EEESIZE_1111;
<> 144:ef7eb2e8f9f7 2369 break;
<> 144:ef7eb2e8f9f7 2370 default:
<> 144:ef7eb2e8f9f7 2371 config->EEpromTotalSize = FLEX_NVM_EEPROM_SIZE_FOR_EEESIZE_RESERVED;
<> 144:ef7eb2e8f9f7 2372 break;
<> 144:ef7eb2e8f9f7 2373 }
<> 144:ef7eb2e8f9f7 2374
<> 144:ef7eb2e8f9f7 2375 /* Fill out partitioned DFlash size */
<> 144:ef7eb2e8f9f7 2376 dataIFRReadOut.FlexNVMPartitionCode &= 0x0FU;
<> 144:ef7eb2e8f9f7 2377 switch (dataIFRReadOut.FlexNVMPartitionCode)
<> 144:ef7eb2e8f9f7 2378 {
<> 144:ef7eb2e8f9f7 2379 case 0x00U:
<> 144:ef7eb2e8f9f7 2380 #if (FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_0000 != 0xFFFFFFFF)
<> 144:ef7eb2e8f9f7 2381 config->DFlashTotalSize = FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_0000;
<> 144:ef7eb2e8f9f7 2382 #else
<> 144:ef7eb2e8f9f7 2383 config->DFlashTotalSize = FLEX_NVM_DFLASH_SIZE_FOR_DEPART_RESERVED;
<> 144:ef7eb2e8f9f7 2384 #endif /* FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_0000 */
<> 144:ef7eb2e8f9f7 2385 break;
<> 144:ef7eb2e8f9f7 2386 case 0x01U:
<> 144:ef7eb2e8f9f7 2387 #if (FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_0001 != 0xFFFFFFFF)
<> 144:ef7eb2e8f9f7 2388 config->DFlashTotalSize = FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_0001;
<> 144:ef7eb2e8f9f7 2389 #else
<> 144:ef7eb2e8f9f7 2390 config->DFlashTotalSize = FLEX_NVM_DFLASH_SIZE_FOR_DEPART_RESERVED;
<> 144:ef7eb2e8f9f7 2391 #endif /* FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_0001 */
<> 144:ef7eb2e8f9f7 2392 break;
<> 144:ef7eb2e8f9f7 2393 case 0x02U:
<> 144:ef7eb2e8f9f7 2394 #if (FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_0010 != 0xFFFFFFFF)
<> 144:ef7eb2e8f9f7 2395 config->DFlashTotalSize = FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_0010;
<> 144:ef7eb2e8f9f7 2396 #else
<> 144:ef7eb2e8f9f7 2397 config->DFlashTotalSize = FLEX_NVM_DFLASH_SIZE_FOR_DEPART_RESERVED;
<> 144:ef7eb2e8f9f7 2398 #endif /* FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_0010 */
<> 144:ef7eb2e8f9f7 2399 break;
<> 144:ef7eb2e8f9f7 2400 case 0x03U:
<> 144:ef7eb2e8f9f7 2401 #if (FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_0011 != 0xFFFFFFFF)
<> 144:ef7eb2e8f9f7 2402 config->DFlashTotalSize = FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_0011;
<> 144:ef7eb2e8f9f7 2403 #else
<> 144:ef7eb2e8f9f7 2404 config->DFlashTotalSize = FLEX_NVM_DFLASH_SIZE_FOR_DEPART_RESERVED;
<> 144:ef7eb2e8f9f7 2405 #endif /* FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_0011 */
<> 144:ef7eb2e8f9f7 2406 break;
<> 144:ef7eb2e8f9f7 2407 case 0x04U:
<> 144:ef7eb2e8f9f7 2408 #if (FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_0100 != 0xFFFFFFFF)
<> 144:ef7eb2e8f9f7 2409 config->DFlashTotalSize = FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_0100;
<> 144:ef7eb2e8f9f7 2410 #else
<> 144:ef7eb2e8f9f7 2411 config->DFlashTotalSize = FLEX_NVM_DFLASH_SIZE_FOR_DEPART_RESERVED;
<> 144:ef7eb2e8f9f7 2412 #endif /* FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_0100 */
<> 144:ef7eb2e8f9f7 2413 break;
<> 144:ef7eb2e8f9f7 2414 case 0x05U:
<> 144:ef7eb2e8f9f7 2415 #if (FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_0101 != 0xFFFFFFFF)
<> 144:ef7eb2e8f9f7 2416 config->DFlashTotalSize = FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_0101;
<> 144:ef7eb2e8f9f7 2417 #else
<> 144:ef7eb2e8f9f7 2418 config->DFlashTotalSize = FLEX_NVM_DFLASH_SIZE_FOR_DEPART_RESERVED;
<> 144:ef7eb2e8f9f7 2419 #endif /* FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_0101 */
<> 144:ef7eb2e8f9f7 2420 break;
<> 144:ef7eb2e8f9f7 2421 case 0x06U:
<> 144:ef7eb2e8f9f7 2422 #if (FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_0110 != 0xFFFFFFFF)
<> 144:ef7eb2e8f9f7 2423 config->DFlashTotalSize = FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_0110;
<> 144:ef7eb2e8f9f7 2424 #else
<> 144:ef7eb2e8f9f7 2425 config->DFlashTotalSize = FLEX_NVM_DFLASH_SIZE_FOR_DEPART_RESERVED;
<> 144:ef7eb2e8f9f7 2426 #endif /* FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_0110 */
<> 144:ef7eb2e8f9f7 2427 break;
<> 144:ef7eb2e8f9f7 2428 case 0x07U:
<> 144:ef7eb2e8f9f7 2429 #if (FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_0111 != 0xFFFFFFFF)
<> 144:ef7eb2e8f9f7 2430 config->DFlashTotalSize = FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_0111;
<> 144:ef7eb2e8f9f7 2431 #else
<> 144:ef7eb2e8f9f7 2432 config->DFlashTotalSize = FLEX_NVM_DFLASH_SIZE_FOR_DEPART_RESERVED;
<> 144:ef7eb2e8f9f7 2433 #endif /* FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_0111 */
<> 144:ef7eb2e8f9f7 2434 break;
<> 144:ef7eb2e8f9f7 2435 case 0x08U:
<> 144:ef7eb2e8f9f7 2436 #if (FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_1000 != 0xFFFFFFFF)
<> 144:ef7eb2e8f9f7 2437 config->DFlashTotalSize = FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_1000;
<> 144:ef7eb2e8f9f7 2438 #else
<> 144:ef7eb2e8f9f7 2439 config->DFlashTotalSize = FLEX_NVM_DFLASH_SIZE_FOR_DEPART_RESERVED;
<> 144:ef7eb2e8f9f7 2440 #endif /* FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_1000 */
<> 144:ef7eb2e8f9f7 2441 break;
<> 144:ef7eb2e8f9f7 2442 case 0x09U:
<> 144:ef7eb2e8f9f7 2443 #if (FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_1001 != 0xFFFFFFFF)
<> 144:ef7eb2e8f9f7 2444 config->DFlashTotalSize = FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_1001;
<> 144:ef7eb2e8f9f7 2445 #else
<> 144:ef7eb2e8f9f7 2446 config->DFlashTotalSize = FLEX_NVM_DFLASH_SIZE_FOR_DEPART_RESERVED;
<> 144:ef7eb2e8f9f7 2447 #endif /* FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_1001 */
<> 144:ef7eb2e8f9f7 2448 break;
<> 144:ef7eb2e8f9f7 2449 case 0x0AU:
<> 144:ef7eb2e8f9f7 2450 #if (FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_1010 != 0xFFFFFFFF)
<> 144:ef7eb2e8f9f7 2451 config->DFlashTotalSize = FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_1010;
<> 144:ef7eb2e8f9f7 2452 #else
<> 144:ef7eb2e8f9f7 2453 config->DFlashTotalSize = FLEX_NVM_DFLASH_SIZE_FOR_DEPART_RESERVED;
<> 144:ef7eb2e8f9f7 2454 #endif /* FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_1010 */
<> 144:ef7eb2e8f9f7 2455 break;
<> 144:ef7eb2e8f9f7 2456 case 0x0BU:
<> 144:ef7eb2e8f9f7 2457 #if (FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_1011 != 0xFFFFFFFF)
<> 144:ef7eb2e8f9f7 2458 config->DFlashTotalSize = FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_1011;
<> 144:ef7eb2e8f9f7 2459 #else
<> 144:ef7eb2e8f9f7 2460 config->DFlashTotalSize = FLEX_NVM_DFLASH_SIZE_FOR_DEPART_RESERVED;
<> 144:ef7eb2e8f9f7 2461 #endif /* FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_1011 */
<> 144:ef7eb2e8f9f7 2462 break;
<> 144:ef7eb2e8f9f7 2463 case 0x0CU:
<> 144:ef7eb2e8f9f7 2464 #if (FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_1100 != 0xFFFFFFFF)
<> 144:ef7eb2e8f9f7 2465 config->DFlashTotalSize = FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_1100;
<> 144:ef7eb2e8f9f7 2466 #else
<> 144:ef7eb2e8f9f7 2467 config->DFlashTotalSize = FLEX_NVM_DFLASH_SIZE_FOR_DEPART_RESERVED;
<> 144:ef7eb2e8f9f7 2468 #endif /* FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_1100 */
<> 144:ef7eb2e8f9f7 2469 break;
<> 144:ef7eb2e8f9f7 2470 case 0x0DU:
<> 144:ef7eb2e8f9f7 2471 #if (FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_1101 != 0xFFFFFFFF)
<> 144:ef7eb2e8f9f7 2472 config->DFlashTotalSize = FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_1101;
<> 144:ef7eb2e8f9f7 2473 #else
<> 144:ef7eb2e8f9f7 2474 config->DFlashTotalSize = FLEX_NVM_DFLASH_SIZE_FOR_DEPART_RESERVED;
<> 144:ef7eb2e8f9f7 2475 #endif /* FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_1101 */
<> 144:ef7eb2e8f9f7 2476 break;
<> 144:ef7eb2e8f9f7 2477 case 0x0EU:
<> 144:ef7eb2e8f9f7 2478 #if (FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_1110 != 0xFFFFFFFF)
<> 144:ef7eb2e8f9f7 2479 config->DFlashTotalSize = FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_1110;
<> 144:ef7eb2e8f9f7 2480 #else
<> 144:ef7eb2e8f9f7 2481 config->DFlashTotalSize = FLEX_NVM_DFLASH_SIZE_FOR_DEPART_RESERVED;
<> 144:ef7eb2e8f9f7 2482 #endif /* FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_1110 */
<> 144:ef7eb2e8f9f7 2483 break;
<> 144:ef7eb2e8f9f7 2484 case 0x0FU:
<> 144:ef7eb2e8f9f7 2485 #if (FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_1111 != 0xFFFFFFFF)
<> 144:ef7eb2e8f9f7 2486 config->DFlashTotalSize = FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_1111;
<> 144:ef7eb2e8f9f7 2487 #else
<> 144:ef7eb2e8f9f7 2488 config->DFlashTotalSize = FLEX_NVM_DFLASH_SIZE_FOR_DEPART_RESERVED;
<> 144:ef7eb2e8f9f7 2489 #endif /* FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_1111 */
<> 144:ef7eb2e8f9f7 2490 break;
<> 144:ef7eb2e8f9f7 2491 default:
<> 144:ef7eb2e8f9f7 2492 config->DFlashTotalSize = FLEX_NVM_DFLASH_SIZE_FOR_DEPART_RESERVED;
<> 144:ef7eb2e8f9f7 2493 break;
<> 144:ef7eb2e8f9f7 2494 }
<> 144:ef7eb2e8f9f7 2495
<> 144:ef7eb2e8f9f7 2496 return kStatus_FLASH_Success;
<> 144:ef7eb2e8f9f7 2497 }
<> 144:ef7eb2e8f9f7 2498 #endif /* FLASH_SSD_IS_FLEXNVM_ENABLED */
<> 144:ef7eb2e8f9f7 2499
<> 144:ef7eb2e8f9f7 2500 #if defined(FSL_FEATURE_FLASH_HAS_READ_RESOURCE_CMD) && FSL_FEATURE_FLASH_HAS_READ_RESOURCE_CMD
<> 144:ef7eb2e8f9f7 2501 /*! @brief Validates the range of the given resource address.*/
<> 144:ef7eb2e8f9f7 2502 static status_t flash_check_resource_range(uint32_t start,
<> 144:ef7eb2e8f9f7 2503 uint32_t lengthInBytes,
<> 144:ef7eb2e8f9f7 2504 uint32_t alignmentBaseline,
<> 144:ef7eb2e8f9f7 2505 flash_read_resource_option_t option)
<> 144:ef7eb2e8f9f7 2506 {
<> 144:ef7eb2e8f9f7 2507 status_t status;
<> 144:ef7eb2e8f9f7 2508 uint32_t maxReadbleAddress;
<> 144:ef7eb2e8f9f7 2509
<> 144:ef7eb2e8f9f7 2510 if ((start & (alignmentBaseline - 1)) || (lengthInBytes & (alignmentBaseline - 1)))
<> 144:ef7eb2e8f9f7 2511 {
<> 144:ef7eb2e8f9f7 2512 return kStatus_FLASH_AlignmentError;
<> 144:ef7eb2e8f9f7 2513 }
<> 144:ef7eb2e8f9f7 2514
<> 144:ef7eb2e8f9f7 2515 status = kStatus_FLASH_Success;
<> 144:ef7eb2e8f9f7 2516
<> 144:ef7eb2e8f9f7 2517 maxReadbleAddress = start + lengthInBytes - 1;
<> 144:ef7eb2e8f9f7 2518 if (option == kFLASH_resourceOptionVersionId)
<> 144:ef7eb2e8f9f7 2519 {
<> 144:ef7eb2e8f9f7 2520 if ((start != kFLASH_resourceRangeVersionIdStart) ||
<> 144:ef7eb2e8f9f7 2521 ((start + lengthInBytes - 1) != kFLASH_resourceRangeVersionIdEnd))
<> 144:ef7eb2e8f9f7 2522 {
<> 144:ef7eb2e8f9f7 2523 status = kStatus_FLASH_InvalidArgument;
<> 144:ef7eb2e8f9f7 2524 }
<> 144:ef7eb2e8f9f7 2525 }
<> 144:ef7eb2e8f9f7 2526 else if (option == kFLASH_resourceOptionFlashIfr)
<> 144:ef7eb2e8f9f7 2527 {
<> 144:ef7eb2e8f9f7 2528 if (maxReadbleAddress < kFLASH_resourceRangePflashIfrSizeInBytes)
<> 144:ef7eb2e8f9f7 2529 {
<> 144:ef7eb2e8f9f7 2530 }
<> 144:ef7eb2e8f9f7 2531 #if defined(FSL_FEATURE_FLASH_HAS_PFLASH_BLOCK_SWAP) && FSL_FEATURE_FLASH_HAS_PFLASH_BLOCK_SWAP
<> 144:ef7eb2e8f9f7 2532 else if ((start >= kFLASH_resourceRangePflashSwapIfrStart) &&
<> 144:ef7eb2e8f9f7 2533 (maxReadbleAddress <= kFLASH_resourceRangePflashSwapIfrEnd))
<> 144:ef7eb2e8f9f7 2534 {
<> 144:ef7eb2e8f9f7 2535 }
<> 144:ef7eb2e8f9f7 2536 #endif /* FSL_FEATURE_FLASH_HAS_PFLASH_BLOCK_SWAP */
<> 144:ef7eb2e8f9f7 2537 else if ((start >= kFLASH_resourceRangeDflashIfrStart) &&
<> 144:ef7eb2e8f9f7 2538 (maxReadbleAddress <= kFLASH_resourceRangeDflashIfrEnd))
<> 144:ef7eb2e8f9f7 2539 {
<> 144:ef7eb2e8f9f7 2540 }
<> 144:ef7eb2e8f9f7 2541 else
<> 144:ef7eb2e8f9f7 2542 {
<> 144:ef7eb2e8f9f7 2543 status = kStatus_FLASH_InvalidArgument;
<> 144:ef7eb2e8f9f7 2544 }
<> 144:ef7eb2e8f9f7 2545 }
<> 144:ef7eb2e8f9f7 2546 else
<> 144:ef7eb2e8f9f7 2547 {
<> 144:ef7eb2e8f9f7 2548 status = kStatus_FLASH_InvalidArgument;
<> 144:ef7eb2e8f9f7 2549 }
<> 144:ef7eb2e8f9f7 2550
<> 144:ef7eb2e8f9f7 2551 return status;
<> 144:ef7eb2e8f9f7 2552 }
<> 144:ef7eb2e8f9f7 2553 #endif /* FSL_FEATURE_FLASH_HAS_READ_RESOURCE_CMD */
<> 144:ef7eb2e8f9f7 2554
<> 144:ef7eb2e8f9f7 2555 #if defined(FSL_FEATURE_FLASH_HAS_SWAP_CONTROL_CMD) && FSL_FEATURE_FLASH_HAS_SWAP_CONTROL_CMD
<> 144:ef7eb2e8f9f7 2556 /*! @brief Validates the gived swap control option.*/
<> 144:ef7eb2e8f9f7 2557 static status_t flash_check_swap_control_option(flash_swap_control_option_t option)
<> 144:ef7eb2e8f9f7 2558 {
<> 144:ef7eb2e8f9f7 2559 if ((option == kFLASH_swapControlOptionIntializeSystem) || (option == kFLASH_swapControlOptionSetInUpdateState) ||
<> 144:ef7eb2e8f9f7 2560 (option == kFLASH_swapControlOptionSetInCompleteState) || (option == kFLASH_swapControlOptionReportStatus) ||
<> 144:ef7eb2e8f9f7 2561 (option == kFLASH_swapControlOptionDisableSystem))
<> 144:ef7eb2e8f9f7 2562 {
<> 144:ef7eb2e8f9f7 2563 return kStatus_FLASH_Success;
<> 144:ef7eb2e8f9f7 2564 }
<> 144:ef7eb2e8f9f7 2565
<> 144:ef7eb2e8f9f7 2566 return kStatus_FLASH_InvalidArgument;
<> 144:ef7eb2e8f9f7 2567 }
<> 144:ef7eb2e8f9f7 2568 #endif /* FSL_FEATURE_FLASH_HAS_SWAP_CONTROL_CMD */
<> 144:ef7eb2e8f9f7 2569
<> 144:ef7eb2e8f9f7 2570 #if defined(FSL_FEATURE_FLASH_HAS_PFLASH_BLOCK_SWAP) && FSL_FEATURE_FLASH_HAS_PFLASH_BLOCK_SWAP
<> 144:ef7eb2e8f9f7 2571 /*! @brief Validates the gived address to see if it is equal to swap indicator address in pflash swap IFR.*/
<> 144:ef7eb2e8f9f7 2572 static status_t flash_validate_swap_indicator_address(flash_config_t *config, uint32_t address)
<> 144:ef7eb2e8f9f7 2573 {
<> 144:ef7eb2e8f9f7 2574 flash_swap_ifr_field_config_t flashSwapIfrField;
<> 144:ef7eb2e8f9f7 2575 uint32_t swapIndicatorAddress;
<> 144:ef7eb2e8f9f7 2576
<> 144:ef7eb2e8f9f7 2577 status_t returnCode;
<> 144:ef7eb2e8f9f7 2578 returnCode = FLASH_ReadResource(config, kFLASH_resourceRangePflashSwapIfrStart, (uint32_t *)&flashSwapIfrField,
<> 144:ef7eb2e8f9f7 2579 sizeof(flash_swap_ifr_field_config_t), kFLASH_resourceOptionFlashIfr);
<> 144:ef7eb2e8f9f7 2580 if (returnCode != kStatus_FLASH_Success)
<> 144:ef7eb2e8f9f7 2581 {
<> 144:ef7eb2e8f9f7 2582 return returnCode;
<> 144:ef7eb2e8f9f7 2583 }
<> 144:ef7eb2e8f9f7 2584
<> 144:ef7eb2e8f9f7 2585 /* The high 2 byte value of Swap Indicator Address is stored in Program Flash Swap IFR Field,
<> 144:ef7eb2e8f9f7 2586 * the low 4 bit value of Swap Indicator Address is always 4'b0000 */
<> 144:ef7eb2e8f9f7 2587 swapIndicatorAddress =
<> 144:ef7eb2e8f9f7 2588 (uint32_t)flashSwapIfrField.swapIndicatorAddress * FSL_FEATURE_FLASH_PFLASH_SWAP_CONTROL_CMD_ADDRESS_ALIGMENT;
<> 144:ef7eb2e8f9f7 2589 if (address != swapIndicatorAddress)
<> 144:ef7eb2e8f9f7 2590 {
<> 144:ef7eb2e8f9f7 2591 return kStatus_FLASH_SwapIndicatorAddressError;
<> 144:ef7eb2e8f9f7 2592 }
<> 144:ef7eb2e8f9f7 2593
<> 144:ef7eb2e8f9f7 2594 return returnCode;
<> 144:ef7eb2e8f9f7 2595 }
<> 144:ef7eb2e8f9f7 2596 #endif /* FSL_FEATURE_FLASH_HAS_PFLASH_BLOCK_SWAP */
<> 144:ef7eb2e8f9f7 2597
<> 144:ef7eb2e8f9f7 2598 #if defined(FSL_FEATURE_FLASH_HAS_SET_FLEXRAM_FUNCTION_CMD) && FSL_FEATURE_FLASH_HAS_SET_FLEXRAM_FUNCTION_CMD
<> 144:ef7eb2e8f9f7 2599 /*! @brief Validates the gived flexram function option.*/
<> 144:ef7eb2e8f9f7 2600 static inline status_t flasn_check_flexram_function_option_range(flash_flexram_function_option_t option)
<> 144:ef7eb2e8f9f7 2601 {
<> 144:ef7eb2e8f9f7 2602 if ((option != kFLASH_flexramFunctionOptionAvailableAsRam) &&
<> 144:ef7eb2e8f9f7 2603 (option != kFLASH_flexramFunctionOptionAvailableForEeprom))
<> 144:ef7eb2e8f9f7 2604 {
<> 144:ef7eb2e8f9f7 2605 return kStatus_FLASH_InvalidArgument;
<> 144:ef7eb2e8f9f7 2606 }
<> 144:ef7eb2e8f9f7 2607
<> 144:ef7eb2e8f9f7 2608 return kStatus_FLASH_Success;
<> 144:ef7eb2e8f9f7 2609 }
<> 144:ef7eb2e8f9f7 2610 #endif /* FSL_FEATURE_FLASH_HAS_SET_FLEXRAM_FUNCTION_CMD */