added NVMC to SplitFlap project

main
Jonas Arnold 4 years ago
parent 72d9f5cd7b
commit 361fbeb73c
  1. 22
      ADIS_tinyK22_SplitFlap/.cproject
  2. 41
      ADIS_tinyK22_SplitFlap/drivers/fsl_flash.h
  3. 396
      ADIS_tinyK22_SplitFlap/drivers/fsl_ftfx_adapter.h
  4. 549
      ADIS_tinyK22_SplitFlap/drivers/fsl_ftfx_cache.c
  5. 113
      ADIS_tinyK22_SplitFlap/drivers/fsl_ftfx_cache.h
  6. 1510
      ADIS_tinyK22_SplitFlap/drivers/fsl_ftfx_controller.c
  7. 846
      ADIS_tinyK22_SplitFlap/drivers/fsl_ftfx_controller.h
  8. 90
      ADIS_tinyK22_SplitFlap/drivers/fsl_ftfx_features.h
  9. 1544
      ADIS_tinyK22_SplitFlap/drivers/fsl_ftfx_flash.c
  10. 705
      ADIS_tinyK22_SplitFlap/drivers/fsl_ftfx_flash.h
  11. 511
      ADIS_tinyK22_SplitFlap/drivers/fsl_ftfx_flexnvm.c
  12. 564
      ADIS_tinyK22_SplitFlap/drivers/fsl_ftfx_flexnvm.h
  13. 70
      ADIS_tinyK22_SplitFlap/drivers/fsl_ftfx_utilities.h
  14. 10
      ADIS_tinyK22_SplitFlap/source/IncludeMcuLibConfig.h
  15. 238
      ADIS_tinyK22_SplitFlap/source/nvmc.c
  16. 106
      ADIS_tinyK22_SplitFlap/source/nvmc.h
  17. 26
      ADIS_tinyK22_SplitFlap/source/platform.c
  18. 2
      ADIS_tinyK22_SplitFlap/source/platform.h
  19. 7
      ADIS_tinyK22_SplitFlap/source/shell.c

@ -116,6 +116,14 @@
<option id="gnu.c.compiler.option.preprocessor.preprocess.1553097693" name="Preprocess only (-E)" superClass="gnu.c.compiler.option.preprocessor.preprocess" useByScannerDiscovery="false"/> <option id="gnu.c.compiler.option.preprocessor.preprocess.1553097693" name="Preprocess only (-E)" superClass="gnu.c.compiler.option.preprocessor.preprocess" useByScannerDiscovery="false"/>
<option id="gnu.c.compiler.option.preprocessor.undef.symbol.1056528635" name="Undefined symbols (-U)" superClass="gnu.c.compiler.option.preprocessor.undef.symbol" useByScannerDiscovery="false"/> <option id="gnu.c.compiler.option.preprocessor.undef.symbol.1056528635" name="Undefined symbols (-U)" superClass="gnu.c.compiler.option.preprocessor.undef.symbol" useByScannerDiscovery="false"/>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="gnu.c.compiler.option.include.paths.389847322" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath"> <option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="gnu.c.compiler.option.include.paths.389847322" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath">
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/drivers}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/device}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/CMSIS}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/component/serial_manager}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/utilities}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/component/uart}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/component/lists}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/board}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/drivers}&quot;"/> <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/drivers}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/device}&quot;"/> <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/device}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/CMSIS}&quot;"/> <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/CMSIS}&quot;"/>
@ -362,7 +370,7 @@
</folderInfo> </folderInfo>
<sourceEntries> <sourceEntries>
<entry flags="LOCAL|VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="CMSIS"/> <entry flags="LOCAL|VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="CMSIS"/>
<entry excluding="FreeRTOS/Source/portable/GCC/RISC-V|FreeRTOS/Source/portable/GCC/ARM_CM33|TraceRecorder|SEGGER_Sysview|minIni|LittlevGL|littleFS|HD44780|fonts|FatFS" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="McuLib"/> <entry excluding="FreeRTOS/Source/portable/GCC/RISC-V|FreeRTOS/Source/portable/GCC/ARM_CM33|TraceRecorder|SEGGER_Sysview|LittlevGL|littleFS|HD44780|fonts|FatFS" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="McuLib"/>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="board"/> <entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="board"/>
<entry flags="LOCAL|VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="component"/> <entry flags="LOCAL|VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="component"/>
<entry flags="LOCAL|VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="device"/> <entry flags="LOCAL|VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="device"/>
@ -483,6 +491,14 @@
</option> </option>
<option id="gnu.c.compiler.option.preprocessor.undef.symbol.1092760296" name="Undefined symbols (-U)" superClass="gnu.c.compiler.option.preprocessor.undef.symbol" useByScannerDiscovery="false"/> <option id="gnu.c.compiler.option.preprocessor.undef.symbol.1092760296" name="Undefined symbols (-U)" superClass="gnu.c.compiler.option.preprocessor.undef.symbol" useByScannerDiscovery="false"/>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="gnu.c.compiler.option.include.paths.2049780101" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath"> <option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="gnu.c.compiler.option.include.paths.2049780101" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath">
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/drivers}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/device}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/CMSIS}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/component/serial_manager}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/utilities}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/component/uart}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/component/lists}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/board}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/drivers}&quot;"/> <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/drivers}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/device}&quot;"/> <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/device}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/CMSIS}&quot;"/> <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/CMSIS}&quot;"/>
@ -729,7 +745,7 @@
</folderInfo> </folderInfo>
<sourceEntries> <sourceEntries>
<entry flags="LOCAL|VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="CMSIS"/> <entry flags="LOCAL|VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="CMSIS"/>
<entry excluding="FreeRTOS/Source/portable/GCC/RISC-V|FreeRTOS/Source/portable/GCC/ARM_CM33|TraceRecorder|SEGGER_Sysview|minIni|LittlevGL|littleFS|HD44780|fonts|FatFS" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="McuLib"/> <entry excluding="FreeRTOS/Source/portable/GCC/RISC-V|FreeRTOS/Source/portable/GCC/ARM_CM33|TraceRecorder|SEGGER_Sysview|LittlevGL|littleFS|HD44780|fonts|FatFS" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="McuLib"/>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="board"/> <entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="board"/>
<entry flags="LOCAL|VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="component"/> <entry flags="LOCAL|VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="component"/>
<entry flags="LOCAL|VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="device"/> <entry flags="LOCAL|VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="device"/>
@ -765,7 +781,7 @@
<storageModule moduleId="com.nxp.mcuxpresso.core.datamodels"> <storageModule moduleId="com.nxp.mcuxpresso.core.datamodels">
<sdkName>SDK_2.x_MK22FN512xxx12</sdkName> <sdkName>SDK_2.x_MK22FN512xxx12</sdkName>
<sdkVersion>2.12.0</sdkVersion> <sdkVersion>2.12.0</sdkVersion>
<sdkComponents>middleware.baremetal.MK22F51212;platform.drivers.smc.MK22F51212;platform.drivers.port.MK22F51212;platform.drivers.dspi.MK22F51212;platform.drivers.adc16.MK22F51212;platform.drivers.uart.MK22F51212;platform.drivers.clock.MK22F51212;platform.drivers.rtc.MK22F51212;platform.drivers.common.MK22F51212;platform.drivers.i2c.MK22F51212;platform.drivers.gpio.MK22F51212;device.MK22F51212_system.MK22F51212;device.MK22F51212_CMSIS.MK22F51212;CMSIS_Include_core_cm.MK22F51212;platform.utilities.assert.MK22F51212;component.serial_manager_uart.MK22F51212;utility.debug_console.MK22F51212;component.serial_manager.MK22F51212;component.uart_adapter.MK22F51212;component.lists.MK22F51212;project_template.MK22F51212.MK22F51212;device.MK22F51212_startup.MK22F51212;platform.drivers.sim.MK22F51212;</sdkComponents> <sdkComponents>middleware.baremetal.MK22F51212;platform.drivers.smc.MK22F51212;platform.drivers.port.MK22F51212;platform.drivers.dspi.MK22F51212;platform.drivers.adc16.MK22F51212;platform.drivers.uart.MK22F51212;platform.drivers.clock.MK22F51212;platform.drivers.rtc.MK22F51212;platform.drivers.common.MK22F51212;platform.drivers.i2c.MK22F51212;platform.drivers.gpio.MK22F51212;device.MK22F51212_system.MK22F51212;device.MK22F51212_CMSIS.MK22F51212;CMSIS_Include_core_cm.MK22F51212;platform.utilities.assert.MK22F51212;component.serial_manager_uart.MK22F51212;utility.debug_console.MK22F51212;component.serial_manager.MK22F51212;component.uart_adapter.MK22F51212;component.lists.MK22F51212;project_template.MK22F51212.MK22F51212;device.MK22F51212_startup.MK22F51212;platform.drivers.sim.MK22F51212;platform.drivers.flash.MK22F51212;</sdkComponents>
<package>MK22FN512VLH12</package> <package>MK22FN512VLH12</package>
<core>cm4</core> <core>cm4</core>
<coreId>core0_MK22FN512xxx12</coreId> <coreId>core0_MK22FN512xxx12</coreId>

@ -0,0 +1,41 @@
/*
* Copyright 2013-2016 Freescale Semiconductor, Inc.
* Copyright 2016-2020 NXP
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
*/
#ifndef FSL_FLASH_H
#define FSL_FLASH_H
#include "fsl_ftfx_cache.h"
#include "fsl_ftfx_flash.h"
#if FSL_FEATURE_FLASH_HAS_FLEX_NVM
#include "fsl_ftfx_flexnvm.h"
#endif
/*!
* @addtogroup flash_driver
* @{
*/
/*******************************************************************************
* Definitions
******************************************************************************/
/*******************************************************************************
* API
******************************************************************************/
#if defined(__cplusplus)
extern "C" {
#endif
#if defined(__cplusplus)
}
#endif
/*! @}*/
#endif /* FSL_FLASH_H */

