2016-03-29 9 views
0

私はMCF51EM256 Freescaleマイクロコントローラで作業していますが、外部フラッシュメモリ(0x20000 - 0x2FFFF)を消去する際にいくつか問題があります。外部フラッシュメモリの消去(MCF51EM256マイクロコントローラ)

これは私のメインプログラムである:

void main(void) { 
    EnableInterrupts; 

    FlashInit(); 

    DisableInterrupts; 
    EraseFlash(0x020000); 
    EraseFlash(0x020800); 
    EraseFlash(0x020C00); 
    EnableInterrupts; 

    for(;;) { 
    __RESET_WATCHDOG(); /* feeds the dog */ 
    SetLED(2, 2);  // Toggle led if the program is running 
    } /* loop forever */ 
    /* please make sure that you never leave main */ 
} 

"EraseFlash()":

void EraseFlash(long addr){ 
    // The flash sector to erase is always 1 kB 

    long eraseValue = 0xFFFFFFFF; 
    Flash_Cmd((unsigned long)addr, 1, &eraseValue, 0x40); 
} 

そして "Flash_Cmd()":

#define FLASH_MASS_ERASE_CMD 0x41 
#define FLASH_ERASE_CMD  0x40 
#define FLASH_PROGRAM_CMD  0x20 
#define FLASH_BURST_CMD  0x25 

UINT8 /*far*/ 
Flash_Cmd(UINT32 FlashAddress, 
     UINT16 FlashDataCounter, 
     UINT32 *pFlashDataPtr, 
     UINT8 FlashCommand) 
{ 
    /* Check to see if FACCERR or PVIOL is set */ 
    if (FSTAT &0x30) 
    {   
     /* Clear Flags if set*/ 
     FSTAT = 0x30; 
    } 

    if (FlashDataCounter) 
    { 
    do 
    { 
     /* Wait for the Last Busrt Command to complete */ 
     while(!(FSTAT&FSTAT_FCBEF_MASK)){};/*wait until termination*/ 

     /* Write Data into Flash*/ 
     (*((volatile unsigned long *)(FlashAddress))) = *pFlashDataPtr; 
     FlashAddress += 4; 
     pFlashDataPtr++; 

     /* Write Command */ 
     FCMD = FlashCommand; 

     /* Put FCBEF at 1 */ 
     FSTAT = FSTAT_FCBEF_MASK; 

     asm (NOP); 
     asm (NOP); 
     asm (NOP); 

     /* Check if Flash Access Error or Protection Violation Error are Set */ 
     if (FSTAT&0x30) 
     {  
      /* If so, finish the function returning 1 to indicate error */ 
      return (1); 
     } 

    }while (--FlashDataCounter); 
    } 
    /* wait for the last command to complete */ 
    while ((FSTAT&FSTAT_FCCF_MASK)==0){};/*wait until termination*/ 

    /* Return zero to indicate that the function executed OK */ 
    return (0); 
} 

私の主は達することはありませんfor(;;)ループは、EraseFlash()への3回目の呼び出しによってブロックされるためです。

2回以下のコールを入れると機能します。 例:

void main(void) { 
    EnableInterrupts; 

    Platform_GPIO_Init(); 
    FlashInit(); 

    DisableInterrupts; 
    EraseFlash(0x020000); 
    EraseFlash(0x020800); 
    EnableInterrupts; 

    for(;;) { 
    __RESET_WATCHDOG(); /* feeds the dog */ 
    SetLED(2, 2);  // Toggle led if the program is running 
    } /* loop forever */ 
    /* please make sure that you never leave main */ 
} 

誰かが私が間違ってやっているものを私に伝えることができますか?私はまた、他のフラッシュメモリアドレスと割り込みを無効にしていないと同じtryedと同じ。

編集:両方の通話はOK

を実行する機能はあなたのすべてに感謝を意味し、0を返します!

+0

[this](http://stackoverflow.com/questions/36260611/erasing-external-flash)と比べて少し異なる質問ですが、答えは両方とも同じになるとはかなり確信しています。 – Lundin

+0

外部フラッシュメモリとはどういう意味ですか?これらのルーチンは、onChipバンクフラッシュで動作します。 – LPs

答えて

0

私は、データシートをチェックして、私のフラッシュドライバのヘッダにFLASH_CLOCKを変更しました:

(SYSTEM_CLOCK/200000)へ(SYSTEM_CLOCK/400000)

前:

#if (SYSTEM_CLOCK/2) > 12800000 /* 12.8 MHz */ 
    #define FLASH_CLOCK (UINT8)(((SYSTEM_CLOCK/3200000) -1) | 0x40) 
#else 
    #define FLASH_CLOCK (unsigned char)((SYSTEM_CLOCK/200000) -1)//<200KHz 
#endif 

#if (SYSTEM_CLOCK/2) > 12800000 /* 12.8 MHz */ 
    #define FLASH_CLOCK (UINT8)(((SYSTEM_CLOCK/3200000) -1) | 0x40) 
#else 
    #define FLASH_CLOCK (unsigned char)((SYSTEM_CLOCK/400000) -1)//<200KHz 
#endif 

最後に私のプログラムが動作します。

関連する問題