MCUXpresso SDK API Reference Manual  Rev. 0
NXP Semiconductors
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
FLASH: Flash driver

Overview

The MCUXpresso SDK provides a peripheral driver for the flash driver module of MCUXpresso SDK devices.

Files

file  flash_header.h
 
file  fsl_flash.h
 

Data Structures

struct  IMG_HEADER_T
 Image header. More...
 
struct  BOOT_BLOCK_T
 Boot block. More...
 
struct  flash_config_t
 Flash configuration information. More...
 

Macros

#define FLASH_FAIL   (1 << 0)
 FLASH INT_STATUS register definitions. More...
 
#define FLASH_FAIL   (1 << 0)
 FLASH INT_STATUS register definitions. More...
 
#define FLASH_ERR   (1 << 1)
 Illegal command.
 
#define FLASH_ERR   (1 << 1)
 Illegal command.
 
#define FLASH_DONE   (1 << 2)
 Command complete.
 
#define FLASH_DONE   (1 << 2)
 Command complete.
 
#define FLASH_ECC_ERR   (1 << 3)
 ECC error detected.
 
#define FLASH_ECC_ERR   (1 << 3)
 ECC error detected.
 

Enumerations

enum  flash_status_t {
  kStatus_FLASH_Success = FLASH_DONE,
  kStatus_FLASH_Fail = FLASH_DONE | FLASH_FAIL,
  kStatus_FLASH_InvalidArgument = MAKE_STATUS(kStatusGroup_Generic, 4),
  kStatus_FLASH_AlignmentError = MAKE_STATUS(kStatusGroup_FLASH, 6),
  kStatus_FLASH_EccError = FLASH_DONE | FLASH_ECC_ERR,
  kStatus_FLASH_Error = FLASH_DONE | FLASH_ERR
}
 
enum  flash_read_mode_t { , FLASH_ReadModeNormalEccOff = (FLASH_READ_MODE_NORMAL << FLASH_READ_MODE_SHIFT)|(1<<FLASH_READ_MODE_ECC_OFF_SHIFT) }
 

Functions

void FLASH_Init (FLASH_Type *pFLASH)
 Enable the FLASH. More...
 
void FLASH_Powerdown (FLASH_Type *pFLASH)
 Power down the FLASH. More...
 
int FLASH_Wait (FLASH_Type *pFLASH)
 Wait for FLASH command to complete. More...
 
int FLASH_Erase (FLASH_Type *pFLASH, uint8_t *pu8Start, uint8_t *pu8End)
 Erase page. More...
 
int FLASH_ErasePages (FLASH_Type *pFLASH, uint32_t u32StartPage, uint32_t u32PageCount)
 Erase multiple pages. More...
 
int FLASH_BlankCheck (FLASH_Type *pFLASH, uint8_t *pu8Start, uint8_t *pu8End)
 Page Blank check. More...
 
int FLASH_MarginCheck (FLASH_Type *pFLASH, uint8_t *pu8Start, uint8_t *pu8End)
 Margin Check. More...
 
int FLASH_Program (FLASH_Type *pFLASH, uint32_t *pu32Start, uint32_t *pu32Data, uint32_t u32Length)
 Program page. More...
 
int FLASH_Checksum (FLASH_Type *pFLASH, uint8_t *pu8Start, uint8_t *pu8End, uint32_t au32Checksum[4])
 Page Checksum. More...
 
int FLASH_Read (FLASH_Type *pFLASH, uint8_t *pu8Start, uint32_t u32ReadMode, uint32_t au32Data[4])
 Read flash word (16 byte worth of data) More...
 
void FLASH_SetReadMode (FLASH_Type *pFLASH, bool freq_48M_not_32M)
 Configure the flash wait state depending of the elwe mode and CPU frequency. When the CPU clock frequency is decreased, the Set Read command shall be called after the frequency change. When the CPU clock frequency is increased, the Set Read command shall be called before the frequency change. More...
 
void FLASH_CalculateChecksum (const uint32_t *input, size_t nb_128b_words, uint32_t *misr, int init)
 Calculate checksum using the same checksum algorithm as the CMD_CHECKSUM implementation of the Flash controller. When executed over a 512 byte page (page size) must return the same value as FLASH_Checksum. More...
 
int FLASH_ConfigPageVerifyPageChecksum (const uint32_t *page_buffer, uint32_t *misr)
 Calculate checksum over page (N-2) aka CONFIG page and check it matches the expected value. More...
 
int FLASH_ConfigPageVerifyGpoChecksum (const uint32_t *page_buffer, uint32_t *misr)
 Calculate checksum over GPO array of CONFIG page and check it matches the expected value. More...
 
void FLASH_ConfigPageUpdate (uint32_t *page_ram_buffer, uint32_t *gpo_chksum, uint32_t *page_chksum)
 Configure the flash wait state depending of the elwe mode and CPU frequency. When the CPU clock frequency is decreased, the Set Read command shall be called after the frequency change. When the CPU clock frequency is increased, the Set Read command shall be called before the frequency change. More...
 