@ -0,0 +1,396 @@
/*
* Copyright 2017-2020 NXP
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
*/
#ifndef FSL_FTFX_ADAPTER_H
#define FSL_FTFX_ADAPTER_H
/*******************************************************************************
* Definitions
******************************************************************************/
#define INVALID_REG_MASK (0)
#define INVALID_REG_SHIFT (0)
#define INVALID_REG_ADDRESS (NULL)
#define INVALID_REG_VALUE (0x00U)
/* @brief Flash register access type defines */
#define FTFx_REG8_ACCESS_TYPE volatile uint8_t *
#define FTFx_REG32_ACCESS_TYPE volatile uint32_t *
/*!
* @name Common flash register info defines
* @{
*/
#if defined(FTFA)
#define FTFx FTFA
#define FTFx_BASE FTFA_BASE
#define FTFx_FSTAT_CCIF_MASK FTFA_FSTAT_CCIF_MASK
#define FTFx_FSTAT_CCIF_SHIFT FTFA_FSTAT_CCIF_SHIFT
#define FTFx_FSTAT_RDCOLERR_MASK FTFA_FSTAT_RDCOLERR_MASK
#define FTFx_FSTAT_ACCERR_MASK FTFA_FSTAT_ACCERR_MASK
#define FTFx_FSTAT_FPVIOL_MASK FTFA_FSTAT_FPVIOL_MASK
#define FTFx_FSTAT_MGSTAT0_MASK FTFA_FSTAT_MGSTAT0_MASK
#define FTFx_FSEC_SEC_MASK FTFA_FSEC_SEC_MASK
#define FTFx_FSEC_KEYEN_MASK FTFA_FSEC_KEYEN_MASK
#if defined(FSL_FEATURE_FLASH_HAS_FLEX_RAM) && FSL_FEATURE_FLASH_HAS_FLEX_RAM
#define FTFx_FCNFG_RAMRDY_MASK FTFA_FCNFG_RAMRDY_MASK
#endif /* FSL_FEATURE_FLASH_HAS_FLEX_RAM */
#if defined(FSL_FEATURE_FLASH_HAS_FLEX_NVM) && FSL_FEATURE_FLASH_HAS_FLEX_NVM
#define FTFx_FCNFG_EEERDY_MASK FTFA_FCNFG_EEERDY_MASK
#endif /* FSL_FEATURE_FLASH_HAS_FLEX_NVM */
#elif defined(FTFE)
#define FTFx FTFE
#define FTFx_BASE FTFE_BASE
#define FTFx_FSTAT_CCIF_MASK FTFE_FSTAT_CCIF_MASK
#define FTFx_FSTAT_CCIF_SHIFT FTFE_FSTAT_CCIF_SHIFT
#define FTFx_FSTAT_RDCOLERR_MASK FTFE_FSTAT_RDCOLERR_MASK
#define FTFx_FSTAT_ACCERR_MASK FTFE_FSTAT_ACCERR_MASK
#define FTFx_FSTAT_FPVIOL_MASK FTFE_FSTAT_FPVIOL_MASK
#define FTFx_FSTAT_MGSTAT0_MASK FTFE_FSTAT_MGSTAT0_MASK
#define FTFx_FSEC_SEC_MASK FTFE_FSEC_SEC_MASK
#define FTFx_FSEC_KEYEN_MASK FTFE_FSEC_KEYEN_MASK
#if defined(FSL_FEATURE_FLASH_HAS_FLEX_RAM) && FSL_FEATURE_FLASH_HAS_FLEX_RAM
#define FTFx_FCNFG_RAMRDY_MASK FTFE_FCNFG_RAMRDY_MASK
#endif /* FSL_FEATURE_FLASH_HAS_FLEX_RAM */
#if defined(FSL_FEATURE_FLASH_HAS_FLEX_NVM) && FSL_FEATURE_FLASH_HAS_FLEX_NVM
#define FTFx_FCNFG_EEERDY_MASK FTFE_FCNFG_EEERDY_MASK
#endif /* FSL_FEATURE_FLASH_HAS_FLEX_NVM */
#elif defined(FTFL)
#define FTFx FTFL
#define FTFx_BASE FTFL_BASE
#define FTFx_FSTAT_CCIF_MASK FTFL_FSTAT_CCIF_MASK
#define FTFx_FSTAT_CCIF_SHIFT FTFL_FSTAT_CCIF_SHIFT
#define FTFx_FSTAT_RDCOLERR_MASK FTFL_FSTAT_RDCOLERR_MASK
#define FTFx_FSTAT_ACCERR_MASK FTFL_FSTAT_ACCERR_MASK
#define FTFx_FSTAT_FPVIOL_MASK FTFL_FSTAT_FPVIOL_MASK
#define FTFx_FSTAT_MGSTAT0_MASK FTFL_FSTAT_MGSTAT0_MASK
#define FTFx_FSEC_SEC_MASK FTFL_FSEC_SEC_MASK
#define FTFx_FSEC_KEYEN_MASK FTFL_FSEC_KEYEN_MASK
#if defined(FSL_FEATURE_FLASH_HAS_FLEX_RAM) && FSL_FEATURE_FLASH_HAS_FLEX_RAM
#define FTFx_FCNFG_RAMRDY_MASK FTFL_FCNFG_RAMRDY_MASK
#endif /* FSL_FEATURE_FLASH_HAS_FLEX_RAM */
#if defined(FSL_FEATURE_FLASH_HAS_FLEX_NVM) && FSL_FEATURE_FLASH_HAS_FLEX_NVM
#define FTFx_FCNFG_EEERDY_MASK FTFL_FCNFG_EEERDY_MASK
#endif /* FSL_FEATURE_FLASH_HAS_FLEX_NVM */
#else
#error "Unknown flash controller"
#endif
/*@}*/
/*!
* @name Common flash register access info defines
* @{
*/
#define FTFx_FCCOB3_REG (FTFx->FCCOB3)
#define FTFx_FCCOB5_REG (FTFx->FCCOB5)
#define FTFx_FCCOB6_REG (FTFx->FCCOB6)
#define FTFx_FCCOB7_REG (FTFx->FCCOB7)
#if defined(FSL_FEATURE_FLASH_HAS_MULTIPLE_FLASH) || defined(FSL_FEATURE_FLASH_PFLASH_1_START_ADDRESS)
#if defined(FTFA_FPROTSL_PROTS_MASK) || defined(FTFE_FPROTSL_PROTS_MASK) || defined(FTFL_FPROTSL_PROTS_MASK)
#define FTFx_FLASH1_HAS_INT_PROT_REG (1)
#define FTFx_FPROTSH_REG (FTFx->FPROTSH)
#define FTFx_FPROTSL_REG (FTFx->FPROTSL)
#else
#define FTFx_FLASH1_HAS_INT_PROT_REG (0)
#endif
#endif
#if defined(FTFA_FPROTH0_PROT_MASK) || defined(FTFE_FPROTH0_PROT_MASK) || defined(FTFL_FPROTH0_PROT_MASK)
#define FTFx_FLASH0_HAS_HIGH_PROT_REG (1)
#define FTFx_FPROT_HIGH_REG (FTFx->FPROTH3)
#define FTFx_FPROTH3_REG (FTFx->FPROTH3)
#define FTFx_FPROTH2_REG (FTFx->FPROTH2)
#define FTFx_FPROTH1_REG (FTFx->FPROTH1)
#define FTFx_FPROTH0_REG (FTFx->FPROTH0)
#else
#define FTFx_FLASH0_HAS_HIGH_PROT_REG (0)
#endif
#if defined(FTFA_FPROTL0_PROT_MASK) || defined(FTFE_FPROTL0_PROT_MASK) || defined(FTFL_FPROTL0_PROT_MASK)
#define FTFx_FPROT_LOW_REG (FTFx->FPROTL3)
#define FTFx_FPROTL3_REG (FTFx->FPROTL3)
#define FTFx_FPROTL2_REG (FTFx->FPROTL2)
#define FTFx_FPROTL1_REG (FTFx->FPROTL1)
#define FTFx_FPROTL0_REG (FTFx->FPROTL0)
#elif defined(FTFA_FPROT0_PROT_MASK) || defined(FTFE_FPROT0_PROT_MASK) || defined(FTFL_FPROT0_PROT_MASK)
#define FTFx_FPROT_LOW_REG (FTFx->FPROT3)
#define FTFx_FPROTL3_REG (FTFx->FPROT3)
#define FTFx_FPROTL2_REG (FTFx->FPROT2)
#define FTFx_FPROTL1_REG (FTFx->FPROT1)
#define FTFx_FPROTL0_REG (FTFx->FPROT0)
#endif
#if defined(FSL_FEATURE_FLASH_HAS_MULTIPLE_FLASH) || defined(FSL_FEATURE_FLASH_PFLASH_1_START_ADDRESS)
#if defined(FTFA_FACSSS_SGSIZE_S_MASK) || defined(FTFE_FACSSS_SGSIZE_S_MASK) || defined(FTFL_FACSSS_SGSIZE_S_MASK)
#define FTFx_FLASH1_HAS_INT_XACC_REG (1)
#define FTFx_XACCSH_REG (FTFx->XACCSH)
#define FTFx_XACCSL_REG (FTFx->XACCSL)
#define FTFx_FACSSS_REG (FTFx->FACSSS)
#define FTFx_FACSNS_REG (FTFx->FACSNS)
#else
#define FTFx_FLASH1_HAS_INT_XACC_REG (0)
#endif
#endif
#if (defined(FTFA_FACSS_SGSIZE_MASK) || defined(FTFE_FACSS_SGSIZE_MASK) || defined(FTFL_FACSS_SGSIZE_MASK) || \
defined(FTFA_FACSS_SGSIZE_S_MASK) || defined(FTFE_FACSS_SGSIZE_S_MASK) || defined(FTFL_FACSS_SGSIZE_S_MASK))
#define FTFx_FLASH0_HAS_INT_XACC_REG (1)
#define FTFx_XACCH3_REG (FTFx->XACCH3)
#define FTFx_XACCL3_REG (FTFx->XACCL3)
#define FTFx_FACSS_REG (FTFx->FACSS)
#define FTFx_FACSN_REG (FTFx->FACSN)
#else
#define FTFx_FLASH0_HAS_INT_XACC_REG (0)
#endif
/*@}*/
/*!
* @brief MCM cache register access info defines.
*/
#if defined(MCM_PLACR_CFCC_MASK)
#define MCM_CACHE_CLEAR_MASK MCM_PLACR_CFCC_MASK
#define MCM_CACHE_CLEAR_SHIFT MCM_PLACR_CFCC_SHIFT
#if defined(MCM0)
#define MCM0_CACHE_REG MCM0->PLACR
#elif defined(MCM) && (!defined(MCM1))
#define MCM0_CACHE_REG MCM->PLACR
#endif
#if defined(MCM1)
#define MCM1_CACHE_REG MCM1->PLACR
#elif defined(MCM) && (!defined(MCM0))
#define MCM1_CACHE_REG MCM->PLACR
#endif
#else
#define MCM_CACHE_CLEAR_MASK INVALID_REG_MASK
#define MCM_CACHE_CLEAR_SHIFT INVALID_REG_SHIFT
#define MCM0_CACHE_REG (INVALID_REG_ADDRESS)
#define MCM1_CACHE_REG (INVALID_REG_ADDRESS)
#endif
/*!
* @brief FMC cache register access info defines.
*/
#if defined(FMC_PFB01CR_S_INV_MASK)
#define FMC_SPECULATION_INVALIDATE_MASK FMC_PFB01CR_S_INV_MASK
#define FMC_SPECULATION_INVALIDATE_SHIFT FMC_PFB01CR_S_INV_SHIFT
#define FMC_SPECULATION_INVALIDATE_REG FMC->PFB01CR
#elif defined(FMC_PFB01CR_S_B_INV_MASK)
#define FMC_SPECULATION_INVALIDATE_MASK FMC_PFB01CR_S_B_INV_MASK
#define FMC_SPECULATION_INVALIDATE_SHIFT FMC_PFB01CR_S_B_INV_SHIFT
#define FMC_SPECULATION_INVALIDATE_REG FMC->PFB01CR
#elif defined(FMC_PFB0CR_S_INV_MASK)
#define FMC_SPECULATION_INVALIDATE_MASK FMC_PFB0CR_S_INV_MASK
#define FMC_SPECULATION_INVALIDATE_SHIFT FMC_PFB0CR_S_INV_SHIFT
#define FMC_SPECULATION_INVALIDATE_REG FMC->PFB0CR
#elif defined(FMC_PFB0CR_S_B_INV_MASK)
#define FMC_SPECULATION_INVALIDATE_MASK FMC_PFB0CR_S_B_INV_MASK
#define FMC_SPECULATION_INVALIDATE_SHIFT FMC_PFB0CR_S_B_INV_SHIFT
#define FMC_SPECULATION_INVALIDATE_REG FMC->PFB0CR
#else
#define FMC_SPECULATION_INVALIDATE_MASK INVALID_REG_MASK
#define FMC_SPECULATION_INVALIDATE_SHIFT INVALID_REG_SHIFT
#define FMC_SPECULATION_INVALIDATE(x) (((uint32_t)(((uint32_t)(x)) << INVALID_REG_SHIFT)) & INVALID_REG_MASK)
#define FMC_SPECULATION_INVALIDATE_REG (INVALID_REG_ADDRESS)
#endif
#if defined(FMC_PFB01CR_CINV_WAY_MASK)
#define FMC_CACHE_CLEAR_MASK FMC_PFB01CR_CINV_WAY_MASK
#define FMC_CACHE_CLEAR_SHIFT FMC_PFB01CR_CINV_WAY_SHIFT
#define FMC_CACHE_CLEAR(x) FMC_PFB01CR_CINV_WAY(x)
#elif defined(FMC_PFB0CR_CINV_WAY_MASK)
#define FMC_CACHE_CLEAR_MASK FMC_PFB0CR_CINV_WAY_MASK
#define FMC_CACHE_CLEAR_SHIFT FMC_PFB0CR_CINV_WAY_SHIFT
#define FMC_CACHE_CLEAR(x) FMC_PFB0CR_CINV_WAY(x)
#else
#define FMC_CACHE_CLEAR_MASK INVALID_REG_MASK
#define FMC_CACHE_CLEAR_SHIFT INVALID_REG_SHIFT
#define FMC_CACHE_CLEAR(x) (((uint32_t)(((uint32_t)(x)) << INVALID_REG_SHIFT)) & INVALID_REG_MASK)
#endif
#if defined(FMC_PFB01CR_B0DPE_MASK)
#define FMC_CACHE_B0DPE_MASK FMC_PFB01CR_B0DPE_MASK
#define FMC_CACHE_B0IPE_MASK FMC_PFB01CR_B0IPE_MASK
#define FMC_CACHE_REG FMC->PFB01CR
#elif defined(FMC_PFB0CR_B0DPE_MASK)
#define FMC_CACHE_B0DPE_MASK FMC_PFB0CR_B0DPE_MASK
#define FMC_CACHE_B0IPE_MASK FMC_PFB0CR_B0IPE_MASK
#define FMC_CACHE_REG FMC->PFB0CR
#else
#define FMC_CACHE_B0DPE_MASK INVALID_REG_MASK
#define FMC_CACHE_B0IPE_MASK INVALID_REG_MASK
#define FMC_CACHE_REG (INVALID_REG_ADDRESS)
#endif
/*!
* @brief MSCM cache register access info defines.
*/
#if defined(MSCM_OCMDR_OCM1_MASK)
#define MSCM_SPECULATION_SET_MASK MSCM_OCMDR_OCM1_MASK
#define MSCM_SPECULATION_SET_SHIFT MSCM_OCMDR_OCM1_SHIFT
#define MSCM_SPECULATION_SET(x) MSCM_OCMDR_OCM1(x)
#elif defined(MSCM_OCMDR0_OCM1_MASK) || defined(MSCM_OCMDR1_OCM1_MASK)
#define MSCM_SPECULATION_SET_MASK MSCM_OCMDR0_OCM1_MASK
#define MSCM_SPECULATION_SET_SHIFT MSCM_OCMDR0_OCM1_SHIFT
#define MSCM_SPECULATION_SET(x) MSCM_OCMDR0_OCM1(x)
#elif defined(MSCM_OCMDR_OCMC1_MASK)
#define MSCM_SPECULATION_SET_MASK MSCM_OCMDR_OCMC1_MASK
#define MSCM_SPECULATION_SET_SHIFT MSCM_OCMDR_OCMC1_SHIFT
#define MSCM_SPECULATION_SET(x) MSCM_OCMDR_OCMC1(x)
#else
#define MSCM_SPECULATION_SET_MASK INVALID_REG_MASK
#define MSCM_SPECULATION_SET_SHIFT INVALID_REG_SHIFT
#define MSCM_SPECULATION_SET(x) (((uint32_t)(((uint32_t)(x)) << INVALID_REG_SHIFT)) & INVALID_REG_MASK)
#endif
#if defined(MSCM_OCMDR_OCM2_MASK)
#define MSCM_CACHE_CLEAR_MASK MSCM_OCMDR_OCM2_MASK
#define MSCM_CACHE_CLEAR_SHIFT MSCM_OCMDR_OCM2_SHIFT
#define MSCM_CACHE_CLEAR(x) MSCM_OCMDR_OCM2(x)
#else
#define MSCM_CACHE_CLEAR_MASK INVALID_REG_MASK
#define MSCM_CACHE_CLEAR_SHIFT INVALID_REG_SHIFT
#define MSCM_CACHE_CLEAR(x) (((uint32_t)(((uint32_t)(x)) << INVALID_REG_SHIFT)) & INVALID_REG_MASK)
#endif
#if defined(MSCM_OCMDR_OCM1_MASK) || defined(MSCM_OCMDR_OCMC1_MASK)
#define MSCM_OCMDR0_REG MSCM->OCMDR[0]
#define MSCM_OCMDR1_REG MSCM->OCMDR[1]
#elif defined(MSCM_OCMDR0_OCM1_MASK) || defined(MSCM_OCMDR1_OCM1_MASK)
#define MSCM_OCMDR0_REG MSCM->OCMDR0
#define MSCM_OCMDR1_REG MSCM->OCMDR1
#else
#define MSCM_OCMDR0_REG (INVALID_REG_ADDRESS)
#define MSCM_OCMDR1_REG (INVALID_REG_ADDRESS)
#endif
/*!
* @brief MSCM prefetch speculation defines.
*/
#define MSCM_OCMDR_OCMC1_DFDS_MASK (0x10U)
#define MSCM_OCMDR_OCMC1_DFCS_MASK (0x20U)
#define MSCM_OCMDR_OCMC1_DFDS_SHIFT (4U)
#define MSCM_OCMDR_OCMC1_DFCS_SHIFT (5U)
/*!
* @brief SIM PFSIZE register access info defines.
*/
#if defined(SIM_FCFG1_CORE0_PFSIZE_MASK)
#define SIM_FLASH0_PFSIZE_MASK SIM_FCFG1_CORE0_PFSIZE_MASK
#define SIM_FLASH0_PFSIZE_SHIFT SIM_FCFG1_CORE0_PFSIZE_SHIFT
#define SIM_FCFG1_REG SIM->FCFG1
#elif defined(SIM_FCFG1_PFSIZE_MASK)
#define SIM_FLASH0_PFSIZE_MASK SIM_FCFG1_PFSIZE_MASK
#define SIM_FLASH0_PFSIZE_SHIFT SIM_FCFG1_PFSIZE_SHIFT
#define SIM_FCFG1_REG SIM->FCFG1
#else
#define SIM_FLASH0_PFSIZE_MASK INVALID_REG_MASK
#define SIM_FLASH0_PFSIZE_SHIFT INVALID_REG_SHIFT
#define SIM_FCFG1_REG INVALID_REG_VALUE
#endif
#if defined(SIM_FCFG1_CORE1_PFSIZE_MASK)
#define SIM_FLASH1_PFSIZE_MASK SIM_FCFG1_CORE1_PFSIZE_MASK
#define SIM_FLASH1_PFSIZE_SHIFT SIM_FCFG1_CORE1_PFSIZE_SHIFT
#else
#define SIM_FLASH1_PFSIZE_MASK INVALID_REG_MASK
#define SIM_FLASH1_PFSIZE_SHIFT INVALID_REG_SHIFT
#endif
/*!
* @name Dual core/flash configuration
* @{
*/
/*! @brief Redefines some flash features. */
#if defined(FSL_FEATURE_FLASH_CURRENT_CORE_ID)
#if (FSL_FEATURE_FLASH_CURRENT_CORE_ID == 0u)
#define FLASH0_FEATURE_PFLASH_START_ADDRESS FSL_FEATURE_FLASH_PFLASH_START_ADDRESS
#define FLASH0_FEATURE_PFLASH_BLOCK_COUNT FSL_FEATURE_FLASH_PFLASH_BLOCK_COUNT
#define FLASH0_FEATURE_PFLASH_BLOCK_SIZE FSL_FEATURE_FLASH_PFLASH_BLOCK_SIZE
#define FLASH0_FEATURE_PFLASH_BLOCK_SECTOR_SIZE FSL_FEATURE_FLASH_PFLASH_BLOCK_SECTOR_SIZE
#define FLASH0_FEATURE_PFLASH_BLOCK_WRITE_UNIT_SIZE FSL_FEATURE_FLASH_PFLASH_BLOCK_WRITE_UNIT_SIZE
#define FLASH0_FEATURE_PFLASH_SECTOR_CMD_ADDRESS_ALIGMENT FSL_FEATURE_FLASH_PFLASH_SECTOR_CMD_ADDRESS_ALIGMENT
#define FLASH0_FEATURE_PFLASH_SECTION_CMD_ADDRESS_ALIGMENT FSL_FEATURE_FLASH_PFLASH_SECTION_CMD_ADDRESS_ALIGMENT
#define FLASH0_FEATURE_PFLASH_PROTECTION_REGION_COUNT FSL_FEATURE_FLASH_PFLASH_PROTECTION_REGION_COUNT
#define FLASH1_FEATURE_PFLASH_START_ADDRESS FSL_FEATURE_FLASH_PFLASH_1_START_ADDRESS
#define FLASH1_FEATURE_PFLASH_BLOCK_COUNT FSL_FEATURE_FLASH_PFLASH_1_BLOCK_COUNT
#define FLASH1_FEATURE_PFLASH_BLOCK_SIZE FSL_FEATURE_FLASH_PFLASH_1_BLOCK_SIZE
#define FLASH1_FEATURE_PFLASH_BLOCK_SECTOR_SIZE FSL_FEATURE_FLASH_PFLASH_1_BLOCK_SECTOR_SIZE
#define FLASH1_FEATURE_PFLASH_BLOCK_WRITE_UNIT_SIZE FSL_FEATURE_FLASH_PFLASH_1_BLOCK_WRITE_UNIT_SIZE
#if defined(FSL_FEATURE_FLASH_PFLASH_1_SECTOR_CMD_ADDRESS_ALIGMENT) && \
defined(FSL_FEATURE_FLASH_PFLASH_1_SECTION_CMD_ADDRESS_ALIGMENT)
#define FLASH1_FEATURE_PFLASH_SECTOR_CMD_ADDRESS_ALIGMENT FSL_FEATURE_FLASH_PFLASH_1_SECTOR_CMD_ADDRESS_ALIGMENT
#define FLASH1_FEATURE_PFLASH_SECTION_CMD_ADDRESS_ALIGMENT FSL_FEATURE_FLASH_PFLASH_1_SECTION_CMD_ADDRESS_ALIGMENT
#else
#define FLASH1_FEATURE_PFLASH_SECTOR_CMD_ADDRESS_ALIGMENT FSL_FEATURE_FLASH_PFLASH_SECTOR_CMD_ADDRESS_ALIGMENT
#define FLASH1_FEATURE_PFLASH_SECTION_CMD_ADDRESS_ALIGMENT FSL_FEATURE_FLASH_PFLASH_SECTION_CMD_ADDRESS_ALIGMENT
#endif
#define FLASH1_FEATURE_PFLASH_PROTECTION_REGION_COUNT FSL_FEATURE_FLASH_PFLASH_1_PROTECTION_REGION_COUNT
#elif (FSL_FEATURE_FLASH_CURRENT_CORE_ID == 1u)
#define FLASH0_FEATURE_PFLASH_START_ADDRESS FSL_FEATURE_FLASH_PFLASH_1_START_ADDRESS
#define FLASH0_FEATURE_PFLASH_BLOCK_COUNT FSL_FEATURE_FLASH_PFLASH_1_BLOCK_COUNT
#define FLASH0_FEATURE_PFLASH_BLOCK_SIZE FSL_FEATURE_FLASH_PFLASH_1_BLOCK_SIZE
#define FLASH0_FEATURE_PFLASH_BLOCK_SECTOR_SIZE FSL_FEATURE_FLASH_PFLASH_1_BLOCK_SECTOR_SIZE
#define FLASH0_FEATURE_PFLASH_BLOCK_WRITE_UNIT_SIZE FSL_FEATURE_FLASH_PFLASH_1_BLOCK_WRITE_UNIT_SIZE
#if defined(FSL_FEATURE_FLASH_PFLASH_1_SECTOR_CMD_ADDRESS_ALIGMENT) && \
defined(FSL_FEATURE_FLASH_PFLASH_1_SECTION_CMD_ADDRESS_ALIGMENT)
#define FLASH0_FEATURE_PFLASH_SECTOR_CMD_ADDRESS_ALIGMENT FSL_FEATURE_FLASH_PFLASH_1_SECTOR_CMD_ADDRESS_ALIGMENT
#define FLASH0_FEATURE_PFLASH_SECTION_CMD_ADDRESS_ALIGMENT FSL_FEATURE_FLASH_PFLASH_1_SECTION_CMD_ADDRESS_ALIGMENT
#else
#define FLASH0_FEATURE_PFLASH_SECTOR_CMD_ADDRESS_ALIGMENT FSL_FEATURE_FLASH_PFLASH_SECTOR_CMD_ADDRESS_ALIGMENT
#define FLASH0_FEATURE_PFLASH_SECTION_CMD_ADDRESS_ALIGMENT FSL_FEATURE_FLASH_PFLASH_SECTION_CMD_ADDRESS_ALIGMENT
#endif
#define FLASH0_FEATURE_PFLASH_PROTECTION_REGION_COUNT FSL_FEATURE_FLASH_PFLASH_1_PROTECTION_REGION_COUNT
#define FLASH1_FEATURE_PFLASH_START_ADDRESS FSL_FEATURE_FLASH_PFLASH_START_ADDRESS
#define FLASH1_FEATURE_PFLASH_BLOCK_COUNT FSL_FEATURE_FLASH_PFLASH_BLOCK_COUNT
#define FLASH1_FEATURE_PFLASH_BLOCK_SIZE FSL_FEATURE_FLASH_PFLASH_BLOCK_SIZE
#define FLASH1_FEATURE_PFLASH_BLOCK_SECTOR_SIZE FSL_FEATURE_FLASH_PFLASH_BLOCK_SECTOR_SIZE
#define FLASH1_FEATURE_PFLASH_BLOCK_WRITE_UNIT_SIZE FSL_FEATURE_FLASH_PFLASH_BLOCK_WRITE_UNIT_SIZE
#define FLASH1_FEATURE_PFLASH_SECTOR_CMD_ADDRESS_ALIGMENT FSL_FEATURE_FLASH_PFLASH_SECTOR_CMD_ADDRESS_ALIGMENT
#define FLASH1_FEATURE_PFLASH_SECTION_CMD_ADDRESS_ALIGMENT FSL_FEATURE_FLASH_PFLASH_SECTION_CMD_ADDRESS_ALIGMENT
#define FLASH1_FEATURE_PFLASH_PROTECTION_REGION_COUNT FSL_FEATURE_FLASH_PFLASH_PROTECTION_REGION_COUNT
#endif
#else /* undfine FSL_FEATURE_FLASH_CURRENT_CORE_ID */
#define FLASH0_FEATURE_PFLASH_START_ADDRESS FSL_FEATURE_FLASH_PFLASH_START_ADDRESS
#define FLASH0_FEATURE_PFLASH_BLOCK_COUNT FSL_FEATURE_FLASH_PFLASH_BLOCK_COUNT
#define FLASH0_FEATURE_PFLASH_BLOCK_SIZE FSL_FEATURE_FLASH_PFLASH_BLOCK_SIZE
#define FLASH0_FEATURE_PFLASH_BLOCK_SECTOR_SIZE FSL_FEATURE_FLASH_PFLASH_BLOCK_SECTOR_SIZE
#define FLASH0_FEATURE_PFLASH_BLOCK_WRITE_UNIT_SIZE FSL_FEATURE_FLASH_PFLASH_BLOCK_WRITE_UNIT_SIZE
#define FLASH0_FEATURE_PFLASH_SECTOR_CMD_ADDRESS_ALIGMENT FSL_FEATURE_FLASH_PFLASH_SECTOR_CMD_ADDRESS_ALIGMENT
#define FLASH0_FEATURE_PFLASH_SECTION_CMD_ADDRESS_ALIGMENT FSL_FEATURE_FLASH_PFLASH_SECTION_CMD_ADDRESS_ALIGMENT
#define FLASH0_FEATURE_PFLASH_PROTECTION_REGION_COUNT FSL_FEATURE_FLASH_PFLASH_PROTECTION_REGION_COUNT
#if defined(FSL_FEATURE_FLASH_HAS_MULTIPLE_FLASH) || defined(FSL_FEATURE_FLASH_PFLASH_1_START_ADDRESS)
#define FLASH1_FEATURE_PFLASH_START_ADDRESS FSL_FEATURE_FLASH_PFLASH_1_START_ADDRESS
#define FLASH1_FEATURE_PFLASH_BLOCK_COUNT FSL_FEATURE_FLASH_PFLASH_1_BLOCK_COUNT
#define FLASH1_FEATURE_PFLASH_BLOCK_SIZE FSL_FEATURE_FLASH_PFLASH_1_BLOCK_SIZE
#define FLASH1_FEATURE_PFLASH_BLOCK_SECTOR_SIZE FSL_FEATURE_FLASH_PFLASH_1_BLOCK_SECTOR_SIZE
#define FLASH1_FEATURE_PFLASH_BLOCK_WRITE_UNIT_SIZE FSL_FEATURE_FLASH_PFLASH_1_BLOCK_WRITE_UNIT_SIZE
#define FLASH1_FEATURE_PFLASH_SECTOR_CMD_ADDRESS_ALIGMENT FSL_FEATURE_FLASH_PFLASH_SECTOR_CMD_ADDRESS_ALIGMENT
#define FLASH1_FEATURE_PFLASH_SECTION_CMD_ADDRESS_ALIGMENT FSL_FEATURE_FLASH_PFLASH_SECTION_CMD_ADDRESS_ALIGMENT
#define FLASH1_FEATURE_PFLASH_PROTECTION_REGION_COUNT FSL_FEATURE_FLASH_PFLASH_PROTECTION_REGION_COUNT
#else /* undfine FSL_FEATURE_FLASH_HAS_MULTIPLE_FLASH or FSL_FEATURE_FLASH_PFLASH_1_START_ADDRESS */
#define FLASH1_FEATURE_PFLASH_START_ADDRESS 0
#define FLASH1_FEATURE_PFLASH_BLOCK_COUNT 0
#define FLASH1_FEATURE_PFLASH_BLOCK_SIZE 0
#define FLASH1_FEATURE_PFLASH_BLOCK_SECTOR_SIZE 0
#define FLASH1_FEATURE_PFLASH_BLOCK_WRITE_UNIT_SIZE 0
#define FLASH1_FEATURE_PFLASH_SECTOR_CMD_ADDRESS_ALIGMENT 0
#define FLASH1_FEATURE_PFLASH_SECTION_CMD_ADDRESS_ALIGMENT 0
#define FLASH1_FEATURE_PFLASH_PROTECTION_REGION_COUNT 0
#endif
#endif
#if FLASH0_FEATURE_PFLASH_PROTECTION_REGION_COUNT > FLASH1_FEATURE_PFLASH_PROTECTION_REGION_COUNT
#define MAX_FLASH_PROT_REGION_COUNT FLASH0_FEATURE_PFLASH_PROTECTION_REGION_COUNT
#else
#define MAX_FLASH_PROT_REGION_COUNT FLASH1_FEATURE_PFLASH_PROTECTION_REGION_COUNT
#endif
/*@}*/
#endif /* FSL_FTFX_ADAPTER_H */

