356 lines
8.9 KiB
C
356 lines
8.9 KiB
C
|
/***************************************************************
|
|||
|
*Copyright (C), 2017, Shanghai Eastsoft Microelectronics Co., Ltd
|
|||
|
*<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> lib_flashiap.c
|
|||
|
*<EFBFBD><EFBFBD> <EFBFBD>ߣ<EFBFBD> Liut
|
|||
|
*<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD> V1.00
|
|||
|
*<EFBFBD><EFBFBD> <EFBFBD>ڣ<EFBFBD> 2017/07/14
|
|||
|
*<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD> flash<EFBFBD><EFBFBD>д<EFBFBD>⺯<EFBFBD><EFBFBD>
|
|||
|
*<EFBFBD><EFBFBD> ע<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ES8P508xоƬ
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧϰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾʹ<EFBFBD>ã<EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD>ֱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ô<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ķ<EFBFBD><EFBFBD>ջ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><EFBFBD>κη<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ρ<EFBFBD>
|
|||
|
***************************************************************/
|
|||
|
#include "lib_flashiap.h"
|
|||
|
|
|||
|
/***************************************************************
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>FlashIap_Close_WPROT
|
|||
|
<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>IAP<EFBFBD>ر<EFBFBD>д<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD>Page:0-63,ÿpage<EFBFBD><EFBFBD>Ӧ2K<EFBFBD>ֽ<EFBFBD>,64 ΪINFO<EFBFBD><EFBFBD>
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>
|
|||
|
***************************************************************/
|
|||
|
ErrorStatus FlashIap_Close_WPROT(uint8_t Page)
|
|||
|
{
|
|||
|
if(Page > 64)
|
|||
|
return ERROR;
|
|||
|
|
|||
|
if(Page == 64)
|
|||
|
{
|
|||
|
IAP->WPROT2.Word = 0x00000000;
|
|||
|
return SUCCESS;
|
|||
|
}
|
|||
|
|
|||
|
if(Page < 32)
|
|||
|
{
|
|||
|
IAP->WPROT0.Word &=~ ((uint32_t)0x1 << Page);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
Page -= 32;
|
|||
|
IAP->WPROT1.Word &=~ ((uint32_t)0x1 << Page);
|
|||
|
}
|
|||
|
|
|||
|
return SUCCESS;
|
|||
|
}
|
|||
|
|
|||
|
/***************************************************************
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>FlashIap_Open_WPROT
|
|||
|
<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>IAP<EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD>Page:0-63,ÿpage<EFBFBD><EFBFBD>Ӧ2K<EFBFBD>ֽ<EFBFBD>,,64 ΪINFO<EFBFBD><EFBFBD>
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>
|
|||
|
***************************************************************/
|
|||
|
ErrorStatus FlashIap_Open_WPROT(uint8_t Page)
|
|||
|
{
|
|||
|
if(Page > 64)
|
|||
|
return ERROR;
|
|||
|
|
|||
|
if(Page == 64)
|
|||
|
{
|
|||
|
IAP->WPROT2.Word = 0x00000001;
|
|||
|
return SUCCESS;
|
|||
|
}
|
|||
|
|
|||
|
if(Page < 32)
|
|||
|
{
|
|||
|
IAP->WPROT0.Word &=~ ((uint32_t)0x1 << Page);
|
|||
|
IAP->WPROT0.Word |= ((uint32_t)0x1 << Page);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
Page -= 32;
|
|||
|
IAP->WPROT1.Word &=~ ((uint32_t)0x1 << Page);
|
|||
|
IAP->WPROT1.Word |= ((uint32_t)0x1 << Page);
|
|||
|
}
|
|||
|
|
|||
|
return SUCCESS;
|
|||
|
}
|
|||
|
|
|||
|
/***************************************************************
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>FlashIap_CloseAll_WPROT
|
|||
|
<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>IAP<EFBFBD>ر<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD>Page:0-63,ÿpage<EFBFBD><EFBFBD>Ӧ2K<EFBFBD>ֽ<EFBFBD>
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>
|
|||
|
***************************************************************/
|
|||
|
ErrorStatus FlashIap_CloseAll_WPROT(void)
|
|||
|
{
|
|||
|
IAP->WPROT0.Word = 0x00000000;
|
|||
|
IAP->WPROT1.Word = 0x00000000;
|
|||
|
IAP->WPROT2.Word = 0x00000000;
|
|||
|
|
|||
|
return SUCCESS;
|
|||
|
}
|
|||
|
/***************************************************************
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>FlashIap_OpenAll_WPROT
|
|||
|
<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>IAP<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD>
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>
|
|||
|
***************************************************************/
|
|||
|
ErrorStatus FlashIap_OpenAll_WPROT(void)
|
|||
|
{
|
|||
|
IAP->WPROT0.Word = 0xFFFFFFFF;
|
|||
|
IAP->WPROT1.Word = 0xFFFFFFFF;
|
|||
|
IAP->WPROT2.Word = 0xFFFFFFFF;
|
|||
|
|
|||
|
return SUCCESS;
|
|||
|
}
|
|||
|
|
|||
|
/***************************************************************
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>FlashIap_Unlock
|
|||
|
<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>IAP<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>
|
|||
|
***************************************************************/
|
|||
|
ErrorStatus FlashIap_Unlock(void)
|
|||
|
{
|
|||
|
uint16_t Temp16;
|
|||
|
|
|||
|
FlashIAP_RegUnLock(); //<2F><><EFBFBD><EFBFBD> IAP
|
|||
|
|
|||
|
FlashIAP_Enable(); //ʹ<><CAB9>IAP
|
|||
|
|
|||
|
FlashIAP_REQ(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
for(Temp16 = 0; Temp16 < 0xFFFF; Temp16++) //<2F>ȴ<EFBFBD>FLASHӦ<48><D3A6><EFBFBD>ź<EFBFBD>
|
|||
|
{
|
|||
|
if(IAP->CON.FLASH_ACK != 0)
|
|||
|
break;
|
|||
|
}
|
|||
|
|
|||
|
if(Temp16 == 0xFFFF)
|
|||
|
return ERROR;
|
|||
|
else
|
|||
|
return SUCCESS;
|
|||
|
}
|
|||
|
|
|||
|
/***************************************************************
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>FlashIap_WriteEnd
|
|||
|
<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>IAPд<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>
|
|||
|
***************************************************************/
|
|||
|
ErrorStatus FlashIap_WriteEnd(void)
|
|||
|
{
|
|||
|
uint32_t Temp32;
|
|||
|
|
|||
|
FlashIAP_RegUnLock(); //IAP<41><50><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
IAP->CON.Word &= 0xFFFFFFEE; //IAP<41><50><EFBFBD><EFBFBD>FLASH<53><48><EFBFBD><EFBFBD>(<28><><EFBFBD><EFBFBD>)
|
|||
|
|
|||
|
for(Temp32 = 0; Temp32 < 0xFFFF; Temp32++) //<2F>ȴ<EFBFBD>FLASHӦ<48><D3A6><EFBFBD>ź<EFBFBD>(<28><><EFBFBD><EFBFBD>)
|
|||
|
{
|
|||
|
if(IAP->CON.FLASH_ACK == 0)
|
|||
|
break;
|
|||
|
}
|
|||
|
|
|||
|
if(Temp32 == 0xFFFF)
|
|||
|
return ERROR;
|
|||
|
else
|
|||
|
return SUCCESS;
|
|||
|
}
|
|||
|
|
|||
|
/***************************************************************
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>FlashIap_ErasePage
|
|||
|
<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>IAPҳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD>Page_Addr<EFBFBD><EFBFBD>ҳ<EFBFBD><EFBFBD>ַ
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>
|
|||
|
***************************************************************/
|
|||
|
ErrorStatus FlashIap_ErasePage(uint8_t Page_Addr)
|
|||
|
{
|
|||
|
uint16_t Temp16;
|
|||
|
uint32_t temp;
|
|||
|
|
|||
|
temp = __get_PRIMASK(); //<2F><>ȡPRIMASK<53>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD>ǰ״̬
|
|||
|
__disable_irq(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
|||
|
|
|||
|
if(FlashIap_Unlock() == ERROR)
|
|||
|
{
|
|||
|
__set_PRIMASK(temp); //<2F>ָ<EFBFBD>PRIMASK<53>Ĵ<EFBFBD><C4B4><EFBFBD>״̬
|
|||
|
return ERROR;
|
|||
|
}
|
|||
|
|
|||
|
if(FlashIap_CloseAll_WPROT() == ERROR)
|
|||
|
{
|
|||
|
__set_PRIMASK(temp);
|
|||
|
return ERROR;
|
|||
|
}
|
|||
|
|
|||
|
IAP->ADDR.IAPPA = Page_Addr; //<2F><><EFBFBD><EFBFBD>ҳ<EFBFBD><D2B3>ַ
|
|||
|
|
|||
|
IAP->TRIG.TRIG = 0x00005EA1; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
for(Temp16 = 0; Temp16 < 0xFFFF; Temp16++)
|
|||
|
{ //<2F>ж<EFBFBD>IAP<41><50><EFBFBD><EFBFBD>״̬
|
|||
|
if((IAP->STA.Word & (uint32_t)0x01) == (uint32_t)0x00)
|
|||
|
break;
|
|||
|
}
|
|||
|
|
|||
|
if(Temp16 == 0xFFFF)
|
|||
|
{
|
|||
|
__set_PRIMASK(temp); //<2F>ָ<EFBFBD>PRIMASK<53>Ĵ<EFBFBD><C4B4><EFBFBD>״̬
|
|||
|
return ERROR;
|
|||
|
}
|
|||
|
|
|||
|
for(Temp16 = 0; Temp16 < 0xFFFF; Temp16++)
|
|||
|
{
|
|||
|
if((IAP->STA.Word & (uint32_t)0x02) == (uint32_t)0x02) //<2F>ж<EFBFBD>IAPҳ<50><D2B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־
|
|||
|
break;
|
|||
|
}
|
|||
|
|
|||
|
if(Temp16 == 0xFFFF)
|
|||
|
{
|
|||
|
__set_PRIMASK(temp); //<2F>ָ<EFBFBD>PRIMASK<53>Ĵ<EFBFBD><C4B4><EFBFBD>״̬
|
|||
|
return ERROR;
|
|||
|
}
|
|||
|
|
|||
|
if(FlashIap_WriteEnd() == ERROR)
|
|||
|
{
|
|||
|
__set_PRIMASK(temp); //<2F>ָ<EFBFBD>PRIMASK<53>Ĵ<EFBFBD><C4B4><EFBFBD>״̬
|
|||
|
return ERROR;
|
|||
|
}
|
|||
|
|
|||
|
if(FlashIap_OpenAll_WPROT() == ERROR)
|
|||
|
{
|
|||
|
__set_PRIMASK(temp);
|
|||
|
return ERROR;
|
|||
|
}
|
|||
|
|
|||
|
__set_PRIMASK(temp); //<2F>ָ<EFBFBD>PRIMASK<53>Ĵ<EFBFBD><C4B4><EFBFBD>״̬
|
|||
|
|
|||
|
return SUCCESS;
|
|||
|
}
|
|||
|
|
|||
|
/***************************************************************
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>FlashIap_WriteCont
|
|||
|
<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>IAP<EFBFBD><EFBFBD><EFBFBD><EFBFBD>д
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD>Unit_addr<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԫ<EFBFBD><EFBFBD>ַ <EFBFBD><EFBFBD> Page_addr<EFBFBD><EFBFBD>ҳ<EFBFBD><EFBFBD>ַ <EFBFBD><EFBFBD> Data32<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>
|
|||
|
***************************************************************/
|
|||
|
ErrorStatus FlashIap_WriteCont(uint8_t Unit_addr, uint8_t Page_addr, uint32_t Data32)
|
|||
|
{
|
|||
|
uint16_t temp16;
|
|||
|
|
|||
|
IAP->ADDR.IAPPA = Page_addr; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ
|
|||
|
IAP->ADDR.IAPCA = Unit_addr;
|
|||
|
|
|||
|
IAP->DATA.DATA = Data32; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
IAP->TRIG.TRIG = 0x00005DA2; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
for(temp16 = 0; temp16 < 0xFFFF; temp16++)
|
|||
|
{
|
|||
|
if((IAP->STA.Word & (uint32_t)0x01) == (uint32_t)0x00) //<2F>ж<EFBFBD>IAP<41><50><EFBFBD><EFBFBD>״̬
|
|||
|
break;
|
|||
|
}
|
|||
|
|
|||
|
if(temp16 == 0xFFFF)
|
|||
|
return ERROR;
|
|||
|
|
|||
|
for(temp16 = 0; temp16 < 0xFFFF; temp16++)
|
|||
|
{
|
|||
|
if((IAP->STA.Word & 0x04)==0x04) //<2F>ж<EFBFBD>IAP<41><50><EFBFBD>̽<EFBFBD><CCBD><EFBFBD><EFBFBD><EFBFBD>־
|
|||
|
break;
|
|||
|
}
|
|||
|
|
|||
|
if(temp16 == 0xFFFF)
|
|||
|
return ERROR;
|
|||
|
|
|||
|
return SUCCESS;
|
|||
|
}
|
|||
|
|
|||
|
/***************************************************************
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>FlashIap_WriteWord
|
|||
|
<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>IAPдһ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD>Unit_addr<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԫ<EFBFBD><EFBFBD>ַ <EFBFBD><EFBFBD> Page_addr<EFBFBD><EFBFBD>ҳ<EFBFBD><EFBFBD>ַ <EFBFBD><EFBFBD> Data32<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>
|
|||
|
***************************************************************/
|
|||
|
ErrorStatus FlashIap_WriteWord(uint8_t Unit_addr, uint8_t Page_addr, uint32_t Data32)
|
|||
|
{
|
|||
|
uint32_t temp;
|
|||
|
|
|||
|
temp = __get_PRIMASK(); //<2F><>ȡPRIMASK<53>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD>ǰ״̬
|
|||
|
__disable_irq(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
|||
|
|
|||
|
if(FlashIap_Unlock() == ERROR)
|
|||
|
{
|
|||
|
__set_PRIMASK(temp); //<2F>ָ<EFBFBD>PRIMASK<53>Ĵ<EFBFBD><C4B4><EFBFBD>״̬
|
|||
|
return ERROR;
|
|||
|
}
|
|||
|
|
|||
|
if(FlashIap_CloseAll_WPROT() == ERROR)
|
|||
|
{
|
|||
|
__set_PRIMASK(temp); //<2F>ر<EFBFBD><D8B1><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD>״̬
|
|||
|
return ERROR;
|
|||
|
}
|
|||
|
|
|||
|
if(FlashIap_WriteCont(Unit_addr, Page_addr, Data32) == ERROR)
|
|||
|
{
|
|||
|
__set_PRIMASK(temp); //<2F>ָ<EFBFBD>PRIMASK<53>Ĵ<EFBFBD><C4B4><EFBFBD>״̬
|
|||
|
return ERROR;
|
|||
|
}
|
|||
|
|
|||
|
if(FlashIap_WriteEnd() == ERROR)
|
|||
|
{
|
|||
|
__set_PRIMASK(temp); //<2F>ָ<EFBFBD>PRIMASK<53>Ĵ<EFBFBD><C4B4><EFBFBD>״̬
|
|||
|
return ERROR;
|
|||
|
}
|
|||
|
|
|||
|
if(FlashIap_OpenAll_WPROT() == ERROR)
|
|||
|
{
|
|||
|
__set_PRIMASK(temp); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD>״̬
|
|||
|
return ERROR;
|
|||
|
}
|
|||
|
|
|||
|
__set_PRIMASK(temp); //<2F>ָ<EFBFBD>PRIMASK<53>Ĵ<EFBFBD><C4B4><EFBFBD>״̬
|
|||
|
|
|||
|
return SUCCESS;
|
|||
|
}
|
|||
|
|
|||
|
/***************************************************************
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Flash_Read
|
|||
|
<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>Flash<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD>Ram_Addr<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵĴ<EFBFBD><EFBFBD>ŵ<EFBFBD>ַ <EFBFBD><EFBFBD> Flash_Addr<EFBFBD><EFBFBD>Flash<EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD>0x00000000 ~ 0x0001FFFF<EFBFBD><EFBFBD><EFBFBD><EFBFBD> Len<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD>ֳ<EFBFBD><EFBFBD><EFBFBD>
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>
|
|||
|
***************************************************************/
|
|||
|
ErrorStatus Flash_Read(uint32_t * Ram_Addr, uint32_t Flash_Addr, uint8_t Len)
|
|||
|
{
|
|||
|
uint8_t i;
|
|||
|
uint32_t *ram_addr32;
|
|||
|
const uint32_t *flash_addr32;
|
|||
|
|
|||
|
ram_addr32 = (uint32_t *)Ram_Addr;
|
|||
|
flash_addr32 = (const uint32_t *)Flash_Addr;
|
|||
|
|
|||
|
if((Len == 0) & (Len>(0x20000 - Flash_Addr) / 4)) //<2F>ж϶<D0B6>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>Ϸ<EFBFBD>
|
|||
|
{
|
|||
|
return ERROR;
|
|||
|
}
|
|||
|
|
|||
|
for(i=0; i<Len; i++)
|
|||
|
{
|
|||
|
*ram_addr32 = *flash_addr32;
|
|||
|
ram_addr32++;
|
|||
|
flash_addr32++;
|
|||
|
}
|
|||
|
|
|||
|
return SUCCESS;
|
|||
|
}
|
|||
|
|
|||
|
/*************************END OF FILE**********************/
|
|||
|
|