int FLASH_GetStatus (FLASH_Type *pFLASH)
 Return unfiltered FLASH INT_STATUS. In normal operation FLASH_DONE rises systematically but other status bits may rise at the same time or have risen before to notify of an error. Usually testing the value returned by FLASH_Wait is sufficionet but in some special cases the raw value may be needed. More...
 

Variables

uint32_t IMG_HEADER_T::vectors [NUMBER_CCSUM_VECTORS]
 critical vectors protected by csum
 
uint32_t IMG_HEADER_T::vectorCsum
 csum of vectors 0-7
 
uint32_t IMG_HEADER_T::imageSignature
 image signature
 
uint32_t IMG_HEADER_T::bootBlockOffset
 offset of boot block structure
 
uint32_t IMG_HEADER_T::header_crc
 the CRC of header
 
uint32_t BOOT_BLOCK_T::header_marker
 Image header marker should always be set to 0xbb0110bb+/-2.
 
uint32_t BOOT_BLOCK_T::img_type
 Image check type, with or without optional CRC.
 
uint32_t BOOT_BLOCK_T::target_addr
 Target address.
 
uint32_t BOOT_BLOCK_T::img_len
 Image length or the length of image CRC check should be done. More...
 
uint32_t BOOT_BLOCK_T::stated_size
 max size of any subsequent image : AppSize0 = 2 x stated_size
 
uint32_t BOOT_BLOCK_T::certificate_offset
 Offset of the certificate list.
 
uint32_t BOOT_BLOCK_T::compatibility_offset
 Offset of the compatibility list.
 
uint32_t BOOT_BLOCK_T::version
 Image version for multi-image support.
 

Data Structure Documentation

struct IMG_HEADER_T

Be very cautious when modifying the IMG_HEADER_T and the BOOT_BLOCK_T structures (alignment) as these structures are used in the image_tool.py (which does not take care of alignment).

Data Fields

uint32_t vectors [NUMBER_CCSUM_VECTORS]
 critical vectors protected by csum
 
uint32_t vectorCsum
 csum of vectors 0-7
 
uint32_t imageSignature
 image signature
 
uint32_t bootBlockOffset
 offset of boot block structure
 
uint32_t header_crc
 the CRC of header
 
struct BOOT_BLOCK_T

For some ADC16 channels, there are two pin selections in channel multiplexer. For example, ADC0_SE4a and ADC0_SE4b are the different channels that share the same channel number.

Data Fields

uint32_t header_marker
 Image header marker should always be set to 0xbb0110bb+/-2.
 
uint32_t img_type
 Image check type, with or without optional CRC.
 
uint32_t target_addr
 Target address.
 
uint32_t img_len
 Image length or the length of image CRC check should be done. More...
 
uint32_t stated_size
 max size of any subsequent image : AppSize0 = 2 x stated_size
 
uint32_t certificate_offset
 Offset of the certificate list.
 
uint32_t compatibility_offset
 Offset of the compatibility list.
 
uint32_t version
 Image version for multi-image support.
 
struct flash_config_t

An instance of this structure is allocated by the user of the flash driver and at initialization.

Data Fields

uint32_t PFlashBlockBase
 A base address of the first PFlash block.
 
uint32_t PFlashTotalSize
 The size of the combined PFlash block. More...
 
uint32_t PFlashSectorSize
 The size in bytes of a sector of PFlash. More...
 

Field Documentation

uint32_t flash_config_t::PFlashTotalSize
uint32_t flash_config_t::PFlashSectorSize

Macro Definition Documentation

#define FLASH_FAIL   (1 << 0)

FLASH INT_ENABLE register definitions.

Command failed

#define FLASH_FAIL   (1 << 0)

FLASH INT_ENABLE register definitions.

Command failed

Enumeration Type Documentation

Enumerator
kStatus_FLASH_Success 

flash operation is successful

kStatus_FLASH_Fail 

flash operation is not successful

kStatus_FLASH_InvalidArgument 

Invalid argument.

kStatus_FLASH_AlignmentError 

Alignment Error.

kStatus_FLASH_EccError 

ECC error detected.

kStatus_FLASH_Error 

Illegal command.

Enumerator
FLASH_ReadModeNormalEccOff 

flash operation is not successful

Function Documentation