@ -0,0 +1,549 @@
/*
* Copyright 2013-2016 Freescale Semiconductor, Inc.
* Copyright 2016-2020 NXP
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
*/
#include "fsl_ftfx_cache.h"
/*******************************************************************************
* Definitions
******************************************************************************/
/* Component ID definition, used by tools. */
#ifndef FSL_COMPONENT_ID
#define FSL_COMPONENT_ID "platform.drivers.flash"
#endif
/*!
* @name Flash cache and speculation control defines
* @{
*/
#if defined(MCM_PLACR_CFCC_MASK)
#define FLASH_CACHE_IS_CONTROLLED_BY_MCM (1u)
#else
#define FLASH_CACHE_IS_CONTROLLED_BY_MCM (0u)
#endif
#define FLASH_CACHE_IS_CONTROLLED_BY_MSCM (0u)
#if defined(FMC_PFB0CR_CINV_WAY_MASK) || defined(FMC_PFB01CR_CINV_WAY_MASK)
#define FLASH_CACHE_IS_CONTROLLED_BY_FMC (1u)
#else
#define FLASH_CACHE_IS_CONTROLLED_BY_FMC (0u)
#endif
#if defined(MCM_PLACR_DFCS_MASK)
#define FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_MCM (1u)
#else
#define FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_MCM (0u)
#endif
#if defined(MSCM_OCMDR_OCMC1_MASK) || defined(MSCM_OCMDR_OCM1_MASK) || defined(MSCM_OCMDR0_OCM1_MASK) || \
defined(MSCM_OCMDR1_OCM1_MASK)
#define FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_MSCM (1u)
#else
#define FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_MSCM (0u)
#endif
#if defined(FMC_PFB0CR_S_INV_MASK) || defined(FMC_PFB0CR_S_B_INV_MASK) || defined(FMC_PFB01CR_S_INV_MASK) || \
defined(FMC_PFB01CR_S_B_INV_MASK)
#define FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_FMC (1u)
#else
#define FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_FMC (0u)
#endif
#if FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_MSCM || FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_FMC || \
FLASH_CACHE_IS_CONTROLLED_BY_MCM || FLASH_CACHE_IS_CONTROLLED_BY_FMC || FLASH_CACHE_IS_CONTROLLED_BY_MSCM
#define FLASH_IS_CACHE_INVALIDATION_AVAILABLE (1)
#else
#define FLASH_IS_CACHE_INVALIDATION_AVAILABLE (0u)
#endif
/*@}*/
/*! @brief A function pointer used to point to relocated ftfx_common_bit_operation() */
typedef void (*callftfxCommonBitOperation_t)(FTFx_REG32_ACCESS_TYPE base,
uint32_t bitMask,
uint32_t bitShift,
uint32_t bitValue);
/*******************************************************************************
* Prototypes
******************************************************************************/
#if FLASH_CACHE_IS_CONTROLLED_BY_MCM
/*! @brief Performs the cache clear to the flash by MCM.*/
void mcm_flash_cache_clear(ftfx_cache_config_t *config);
#endif /* FLASH_CACHE_IS_CONTROLLED_BY_MCM */
#if FLASH_CACHE_IS_CONTROLLED_BY_MSCM
/*! @brief Performs the cache clear to the flash by MSCM.*/
void mscm_flash_cache_clear(ftfx_cache_config_t *config);
#endif /* FLASH_CACHE_IS_CONTROLLED_BY_MSCM */
#if FLASH_CACHE_IS_CONTROLLED_BY_FMC
/*! @brief Performs the cache clear to the flash by FMC.*/
void fmc_flash_cache_clear(ftfx_cache_config_t *config);
#endif /* FLASH_CACHE_IS_CONTROLLED_BY_FMC */
#if FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_MSCM
/*! @brief Sets the prefetch speculation buffer to the flash by MSCM.*/
void mscm_flash_prefetch_speculation_enable(ftfx_cache_config_t *config, bool enable);
#endif /* FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_MSCM */
#if FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_FMC
/*! @brief Performs the prefetch speculation buffer clear to the flash by FMC.*/
void fmc_flash_prefetch_speculation_clear(ftfx_cache_config_t *config);
#endif /* FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_FMC */
#if FTFx_DRIVER_IS_FLASH_RESIDENT
static void ftfx_common_bit_operation_command_sequence(
ftfx_cache_config_t *config, FTFx_REG32_ACCESS_TYPE base, uint32_t bitMask, uint32_t bitShift, uint32_t bitValue);
#endif /* FTFx_DRIVER_IS_FLASH_RESIDENT */
#if FTFx_DRIVER_IS_FLASH_RESIDENT && FLASH_IS_CACHE_INVALIDATION_AVAILABLE
/*! @brief Copy flash_cache_clear_command() to RAM*/
static void ftfx_copy_common_bit_operation_to_ram(uint32_t *ftfxCommonBitOperation);
#endif /* FTFx_DRIVER_IS_FLASH_RESIDENT */
/*******************************************************************************
* Variables
******************************************************************************/
#if FTFx_DRIVER_IS_FLASH_RESIDENT && FLASH_IS_CACHE_INVALIDATION_AVAILABLE
/*!
* @brief Position independent code of ftfx_common_bit_operation()
*
* Note1: The prototype of C function is shown as below:
* @code
* void ftfx_common_bit_operation(FTFx_REG32_ACCESS_TYPE base, uint32_t bitMask, uint32_t bitShift, uint32_t
* bitValue)
* {
* if (bitMask)
* {
* uint32_t value = (((uint32_t)(((uint32_t)(bitValue)) << bitShift)) & bitMask);
* *base = (*base & (~bitMask)) | value;
* }
*
* __ISB();
* __DSB();
* }
* @endcode
* Note2: The binary code is generated by IAR 7.70.1
*/
static const uint32_t s_ftfxCommonBitOperationFunctionCode[] = {
0x2900b510u, 0x6804d005u, 0x4093438cu, 0x43214019u, 0xf3bf6001u, 0xf3bf8f6fu, 0xbd108f4fu,
};
#if (!FTFx_DRIVER_IS_EXPORTED)
/*! @brief A static buffer used to hold ftfx_common_bit_operation() */
static uint32_t s_ftfxCommonBitOperation[kFTFx_CACHE_RamFuncMaxSizeInWords];
#endif /* (!FTFx_DRIVER_IS_EXPORTED) */
#endif /* FLASH_IS_CACHE_INVALIDATION_AVAILABLE && FTFx_DRIVER_IS_FLASH_RESIDENT */
/*******************************************************************************
* Code
******************************************************************************/
status_t FTFx_CACHE_Init(ftfx_cache_config_t *config)
{
if (config == NULL)
{
return kStatus_FTFx_InvalidArgument;
}
/* copy required flash commands to RAM */
#if FTFx_DRIVER_IS_FLASH_RESIDENT && FLASH_IS_CACHE_INVALIDATION_AVAILABLE
if (NULL == config->bitOperFuncAddr.callFlashCommand)
{
#if FTFx_DRIVER_IS_EXPORTED
return kStatus_FTFx_ExecuteInRamFunctionNotReady;
#else
config->bitOperFuncAddr.commadAddr = (uint32_t)s_ftfxCommonBitOperation;
#endif /* FTFx_DRIVER_IS_EXPORTED */
}
ftfx_copy_common_bit_operation_to_ram((uint32_t *)config->bitOperFuncAddr.commadAddr);
#endif /* FLASH_IS_CACHE_INVALIDATION_AVAILABLE && FTFx_DRIVER_IS_FLASH_RESIDENT */
return kStatus_FTFx_Success;
}
/*!
* @brief Flash Cache/Prefetch/Speculation Clear Process
*
* This function is used to perform the cache and prefetch speculation clear process to the flash.
*/
status_t FTFx_CACHE_ClearCachePrefetchSpeculation(ftfx_cache_config_t *config, bool isPreProcess)
{
/* We pass the ftfx register address as a parameter to ftfx_common_bit_operation() instead of using
* pre-processed MACROs or a global variable in ftfx_common_bit_operation()
* to make sure that ftfx_common_bit_operation() will be compiled into position-independent code (PIC). */
if (!isPreProcess)
{
#if FLASH_CACHE_IS_CONTROLLED_BY_MCM
mcm_flash_cache_clear(config);
#endif
#if FLASH_CACHE_IS_CONTROLLED_BY_MSCM
mscm_flash_cache_clear(config);
#endif
#if FLASH_CACHE_IS_CONTROLLED_BY_FMC
fmc_flash_cache_clear(config);
#endif
#if FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_MSCM
mscm_flash_prefetch_speculation_enable(config, true);
#endif
#if FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_FMC
fmc_flash_prefetch_speculation_clear(config);
#endif
}
if (isPreProcess)
{
#if FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_MSCM
mscm_flash_prefetch_speculation_enable(config, false);
#endif
}
return kStatus_FTFx_Success;
}
status_t FTFx_CACHE_PflashSetPrefetchSpeculation(ftfx_prefetch_speculation_status_t *speculationStatus)
{
#if FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_MCM
{
if (true == speculationStatus->instructionOff)
{
if (false == speculationStatus->dataOff)
{
return kStatus_FTFx_InvalidSpeculationOption;
}
else
{
MCM0_CACHE_REG |= MCM_PLACR_DFCS_MASK;
}
}
else
{
MCM0_CACHE_REG &= ~MCM_PLACR_DFCS_MASK;
if (false == speculationStatus->dataOff)
{
MCM0_CACHE_REG |= MCM_PLACR_EFDS_MASK;
}
else
{
MCM0_CACHE_REG &= ~MCM_PLACR_EFDS_MASK;
}
}
}
#elif FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_FMC
{
if (false == speculationStatus->instructionOff)
{
FMC_CACHE_REG |= FMC_CACHE_B0IPE_MASK;
}
else
{
FMC_CACHE_REG &= ~FMC_CACHE_B0IPE_MASK;
}
if (false == speculationStatus->dataOff)
{
FMC_CACHE_REG |= FMC_CACHE_B0DPE_MASK;
}
else
{
FMC_CACHE_REG &= ~FMC_CACHE_B0DPE_MASK;
}
/* Invalidate Prefetch Speculation Buffer */
FMC_SPECULATION_INVALIDATE_REG |= FMC_SPECULATION_INVALIDATE_MASK;
}
#elif FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_MSCM
{
if (true == speculationStatus->instructionOff)
{
if (false == speculationStatus->dataOff)
{
return kStatus_FTFx_InvalidSpeculationOption;
}
else
{
MSCM_OCMDR0_REG |= MSCM_OCMDR_OCMC1_DFCS_MASK;
}
}
else
{
MSCM_OCMDR0_REG &= ~MSCM_OCMDR_OCMC1_DFCS_MASK;
if (false == speculationStatus->dataOff)
{
MSCM_OCMDR0_REG &= ~MSCM_OCMDR_OCMC1_DFDS_MASK;
}
else
{
MSCM_OCMDR0_REG |= MSCM_OCMDR_OCMC1_DFDS_MASK;
}
}
}
#endif /* FSL_FEATURE_FTFx_MCM_FLASH_CACHE_CONTROLS */
return kStatus_FTFx_Success;
}
status_t FTFx_CACHE_PflashGetPrefetchSpeculation(ftfx_prefetch_speculation_status_t *speculationStatus)
{
(void)memset(speculationStatus, 0, sizeof(ftfx_prefetch_speculation_status_t));
/* Assuming that all speculation options are enabled. */
speculationStatus->instructionOff = false;
speculationStatus->dataOff = false;
#if FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_MCM
{
uint32_t value = MCM0_CACHE_REG;
if (0U != (value & MCM_PLACR_DFCS_MASK))
{
/* Speculation buffer is off. */
speculationStatus->instructionOff = true;
speculationStatus->dataOff = true;
}
else
{
/* Speculation buffer is on for instruction. */
if (0U == (value & MCM_PLACR_EFDS_MASK))
{
/* Speculation buffer is off for data. */
speculationStatus->dataOff = true;
}
}
}
#elif FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_FMC
{
uint32_t value = FMC_CACHE_REG;
if (0U == (value & FMC_CACHE_B0DPE_MASK))
{
/* Do not prefetch in response to data references. */
speculationStatus->dataOff = true;
}
if (0U == (value & FMC_CACHE_B0IPE_MASK))
{
/* Do not prefetch in response to instruction fetches. */
speculationStatus->instructionOff = true;
}
}
#elif FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_MSCM
{
uint32_t value = MSCM_OCMDR0_REG;
if (0U != (value & MSCM_OCMDR_OCMC1_DFCS_MASK))
{
/* Speculation buffer is off. */
speculationStatus->instructionOff = true;
speculationStatus->dataOff = true;
}
else
{
/* Speculation buffer is on for instruction. */
if (0U != (value & MSCM_OCMDR_OCMC1_DFDS_MASK))
{
/* Speculation buffer is off for data. */
speculationStatus->dataOff = true;
}
}
}
#endif
return kStatus_FTFx_Success;
}
#if FTFx_DRIVER_IS_FLASH_RESIDENT && FLASH_IS_CACHE_INVALIDATION_AVAILABLE
/*! @brief Copy PIC of ftfx_common_bit_operation() to RAM */
static void ftfx_copy_common_bit_operation_to_ram(uint32_t *ftfxCommonBitOperation)
{
assert(sizeof(s_ftfxCommonBitOperationFunctionCode) <= ((uint32_t)kFTFx_CACHE_RamFuncMaxSizeInWords * 4U));
(void)memcpy(ftfxCommonBitOperation, s_ftfxCommonBitOperationFunctionCode,
sizeof(s_ftfxCommonBitOperationFunctionCode));
}
#endif /* FTFx_DRIVER_IS_FLASH_RESIDENT && FLASH_IS_CACHE_INVALIDATION_AVAILABLE */
#if FTFx_DRIVER_IS_FLASH_RESIDENT
static void ftfx_common_bit_operation_command_sequence(
ftfx_cache_config_t *config, FTFx_REG32_ACCESS_TYPE base, uint32_t bitMask, uint32_t bitShift, uint32_t bitValue)
{
uint32_t *ftfxCommonBitOperationAddr;
ftfxCommonBitOperationAddr = &config->bitOperFuncAddr.commadAddr;
/* Since the value of ARM function pointer is always odd, but the real start
* address
* of function memory should be even, that's why +1 operation exist. */
*ftfxCommonBitOperationAddr += 1UL;
callftfxCommonBitOperation_t ftfxCommonBitOperationCommand = config->bitOperFuncAddr.callFlashCommand;
/* Workround for some devices which doesn't need this function */
ftfxCommonBitOperationCommand((FTFx_REG32_ACCESS_TYPE)base, bitMask, bitShift, bitValue);
*ftfxCommonBitOperationAddr -= 1UL;
}
#endif /*FTFx_DRIVER_IS_FLASH_RESIDENT*/
#if FLASH_CACHE_IS_CONTROLLED_BY_MCM
/*! @brief Performs the cache clear to the flash by MCM.*/
void mcm_flash_cache_clear(ftfx_cache_config_t *config)
{
FTFx_REG32_ACCESS_TYPE regBase;
#if defined(MCM0_CACHE_REG)
regBase = (FTFx_REG32_ACCESS_TYPE)&MCM0_CACHE_REG;
#elif defined(MCM1_CACHE_REG)
regBase = (FTFx_REG32_ACCESS_TYPE)&MCM1_CACHE_REG;
#endif
#if FTFx_DRIVER_IS_FLASH_RESIDENT
/* calling flash command sequence function to execute the command */
ftfx_common_bit_operation_command_sequence(config, regBase, MCM_CACHE_CLEAR_MASK, MCM_CACHE_CLEAR_SHIFT, 1UL);
#else /* !FTFx_DRIVER_IS_FLASH_RESIDENT */
*regBase |= MCM_CACHE_CLEAR_MASK;
/* Memory barriers for good measure.
* All Cache, Branch predictor and TLB maintenance operations before this instruction complete */
__ISB();
__DSB();
#endif /* FTFx_DRIVER_IS_FLASH_RESIDENT */
}
#endif /* FLASH_CACHE_IS_CONTROLLED_BY_MCM */
#if FLASH_CACHE_IS_CONTROLLED_BY_MSCM
/*! @brief Performs the cache clear to the flash by MSCM.*/
void mscm_flash_cache_clear(ftfx_cache_config_t *config)
{
uint8_t setValue = 0x1U;
/* The OCMDR[0] is always used to cache main Pflash*/
/* For device with FlexNVM support, the OCMDR[1] is used to cache Dflash.
* For device with secondary flash support, the OCMDR[1] is used to cache secondary Pflash. */
#if FTFx_DRIVER_IS_FLASH_RESIDENT
switch (config->flashMemoryIndex)
{
case kFLASH_MemoryIndexSecondaryFlash:
/* calling flash command sequence function to execute the command */
ftfx_common_bit_operation_command_sequence(config, (FTFx_REG32_ACCESS_TYPE)&MSCM_OCMDR1_REG,
MSCM_CACHE_CLEAR_MASK, MSCM_CACHE_CLEAR_SHIFT, setValue);
break;
case kFLASH_MemoryIndexPrimaryFlash:
default:
/* calling flash command sequence function to execute the command */
ftfx_common_bit_operation_command_sequence(config, (FTFx_REG32_ACCESS_TYPE)&MSCM_OCMDR0_REG,
MSCM_CACHE_CLEAR_MASK, MSCM_CACHE_CLEAR_SHIFT, setValue);
break;
}
#else /* !FTFx_DRIVER_IS_FLASH_RESIDENT */
switch (config->flashMemoryIndex)
{
case kFLASH_MemoryIndexSecondaryFlash:
MSCM_OCMDR1_REG = (MSCM_OCMDR1_REG & (~MSCM_CACHE_CLEAR_MASK)) | MSCM_CACHE_CLEAR(setValue);
/* Each cache clear instruction should be followed by below code*/
__ISB();
__DSB();
break;
case kFLASH_MemoryIndexPrimaryFlash:
default:
MSCM_OCMDR0_REG = (MSCM_OCMDR0_REG & (~MSCM_CACHE_CLEAR_MASK)) | MSCM_CACHE_CLEAR(setValue);
/* Memory barriers for good measure.
* All Cache, Branch predictor and TLB maintenance operations before this instruction complete */
__ISB();
__DSB();
break;
}
#endif /* FTFx_DRIVER_IS_FLASH_RESIDENT */
}
#endif /* FLASH_CACHE_IS_CONTROLLED_BY_MSCM */
#if FLASH_CACHE_IS_CONTROLLED_BY_FMC
/*! @brief Performs the cache clear to the flash by FMC.*/
void fmc_flash_cache_clear(ftfx_cache_config_t *config)
{
#if FTFx_DRIVER_IS_FLASH_RESIDENT
/* calling flash command sequence function to execute the command */
ftfx_common_bit_operation_command_sequence(config, (FTFx_REG32_ACCESS_TYPE)&FMC_CACHE_REG, FMC_CACHE_CLEAR_MASK,
FMC_CACHE_CLEAR_SHIFT, 0xFUL);
#else /* !FTFx_DRIVER_IS_FLASH_RESIDENT */
FMC_CACHE_REG = (FMC_CACHE_REG & (~FMC_CACHE_CLEAR_MASK)) | FMC_CACHE_CLEAR(~0);
/* Memory barriers for good measure.
* All Cache, Branch predictor and TLB maintenance operations before this instruction complete */
__ISB();
__DSB();
#endif /* FTFx_DRIVER_IS_FLASH_RESIDENT */
}
#endif /* FLASH_CACHE_IS_CONTROLLED_BY_FMC */
#if FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_MSCM
/*! @brief Performs the prefetch speculation buffer clear to the flash by MSCM.*/
void mscm_flash_prefetch_speculation_enable(ftfx_cache_config_t *config, bool enable)
{
uint8_t setValue;
if (enable)
{
setValue = 0x0U;
}
else
{
setValue = 0x3U;
}
/* The OCMDR[0] is always used to prefetch main Pflash*/
/* For device with FlexNVM support, the OCMDR[1] is used to prefetch Dflash.
* For device with secondary flash support, the OCMDR[1] is used to prefetch secondary Pflash. */
#if FTFx_DRIVER_IS_FLASH_RESIDENT
switch (config->flashMemoryIndex)
{
case 1:
/* calling flash command sequence function to execute the command */
ftfx_common_bit_operation_command_sequence(config, (FTFx_REG32_ACCESS_TYPE)&MSCM_OCMDR1_REG,
MSCM_SPECULATION_SET_MASK, MSCM_SPECULATION_SET_SHIFT, setValue);
break;
case 0:
default:
/* calling flash command sequence function to execute the command */
ftfx_common_bit_operation_command_sequence(config, (FTFx_REG32_ACCESS_TYPE)&MSCM_OCMDR0_REG,
MSCM_SPECULATION_SET_MASK, MSCM_SPECULATION_SET_SHIFT, setValue);
break;
}
#else /* !FTFx_DRIVER_IS_FLASH_RESIDENT */
switch (config->flashMemoryIndex)
{
case kFLASH_MemoryIndexSecondaryFlash:
MSCM_OCMDR1_REG = (MSCM_OCMDR1_REG & (~MSCM_SPECULATION_SET_MASK)) | MSCM_SPECULATION_SET(setValue);
/* Each cache clear instruction should be followed by below code*/
__ISB();
__DSB();
break;
case kFLASH_MemoryIndexPrimaryFlash:
default:
MSCM_OCMDR0_REG = (MSCM_OCMDR0_REG & (~MSCM_SPECULATION_SET_MASK)) | MSCM_SPECULATION_SET(setValue);
/* Memory barriers for good measure.
* All Cache, Branch predictor and TLB maintenance operations before this instruction complete */
__ISB();
__DSB();
break;
}
#endif /* FTFx_DRIVER_IS_FLASH_RESIDENT */
}
#endif /* FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_MSCM */
#if FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_FMC
/*! @brief Performs the prefetch speculation buffer clear to the flash by FMC.*/
void fmc_flash_prefetch_speculation_clear(ftfx_cache_config_t *config)
{
#if FTFx_DRIVER_IS_FLASH_RESIDENT
/* calling flash command sequence function to execute the command */
ftfx_common_bit_operation_command_sequence(config, (FTFx_REG32_ACCESS_TYPE)&FMC_SPECULATION_INVALIDATE_REG,
FMC_SPECULATION_INVALIDATE_MASK, FMC_SPECULATION_INVALIDATE_SHIFT, 1UL);
#else /* !FTFx_DRIVER_IS_FLASH_RESIDENT */
FMC_SPECULATION_INVALIDATE_REG |= FMC_SPECULATION_INVALIDATE_MASK;
/* Memory barriers for good measure.
* All Cache, Branch predictor and TLB maintenance operations before this instruction complete */
__ISB();
__DSB();
#endif /* FTFx_DRIVER_IS_FLASH_RESIDENT */
}
#endif /* FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_FMC */

@ -0,0 +1,113 @@
/*
* Copyright 2013-2016 Freescale Semiconductor, Inc.
* Copyright 2016-2020 NXP
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
*/
#ifndef FSL_FTFX_CACHE_H
#define FSL_FTFX_CACHE_H
#include "fsl_ftfx_controller.h"
/*!
* @addtogroup ftfx_cache_driver
* @{
*/
/*******************************************************************************
* Definitions
******************************************************************************/
/*!
* @brief FTFx prefetch speculation status.
*/
typedef struct _flash_prefetch_speculation_status
{
bool instructionOff; /*!< Instruction speculation.*/
bool dataOff; /*!< Data speculation.*/
} ftfx_prefetch_speculation_status_t;
/*!
* @brief Constants for execute-in-RAM flash function.
*/
enum _ftfx_cache_ram_func_constants
{
kFTFx_CACHE_RamFuncMaxSizeInWords = 16U, /*!< The maximum size of execute-in-RAM function.*/
};
typedef union
{
uint32_t commadAddr;
void (*callFlashCommand)(FTFx_REG32_ACCESS_TYPE base, uint32_t bitMask, uint32_t bitShift, uint32_t bitValue);
} function_bit_operation_ptr_t;
/*! @brief FTFx cache driver state information.
*
* An instance of this structure is allocated by the user of the flash driver and
* passed into each of the driver APIs.
*/
typedef struct _ftfx_cache_config
{
uint8_t flashMemoryIndex; /*!< 0 - primary flash; 1 - secondary flash*/
uint8_t reserved[3];
function_bit_operation_ptr_t bitOperFuncAddr; /*!< An buffer point to the flash execute-in-RAM function. */
} ftfx_cache_config_t;
/*******************************************************************************
* API
******************************************************************************/
#if defined(__cplusplus)
extern "C" {
#endif
/*!
* @brief Initializes the global FTFx cache structure members.
*
* This function checks and initializes the Flash module for the other FTFx cache APIs.
*
* @param config Pointer to the storage for the driver runtime state.
*
* @retval #kStatus_FTFx_Success API was executed successfully.
* @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
* @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
*/
status_t FTFx_CACHE_Init(ftfx_cache_config_t *config);
/*!
* @brief Process the cache/prefetch/speculation to the flash.
*
* @param config A pointer to the storage for the driver runtime state.
* @param isPreProcess The possible option used to control flash cache/prefetch/speculation
* @retval #kStatus_FTFx_Success API was executed successfully.
* @retval #kStatus_FTFx_InvalidArgument Invalid argument is provided.
* @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
*/
status_t FTFx_CACHE_ClearCachePrefetchSpeculation(ftfx_cache_config_t *config, bool isPreProcess);
/*!
* @brief Sets the PFlash prefetch speculation to the intended speculation status.
*
* @param speculationStatus The expected protect status to set to the PFlash protection register. Each bit is
* @retval #kStatus_FTFx_Success API was executed successfully.
* @retval #kStatus_FTFx_InvalidSpeculationOption An invalid speculation option argument is provided.
*/
status_t FTFx_CACHE_PflashSetPrefetchSpeculation(ftfx_prefetch_speculation_status_t *speculationStatus);
/*!
* @brief Gets the PFlash prefetch speculation status.
*
* @param speculationStatus Speculation status returned by the PFlash IP.
* @retval #kStatus_FTFx_Success API was executed successfully.
*/
status_t FTFx_CACHE_PflashGetPrefetchSpeculation(ftfx_prefetch_speculation_status_t *speculationStatus);
#if defined(__cplusplus)
}
#endif
/*! @}*/
#endif /* FSL_FTFX_CACHE_H */

File diff suppressed because it is too large Load Diff

