2020-03-11 07:25 AM
Hi All,
We are having issue on stopping interrupt while doing Flash Erase.
What we are doing:
1. Unlocking flash.
2. Entering Critical Section by disabling ISR.
3. Erasing a Flash Page.
4. Waiting for operation to complete by checking busy flag.
5. After completion of erase, leaving Critical Section by enabling ISR.
6. Locking the Flash.
Code:
----------------------------------------------------------------------------------------------------
/* Unlock */
if ((FLASH->CR & FLASH_CR_LOCK) != 0)
{
FLASH->KEYR = FLASH_FKEY1;
FLASH->KEYR = FLASH_FKEY2;
}
/* Entering Critical Section */
CriticalHndl = CritSect_Enter(CRITSECT_TYPE_HIGH);
/* Erase */
FLASH->CR |= FLASH_CR_PER;
FLASH->AR = page_addr;
FLASH->CR |= FLASH_CR_STRT;
/*Wait for Flash Operation to be finished */
while ((FLASH->SR & FLASH_SR_BSY) == FLASH_SR_BSY)
{
//TimeOut
}
/* Leaving Critical Section */
CritSect_Leave(CRITSECT_TYPE_HIGH, CriticalHndl);
/* Locking */
SET_BIT(FLASH->CR, FLASH_CR_LOCK);
------------------------------------------------------------------------------------------------
Our Issue:
· Erase is working as expected.
· Other functionality in while loop(thread mode) works fine.
· But ‘Interrupts’ are not re-enabling.
· The timer interrupts also stops after the erase.
What we found on resources:
There are suggestions to
1) Remap IVT to RAM.
2) Use Critical Sections.
We don’t want to remap IVT to RAM as we are running OS. How can we solve this issue? Please suggest some alternate solutions.
2020-03-11 08:41 AM
> CritSect_Leave(CRITSECT_TYPE_HIGH, CriticalHndl);
CritSect_Leave is not a HAL library function or FreeRTOS function. We don't know what it does.
-- pa
2020-03-11 12:32 PM
You don't have to disable interrupts at all.
Code execution would be stalled during the erase operation, and continue afterwards. No interrupts either way, is there any difference?
Do you actually check a timeout in your code? Why? How do you plan to recover when the erase is not completed in time, and the flash remains blocked?
2020-03-11 11:45 PM
CritSect_Enter just disables the interrupts [disable_irq()] and CritSect_Leave re-enables the interrupts [enable_irq()].