void FLASH_Init ( FLASH_Type *  pFLASH)
Parameters
pFLASHPointer to selected FLASHx peripheral
Returns
Nothing
void FLASH_Powerdown ( FLASH_Type *  pFLASH)
Parameters
pFLASHPointer to selected FLASHx peripheral
Returns
Nothing
int FLASH_Wait ( FLASH_Type *  pFLASH)
Parameters
pFLASHPointer to selected FLASHx peripheral
Returns
INT_STATUS with ECC_ERR bit masked out
int FLASH_Erase ( FLASH_Type *  pFLASH,
uint8_t *  pu8Start,
uint8_t *  pu8End 
)
Parameters
pFLASHPointer to selected FLASH peripheral
[in]pu8StartStart address with page to inspect
[in]pu8EndEnd address (included in check)
Returns
INT_STATUS with ECC_ERR bit masked out
See Also
flash_status_t
int FLASH_ErasePages ( FLASH_Type *  pFLASH,
uint32_t  u32StartPage,
uint32_t  u32PageCount 
)
Parameters
pFLASHPointer to selected FLASH peripheral
[in]u32StartPageIndex of page to start erasing from
[in]u32PageCountNumber of pages to erase
Returns
INT_STATUS with ECC_ERR bit masked out
See Also
flash_status_t
int FLASH_BlankCheck ( FLASH_Type *  pFLASH,
uint8_t *  pu8Start,
uint8_t *  pu8End 
)
Parameters
pFLASHPointer to selected FLASH peripheral
[in]pu8StartStart address with page to inspect
[in]pu8EndEnd address (included in check)
Returns
INT_STATUS with ECC_ERR bit masked out
See Also
flash_status_t
int FLASH_MarginCheck ( FLASH_Type *  pFLASH,
uint8_t *  pu8Start,
uint8_t *  pu8End 
)
Parameters
pFLASHPointer to selected FLASH peripheral
[in]pu8StartStart address with page to inspect
[in]pu8EndEnd address (included in check)
Returns
INT_STATUS with ECC_ERR bit masked out
See Also
flash_status_t
int FLASH_Program ( FLASH_Type *  pFLASH,
uint32_t *  pu32Start,
uint32_t *  pu32Data,
uint32_t  u32Length 
)
Parameters
[in]pFLASHPointer to selected FLASH peripheral
[out]pu32StartPointer location that must be programmed in flash
[in]pu32DataPointer to source buffer being written to flash
[in]u32LengthNumber of bytes to be programmed
Returns
INT_STATUS with ECC_ERR bit masked out
See Also
flash_status_t
int FLASH_Checksum ( FLASH_Type *  pFLASH,
uint8_t *  pu8Start,
uint8_t *  pu8End,
uint32_t  au32Checksum[4] 
)
Parameters
pFLASHPointer to selected FLASH peripheral
[in]pu8StartPointer to data within starting page page checksum must be computed
[in]pu8EndPointer to data whose page is the last of the checksum calculation
[out]au32ChecksumFour 32bit word array to store checksum calculation result
Returns
INT_STATUS with ECC_ERR bit masked out
See Also
flash_status_t
int FLASH_Read ( FLASH_Type *  pFLASH,
uint8_t *  pu8Start,
uint32_t  u32ReadMode,
uint32_t  au32Data[4] 
)
Parameters
pFLASHPointer to selected FLASH peripheral
[in]pu8StartPointer to data to be read
[in]u32ReadModeRead mode see also flash_read_mode_t
[out]au32DataFour 32bit word array to store read result
Returns
INT_STATUS with ECC_ERR bit masked out
See Also
flash_status_t
void FLASH_SetReadMode ( FLASH_Type *  pFLASH,
bool  freq_48M_not_32M 
)
Parameters
pFLASHPointer to selected FLASHx peripheral
freq_48M_not_32MCPU clock frequency @48MHz - lower or equal to 32Mhz if 0
Returns
Nothing
void FLASH_CalculateChecksum ( const uint32_t *  input,
size_t  nb_128b_words,
uint32_t *  misr,
int  init 
)
Parameters
[in]inputPointer to data over which checksum calculation must be executed.
[in]nb_128b_wordsNumber of 16 byte words on flash.
[out]misrPointer on a four 32bit word array to store calculated checksum.
[in]initSet to true to clear the misr buffer.
Returns
Nothing
int FLASH_ConfigPageVerifyPageChecksum ( const uint32_t *  page_buffer,
uint32_t *  misr 
)
Parameters
[in]page_bufferPointer to data over which checksum calculation must be executed.
[out]misrPointer on a four 32bit word array to store calculated checksum. Note: this buffer is only useful for debugging purposes.
Returns
Result of the page checksum verification:
  • 0: Verify successfully.
  • -1: Verification failed.
int FLASH_ConfigPageVerifyGpoChecksum ( const uint32_t *  page_buffer,
uint32_t *  misr 
)
Parameters
[in]page_bufferPointer to data over which checksum calculation must be executed.
[out]misrPointer on a 4 32bit word array to store calculated checksum. Note: this buffer is only useful for debugging purposes.
Returns
Result of the GPO array checksum verification:
  • 0: Verify successfully.
  • -1: Verification failed.
void FLASH_ConfigPageUpdate ( uint32_t *  page_ram_buffer,
uint32_t *  gpo_chksum,
uint32_t *  page_chksum 
)
Parameters
page_ram_bufferPointer to RAM page buffer in which the read-modify-write of page (N-2) is performed
gpo_chksumPointer on a four 32bit word array to store calculated checksum.
page_chksumPointer on a four 32bit word array to store calculated checksum.
Returns
Nothing
int FLASH_GetStatus ( FLASH_Type *  pFLASH)
Parameters
pFLASHPointer to selected FLASHx peripheral.
Returns
INT_STATUS raw value.
See Also
flash_status_t

Variable Documentation

uint32_t BOOT_BLOCK_T::img_len

For faster boot application could set a smaller length than actual image. For Secure boot images, this MUST be the entire image length