@ -0,0 +1,846 @@
/*
* Copyright 2013-2016 Freescale Semiconductor, Inc.
* Copyright 2016-2020 NXP
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
*/
#ifndef FSL_FTFX_CONTROLLER_H
#define FSL_FTFX_CONTROLLER_H
#include "fsl_ftfx_features.h"
#include "fsl_ftfx_utilities.h"
/*!
* @addtogroup ftfx_controller
* @{
*/
/*******************************************************************************
* Definitions
******************************************************************************/
/*!
* @name FTFx status
* @{
*/
/*! @brief FTFx driver status group. */
#if defined(kStatusGroup_FlashDriver)
#define kStatusGroupGeneric kStatusGroup_Generic
#define kStatusGroupFtfxDriver kStatusGroup_FlashDriver
#elif defined(kStatusGroup_FLASH)
#define kStatusGroupGeneric kStatusGroup_Generic
#define kStatusGroupFtfxDriver kStatusGroup_FLASH
#else
#define kStatusGroupGeneric 0
#define kStatusGroupFtfxDriver 1
#endif
/*!
* @brief FTFx driver status codes.
*/
enum
{
kStatus_FTFx_Success = MAKE_STATUS(kStatusGroupGeneric, 0), /*!< API is executed successfully*/
kStatus_FTFx_InvalidArgument = MAKE_STATUS(kStatusGroupGeneric, 4), /*!< Invalid argument*/
kStatus_FTFx_SizeError = MAKE_STATUS(kStatusGroupFtfxDriver, 0), /*!< Error size*/
kStatus_FTFx_AlignmentError =
MAKE_STATUS(kStatusGroupFtfxDriver, 1), /*!< Parameter is not aligned with the specified baseline*/
kStatus_FTFx_AddressError = MAKE_STATUS(kStatusGroupFtfxDriver, 2), /*!< Address is out of range */
kStatus_FTFx_AccessError =
MAKE_STATUS(kStatusGroupFtfxDriver, 3), /*!< Invalid instruction codes and out-of bound addresses */
kStatus_FTFx_ProtectionViolation = MAKE_STATUS(
kStatusGroupFtfxDriver, 4), /*!< The program/erase operation is requested to execute on protected areas */
kStatus_FTFx_CommandFailure =
MAKE_STATUS(kStatusGroupFtfxDriver, 5), /*!< Run-time error during command execution. */
kStatus_FTFx_UnknownProperty = MAKE_STATUS(kStatusGroupFtfxDriver, 6), /*!< Unknown property.*/
kStatus_FTFx_EraseKeyError = MAKE_STATUS(kStatusGroupFtfxDriver, 7), /*!< API erase key is invalid.*/
kStatus_FTFx_RegionExecuteOnly = MAKE_STATUS(kStatusGroupFtfxDriver, 8), /*!< The current region is execute-only.*/
kStatus_FTFx_ExecuteInRamFunctionNotReady =
MAKE_STATUS(kStatusGroupFtfxDriver, 9), /*!< Execute-in-RAM function is not available.*/
kStatus_FTFx_PartitionStatusUpdateFailure =
MAKE_STATUS(kStatusGroupFtfxDriver, 10), /*!< Failed to update partition status.*/
kStatus_FTFx_SetFlexramAsEepromError =
MAKE_STATUS(kStatusGroupFtfxDriver, 11), /*!< Failed to set FlexRAM as EEPROM.*/
kStatus_FTFx_RecoverFlexramAsRamError =
MAKE_STATUS(kStatusGroupFtfxDriver, 12), /*!< Failed to recover FlexRAM as RAM.*/
kStatus_FTFx_SetFlexramAsRamError = MAKE_STATUS(kStatusGroupFtfxDriver, 13), /*!< Failed to set FlexRAM as RAM.*/
kStatus_FTFx_RecoverFlexramAsEepromError =
MAKE_STATUS(kStatusGroupFtfxDriver, 14), /*!< Failed to recover FlexRAM as EEPROM.*/
kStatus_FTFx_CommandNotSupported = MAKE_STATUS(kStatusGroupFtfxDriver, 15), /*!< Flash API is not supported.*/
kStatus_FTFx_SwapSystemNotInUninitialized =
MAKE_STATUS(kStatusGroupFtfxDriver, 16), /*!< Swap system is not in an uninitialzed state.*/
kStatus_FTFx_SwapIndicatorAddressError =
MAKE_STATUS(kStatusGroupFtfxDriver, 17), /*!< The swap indicator address is invalid.*/
kStatus_FTFx_ReadOnlyProperty = MAKE_STATUS(kStatusGroupFtfxDriver, 18), /*!< The flash property is read-only.*/
kStatus_FTFx_InvalidPropertyValue =
MAKE_STATUS(kStatusGroupFtfxDriver, 19), /*!< The flash property value is out of range.*/
kStatus_FTFx_InvalidSpeculationOption =
MAKE_STATUS(kStatusGroupFtfxDriver, 20), /*!< The option of flash prefetch speculation is invalid.*/
kStatus_FTFx_CommandOperationInProgress =
MAKE_STATUS(kStatusGroupFtfxDriver, 21), /*!< The option of flash command is processing.*/
};
/*@}*/
/*!
* @name FTFx API key
* @{
*/
/*!
* @brief Enumeration for FTFx driver API keys.
*
* @note The resulting value is built with a byte order such that the string
* being readable in expected order when viewed in a hex editor, if the value
* is treated as a 32-bit little endian value.
*/
enum _ftfx_driver_api_keys
{
kFTFx_ApiEraseKey = FOUR_CHAR_CODE('k', 'f', 'e', 'k') /*!< Key value used to validate all FTFx erase APIs.*/
};
/*@}*/
/*!
* @brief Enumeration for the FlexRAM load during reset option.
*/
typedef enum _ftfx_partition_flexram_load_option
{
kFTFx_PartitionFlexramLoadOptLoadedWithValidEepromData =
0x00U, /*!< FlexRAM is loaded with valid EEPROM data during reset sequence.*/
kFTFx_PartitionFlexramLoadOptNotLoaded = 0x01U /*!< FlexRAM is not loaded during reset sequence.*/
} ftfx_partition_flexram_load_opt_t;
/*!
* @brief Enumeration for the two possible options of flash read resource command.
*/
typedef enum _ftfx_read_resource_opt
{
kFTFx_ResourceOptionFlashIfr =
0x00U, /*!< Select code for Program flash 0 IFR, Program flash swap 0 IFR, Data flash 0 IFR */
kFTFx_ResourceOptionVersionId = 0x01U /*!< Select code for the version ID*/
} ftfx_read_resource_opt_t;
/*!
* @brief Enumeration for supported FTFx margin levels.
*/
typedef enum _ftfx_margin_value
{
kFTFx_MarginValueNormal, /*!< Use the 'normal' read level for 1s.*/
kFTFx_MarginValueUser, /*!< Apply the 'User' margin to the normal read-1 level.*/
kFTFx_MarginValueFactory, /*!< Apply the 'Factory' margin to the normal read-1 level.*/
kFTFx_MarginValueInvalid /*!< Not real margin level, Used to determine the range of valid margin level. */
} ftfx_margin_value_t;
/*!
* @brief Enumeration for the three possible FTFx security states.
*/
typedef enum _ftfx_security_state
{
kFTFx_SecurityStateNotSecure = (int)0xc33cc33cu, /*!< Flash is not secure.*/
kFTFx_SecurityStateBackdoorEnabled = (int)0x5aa55aa5u, /*!< Flash backdoor is enabled.*/
kFTFx_SecurityStateBackdoorDisabled = (int)0x5ac33ca5u /*!< Flash backdoor is disabled.*/
} ftfx_security_state_t;
/*!
* @brief Enumeration for the two possilbe options of set FlexRAM function command.
*/
typedef enum _ftfx_flexram_function_option
{
kFTFx_FlexramFuncOptAvailableAsRam = 0xFFU, /*!< An option used to make FlexRAM available as RAM */
kFTFx_FlexramFuncOptAvailableForEeprom = 0x00U /*!< An option used to make FlexRAM available for EEPROM */
} ftfx_flexram_func_opt_t;
/*!
* @brief Enumeration for acceleration ram property.
*/
enum _flash_acceleration_ram_property
{
kFLASH_AccelerationRamSize = 0x400U
};
#if defined(FSL_FEATURE_FLASH_HAS_SWAP_CONTROL_CMD) && FSL_FEATURE_FLASH_HAS_SWAP_CONTROL_CMD
/*!
* @brief Enumeration for the possible options of Swap control commands
*/
typedef enum _ftfx_swap_control_option
{
kFTFx_SwapControlOptionIntializeSystem = 0x01U, /*!< An option used to initialize the Swap system */
kFTFx_SwapControlOptionSetInUpdateState = 0x02U, /*!< An option used to set the Swap in an update state */
kFTFx_SwapControlOptionSetInCompleteState = 0x04U, /*!< An option used to set the Swap in a complete state */
kFTFx_SwapControlOptionReportStatus = 0x08U, /*!< An option used to report the Swap status */
kFTFx_SwapControlOptionDisableSystem = 0x10U /*!< An option used to disable the Swap status */
} ftfx_swap_control_opt_t;
#endif /* FSL_FEATURE_FLASH_HAS_SWAP_CONTROL_CMD */
/*!
* @brief Enumeration for the possible flash Swap status.
*/
typedef enum _ftfx_swap_state
{
kFTFx_SwapStateUninitialized = 0x00U, /*!< Flash Swap system is in an uninitialized state.*/
kFTFx_SwapStateReady = 0x01U, /*!< Flash Swap system is in a ready state.*/
kFTFx_SwapStateUpdate = 0x02U, /*!< Flash Swap system is in an update state.*/
kFTFx_SwapStateUpdateErased = 0x03U, /*!< Flash Swap system is in an updateErased state.*/
kFTFx_SwapStateComplete = 0x04U, /*!< Flash Swap system is in a complete state.*/
kFTFx_SwapStateDisabled = 0x05U /*!< Flash Swap system is in a disabled state.*/
} ftfx_swap_state_t;
#if defined(FSL_FEATURE_FLASH_HAS_SWAP_CONTROL_CMD) && FSL_FEATURE_FLASH_HAS_SWAP_CONTROL_CMD
/*!
* @brief Enumeration for the possible flash Swap block status
*/
typedef enum _ftfx_swap_block_status
{
kFTFx_SwapBlockStatusLowerHalfProgramBlocksAtZero =
0x00U, /*!< Swap block status is that lower half program block at zero.*/
kFTFx_SwapBlockStatusUpperHalfProgramBlocksAtZero =
0x01U, /*!< Swap block status is that upper half program block at zero.*/
} ftfx_swap_block_status_t;
/*!
* @brief Flash Swap information
*/
typedef struct _ftfx_swap_state_config
{
ftfx_swap_state_t flashSwapState; /*!<The current Swap system status.*/
ftfx_swap_block_status_t currentSwapBlockStatus; /*!< The current Swap block status.*/
ftfx_swap_block_status_t nextSwapBlockStatus; /*!< The next Swap block status.*/
} ftfx_swap_state_config_t;
#endif /* FSL_FEATURE_FLASH_HAS_SWAP_CONTROL_CMD */
/*!
* @brief Enumeration for FTFx memory type.
*/
enum _ftfx_memory_type
{
kFTFx_MemTypePflash = 0x00U,
kFTFx_MemTypeFlexnvm = 0x01U
};
/*!
* @brief ftfx special memory access information.
*/
typedef struct _ftfx_special_mem
{
uint32_t base; /*!< Base address of flash special memory.*/
uint32_t size; /*!< size of flash special memory.*/
uint32_t count; /*!< flash special memory count.*/
} ftfx_spec_mem_t;
#if defined(__CC_ARM)
#pragma anon_unions
#endif
/*!
* @brief Flash memory descriptor.
*/
typedef struct _ftfx_mem_descriptor
{
struct
{
uint8_t type; /*!< Type of flash block.*/
uint8_t index; /*!< Index of flash block.*/
uint8_t reserved[2];
};
struct
{
uint32_t isIndBlock : 1;
uint32_t hasIndPfsizeReg : 1;
uint32_t hasProtControl : 1;
uint32_t hasIndProtReg : 1;
uint32_t hasXaccControl : 1;
uint32_t hasIndXaccReg : 1;
uint32_t : 18;
uint32_t ProtRegBits : 8;
} feature;
uint32_t blockBase; /*!< A base address of the flash block */
#if defined(FSL_FEATURE_FLASH_HAS_FLEX_NVM_ALIAS) && FSL_FEATURE_FLASH_HAS_FLEX_NVM_ALIAS
uint32_t aliasBlockBase; /*!< A base address of the alias flash block */
#endif
uint32_t totalSize; /*!< The size of the flash block. */
uint32_t sectorSize; /*!< The size in bytes of a sector of flash. */
uint32_t blockCount; /*!< A number of flash blocks. */
ftfx_spec_mem_t accessSegmentMem;
ftfx_spec_mem_t protectRegionMem;
} ftfx_mem_desc_t;
/*!
* @brief Active FTFx information for the current operation.
*/
typedef struct _ftfx_ops_config
{
uint32_t convertedAddress; /*!< A converted address for the current flash type.*/
struct
{
uint8_t sectorCmd;
uint8_t sectionCmd;
uint8_t resourceCmd;
uint8_t checkCmd;
uint8_t swapCtrlCmd;
uint8_t blockWriteUnitSize;
uint8_t reserved[2];
} addrAligment;
} ftfx_ops_config_t;
/*!
* @brief Flash IFR memory descriptor.
*/
typedef struct _ftfx_ifr_descriptor
{
struct
{
uint32_t has4ByteIdxSupport : 1;
uint32_t has8ByteIdxSupport : 1;
uint32_t : 30;
} feature;
struct
{
uint8_t versionIdStart; /*!< Version ID start address */
uint8_t versionIdSize;
uint16_t ifrMemSize;
uint32_t pflashIfrStart; /*!< Program Flash 0 IFR start address */
uint32_t dflashIfrStart; /*!< Data Flash 0 IFR start address */
uint32_t pflashSwapIfrStart; /*!< Program Flash Swap IFR start address*/
} resRange;
struct
{
uint16_t mix8byteIdxStart;
uint16_t mix8byteIdxEnd;
} idxInfo;
} ftfx_ifr_desc_t;
typedef union
{
uint32_t commadAddr;
void (*callFlashCommand)(FTFx_REG8_ACCESS_TYPE FTMRx_fstat);
} function_ptr_t;
/*! @brief Flash driver state information.
*
* An instance of this structure is allocated by the user of the flash driver and
* passed into each of the driver APIs.
*/
typedef struct _ftfx_config
{
ftfx_mem_desc_t flashDesc;
ftfx_ops_config_t opsConfig;
uint32_t flexramBlockBase; /*!< The base address of the FlexRAM/acceleration RAM */
uint32_t flexramTotalSize; /*!< The size of the FlexRAM/acceleration RAM */
uint16_t eepromTotalSize; /*!< The size of EEPROM area which was partitioned from FlexRAM */
uint16_t reserved;
function_ptr_t runCmdFuncAddr; /*!< An buffer point to the flash execute-in-RAM function. */
ftfx_ifr_desc_t ifrDesc;
} ftfx_config_t;
/*******************************************************************************
* API
******************************************************************************/
#if defined(__cplusplus)
extern "C" {
#endif
/*!
* @name Initialization
* @{
*/
/*!
* @brief Initializes the global flash properties structure members.
*
* This function checks and initializes the Flash module for the other Flash APIs.
*
* @param config Pointer to the storage for the driver runtime state.
*
*/
void FTFx_API_Init(ftfx_config_t *config);
#if defined(FSL_FEATURE_FLASH_HAS_FLEX_NVM) && FSL_FEATURE_FLASH_HAS_FLEX_NVM
/*!
* @brief Updates FlexNVM memory partition status according to data flash 0 IFR.
*
* This function updates FlexNVM memory partition status.
*
* @param config Pointer to the storage for the driver runtime state.
*
* @retval #kStatus_FTFx_Success API was executed successfully.
* @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
* @retval #kStatus_FTFx_PartitionStatusUpdateFailure Failed to update the partition status.
*/
status_t FTFx_API_UpdateFlexnvmPartitionStatus(ftfx_config_t *config);
#endif /* FSL_FEATURE_FLASH_HAS_FLEX_NVM */
/*@}*/
/*!
* @name Erasing
* @{
*/
/*!
* @brief Erases the flash sectors encompassed by parameters passed into function.
*
* This function erases the appropriate number of flash sectors based on the
* desired start address and length.
*
* @param config The pointer to the storage for the driver runtime state.
* @param start The start address of the desired flash memory to be erased.
* The start address does not need to be sector-aligned but must be word-aligned.
* @param lengthInBytes The length, given in bytes (not words or long-words)
* to be erased. Must be word-aligned.
* @param key The value used to validate all flash erase APIs.
*
* @retval #kStatus_FTFx_Success API was executed successfully.
* @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
* @retval #kStatus_FTFx_AlignmentError The parameter is not aligned with the specified baseline.
* @retval #kStatus_FTFx_AddressError The address is out of range.
* @retval #kStatus_FTFx_EraseKeyError The API erase key is invalid.
* @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
* @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
* @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
* @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
*/
status_t FTFx_CMD_Erase(ftfx_config_t *config, uint32_t start, uint32_t lengthInBytes, uint32_t key);
/*!
* @brief Erases the flash sectors encompassed by parameters passed into function.
*
* This function erases one flash sector size based on the start address.
*
* @param config The pointer to the storage for the driver runtime state.
* @param start The start address of the desired flash memory to be erased.
* The start address does not need to be sector-aligned but must be word-aligned.
* @param key The value used to validate all flash erase APIs.
*
* @retval #kStatus_FTFx_Success API was executed successfully.
* @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
* @retval #kStatus_FTFx_AlignmentError The parameter is not aligned with the specified baseline.
* @retval #kStatus_FTFx_AddressError The address is out of range.
* @retval #kStatus_FTFx_EraseKeyError The API erase key is invalid.
* @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
*/
status_t FTFx_CMD_EraseSectorNonBlocking(ftfx_config_t *config, uint32_t start, uint32_t key);
/*!
* @brief Erases entire flash
*
* @param config Pointer to the storage for the driver runtime state.
* @param key A value used to validate all flash erase APIs.
*
* @retval #kStatus_FTFx_Success API was executed successfully.
* @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
* @retval #kStatus_FTFx_EraseKeyError API erase key is invalid.
* @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
* @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
* @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
* @retval #kStatus_FTFx_CommandFailure Run-time error during command execution.
* @retval #kStatus_FTFx_PartitionStatusUpdateFailure Failed to update the partition status.
*/
status_t FTFx_CMD_EraseAll(ftfx_config_t *config, uint32_t key);
#if defined(FSL_FEATURE_FLASH_HAS_ERASE_ALL_BLOCKS_UNSECURE_CMD) && FSL_FEATURE_FLASH_HAS_ERASE_ALL_BLOCKS_UNSECURE_CMD
/*!
* @brief Erases the entire flash, including protected sectors.
*
* @param config Pointer to the storage for the driver runtime state.
* @param key A value used to validate all flash erase APIs.
*
* @retval #kStatus_FTFx_Success API was executed successfully.
* @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
* @retval #kStatus_FTFx_EraseKeyError API erase key is invalid.
* @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
* @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
* @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
* @retval #kStatus_FTFx_CommandFailure Run-time error during command execution.
* @retval #kStatus_FTFx_PartitionStatusUpdateFailure Failed to update the partition status.
*/
status_t FTFx_CMD_EraseAllUnsecure(ftfx_config_t *config, uint32_t key);
#endif /* FSL_FEATURE_FLASH_HAS_ERASE_ALL_BLOCKS_UNSECURE_CMD */
/*!
* @brief Erases all program flash execute-only segments defined by the FXACC registers.
*
* @param config Pointer to the storage for the driver runtime state.
* @param key A value used to validate all flash erase APIs.
*
* @retval #kStatus_FTFx_Success API was executed successfully.
* @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
* @retval #kStatus_FTFx_EraseKeyError API erase key is invalid.
* @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
* @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
* @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
* @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
*/
status_t FTFx_CMD_EraseAllExecuteOnlySegments(ftfx_config_t *config, uint32_t key);
/*@}*/
/*!
* @name Programming
* @{
*/
/*!
* @brief Programs flash with data at locations passed in through parameters.
*
* This function programs the flash memory with the desired data for a given
* flash area as determined by the start address and the length.
*
* @param config A pointer to the storage for the driver runtime state.
* @param start The start address of the desired flash memory to be programmed. Must be
* word-aligned.
* @param src A pointer to the source buffer of data that is to be programmed
* into the flash.
* @param lengthInBytes The length, given in bytes (not words or long-words),
* to be programmed. Must be word-aligned.
*
* @retval #kStatus_FTFx_Success API was executed successfully.
* @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
* @retval #kStatus_FTFx_AlignmentError Parameter is not aligned with the specified baseline.
* @retval #kStatus_FTFx_AddressError Address is out of range.
* @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
* @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
* @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
* @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
*/
status_t FTFx_CMD_Program(ftfx_config_t *config, uint32_t start, const uint8_t *src, uint32_t lengthInBytes);
/*!
* @brief Programs Program Once Field through parameters.
*
* This function programs the Program Once Field with the desired data for a given
* flash area as determined by the index and length.
*
* @param config A pointer to the storage for the driver runtime state.
* @param index The index indicating which area of the Program Once Field to be programmed.
* @param src A pointer to the source buffer of data that is to be programmed
* into the Program Once Field.
* @param lengthInBytes The length, given in bytes (not words or long-words),
* to be programmed. Must be word-aligned.
*
* @retval #kStatus_FTFx_Success API was executed successfully.
* @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
* @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
* @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
* @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
* @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
*/
status_t FTFx_CMD_ProgramOnce(ftfx_config_t *config, uint32_t index, const uint8_t *src, uint32_t lengthInBytes);
#if defined(FSL_FEATURE_FLASH_HAS_PROGRAM_SECTION_CMD) && FSL_FEATURE_FLASH_HAS_PROGRAM_SECTION_CMD
/*!
* @brief Programs flash with data at locations passed in through parameters via the Program Section command.
*
* This function programs the flash memory with the desired data for a given
* flash area as determined by the start address and length.
*
* @param config A pointer to the storage for the driver runtime state.
* @param start The start address of the desired flash memory to be programmed. Must be
* word-aligned.
* @param src A pointer to the source buffer of data that is to be programmed
* into the flash.
* @param lengthInBytes The length, given in bytes (not words or long-words),
* to be programmed. Must be word-aligned.
*
* @retval #kStatus_FTFx_Success API was executed successfully.
* @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
* @retval #kStatus_FTFx_AlignmentError Parameter is not aligned with specified baseline.
* @retval #kStatus_FTFx_AddressError Address is out of range.
* @retval #kStatus_FTFx_SetFlexramAsRamError Failed to set flexram as RAM.
* @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
* @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
* @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
* @retval #kStatus_FTFx_CommandFailure Run-time error during command execution.
* @retval #kStatus_FTFx_RecoverFlexramAsEepromError Failed to recover FlexRAM as EEPROM.
*/
status_t FTFx_CMD_ProgramSection(ftfx_config_t *config, uint32_t start, const uint8_t *src, uint32_t lengthInBytes);
#endif /* FSL_FEATURE_FLASH_HAS_PROGRAM_SECTION_CMD */
#if defined(FSL_FEATURE_FLASH_HAS_PROGRAM_PARTITION_CMD) && FSL_FEATURE_FLASH_HAS_PROGRAM_PARTITION_CMD
/*!
* @brief Prepares the FlexNVM block for use as data flash, EEPROM backup, or a combination of both and initializes the
* FlexRAM.
*
* @param config Pointer to storage for the driver runtime state.
* @param option The option used to set FlexRAM load behavior during reset.
* @param eepromDataSizeCode Determines the amount of FlexRAM used in each of the available EEPROM subsystems.
* @param flexnvmPartitionCode Specifies how to split the FlexNVM block between data flash memory and EEPROM backup
* memory supporting EEPROM functions.
*
* @retval #kStatus_FTFx_Success API was executed successfully.
* @retval #kStatus_FTFx_InvalidArgument Invalid argument is provided.
* @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
* @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
* @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
* @retval #kStatus_FTFx_CommandFailure Run-time error during command execution.
*/
status_t FTFx_CMD_ProgramPartition(ftfx_config_t *config,
ftfx_partition_flexram_load_opt_t option,
uint32_t eepromDataSizeCode,
uint32_t flexnvmPartitionCode);
#endif /* FSL_FEATURE_FLASH_HAS_PROGRAM_PARTITION_CMD */
/*@}*/
/*!
* @name Reading
* @{
*/
/*!
* @brief Reads the Program Once Field through parameters.
*
* This function reads the read once feild with given index and length.
*
* @param config A pointer to the storage for the driver runtime state.
* @param index The index indicating the area of program once field to be read.
* @param dst A pointer to the destination buffer of data that is used to store
* data to be read.
* @param lengthInBytes The length, given in bytes (not words or long-words),
* to be programmed. Must be word-aligned.
*
* @retval #kStatus_FTFx_Success API was executed successfully.
* @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
* @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
* @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
* @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
* @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
*/
status_t FTFx_CMD_ReadOnce(ftfx_config_t *config, uint32_t index, uint8_t *dst, uint32_t lengthInBytes);
#if defined(FSL_FEATURE_FLASH_HAS_READ_RESOURCE_CMD) && FSL_FEATURE_FLASH_HAS_READ_RESOURCE_CMD
/*!
* @brief Reads the resource with data at locations passed in through parameters.
*
* This function reads the flash memory with the desired location for a given
* flash area as determined by the start address and length.
*
* @param config A pointer to the storage for the driver runtime state.
* @param start The start address of the desired flash memory to be programmed. Must be
* word-aligned.
* @param dst A pointer to the destination buffer of data that is used to store
* data to be read.
* @param lengthInBytes The length, given in bytes (not words or long-words),
* to be read. Must be word-aligned.
* @param option The resource option which indicates which area should be read back.
*
* @retval #kStatus_FTFx_Success API was executed successfully.
* @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
* @retval #kStatus_FTFx_AlignmentError Parameter is not aligned with the specified baseline.
* @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
* @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
* @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
* @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
*/
status_t FTFx_CMD_ReadResource(
ftfx_config_t *config, uint32_t start, uint8_t *dst, uint32_t lengthInBytes, ftfx_read_resource_opt_t option);
#endif /* FSL_FEATURE_FLASH_HAS_READ_RESOURCE_CMD */
/*@}*/
/*!
* @name Verification
* @{
*/
/*!
* @brief Verifies an erasure of the desired flash area at a specified margin level.
*
* This function checks the appropriate number of flash sectors based on
* the desired start address and length to check whether the flash is erased
* to the specified read margin level.
*
* @param config A pointer to the storage for the driver runtime state.
* @param start The start address of the desired flash memory to be verified.
* The start address does not need to be sector-aligned but must be word-aligned.
* @param lengthInBytes The length, given in bytes (not words or long-words),
* to be verified. Must be word-aligned.
* @param margin Read margin choice.
*
* @retval #kStatus_FTFx_Success API was executed successfully.
* @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
* @retval #kStatus_FTFx_AlignmentError Parameter is not aligned with specified baseline.
* @retval #kStatus_FTFx_AddressError Address is out of range.
* @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
* @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
* @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
* @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
*/
status_t FTFx_CMD_VerifyErase(ftfx_config_t *config,
uint32_t start,
uint32_t lengthInBytes,
ftfx_margin_value_t margin);
/*!
* @brief Verifies erasure of the entire flash at a specified margin level.
*
* This function checks whether the flash is erased to the
* specified read margin level.
*
* @param config A pointer to the storage for the driver runtime state.
* @param margin Read margin choice.
*
* @retval #kStatus_FTFx_Success API was executed successfully.
* @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
* @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
* @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
* @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
* @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
*/
status_t FTFx_CMD_VerifyEraseAll(ftfx_config_t *config, ftfx_margin_value_t margin);
/*!
* @brief Verifies whether the program flash execute-only segments have been erased to
* the specified read margin level.
*
* @param config A pointer to the storage for the driver runtime state.
* @param margin Read margin choice.
*
* @retval #kStatus_FTFx_Success API was executed successfully.
* @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
* @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
* @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
* @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
* @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
*/
status_t FTFx_CMD_VerifyEraseAllExecuteOnlySegments(ftfx_config_t *config, ftfx_margin_value_t margin);
/*!
* @brief Verifies programming of the desired flash area at a specified margin level.
*
* This function verifies the data programed in the flash memory using the
* Flash Program Check Command and compares it to the expected data for a given
* flash area as determined by the start address and length.
*
* @param config A pointer to the storage for the driver runtime state.
* @param start The start address of the desired flash memory to be verified. Must be word-aligned.
* @param lengthInBytes The length, given in bytes (not words or long-words),
* to be verified. Must be word-aligned.
* @param expectedData A pointer to the expected data that is to be
* verified against.
* @param margin Read margin choice.
* @param failedAddress A pointer to the returned failing address.
* @param failedData A pointer to the returned failing data. Some derivatives do
* not include failed data as part of the FCCOBx registers. In this
* case, zeros are returned upon failure.
*
* @retval #kStatus_FTFx_Success API was executed successfully.
* @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
* @retval #kStatus_FTFx_AlignmentError Parameter is not aligned with specified baseline.
* @retval #kStatus_FTFx_AddressError Address is out of range.
* @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
* @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
* @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
* @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
*/
status_t FTFx_CMD_VerifyProgram(ftfx_config_t *config,
uint32_t start,
uint32_t lengthInBytes,
const uint8_t *expectedData,
ftfx_margin_value_t margin,
uint32_t *failedAddress,
uint32_t *failedData);
/*@}*/
/*!
* @name Security
* @{
*/
/*!
* @brief Returns the security state via the pointer passed into the function.
*
* This function retrieves the current flash security status, including the
* security enabling state and the backdoor key enabling state.
*
* @param config A pointer to storage for the driver runtime state.
* @param state A pointer to the value returned for the current security status code:
*
* @retval #kStatus_FTFx_Success API was executed successfully.
* @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
*/
status_t FTFx_REG_GetSecurityState(ftfx_config_t *config, ftfx_security_state_t *state);
/*!
* @brief Allows users to bypass security with a backdoor key.
*
* If the MCU is in secured state, this function unsecures the MCU by
* comparing the provided backdoor key with ones in the flash configuration
* field.
*
* @param config A pointer to the storage for the driver runtime state.
* @param backdoorKey A pointer to the user buffer containing the backdoor key.
*
* @retval #kStatus_FTFx_Success API was executed successfully.
* @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
* @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
* @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
* @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
* @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
*/
status_t FTFx_CMD_SecurityBypass(ftfx_config_t *config, const uint8_t *backdoorKey);
/*@}*/
/*!
* @name FlexRAM
* @{
*/
#if defined(FSL_FEATURE_FLASH_HAS_SET_FLEXRAM_FUNCTION_CMD) && FSL_FEATURE_FLASH_HAS_SET_FLEXRAM_FUNCTION_CMD
/*!
* @brief Sets the FlexRAM function command.
*
* @param config A pointer to the storage for the driver runtime state.
* @param option The option used to set the work mode of FlexRAM.
*
* @retval #kStatus_FTFx_Success API was executed successfully.
* @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
* @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
* @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
* @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
* @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
*/
status_t FTFx_CMD_SetFlexramFunction(ftfx_config_t *config, ftfx_flexram_func_opt_t option);
#endif /* FSL_FEATURE_FLASH_HAS_SET_FLEXRAM_FUNCTION_CMD */
/*@}*/
/*!
* @name Swap
* @{
*/
#if defined(FSL_FEATURE_FLASH_HAS_SWAP_CONTROL_CMD) && FSL_FEATURE_FLASH_HAS_SWAP_CONTROL_CMD
/*!
* @brief Configures the Swap function or checks the swap state of the Flash module.
*
* @param config A pointer to the storage for the driver runtime state.
* @param address Address used to configure the flash Swap function.
* @param option The possible option used to configure Flash Swap function or check the flash Swap status
* @param returnInfo A pointer to the data which is used to return the information of flash Swap.
*
* @retval #kStatus_FTFx_Success API was executed successfully.
* @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
* @retval #kStatus_FTFx_AlignmentError Parameter is not aligned with specified baseline.
* @retval #kStatus_FTFx_SwapIndicatorAddressError Swap indicator address is invalid.
* @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
* @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
* @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
* @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
*/
status_t FTFx_CMD_SwapControl(ftfx_config_t *config,
uint32_t address,
ftfx_swap_control_opt_t option,
ftfx_swap_state_config_t *returnInfo);
#endif /* FSL_FEATURE_FLASH_HAS_SWAP_CONTROL_CMD */
/*@}*/
#if defined(__cplusplus)
}
#endif
/*! @}*/
#endif /* FSL_FTFX_CONTROLLER_H */

