我正在使用MSP430和處理內部閃存。 我對MSP430閃存寫入庫有疑問。 在我看來,在這個實現中,在某些情況下可能不會寫最後一個字節。 這是函數實現。MSP430內部閃存寫入工作正常
void FlashCtl_write8(uint8_t *data_ptr,uint8_t *flash_ptr,uint16_t count){
//Clear Lock bit
HWREG16(FLASH_BASE + OFS_FCTL3) = FWKEY;
//Enable byte/word write mode
HWREG16(FLASH_BASE + OFS_FCTL1) = FWKEY + WRT;
while(count > 0)
{
//test busy
while(HWREG8(FLASH_BASE + OFS_FCTL3) & BUSY)
{
;
}
//Write to Flash
*flash_ptr++ = *data_ptr++;
count--;
}
//Clear WRT bit
HWREG16(FLASH_BASE + OFS_FCTL1) = FWKEY;
//Set LOCK bit
HWREG16(FLASH_BASE + OFS_FCTL3) = FWKEY + LOCK;
}
它是一個更好的解決方案,如果該函數如下實施:
void FlashCtl_write8(uint8_t *data_ptr,uint8_t *flash_ptr,uint16_t count){
//Clear Lock bit
HWREG16(FLASH_BASE + OFS_FCTL3) = FWKEY;
//Enable byte/word write mode
HWREG16(FLASH_BASE + OFS_FCTL1) = FWKEY + WRT;
//test busy
while(HWREG8(FLASH_BASE + OFS_FCTL3) & BUSY)
{
;
}
while(count > 0)
{
//Write to Flash
*flash_ptr++ = *data_ptr++;
while(HWREG8(FLASH_BASE + OFS_FCTL3) & BUSY)
{
;
}
count--;
}
//Clear WRT bit
HWREG16(FLASH_BASE + OFS_FCTL1) = FWKEY;
//Set LOCK bit
HWREG16(FLASH_BASE + OFS_FCTL3) = FWKEY + LOCK;
}
哦,是的,我明白這一點。感謝您的幫助 –