S32 SDK
flash_driver.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 Freescale Semiconductor, Inc.
3  * Copyright 2016-2017 NXP
4  * All rights reserved.
5  *
6  * THIS SOFTWARE IS PROVIDED BY NXP "AS IS" AND ANY EXPRESSED OR
7  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
8  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
9  * IN NO EVENT SHALL NXP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
10  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
11  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
12  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
13  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
14  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
15  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
16  * THE POSSIBILITY OF SUCH DAMAGE.
17  */
71 #include "flash_driver.h"
72 
74 static status_t FLASH_DRV_CommandSequence(const flash_ssd_config_t * pSSDConfig)
76 /*******************************************************************************
77  * Code
78  ******************************************************************************/
79 
80 /*FUNCTION**********************************************************************
81  *
82  * Function Name : FLASH_DRV_GetDEPartitionCode
83  * Description : Gets DFlash size from FlexNVM Partition Code.
84  *
85  *END**************************************************************************/
86 static void FLASH_DRV_GetDEPartitionCode(flash_ssd_config_t * const pSSDConfig,
87  uint8_t DEPartitionCode)
88 {
89  /* Select D-Flash size */
90  if (0x00U == DEPartitionCode) {pSSDConfig->DFlashSize = (uint32_t)FEATURE_FLS_DF_SIZE_0000;}
91  else if (0x01U == DEPartitionCode) {pSSDConfig->DFlashSize = (uint32_t)FEATURE_FLS_DF_SIZE_0001;}
92  else if (0x02U == DEPartitionCode) {pSSDConfig->DFlashSize = (uint32_t)FEATURE_FLS_DF_SIZE_0010;}
93  else if (0x03U == DEPartitionCode) {pSSDConfig->DFlashSize = (uint32_t)FEATURE_FLS_DF_SIZE_0011;}
94  else if (0x04U == DEPartitionCode) {pSSDConfig->DFlashSize = (uint32_t)FEATURE_FLS_DF_SIZE_0100;}
95  else if (0x05U == DEPartitionCode) {pSSDConfig->DFlashSize = (uint32_t)FEATURE_FLS_DF_SIZE_0101;}
96  else if (0x06U == DEPartitionCode) {pSSDConfig->DFlashSize = (uint32_t)FEATURE_FLS_DF_SIZE_0110;}
97  else if (0x07U == DEPartitionCode) {pSSDConfig->DFlashSize = (uint32_t)FEATURE_FLS_DF_SIZE_0111;}
98  else if (0x08U == DEPartitionCode) {pSSDConfig->DFlashSize = (uint32_t)FEATURE_FLS_DF_SIZE_1000;}
99  else if (0x09U == DEPartitionCode) {pSSDConfig->DFlashSize = (uint32_t)FEATURE_FLS_DF_SIZE_1001;}
100  else if (0x0AU == DEPartitionCode) {pSSDConfig->DFlashSize = (uint32_t)FEATURE_FLS_DF_SIZE_1010;}
101  else if (0x0BU == DEPartitionCode) {pSSDConfig->DFlashSize = (uint32_t)FEATURE_FLS_DF_SIZE_1011;}
102  else if (0x0CU == DEPartitionCode) {pSSDConfig->DFlashSize = (uint32_t)FEATURE_FLS_DF_SIZE_1100;}
103  else if (0x0DU == DEPartitionCode) {pSSDConfig->DFlashSize = (uint32_t)FEATURE_FLS_DF_SIZE_1101;}
104  else if (0x0EU == DEPartitionCode) {pSSDConfig->DFlashSize = (uint32_t)FEATURE_FLS_DF_SIZE_1110;}
105  else if (0x0FU == DEPartitionCode) {pSSDConfig->DFlashSize = (uint32_t)FEATURE_FLS_DF_SIZE_1111;}
106  else {/* Undefined value */}
107 }
108 
109 #if (FEATURE_FLS_IS_FTFC == 0U)
110 /*FUNCTION**********************************************************************
111  *
112  * Function Name : FLASH_DRV_GetEEEDataSetSize
113  * Description : Gets EEPROM size from EEPROM Data Set Size.
114  *
115  *END**************************************************************************/
116 static void FLASH_DRV_GetEEEDataSetSize(flash_ssd_config_t * const pSSDConfig,
117  uint8_t EEEDataSetSize)
118 {
119  /* Select EEPROM size */
120  if (0x00U == EEEDataSetSize) {pSSDConfig->EEESize = (uint32_t)FEATURE_FLS_EE_SIZE_0000;}
121  else if (0x01U == EEEDataSetSize) {pSSDConfig->EEESize = (uint32_t)FEATURE_FLS_EE_SIZE_0001;}
122  else if (0x02U == EEEDataSetSize) {pSSDConfig->EEESize = (uint32_t)FEATURE_FLS_EE_SIZE_0010;}
123  else if (0x03U == EEEDataSetSize) {pSSDConfig->EEESize = (uint32_t)FEATURE_FLS_EE_SIZE_0011;}
124  else if (0x04U == EEEDataSetSize) {pSSDConfig->EEESize = (uint32_t)FEATURE_FLS_EE_SIZE_0100;}
125  else if (0x05U == EEEDataSetSize) {pSSDConfig->EEESize = (uint32_t)FEATURE_FLS_EE_SIZE_0101;}
126  else if (0x06U == EEEDataSetSize) {pSSDConfig->EEESize = (uint32_t)FEATURE_FLS_EE_SIZE_0110;}
127  else if (0x07U == EEEDataSetSize) {pSSDConfig->EEESize = (uint32_t)FEATURE_FLS_EE_SIZE_0111;}
128  else if (0x08U == EEEDataSetSize) {pSSDConfig->EEESize = (uint32_t)FEATURE_FLS_EE_SIZE_1000;}
129  else if (0x09U == EEEDataSetSize) {pSSDConfig->EEESize = (uint32_t)FEATURE_FLS_EE_SIZE_1001;}
130  else if (0x0AU == EEEDataSetSize) {pSSDConfig->EEESize = (uint32_t)FEATURE_FLS_EE_SIZE_1010;}
131  else if (0x0BU == EEEDataSetSize) {pSSDConfig->EEESize = (uint32_t)FEATURE_FLS_EE_SIZE_1011;}
132  else if (0x0CU == EEEDataSetSize) {pSSDConfig->EEESize = (uint32_t)FEATURE_FLS_EE_SIZE_1100;}
133  else if (0x0DU == EEEDataSetSize) {pSSDConfig->EEESize = (uint32_t)FEATURE_FLS_EE_SIZE_1101;}
134  else if (0x0EU == EEEDataSetSize) {pSSDConfig->EEESize = (uint32_t)FEATURE_FLS_EE_SIZE_1110;}
135  else if (0x0FU == EEEDataSetSize) {pSSDConfig->EEESize = (uint32_t)FEATURE_FLS_EE_SIZE_1111;}
136  else {/* Undefined value */}
137 }
138 #endif /* if (FEATURE_FLS_IS_FTFC == 0U) */
139 
140 /*FUNCTION**********************************************************************
141  *
142  * Function Name : FLASH_DRV_Init
143  * Description : Initializes Flash module by clearing status error bit
144  * and reporting the memory configuration via SSD configuration structure.
145  *
146  * Implements : FLASH_DRV_Init_Activity
147  *END**************************************************************************/
148 status_t FLASH_DRV_Init(const flash_user_config_t * const pUserConf,
149  flash_ssd_config_t * const pSSDConfig)
150 {
151  DEV_ASSERT(pUserConf != NULL);
152  DEV_ASSERT(pSSDConfig != NULL);
153  status_t ret = STATUS_SUCCESS;
154 #if FEATURE_FLS_HAS_FLEX_NVM
155  uint8_t DEPartitionCode; /* store D/E-Flash Partition Code */
156 #endif
157 
158  pSSDConfig->PFlashBase = pUserConf->PFlashBase;
159  pSSDConfig->PFlashSize = pUserConf->PFlashSize;
160  pSSDConfig->DFlashBase = pUserConf->DFlashBase;
161  pSSDConfig->EERAMBase = pUserConf->EERAMBase;
162  pSSDConfig->CallBack = pUserConf->CallBack;
163 
164 #if FEATURE_FLS_HAS_FLEX_NVM
165  /* Temporary solution for FTFC and S32K144 CSEc part */
166  /* Get DEPART from Flash Configuration Register 1 */
167  DEPartitionCode = (uint8_t)((SIM->FCFG1 & SIM_FCFG1_DEPART_MASK) >> SIM_FCFG1_DEPART_SHIFT);
168  /* Get data flash size */
169  FLASH_DRV_GetDEPartitionCode(pSSDConfig, DEPartitionCode);
170  if (pSSDConfig->DFlashSize < FEATURE_FLS_DF_BLOCK_SIZE)
171  {
172  pSSDConfig->EEESize = FEATURE_FLS_FLEX_RAM_SIZE;
173  }
174  else
175  {
176  pSSDConfig->EEESize = 0U;
177  }
178 #else /* FEATURE_FLS_HAS_FLEX_NVM == 0 */
179  /* If size of D/E-Flash = 0 */
180  pSSDConfig->DFlashSize = 0U;
181  pSSDConfig->EEESize = 0U;
182 #endif /* End of FEATURE_FLS_HAS_FLEX_NVM */
183 
184  return ret;
185 }
186 
187 /*FUNCTION**********************************************************************
188  *
189  * Function Name : FLASH_DRV_CommandSequence
190  * Description : Perform command write sequence on Flash.
191  * It is internal function, called by driver APIs only.
192  *
193  *END**************************************************************************/
195 static status_t FLASH_DRV_CommandSequence(const flash_ssd_config_t * pSSDConfig)
196 {
197  status_t ret = STATUS_SUCCESS; /* Return code variable */
198 
199  /* Clear CCIF to launch command */
201 
202  while (0U == (FTFx_FSTAT & FTFx_FSTAT_CCIF_MASK))
203  {
204  /* Wait till CCIF bit is set
205  * Serve callback function as often as possible
206  */
207  if (NULL_CALLBACK != pSSDConfig->CallBack)
208  {
209  /* Temporarily disable compiler's check for ROM access call from within a ram function.
210  * The use of a function pointer type makes this check irrelevant.
211  * Nevertheless, it is imperative that the user-provided callback be defined in RAMSECTION */
213  (pSSDConfig->CallBack)();
215  }
216  }
217 
218  /* Check if an error is occurred */
220  {
221  ret = STATUS_ERROR;
222  }
223 
224  return ret;
225 }
227 
228 /*FUNCTION**********************************************************************
229  *
230  * Function Name : FLASH_DRV_GetPFlashProtection
231  * Description : Retrieves the current P-Flash protection status.
232  * Considering the time consumption for getting protection is very low and
233  * even can be ignored. It is not necessary to utilize the Callback function to
234  * support the time-critical events.
235  *
236  * Implements : FLASH_DRV_GetPFlashProtection_Activity
237  *END**************************************************************************/
238 void FLASH_DRV_GetPFlashProtection(uint32_t * protectStatus)
239 {
240  DEV_ASSERT(protectStatus != NULL);
241  uint32_t reg0, reg1, reg2, reg3;
242 
243  reg0 = FTFx_FPROT0;
244  reg1 = FTFx_FPROT1;
245  reg2 = FTFx_FPROT2;
246  reg3 = FTFx_FPROT3;
247 
248  *protectStatus = (uint32_t)((reg0 << 24U) | (reg1 << 16U) | (reg2 << 8U) | reg3);
249 }
250 
251 /*FUNCTION**********************************************************************
252  *
253  * Function Name : FLASH_DRV_SetPFlashProtection
254  * Description : Sets the P-Flash protection to the intended protection status.
255  * Setting P-Flash protection status is subject to a protection transition
256  * restriction. If there is a setting violation, it returns an error code
257  * and the current protection status will not be changed.
258  *
259  * Implements : FLASH_DRV_SetPFlashProtection_Activity
260  *END**************************************************************************/
261 status_t FLASH_DRV_SetPFlashProtection(uint32_t protectStatus)
262 {
263  status_t ret = STATUS_SUCCESS;
264  uint8_t reg0, reg1, reg2, reg3;
265  bool flag0, flag1, flag2, flag3;
266 
267  /* Get register */
268  reg0 = GET_BIT_24_31(protectStatus);
269  reg1 = GET_BIT_16_23(protectStatus);
270  reg2 = GET_BIT_8_15(protectStatus);
271  reg3 = GET_BIT_0_7(protectStatus);
272 
273  /* Write to register */
274  FTFx_FPROT0 = reg0;
275  FTFx_FPROT1 = reg1;
276  FTFx_FPROT2 = reg2;
277  FTFx_FPROT3 = reg3;
278 
279  /* Compare changes */
280  flag0 = (FTFx_FPROT0 != reg0);
281  flag1 = (FTFx_FPROT1 != reg1);
282  flag2 = (FTFx_FPROT2 != reg2);
283  flag3 = (FTFx_FPROT3 != reg3);
284 
285  /* Read the value of FPPROT registers */
286  if (flag0 || flag1 || flag2 || flag3)
287  {
288  ret = STATUS_ERROR;
289  }
290 
291  return ret;
292 }
293 
294 /*FUNCTION**********************************************************************
295  *
296  * Function Name : FLASH_DRV_GetSecurityState
297  * Description : Retrieves the current Flash security status, including
298  * the security enabling state and the back door key enabling state.
299  *
300  * Implements : FLASH_DRV_GetSecurityState_Activity
301  *END**************************************************************************/
302 void FLASH_DRV_GetSecurityState(uint8_t * securityState)
303 {
304  DEV_ASSERT(securityState != NULL);
305  /* Store data read from flash register */
306  uint8_t regValue;
307 
308  /* Get flash security register value */
309  regValue = FTFx_FSEC;
310 
311  /* Check the status of the flash security bits in the security register */
313  {
314  /* Flash in unsecured state */
315  *securityState = FLASH_NOT_SECURE;
316  }
317  else
318  {
319  /* Flash in secured state
320  * Check for backdoor key security enable bit
321  */
322  if (0x80U == (regValue & FTFx_FSEC_KEYEN_MASK))
323  {
324  /* Backdoor key security enabled */
325  *securityState = FLASH_SECURE_BACKDOOR_ENABLED;
326  }
327  else
328  {
329  /* Backdoor key security disabled */
330  *securityState = FLASH_SECURE_BACKDOOR_DISABLED;
331  }
332  }
333 }
334 
335 /*FUNCTION**********************************************************************
336  *
337  * Function Name : FLASH_DRV_SecurityBypass
338  * Description : Un-secures the device by comparing the user's provided back
339  * door key with the ones in the Flash Configuration Field. If they are
340  * matched, the security is released. Otherwise, an error code is returned.
341  *
342  * Implements : FLASH_DRV_SecurityBypass_Activity
343  *END**************************************************************************/
345  const uint8_t * keyBuffer)
346 {
347  DEV_ASSERT(pSSDConfig != NULL);
348  DEV_ASSERT(keyBuffer != NULL);
349  status_t ret; /* Return code variable */
350  uint32_t temp; /* Temporary variable */
351  uint8_t i;
352 
353  /* Clear RDCOLERR & ACCERR & FPVIOL flag in flash status register. Write 1 to clear */
355 
356  /* Passing parameter to the command */
358  for (i = 0U; i < 8U; i++)
359  {
360  temp = FTFx_BASE + i + 0x08U;
361  *(uint8_t *)temp = keyBuffer[i];
362  }
363 
364  ret = FLASH_DRV_CommandSequence(pSSDConfig);
365 
366  return ret;
367 }
368 
369 /*FUNCTION**********************************************************************
370  *
371  * Function Name : FLASH_DRV_EraseAllBlock
372  * Description : Erases all Flash memory, initializes the FlexRAM, verifies
373  * all memory contents, and then releases the MCU security.
374  *
375  * Implements : FLASH_DRV_EraseAllBlock_Activity
376  *END**************************************************************************/
378 {
379  DEV_ASSERT(pSSDConfig != NULL);
380  status_t ret; /* Return code variable */
381 
382  /* Clear RDCOLERR & ACCERR & FPVIOL flag in flash status register. Write 1 to clear */
384 
385  /* Passing parameter to the command */
387 
388  /* Calling flash command sequence function to execute the command */
389  ret = FLASH_DRV_CommandSequence(pSSDConfig);
390 
391  return ret;
392 }
393 
394 /*FUNCTION**********************************************************************
395  *
396  * Function Name : FLASH_DRV_VerifyAllBlock
397  * Description : Checks to see if the P-Flash and/or D-Flash, EEPROM
398  * backup area, and D-Flash IFR have been erased to the specified read
399  * margin level, if applicable, and releases security if the readout passes.
400  *
401  * Implements : FLASH_DRV_VerifyAllBlock_Activity
402  *END**************************************************************************/
404  uint8_t marginLevel)
405 {
406  DEV_ASSERT(pSSDConfig != NULL);
407  status_t ret; /* Return code variable */
408 
409  /* Clear RDCOLERR & ACCERR & FPVIOL flag in flash status register. Write 1 to clear */
411 
412  /* Passing parameter to the command */
414  FTFx_FCCOB1 = marginLevel;
415 
416  /* Calling flash command sequence function to execute the command */
417  ret = FLASH_DRV_CommandSequence(pSSDConfig);
418 
419  return ret;
420 }
421 
422 /*FUNCTION**********************************************************************
423  *
424  * Function Name : FLASH_DRV_EraseSector
425  * Description : Erases one or more sectors in P-Flash or D-Flash memory.
426  * This API always returns STATUS_SUCCESS if size provided by the user is
427  * zero regardless of the input validation.
428  *
429  * Implements : FLASH_DRV_EraseSector_Activity
430  *END**************************************************************************/
432  uint32_t dest,
433  uint32_t size)
434 {
435  DEV_ASSERT(pSSDConfig != NULL);
436  status_t ret = STATUS_SUCCESS; /* Return code variable */
437  uint32_t sectorSize; /* Size of one sector */
438  uint32_t temp; /* Temporary variable */
439  uint32_t tempSize = size; /* Temporary of size variation */
440 
441 #if FEATURE_FLS_HAS_FLEX_NVM
442  temp = pSSDConfig->DFlashBase;
443  if ((dest >= temp) && (dest < (temp + pSSDConfig->DFlashSize)))
444  {
445  dest += 0x800000U - temp;
446  sectorSize = (uint32_t)FEATURE_FLS_DF_BLOCK_SECTOR_SIZE;
447  }
448  else
449 #endif
450  {
451  temp = pSSDConfig->PFlashBase;
452  if ((dest >= temp) && (dest < (temp + pSSDConfig->PFlashSize)))
453  {
454  dest -= temp;
455  sectorSize = (uint32_t)FEATURE_FLS_PF_BLOCK_SECTOR_SIZE;
456  }
457  else
458  {
459  ret = STATUS_ERROR;
460  tempSize = 0U;
461  sectorSize = 0U;
462  }
463  }
464 
465  /* Check if the size is sector alignment or not */
466  if ((tempSize & (sectorSize - 1U)) != 0U)
467  {
468  /* Return an error code */
469  ret = STATUS_UNSUPPORTED;
470  }
471 
472  while ((tempSize > 0U) && (STATUS_SUCCESS == ret))
473  {
474  /* Clear RDCOLERR & ACCERR & FPVIOL flag in flash status register. Write 1 to clear */
476 
477  /* Passing parameter to the command */
479  FTFx_FCCOB1 = GET_BIT_16_23(dest);
480  FTFx_FCCOB2 = GET_BIT_8_15(dest);
481  FTFx_FCCOB3 = GET_BIT_0_7(dest);
482 
483  /* Calling flash command sequence function to execute the command */
484  ret = FLASH_DRV_CommandSequence(pSSDConfig);
485 
486  /* Update size and destination address */
487  tempSize -= sectorSize;
488  dest += sectorSize;
489  }
490 
491  return ret;
492 }
493 
494 /*FUNCTION**********************************************************************
495  *
496  * Function Name : FLASH_DRV_VerifySection
497  * Description : Checks if a section of the P-Flash or the D-Flash memory
498  * is erased to the specified read margin level.
499  *
500  * Implements : FLASH_DRV_VerifySection_Activity
501  *END**************************************************************************/
503  uint32_t dest,
504  uint16_t number,
505  uint8_t marginLevel)
506 {
507  DEV_ASSERT(pSSDConfig != NULL);
508  status_t ret = STATUS_SUCCESS; /* Return code variable */
509  uint32_t temp;
510 
511  /* Check if the destination is aligned or not */
512 #if FEATURE_FLS_HAS_FLEX_NVM
513  temp = pSSDConfig->DFlashBase;
514  if ((dest >= temp) && (dest < (temp + pSSDConfig->DFlashSize)))
515  {
516  dest += 0x800000U - temp;
517  }
518  else
519 #endif
520  {
521  temp = pSSDConfig->PFlashBase;
522  if ((dest >= temp) && (dest < (temp + pSSDConfig->PFlashSize)))
523  {
524  dest -= temp;
525  }
526  else
527  {
528  ret = STATUS_ERROR;
529  }
530  }
531 
532  if (STATUS_SUCCESS == ret)
533  {
534  /* Clear RDCOLERR & ACCERR & FPVIOL flag in flash status register. Write 1 to clear */
536 
537  /* Passing parameter to the command */
539  FTFx_FCCOB1 = GET_BIT_16_23(dest);
540  FTFx_FCCOB2 = GET_BIT_8_15(dest);
541  FTFx_FCCOB3 = GET_BIT_0_7(dest);
542  FTFx_FCCOB4 = GET_BIT_8_15(number);
543  FTFx_FCCOB5 = GET_BIT_0_7(number);
544  FTFx_FCCOB6 = marginLevel;
545 
546  /* Calling flash command sequence function to execute the command */
547  ret = FLASH_DRV_CommandSequence(pSSDConfig);
548  }
549 
550  return ret;
551 }
552 
553 /*FUNCTION**********************************************************************
554  *
555  * Function Name : FLASH_DRV_EraseSuspend
556  * Description : Suspend a current operation of Flash erase sector command.
557  * This function must be located in RAM memory or different Flash blocks which are
558  * targeted for writing to avoid the RWW error.
559  *
560  * Implements : FLASH_DRV_EraseSuspend_Activity
561  *END**************************************************************************/
562 void FLASH_DRV_EraseSuspend(void)
563 {
564  if ((FTFx_FSTAT & FTFx_FSTAT_CCIF_MASK) == 0U)
565  {
567 
568  while ((FTFx_FSTAT & FTFx_FSTAT_CCIF_MASK) == 0U)
569  {
570  /* Wait till CCIF bit is set */
571  }
572  }
573 }
574 
575 /*FUNCTION**********************************************************************
576  *
577  * Function Name : FLASH_DRV_EraseResume
578  * Description : Resume a previous suspended operation of Flash erase sector command
579  * This function must be located in RAM memory or different Flash blocks which are targeted
580  * for writing to avoid RWW error.
581  *
582  * Implements : FLASH_DRV_EraseResume_Activity
583  *END**************************************************************************/
584 void FLASH_DRV_EraseResume(void)
585 {
586  uint16_t i = 0U; /* Counter variable */
587 
588  /* Check ERSSUSP bit of the flash configuration register */
589  if ((FTFx_FCNFG & FTFx_FCNFG_ERSSUSP_MASK) == FTFx_FCNFG_ERSSUSP_MASK)
590  {
591  /* Clear CCIF to launch command */
593  /* Wait for completion of this command */
594  while ((0U == (FTFx_FSTAT & FTFx_FSTAT_CCIF_MASK)) || (i < RESUME_WAIT_CNT))
595  {
596  i++;
597  }
598  }
599 }
600 
601 /*FUNCTION**********************************************************************
602  *
603  * Function Name : FLASH_DRV_ReadOnce
604  * Description : Read out a reserved 64 byte field located in the P-Flash IFR via given number
605  * of record. See the corresponding reference manual to get the correct value of this number.
606  *
607  * Implements : FLASH_DRV_ReadOnce_Activity
608  *END**************************************************************************/
610  uint8_t recordIndex,
611  uint8_t * pDataArray)
612 {
613  DEV_ASSERT(pSSDConfig != NULL);
614  DEV_ASSERT(pDataArray != NULL);
615  status_t ret; /* Return code variable */
616  uint32_t temp; /* Temporary variable */
617  uint8_t i;
618 
619  /* Clear RDCOLERR & ACCERR & FPVIOL flag in flash status register. Write 1 to clear */
621 
622  /* Passing parameter to the command */
624  FTFx_FCCOB1 = recordIndex;
625 
626  /* Calling flash command sequence function to execute the command */
627  ret = FLASH_DRV_CommandSequence(pSSDConfig);
628 
629  /* Checking for the success of command execution */
630  if (STATUS_SUCCESS == ret)
631  {
632  /* Read the data from the FCCOB registers into the pDataArray */
633  for (i = 0U; i < FEATURE_FLS_PF_BLOCK_WRITE_UNIT_SIZE; i++)
634  {
635  temp = FTFx_BASE + i + 0x08U;
636  pDataArray[i] = *(uint8_t *)temp;
637  }
638  }
639 
640  return ret;
641 }
642 
643 /*FUNCTION**********************************************************************
644  *
645  * Function Name : FLASH_DRV_ProgramOnce
646  * Description : Program to a reserved 64 byte field located in the
647  * P-Flash IFR via given number of record. See the corresponding reference manual
648  * to get correct value of this number.
649  *
650  * Implements : FLASH_DRV_ProgramOnce_Activity
651  *END**************************************************************************/
653  uint8_t recordIndex,
654  const uint8_t * pDataArray)
655 {
656  DEV_ASSERT(pSSDConfig != NULL);
657  DEV_ASSERT(pDataArray != NULL);
658  status_t ret; /* Return code variable */
659  uint32_t temp; /* Temporary variable */
660  uint8_t i;
661 
662  /* Clear RDCOLERR & ACCERR & FPVIOL flag in flash status register. Write 1 to clear */
664 
665  /* Passing parameter to the command */
667  FTFx_FCCOB1 = recordIndex;
668 
669  for (i = 0U; i < FEATURE_FLS_PF_BLOCK_WRITE_UNIT_SIZE; i++)
670  {
671  temp = FTFx_BASE + i + 0x08U;
672  *(uint8_t *)temp = pDataArray[i];
673  }
674 
675  /* Calling flash command sequence function to execute the command */
676  ret = FLASH_DRV_CommandSequence(pSSDConfig);
677 
678  return ret;
679 }
680 
681 #if FEATURE_FLS_HAS_READ_RESOURCE_CMD
682 /*FUNCTION**********************************************************************
683  *
684  * Function Name : FLASH_DRV_ReadResource
685  * Description : Read data from special purpose memory in Flash memory module
686  * including P-Flash IFR, swap IFR, D-Flash IFR space and version ID.
687  *
688  *END**************************************************************************/
689 status_t FLASH_DRV_ReadResource(const flash_ssd_config_t * pSSDConfig,
690  uint32_t dest,
691  uint8_t * pDataArray,
692  uint8_t resourceSelectCode)
693 {
694  DEV_ASSERT(pSSDConfig != NULL);
695  DEV_ASSERT(pDataArray != NULL);
696  status_t ret = STATUS_SUCCESS; /* Return code variable */
697  uint32_t temp;
698  uint8_t i;
699 
700  /* Check if the destination is aligned or not */
701 #if FEATURE_FLS_HAS_FLEX_NVM
702  temp = pSSDConfig->DFlashBase;
703  if ((dest >= temp) && (dest < (temp + pSSDConfig->DFlashSize)))
704  {
705  dest += 0x800000U - temp;
706  }
707  else
708 #endif
709  {
710  temp = pSSDConfig->PFlashBase;
711  if ((dest >= temp) && (dest < (temp + pSSDConfig->PFlashSize)))
712  {
713  dest -= temp;
714  }
715  else
716  {
717  ret = STATUS_ERROR;
718  }
719  }
720 
721  if (ret == STATUS_SUCCESS)
722  {
723  /* Clear RDCOLERR & ACCERR & FPVIOL flag in flash status register. Write 1 to clear */
725  /* Passing parameter to the command */
727  FTFx_FCCOB1 = GET_BIT_16_23(dest);
728  FTFx_FCCOB2 = GET_BIT_8_15(dest);
729  FTFx_FCCOB3 = GET_BIT_0_7(dest);
730  FTFx_RSRC_CODE_REG = resourceSelectCode;
731  /* Calling flash command sequence function to execute the command */
732  ret = FLASH_DRV_CommandSequence(pSSDConfig);
733 
734  if (STATUS_SUCCESS == ret)
735  {
736  /* Read the data from the FCCOB registers into the pDataArray */
737  for (i = 0U; i < FEATURE_FLS_PF_BLOCK_WRITE_UNIT_SIZE; i++)
738  {
739  temp = FTFx_BASE + i + 0x08U;
740  pDataArray[i] = *(uint8_t *)temp;
741  }
742  }
743  }
744 
745  return ret;
746 }
747 #endif /* if FEATURE_FLS_HAS_READ_RESOURCE_CMD */
748 
749 /*FUNCTION**********************************************************************
750  *
751  * Function Name : FLASH_DRV_Program
752  * Description : Program 4 consecutive bytes (for program long word command)
753  * and 8 consecutive bytes (for program phrase command) on P-Flash or D-Flash block.
754  * This API always returns STATUS_SUCCESS if size provided by user is
755  * zero regardless of the input validation.
756  *
757  * Implements : FLASH_DRV_Program_Activity
758  *END**************************************************************************/
760  uint32_t dest,
761  uint32_t size,
762  const uint8_t * pData)
763 {
764  DEV_ASSERT(pSSDConfig != NULL);
765  DEV_ASSERT(pData != NULL);
766  status_t ret = STATUS_SUCCESS; /* Return code variable */
767  uint32_t temp;
768  uint8_t i;
769 
770  if ((size & (FEATURE_FLS_PF_BLOCK_WRITE_UNIT_SIZE - 1U)) != 0U)
771  {
772  ret = STATUS_UNSUPPORTED;
773  }
774  else
775  {
776  #if FEATURE_FLS_HAS_FLEX_NVM
777  temp = pSSDConfig->DFlashBase;
778  if ((dest >= temp) && (dest < (temp + pSSDConfig->DFlashSize)))
779  {
780  dest += 0x800000U - temp;
781  }
782  else
783  #endif
784  {
785  temp = pSSDConfig->PFlashBase;
786  if ((dest >= temp) && (dest < (temp + pSSDConfig->PFlashSize)))
787  {
788  dest -= temp;
789  }
790  else
791  {
792  ret = STATUS_ERROR;
793  }
794  }
795 
796  while ((size > 0U) && (STATUS_SUCCESS == ret))
797  {
798  /* Clear RDCOLERR & ACCERR & FPVIOL flag in flash status register. Write 1 to clear */
800 
801  /* Passing parameter to the command */
802  #if (FEATURE_FLS_DF_BLOCK_WRITE_UNIT_SIZE == FTFx_PHRASE_SIZE)
804  #else
806  #endif
807  FTFx_FCCOB1 = GET_BIT_16_23(dest);
808  FTFx_FCCOB2 = GET_BIT_8_15(dest);
809  FTFx_FCCOB3 = GET_BIT_0_7(dest);
810 
811  for (i = 0U; i < FEATURE_FLS_PF_BLOCK_WRITE_UNIT_SIZE; i++)
812  {
813  temp = FTFx_BASE + i + 0x08U;
814  *(uint8_t *)(temp) = pData[i];
815  }
816 
817  /* Calling flash command sequence function to execute the command */
818  ret = FLASH_DRV_CommandSequence(pSSDConfig);
819 
820  /* Update destination address for next iteration */
822  /* Update size for next iteration */
824  /* Increment the source address by 1 */
826  }
827  }
828 
829  return ret;
830 }
831 
832 /*FUNCTION**********************************************************************
833  *
834  * Function Name : FLASH_DRV_ProgramCheck
835  * Description : Tests a previously programmed P-Flash or D-Flash long word
836  * to see if it reads correctly at the specified margin level. This
837  * API always returns STATUS_SUCCESS if size provided by user is zero
838  * regardless of the input validation
839  *
840  * Implements : FLASH_DRV_ProgramCheck_Activity
841  *END**************************************************************************/
843  uint32_t dest,
844  uint32_t size,
845  const uint8_t * pExpectedData,
846  uint32_t * pFailAddr,
847  uint8_t marginLevel)
848 {
849  DEV_ASSERT(pSSDConfig != NULL);
850  DEV_ASSERT(pExpectedData != NULL);
851  DEV_ASSERT(pFailAddr != NULL);
852  status_t ret = STATUS_SUCCESS; /* Return code variable */
853  uint32_t offsetAddr; /* Offset address to convert to internal memory address */
854  uint32_t temp; /* Temporary variable */
855  uint32_t tempSize = size; /* Temporary of size variation */
856  uint8_t i;
857 
858  if ((tempSize & (FEATURE_FLS_PF_CHECK_CMD_ADDRESS_ALIGMENT - 1U)) != 0U)
859  {
860  ret = STATUS_UNSUPPORTED;
861  }
862  else
863  {
864  /* Check if the destination is aligned or not */
865  #if FEATURE_FLS_HAS_FLEX_NVM
866  offsetAddr = pSSDConfig->DFlashBase;
867  if ((dest >= offsetAddr) && (dest < (offsetAddr + pSSDConfig->DFlashSize)))
868  {
869  dest += 0x800000U - offsetAddr;
870  }
871  else
872  #endif
873  {
874  offsetAddr = pSSDConfig->PFlashBase;
875  if ((dest >= offsetAddr) && (dest < (offsetAddr + pSSDConfig->PFlashSize)))
876  {
877  dest -= offsetAddr;
878  }
879  else
880  {
881  ret = STATUS_ERROR;
882  tempSize = 0U;
883  }
884  }
885 
886  while (tempSize > 0U)
887  {
888  /* Clear RDCOLERR & ACCERR & FPVIOL flag in flash status register. Write 1 to clear */
890 
891  /* Passing parameter to the command */
893  FTFx_FCCOB1 = GET_BIT_16_23(dest);
894  FTFx_FCCOB2 = GET_BIT_8_15(dest);
895  FTFx_FCCOB3 = GET_BIT_0_7(dest);
896  FTFx_FCCOB4 = marginLevel;
897 
898  for (i = 0U; i < FEATURE_FLS_PF_CHECK_CMD_ADDRESS_ALIGMENT; i++)
899  {
900  temp = FTFx_BASE + i + 0x0CU;
901  *(uint8_t *)(temp) = pExpectedData[i];
902  }
903 
904  /* Calling flash command sequence function to execute the command */
905  ret = FLASH_DRV_CommandSequence(pSSDConfig);
906 
907  /* Checking for the success of command execution */
908  if (STATUS_SUCCESS != ret)
909  {
910  #if FEATURE_FLS_HAS_FLEX_NVM
911  if (dest >= 0x800000U)
912  {
913  *pFailAddr = dest + offsetAddr - 0x800000U;
914  }
915  else
916  #endif
917  {
918  *pFailAddr = dest + offsetAddr;
919  }
920 
922  }
923 
924  /* Update size for next iteration */
926  /* Increment the source address by 1 */
928  /* Update destination address for next iteration */
930  }
931  }
932 
933  return ret;
934 }
935 
936 /*FUNCTION**********************************************************************
937  *
938  * Function Name : FLASH_DRV_CheckSum
939  * Description : Performs 32 bit sum of each byte data over a specified Flash
940  * memory range without carry which provides rapid method for checking data integrity.
941  * The callback time period of this API is determined via FLASH_CALLBACK_CS macro in the
942  * flash_driver.h which is used as a counter value for the CallBack() function calling in
943  * this API. This value can be changed as per the user requirement. User can change this value
944  * to obtain the maximum permissible callback time period.
945  * This API always returns STATUS_SUCCESS if size provided by user is zero regardless of the input
946  * validation.
947  *
948  * Implements : FLASH_DRV_CheckSum_Activity
949  *END**************************************************************************/
951  uint32_t dest,
952  uint32_t size,
953  uint32_t * pSum)
954 {
955  DEV_ASSERT(pSSDConfig != NULL);
956  DEV_ASSERT(pSum != NULL);
957  status_t ret = STATUS_SUCCESS; /* Return code variable */
958  uint32_t counter = 0U; /* Counter for callback operation */
959  uint32_t data; /* Data read from Flash address */
960  uint32_t endAddress; /* PFlash end address */
961  uint32_t tempSize = size; /* Temporary of size variation */
962 
963  /* Calculating Flash end address */
964  endAddress = dest + tempSize;
965 
966  /* Check for valid range of the target addresses */
967  if ((dest < pSSDConfig->PFlashBase) || (endAddress > (pSSDConfig->PFlashBase + pSSDConfig->PFlashSize)))
968  {
969  #if FEATURE_FLS_HAS_FLEX_NVM
970  if ((dest < pSSDConfig->DFlashBase) || (endAddress > (pSSDConfig->DFlashBase + pSSDConfig->DFlashSize)))
971  {
972  #endif
973  ret = STATUS_ERROR;
974  tempSize = 0U;
975  #if FEATURE_FLS_HAS_FLEX_NVM
976  }
977  #endif /* End of if FEATURE_FLS_HAS_FLEX_NVM */
978  }
979 
980  *pSum = 0U;
981  /* Doing sum operation */
982  while (tempSize > 0U)
983  {
984  data = *(uint8_t *)(dest);
985  *pSum += data;
986  dest += 1U;
987  tempSize -= 1U;
988  ++counter;
989 
990  /* Check if need to serve callback function */
991  if (counter >= FLASH_CALLBACK_CS)
992  {
993  /* Serve callback function if counter reaches limitation */
994  if (NULL_CALLBACK != pSSDConfig->CallBack)
995  {
996  pSSDConfig->CallBack();
997  }
998 
999  /* Reset counter */
1000  counter = 0U;
1001  }
1002  }
1003 
1004  return ret;
1005 }
1006 
1007 #if FEATURE_FLS_HAS_PROGRAM_SECTION_CMD
1008 /*FUNCTION**********************************************************************
1009  *
1010  * Function Name : FLASH_DRV_ProgramSection
1011  * Description : Program the data found in the Section Program Buffer
1012  * to previously erased locations in the Flash memory. Data is preloaded into
1013  * the Section Program Buffer by writing to the acceleration Ram and FlexRam
1014  * while it is set to function as a RAM. The Section Program Buffer is limited
1015  * to the value of FlexRam divides by a ratio. Refer to the associate reference
1016  * manual to get correct value of this ratio.
1017  * For derivatives including swap feature, the swap indicator address is encountered
1018  * during FlashProgramSection, it is bypassed without setting FPVIOL but the content
1019  * are not be programmed. In addition, the content of source data used to program to
1020  * swap indicator will be re-initialized to 0xFF after completion of this command.
1021  *
1022  * Implements : FLASH_DRV_ProgramSection_Activity
1023  *END**************************************************************************/
1025  uint32_t dest,
1026  uint16_t number)
1027 {
1028  DEV_ASSERT(pSSDConfig != NULL);
1029  status_t ret = STATUS_SUCCESS; /* Return code variable */
1030  uint32_t temp;
1031 
1032  /* Check RAMRDY bit of the flash configuration register */
1033  if (0U == (FTFx_FCNFG & FTFx_FCNFG_RAMRDY_MASK))
1034  {
1035  /* Return an error code */
1036  ret = STATUS_UNSUPPORTED;
1037  }
1038  else
1039  {
1040  #if FEATURE_FLS_HAS_FLEX_NVM
1041  temp = pSSDConfig->DFlashBase;
1042  if ((dest >= temp) && (dest < (temp + pSSDConfig->DFlashSize)))
1043  {
1044  dest += 0x800000U - temp;
1045  }
1046  else
1047  #endif
1048  {
1049  temp = pSSDConfig->PFlashBase;
1050  if ((dest >= temp) && (dest < (temp + pSSDConfig->PFlashSize)))
1051  {
1052  dest -= temp;
1053  }
1054  else
1055  {
1056  ret = STATUS_ERROR;
1057  }
1058  }
1059 
1060  if (ret == STATUS_SUCCESS)
1061  {
1062  /* Clear RDCOLERR & ACCERR & FPVIOL flag in flash status register.
1063  * Write 1 to clear
1064  */
1066  /* Passing parameter to command */
1068  FTFx_FCCOB1 = GET_BIT_16_23(dest);
1069  FTFx_FCCOB2 = GET_BIT_8_15(dest);
1070  FTFx_FCCOB3 = GET_BIT_0_7(dest);
1071  FTFx_FCCOB4 = GET_BIT_8_15(number);
1072  FTFx_FCCOB5 = GET_BIT_0_7(number);
1073 
1074  /* Calling flash command sequence function to execute the command */
1075  ret = FLASH_DRV_CommandSequence(pSSDConfig);
1076  }
1077  }
1078 
1079  return ret;
1080 }
1081 #endif /* if FEATURE_FLS_HAS_PROGRAM_SECTION_CMD */
1082 
1083 #if FEATURE_FLS_HAS_ERASE_BLOCK_CMD
1084 /*FUNCTION**********************************************************************
1085  *
1086  * Function Name : FLASH_DRV_EraseBlock
1087  * Description : Erases all addresses in an individual P-Flash or D-Flash block.
1088  * For the derivatives including multiply logical P-Flash or D-Flash blocks,
1089  * this API erases a single block in a single call.
1090  *
1091  * Implements : FLASH_DRV_EraseBlock_Activity
1092  *END**************************************************************************/
1094  uint32_t dest)
1095 {
1096  DEV_ASSERT(pSSDConfig != NULL);
1097  status_t ret = STATUS_SUCCESS; /* Return code variable */
1098  uint32_t temp; /* Temporary variable */
1099 
1100  /* Check if the destination is aligned or not */
1101 #if FEATURE_FLS_HAS_FLEX_NVM
1102  temp = pSSDConfig->DFlashBase;
1103  if ((dest >= temp) && (dest < (temp + pSSDConfig->DFlashSize)))
1104  {
1105  dest += 0x800000U - temp;
1106  }
1107  else
1108 #endif
1109  {
1110  temp = pSSDConfig->PFlashBase;
1111  if ((dest >= temp) && (dest < (temp + pSSDConfig->PFlashSize)))
1112  {
1113  dest -= temp;
1114  }
1115  else
1116  {
1117  ret = STATUS_ERROR;
1118  }
1119  }
1120 
1121  if (STATUS_SUCCESS == ret)
1122  {
1123  /* Clear RDCOLERR & ACCERR & FPVIOL flag in flash status register. Write 1 to clear */
1125 
1126  /* Passing parameter to the command */
1128  FTFx_FCCOB1 = GET_BIT_16_23(dest);
1129  FTFx_FCCOB2 = GET_BIT_8_15(dest);
1130  FTFx_FCCOB3 = GET_BIT_0_7(dest);
1131 
1132  /* Calling flash command sequence function to execute the command */
1133  ret = FLASH_DRV_CommandSequence(pSSDConfig);
1134  }
1135 
1136  return ret;
1137 }
1138 #endif /* if FEATURE_FLS_HAS_ERASE_BLOCK_CMD */
1139 
1140 #if FEATURE_FLS_HAS_READ_1S_BLOCK_CMD
1141 /*FUNCTION**********************************************************************
1142  *
1143  * Function Name : FLASH_DRV_VerifyBlock
1144  * Description : Checks to see if an entire P-Flash or D-Flash block has been
1145  * erased to the specified margin level. For the derivatives including multiply
1146  * logical P-Flash or D-Flash blocks, this API erases a single block in a single call.
1147  *
1148  * Implements : FLASH_DRV_VerifyBlock_Activity
1149  *END**************************************************************************/
1151  uint32_t dest,
1152  uint8_t marginLevel)
1153 {
1154  DEV_ASSERT(pSSDConfig != NULL);
1155  status_t ret = STATUS_SUCCESS; /* Return code variable */
1156  uint32_t temp;
1157 
1158  /* Check if the destination is aligned or not */
1159 #if FEATURE_FLS_HAS_FLEX_NVM
1160  temp = pSSDConfig->DFlashBase;
1161  if ((dest >= temp) && (dest < (temp + pSSDConfig->DFlashSize)))
1162  {
1163  dest += 0x800000U - temp;
1164  }
1165  else
1166 #endif
1167  {
1168  temp = pSSDConfig->PFlashBase;
1169  if ((dest >= temp) && (dest < (temp + pSSDConfig->PFlashSize)))
1170  {
1171  dest -= temp;
1172  }
1173  else
1174  {
1175  ret = STATUS_ERROR;
1176  }
1177  }
1178 
1179  if (STATUS_SUCCESS == ret)
1180  {
1181  /* Clear RDCOLERR & ACCERR & FPVIOL flag in flash status register. Write 1 to clear */
1183 
1184  /* Passing parameter to the command */
1186  FTFx_FCCOB1 = GET_BIT_16_23(dest);
1187  FTFx_FCCOB2 = GET_BIT_8_15(dest);
1188  FTFx_FCCOB3 = GET_BIT_0_7(dest);
1189  FTFx_FCCOB4 = marginLevel;
1190 
1191  /* Calling flash command sequence function to execute the command */
1192  ret = FLASH_DRV_CommandSequence(pSSDConfig);
1193  }
1194 
1195  return ret;
1196 }
1197 #endif /* if FEATURE_FLS_HAS_READ_1S_BLOCK_CMD */
1198 
1199 #if FEATURE_FLS_HAS_FLEX_NVM
1200 /*FUNCTION**********************************************************************
1201  *
1202  * Function Name : FLASH_DRV_GetEERAMProtection
1203  * Description : Retrieves which EEPROM sections of FlexRAM are protected
1204  * against program and erase operations. Considering the time consumption
1205  * for getting protection is very low and even can be ignored, it is not necessary
1206  * to utilize the Callback function to support the time-critical events
1207  *
1208  * Implements : FLASH_DRV_GetEERAMProtection_Activity
1209  *END**************************************************************************/
1210 status_t FLASH_DRV_GetEERAMProtection(uint8_t * protectStatus)
1211 {
1212  DEV_ASSERT(protectStatus != NULL);
1213  status_t ret = STATUS_SUCCESS; /* Return code variable */
1214 
1215  /* Check if EERAM is set for EEPROM */
1216  if ((FTFx_FCNFG & FTFx_FCNFG_EEERDY_MASK) == FTFx_FCNFG_EEERDY_MASK)
1217  {
1218  *protectStatus = FTFx_FEPROT;
1219  }
1220  else
1221  {
1222  ret = STATUS_UNSUPPORTED;
1223  }
1224 
1225  return ret;
1226 }
1227 
1228 /*FUNCTION**********************************************************************
1229  *
1230  * Function Name : FLASH_DRV_SetEERAMProtection
1231  * Description : Sets protection to the intended protection status for EEPROM us
1232  * area of FlexRam. This is subject to a protection transition restriction.
1233  * If there is a setting violation, it returns failed information and
1234  * the current protection status will not be changed.
1235  *
1236  * Implements : FLASH_DRV_SetEERAMProtection_Activity
1237  *END**************************************************************************/
1238 status_t FLASH_DRV_SetEERAMProtection(uint8_t protectStatus)
1239 {
1240  status_t ret = STATUS_SUCCESS; /* Return code variable */
1241 
1242  /* Check if FlexRAM is set for EEPROM */
1243  if (0U == (FTFx_FCNFG & FTFx_FCNFG_EEERDY_MASK))
1244  {
1245  /* FlexRAM is not set for EEPROM */
1246  ret = STATUS_UNSUPPORTED;
1247  }
1248  else
1249  {
1250  FTFx_FEPROT = protectStatus;
1251  if (protectStatus != FTFx_FEPROT)
1252  {
1253  ret = STATUS_ERROR;
1254  }
1255  else
1256  {
1257  /* Do nothing */
1258  }
1259  }
1260 
1261  return ret;
1262 }
1263 
1264 /*FUNCTION**********************************************************************
1265  *
1266  * Function Name : FLASH_DRV_SetFlexRamFunction
1267  * Description : This function is used to change the function of the FlexRAM. When not partitioned for
1268  * emulated EEPROM, the FlexRAM is typically used as traditional RAM.
1269  * Otherwise, the FlexRam is typically used to store EEPROM data, the writing to EEPROM is normal write or
1270  * quick write.
1271  * In addition, this function may be used to get EEPROM status or complete interrupted EEPROM quick write process.
1272  * For example, after partitioning to have EEPROM backup, FlexRAM is used for EEPROM
1273  * use accordingly and if want to change FlexRAM to traditional RAM for FlashProgramSection() use, call this API
1274  * with the function control code is 0xFFU.
1275  *
1276  * Implements : FLASH_DRV_SetFlexRamFunction_Activity
1277  *END**************************************************************************/
1279  flash_flexRam_function_control_code_t flexRamFuncCode,
1280  uint16_t byteOfQuickWrite,
1281  flash_eeprom_status_t * const pEEPROMStatus)
1282 {
1283  DEV_ASSERT(pSSDConfig != NULL);
1284  status_t ret; /* Return code variable */
1285 
1286  /* Clear RDCOLERR & ACCERR & FPVIOL flag in flash status register. Write 1 to clear */
1288 
1289  /* Passing parameter to the command */
1291  FTFx_FCCOB1 = (uint8_t)flexRamFuncCode;
1292 
1293  if (flexRamFuncCode == EEE_QUICK_WRITE)
1294  {
1295  FTFx_FCCOB4 = (uint8_t)(byteOfQuickWrite >> 0x8U);
1296  FTFx_FCCOB5 = (uint8_t)(byteOfQuickWrite & 0xFFU);
1297  }
1298 
1299  /* Calling flash command sequence function to execute the command */
1300  ret = FLASH_DRV_CommandSequence(pSSDConfig);
1301 
1302  if ((flexRamFuncCode == EEE_STATUS_QUERY) && (ret == STATUS_SUCCESS))
1303  {
1304  if (pEEPROMStatus == NULL)
1305  {
1306  ret = STATUS_ERROR;
1307  }
1308  else
1309  {
1310  pEEPROMStatus->brownOutCode = FTFx_FCCOB5;
1311  pEEPROMStatus->sectorEraseCount = (uint16_t)((uint16_t)FTFx_FCCOB8 << 8U);
1312  pEEPROMStatus->sectorEraseCount |= (uint16_t)FTFx_FCCOB9;
1313  pEEPROMStatus->numOfRecordReqMaintain = (uint16_t)((uint16_t)FTFx_FCCOB6 << 8U);
1314  pEEPROMStatus->numOfRecordReqMaintain |= (uint16_t)FTFx_FCCOB7;
1315  }
1316  }
1317 
1318  return ret;
1319 }
1320 
1321 /*FUNCTION**********************************************************************
1322  *
1323  * Function Name : FLASH_DRV_WaitEEWriteToFinish
1324  * Description : Write to EEPROM with data was aligned and wait until operation finish.
1325  *
1326  *END**************************************************************************/
1327 static status_t FLASH_DRV_WaitEEWriteToFinish(uint32_t dest,
1328  const uint8_t * pData,
1329  uint8_t step)
1330 {
1331  DEV_ASSERT(pData != NULL);
1332  status_t ret = STATUS_SUCCESS; /* Return code variable */
1333  uint32_t temp; /* Temporary variable */
1334 
1335  if (0x01U == step)
1336  {
1337  *(uint8_t *)dest = *pData;
1338  }
1339 
1340  if (0x02U == step)
1341  {
1342  temp = (uint32_t)(pData[1]) << 8U;
1343  temp |= (uint32_t)(pData[0]);
1344  *(volatile uint16_t *)dest = (uint16_t)temp;
1345  }
1346 
1347  if (0x04U == step)
1348  {
1349  temp = (uint32_t)(pData[3]) << 24U;
1350  temp |= (uint32_t)(pData[2]) << 16U;
1351  temp |= (uint32_t)(pData[1]) << 8U;
1352  temp |= (uint32_t)(pData[0]);
1353  *(volatile uint32_t *)dest = temp;
1354  }
1355 
1356  while (0U == (FTFx_FCNFG & FTFx_FCNFG_EEERDY_MASK))
1357  {
1358  /* Wait till EEERDY bit is set */
1359  }
1360 
1361  /* Check for protection violation error */
1363  {
1364  ret = STATUS_ERROR;
1365  }
1366 
1367  return ret;
1368 }
1369 
1370 /*FUNCTION**********************************************************************
1371  *
1372  * Function Name : FLASH_DRV_EEEWrite
1373  * Description : Write data to FlexRAM section which is partitioned
1374  * as EEPROM use for EEPROM operation. After data has been written to EEPROM
1375  * use section of FlexRAM, the EEPROM file system will create new data record
1376  * in EEPROM back-up area of FlexNVM in round-robin fashion.
1377  * There is no alignment constraint for destination and size parameters
1378  * provided by user. However, according to user's input provided, this
1379  * API will set priority to write to FlexRAM with following rules:
1380  * 32-bit writing is invoked if destination is 32 bit aligned and size
1381  * is not less than 32 bits.
1382  * 16-bit writing is invoked if destination is 16 bit aligned and size
1383  * is not less than 16 bits.
1384  * 8-bit writing is invoked if destination is 8 bit aligned and size
1385  * is not less than 8 bits.
1386  *
1387  * Implements : FLASH_DRV_EEEWrite_Activity
1388  *END**************************************************************************/
1390  uint32_t dest,
1391  uint32_t size,
1392  const uint8_t * pData)
1393 {
1394  DEV_ASSERT(pSSDConfig != NULL);
1395  DEV_ASSERT(pData != NULL);
1396  status_t ret = STATUS_SUCCESS; /* Return code variable */
1397  uint8_t i;
1398 
1399  /* Check if EEE is enabled */
1400  if ((FTFx_FCNFG & FTFx_FCNFG_EEERDY_MASK) == FTFx_FCNFG_EEERDY_MASK)
1401  {
1402  /* Check range */
1403  if ((dest < pSSDConfig->EERAMBase) || ((dest + size) > (pSSDConfig->EERAMBase + pSSDConfig->EEESize)))
1404  {
1405  ret = STATUS_ERROR;
1406  }
1407 
1408  while ((size > 0U) && (ret == STATUS_SUCCESS))
1409  {
1410  /* Dest is 32bit-aligned and size is not less than 4 */
1411  if ((0U == (dest & 3U)) && (size >= 4U))
1412  {
1413  i = 4U;
1414  }
1415  else if ((0U == (dest & 1U)) && (size >= 2U))
1416  {
1417  i = 2U;
1418  }
1419  else
1420  {
1421  i = 1U;
1422  }
1423 
1424  ret = FLASH_DRV_WaitEEWriteToFinish(dest, pData, i);
1425  /* Update destination address for next iteration */
1426  dest += i;
1427  /* Update size for next iteration */
1428  size -= i;
1429  /* Update data for next iteration */
1430  pData += i;
1431  }
1432  }
1433  else
1434  {
1435  ret = STATUS_UNSUPPORTED;
1436  }
1437 
1438  return ret;
1439 }
1440 
1441 /*FUNCTION**********************************************************************
1442  *
1443  * Function Name : FLASH_DRV_DEFlashPartition
1444  * Description : Prepares the FlexNVM block for use as D-Flash, EEPROM backup, or a combination
1445  * of both and initializes the FlexRAM.
1446  * The single partition choice should be used through entire life time of a given
1447  * application to guarantee the Flash endurance and data retention of Flash module.
1448  *
1449  * Implements : FLASH_DRV_DEFlashPartition_Activity
1450  *END**************************************************************************/
1452  uint8_t uEEEDataSizeCode,
1453  uint8_t uDEPartitionCode,
1454  uint8_t uCSEcKeySize,
1455  bool uSFE)
1456 {
1457  DEV_ASSERT(pSSDConfig != NULL);
1458  DEV_ASSERT(uCSEcKeySize <= CSE_KEY_SIZE_CODE_MAX);
1459  status_t ret; /* Return code variable */
1460 
1461  /* Clear RDCOLERR & ACCERR & FPVIOL & MGSTAT0 flag in flash status register. Write 1 to clear */
1463 
1464  /* Passing parameter to the command */
1466  FTFx_FCCOB1 = uCSEcKeySize;
1467  FTFx_FCCOB2 = (uint8_t)(uSFE ? 1U : 0U);
1468  FTFx_FCCOB4 = uEEEDataSizeCode;
1469  FTFx_FCCOB5 = uDEPartitionCode;
1470 
1471  /* Calling flash command sequence function to execute the command */
1472  ret = FLASH_DRV_CommandSequence(pSSDConfig);
1473 
1474  return ret;
1475 }
1476 
1477 /*FUNCTION**********************************************************************
1478  *
1479  * Function Name : FLASH_DRV_GetDFlashProtection
1480  * Description : Retrieves current P-Flash protection status. Considering the time consumption
1481  * for getting protection is very low and even can be ignored, it is not necessary to utilize
1482  * the Callback function to support the time-critical events.
1483  *
1484  * Implements : FLASH_DRV_GetDFlashProtection_Activity
1485  *END**************************************************************************/
1487  uint8_t * protectStatus)
1488 {
1489  DEV_ASSERT(pSSDConfig != NULL);
1490  DEV_ASSERT(protectStatus != NULL);
1491  status_t ret = STATUS_SUCCESS; /* Return code variable */
1492 
1493  /* Check if size of DFlash = 0 */
1494  if (pSSDConfig->DFlashSize == 0U)
1495  {
1496  ret = STATUS_UNSUPPORTED;
1497  }
1498  else
1499  {
1500  *protectStatus = FTFx_FDPROT;
1501  }
1502 
1503  return ret;
1504 }
1505 
1506 /*FUNCTION**********************************************************************
1507  *
1508  * Function Name : FLASH_DRV_SetDFlashProtection
1509  * Description : Sets the D-Flash protection to the intended protection status.
1510  * Setting D-Flash protection status is subject to a protection transition restriction.
1511  * If there is a setting violation, it returns failed information
1512  * and the current protection status will not be changed.
1513  *
1514  * Implements : FLASH_DRV_SetDFlashProtection_Activity
1515  *END**************************************************************************/
1517  uint8_t protectStatus)
1518 {
1519  DEV_ASSERT(pSSDConfig != NULL);
1520  status_t ret = STATUS_SUCCESS; /* Return code variable */
1521 
1522  /* Check if size of DFlash = 0 */
1523  if (pSSDConfig->DFlashSize == 0U)
1524  {
1525  ret = STATUS_UNSUPPORTED;
1526  }
1527  else
1528  {
1529  FTFx_FDPROT = protectStatus;
1530  if (protectStatus != FTFx_FDPROT)
1531  {
1532  ret = STATUS_ERROR;
1533  }
1534  else
1535  {
1536  /* Do nothing */
1537  }
1538  }
1539 
1540  return ret;
1541 }
1542 #endif /* If FEATURE_FLS_HAS_FLEX_NVM */
1543 
1544 #if FEATURE_FLS_HAS_PF_BLOCK_SWAP
1545 /*FUNCTION**********************************************************************
1546  *
1547  * Function Name : FLASH_DRV_PFlashSwap
1548  * Description : Provides to user with an ability to interfere in a swap progress by letting the
1549  * user code know about the swap state in each phase of the process. This is done via pSwapCallBack()
1550  * parameter. To stop at each intermediate swap state, set the return value of
1551  * this callback function to FALSE. To complete swap process within a single call,
1552  * set the return value of this function to TRUE.
1553  *
1554  * Erase the non-active swap indicator somewhere in the application code
1555  * or in the swap call back function when swap system is in UPDATE state.
1556  *
1557  * In addition, if user does not want to use the swap call back parameter, pass the NULL_SWAP_CALLBACK
1558  * as a null pointer. In this situation, the PFlashSwap() behaves in the same way as setting the return
1559  * value of pSwapCallBack to TRUE and the user does not need to erase the non-active swap
1560  * indicator when the swap system is in UPDATE state.
1561  * The swap indicator provided by the user must be within the lower half of P-Flash block but not in the
1562  * Flash configuration area. If P-Flash block has two logical blocks, the swap indicator must be
1563  * in P-Flash block 0. If the P-Flash block has four logical blocks, the swap indicator can be in block
1564  * 0 or block 1. It must not be in the Flash configuration field.
1565  * The user must use the same swap indicator for all swap control code except report swap status once
1566  * swap system has been initialized. To refresh swap system to un-initialization state,
1567  * use the FlashEraseAllBlock() to clean up the swap environment.
1568  *
1569  *END**************************************************************************/
1570 status_t FLASH_DRV_PFlashSwap(const flash_ssd_config_t * pSSDConfig,
1571  uint32_t addr,
1572  flash_swap_callback_t pSwapCallback)
1573 {
1574  DEV_ASSERT(pSSDConfig != NULL);
1575  DEV_ASSERT(pSwapCallback != NULL);
1576  status_t ret = STATUS_SUCCESS; /* Return code variable */
1577  uint8_t currentSwapMode, currentSwapBlockStatus, nextSwapBlockStatus;
1578  bool swapContinue;
1579  currentSwapMode = 0xFFU;
1580  currentSwapBlockStatus = 0xFFU;
1581  nextSwapBlockStatus = 0xFFU;
1582  swapContinue = false;
1583 
1584  /* Report current swap state */
1585  ret = FLASH_DRV_PFlashSwapCtl(pSSDConfig, addr, FTFx_SWAP_REPORT_STATUS, &currentSwapMode, &currentSwapBlockStatus, &nextSwapBlockStatus);
1586 
1587  if (STATUS_SUCCESS == ret)
1588  {
1589  if ((FTFx_SWAP_UNINIT == currentSwapMode) || (FTFx_SWAP_READY == currentSwapMode) || (FTFx_SWAP_UPDATE == currentSwapMode))
1590  {
1591  /* If current swap mode is Uninitialized */
1592  if (FTFx_SWAP_UNINIT == currentSwapMode)
1593  {
1594  /* Initialize Swap to Initialized/READY state */
1595  ret = FLASH_DRV_PFlashSwapCtl(pSSDConfig,
1596  addr,
1598  &currentSwapMode,
1599  &currentSwapBlockStatus,
1600  &nextSwapBlockStatus);
1601  }
1602  /* If current swap mode is Initialized/Ready */
1603  else if (FTFx_SWAP_READY == currentSwapMode)
1604  {
1605  /* Initialize Swap to UPDATE state */
1606  ret = FLASH_DRV_PFlashSwapCtl(pSSDConfig,
1607  addr,
1609  &currentSwapMode,
1610  &currentSwapBlockStatus,
1611  &nextSwapBlockStatus);
1612  }
1613  else
1614  {
1615  /* If (FTFx_SWAP_UPDATE == currentSwapMode) do nothing */
1616  }
1617 
1618  /* Check for the success of command execution
1619  * Report the current swap state to user via callback
1620  */
1621  if ((NULL_SWAP_CALLBACK != pSwapCallback) && (STATUS_SUCCESS == ret))
1622  {
1623  swapContinue = pSwapCallback(currentSwapMode);
1624 
1625  if (swapContinue == true)
1626  {
1627  /* Report current swap state */
1628  ret = FLASH_DRV_PFlashSwapCtl(pSSDConfig,
1629  addr,
1631  &currentSwapMode,
1632  &currentSwapBlockStatus,
1633  &nextSwapBlockStatus);
1634  }
1635  }
1636  }
1637  else
1638  {
1639  /* Do nothing */
1640  }
1641 
1642  if ((NULL_SWAP_CALLBACK == pSwapCallback) && (FTFx_SWAP_UPDATE == currentSwapMode))
1643  {
1644  /* Erase indicator sector in non active block to proceed swap system to update-erased state */
1645  ret = FLASH_DRV_EraseSector(pSSDConfig, addr + (pSSDConfig->PFlashSize >> 1U), (uint32_t)FEATURE_FLS_PF_BLOCK_SECTOR_SIZE);
1646  if (STATUS_SUCCESS == ret)
1647  {
1648  /* Now the swap state must be Update-Erased, so report current swap state */
1649  ret = FLASH_DRV_PFlashSwapCtl(pSSDConfig,
1650  addr,
1652  &currentSwapMode,
1653  &currentSwapBlockStatus,
1654  &nextSwapBlockStatus);
1655  }
1656  }
1657 
1658  /* If current swap mode is Update or Update-Erased */
1659  if (FTFx_SWAP_UPDATE_ERASED == currentSwapMode)
1660  {
1661  if (NULL_SWAP_CALLBACK == pSwapCallback)
1662  {
1663  swapContinue = true;
1664  }
1665  else
1666  {
1667  swapContinue = pSwapCallback(currentSwapMode);
1668  }
1669 
1670  if (swapContinue == true)
1671  {
1672  /* Progress Swap to COMPLETE State */
1673  ret = FLASH_DRV_PFlashSwapCtl(pSSDConfig,
1674  addr,
1676  &currentSwapMode,
1677  &currentSwapBlockStatus,
1678  &nextSwapBlockStatus);
1679  }
1680  }
1681  }
1682 
1683  return ret;
1684 }
1685 
1686 /*FUNCTION**********************************************************************
1687  *
1688  * Function Name : FLASH_DRV_PFlashSwapCtl
1689  * Description : Performs swap control command corresponding with the swap
1690  * control code provided via the swap command parameter.
1691  *
1692  *END**************************************************************************/
1693 status_t FLASH_DRV_PFlashSwapCtl(const flash_ssd_config_t * pSSDConfig,
1694  uint32_t addr,
1695  uint8_t swapcmd,
1696  uint8_t * pCurrentSwapMode,
1697  uint8_t * pCurrentSwapBlockStatus,
1698  uint8_t * pNextSwapBlockStatus)
1699 {
1700  DEV_ASSERT(pSSDConfig != NULL);
1701  DEV_ASSERT(pCurrentSwapMode != NULL);
1702  DEV_ASSERT(pCurrentSwapBlockStatus != NULL);
1703  DEV_ASSERT(pNextSwapBlockStatus != NULL);
1704  status_t ret; /* Return code variable */
1705 
1706  /* Clear RDCOLERR & ACCERR & FPVIOL flag in flash status register. Write 1 to clear */
1708 
1709  /* Passing parameter to the command */
1711  FTFx_FCCOB1 = GET_BIT_16_23(addr);
1712  FTFx_FCCOB2 = GET_BIT_8_15(addr);
1713  FTFx_FCCOB3 = GET_BIT_0_7(addr);
1714  FTFx_FCCOB4 = swapcmd;
1715  FTFx_FCCOB5 = 0xFFU;
1716  FTFx_FCCOB6 = 0xFFU;
1717  FTFx_FCCOB7 = 0xFFU;
1718 
1719  /* Calling flash command sequence function to execute the command */
1720  ret = FLASH_DRV_CommandSequence(pSSDConfig);
1721 
1722  if (STATUS_SUCCESS == ret)
1723  {
1724  *pCurrentSwapMode = FTFx_FCCOB5;
1725  *pCurrentSwapBlockStatus = FTFx_FCCOB6;
1726  *pNextSwapBlockStatus = FTFx_FCCOB7;
1727  }
1728 
1729  return ret;
1730 }
1731 #endif /* End of FEATURE_FLASH_HAS_PFLASH_BLOCK_SWAP */
1732 
1733 #if FEATURE_FLS_HAS_ERASE_ALL_BLOCKS_UNSECURE_CMD
1734 /*FUNCTION**********************************************************************
1735  *
1736  * Function Name : FLASH_DRV_EraseAllBlockUnsecure
1737  * Description : Erases all Flash memory, initializes the FlexRAM, verifies
1738  * all memory contents, and then releases the MCU security.
1739  *
1740  * Implements : FLASH_DRV_EraseAllBlockUnsecure_Activity
1741  *END**************************************************************************/
1743 {
1744  DEV_ASSERT(pSSDConfig != NULL);
1745  status_t ret; /* Return code variable */
1746 
1747  /* Clear RDCOLERR & ACCERR & FPVIOL flag in flash status register. Write 1 to clear */
1749 
1750  /* Passing parameter to the command */
1752 
1753  /* Calling flash command sequence function to execute the command */
1754  ret = FLASH_DRV_CommandSequence(pSSDConfig);
1755 
1756  return ret;
1757 }
1758 
1759 #endif /* End of FEATURE_FLS_HAS_ERASE_ALL_BLOCKS_UNSECURE_CMD */
1760 
1761 /*******************************************************************************
1762 * EOF
1763 *******************************************************************************/
#define FTFx_FCNFG_RAMRDY_MASK
Definition: flash_driver.h:259
#define FEATURE_FLS_PF_CHECK_CMD_ADDRESS_ALIGMENT
status_t FLASH_DRV_GetDFlashProtection(const flash_ssd_config_t *pSSDConfig, uint8_t *protectStatus)
D-Flash get protection.
#define FTFx_SWAP_SET_IN_COMPLETE
Set Swap in Complete State.
Definition: flash_driver.h:427
status_t FLASH_DRV_VerifyAllBlock(const flash_ssd_config_t *pSSDConfig, uint8_t marginLevel)
Flash verify all blocks.
#define NULL_CALLBACK
Null callback.
Definition: flash_driver.h:521
#define FTFx_FSEC_SEC_MASK
Definition: flash_driver.h:280
#define FEATURE_FLS_DF_SIZE_0010
#define FTFx_FSTAT_ACCERR_MASK
Definition: flash_driver.h:242
#define FTFx_VERIFY_BLOCK
Definition: flash_driver.h:398
#define FTFx_VERIFY_SECTION
Definition: flash_driver.h:399
#define FEATURE_FLS_PF_BLOCK_WRITE_UNIT_SIZE
#define FTFx_FCNFG_EEERDY_MASK
Definition: flash_driver.h:255
#define FEATURE_FLS_PF_BLOCK_SECTOR_SIZE
void FLASH_DRV_EraseResume(void)
Flash erase resume.
status_t FLASH_DRV_SetEERAMProtection(uint8_t protectStatus)
EERAM set protection.
flash_callback_t CallBack
Definition: flash_driver.h:589
#define FEATURE_FLS_EE_SIZE_1000
#define FEATURE_FLS_EE_SIZE_1010
#define FEATURE_FLS_DF_SIZE_0111
#define CLEAR_FTFx_FSTAT_ERROR_BITS
Definition: flash_driver.h:377
status_t FLASH_DRV_GetEERAMProtection(uint8_t *protectStatus)
EERAM get protection.
#define FTFx_SWAP_SET_IN_PREPARE
Set Swap in Update State.
Definition: flash_driver.h:425
#define FLASH_NOT_SECURE
Flash currently not in secure state.
Definition: flash_driver.h:493
void FLASH_DRV_EraseSuspend(void)
Flash erase suspend.
#define FTFx_FPROT1
Definition: flash_driver.h:222
status_t FLASH_DRV_EEEWrite(const flash_ssd_config_t *pSSDConfig, uint32_t dest, uint32_t size, const uint8_t *pData)
EEPROM Emulator Write.
#define SIM
Definition: S32K144.h:10739
#define FEATURE_FLS_EE_SIZE_1110
#define FTFx_PROGRAM_ONCE
Definition: flash_driver.h:409
#define FTFx_SET_EERAM
Definition: flash_driver.h:415
#define FLASH_SECURE_BACKDOOR_DISABLED
Flash is secured and backdoor key access disabled.
Definition: flash_driver.h:497
status_t FLASH_DRV_EraseSector(const flash_ssd_config_t *pSSDConfig, uint32_t dest, uint32_t size)
Flash erase sector.
#define GET_BIT_0_7(value)
Definition: flash_driver.h:457
#define FEATURE_FLS_EE_SIZE_0100
#define END_FUNCTION_DECLARATION_RAMSECTION
Definition: s32_core_cm4.h:147
#define FTFx_FEPROT
Definition: flash_driver.h:224
#define FTFx_FSTAT_RDCOLERR_MASK
Definition: flash_driver.h:246
#define FTFx_SWAP_UPDATE
Update swap mode.
Definition: flash_driver.h:441
#define FEATURE_FLS_EE_SIZE_1111
#define FLASH_CALLBACK_CS
Callback period count for FlashCheckSum.
Definition: flash_driver.h:510
status_t FLASH_DRV_DEFlashPartition(const flash_ssd_config_t *pSSDConfig, uint8_t uEEEDataSizeCode, uint8_t uDEPartitionCode, uint8_t uCSEcKeySize, bool uSFE)
Flash D/E-Flash Partition.
#define FTFx_FCCOB8
Definition: flash_driver.h:219
#define FTFx_PROGRAM_CHECK
Definition: flash_driver.h:400
#define FTFx_FCCOB2
Definition: flash_driver.h:209
#define FEATURE_FLS_EE_SIZE_0000
status_t FLASH_DRV_Init(const flash_user_config_t *const pUserConf, flash_ssd_config_t *const pSSDConfig)
Initializes Flash.
#define FTFx_SECURITY_BY_PASS
Definition: flash_driver.h:411
#define FEATURE_FLS_EE_SIZE_1001
#define FTFx_FPROT0
Definition: flash_driver.h:223
#define FTFx_ERASE_ALL_BLOCK
Definition: flash_driver.h:410
#define FEATURE_FLS_EE_SIZE_0111
status_t FLASH_DRV_Program(const flash_ssd_config_t *pSSDConfig, uint32_t dest, uint32_t size, const uint8_t *pData)
Flash program.
#define FTFx_ERASE_ALL_BLOCK_UNSECURE
Definition: flash_driver.h:413
#define FTFx_FCCOB4
Definition: flash_driver.h:215
#define FTFx_SWAP_REPORT_STATUS
Report Swap Status.
Definition: flash_driver.h:429
#define FTFx_SWAP_READY
Ready swap mode.
Definition: flash_driver.h:439
#define CSE_KEY_SIZE_CODE_MAX
Definition: flash_driver.h:467
status_t FLASH_DRV_VerifyBlock(const flash_ssd_config_t *pSSDConfig, uint32_t dest, uint8_t marginLevel)
Flash verify block.
flash_flexRam_function_control_code_t
FlexRAM Function control Code.
Definition: flash_driver.h:479
#define FTFx_FSTAT
Definition: flash_driver.h:204
#define FEATURE_FLS_EE_SIZE_0110
#define FEATURE_FLS_EE_SIZE_1100
#define FTFx_FCCOB0
Definition: flash_driver.h:211
#define FEATURE_FLS_DF_SIZE_1111
#define SIM_FCFG1_DEPART_SHIFT
Definition: S32K144.h:10980
#define FTFx_RSRC_CODE_REG
Definition: flash_driver.h:390
#define FEATURE_FLS_DF_SIZE_0011
#define FEATURE_FLS_DF_SIZE_0000
static START_FUNCTION_DECLARATION_RAMSECTION status_t FLASH_DRV_CommandSequence(const flash_ssd_config_t *pSSDConfig) END_FUNCTION_DECLARATION_RAMSECTION static void FLASH_DRV_GetDEPartitionCode(flash_ssd_config_t *const pSSDConfig
#define GET_BIT_8_15(value)
Definition: flash_driver.h:458
#define DEV_ASSERT(x)
Definition: devassert.h:78
void FLASH_DRV_GetPFlashProtection(uint32_t *protectStatus)
P-Flash get protection.
status_t FLASH_DRV_ProgramCheck(const flash_ssd_config_t *pSSDConfig, uint32_t dest, uint32_t size, const uint8_t *pExpectedData, uint32_t *pFailAddr, uint8_t marginLevel)
Flash program check.
#define ENABLE_CHECK_RAMSECTION_FUNCTION_CALL
Definition: s32_core_cm4.h:166
#define END_FUNCTION_DEFINITION_RAMSECTION
Definition: s32_core_cm4.h:158
#define FTFx_FPROT3
Definition: flash_driver.h:220
#define FTFx_READ_ONCE
Definition: flash_driver.h:408
status_t FLASH_DRV_SetFlexRamFunction(const flash_ssd_config_t *pSSDConfig, flash_flexRam_function_control_code_t flexRamFuncCode, uint16_t byteOfQuickWrite, flash_eeprom_status_t *const pEEPROMStatus)
Set FlexRAM function.
#define FEATURE_FLS_DF_SIZE_0100
#define FEATURE_FLS_DF_SIZE_1101
#define FTFx_SWAP_SET_INDICATOR_ADDR
Initialize Swap System control code.
Definition: flash_driver.h:423
status_t FLASH_DRV_CheckSum(const flash_ssd_config_t *pSSDConfig, uint32_t dest, uint32_t size, uint32_t *pSum)
Calculates check sum.
#define FTFx_FSTAT_FPVIOL_MASK
Definition: flash_driver.h:238
#define FEATURE_FLS_DF_SIZE_0101
#define FEATURE_FLS_FLEX_RAM_SIZE
#define FTFx_PROGRAM_LONGWORD
Definition: flash_driver.h:402
#define GET_BIT_24_31(value)
Definition: flash_driver.h:460
#define START_FUNCTION_DECLARATION_RAMSECTION
Places a function in RAM.
Definition: s32_core_cm4.h:146
status_t FLASH_DRV_SetDFlashProtection(const flash_ssd_config_t *pSSDConfig, uint8_t protectStatus)
D-Flash set protection.
status_t FLASH_DRV_EraseBlock(const flash_ssd_config_t *pSSDConfig, uint32_t dest)
Flash erase block.
#define FTFx_FCCOB1
Definition: flash_driver.h:210
#define FTFx_ERASE_BLOCK
Definition: flash_driver.h:404
#define FEATURE_FLS_DF_BLOCK_SECTOR_SIZE
#define FLASH_SECURITY_STATE_UNSECURED
Definition: flash_driver.h:464
status_t
Status return codes. Common error codes will be a unified enumeration (C enum) that will contain all ...
Definition: status.h:31
status_t FLASH_DRV_ProgramSection(const flash_ssd_config_t *pSSDConfig, uint32_t dest, uint16_t number)
Flash program section.
#define FEATURE_FLS_DF_SIZE_0110
#define FTFx_FSEC_KEYEN_MASK
Definition: flash_driver.h:292
EEPROM status structure.
Definition: flash_driver.h:598
#define FTFx_BASE
Definition: flash_driver.h:203
#define FTFx_FSTAT_CCIF_MASK
Definition: flash_driver.h:250
#define FTFx_FCNFG
Definition: flash_driver.h:205
#define FTFx_FCCOB9
Definition: flash_driver.h:218
#define FTFx_FCCOB3
Definition: flash_driver.h:208
#define START_FUNCTION_DEFINITION_RAMSECTION
Definition: s32_core_cm4.h:157
#define FEATURE_FLS_DF_SIZE_1011
uint16_t numOfRecordReqMaintain
Definition: flash_driver.h:601
status_t FLASH_DRV_SetPFlashProtection(uint32_t protectStatus)
P-Flash set protection.
#define DISABLE_CHECK_RAMSECTION_FUNCTION_CALL
Definition: s32_core_cm4.h:165
#define FTFx_SWAP_UPDATE_ERASED
Update-Erased swap mode.
Definition: flash_driver.h:443
#define FTFx_PROGRAM_PHRASE
Definition: flash_driver.h:403
#define FTFx_READ_RESOURCE
Definition: flash_driver.h:401
status_t FLASH_DRV_VerifySection(const flash_ssd_config_t *pSSDConfig, uint32_t dest, uint16_t number, uint8_t marginLevel)
Flash verify section.
#define FTFx_FPROT2
Definition: flash_driver.h:221
#define FTFx_FSTAT_MGSTAT0_MASK
Definition: flash_driver.h:234
status_t FLASH_DRV_ReadOnce(const flash_ssd_config_t *pSSDConfig, uint8_t recordIndex, uint8_t *pDataArray)
Flash read once.
#define FTFx_FCCOB7
Definition: flash_driver.h:212
#define FTFx_VERIFY_ALL_BLOCK
Definition: flash_driver.h:407
#define FTFx_FCCOB6
Definition: flash_driver.h:213
#define FEATURE_FLS_DF_SIZE_1001
#define FTFx_PROGRAM_SECTION
Definition: flash_driver.h:406
Flash SSD Configuration Structure.
Definition: flash_driver.h:576
#define FTFx_FCNFG_ERSSUSP_MASK
Definition: flash_driver.h:263
#define FEATURE_FLS_DF_SIZE_0001
#define FTFx_PFLASH_SWAP
Definition: flash_driver.h:412
status_t FLASH_DRV_EraseAllBlock(const flash_ssd_config_t *pSSDConfig)
Flash erase all blocks.
#define FEATURE_FLS_EE_SIZE_0001
#define FTFx_ERASE_SECTOR
Definition: flash_driver.h:405
#define SIM_FCFG1_DEPART_MASK
Definition: S32K144.h:10979
#define FEATURE_FLS_DF_SIZE_1000
#define FEATURE_FLS_EE_SIZE_1101
#define FLASH_SECURE_BACKDOOR_ENABLED
Flash is secured and backdoor key access enabled.
Definition: flash_driver.h:495
#define FEATURE_FLS_EE_SIZE_1011
#define FEATURE_FLS_DF_BLOCK_SIZE
#define FTFx_FDPROT
Definition: flash_driver.h:225
#define GET_BIT_16_23(value)
Definition: flash_driver.h:459
#define RESUME_WAIT_CNT
Resume wait count used in FlashResume function.
Definition: flash_driver.h:449
#define FTFx_FCCOB5
Definition: flash_driver.h:214
#define FTFx_FSEC
Definition: flash_driver.h:206
#define FTFx_SWAP_UNINIT
Uninitialized swap mode.
Definition: flash_driver.h:437
status_t FLASH_DRV_EraseAllBlockUnsecure(const flash_ssd_config_t *pSSDConfig)
Flash erase all blocks unsecure.
Flash User Configuration Structure.
Definition: flash_driver.h:552
#define FEATURE_FLS_EE_SIZE_0011
#define FEATURE_FLS_DF_SIZE_1110
status_t FLASH_DRV_SecurityBypass(const flash_ssd_config_t *pSSDConfig, const uint8_t *keyBuffer)
Flash security bypass.
#define FEATURE_FLS_EE_SIZE_0010
#define FEATURE_FLS_DF_SIZE_1010
#define FTFx_PROGRAM_PARTITION
Definition: flash_driver.h:414
status_t FLASH_DRV_ProgramOnce(const flash_ssd_config_t *pSSDConfig, uint8_t recordIndex, const uint8_t *pDataArray)
Flash program once.
#define FEATURE_FLS_DF_SIZE_1100
void FLASH_DRV_GetSecurityState(uint8_t *securityState)
Flash get security state.
#define FEATURE_FLS_EE_SIZE_0101