@ -0,0 +1,90 @@
/*
* Copyright 2017-2019 NXP
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
*/
#ifndef FSL_FTFX_FEATURES_H
#define FSL_FTFX_FEATURES_H
#if (defined(BL_TARGET_FLASH) || defined(BL_TARGET_ROM) || defined(BL_TARGET_RAM))
#include <assert.h>
#include <string.h>
#include "fsl_device_registers.h"
#include "bootloader_common.h"
#else
#include "fsl_common.h"
#endif
#include "fsl_ftfx_adapter.h"
/*!
* @addtogroup ftfx_feature
* @{
*/
/*******************************************************************************
* Definitions
******************************************************************************/
/*!
* @name FTFx configuration
* @{
*/
/*! @brief Flash driver location. */
#if !defined(FTFx_DRIVER_IS_FLASH_RESIDENT)
#if (!defined(BL_TARGET_ROM) && !defined(BL_TARGET_RAM))
#define FTFx_DRIVER_IS_FLASH_RESIDENT 1U /*!< Used for the flash resident application. */
#else
#define FTFx_DRIVER_IS_FLASH_RESIDENT 0U /*!< Used for the non-flash resident application. */
#endif
#endif
/*! @brief Flash Driver Export option */
#if !defined(FTFx_DRIVER_IS_EXPORTED)
#if defined(BL_TARGET_ROM)
#define FTFx_DRIVER_IS_EXPORTED 1U /*!< Used for the ROM bootloader. */
#else
#define FTFx_DRIVER_IS_EXPORTED 0U /*!< Used for the MCUXpresso SDK application. */
#endif
#endif
/*@}*/
/*! @brief Indicates whether the secondary flash is supported in the Flash driver */
#if defined(FSL_FEATURE_FLASH_HAS_MULTIPLE_FLASH) || defined(FSL_FEATURE_FLASH_PFLASH_1_START_ADDRESS)
#define FTFx_DRIVER_HAS_FLASH1_SUPPORT (1U)
#define FTFx_FLASH_COUNT (2U)
#else
#define FTFx_DRIVER_HAS_FLASH1_SUPPORT (0U)
#define FTFx_FLASH_COUNT (1U)
#endif
/*!
* @name Secondary flash configuration
* @{
*/
/*! @brief Indicates whether the secondary flash has its own protection register in flash module. */
#if defined(FSL_FEATURE_FLASH_HAS_MULTIPLE_FLASH) && defined(FTFE_FPROTS_PROTS_MASK)
#define FTFx_FLASH1_HAS_PROT_CONTROL (1U)
#else
#define FTFx_FLASH1_HAS_PROT_CONTROL (0U)
#endif
/*! @brief Indicates whether the secondary flash has its own Execute-Only access register in flash module. */
#if defined(FSL_FEATURE_FLASH_HAS_MULTIPLE_FLASH) && defined(FTFE_FACSSS_SGSIZE_S_MASK)
#define FTFx_FLASH1_HAS_XACC_CONTROL (1U)
#else
#define FTFx_FLASH1_HAS_XACC_CONTROL (0U)
#endif
/*@}*/
#if FTFx_FLASH1_HAS_XACC_CONTROL || FTFx_FLASH1_HAS_PROT_CONTROL
#define FTFx_FLASH1_IS_INDEPENDENT_BLOCK (1U)
#else
#define FTFx_FLASH1_IS_INDEPENDENT_BLOCK (0U)
#endif
/*! @}*/
#endif /* FSL_FTFX_FEATURES_H */

File diff suppressed because it is too large Load Diff

@ -0,0 +1,705 @@
/*
* Copyright 2013-2016 Freescale Semiconductor, Inc.
* Copyright 2016-2020 NXP
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
*/
#ifndef FSL_FTFX_FLASH_H
#define FSL_FTFX_FLASH_H
#include "fsl_ftfx_controller.h"
/*!
* @addtogroup ftfx_flash_driver
* @{
*/
/*******************************************************************************
* Definitions
******************************************************************************/
#define kStatus_FLASH_Success kStatus_FTFx_Success
#define kFLASH_ApiEraseKey kFTFx_ApiEraseKey
/*!
* @name Flash version
* @{
*/
/*! @brief Flash driver version for SDK*/
#define FSL_FLASH_DRIVER_VERSION (MAKE_VERSION(3U, 1U, 2U)) /*!< Version 3.1.2. */
/*! @brief Flash driver version for ROM*/
#define FSL_FLASH_DRIVER_VERSION_ROM (MAKE_VERSION(3U, 0U, 0U)) /*!< Version 3.0.0. */
/*@}*/
/*!
* @brief Enumeration for the three possible flash protection levels.
*/
typedef enum _flash_protection_state
{
kFLASH_ProtectionStateUnprotected, /*!< Flash region is not protected.*/
kFLASH_ProtectionStateProtected, /*!< Flash region is protected.*/
kFLASH_ProtectionStateMixed /*!< Flash is mixed with protected and unprotected region.*/
} flash_prot_state_t;
/*!
* @brief PFlash protection status
*/
typedef union _pflash_protection_status
{
uint32_t protl; /*!< PROT[31:0] .*/
uint32_t proth; /*!< PROT[63:32].*/
uint8_t protsl; /*!< PROTS[7:0] .*/
uint8_t protsh; /*!< PROTS[15:8] .*/
uint8_t reserved[2];
} pflash_prot_status_t;
#if defined(FSL_FEATURE_FLASH_HAS_ACCESS_CONTROL) && FSL_FEATURE_FLASH_HAS_ACCESS_CONTROL
/*!
* @brief Enumeration for the three possible flash execute access levels.
*/
typedef enum _flash_execute_only_access_state
{
kFLASH_AccessStateUnLimited, /*!< Flash region is unlimited.*/
kFLASH_AccessStateExecuteOnly, /*!< Flash region is execute only.*/
kFLASH_AccessStateMixed /*!< Flash is mixed with unlimited and execute only region.*/
} flash_xacc_state_t;
#endif /* not define FSL_FEATURE_FLASH_HAS_ACCESS_CONTROL */
/*!
* @brief Enumeration for various flash properties.
*/
typedef enum _flash_property_tag
{
kFLASH_PropertyPflash0SectorSize = 0x00U, /*!< Pflash sector size property.*/
kFLASH_PropertyPflash0TotalSize = 0x01U, /*!< Pflash total size property.*/
kFLASH_PropertyPflash0BlockSize = 0x02U, /*!< Pflash block size property.*/
kFLASH_PropertyPflash0BlockCount = 0x03U, /*!< Pflash block count property.*/
kFLASH_PropertyPflash0BlockBaseAddr = 0x04U, /*!< Pflash block base address property.*/
kFLASH_PropertyPflash0FacSupport = 0x05U, /*!< Pflash fac support property.*/
kFLASH_PropertyPflash0AccessSegmentSize = 0x06U, /*!< Pflash access segment size property.*/
kFLASH_PropertyPflash0AccessSegmentCount = 0x07U, /*!< Pflash access segment count property.*/
kFLASH_PropertyPflash1SectorSize = 0x10U, /*!< Pflash sector size property.*/
kFLASH_PropertyPflash1TotalSize = 0x11U, /*!< Pflash total size property.*/
kFLASH_PropertyPflash1BlockSize = 0x12U, /*!< Pflash block size property.*/
kFLASH_PropertyPflash1BlockCount = 0x13U, /*!< Pflash block count property.*/
kFLASH_PropertyPflash1BlockBaseAddr = 0x14U, /*!< Pflash block base address property.*/
kFLASH_PropertyPflash1FacSupport = 0x15U, /*!< Pflash fac support property.*/
kFLASH_PropertyPflash1AccessSegmentSize = 0x16U, /*!< Pflash access segment size property.*/
kFLASH_PropertyPflash1AccessSegmentCount = 0x17U, /*!< Pflash access segment count property.*/
kFLASH_PropertyFlexRamBlockBaseAddr = 0x20U, /*!< FlexRam block base address property.*/
kFLASH_PropertyFlexRamTotalSize = 0x21U, /*!< FlexRam total size property.*/
} flash_property_tag_t;
/*! @brief Flash driver state information.
*
* An instance of this structure is allocated by the user of the flash driver and
* passed into each of the driver APIs.
*/
typedef struct _flash_config
{
ftfx_config_t ftfxConfig[FTFx_FLASH_COUNT];
} flash_config_t;
/*******************************************************************************
* API
******************************************************************************/
#if defined(__cplusplus)
extern "C" {
#endif
/*!
* @name Initialization
* @{
*/
/*!
* @brief Initializes the global flash properties structure members.
*
* This function checks and initializes the Flash module for the other Flash APIs.
*
* @param config Pointer to the storage for the driver runtime state.
*
* @retval #kStatus_FTFx_Success API was executed successfully.
* @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
* @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
* @retval #kStatus_FTFx_PartitionStatusUpdateFailure Failed to update the partition status.
*/
status_t FLASH_Init(flash_config_t *config);
/*@}*/
/*!
* @name Erasing
* @{
*/
/*!
* @brief Erases the Dflash sectors encompassed by parameters passed into function.
*
* This function erases the appropriate number of flash sectors based on the
* desired start address and length.
*
* @param config The pointer to the storage for the driver runtime state.
* @param start The start address of the desired flash memory to be erased.
* The start address does not need to be sector-aligned but must be word-aligned.
* @param lengthInBytes The length, given in bytes (not words or long-words)
* to be erased. Must be word-aligned.
* @param key The value used to validate all flash erase APIs.
*
* @retval #kStatus_FTFx_Success API was executed successfully; the appropriate number of flash sectors based on the
* desired start address and length were erased successfully.
*
* @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
* @retval #kStatus_FTFx_AlignmentError The parameter is not aligned with the specified baseline.
* @retval #kStatus_FTFx_AddressError The address is out of range.
* @retval #kStatus_FTFx_EraseKeyError The API erase key is invalid.
* @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
* @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
* @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
* @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
*/
status_t FLASH_Erase(flash_config_t *config, uint32_t start, uint32_t lengthInBytes, uint32_t key);
/*!
* @brief Erases the Dflash sectors encompassed by parameters passed into function.
*
* This function erases one flash sector size based on the start address, and it is
* executed asynchronously.
*
* NOTE: This function can only erase one flash sector at a time, and the other commands
* can be executed after the previous command has been completed.
*
* @param config The pointer to the storage for the driver runtime state.
* @param start The start address of the desired flash memory to be erased.
* The start address does not need to be sector-aligned but must be word-aligned.
* @param key The value used to validate all flash erase APIs.
*
* @retval #kStatus_FTFx_Success API was executed successfully.
* @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
* @retval #kStatus_FTFx_AlignmentError The parameter is not aligned with the specified baseline.
* @retval #kStatus_FTFx_AddressError The address is out of range.
* @retval #kStatus_FTFx_EraseKeyError The API erase key is invalid.
*/
status_t FLASH_EraseSectorNonBlocking(flash_config_t *config, uint32_t start, uint32_t key);
/*!
* @brief Erases entire flexnvm
*
* @param config Pointer to the storage for the driver runtime state.
* @param key A value used to validate all flash erase APIs.
*
* @retval #kStatus_FTFx_Success API was executed successfully; the all pflash and flexnvm were erased successfully,
* the swap and eeprom have been reset to unconfigured state.
*
* @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
* @retval #kStatus_FTFx_EraseKeyError API erase key is invalid.
* @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
* @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
* @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
* @retval #kStatus_FTFx_CommandFailure Run-time error during command execution.
* @retval #kStatus_FTFx_PartitionStatusUpdateFailure Failed to update the partition status.
*/
status_t FLASH_EraseAll(flash_config_t *config, uint32_t key);
#if defined(FSL_FEATURE_FLASH_HAS_ERASE_ALL_BLOCKS_UNSECURE_CMD) && FSL_FEATURE_FLASH_HAS_ERASE_ALL_BLOCKS_UNSECURE_CMD
/*!
* @brief Erases the entire flexnvm, including protected sectors.
*
* @param config Pointer to the storage for the driver runtime state.
* @param key A value used to validate all flash erase APIs.
*
* @retval #kStatus_FTFx_Success API was executed successfully;
* the protected sectors of flash were reset to unprotected status.
*
* @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
* @retval #kStatus_FTFx_EraseKeyError API erase key is invalid.
* @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
* @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
* @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
* @retval #kStatus_FTFx_CommandFailure Run-time error during command execution.
* @retval #kStatus_FTFx_PartitionStatusUpdateFailure Failed to update the partition status.
*/
status_t FLASH_EraseAllUnsecure(flash_config_t *config, uint32_t key);
#endif /* FSL_FEATURE_FLASH_HAS_ERASE_ALL_BLOCKS_UNSECURE_CMD */
/*@}*/
/*!
* @name Programming
* @{
*/
/*!
* @brief Programs flash with data at locations passed in through parameters.
*
* This function programs the flash memory with the desired data for a given
* flash area as determined by the start address and the length.
*
* @param config A pointer to the storage for the driver runtime state.
* @param start The start address of the desired flash memory to be programmed. Must be
* word-aligned.
* @param src A pointer to the source buffer of data that is to be programmed
* into the flash.
* @param lengthInBytes The length, given in bytes (not words or long-words),
* to be programmed. Must be word-aligned.
*
* @retval #kStatus_FTFx_Success API was executed successfully; the desired data were programed successfully
* into flash based on desired start address and length.
*
* @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
* @retval #kStatus_FTFx_AlignmentError Parameter is not aligned with the specified baseline.
* @retval #kStatus_FTFx_AddressError Address is out of range.
* @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
* @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
* @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
* @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
*/
status_t FLASH_Program(flash_config_t *config, uint32_t start, uint8_t *src, uint32_t lengthInBytes);
/*!
* @brief Program the Program-Once-Field through parameters.
*
* This function Program the Program-once-feild with given index and length.
*
* @param config A pointer to the storage for the driver runtime state.
* @param index The index indicating the area of program once field to be read.
* @param src A pointer to the source buffer of data that is used to store
* data to be write.
* @param lengthInBytes The length, given in bytes (not words or long-words),
* to be programmed. Must be word-aligned.
*
* @retval #kStatus_FTFx_Success API was executed successfully; The index indicating the area
* of program once field was programed successfully.
*
* @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
* @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
* @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
* @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
* @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
*/
status_t FLASH_ProgramOnce(flash_config_t *config, uint32_t index, uint8_t *src, uint32_t lengthInBytes);
#if defined(FSL_FEATURE_FLASH_HAS_PROGRAM_SECTION_CMD) && FSL_FEATURE_FLASH_HAS_PROGRAM_SECTION_CMD
/*!
* @brief Programs flash with data at locations passed in through parameters via the Program Section command.
*
* This function programs the flash memory with the desired data for a given
* flash area as determined by the start address and length.
*
* @param config A pointer to the storage for the driver runtime state.
* @param start The start address of the desired flash memory to be programmed. Must be
* word-aligned.
* @param src A pointer to the source buffer of data that is to be programmed
* into the flash.
* @param lengthInBytes The length, given in bytes (not words or long-words),
* to be programmed. Must be word-aligned.
*
* @retval #kStatus_FTFx_Success API was executed successfully; the desired data have been programed successfully into
* flash based on start address and length.
*
* @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
* @retval #kStatus_FTFx_AlignmentError Parameter is not aligned with specified baseline.
* @retval #kStatus_FTFx_AddressError Address is out of range.
* @retval #kStatus_FTFx_SetFlexramAsRamError Failed to set flexram as RAM.
* @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
* @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
* @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
* @retval #kStatus_FTFx_CommandFailure Run-time error during command execution.
* @retval #kStatus_FTFx_RecoverFlexramAsEepromError Failed to recover FlexRAM as EEPROM.
*/
status_t FLASH_ProgramSection(flash_config_t *config, uint32_t start, uint8_t *src, uint32_t lengthInBytes);
#endif /* FSL_FEATURE_FLASH_HAS_PROGRAM_SECTION_CMD */
/*@}*/
/*!
* @name Reading
* @{
*/
#if defined(FSL_FEATURE_FLASH_HAS_READ_RESOURCE_CMD) && FSL_FEATURE_FLASH_HAS_READ_RESOURCE_CMD
/*!
* @brief Reads the resource with data at locations passed in through parameters.
*
* This function reads the flash memory with the desired location for a given
* flash area as determined by the start address and length.
*
* @param config A pointer to the storage for the driver runtime state.
* @param start The start address of the desired flash memory to be programmed. Must be
* word-aligned.
* @param dst A pointer to the destination buffer of data that is used to store
* data to be read.
* @param lengthInBytes The length, given in bytes (not words or long-words),
* to be read. Must be word-aligned.
* @param option The resource option which indicates which area should be read back.
*
* @retval #kStatus_FTFx_Success API was executed successfully; the data have been read successfully from
* program flash IFR, data flash IFR space, and the Version ID field.
*
* @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
* @retval #kStatus_FTFx_AlignmentError Parameter is not aligned with the specified baseline.
* @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
* @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
* @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
* @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
*/
status_t FLASH_ReadResource(
flash_config_t *config, uint32_t start, uint8_t *dst, uint32_t lengthInBytes, ftfx_read_resource_opt_t option);
#endif /* FSL_FEATURE_FLASH_HAS_READ_RESOURCE_CMD */
/*!
* @brief Reads the Program Once Field through parameters.
*
* This function reads the read once feild with given index and length.
*
* @param config A pointer to the storage for the driver runtime state.
* @param index The index indicating the area of program once field to be read.
* @param dst A pointer to the destination buffer of data that is used to store
* data to be read.
* @param lengthInBytes The length, given in bytes (not words or long-words),
* to be programmed. Must be word-aligned.
*
* @retval #kStatus_FTFx_Success API was executed successfully; the data have been successfuly
* read form Program flash0 IFR map and Program Once field based on index and length.
* @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
* @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
* @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
* @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
* @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
*/
status_t FLASH_ReadOnce(flash_config_t *config, uint32_t index, uint8_t *dst, uint32_t lengthInBytes);
/*@}*/
/*!
* @name Verification
* @{
*/
/*!
* @brief Verifies an erasure of the desired flash area at a specified margin level.
*
* This function checks the appropriate number of flash sectors based on
* the desired start address and length to check whether the flash is erased
* to the specified read margin level.
*
* @param config A pointer to the storage for the driver runtime state.
* @param start The start address of the desired flash memory to be verified.
* The start address does not need to be sector-aligned but must be word-aligned.
* @param lengthInBytes The length, given in bytes (not words or long-words),
* to be verified. Must be word-aligned.
* @param margin Read margin choice.
*
* @retval #kStatus_FTFx_Success API was executed successfully; the specified FLASH region has been erased.
*
* @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
* @retval #kStatus_FTFx_AlignmentError Parameter is not aligned with specified baseline.
* @retval #kStatus_FTFx_AddressError Address is out of range.
* @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
* @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
* @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
* @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
*/
status_t FLASH_VerifyErase(flash_config_t *config, uint32_t start, uint32_t lengthInBytes, ftfx_margin_value_t margin);
/*!
* @brief Verifies erasure of the entire flash at a specified margin level.
*
* This function checks whether the flash is erased to the
* specified read margin level.
*
* @param config A pointer to the storage for the driver runtime state.
* @param margin Read margin choice.
*
* @retval #kStatus_FTFx_Success API was executed successfully; all program flash and flexnvm were in erased state.
*
* @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
* @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
* @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
* @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
* @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
*/
status_t FLASH_VerifyEraseAll(flash_config_t *config, ftfx_margin_value_t margin);
/*!
* @brief Verifies programming of the desired flash area at a specified margin level.
*
* This function verifies the data programmed in the flash memory using the
* Flash Program Check Command and compares it to the expected data for a given
* flash area as determined by the start address and length.
*
* @param config A pointer to the storage for the driver runtime state.
* @param start The start address of the desired flash memory to be verified. Must be word-aligned.
* @param lengthInBytes The length, given in bytes (not words or long-words),
* to be verified. Must be word-aligned.
* @param expectedData A pointer to the expected data that is to be
* verified against.
* @param margin Read margin choice.
* @param failedAddress A pointer to the returned failing address.
* @param failedData A pointer to the returned failing data. Some derivatives do
* not include failed data as part of the FCCOBx registers. In this
* case, zeros are returned upon failure.
*
* @retval #kStatus_FTFx_Success API was executed successfully; the desired data have been successfully programed into
* specified FLASH region.
*
* @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
* @retval #kStatus_FTFx_AlignmentError Parameter is not aligned with specified baseline.
* @retval #kStatus_FTFx_AddressError Address is out of range.
* @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
* @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
* @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
* @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
*/
status_t FLASH_VerifyProgram(flash_config_t *config,
uint32_t start,
uint32_t lengthInBytes,
const uint8_t *expectedData,
ftfx_margin_value_t margin,
uint32_t *failedAddress,
uint32_t *failedData);
/*@}*/
/*!
* @name Security
* @{
*/
/*!
* @brief Returns the security state via the pointer passed into the function.
*
* This function retrieves the current flash security status, including the
* security enabling state and the backdoor key enabling state.
*
* @param config A pointer to storage for the driver runtime state.
* @param state A pointer to the value returned for the current security status code:
*
* @retval #kStatus_FTFx_Success API was executed successfully; the security state of flash was stored to state.
* @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
*/
status_t FLASH_GetSecurityState(flash_config_t *config, ftfx_security_state_t *state);
/*!
* @brief Allows users to bypass security with a backdoor key.
*
* If the MCU is in secured state, this function unsecures the MCU by
* comparing the provided backdoor key with ones in the flash configuration
* field.
*
* @param config A pointer to the storage for the driver runtime state.
* @param backdoorKey A pointer to the user buffer containing the backdoor key.
*
* @retval #kStatus_FTFx_Success API was executed successfully.
* @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
* @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
* @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
* @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
* @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
*/
status_t FLASH_SecurityBypass(flash_config_t *config, const uint8_t *backdoorKey);
/*@}*/
/*!
* @name FlexRAM
* @{
*/
#if defined(FSL_FEATURE_FLASH_HAS_SET_FLEXRAM_FUNCTION_CMD) && FSL_FEATURE_FLASH_HAS_SET_FLEXRAM_FUNCTION_CMD
/*!
* @brief Sets the FlexRAM function command.
*
* @param config A pointer to the storage for the driver runtime state.
* @param option The option used to set the work mode of FlexRAM.
*
* @retval #kStatus_FTFx_Success API was executed successfully; the FlexRAM has been successfully configured as RAM or
* EEPROM.
* @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
* @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
* @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
* @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
* @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
*/
status_t FLASH_SetFlexramFunction(flash_config_t *config, ftfx_flexram_func_opt_t option);
#endif /* FSL_FEATURE_FLASH_HAS_SET_FLEXRAM_FUNCTION_CMD */
/*@}*/
/*!
* @name Swap
* @{
*/
#if defined(FSL_FEATURE_FLASH_HAS_PFLASH_BLOCK_SWAP) && FSL_FEATURE_FLASH_HAS_PFLASH_BLOCK_SWAP
/*!
* @brief Swaps the lower half flash with the higher half flash.
*
* @param config A pointer to the storage for the driver runtime state.
* @param address Address used to configure the flash swap function
* @param isSetEnable The possible option used to configure the Flash Swap function or check the flash Swap status.
*
* @retval #kStatus_FTFx_Success API was executed successfully; the lower half flash and higher half flash have been
* swaped.
* @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
* @retval #kStatus_FTFx_AlignmentError Parameter is not aligned with specified baseline.
* @retval #kStatus_FTFx_SwapIndicatorAddressError Swap indicator address is invalid.
* @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
* @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
* @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
* @retval #kStatus_FTFx_CommandFailure Run-time error during command execution.
* @retval #kStatus_FTFx_SwapSystemNotInUninitialized Swap system is not in an uninitialized state.
*/
status_t FLASH_Swap(flash_config_t *config, uint32_t address, bool isSetEnable);
#endif /* FSL_FEATURE_FLASH_HAS_PFLASH_BLOCK_SWAP */
/*@}*/
/*!
* @name Protection
* @{
*/
/*!
* @brief Returns the protection state of the desired flash area via the pointer passed into the function.
*
* This function retrieves the current flash protect status for a given
* flash area as determined by the start address and length.
*
* @param config A pointer to the storage for the driver runtime state.
* @param start The start address of the desired flash memory to be checked. Must be word-aligned.
* @param lengthInBytes The length, given in bytes (not words or long-words)
* to be checked. Must be word-aligned.
* @param protection_state A pointer to the value returned for the current
* protection status code for the desired flash area.
*
* @retval #kStatus_FTFx_Success API was executed successfully; the protection state of specified FLASH region was
* stored to protection_state.
*
* @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
* @retval #kStatus_FTFx_AlignmentError Parameter is not aligned with specified baseline.
* @retval #kStatus_FTFx_AddressError The address is out of range.
*/
status_t FLASH_IsProtected(flash_config_t *config,
uint32_t start,
uint32_t lengthInBytes,
flash_prot_state_t *protection_state);
#if defined(FSL_FEATURE_FLASH_HAS_ACCESS_CONTROL) && FSL_FEATURE_FLASH_HAS_ACCESS_CONTROL
/*!
* @brief Returns the access state of the desired flash area via the pointer passed into the function.
*
* This function retrieves the current flash access status for a given
* flash area as determined by the start address and length.
*
* @param config A pointer to the storage for the driver runtime state.
* @param start The start address of the desired flash memory to be checked. Must be word-aligned.
* @param lengthInBytes The length, given in bytes (not words or long-words),
* to be checked. Must be word-aligned.
* @param access_state A pointer to the value returned for the current
* access status code for the desired flash area.
*
* @retval #kStatus_FTFx_Success API was executed successfully; the executeOnly state of specified FLASH region was
* stored to access_state.
*
* @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
* @retval #kStatus_FTFx_AlignmentError The parameter is not aligned to the specified baseline.
* @retval #kStatus_FTFx_AddressError The address is out of range.
*/
status_t FLASH_IsExecuteOnly(flash_config_t *config,
uint32_t start,
uint32_t lengthInBytes,
flash_xacc_state_t *access_state);
#endif /* FSL_FEATURE_FLASH_HAS_ACCESS_CONTROL */
/*!
* @brief Sets the PFlash Protection to the intended protection status.
*
* @param config A pointer to storage for the driver runtime state.
* @param protectStatus The expected protect status to set to the PFlash protection register. Each bit is
* corresponding to protection of 1/32(64) of the total PFlash. The least significant bit is corresponding to the lowest
* address area of PFlash. The most significant bit is corresponding to the highest address area of PFlash. There are
* two possible cases as shown below:
* 0: this area is protected.
* 1: this area is unprotected.
*
* @retval #kStatus_FTFx_Success API was executed successfully; the specified FLASH region is protected.
* @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
* @retval #kStatus_FTFx_CommandFailure Run-time error during command execution.
*/
status_t FLASH_PflashSetProtection(flash_config_t *config, pflash_prot_status_t *protectStatus);
/*!
* @brief Gets the PFlash protection status.
*
* @param config A pointer to the storage for the driver runtime state.
* @param protectStatus Protect status returned by the PFlash IP. Each bit is corresponding to the protection of
* 1/32(64)
* of the
* total PFlash. The least significant bit corresponds to the lowest address area of the PFlash. The most significant
* bit corresponds to the highest address area of PFlash. There are two possible cases as shown below:
* 0: this area is protected.
* 1: this area is unprotected.
*
* @retval #kStatus_FTFx_Success API was executed successfully; the Protection state was stored to protectStatus;
* @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
*/
status_t FLASH_PflashGetProtection(flash_config_t *config, pflash_prot_status_t *protectStatus);
/*@}*/
/*!
* @name Properties
* @{
*/
/*!
* @brief Returns the desired flash property.
*
* @param config A pointer to the storage for the driver runtime state.
* @param whichProperty The desired property from the list of properties in
* enum flash_property_tag_t
* @param value A pointer to the value returned for the desired flash property.
*
* @retval #kStatus_FTFx_Success API was executed successfully; the flash property was stored to value.
* @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
* @retval #kStatus_FTFx_UnknownProperty An unknown property tag.
*/
status_t FLASH_GetProperty(flash_config_t *config, flash_property_tag_t whichProperty, uint32_t *value);
/*@}*/
/*!
* @name commantStatus
* @{
*/
/*!
* @brief Get previous command status.
*
* This function is used to obtain the execution status of the previous command.
*
* @retval #kStatus_FTFx_Success The previous command is executed successfully.
* @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
* @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
* @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
* @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
*/
status_t FLASH_GetCommandState(void);
/*@}*/
#if defined(__cplusplus)
}
#endif
/*! @}*/
#endif /* FSL_FTFX_FLASH_H */

