PDL for FM4  Version1.2
Peripheral Driverl Library for FM4
Work Flash

What is Work Flash? Work Flash have independent area, which is sperated from Main Flash, thus the Flash operation API can be called derectly from Main Flash. More...

Macros

#define Flash_Read(addr)   *(volatile uint16_t*)((uint32_t)(addr))
 Read a half word data from Flash. More...
 
#define Flash_Write(addr, data)   *(volatile uint16_t*)((uint32_t)(addr)) = ( uint16_t)(data)
 Wirte a half word data into Flash. More...
 
#define WFLASH_CODE1   0x0AA8
 
#define WFLASH_CODE2   0x0554
 
#define WFLASH_RET_OK   0
 
#define WFLASH_RET_INVALID_PARA   1
 
#define WFLASH_RET_ABNORMAL   2
 
#define WFLASH_CHK_TOGG_NORMAL   0
 
#define WFLASH_CHK_TOGG_ABNORMAL   1
 
#define WFLASH_CHK_DPOL_NORMAL   0
 
#define WFLASH_CHK_DPOL_ABNORMAL   1
 
#define WFLASH_CHK_DPOL_MASK   (uint16_t)0x0080
 
#define WFLASH_CHK_TOGG_MASK   (uint16_t)0x0040
 
#define WFLASH_CHK_TLOV_MASK   (uint16_t)0x0020
 
#define WFLASH_BASE_ADDR   (0x200C0000)
 

Functions

static uint8_t WFlash_CheckToggle (uint16_t *pu16Addr)
 automatic algorithm of flash memory execution More...
 
static void WFlash_ReadResetCmd (uint16_t *pu16ResetSecAddr)
 Issue read/reset command. More...
 
uint8_t WFlash_ChipErase (void)
 Flash chip erase. More...
 
uint8_t WFlash_SectorErase (uint16_t *pu16SecAddr)
 Flash sector erase. More...
 
uint8_t WFlash_Write (uint16_t *pu16WriteAddr, uint16_t *pu16WriteData, uint32_t u32Size)
 Flash half-word write with ECC. More...
 

Detailed Description

What is Work Flash? Work Flash have independent area, which is sperated from Main Flash, thus the Flash operation API can be called derectly from Main Flash.

Provided functions of Work Flash operation:

How to use Work Flash module? WFlash_ChipErase() can erase whole chip space of Work Flash. WFlash_SectorErase() can erase one selected sector. WFlash_Write() writes data into Flash area with half-word align.

Macro Definition Documentation

#define Flash_Read (   addr)    *(volatile uint16_t*)((uint32_t)(addr))

Read a half word data from Flash.

Parameters
addrPointer to read data address

Definition at line 71 of file work_flash.c.

Referenced by WFlash_CheckToggle(), WFlash_ReadResetCmd(), and WFlash_Write().

#define Flash_Write (   addr,
  data 
)    *(volatile uint16_t*)((uint32_t)(addr)) = ( uint16_t)(data)

Wirte a half word data into Flash.

Parameters
addrPointer to read data address
dataWrite data

Definition at line 80 of file work_flash.c.

Referenced by WFlash_ChipErase(), WFlash_ReadResetCmd(), WFlash_SectorErase(), and WFlash_Write().

#define WFLASH_BASE_ADDR   (0x200C0000)

Definition at line 101 of file work_flash.h.

Referenced by WFlash_ChipErase(), WFlash_SectorErase(), and WFlash_Write().

#define WFLASH_CHK_DPOL_ABNORMAL   1

Definition at line 95 of file work_flash.h.

#define WFLASH_CHK_DPOL_MASK   (uint16_t)0x0080

Definition at line 97 of file work_flash.h.

#define WFLASH_CHK_DPOL_NORMAL   0

Definition at line 94 of file work_flash.h.

#define WFLASH_CHK_TLOV_MASK   (uint16_t)0x0020

Definition at line 99 of file work_flash.h.

Referenced by WFlash_CheckToggle().

#define WFLASH_CHK_TOGG_ABNORMAL   1
#define WFLASH_CHK_TOGG_MASK   (uint16_t)0x0040

Definition at line 98 of file work_flash.h.

Referenced by WFlash_CheckToggle().

#define WFLASH_CHK_TOGG_NORMAL   0

Definition at line 91 of file work_flash.h.

Referenced by WFlash_CheckToggle().

#define WFLASH_CODE1   0x0AA8

