pSysdata.addr = 10;
pSysdata.chanel = 4;
/*写到块中的数据*/
pSysdata.type[0] = 0;
pSysdata.type[1] = 1;
pSysdata.type[2] = 2;
pSysdata.type[3] = 3;
pSysdata.cutdown[0] = 0;
pSysdata.cutdown[1] = 1;
pSysdata.cutdown[2] = 1;
pSysdata.cutdown[3] = 0;
pSysdata.cutdlytime[0] = 1;
pSysdata.cutdlytime[1] = 2;
pSysdata.cutdlytime[2] = 3;
pSysdata.cutdlytime[3] = 4;
Write2Flash(FLASHADDR_PSYDATA, (u8 *)(&pSysdata), sizeof(pSysdata));
/*调用到库中的操作部分*/
void FLASH_EraseBlock(u16 BlockNum, FLASH_MemType_TypeDef MemType)
{
u16 timeout = OPERATION_TIMEOUT;
#ifdef PointerAttr_Far
u32 StartAddress = 0;
#else /* PointerAttr_Near */
PointerAttr u32 *pwFlash;
u32 StartAddress = 0;
#endif /*PointerAttr_Far*/
/* Check parameters */
if (MemType == FLASH_MEMTYPE_PROG)
{
StartAddress = FLASH_PROG_START_PHYSICAL_ADDRESS;
}
else
{
StartAddress = FLASH_DATA_START_PHYSICAL_ADDRESS;
}
#ifdef PointerAttr_Far
/* Point to the first block address */
StartAddress = StartAddress + ((u32)BlockNum * FLASH_BLOCK_SIZE);
/* Enable erase block mode */
FLASH->CR2 |= FLASH_CR2_ERASE;
ON_ALARM_LED(); //程序可正常跑到这里
FLASH->NCR2 &= (u8)(~FLASH_NCR2_NERASE);//似乎是这里擦除始能出现问题
//while (!(FLASH->IAPSR & FLASH_IAPSR_EOP));
OFF_ALARM_LED();
ON_COMMUICATION_LED();//程序没有到这里
*((PointerAttr u8*) StartAddress) = FLASH_CLEAR_BYTE;
*((PointerAttr u8*) StartAddress + 1) = FLASH_CLEAR_BYTE;
*((PointerAttr u8*) StartAddress + 2) = FLASH_CLEAR_BYTE;
*((PointerAttr u8*) StartAddress + 3) = FLASH_CLEAR_BYTE;
#else /*PointerAttr_Near*/
/* Point to the first block address */
pwFlash = (PointerAttr u32 *)(StartAddress + ((u32)BlockNum * FLASH_BLOCK_SIZE));
/* Enable erase block mode */
FLASH->CR2 |= FLASH_CR2_ERASE;
FLASH->NCR2 &= (u8)(~FLASH_NCR2_NERASE);
*pwFlash = (u32)0;
#endif /*PointerAttr_Far*/
#if defined (STM8S208) || defined(STM8S207) || defined(STM8S105)
/* Waiting until High voltage flag is cleared*/
while ((FLASH->IAPSR & FLASH_IAPSR_HVOFF) != 0x00 || (timeout == 0x00))
{
timeout--;
ON_COMMUICATION_LED();
}
#endif /* STM8S208, STM8S207, STM8S105 */
}
/*始能那里出现问题后main中的程序就停止了*/ |