[ion/dfu_interface] Check BSY bit before each CR register access

Change-Id: I4999906c694fed30e6101c8c5e1f33f1957db397
This commit is contained in:
Léa Saviot
2018-05-03 17:49:01 +02:00
committed by Ecco
parent 92b9fc53f3
commit c59778a01e

View File

@@ -221,23 +221,27 @@ void DFUInterface::eraseMemoryIfNeeded() {
// Unlock the Flash and check that no memory operation is ongoing
unlockFlashMemory();
while (FLASH.SR()->getBSY()) {
}
if (m_erasePage == k_flashMemorySectorsCount) {
// Mass erase
while (FLASH.SR()->getBSY()) {
}
FLASH.CR()->setMER(true);
} else {
// Sector erase
while (FLASH.SR()->getBSY()) {
}
FLASH.CR()->setSER(true);
while (FLASH.SR()->getBSY()) {
}
FLASH.CR()->setSNB(m_erasePage);
}
// Trigger the erase operation
while (FLASH.SR()->getBSY()) {
}
FLASH.CR()->setSTRT(true);
// Lock the Flash after all operations are done
while (FLASH.SR()->getBSY()) {
}
lockFlashMemoryAndPurgeCaches();
/* Put an out of range value in m_erasePage to indicate that no erase is
@@ -293,12 +297,12 @@ void DFUInterface::unlockFlashMemory() {
/* After a reset, program and erase operations are forbidden on the flash.
* They can be unlocked by writting the appropriate keys in the FLASH_KEY
* register. */
while (FLASH.SR()->getBSY()) {
}
if (FLASH.CR()->getLOCK()) {
FLASH.KEYR()->set(0x45670123);
FLASH.KEYR()->set(0xCDEF89AB);
// Set the parallelism size
while (FLASH.SR()->getBSY()) {
}
FLASH.CR()->setPSIZE(FLASH::CR::PSIZE::X32);
}
}