This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 9c4593e183 arch/arm/src/samv7/sam_us.c: disable interrupts for flash 
access
9c4593e183 is described below

commit 9c4593e183a68a909e136dfc68385ccf84c8ce38
Author: Michal Lenc <michall...@seznam.cz>
AuthorDate: Fri May 23 11:59:02 2025 +0200

    arch/arm/src/samv7/sam_us.c: disable interrupts for flash access
    
    Interrupts should be disabled during the access to the user signature
    area in internal flash memory, otherwise the system might be halted.
    
    This applies also for read operation as this is performed with a
    special flash commands on  a special part of memory.
    
    Signed-off-by: Michal Lenc <michall...@seznam.cz>
---
 arch/arm/src/samv7/sam_us.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/arch/arm/src/samv7/sam_us.c b/arch/arm/src/samv7/sam_us.c
index f3720f95a8..87aab73166 100644
--- a/arch/arm/src/samv7/sam_us.c
+++ b/arch/arm/src/samv7/sam_us.c
@@ -98,6 +98,7 @@ int sam_erase_user_signature(void)
 
 int sam_write_user_signature(void *buffer, size_t buflen)
 {
+  irqstate_t flags;
   uint32_t *dest;
   int ret;
 
@@ -120,6 +121,7 @@ int sam_write_user_signature(void *buffer, size_t buflen)
    * within the internal memory area address space.
    */
 
+  flags = up_irq_save();
   dest = (uint32_t *)SAMV7_US_START;
   for (int i = 0; i < SAMV7_US_PAGE_WORDS; i++)
     {
@@ -134,6 +136,8 @@ int sam_write_user_signature(void *buffer, size_t buflen)
 
   up_clean_dcache(SAMV7_US_START, SAMV7_US_START + SAMV7_US_SIZE);
 
+  up_irq_restore(flags);
+
   /* EEFC_FCR_FARG does not have any affect for user signature,
    * therefore second argument can be zero.
    */
@@ -166,6 +170,7 @@ int sam_write_user_signature(void *buffer, size_t buflen)
 
 int sam_read_user_signature(void *buffer, size_t buflen)
 {
+  irqstate_t flags;
   size_t nwords;
   int ret;
 
@@ -180,7 +185,9 @@ int sam_read_user_signature(void *buffer, size_t buflen)
   /* sam_eefc_readsequence requires read length in bit words. */
 
   nwords = (buflen + sizeof(uint32_t)) / sizeof(uint32_t);
+  flags = up_irq_save();
   sam_eefc_readsequence(FCMD_STUS, FCMD_SPUS, g_page_buffer, nwords);
+  up_irq_restore(flags);
 
   /* Copy local buffer to void *buffer provided by the user. */
 

Reply via email to