cancel
Showing results for 
Search instead for 
Did you mean: 

erasing a sector with/without flash interrupt cause the system hung.

roseanne qiu
Associate II

Dear Sir/Madam:

I try to use write and erase a sector with interrupt enable.

writing interrupt work , but erase interrupt does not work and cause the system reset after hunging for a while

the reason I use interrupt, is to avoid the erase holding system too long .

here are my setting.

....

 NVIC_EnableIrq(NVIC_FLASH);

...

  1. working for writing data to sector works

the interrupt work

 if (!FLASH_SR_bit.BSY)

   {

    FLASH_UNLOCK();

    fl8Data = (uint8_t*)data;

    fl8Addr = (uint8_t*)addr;

// for 8 bytes write   

    if (FLASH_IS_UNLOCKED())

{

  /*Set the programming bit*/

  FLASH_CR_bit.MER = false;

  FLASH_CR_bit.SER = false;

  FLASH_CR_bit.PSIZE = 0;

  FLASH_CR_bit.EOPIE = 1; // operation done interrupt

  FLASH_CR_bit.ERRIE = 1; // ERROR INTERRUPT

  

     *fl8Addr = *fl8Data;

  

  FLASH_CR_bit.PG = true;   

 FLASH_LOCK();

   }

}

2 erase with/wihtout interrupt , does not work.

 if(!FLASH_SR_bit.BSY)

  {

   FLASH_UNLOCK();

   if (FLASH_IS_UNLOCKED())

   {

     FLASH_CR_bit.PG = false;

     FLASH_CR_bit.MER = false;

FLASH_CR_bit.EOPIE = 1; // operation done interrupt

FLASH_CR_bit.ERRIE = 1; // ERROR INTERRUPT

     FLASH_CR_bit.SER = true;

     FLASH_CR_bit.SNB = 5; // any kinds of sector does not work

FLASH_CR_bit.STRT = true;

retval = true;

     FLASH_LOCK();

   }

  }

in erase case, both interrupt and no interrupt do not work , and system reset after the system hung there for a while

my questions

does erasing sector work like this way, or my setting is not correct?

thanks

rose

8 REPLIES 8
roseanne qiu
Associate II

Dear Sir/Madam:

I would like to add more:

I would add more, there is write interrupt for write, but I found OPERR bit is set for operation error, checking other error bit, they are all not set.

obviously write interrupt work, but operr bit set, I do not know why. since checking other error bit , they are all not set.

any advice?

thanks

rose

What part are we talking about? What tools? Is this type of bit level programming efficient/desirable? Are they interfering with the operation? Should you be clearing the pending errors before you start?

Shouldn't PG set *before* the write, and cleared after it has completed? What's the IRQHandler look like?

There should be examples of the flashing, do those behave oddly?

The Flash will cause stalling if other operations touch the array, the processor stuffs wait states in this situation, and no interrupt can occur. The way to avoid stalling is to have your entire working set in RAM, including the vector table and handlers.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
roseanne qiu
Associate II

Dear Clive:

thanks for your answer. about writing error, I find , yes, you are correct,

flash write interrupt work and no error bit

it should be set for PG and then write.

to erase, I just want to set start erase, and then switch to other tasks until the erase interrupt is got.

above 2 is task level, after all settings, , task just wait for erase interrupt happens.

I am talking about stm32F2xx internal flash management.

flash IRQ handler look like the

void FLASH_IRQHandler(void)

{

 // first clear interrupt bit

 // check whether it is read or write interrupt

 // set flag for flash interrupt

 // read interrupt

printf("flashirq\n");

 if ( FLASH_SR_bit.OPERR ) // operation error

  {

   FLASH_SR_bit.OPERR = 1;

   // write interrupt

   SYS_setInt(FLASH_WRITE_ERROR_INT);->tell task level , it is done with error

   fFlashError |= FLASH_WRITE_OPER_ERROR;

  }

 if ( FLASH_SR_bit.PGSERR )

  {

   SYS_setInt(FLASH_WRITE_ERROR_INT);->tell task level , it is done with error

   fFlashError |= FLASH_WRITE_SEQ_ERROR;

   FLASH_SR_bit.PGSERR = 1;

  }

 if ( FLASH_SR_bit.PGPERR)

  {

   SYS_setInt(FLASH_WRITE_ERROR_INT);->tell task level , it is done with error

   fFlashError |= FLASH_WRITE_PARA_ERROR;

   FLASH_SR_bit.PGPERR = 1;

  }

 if ( FLASH_SR_bit.PGAERR )

  {

   SYS_setInt(FLASH_WRITE_ERROR_INT);->tell task level , it is done with error

   fFlashError |= FLASH_WRITE_ALIGN_ERROR;

   FLASH_SR_bit.PGAERR = 1; 

  }

 if ( FLASH_SR_bit.WRPERR )

  {

  SYS_setInt(FLASH_WRITE_ERROR_INT);-->tell task level , it is done with error

  fFlashError |= FLASH_WRITE_PROTECT_ERROR;

   FLASH_SR_bit.WRPERR = 1;

  }

 if ( FLASH_SR_bit.EOP )// operation done

  {

   SYS_setInt(FLASH_WRITE_INT); --->tell task level , it is done

   fFlashError = FLASH_WRITE_NO_ERROR;

   FLASH_SR_bit.EOP = 1;

  }

   

}

I do not understand why after above 2, system hang and then reset.

anything wrong with my setting?

thanks

rose

If the code for the other tasks is in FLASH they aren't going to run concurrently with the ERASE

Crashing can occur if you ERASE memory the processor is executing from. Pick a sector at the far end of memory, 11? Although 128KB sectors take a long time to erase.

Does the Hard Fault enter? Watchdog? If you examine memory post crash can you still see your application code in FLASH? Can you see the expected sector is erased?

Don't use printf() in the IRQ Handler, if you need check-point output, send a character to the SWO/SWV channel via ITM_SendChar()

Is this Mikro C ?

From a HW side make sure you have an adequate supply, and suitable capacitors on VCAP pins. Scope them across the failure scenario.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
roseanne qiu
Associate II

Dear Clive:

more.

only one task control to access the flash. This design is to protect flash reading and write at the same time.

I guess that erase setting registers may be wrong?

thanks

rosean

roseanne qiu
Associate II

Dear Clive:

I found I lost my reply to you .

erasing sector 11 also does not work: system reset.

I check the "erased " sector part, the sector data is not erased. no matter enabling flash interrupt or not, erase does not work.

I also check all the erased sectors have no running codes. Just the data I wrote and read by a task during running time.

I am thinking whether setting for erase is not correct?

this is C

I could not get hard fault enter? how ?

in our case , we disable watchdog

I read through doc for stm32 flash, I could not think over why my setting does not work.

I am stuck here forever.

help needed

thanks

rose

roseanne qiu
Associate II

Dear Sir/Madam:

I read through the doc :

for erase:

check busy bit from FLASH_SR

SET ser bit and snb bit

set strt bit

wait for bsy bit to be cleared.

I follow the exactly steps. in interrupt mode, i just wait for interrupt oper done(set two bits:.EOPIE and ERRIE(our interrupt work since writing irq work )

for none interrupt mode, just check bsy bit.

both does not work.

in both case, once set strt bit, system reset.

write and read have no problem with both interrupt enable or disable)

any advices?

thanks

rose

roseanne qiu
Associate II

Dear Sir/Madam:

I read through nucleo Hal source codes, my setting for erase is the same as theirs. I do not know why it does not work.

any tests and tries should I use?

thanks

rsoe