From 45b9920504c5192e331c93d232355655f9d2de48 Mon Sep 17 00:00:00 2001 From: David Crocker Date: Sat, 13 Aug 2022 17:02:03 +0100 Subject: [PATCH] Disable cache when reading flash user signature area on SAM4E --- src/SAM4S_4E_E70/Flash.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/SAM4S_4E_E70/Flash.cpp b/src/SAM4S_4E_E70/Flash.cpp index 5bb65a2a..f912b853 100644 --- a/src/SAM4S_4E_E70/Flash.cpp +++ b/src/SAM4S_4E_E70/Flash.cpp @@ -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(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; }