Kinetis SDK v.1.2 Demo Applications User's Guide  Rev. 0
Freescale Semiconductor, Inc.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
flash_demo.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * o Redistributions of source code must retain the above copyright notice, this list
9  * of conditions and the following disclaimer.
10  *
11  * o Redistributions in binary form must reproduce the above copyright notice, this
12  * list of conditions and the following disclaimer in the documentation and/or
13  * other materials provided with the distribution.
14  *
15  * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16  * contributors may be used to endorse or promote products derived from this
17  * software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #ifndef _FLASH_DEMO_H_
32 #define _FLASH_DEMO_H_
33 
34 #include "board.h"
35 #include "SSD_FTFx.h"
36 /* size of array to copy__Launch_Command function to.*/
37 /* It should be at least equal to actual size of __Launch_Command func */
38 /* User can change this value based on RAM size availability and actual size of __Launch_Command function */
39 #define LAUNCH_CMD_SIZE 0x100
40 
41 /* Size of function used for callback. Change this depending on the size of your function */
42 #define CALLBACK_SIZE 0x80
43 
44 #define BUFFER_SIZE_BYTE 0x80
45 
46 #define FTFx_REG_BASE 0x40020000
47 #define P_FLASH_BASE 0x00000000
48 
49 /* Program Flash block information */
50 #define P_FLASH_SIZE (FSL_FEATURE_FLASH_PFLASH_BLOCK_SIZE * FSL_FEATURE_FLASH_PFLASH_BLOCK_COUNT)
51 #define P_BLOCK_NUM FSL_FEATURE_FLASH_PFLASH_BLOCK_COUNT
52 #define P_SECTOR_SIZE FSL_FEATURE_FLASH_PFLASH_BLOCK_SECTOR_SIZE
53 /* Data Flash block information */
54 #define FLEXNVM_BASE FSL_FEATURE_FLASH_FLEX_NVM_START_ADDRESS
55 #define FLEXNVM_SECTOR_SIZE FSL_FEATURE_FLASH_FLEX_NVM_BLOCK_SECTOR_SIZE
56 #define FLEXNVM_BLOCK_SIZE FSL_FEATURE_FLASH_FLEX_NVM_BLOCK_SIZE
57 #define FLEXNVM_BLOCK_NUM FSL_FEATURE_FLASH_FLEX_NVM_BLOCK_COUNT
58 
59 /* Flex Ram block information */
60 #define EERAM_BASE FSL_FEATURE_FLASH_FLEX_RAM_START_ADDRESS
61 #define EERAM_SIZE FSL_FEATURE_FLASH_FLEX_RAM_SIZE
62 
63 /* Destination to program security key back to flash location */
64 #if (FSL_FEATURE_FLASH_PFLASH_BLOCK_WRITE_UNIT_SIZE == 8)
65  #define SECURITY_LOCATION 0x408
66 #else /* FSL_FEATURE_FLASH_PFLASH_BLOCK_WRITE_UNIT_SIZE == 4 */
67  #define SECURITY_LOCATION 0x40C
68 #endif
69 
70 #define BACKDOOR_KEY_LOCATION 0x400
71 
72 /* Program flash IFR map*/
73 #if (FSL_FEATURE_FLASH_IS_FTFE == 1)
74  #define PFLASH_IFR 0x3C0
75 #else /* FSL_FEATURE_FLASH_IS_FTFL == 1 or FSL_FEATURE_FLASH_IS_FTFA = =1 */
76  #define PFLASH_IFR 0xC0
77 #endif
78 
79 #if (FSL_FEATURE_FLASH_HAS_PFLASH_BLOCK_SWAP == 1)
80  #if (FSL_FEATURE_FLASH_IS_FTFE == 1)
81  #define SWAP_STATUS_BIT (REG_READ(FTFx_REG_BASE + FTFx_SSD_FCNFG_OFFSET) & FTFE_FCNFG_SWAP_MASK)
82  #endif
83  #if (FSL_FEATURE_FLASH_IS_FTFL == 1)
84  #define SWAP_STATUS_BIT (REG_READ(FTFx_REG_BASE + FTFx_SSD_FCNFG_OFFSET) & FTFL_FCNFG_SWAP_MASK)
85  #endif
86  #if (FSL_FEATURE_FLASH_IS_FTFA == 1)
87  #define SWAP_STATUS_BIT (REG_READ(FTFx_REG_BASE + FTFx_SSD_FCNFG_OFFSET) & FTFA_FCNFG_SWAP_MASK)
88  #endif
89 #endif
90 
91 /* Has flash cache control in MCM module */
92 #if (FSL_FEATURE_FLASH_HAS_MCM_FLASH_CACHE_CONTROLS == 1)
93  #define CACHE_DISABLE MCM_BWR_PLACR_DFCS(MCM_BASE_PTR, 1);
94 /* Has flash cache control in FMC module */
95 #elif (FSL_FEATURE_FLASH_HAS_FMC_FLASH_CACHE_CONTROLS == 1)
96  #if defined(FMC_PFB1CR) && defined(FMC_PFB1CR_B1SEBE_MASK)
97  #define CACHE_DISABLE FMC_PFB0CR &= ~(FMC_PFB0CR_B0SEBE_MASK | FMC_PFB0CR_B0IPE_MASK | FMC_PFB0CR_B0DPE_MASK | FMC_PFB0CR_B0ICE_MASK | FMC_PFB0CR_B0DCE_MASK);\
98  FMC_PFB1CR &= ~(FMC_PFB1CR_B1SEBE_MASK | FMC_PFB1CR_B1IPE_MASK | FMC_PFB1CR_B1DPE_MASK | FMC_PFB1CR_B1ICE_MASK | FMC_PFB1CR_B1DCE_MASK);
99  #elif defined(FMC_PFB23CR)
100  #define CACHE_DISABLE FMC_PFB01CR &= ~(FMC_PFB01CR_B0IPE_MASK | FMC_PFB01CR_B0DPE_MASK | FMC_PFB01CR_B0ICE_MASK | FMC_PFB01CR_B0DCE_MASK);\
101  FMC_PFB23CR &= ~(FMC_PFB23CR_B1IPE_MASK | FMC_PFB23CR_B1DPE_MASK | FMC_PFB23CR_B1ICE_MASK | FMC_PFB23CR_B1DCE_MASK);
102  #else
103  #define CACHE_DISABLE FMC_PFB0CR &= ~(FMC_PFB0CR_B0SEBE_MASK | FMC_PFB0CR_B0IPE_MASK | FMC_PFB0CR_B0DPE_MASK | FMC_PFB0CR_B0ICE_MASK | FMC_PFB0CR_B0DCE_MASK);
104  #endif
105 #else
106 /* No cache in the device */
107  #define CACHE_DISABLE
108 #endif
109 
110 /***************************************************************************************/
111 /***************************************************************************************/
112 
113 /* Other defines */
114 #define DEBUGENABLE 0x00
115 
116 #define READ_NORMAL_MARGIN 0x00
117 #define READ_USER_MARGIN 0x01
118 #define READ_FACTORY_MARGIN 0x02
119 
120 #define ONE_KB 1024 //0x400: 10 zeros
121 #define TWO_KB (2*ONE_KB)
122 #define THREE_KB (3*ONE_KB)
123 #define FOUR_KB (4*ONE_KB)
124 #define FIVE_KB (5*ONE_KB)
125 #define SIX_KB (6*ONE_KB)
126 #define SEVEN_KB (7*ONE_KB)
127 #define EIGHT_KB (8*ONE_KB)
128 #define NINE_KB (9*ONE_KB)
129 #define TEN_KB (10*ONE_KB)
130 #define ONE_MB (ONE_KB*ONE_KB) //0x100000: 20 zeros
131 #define ONE_GB (ONE_KB*ONE_KB*ONE_KB) //0x40000000: 30 zeros
132 
133 #if defined(SWAP_M)
134 /****************************************************************************/
135 /* Use an address towards the end of P-Flash block for the swap indicator. */
136 /* The swap indicator is managed by the swap system, but is a location in */
137 /* PFlash and it gets modified (erased & programmed) throughout the swap */
138 /* process, so it cannot share space with normal application code */
139 /* Here, we are using the second-to-last sector, since the Lower/Upper */
140 /* data blocks use the last sector are used to hold our test data to help */
141 /* identify each block after the swap */
142 /****************************************************************************/
143  #define PSWAP_INDICATOR_ADDR (P_FLASH_SIZE/2 - 2*(FTFx_PSECTOR_SIZE))
144 /* The Lower & Upper Data sectors are used to program test data into, to */
145 /* help identify each block - for debug purposes. */
146  #define PSWAP_LOWERDATA_ADDR (PSWAP_INDICATOR_ADDR + FTFx_PSECTOR_SIZE + 0x100)
147  #define PSWAP_UPPERDATA_ADDR (PSWAP_INDICATOR_ADDR + FTFx_PSECTOR_SIZE + P_FLASH_SIZE/2 + 0x100)
148 /************************************************************************************************/
149 #endif /* End of #if defined(SWAP_M) */
150 /************************************************************/
151 /* prototypes */
152 /************************************************************/
153 void callback(void);
154 extern uint32_t RelocateFunction(uint32_t dest, uint32_t size, uint32_t src);
155 void print_welcome_message(void);
156 void ErrorTrap(uint32_t returnCode);
157 
158 #if (defined(SWAP_M))
159 uint32_t flash_swap(void);
160 void run_flash_swap(void);
161 void print_swap_application_data(void);
162 #endif /* #if (defined(SWAP)) */
163 
164 #endif /* _FLASH_DEMO_H_ */
void ErrorTrap(uint32_t returnCode)
Definition: demo_apps/flash_demo/main.c:372
void callback(void)
Definition: flash_demo_ram.c:707
void print_welcome_message(void)
uint32_t RelocateFunction(uint32_t dest, uint32_t size, uint32_t src)