PDB stops working after erasing a section on Flash

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

PDB stops working after erasing a section on Flash

1,792 Views
zainali
Contributor II

Hi,

I am observing an issue of PDB stop working after performing erase on Flash.
In my application, PDB is used as a trigger for ADC. When I erase some section of flash, the PDB stops triggering the ADC. I observed that this only happens for erase, i can write to flash without any problem.
I do disable interrupts before erasing/writing flash.

Anyone has any idea what might be the problem or has anyone faced similar issue.

Microcontroller used is MK10DN512

Thanks

0 Kudos
7 Replies

1,785 Views
myke_predko
Senior Contributor III

Hey @zainali 

Two comments back.  

First off, how do you know that interrupts are re-enabled after your erase?  Have you checked the PDB Trigger bits to make sure your ADC start is being requested?  

Secondly, how are you setting up boundaries for erasing the Flash?  You are mentioning that you are erasing a "section" and not a "sector".  How do you determine what is your start address and length when you call "FLASH_Erase"?  Is it possible that you are erasing code?  

I know the SDK APIs (strongly) imply that you can arbitrarily erase and write where you want and how many bytes, but this is... misleading and can result in unintended erasures and unexpected changes.  

Personally, I identify the sectors where my code resides and only read/write sectors that are outside this area.  Note that I ONLY work at the sector level - if I'm updating a sector I copy the sector into a buffer, update the buffer with the changes I want to make and then erase the sector and write the buffer contents into it.  

Yes I know that in Flash, you should be able to write to erased cells without problem but I have had issues with this in the past.  This is a case where you need to make sure you EXACTLY understand your Flash sector boundaries and work at the sector level, not arbitrary string/structure lengths.  

Good luck!

0 Kudos

1,771 Views
zainali
Contributor II

Hi @myke_predko ,

Thanks for response.

Before any flash operation I disable global interrupt and then re-enable them after flash operation is completed. For the trigger, I observed that after enabling the global interrupt, the ADC is triggered once only and that too immediately after enabling global interrupt.


The boundaries are defined in linker script. The place where I perform erase is not part of the code, I have made sure of that.. And sorry, by "section" I meant "sector" and I am erasing 2K bytes.

0 Kudos

1,764 Views
myke_predko
Senior Contributor III

Hi @zainali 

Thanx for verifying what you are doing.  

What is your PDB Interrupt period?  What you're describing here sounds like you're getting multiple interrupt requests (which are ignored) during the period you have interrupts disabled which results in the PDB is stopping (but still leaving a pending interrupt request).  

Could you check the PDBx_SC register after the last interrupt is received?  Start with checking bits 7 (PDBEN), 6 (PDBIF) and 5 (PDBIE) as well as the 15 (DMAEN).  

0 Kudos

1,747 Views
zainali
Contributor II

Hi @myke_predko ,

My PDB interrupt period is 1ms (1Khz) with pre trigger delay of ~80us to ADC. 

I checked the PDBx_SC register and after last interrupt PDBEN and PDBIE bits were set. DMA is not used so its bit value was 0 and PDBIF was also zero. And afterwards, PDBx_SC values remain same.

0 Kudos

1,736 Views
myke_predko
Senior Contributor III

Hi @zainali 

Then I'm out of ideas.  

I'm guessing that something unexpected is getting trashed and the only suggestions I have are to:

  1. Post snippets (just the relevant code pieces) of your erase versus write code
  2. Try rewriting the erase code without referring to the existing code to see if there's something in the original code that doesn't make sense.  

Sorry I can't be of more help.

0 Kudos

1,721 Views
zainali
Contributor II

Hi @myke_predko ,

Thanks for your valuable suggestions.

I have done some more tests and found that if I disable interrupt and do some processing and then enable interrupt, I get same issue. For this test, I am using following code.

zainali_0-1633623356407.png

I found that roughly if I set the loop iteration below 13000, I don't get issue with PDB.

The issue seems to be with disabling the global interrupt for long time not with Flash erase.

0 Kudos

1,715 Views
myke_predko
Senior Contributor III

Hi @zainali 

That's a perfect way of testing things unfortunately it doesn't really give us any hard numbers but it may give us some clues.  

Could you dump the PDB registers upon return re-enabling interrupts?  

If you can do that, I'd suggest dumping them after < 13,000 loops when everything works okay and then after > 13,000 loops when the PDB fails.  

Hopefully you'll see a difference that helps explains what the problem is.  

0 Kudos