I am debugging the flash writing routines for an embedded 68LC302
application. I seem to get some kind of bus fault? when I disable interrupts
prior to invoking a flash erase followed by interrupt enable. I think the
communications engine is in the process of transmitting and it may have a
transmitter interrupt ready when I invoke the enable interrupts code.
Does anyone have a sense that I should be doing something additional in my
entry and leaving the flash routines. Note the flash routines are located in
RAM. The rest of the code is in the FLASH. These routines involve execution
from RAM since the FLASH is not valid during erase or write.
To disable interrupts:
#define DISABLE ASM(" ori.w #0x0700,%sr")
To enable interrups:
#define ENABLE ASM(" andi.w #0xf8ff,%sr")
To erase flash:
void FlashErase(int sector)
{
FLASH_PTR[0] = 0xF0F0; // reset device to read mode
DISABLE;
FLASH_PTR[0x555] = 0xAAAA; // unlock 1
FLASH_PTR[0x2AA] = 0x5555; // unlock 2
FLASH_PTR[0x555] = 0x8080;
FLASH_PTR[0x555] = 0xAAAA;
FLASH_PTR[0x2AA] = 0x5555;
FLASH_PTR[flashSectors[sector].offset/2] = 0x3030;
while(FlashStatus(FLASH_PTR)!=STATUS_READY)
TICKLE_WATCHDOG;
ENABLE;
}
int FlashStatus(volatile WORD *fp)
{
unsigned char d, t;
int retry = 1;
again:
d = *fp; /* read data */
t = d ^ *fp; /* read it again and see what toggled */
if (t == 0) { /* no toggles, nothing's happening */
return STATUS_READY;
}
else if (t == 0x04) { /* erase-suspend */
if (retry--) goto again; /* may have been write completion */
return STATUS_ERSUSP;
}
else if (t & 0x40) {
if (d & 0x20) { /* timeout */
return STATUS_TIMEOUT;
}
else {
return STATUS_BUSY;
}
}
if (retry--) goto again; /* may have been write completion */
return STATUS_ERROR;
}Message
Disabling interrupts during Flash writing sessions
2003-09-14 by Marty Burns
Attachments
- No local attachments were found for this message.