Skip to content

Commit

Permalink
Disable cache when reading flash user signature area on SAM4E
Browse files Browse the repository at this point in the history
  • Loading branch information
dc42 committed Aug 13, 2022
1 parent 21735eb commit 45b9920
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/SAM4S_4E_E70/Flash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -482,10 +482,20 @@ bool Flash::ReadUserSignature(uint32_t *p_data, uint32_t ul_size) noexcept

// dc42 bug fix: must disable interrupts while executing the EFC read command
const irqflags_t flags = IrqSave();
#if SAM4E
// On the SAM4E we get a crash if we try to read the user signature with cache enabled
const bool cacheWasEnabled = Cache::Disable();
const uint32_t rc = efc_perform_read_sequence(EFC, EFC_FCMD_STUS, EFC_FCMD_SPUS, p_data, ul_size);
if (cacheWasEnabled)
{
Cache::Enable();
}
#else
// Ideally the cache invalidate call would be inside function efc_perform_read_sequence,
// but here will do because we have disabled interrupts and this code won't be within 512b of the start of flash memory
Cache::InvalidateAfterDMAReceive(reinterpret_cast<const void*>(IFLASH_ADDR), FLASH_USER_SIG_SIZE);
const uint32_t rc = efc_perform_read_sequence(EFC, EFC_FCMD_STUS, EFC_FCMD_SPUS, p_data, ul_size);
#endif
IrqRestore(flags);
return rc == 0;
}
Expand Down

0 comments on commit 45b9920

Please sign in to comment.