@ -0,0 +1,511 @@
/*
* Copyright 2013-2016 Freescale Semiconductor, Inc.
* Copyright 2016-2020 NXP
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
*/
#include "fsl_ftfx_flexnvm.h"
#if FSL_FEATURE_FLASH_HAS_FLEX_NVM
/*******************************************************************************
* Definitions
******************************************************************************/
/* Component ID definition, used by tools. */
#ifndef FSL_COMPONENT_ID
#define FSL_COMPONENT_ID "platform.drivers.flash"
#endif
/*******************************************************************************
* Prototypes
******************************************************************************/
/*! @brief Convert address for Flexnvm dflash.*/
static status_t flexnvm_convert_start_address(flexnvm_config_t *config, uint32_t start);
/*******************************************************************************
* Variables
******************************************************************************/
/*******************************************************************************
* Code
******************************************************************************/
status_t FLEXNVM_Init(flexnvm_config_t *config)
{
status_t returnCode;
if (config == NULL)
{
return kStatus_FTFx_InvalidArgument;
}
config->ftfxConfig.flashDesc.type = (uint8_t)kFTFx_MemTypeFlexnvm;
config->ftfxConfig.flashDesc.index = 0U;
/* Set Flexnvm memory operation parameters */
config->ftfxConfig.opsConfig.addrAligment.blockWriteUnitSize = FSL_FEATURE_FLASH_FLEX_NVM_BLOCK_WRITE_UNIT_SIZE;
config->ftfxConfig.opsConfig.addrAligment.sectorCmd = FSL_FEATURE_FLASH_FLEX_NVM_SECTOR_CMD_ADDRESS_ALIGMENT;
config->ftfxConfig.opsConfig.addrAligment.sectionCmd = FSL_FEATURE_FLASH_FLEX_NVM_SECTION_CMD_ADDRESS_ALIGMENT;
config->ftfxConfig.opsConfig.addrAligment.resourceCmd = FSL_FEATURE_FLASH_FLEX_NVM_RESOURCE_CMD_ADDRESS_ALIGMENT;
config->ftfxConfig.opsConfig.addrAligment.checkCmd = FSL_FEATURE_FLASH_FLEX_NVM_CHECK_CMD_ADDRESS_ALIGMENT;
/* Set Flexnvm memory properties */
config->ftfxConfig.flashDesc.blockBase = FSL_FEATURE_FLASH_FLEX_NVM_START_ADDRESS;
#if defined(FSL_FEATURE_FLASH_HAS_FLEX_NVM_ALIAS) && FSL_FEATURE_FLASH_HAS_FLEX_NVM_ALIAS
config->ftfxConfig.flashDesc.aliasBlockBase = FSL_FEATURE_FLASH_FLEX_NVM_ALIAS_START_ADDRESS;
#endif
config->ftfxConfig.flashDesc.sectorSize = FSL_FEATURE_FLASH_FLEX_NVM_BLOCK_SECTOR_SIZE;
config->ftfxConfig.flashDesc.blockCount = FSL_FEATURE_FLASH_FLEX_NVM_BLOCK_COUNT;
/* Init FTFx Kernel */
FTFx_API_Init(&config->ftfxConfig);
returnCode = FTFx_API_UpdateFlexnvmPartitionStatus(&config->ftfxConfig);
if (returnCode != kStatus_FTFx_Success)
{
return returnCode;
}
return kStatus_FTFx_Success;
}
/*!
* @brief Erases the Dflash sectors encompassed by parameters passed into function.
*/
status_t FLEXNVM_DflashErase(flexnvm_config_t *config, uint32_t start, uint32_t lengthInBytes, uint32_t key)
{
status_t returnCode;
returnCode = flexnvm_convert_start_address(config, start);
if (returnCode != kStatus_FTFx_Success)
{
return returnCode;
}
return FTFx_CMD_Erase(&config->ftfxConfig, start, lengthInBytes, key);
}
/*!
* @brief Erases entire flexnvm
*/
status_t FLEXNVM_EraseAll(flexnvm_config_t *config, uint32_t key)
{
return FTFx_CMD_EraseAll(&config->ftfxConfig, key);
}
#if defined(FSL_FEATURE_FLASH_HAS_ERASE_ALL_BLOCKS_UNSECURE_CMD) && FSL_FEATURE_FLASH_HAS_ERASE_ALL_BLOCKS_UNSECURE_CMD
/*!
* @brief Erases the entire flexnvm, including protected sectors.
*/
status_t FLEXNVM_EraseAllUnsecure(flexnvm_config_t *config, uint32_t key)
{
return FTFx_CMD_EraseAllUnsecure(&config->ftfxConfig, key);
}
#endif /* FSL_FEATURE_FLASH_HAS_ERASE_ALL_BLOCKS_UNSECURE_CMD */
/*!
* @brief Programs flash with data at locations passed in through parameters.
*/
status_t FLEXNVM_DflashProgram(flexnvm_config_t *config, uint32_t start, uint8_t *src, uint32_t lengthInBytes)
{
status_t returnCode;
returnCode = flexnvm_convert_start_address(config, start);
if (returnCode != kStatus_FTFx_Success)
{
return returnCode;
}
return FTFx_CMD_Program(&config->ftfxConfig, start, src, lengthInBytes);
}
#if defined(FSL_FEATURE_FLASH_HAS_PROGRAM_SECTION_CMD) && FSL_FEATURE_FLASH_HAS_PROGRAM_SECTION_CMD
/*!
* @brief Programs flash with data at locations passed in through parameters via the Program Section command.
*/
status_t FLEXNVM_DflashProgramSection(flexnvm_config_t *config, uint32_t start, uint8_t *src, uint32_t lengthInBytes)
{
status_t returnCode;
/* Convert address for Flexnvm dflash */
returnCode = flexnvm_convert_start_address(config, start);
if (returnCode != kStatus_FTFx_Success)
{
return returnCode;
}
return FTFx_CMD_ProgramSection(&config->ftfxConfig, start, src, lengthInBytes);
}
#endif /* FSL_FEATURE_FLASH_HAS_PROGRAM_SECTION_CMD */
/*!
* @brief Prepares the FlexNVM block for use as data flash, EEPROM backup, or a combination
* of both and initializes the FlexRAM.
*/
status_t FLEXNVM_ProgramPartition(flexnvm_config_t *config,
ftfx_partition_flexram_load_opt_t option,
uint32_t eepromDataSizeCode,
uint32_t flexnvmPartitionCode)
{
return FTFx_CMD_ProgramPartition(&config->ftfxConfig, option, eepromDataSizeCode, flexnvmPartitionCode);
}
#if defined(FSL_FEATURE_FLASH_HAS_READ_RESOURCE_CMD) && FSL_FEATURE_FLASH_HAS_READ_RESOURCE_CMD
/*!
* @brief Reads the resource with data at locations passed in through parameters.
*/
status_t FLEXNVM_ReadResource(
flexnvm_config_t *config, uint32_t start, uint8_t *dst, uint32_t lengthInBytes, ftfx_read_resource_opt_t option)
{
return FTFx_CMD_ReadResource(&config->ftfxConfig, start, dst, lengthInBytes, option);
}
#endif /* FSL_FEATURE_FLASH_HAS_READ_RESOURCE_CMD */
/*!
* @brief Verifies an erasure of the desired flash area at a specified margin level.
*/
status_t FLEXNVM_DflashVerifyErase(flexnvm_config_t *config,
uint32_t start,
uint32_t lengthInBytes,
ftfx_margin_value_t margin)
{
status_t returnCode;
returnCode = flexnvm_convert_start_address(config, start);
if (returnCode != kStatus_FTFx_Success)
{
return returnCode;
}
return FTFx_CMD_VerifyErase(&config->ftfxConfig, start, lengthInBytes, margin);
}
/*!
* @brief Verifies erasure of the entire flash at a specified margin level.
*/
status_t FLEXNVM_VerifyEraseAll(flexnvm_config_t *config, ftfx_margin_value_t margin)
{
return FTFx_CMD_VerifyEraseAll(&config->ftfxConfig, margin);
}
/*!
* @brief Verifies programming of the desired flash area at a specified margin level.
*/
status_t FLEXNVM_DflashVerifyProgram(flexnvm_config_t *config,
uint32_t start,
uint32_t lengthInBytes,
const uint8_t *expectedData,
ftfx_margin_value_t margin,
uint32_t *failedAddress,
uint32_t *failedData)
{
status_t returnCode;
returnCode = flexnvm_convert_start_address(config, start);
if (returnCode != kStatus_FTFx_Success)
{
return returnCode;
}
return FTFx_CMD_VerifyProgram(&config->ftfxConfig, start, lengthInBytes, expectedData, margin, failedAddress,
failedData);
}
/*!
* @brief Returns the security state via the pointer passed into the function.
*/
status_t FLEXNVM_GetSecurityState(flexnvm_config_t *config, ftfx_security_state_t *state)
{
return FTFx_REG_GetSecurityState(&config->ftfxConfig, state);
}
/*!
* @brief Allows users to bypass security with a backdoor key.
*/
status_t FLEXNVM_SecurityBypass(flexnvm_config_t *config, const uint8_t *backdoorKey)
{
return FTFx_CMD_SecurityBypass(&config->ftfxConfig, backdoorKey);
}
#if defined(FSL_FEATURE_FLASH_HAS_SET_FLEXRAM_FUNCTION_CMD) && FSL_FEATURE_FLASH_HAS_SET_FLEXRAM_FUNCTION_CMD
/*!
* @brief Sets the FlexRAM function command.
*/
status_t FLEXNVM_SetFlexramFunction(flexnvm_config_t *config, ftfx_flexram_func_opt_t option)
{
return FTFx_CMD_SetFlexramFunction(&config->ftfxConfig, option);
}
#endif /* FSL_FEATURE_FLASH_HAS_SET_FLEXRAM_FUNCTION_CMD */
/*!
* @brief Programs the EEPROM with data at locations passed in through parameters.
*/
status_t FLEXNVM_EepromWrite(flexnvm_config_t *config, uint32_t start, uint8_t *src, uint32_t lengthInBytes)
{
status_t returnCode;
bool needSwitchFlexRamMode = false;
if (config == NULL)
{
return kStatus_FTFx_InvalidArgument;
}
/* Validates the range of the given address */
if ((start < config->ftfxConfig.flexramBlockBase) ||
((start + lengthInBytes) > (config->ftfxConfig.flexramBlockBase + config->ftfxConfig.eepromTotalSize)))
{
return kStatus_FTFx_AddressError;
}
returnCode = kStatus_FTFx_Success;
/* Switch function of FlexRAM if needed */
if (0U == (FTFx->FCNFG & FTFx_FCNFG_EEERDY_MASK))
{
needSwitchFlexRamMode = true;
returnCode = FTFx_CMD_SetFlexramFunction(&config->ftfxConfig, kFTFx_FlexramFuncOptAvailableForEeprom);
if (returnCode != kStatus_FTFx_Success)
{
return kStatus_FTFx_SetFlexramAsEepromError;
}
}
/* Write data to FlexRAM when it is used as EEPROM emulator */
while (lengthInBytes > 0U)
{
if ((0U == (start & 0x3U)) && (0U == ((uint32_t)src & 0x3U)) && (lengthInBytes >= 4U))
{
*(uint32_t *)start = *(uint32_t *)(uint32_t)src;
start += 4U;
src = &src[4];
lengthInBytes -= 4U;
}
else if ((0U == (start & 0x1U)) && (0U == ((uint32_t)src & 0x1U)) && (lengthInBytes >= 2U))
{
*(uint16_t *)start = *(uint16_t *)(uint32_t)src;
start += 2U;
src = &src[2];
lengthInBytes -= 2U;
}
else
{
*(uint8_t *)start = *src;
start += 1U;
src = &src[1];
lengthInBytes -= 1U;
}
/* Wait till EEERDY bit is set */
while (0U == (FTFx->FCNFG & FTFx_FCNFG_EEERDY_MASK))
{
}
/* Check for protection violation error */
if (0U != (FTFx->FSTAT & FTFx_FSTAT_FPVIOL_MASK))
{
return kStatus_FTFx_ProtectionViolation;
}
}
/* Switch function of FlexRAM if needed */
if (needSwitchFlexRamMode)
{
returnCode = FTFx_CMD_SetFlexramFunction(&config->ftfxConfig, kFTFx_FlexramFuncOptAvailableAsRam);
if (returnCode != kStatus_FTFx_Success)
{
return kStatus_FTFx_RecoverFlexramAsRamError;
}
}
return returnCode;
}
/*!
* @brief Sets the DFlash protection to the intended protection status.
*/
status_t FLEXNVM_DflashSetProtection(flexnvm_config_t *config, uint8_t protectStatus)
{
if (config == NULL)
{
return kStatus_FTFx_InvalidArgument;
}
if ((config->ftfxConfig.flashDesc.totalSize == 0U) || (config->ftfxConfig.flashDesc.totalSize == 0xFFFFFFFFU))
{
return kStatus_FTFx_CommandNotSupported;
}
/* Individual data flash regions will be protected from program and erase operations by setting the
* associated DPROT bit to the protected state. Each FDPROT bit only be changed from 1s to 0s,
* meaning the protection can only be increased */
FTFx->FDPROT = protectStatus;
if (FTFx->FDPROT != protectStatus)
{
return kStatus_FTFx_CommandFailure;
}
return kStatus_FTFx_Success;
}
/*!
* @brief Gets the DFlash protection status.
*/
status_t FLEXNVM_DflashGetProtection(flexnvm_config_t *config, uint8_t *protectStatus)
{
if ((config == NULL) || (protectStatus == NULL))
{
return kStatus_FTFx_InvalidArgument;
}
if ((config->ftfxConfig.flashDesc.totalSize == 0U) || (config->ftfxConfig.flashDesc.totalSize == 0xFFFFFFFFU))
{
return kStatus_FTFx_CommandNotSupported;
}
/* return the flexnvm DFlash protection status */
*protectStatus = FTFx->FDPROT;
return kStatus_FTFx_Success;
}
/*!
* @brief Sets the EEPROM protection to the intended protection status.
*/
status_t FLEXNVM_EepromSetProtection(flexnvm_config_t *config, uint8_t protectStatus)
{
if (config == NULL)
{
return kStatus_FTFx_InvalidArgument;
}
if ((config->ftfxConfig.eepromTotalSize == 0U) || (config->ftfxConfig.eepromTotalSize == 0xFFFFU))
{
return kStatus_FTFx_CommandNotSupported;
}
/* Individual data flash regions will be protected from program and erase operations by setting the
* associated FEPROT bit to the protected state; Each FEPROT bit only be changed from 1s to 0s,
* meaning the protection can only be increased. */
FTFx->FEPROT = protectStatus;
if (FTFx->FEPROT != protectStatus)
{
return kStatus_FTFx_CommandFailure;
}
return kStatus_FTFx_Success;
}
/*!
* @brief Gets the EEPROM protection status.
*/
status_t FLEXNVM_EepromGetProtection(flexnvm_config_t *config, uint8_t *protectStatus)
{
if ((config == NULL) || (protectStatus == NULL))
{
return kStatus_FTFx_InvalidArgument;
}
if ((config->ftfxConfig.eepromTotalSize == 0U) || (config->ftfxConfig.eepromTotalSize == 0xFFFFU))
{
return kStatus_FTFx_CommandNotSupported;
}
/* return EEPROM protection status */
*protectStatus = FTFx->FEPROT;
return kStatus_FTFx_Success;
}
/*!
* @brief Returns the desired flexnvm property.
*/
status_t FLEXNVM_GetProperty(flexnvm_config_t *config, flexnvm_property_tag_t whichProperty, uint32_t *value)
{
if ((config == NULL) || (value == NULL))
{
return kStatus_FTFx_InvalidArgument;
}
status_t status = kStatus_FTFx_Success;
switch (whichProperty)
{
/* get flexnvm date flash sector size */
case kFLEXNVM_PropertyDflashSectorSize:
*value = config->ftfxConfig.flashDesc.sectorSize;
break;
/* get flexnvm date flash total size */
case kFLEXNVM_PropertyDflashTotalSize:
*value = config->ftfxConfig.flashDesc.totalSize;
break;
/* get flexnvm date flash block size */
case kFLEXNVM_PropertyDflashBlockSize:
*value = config->ftfxConfig.flashDesc.totalSize / config->ftfxConfig.flashDesc.blockCount;
break;
/* get flexnvm date flash block cont */
case kFLEXNVM_PropertyDflashBlockCount:
*value = config->ftfxConfig.flashDesc.blockCount;
break;
/* get flexnvm date flash block base address */
case kFLEXNVM_PropertyDflashBlockBaseAddr:
*value = config->ftfxConfig.flashDesc.blockBase;
break;
#if defined(FSL_FEATURE_FLASH_HAS_FLEX_NVM_ALIAS) && FSL_FEATURE_FLASH_HAS_FLEX_NVM_ALIAS
case kFLEXNVM_PropertyAliasDflashBlockBaseAddr:
*value = config->ftfxConfig.flashDesc.aliasBlockBase;
break;
#endif /* FSL_FEATURE_FLASH_HAS_FLEX_NVM_ALIAS */
case kFLEXNVM_PropertyFlexRamBlockBaseAddr:
*value = config->ftfxConfig.flexramBlockBase;
break;
/* get flexram total size */
case kFLEXNVM_PropertyFlexRamTotalSize:
*value = config->ftfxConfig.flexramTotalSize;
break;
/* get flexnvm eeprom total size */
case kFLEXNVM_PropertyEepromTotalSize:
*value = config->ftfxConfig.eepromTotalSize;
break;
/* catch inputs that are not recognized */
default:
status = kStatus_FTFx_UnknownProperty;
break;
}
return status;
}
/*! @brief Convert address for Flexnvm dflash.*/
static status_t flexnvm_convert_start_address(flexnvm_config_t *config, uint32_t start)
{
status_t status = kStatus_FTFx_AddressError;
if (config == NULL)
{
return kStatus_FTFx_InvalidArgument;
}
/* From Spec: When required by the command, address bit 23 selects between program flash memory
* (=0) and data flash memory (=1).*/
if (start >= config->ftfxConfig.flashDesc.blockBase)
{
config->ftfxConfig.opsConfig.convertedAddress = start - config->ftfxConfig.flashDesc.blockBase + 0x800000U;
status = kStatus_FTFx_Success;
}
#if defined(FSL_FEATURE_FLASH_HAS_FLEX_NVM_ALIAS) && FSL_FEATURE_FLASH_HAS_FLEX_NVM_ALIAS
/* for MKW39/38/37 which have alias blockBase */
else if (start >= config->ftfxConfig.flashDesc.aliasBlockBase)
{
config->ftfxConfig.opsConfig.convertedAddress = start - config->ftfxConfig.flashDesc.aliasBlockBase + 0x800000U;
status = kStatus_FTFx_Success;
}
else
{
status = kStatus_FTFx_Success;
}
#endif /* FSL_FEATURE_FLASH_HAS_FLEX_NVM_ALIAS */
return status;
}
#endif /* FSL_FEATURE_FLASH_HAS_FLEX_NVM */