Definition at line 84 of file work_flash.h.

Referenced by WFlash_ChipErase(), WFlash_SectorErase(), and WFlash_Write().

#define WFLASH_CODE2   0x0554

Definition at line 85 of file work_flash.h.

Referenced by WFlash_ChipErase(), WFlash_SectorErase(), and WFlash_Write().

#define WFLASH_RET_ABNORMAL   2

Definition at line 89 of file work_flash.h.

Referenced by WFlash_ChipErase(), WFlash_SectorErase(), and WFlash_Write().

#define WFLASH_RET_INVALID_PARA   1

Definition at line 88 of file work_flash.h.

Referenced by WFlash_SectorErase(), and WFlash_Write().

#define WFLASH_RET_OK   0

Definition at line 87 of file work_flash.h.

Referenced by WFlash_ChipErase(), WFlash_SectorErase(), and WFlash_Write().

Function Documentation

static uint8_t WFlash_CheckToggle ( uint16_t *  pu16Addr)
static

automatic algorithm of flash memory execution

Parameters
pu16Addraddress of flash data
Returns
Operation status
Return values
MFLASH_RET_OK
MFLASH_RET_ABNORMAL
MFLASH_RET_INVALID_PARA

Definition at line 284 of file work_flash.c.

References Flash_Read, WFLASH_CHK_TLOV_MASK, WFLASH_CHK_TOGG_ABNORMAL, WFLASH_CHK_TOGG_MASK, and WFLASH_CHK_TOGG_NORMAL.

Referenced by WFlash_ChipErase(), WFlash_SectorErase(), and WFlash_Write().

Here is the caller graph for this function:

uint8_t WFlash_ChipErase ( void  )

Flash chip erase.

Returns
Operation status
Return values
MFLASH_RET_OK
MFLASH_RET_ABNORMAL
MFLASH_RET_INVALID_PARA

Definition at line 121 of file work_flash.c.

References Flash_Write, WFLASH_BASE_ADDR, WFlash_CheckToggle(), WFLASH_CHK_TOGG_ABNORMAL, WFLASH_CODE1, WFLASH_CODE2, WFlash_ReadResetCmd(), WFLASH_RET_ABNORMAL, and WFLASH_RET_OK.

Here is the call graph for this function:

static void WFlash_ReadResetCmd ( uint16_t *  pu16ResetSecAddr)
static

Issue read/reset command.

Parameters
pu16ResetSecAddraddress of reset sector
Returns
None

Definition at line 98 of file work_flash.c.

References Flash_Read, and Flash_Write.

Referenced by WFlash_ChipErase(), WFlash_SectorErase(), and WFlash_Write().

Here is the caller graph for this function:

uint8_t WFlash_SectorErase ( uint16_t *  pu16SecAddr)

Flash sector erase.

Parameters
pu16SecAddraddress of flash sector
Returns
Operation status
Return values
MFLASH_RET_OK
MFLASH_RET_ABNORMAL
MFLASH_RET_INVALID_PARA

Definition at line 167 of file work_flash.c.

References Flash_Write, WFLASH_BASE_ADDR, WFlash_CheckToggle(), WFLASH_CHK_TOGG_ABNORMAL, WFLASH_CODE1, WFLASH_CODE2, WFlash_ReadResetCmd(), WFLASH_RET_ABNORMAL, WFLASH_RET_INVALID_PARA, and WFLASH_RET_OK.

Here is the call graph for this function:

uint8_t WFlash_Write ( uint16_t *  pu16WriteAddr,
uint16_t *  pu16WriteData,
uint32_t  u32Size 
)

Flash half-word write with ECC.

Parameters
pu16WriteAddraddress of flash data
pu16WriteDatapointer to write data
u32Sizedata size, 1 indicates 1 16-bit data, always set it to even
Returns
Operation status
Return values
MFLASH_RET_OK
MFLASH_RET_ABNORMAL
MFLASH_RET_INVALID_PARA

Definition at line 219 of file work_flash.c.

References Flash_Read, Flash_Write, WFLASH_BASE_ADDR, WFlash_CheckToggle(), WFLASH_CHK_TOGG_ABNORMAL, WFLASH_CODE1, WFLASH_CODE2, WFlash_ReadResetCmd(), WFLASH_RET_ABNORMAL, WFLASH_RET_INVALID_PARA, and WFLASH_RET_OK.

Here is the call graph for this function: