iLLD_TC29x  1.0
IfxFlash.c
Go to the documentation of this file.
1 /**
2  * \file IfxFlash.c
3  * \brief FLASH basic functionality
4  *
5  * \version iLLD_1_0_0_11_0
6  * \copyright Copyright (c) 2013 Infineon Technologies AG. All rights reserved.
7  *
8  *
9  * IMPORTANT NOTICE
10  *
11  *
12  * Infineon Technologies AG (Infineon) is supplying this file for use
13  * exclusively with Infineon's microcontroller products. This file can be freely
14  * distributed within development tools that are supporting such microcontroller
15  * products.
16  *
17  * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
18  * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
19  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
20  * INFINEON SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
21  * OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
22  *
23  *
24  */
25 
26 /******************************************************************************/
27 /*----------------------------------Includes----------------------------------*/
28 /******************************************************************************/
29 
30 #include "IfxFlash.h"
31 
32 /******************************************************************************/
33 /*-------------------------Function Implementations---------------------------*/
34 /******************************************************************************/
35 
37 {
38  MODULE_FLASH0.CBAB[portId].CFG.B.CLR = 1;
39 }
40 
41 
43 {
44  volatile uint32 *addr1 = (volatile uint32 *)(IFXFLASH_CMD_BASE_ADDRESS | 0x5554);
45 
46  *addr1 = 0xFA;
47 
48  __dsync();
49 }
50 
51 
53 {
54  MODULE_FLASH0.UBAB[portId].CFG.B.CLR = 1;
55 }
56 
57 
59 {
60  MODULE_FLASH0.CBAB[portId].CFG.B.DIS = disable;
61 }
62 
63 
65 {
66  MODULE_FLASH0.UBAB[portId].CFG.B.DIS = disable;
67 }
68 
69 
71 {
72  volatile uint32 *addr1 = (volatile uint32 *)(IFXFLASH_CMD_BASE_ADDRESS | 0x553c);
73  uint32 i;
74 
75  *addr1 = ucb;
76 
77  for (i = 0; i < 8; i++)
78  {
79  *addr1 = password[i];
80  }
81 
82  __dsync();
83 }
84 
85 
87 {
88  volatile uint32 *addr1 = (volatile uint32 *)(IFXFLASH_CMD_BASE_ADDRESS | 0x5554);
89 
90  if ((pageAddr & 0xff000000) == 0xa0000000) // program flash
91  {
92  *addr1 = 0x50;
93  return 0;
94  }
95  else if ((pageAddr & 0xff000000) == 0xaf000000) // data flash
96  {
97  *addr1 = 0x5D;
98  return 0;
99  }
100 
101  __dsync();
102  return 1; // invalid flash address
103 }
104 
105 
107 {
108  volatile uint32 *addr1 = (volatile uint32 *)(IFXFLASH_CMD_BASE_ADDRESS | 0xaa50);
109  volatile uint32 *addr2 = (volatile uint32 *)(IFXFLASH_CMD_BASE_ADDRESS | 0xaa58);
110  volatile uint32 *addr3 = (volatile uint32 *)(IFXFLASH_CMD_BASE_ADDRESS | 0xaaa8);
111  volatile uint32 *addr4 = (volatile uint32 *)(IFXFLASH_CMD_BASE_ADDRESS | 0xaaa8);
112 
113  *addr1 = sectorAddr;
114  *addr2 = numSector;
115  *addr3 = 0x80;
116  *addr4 = 0x5a;
117 
118  __dsync();
119 }
120 
121 
122 void IfxFlash_eraseMultipleSectors(uint32 sectorAddr, uint32 numSector)
123 {
124  volatile uint32 *addr1 = (volatile uint32 *)(IFXFLASH_CMD_BASE_ADDRESS | 0xaa50);
125  volatile uint32 *addr2 = (volatile uint32 *)(IFXFLASH_CMD_BASE_ADDRESS | 0xaa58);
126  volatile uint32 *addr3 = (volatile uint32 *)(IFXFLASH_CMD_BASE_ADDRESS | 0xaaa8);
127  volatile uint32 *addr4 = (volatile uint32 *)(IFXFLASH_CMD_BASE_ADDRESS | 0xaaa8);
128 
129  *addr1 = sectorAddr;
130  *addr2 = numSector;
131  *addr3 = 0x80;
132  *addr4 = 0x50;
133 
134  __dsync();
135 }
136 
137 
139 {
140  volatile uint32 *addr1 = (volatile uint32 *)(IFXFLASH_CMD_BASE_ADDRESS | 0xaa50);
141  volatile uint32 *addr2 = (volatile uint32 *)(IFXFLASH_CMD_BASE_ADDRESS | 0xaa58);
142  volatile uint32 *addr3 = (volatile uint32 *)(IFXFLASH_CMD_BASE_ADDRESS | 0xaaa8);
143  volatile uint32 *addr4 = (volatile uint32 *)(IFXFLASH_CMD_BASE_ADDRESS | 0xaaa8);
144 
145  *addr1 = sectorAddr;
146  *addr2 = 1;
147  *addr3 = 0x80;
148  *addr4 = 0x5a;
149 
150  __dsync();
151 }
152 
153 
154 void IfxFlash_eraseSector(uint32 sectorAddr)
155 {
156  volatile uint32 *addr1 = (volatile uint32 *)(IFXFLASH_CMD_BASE_ADDRESS | 0xaa50);
157  volatile uint32 *addr2 = (volatile uint32 *)(IFXFLASH_CMD_BASE_ADDRESS | 0xaa58);
158  volatile uint32 *addr3 = (volatile uint32 *)(IFXFLASH_CMD_BASE_ADDRESS | 0xaaa8);
159  volatile uint32 *addr4 = (volatile uint32 *)(IFXFLASH_CMD_BASE_ADDRESS | 0xaaa8);
160 
161  *addr1 = sectorAddr;
162  *addr2 = 1;
163  *addr3 = 0x80;
164  *addr4 = 0x50;
165 
166  __dsync();
167 }
168 
169 
171 {
172  volatile uint32 *addr1 = (volatile uint32 *)(IFXFLASH_CMD_BASE_ADDRESS | 0xaa50);
173  volatile uint32 *addr2 = (volatile uint32 *)(IFXFLASH_CMD_BASE_ADDRESS | 0xaa58);
174  volatile uint32 *addr3 = (volatile uint32 *)(IFXFLASH_CMD_BASE_ADDRESS | 0xaaa8);
175  volatile uint32 *addr4 = (volatile uint32 *)(IFXFLASH_CMD_BASE_ADDRESS | 0xaaa8);
176 
177  *addr1 = sectorAddr;
178  *addr2 = numSector;
179  *addr3 = 0x80;
180  *addr4 = 0x5F;
181 
182  __dsync();
183 }
184 
185 
187 {
188  volatile uint32 *addr1 = (volatile uint32 *)(IFXFLASH_CMD_BASE_ADDRESS | 0xaa50);
189  volatile uint32 *addr2 = (volatile uint32 *)(IFXFLASH_CMD_BASE_ADDRESS | 0xaa58);
190  volatile uint32 *addr3 = (volatile uint32 *)(IFXFLASH_CMD_BASE_ADDRESS | 0xaaa8);
191  volatile uint32 *addr4 = (volatile uint32 *)(IFXFLASH_CMD_BASE_ADDRESS | 0xaaa8);
192 
193  *addr1 = sectorAddr;
194  *addr2 = 1;
195  *addr3 = 0x80;
196  *addr4 = 0x5F;
197 
198  __dsync();
199 }
200 
201 
203 {
204  uint32 numErrors = 0;
205  uint32 fillingLevel = MODULE_FLASH0.CBAB[portId].STAT.U;
206 
207  int i;
208 
209  for (i = 0;
211  (fillingLevel & (1 << i)) != 0;
212  ++i)
213  {
214  Ifx_FLASH_CBAB_TOP top;
215  top.U = MODULE_FLASH0.CBAB[portId].TOP.U;
216 
217  if (top.B.VLD)
218  {
219  trackedFlashAdresses[numErrors].address = 0xa0000000 | (top.B.ADDR << 5);
220  trackedFlashAdresses[numErrors].errorType = top.B.ERR;
221  ++numErrors;
222  }
223 
224  // clear entry
225  MODULE_FLASH0.CBAB[portId].TOP.U = (1 << 31);
226  }
227 
228  return numErrors;
229 }
230 
231 
233 {
234  uint32 numErrors = 0;
235  uint32 fillingLevel = MODULE_FLASH0.UBAB[portId].STAT.U;
236 
237  int i;
238 
239  for (i = 0;
241  (fillingLevel & (1 << i)) != 0;
242  ++i)
243  {
244  Ifx_FLASH_UBAB_TOP top;
245  top.U = MODULE_FLASH0.UBAB[portId].TOP.U;
246 
247  if (top.B.VLD)
248  {
249  trackedFlashAdresses[numErrors].address = 0xa0000000 | (top.B.ADDR << 5);
250  trackedFlashAdresses[numErrors].errorType = top.B.ERR;
251  ++numErrors;
252  }
253 
254  // clear entry
255  MODULE_FLASH0.UBAB[portId].TOP.U = (1 << 31);
256  }
257 
258  return numErrors;
259 }
260 
261 
262 void IfxFlash_loadPage(uint32 pageAddr, uint32 wordL, uint32 wordU)
263 {
264  uint64 *addr1 = (uint64 *)(IFXFLASH_CMD_BASE_ADDRESS | 0x55f0);
265 
266  __st64_lu(addr1, wordL, wordU);
267 
268  __dsync();
269 }
270 
271 
272 void IfxFlash_loadPage2X32(uint32 pageAddr, uint32 wordL, uint32 wordU)
273 {
274  volatile uint32 *addr1 = (volatile uint32 *)(IFXFLASH_CMD_BASE_ADDRESS | 0x55f0);
275 
276  *addr1 = wordL;
277  addr1++;
278  *addr1 = wordU;
279 
280  __dsync();
281 }
282 
283 
285 {
286  volatile uint32 *addr1 = (volatile uint32 *)(IFXFLASH_CMD_BASE_ADDRESS | 0x5554);
287  *addr1 = 0xf0;
288 
289  __dsync();
290 }
291 
292 
294 {
295  volatile uint32 *addr1 = (volatile uint32 *)(IFXFLASH_CMD_BASE_ADDRESS | 0x5554);
296 
297  *addr1 = 0xF5;
298 
299  __dsync();
300 }
301 
302 
304 {
306  errorTracking == IfxFlash_ErrorTracking_none ||
310 
311  MODULE_FLASH0.CBAB[portId].CFG.B.SEL = errorTracking;
312 }
313 
314 
316 {
318  errorTracking == IfxFlash_ErrorTracking_none ||
320 
321  MODULE_FLASH0.UBAB[portId].CFG.B.SEL = errorTracking;
322 }
323 
324 
326 {
327  volatile uint32 *addr1 = (volatile uint32 *)(IFXFLASH_CMD_BASE_ADDRESS | 0xaa50);
328  volatile uint32 *addr2 = (volatile uint32 *)(IFXFLASH_CMD_BASE_ADDRESS | 0xaa58);
329  volatile uint32 *addr3 = (volatile uint32 *)(IFXFLASH_CMD_BASE_ADDRESS | 0xaaa8);
330  volatile uint32 *addr4 = (volatile uint32 *)(IFXFLASH_CMD_BASE_ADDRESS | 0xaaa8);
331 
332  *addr1 = sectorAddr;
333  *addr2 = numSector;
334  *addr3 = 0x70;
335  *addr4 = 0xCC;
336 
337  __dsync();
338 }
339 
340 
342 {
343  volatile uint32 *addr1 = (volatile uint32 *)(IFXFLASH_CMD_BASE_ADDRESS | 0xaa50);
344  volatile uint32 *addr2 = (volatile uint32 *)(IFXFLASH_CMD_BASE_ADDRESS | 0xaa58);
345  volatile uint32 *addr3 = (volatile uint32 *)(IFXFLASH_CMD_BASE_ADDRESS | 0xaaa8);
346  volatile uint32 *addr4 = (volatile uint32 *)(IFXFLASH_CMD_BASE_ADDRESS | 0xaaa8);
347 
348  *addr1 = sectorAddr;
349  *addr2 = 1;
350  *addr3 = 0x70;
351  *addr4 = 0xCC;
352 
353  __dsync();
354 }
355 
356 
358 {
359  if (flash == 0)
360  {
361  while (FLASH0_FSR.U & (1 << flashType))
362  {}
363  }
364 
365 #if IFXFLASH_NUM_FLASH_MODULES > 1
366  else if (flash == 1)
367  {
368  while (FLASH1_FSR.U & (1 << flashType))
369  {}
370  }
371 #endif
372  else
373  {
374  return 1; // invalid flash selected
375  }
376  __dsync();
377  return 0; // finished
378 }
379 
380 
382 {
383  volatile uint32 *addr1 = (volatile uint32 *)(IFXFLASH_CMD_BASE_ADDRESS | 0xaa50);
384  volatile uint32 *addr2 = (volatile uint32 *)(IFXFLASH_CMD_BASE_ADDRESS | 0xaa58);
385  volatile uint32 *addr3 = (volatile uint32 *)(IFXFLASH_CMD_BASE_ADDRESS | 0xaaa8);
386  volatile uint32 *addr4 = (volatile uint32 *)(IFXFLASH_CMD_BASE_ADDRESS | 0xaaa8);
387 
388  *addr1 = pageAddr;
389  *addr2 = 0x00;
390  *addr3 = 0xa0;
391  *addr4 = 0x7a;
392 
393  __dsync();
394 }
395 
396 
398 {
399  volatile uint32 *addr1 = (volatile uint32 *)(IFXFLASH_CMD_BASE_ADDRESS | 0xaa50);
400  volatile uint32 *addr2 = (volatile uint32 *)(IFXFLASH_CMD_BASE_ADDRESS | 0xaa58);
401  volatile uint32 *addr3 = (volatile uint32 *)(IFXFLASH_CMD_BASE_ADDRESS | 0xaaa8);
402  volatile uint32 *addr4 = (volatile uint32 *)(IFXFLASH_CMD_BASE_ADDRESS | 0xaaa8);
403 
404  *addr1 = pageAddr;
405  *addr2 = 0x00;
406  *addr3 = 0xa0;
407  *addr4 = 0xaa;
408 
409  __dsync();
410 }
411 
412 
414 {
415  volatile uint32 *addr1 = (volatile uint32 *)(IFXFLASH_CMD_BASE_ADDRESS | 0xaa50);
416  volatile uint32 *addr2 = (volatile uint32 *)(IFXFLASH_CMD_BASE_ADDRESS | 0xaa58);
417  volatile uint32 *addr3 = (volatile uint32 *)(IFXFLASH_CMD_BASE_ADDRESS | 0xaaa8);
418  volatile uint32 *addr4 = (volatile uint32 *)(IFXFLASH_CMD_BASE_ADDRESS | 0xaaa8);
419 
420  *addr1 = pageAddr;
421  *addr2 = 0x00;
422  *addr3 = 0xa0;
423  *addr4 = 0x9a;
424 
425  __dsync();
426 }