@ -0,0 +1,564 @@
/*
* Copyright 2013-2016 Freescale Semiconductor, Inc.
* Copyright 2016-2020 NXP
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
*/
#ifndef FSL_FTFX_FLEXNVM_H
#define FSL_FTFX_FLEXNVM_H
#include "fsl_ftfx_controller.h"
/*!
* @addtogroup ftfx_flexnvm_driver
* @{
*/
/*******************************************************************************
* Definitions
******************************************************************************/
/*!
* @brief Enumeration for various flexnvm properties.
*/
typedef enum _flexnvm_property_tag
{
kFLEXNVM_PropertyDflashSectorSize = 0x00U, /*!< Dflash sector size property.*/
kFLEXNVM_PropertyDflashTotalSize = 0x01U, /*!< Dflash total size property.*/
kFLEXNVM_PropertyDflashBlockSize = 0x02U, /*!< Dflash block size property.*/
kFLEXNVM_PropertyDflashBlockCount = 0x03U, /*!< Dflash block count property.*/
kFLEXNVM_PropertyDflashBlockBaseAddr = 0x04U, /*!< Dflash block base address property.*/
kFLEXNVM_PropertyAliasDflashBlockBaseAddr = 0x05U, /*!< Dflash block base address Alias property.*/
kFLEXNVM_PropertyFlexRamBlockBaseAddr = 0x06U, /*!< FlexRam block base address property.*/
kFLEXNVM_PropertyFlexRamTotalSize = 0x07U, /*!< FlexRam total size property.*/
kFLEXNVM_PropertyEepromTotalSize = 0x08U, /*!< EEPROM total size property.*/
} flexnvm_property_tag_t;
/*! @brief Flexnvm driver state information.
*
* An instance of this structure is allocated by the user of the Flexnvm driver and
* passed into each of the driver APIs.
*/
typedef struct _flexnvm_config
{
ftfx_config_t ftfxConfig;
} flexnvm_config_t;
/*******************************************************************************
* API
******************************************************************************/
#if defined(__cplusplus)
extern "C" {
#endif
/*!
* @name Initialization
* @{
*/
/*!
* @brief Initializes the global flash properties structure members.
*
* This function checks and initializes the Flash module for the other Flash APIs.
*
* @param config Pointer to the storage for the driver runtime state.
*
* @retval #kStatus_FTFx_Success API was executed successfully.
* @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
* @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
* @retval #kStatus_FTFx_PartitionStatusUpdateFailure Failed to update the partition status.
*/
status_t FLEXNVM_Init(flexnvm_config_t *config);
/*@}*/
/*!
* @name Erasing
* @{
*/
/*!
* @brief Erases the Dflash sectors encompassed by parameters passed into function.
*
* This function erases the appropriate number of flash sectors based on the
* desired start address and length.
*
* @param config The pointer to the storage for the driver runtime state.
* @param start The start address of the desired flash memory to be erased.
* The start address does not need to be sector-aligned but must be word-aligned.
* @param lengthInBytes The length, given in bytes (not words or long-words)
* to be erased. Must be word-aligned.
* @param key The value used to validate all flash erase APIs.
*
* @retval #kStatus_FTFx_Success API was executed successfully; the appropriate number of date flash sectors based on
* the desired start address and length were erased successfully.
*
* @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
* @retval #kStatus_FTFx_AlignmentError The parameter is not aligned with the specified baseline.
* @retval #kStatus_FTFx_AddressError The address is out of range.
* @retval #kStatus_FTFx_EraseKeyError The API erase key is invalid.
* @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
* @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
* @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
* @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
*/
status_t FLEXNVM_DflashErase(flexnvm_config_t *config, uint32_t start, uint32_t lengthInBytes, uint32_t key);
/*!
* @brief Erases entire flexnvm
*
* @param config Pointer to the storage for the driver runtime state.
* @param key A value used to validate all flash erase APIs.
*
* @retval #kStatus_FTFx_Success API was executed successfully; the entire flexnvm has been erased successfully.
* @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
* @retval #kStatus_FTFx_EraseKeyError API erase key is invalid.
* @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
* @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
* @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
* @retval #kStatus_FTFx_CommandFailure Run-time error during command execution.
* @retval #kStatus_FTFx_PartitionStatusUpdateFailure Failed to update the partition status.
*/
status_t FLEXNVM_EraseAll(flexnvm_config_t *config, uint32_t key);
#if defined(FSL_FEATURE_FLASH_HAS_ERASE_ALL_BLOCKS_UNSECURE_CMD) && FSL_FEATURE_FLASH_HAS_ERASE_ALL_BLOCKS_UNSECURE_CMD
/*!
* @brief Erases the entire flexnvm, including protected sectors.
*
* @param config Pointer to the storage for the driver runtime state.
* @param key A value used to validate all flash erase APIs.
*
* @retval #kStatus_FTFx_Success API was executed successfully; the flexnvm is not in securityi state.
* @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
* @retval #kStatus_FTFx_EraseKeyError API erase key is invalid.
* @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
* @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
* @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
* @retval #kStatus_FTFx_CommandFailure Run-time error during command execution.
* @retval #kStatus_FTFx_PartitionStatusUpdateFailure Failed to update the partition status.
*/
status_t FLEXNVM_EraseAllUnsecure(flexnvm_config_t *config, uint32_t key);
#endif /* FSL_FEATURE_FLASH_HAS_ERASE_ALL_BLOCKS_UNSECURE_CMD */
/*@}*/
/*!
* @name Programming
* @{
*/
/*!
* @brief Programs flash with data at locations passed in through parameters.
*
* This function programs the flash memory with the desired data for a given
* flash area as determined by the start address and the length.
*
* @param config A pointer to the storage for the driver runtime state.
* @param start The start address of the desired flash memory to be programmed. Must be
* word-aligned.
* @param src A pointer to the source buffer of data that is to be programmed
* into the flash.
* @param lengthInBytes The length, given in bytes (not words or long-words),
* to be programmed. Must be word-aligned.
*
* @retval #kStatus_FTFx_Success API was executed successfully; the desired date have been successfully
* programed into specified date flash region.
*
* @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
* @retval #kStatus_FTFx_AlignmentError Parameter is not aligned with the specified baseline.
* @retval #kStatus_FTFx_AddressError Address is out of range.
* @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
* @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
* @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
* @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
*/
status_t FLEXNVM_DflashProgram(flexnvm_config_t *config, uint32_t start, uint8_t *src, uint32_t lengthInBytes);
#if defined(FSL_FEATURE_FLASH_HAS_PROGRAM_SECTION_CMD) && FSL_FEATURE_FLASH_HAS_PROGRAM_SECTION_CMD
/*!
* @brief Programs flash with data at locations passed in through parameters via the Program Section command.
*
* This function programs the flash memory with the desired data for a given
* flash area as determined by the start address and length.
*
* @param config A pointer to the storage for the driver runtime state.
* @param start The start address of the desired flash memory to be programmed. Must be
* word-aligned.
* @param src A pointer to the source buffer of data that is to be programmed
* into the flash.
* @param lengthInBytes The length, given in bytes (not words or long-words),
* to be programmed. Must be word-aligned.
*
* @retval #kStatus_FTFx_Success API was executed successfully; the desired date have been successfully
* programed into specified date flash area.
*
* @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
* @retval #kStatus_FTFx_AlignmentError Parameter is not aligned with specified baseline.
* @retval #kStatus_FTFx_AddressError Address is out of range.
* @retval #kStatus_FTFx_SetFlexramAsRamError Failed to set flexram as RAM.
* @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
* @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
* @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
* @retval #kStatus_FTFx_CommandFailure Run-time error during command execution.
* @retval #kStatus_FTFx_RecoverFlexramAsEepromError Failed to recover FlexRAM as EEPROM.
*/
status_t FLEXNVM_DflashProgramSection(flexnvm_config_t *config, uint32_t start, uint8_t *src, uint32_t lengthInBytes);
#endif /* FSL_FEATURE_FLASH_HAS_PROGRAM_SECTION_CMD */
/*!
* @brief Prepares the FlexNVM block for use as data flash, EEPROM backup, or a combination of both and initializes the
* FlexRAM.
*
* @param config Pointer to storage for the driver runtime state.
* @param option The option used to set FlexRAM load behavior during reset.
* @param eepromDataSizeCode Determines the amount of FlexRAM used in each of the available EEPROM subsystems.
* @param flexnvmPartitionCode Specifies how to split the FlexNVM block between data flash memory and EEPROM backup
* memory supporting EEPROM functions.
*
* @retval #kStatus_FTFx_Success API was executed successfully; the FlexNVM block for use as data flash, EEPROM backup,
* or a combination of both have been Prepared.
*
* @retval #kStatus_FTFx_InvalidArgument Invalid argument is provided.
* @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
* @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
* @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
* @retval #kStatus_FTFx_CommandFailure Run-time error during command execution.
*/
status_t FLEXNVM_ProgramPartition(flexnvm_config_t *config,
ftfx_partition_flexram_load_opt_t option,
uint32_t eepromDataSizeCode,
uint32_t flexnvmPartitionCode);
/*@}*/
/*!
* @name Reading
* @{
*/
#if defined(FSL_FEATURE_FLASH_HAS_READ_RESOURCE_CMD) && FSL_FEATURE_FLASH_HAS_READ_RESOURCE_CMD
/*!
* @brief Reads the resource with data at locations passed in through parameters.
*
* This function reads the flash memory with the desired location for a given
* flash area as determined by the start address and length.
*
* @param config A pointer to the storage for the driver runtime state.
* @param start The start address of the desired flash memory to be programmed. Must be
* word-aligned.
* @param dst A pointer to the destination buffer of data that is used to store
* data to be read.
* @param lengthInBytes The length, given in bytes (not words or long-words),
* to be read. Must be word-aligned.
* @param option The resource option which indicates which area should be read back.
*
* @retval #kStatus_FTFx_Success API was executed successfully; the data have been read successfully from
* program flash IFR, data flash IFR space, and the Version ID field
*
* @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
* @retval #kStatus_FTFx_AlignmentError Parameter is not aligned with the specified baseline.
* @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
* @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
* @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
* @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
*/
status_t FLEXNVM_ReadResource(
flexnvm_config_t *config, uint32_t start, uint8_t *dst, uint32_t lengthInBytes, ftfx_read_resource_opt_t option);
#endif /* FSL_FEATURE_FLASH_HAS_READ_RESOURCE_CMD */
/*@}*/
/*!
* @name Verification
* @{
*/
/*!
* @brief Verifies an erasure of the desired flash area at a specified margin level.
*
* This function checks the appropriate number of flash sectors based on
* the desired start address and length to check whether the flash is erased
* to the specified read margin level.
*
* @param config A pointer to the storage for the driver runtime state.
* @param start The start address of the desired flash memory to be verified.
* The start address does not need to be sector-aligned but must be word-aligned.
* @param lengthInBytes The length, given in bytes (not words or long-words),
* to be verified. Must be word-aligned.
* @param margin Read margin choice.
*
* @retval #kStatus_FTFx_Success API was executed successfully; the specified data flash region is in erased state.
* @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
* @retval #kStatus_FTFx_AlignmentError Parameter is not aligned with specified baseline.
* @retval #kStatus_FTFx_AddressError Address is out of range.
* @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
* @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
* @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
* @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
*/
status_t FLEXNVM_DflashVerifyErase(flexnvm_config_t *config,
uint32_t start,
uint32_t lengthInBytes,
ftfx_margin_value_t margin);
/*!
* @brief Verifies erasure of the entire flash at a specified margin level.
*
* This function checks whether the flash is erased to the
* specified read margin level.
*
* @param config A pointer to the storage for the driver runtime state.
* @param margin Read margin choice.
*
* @retval #kStatus_FTFx_Success API was executed successfully; the entire flexnvm region is in erased state.
* @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
* @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
* @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
* @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
* @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
*/
status_t FLEXNVM_VerifyEraseAll(flexnvm_config_t *config, ftfx_margin_value_t margin);
/*!
* @brief Verifies programming of the desired flash area at a specified margin level.
*
* This function verifies the data programmed in the flash memory using the
* Flash Program Check Command and compares it to the expected data for a given
* flash area as determined by the start address and length.
*
* @param config A pointer to the storage for the driver runtime state.
* @param start The start address of the desired flash memory to be verified. Must be word-aligned.
* @param lengthInBytes The length, given in bytes (not words or long-words),
* to be verified. Must be word-aligned.
* @param expectedData A pointer to the expected data that is to be
* verified against.
* @param margin Read margin choice.
* @param failedAddress A pointer to the returned failing address.
* @param failedData A pointer to the returned failing data. Some derivatives do
* not include failed data as part of the FCCOBx registers. In this
* case, zeros are returned upon failure.
*
* @retval #kStatus_FTFx_Success API was executed successfully; the desired data hve been programed successfully into
* specified data flash region.
*
* @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
* @retval #kStatus_FTFx_AlignmentError Parameter is not aligned with specified baseline.
* @retval #kStatus_FTFx_AddressError Address is out of range.
* @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
* @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
* @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
* @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
*/
status_t FLEXNVM_DflashVerifyProgram(flexnvm_config_t *config,
uint32_t start,
uint32_t lengthInBytes,
const uint8_t *expectedData,
ftfx_margin_value_t margin,
uint32_t *failedAddress,
uint32_t *failedData);
/*@}*/
/*!
* @name Security
* @{
*/
/*!
* @brief Returns the security state via the pointer passed into the function.
*
* This function retrieves the current flash security status, including the
* security enabling state and the backdoor key enabling state.
*
* @param config A pointer to storage for the driver runtime state.
* @param state A pointer to the value returned for the current security status code:
*
* @retval #kStatus_FTFx_Success API was executed successfully;
* the security state of flexnvm was stored to state.
*
* @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
*/
status_t FLEXNVM_GetSecurityState(flexnvm_config_t *config, ftfx_security_state_t *state);
/*!
* @brief Allows users to bypass security with a backdoor key.
*
* If the MCU is in secured state, this function unsecures the MCU by
* comparing the provided backdoor key with ones in the flash configuration
* field.
*
* @param config A pointer to the storage for the driver runtime state.
* @param backdoorKey A pointer to the user buffer containing the backdoor key.
*
* @retval #kStatus_FTFx_Success API was executed successfully.
* @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
* @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
* @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
* @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
* @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
*/
status_t FLEXNVM_SecurityBypass(flexnvm_config_t *config, const uint8_t *backdoorKey);
/*@}*/
/*!
* @name FlexRAM
* @{
*/
#if defined(FSL_FEATURE_FLASH_HAS_SET_FLEXRAM_FUNCTION_CMD) && FSL_FEATURE_FLASH_HAS_SET_FLEXRAM_FUNCTION_CMD
/*!
* @brief Sets the FlexRAM function command.
*
* @param config A pointer to the storage for the driver runtime state.
* @param option The option used to set the work mode of FlexRAM.
*
* @retval #kStatus_FTFx_Success API was executed successfully;
* the FlexRAM has been successfully configured as RAM or EEPROM
*
* @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
* @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
* @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
* @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
* @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
*/
status_t FLEXNVM_SetFlexramFunction(flexnvm_config_t *config, ftfx_flexram_func_opt_t option);
#endif /* FSL_FEATURE_FLASH_HAS_SET_FLEXRAM_FUNCTION_CMD */
/*@}*/
/*!
* @brief Programs the EEPROM with data at locations passed in through parameters.
*
* This function programs the emulated EEPROM with the desired data for a given
* flash area as determined by the start address and length.
*
* @param config A pointer to the storage for the driver runtime state.
* @param start The start address of the desired flash memory to be programmed. Must be
* word-aligned.
* @param src A pointer to the source buffer of data that is to be programmed
* into the flash.
* @param lengthInBytes The length, given in bytes (not words or long-words),
* to be programmed. Must be word-aligned.
*
* @retval #kStatus_FTFx_Success API was executed successfully; the desires data have been successfully programed
* into specified eeprom region.
*
* @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
* @retval #kStatus_FTFx_AddressError Address is out of range.
* @retval #kStatus_FTFx_SetFlexramAsEepromError Failed to set flexram as eeprom.
* @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
* @retval #kStatus_FTFx_RecoverFlexramAsRamError Failed to recover the FlexRAM as RAM.
*/
status_t FLEXNVM_EepromWrite(flexnvm_config_t *config, uint32_t start, uint8_t *src, uint32_t lengthInBytes);
/*!
* @name Flash Protection Utilities
* @{
*/
/*!
* @brief Sets the DFlash protection to the intended protection status.
*
* @param config A pointer to the storage for the driver runtime state.
* @param protectStatus The expected protect status to set to the DFlash protection register. Each bit
* corresponds to the protection of the 1/8 of the total DFlash. The least significant bit corresponds to the lowest
* address area of the DFlash. The most significant bit corresponds to the highest address area of the DFlash. There
* are
* two possible cases as shown below:
* 0: this area is protected.
* 1: this area is unprotected.
*
* @retval #kStatus_FTFx_Success API was executed successfully; the specified DFlash region is protected.
* @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
* @retval #kStatus_FTFx_CommandNotSupported Flash API is not supported.
* @retval #kStatus_FTFx_CommandFailure Run-time error during command execution.
*/
status_t FLEXNVM_DflashSetProtection(flexnvm_config_t *config, uint8_t protectStatus);
/*!
* @brief Gets the DFlash protection status.
*
* @param config A pointer to the storage for the driver runtime state.
* @param protectStatus DFlash Protect status returned by the PFlash IP. Each bit corresponds to the protection of the
* 1/8 of
* the total DFlash. The least significant bit corresponds to the lowest address area of the DFlash. The most
* significant bit corresponds to the highest address area of the DFlash, and so on. There are two possible cases as
* below:
* 0: this area is protected.
* 1: this area is unprotected.
*
* @retval #kStatus_FTFx_Success API was executed successfully.
* @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
* @retval #kStatus_FTFx_CommandNotSupported Flash API is not supported.
*/
status_t FLEXNVM_DflashGetProtection(flexnvm_config_t *config, uint8_t *protectStatus);
/*!
* @brief Sets the EEPROM protection to the intended protection status.
*
* @param config A pointer to the storage for the driver runtime state.
* @param protectStatus The expected protect status to set to the EEPROM protection register. Each bit
* corresponds to the protection of the 1/8 of the total EEPROM. The least significant bit corresponds to the lowest
* address area of the EEPROM. The most significant bit corresponds to the highest address area of EEPROM, and so on.
* There are two possible cases as shown below:
* 0: this area is protected.
* 1: this area is unprotected.
*
* @retval #kStatus_FTFx_Success API was executed successfully.
* @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
* @retval #kStatus_FTFx_CommandNotSupported Flash API is not supported.
* @retval #kStatus_FTFx_CommandFailure Run-time error during command execution.
*/
status_t FLEXNVM_EepromSetProtection(flexnvm_config_t *config, uint8_t protectStatus);
/*!
* @brief Gets the EEPROM protection status.
*
* @param config A pointer to the storage for the driver runtime state.
* @param protectStatus DFlash Protect status returned by the PFlash IP. Each bit corresponds to the protection of the
* 1/8 of
* the total EEPROM. The least significant bit corresponds to the lowest address area of the EEPROM. The most
* significant bit corresponds to the highest address area of the EEPROM. There are two possible cases as below:
* 0: this area is protected.
* 1: this area is unprotected.
*
* @retval #kStatus_FTFx_Success API was executed successfully.
* @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
* @retval #kStatus_FTFx_CommandNotSupported Flash API is not supported.
*/
status_t FLEXNVM_EepromGetProtection(flexnvm_config_t *config, uint8_t *protectStatus);
/*@}*/
/*!
* @name Properties
* @{
*/
/*!
* @brief Returns the desired flexnvm property.
*
* @param config A pointer to the storage for the driver runtime state.
* @param whichProperty The desired property from the list of properties in
* enum flexnvm_property_tag_t
* @param value A pointer to the value returned for the desired flexnvm property.
*
* @retval #kStatus_FTFx_Success API was executed successfully.
* @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
* @retval #kStatus_FTFx_UnknownProperty An unknown property tag.
*/
status_t FLEXNVM_GetProperty(flexnvm_config_t *config, flexnvm_property_tag_t whichProperty, uint32_t *value);
/*@}*/
#if defined(__cplusplus)
}
#endif
/*! @}*/
#endif /* FSL_FTFX_FLEXNVM_H */

