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