This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

how to trigger an interrupt for erase-complete or programming-done in flash memory



I am using TM4C123GXL EVB to build programs to erase or write to flash memory block with the interrupt driven function. However, the interrupt seems never be triggered. Following is a piece of my codes:

uint32_t   eraseFlag = 0;

uint32_t DRAFlashErase(unsigned long ulAddr)

{

eraseFlag++;

FLASH_FCMISC_R = FLASH_FCMISC_PMISC & 0x2;   // reset PMISC and PRIS bit in FCRIS reg to clear interrupt

FLASH_FCIM_R = FLASH_FCIM_PMASK & 0x2;          // unmask bit[1] (PMASK) in the FCIM reg

// erase flash memory 1 KB block starting 0x2000

FLASH_FCMISC_R = FLASH_FCMISC_AMISC;                  // Clear the flash access interrupt

FLASH_FMA_R = ulAddr;                                                   // assign the starting address to FMA

FLASH_FMC_R = FLASH_FMC_WRKEY|FLASH_FMC_ERASE;      // perform the erase operation...

                               

    // wait for erase complete interrupt...

   while(eraseFlag)

    {

                if (eraseFlag == 0) { break; }

    }

if(FLASH_FCRIS_R & FLASH_FCRIS_ARIS)                        // if FCRIS_ARIS is 1, an error occurred

  {

    return 1;

  }

return 0;

}

 

void FLASH_Handler(void)

{

    uint32_t readBit;

    intCount++;

               

    GPIOB->DATA = 0x01;   

     readBit = FLASH_CTRL->FCMISC & 0x2;                     // check if bit[1] on FCMISC = 1

     if (readBit == 1)                                                               // either an erase or a write interrupt occurred

     {

         if (intCount == 1)                                                         // erase interrupt

         {

                GPIOB->DATA = 0x01;                                        // Set PB0 to HIGH to indicate erasing done

                eraseFlag--;                                                           // trigger while() loop in DRAFlashErase() stop

         }

        else                                                                                 // program interrupt

        {

                GPIOB->DATA = 0x09;                                        // Set PB3 & PB0 to HIGH to indicate erasing done

                writeFlag--;                                                            // trigger while() loop in DRAFlashWrite() stop

       }

       FLASH_CTRL->FCMISC = 0x2;                                     // clear PMISC and PRIS bits to reset interrupt

                }

}

  • I post this piece of codes for morer than 2 days, but no solution so far. Finally I found the solution myself now.

    When using the flash memory to perform some programming or erasing operations, regularly the vector table is moved or copied into the SRAM space. In my original codes, I did not have any ability to do this. In other word, you must or have to use the library API function IntRegister() to do this moving, and also you must make sure that the vector table is correctly aligned in the SRAM beginning space.

    Of course you can use those system DRA codes to do this, but it is too long and makes your program large size.

    after the interrupt handler is registered in this way, the FLASH_Handler() can be recognized and executed as soon as a flash operation-complete event occurred. so the best way to build a flash programming or erasing project to use Direct Register Access (DRA) with interrupt-driven method is to use mixed coding tech: use DRA with a library API function IntRegister() to make your project easy and simple.

    Now my project works fine.