@ -0,0 +1,70 @@
/*
* Copyright 2017-2020 NXP
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
*/
#ifndef FSL_FTFX_UTILITIES_H
#define FSL_FTFX_UTILITIES_H
/*!
* @addtogroup ftfx_utilities
* @{
*/
/*******************************************************************************
* Definitions
******************************************************************************/
/*! @brief Constructs the version number for drivers. */
#if !defined(MAKE_VERSION)
#define MAKE_VERSION(major, minor, bugfix) (((major) << 16) | ((minor) << 8) | (bugfix))
#endif
/*! @brief Constructs a status code value from a group and a code number. */
#if !defined(MAKE_STATUS)
#define MAKE_STATUS(group, code) ((((group)*100) + (code)))
#endif
/*! @brief Constructs the four character code for the Flash driver API key. */
#if !defined(FOUR_CHAR_CODE)
#define FOUR_CHAR_CODE(a, b, c, d) \
(((uint32_t)(d) << 24u) | ((uint32_t)(c) << 16u) | ((uint32_t)(b) << 8u) | ((uint32_t)(a)))
#endif
//! @name Alignment macros
//@{
/*! @brief Alignment(down) utility. */
#if !defined(ALIGN_DOWN)
#define ALIGN_DOWN(x, a) (((uint32_t)(x)) & ~((uint32_t)(a)-1u))
#endif
/*! @brief Alignment(up) utility. */
#if !defined(ALIGN_UP)
#define ALIGN_UP(x, a) ALIGN_DOWN((uint32_t)(x) + (uint32_t)(a)-1u, a)
#endif
//@}
/*! @brief bytes2word utility. */
#define B1P4(b) (((uint32_t)(b)&0xFFU) << 24U)
#define B1P3(b) (((uint32_t)(b)&0xFFU) << 16U)
#define B1P2(b) (((uint32_t)(b)&0xFFU) << 8U)
#define B1P1(b) ((uint32_t)(b)&0xFFU)
#define B2P3(b) (((uint32_t)(b)&0xFFFFU) << 16U)
#define B2P2(b) (((uint32_t)(b)&0xFFFFU) << 8U)
#define B2P1(b) ((uint32_t)(b)&0xFFFFU)
#define B3P2(b) (((uint32_t)(b)&0xFFFFFFU) << 8U)
#define B3P1(b) ((uint32_t)(b)&0xFFFFFFU)
#define BYTE2WORD_1_3(x, y) (B1P4(x) | B3P1(y))
#define BYTE2WORD_2_2(x, y) (B2P3(x) | B2P1(y))
#define BYTE2WORD_3_1(x, y) (B3P2(x) | B1P1(y))
#define BYTE2WORD_1_1_2(x, y, z) (B1P4(x) | B1P3(y) | B2P1(z))
#define BYTE2WORD_1_2_1(x, y, z) (B1P4(x) | B2P2(y) | B1P1(z))
#define BYTE2WORD_2_1_1(x, y, z) (B2P3(x) | B1P2(y) | B1P1(z))
#define BYTE2WORD_1_1_1_1(x, y, z, w) (B1P4(x) | B1P3(y) | B1P2(z) | B1P1(w))
/*! @}*/
#endif /* FSL_FTFX_UTILITIES_H */

@ -120,5 +120,15 @@ add_compile_options(-include "../config/IncludeMcuLibConfig.h")
/* #define configHEAP_SECTION_NAME_STRING ".bss.$SRAM_LOWER.FreeRTOS" */ /* #define configHEAP_SECTION_NAME_STRING ".bss.$SRAM_LOWER.FreeRTOS" */
/* ------------------- FatFS ---------------------------*/ /* ------------------- FatFS ---------------------------*/
#define McuLib_CONFIG_USE_FAT_FS (0) #define McuLib_CONFIG_USE_FAT_FS (0)
/* ---------------------------------------------------------------------------------------*/
/* McuFlash */
#define McuFlash_CONFIG_IS_ENABLED (1)
/* ---------------------------------------------------------------------------------------*/
/* MinINI */
#define McuMinINI_CONFIG_FS (McuMinINI_CONFIG_FS_TYPE_FLASH_FS)
#define McuMinINI_CONFIG_FLASH_NVM_ADDR_START ((0+512*1024)-McuMinINI_CONFIG_FLASH_NVM_BLOCK_SIZE)
#define McuMinINI_CONFIG_FLASH_NVM_BLOCK_SIZE (0x800)
#define McuMinINI_CONFIG_FLASH_NVM_MAX_DATA_SIZE (0x800) /* must be 64, 128, 256, ... */
#endif /* INCLUDEMCULIBCONFIG_H_ */ #endif /* INCLUDEMCULIBCONFIG_H_ */

@ -0,0 +1,238 @@
/*
* Copyright (c) 2019-2022, Erich Styger
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include "platform.h"
#if PL_CONFIG_USE_NVMC
#include "nvmc.h"
#include <string.h>
#if PL_CONFIG_USE_MININI
#include "MinIni/McuMinINI.h"
#endif
#include "McuLib.h"
#include "McuUtility.h"
#include "Shell.h"
#include "McuLog.h"
#define NVMC_MININI_FILE_NAME "settings.ini" /* 'file' name used */
/* RS-485 bus settings */
#define NVMC_MININI_SECTION_RS485 "rs485"
#define NVMC_MININI_KEY_RS485_ADDR "addr" /* long value: RS-485 address */
/* application settings */
#define NVMC_MININI_SECTION_APP "app"
#define NVMC_MININI_KEY_APP_FLAGS "flags" /* long value: application flags */
/* motor settings */
#define NVMC_MININI_SECTION_MOTOR "motor" /* motor0, motor1, ... */
#define NVMC_MININI_KEY_MOTOR_ID "id" /* long value: stepper motor id/label */
#define NVMC_MININI_KEY_MOTOR_OFFSET "offs" /* long value: stepper motor offset */
#define NVMC_MININI_KEY_MOTOR_X "x" /* long value: x position of split-flap */
#define NVMC_MININI_KEY_MOTOR_Y "y" /* long value: y position of split-flap */
uint8_t NVMC_GetRS485Addr(uint8_t *addr) {
#if PL_CONFIG_USE_MININI
*addr = McuMinINI_ini_getl(NVMC_MININI_SECTION_RS485, NVMC_MININI_KEY_RS485_ADDR, 0x1, NVMC_MININI_FILE_NAME);
return ERR_OK;
#else
*addr = 0x1;
return ERR_OK;
#endif
}
uint8_t NVMC_SetRS485Addr(uint8_t addr) {
#if PL_CONFIG_USE_MININI && McuMinINI_CONFIG_READ_ONLY
return ERR_FAILED;
#elif PL_CONFIG_USE_MININI
McuMinINI_ini_putl(NVMC_MININI_SECTION_RS485, NVMC_MININI_KEY_RS485_ADDR, addr, NVMC_MININI_FILE_NAME);
return ERR_OK;
#else
return ERR_FAILED;
#endif
}
uint8_t NVMC_GetFlags(uint32_t *flags) {
#if PL_CONFIG_USE_MININI
*flags = McuMinINI_ini_getl(NVMC_MININI_SECTION_APP, NVMC_MININI_KEY_APP_FLAGS, 0x0, NVMC_MININI_FILE_NAME);
return ERR_OK;
#else
*flags = 0;
return ERR_OK;
#endif
}
uint8_t NVMC_SetFlags(uint32_t flags) {
#if PL_CONFIG_USE_MININI && McuMinINI_CONFIG_READ_ONLY
return ERR_FAILED;
#elif PL_CONFIG_USE_MININI
McuMinINI_ini_putl(NVMC_MININI_SECTION_APP, NVMC_MININI_KEY_APP_FLAGS, flags, NVMC_MININI_FILE_NAME);
return ERR_OK;
#else
return ERR_FAILED;
#endif
}
#if PL_CONFIG_USE_MININI
static void BuildStepperSectionName(unsigned char *sectionName, size_t nameSize, uint8_t motorIdx) {
McuUtility_strcpy(sectionName, nameSize, (unsigned char*)NVMC_MININI_SECTION_MOTOR);
McuUtility_strcatNum8u(sectionName, nameSize, motorIdx); /* append motor index to section name */
}
#endif
uint8_t NVMC_GetStepperID(uint8_t motorIdx, int16_t *id) {
#if PL_CONFIG_USE_MININI
unsigned char sectionName[16];
BuildStepperSectionName(sectionName, sizeof(sectionName), motorIdx);
*id = McuMinINI_ini_getl((char*)sectionName, NVMC_MININI_KEY_MOTOR_ID, -1, NVMC_MININI_FILE_NAME);
return ERR_OK;
#else
*id = -1;
return ERR_OK;
#endif
}
uint8_t NVMC_SetStepperID(uint8_t motorIdx, uint16_t id) {
#if PL_CONFIG_USE_MININI && McuMinINI_CONFIG_READ_ONLY
return ERR_FAILED;
#elif PL_CONFIG_USE_MININI
unsigned char sectionName[16];
BuildStepperSectionName(sectionName, sizeof(sectionName), motorIdx);
McuMinINI_ini_putl((char*)sectionName, NVMC_MININI_KEY_MOTOR_ID, id, NVMC_MININI_FILE_NAME);
return ERR_OK;
#else
return ERR_FAILED;
#endif
}
uint8_t NVMC_GetStepperPosition(uint8_t motorIdx, int16_t *xp, int16_t *yp) {
#if PL_CONFIG_USE_MININI
unsigned char sectionName[16];
BuildStepperSectionName(sectionName, sizeof(sectionName), motorIdx);
*xp = McuMinINI_ini_getl((char*)sectionName, NVMC_MININI_KEY_MOTOR_X, -1, NVMC_MININI_FILE_NAME);
*yp = McuMinINI_ini_getl((char*)sectionName, NVMC_MININI_KEY_MOTOR_Y, -1, NVMC_MININI_FILE_NAME);
return ERR_OK;
#else
*xp = 0;
*yp = 0;
return ERR_OK;
#endif
}
uint8_t NVMC_SetStepperPosition(uint8_t motorIdx, int16_t xPos, int16_t yPos) {
#if PL_CONFIG_USE_MININI && McuMinINI_CONFIG_READ_ONLY
return ERR_FAILED;
#elif PL_CONFIG_USE_MININI
unsigned char sectionName[16];
BuildStepperSectionName(sectionName, sizeof(sectionName), motorIdx);
McuMinINI_ini_putl((char*)sectionName, NVMC_MININI_KEY_MOTOR_X, xPos, NVMC_MININI_FILE_NAME);
McuMinINI_ini_putl((char*)sectionName, NVMC_MININI_KEY_MOTOR_Y, yPos, NVMC_MININI_FILE_NAME);
return ERR_OK;
#else
return ERR_FAILED;
#endif
}
int16_t NVMC_GetStepperZeroOffset(uint8_t motorIdx) {
#if PL_CONFIG_USE_MININI
unsigned char sectionName[16];
BuildStepperSectionName(sectionName, sizeof(sectionName), motorIdx);
return McuMinINI_ini_getl((char*)sectionName, NVMC_MININI_KEY_MOTOR_OFFSET, 0, NVMC_MININI_FILE_NAME);
#else
return 0;
#endif
}
uint8_t NVMC_SetStepperZeroOffset(uint8_t motorIdx, int16_t offset) {
#if PL_CONFIG_USE_MININI && McuMinINI_CONFIG_READ_ONLY
return ERR_FAILED;
#elif PL_CONFIG_USE_MININI
unsigned char sectionName[16];
BuildStepperSectionName(sectionName, sizeof(sectionName), motorIdx);
McuMinINI_ini_putl((char*)sectionName, NVMC_MININI_KEY_MOTOR_OFFSET, offset, NVMC_MININI_FILE_NAME);
return ERR_OK;
#else
return ERR_FAILED;
#endif
}
static uint8_t PrintStatus(const McuShell_StdIOType *io) {
uint8_t buf[64];
uint8_t res, addr;
uint32_t flags;
McuShell_SendStatusStr((unsigned char*)"nvmc", (unsigned char*)"Non-volatile memory configuration area\r\n", io->stdOut);
res = NVMC_GetRS485Addr(&addr);
if (res==ERR_OK) {
McuUtility_strcpy(buf, sizeof(buf), (unsigned char*)"0x");
McuUtility_strcatNum8Hex(buf, sizeof(buf), addr);
McuUtility_strcat(buf, sizeof(buf), (unsigned char*)"\r\n");
} else {
McuUtility_strcpy(buf, sizeof(buf), (unsigned char*)"ERROR\r\n");
}
McuShell_SendStatusStr((unsigned char*)" RS-485 addr", buf, io->stdOut);
res = NVMC_GetFlags(&flags);
if (res==ERR_OK) {
McuUtility_strcpy(buf, sizeof(buf), (unsigned char*)"0x");
McuUtility_strcatNum32Hex(buf, sizeof(buf), flags);
McuUtility_strcat(buf, sizeof(buf), (unsigned char*)" mag: ");
if (flags&NVMC_FLAGS_MAGNET_ENABLED) {
McuUtility_strcat(buf, sizeof(buf), (unsigned char*)"1");
} else {
McuUtility_strcat(buf, sizeof(buf), (unsigned char*)"0");
}
McuUtility_strcat(buf, sizeof(buf), (unsigned char*)"\r\n");
} else {
McuUtility_strcpy(buf, sizeof(buf), (unsigned char*)"ERROR\r\n");
}
McuShell_SendStatusStr((unsigned char*)" flags", buf, io->stdOut);
return ERR_OK;
}
static uint8_t PrintHelp(const McuShell_StdIOType *io) {
McuShell_SendHelpStr((unsigned char*)"nvmc", (unsigned char*)"Group of NVMC commands\r\n", io->stdOut);
McuShell_SendHelpStr((unsigned char*)" help|status", (unsigned char*)"Print help or status information\r\n", io->stdOut);
McuShell_SendHelpStr((unsigned char*)" flags <val>", (unsigned char*)"Set flags\r\n", io->stdOut);
return ERR_OK;
}
uint8_t NVMC_ParseCommand(const unsigned char *cmd, bool *handled, const McuShell_StdIOType *io) {
if (McuUtility_strcmp((char*)cmd, McuShell_CMD_HELP)==0 || McuUtility_strcmp((char*)cmd, "nvmc help")==0) {
*handled = true;
return PrintHelp(io);
} else if ((McuUtility_strcmp((char*)cmd, McuShell_CMD_STATUS)==0) || (McuUtility_strcmp((char*)cmd, "nvmc status")==0)) {
*handled = true;
return PrintStatus(io);
} else if (McuUtility_strncmp((char*)cmd, "nvmc flags", sizeof("nvmc flags")-1)==0) {
*handled = true;
const unsigned char *p;
int32_t val;
p = cmd + sizeof("nvmc flags ")-1;
if (McuUtility_xatoi(&p, &val)==ERR_OK) {
return NVMC_SetFlags((uint32_t)val);
} else {
return ERR_FAILED;
}
}
return ERR_OK;
}
void NVMC_Deinit(void) {
/* nothing needed */
}
void NVMC_Init(void){
/* nothing needed */
}
#endif /* PL_CONFIG_USE_NVMC */

@ -0,0 +1,106 @@
/*
* Copyright (c) 2019-2022, Erich Styger
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef NVMC_H_
#define NVMC_H_
#include "platform.h"
#include <stdint.h>
#include <stdbool.h>
#include "McuShell.h"
#ifdef __cplusplus
extern "C" {
#endif
#define NVMC_FLAGS_MAGNET_ENABLED (1<<0) /* if magnets are enabled or not */
/*!
* \brief Provide the id/label of the stepper motor
* \param motorIdx Motor index
* \param id Where the id gets stored
* \return Error code, ERR_OK for everything ok
*/
uint8_t NVMC_GetStepperID(uint8_t motorIdx, int16_t *id);
/*!
* \brief Set the id/label of the stepper motor
* \param motorIdx Motor index
* \return Error code, ERR_OK for everything ok
*/
uint8_t NVMC_SetStepperID(uint8_t motorIdx, uint16_t id);
/*!
* \brief Provide the offset from the magnet position for a stepper motor
* \param motorIdx Motor index
* \return Stored offset
*/
int16_t NVMC_GetStepperZeroOffset(uint8_t motorIdx);
/*!
* \brief Store the offset from the magnet position for a stepper motor
* \param motorIdx Motor index
* \return Error code, ERR_OK for everything ok
*/
uint8_t NVMC_SetStepperZeroOffset(uint8_t motorIdx, int16_t offset);
/*!
* \brief Getter to get the RS-485 address
* \param addr Where to store the address
* \return Error code, ERR_OK for everything ok
*/
uint8_t NVMC_GetRS485Addr(uint8_t *addr);
/*!
* \brief Setter to set the RS-485 address.
* \param addr Address to store
* \return Error code, ERR_OK for everything ok
*/
uint8_t NVMC_SetRS485Addr(uint8_t addr);
/*!
* \brief Return for a given motor the character it is responsible for.
* \param motorIdx Motor index number
* \param xp Where to store the x coordinate, returns -1 for not attached motor
* \param yp Where to store the y coordinate, returns -1 for not attached motor
*/
uint8_t NVMC_GetStepperPosition(uint8_t motorIdx, int16_t *xp, int16_t *yp);
/*!
* \brief Set position for a given motor the character it is responsible for.
* \param motorIdx Motor index number
* \param xp Where to store the x coordinate, returns -1 for not attached motor
* \param yp Where to store the y coordinate, returns -1 for not attached motor
*/
uint8_t NVMC_SetStepperPosition(uint8_t motorIdx, int16_t xPos, int16_t yPos);
/*!
* \brief Getter to get the flags stored
* \flags Where to store the flags
* \return Error code, ERR_OK for everything ok
*/
uint8_t NVMC_GetFlags(uint32_t *flags);
/*!
* \brief Setter to set the flags in the configuration
* \param flags The flags to be set
* \return Error code, ERR_OK for everything ok
*/
uint8_t NVMC_SetFlags(uint32_t flags);
/*! \brief Command line shell parser interface */
uint8_t NVMC_ParseCommand(const unsigned char *cmd, bool *handled, const McuShell_StdIOType *io);
/*! \brief Module de-initialization */
void NVMC_Deinit(void);
/*! \brief Module initialization */
void NVMC_Init(void);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* NVMC_H_ */

@ -18,6 +18,13 @@
#include "shell.h" #include "shell.h"
#include "McuShellUart.h" #include "McuShellUart.h"
#include "McuLog.h" #include "McuLog.h"
#if PL_CONFIG_USE_NVMC
#include "nvmc.h"
#endif
#if PL_CONFIG_USE_MININI
#include "MinIni/McuMinINI.h"
#include "minIni/McuFlash.h"
#endif
void PL_Init(void){ void PL_Init(void){
@ -26,6 +33,16 @@ void PL_Init(void){
CLOCK_EnableClock(kCLOCK_PortB); CLOCK_EnableClock(kCLOCK_PortB);
CLOCK_EnableClock(kCLOCK_PortC); CLOCK_EnableClock(kCLOCK_PortC);
/* NVMC init */
#if PL_CONFIG_USE_NVMC
NVMC_Init();
#endif
#if PL_CONFIG_USE_MININI
McuMinINI_Init();
McuFlash_Init();
McuFlash_RegisterMemory((const void*)McuMinINI_CONFIG_FLASH_NVM_ADDR_START, 1*McuMinINI_CONFIG_FLASH_NVM_BLOCK_SIZE);
#endif
McuLib_Init(); McuLib_Init();
McuRTOS_Init(); McuRTOS_Init();
McuWait_Init(); McuWait_Init();
@ -55,4 +72,13 @@ void PL_Deinit(void){
McuWait_Deinit(); McuWait_Deinit();
McuRTOS_Deinit(); McuRTOS_Deinit();
McuLib_Deinit(); McuLib_Deinit();
/* NVMC deinit */
#if PL_CONFIG_USE_MININI
McuMinINI_Deinit();
McuFlash_Deinit();
#endif
#if PL_CONFIG_USE_NVMC
NVMC_Deinit();
#endif
} }

@ -10,6 +10,8 @@
/* SETTINGS */ /* SETTINGS */
//#define APP_DEBUG //#define APP_DEBUG
#define PL_CONFIG_USE_NVMC (1)
#define PL_CONFIG_USE_MININI (1 && PL_CONFIG_USE_NVMC)
/* Platform initialization */ /* Platform initialization */
void PL_Init(void); void PL_Init(void);

@ -13,6 +13,9 @@
#include "McuLog.h" #include "McuLog.h"
#include "McuUtility.h" #include "McuUtility.h"
#include "MotOffsetTable.h" #include "MotOffsetTable.h"
#include "minIni/McuMinINI.h"
#include "minIni/McuFlash.h"
#include "nvmc.h"
#define SHELL_CMD_ELEM_SIZE (sizeof(Shell_cmd_s)) #define SHELL_CMD_ELEM_SIZE (sizeof(Shell_cmd_s))
@ -138,6 +141,10 @@ static const McuShell_ParseCommandCallback CmdParserTable[] =
ParseCommand, ParseCommand,
McuShell_ParseCommand, McuShell_ParseCommand,
McuRTOS_ParseCommand, McuRTOS_ParseCommand,
McuFlash_ParseCommand,
ini_ParseCommand,
McuMinINI_ParseCommand,
NVMC_ParseCommand,
NULL /* Sentinel */ NULL /* Sentinel */
}; };

Loading…
Cancel
Save