This is the mail archive of the ecos-patches@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Atmel at49xxxx flash driver


Hi,

the attached patch fixes a problem with some Atmel
microcontrollers that have an internal flash
chip of this type. For these devices, flash erase
operations are unreliable. For more information,
see http://www.atmel.com/dyn/resources/prod_documents/doc6076.pdf.



diff -ru packages-orig/devs/flash/atmel/at49xxxx/current/ChangeLog packages/devs/flash/atmel/at49xxxx/current/ChangeLog
--- packages-orig/devs/flash/atmel/at49xxxx/current/ChangeLog	2004-05-12 16:01:45.303961056 +0200
+++ packages/devs/flash/atmel/at49xxxx/current/ChangeLog	2004-05-12 15:57:57.034663264 +0200
@@ -1,3 +1,9 @@
+2004-05-11  Thomas Koeller  <thomas.koeller@baslerweb.com>
+
+	* cdl/flash_atmel_at49xxxx.cdl:
+	* include/flash_at49xxxx.inl: Added workaround for Atmel
+	AT91FR40162 erase bug.
+
 2003-11-10  Gary Thomas  <gary@mlbassoc.com>
 
 	* include/flash_at49xxxx_parts.inl: Add AT29LV200BB
diff -ru packages-orig/devs/flash/atmel/at49xxxx/current/cdl/flash_atmel_at49xxxx.cdl packages/devs/flash/atmel/at49xxxx/current/cdl/flash_atmel_at49xxxx.cdl
--- packages-orig/devs/flash/atmel/at49xxxx/current/cdl/flash_atmel_at49xxxx.cdl	2004-05-12 16:01:45.304960904 +0200
+++ packages/devs/flash/atmel/at49xxxx/current/cdl/flash_atmel_at49xxxx.cdl	2004-05-12 15:57:57.032663568 +0200
@@ -59,6 +59,18 @@
     implements    CYGHWR_IO_FLASH_DEVICE
 
     include_dir   cyg/io
+    
+    cdl_option    CYGHWR_DEVS_FLASH_ATMEL_AT49XXXX_ERASE_BUG_WORKAROUND {
+        display       "AT91FR40162 erase bug workaround"
+        flavor        bool
+        default_value 0
+        description   "
+            The flash chips used in Atmel AT91FR40162 microcontrollers have a silicon bug
+            that causes erase operations to be unreliable unless any data to be erased is
+            cleared first, see http://www.atmel.com/dyn/resources/prod_documents/doc6076.pdf.
+            Selecting this option enables that workaround. Of course, erase operations will be
+            slower then."
+    }
 }
 
 # EOF flash_atmel_49xxxx.cdl
diff -ru packages-orig/devs/flash/atmel/at49xxxx/current/include/flash_at49xxxx.inl packages/devs/flash/atmel/at49xxxx/current/include/flash_at49xxxx.inl
--- packages-orig/devs/flash/atmel/at49xxxx/current/include/flash_at49xxxx.inl	2004-05-12 16:01:45.378949656 +0200
+++ packages/devs/flash/atmel/at49xxxx/current/include/flash_at49xxxx.inl	2004-05-12 15:57:57.036662960 +0200
@@ -56,6 +56,7 @@
 //==========================================================================
 
 #include <pkgconf/hal.h>
+#include <pkgconf/devs_flash_atmel_at49xxxx.h>
 #include <cyg/hal/hal_arch.h>
 #include <cyg/hal/hal_cache.h>
 #include <cyg/hal/hal_diag.h>
@@ -272,7 +273,7 @@
     volatile flash_data_t* b_p = (volatile flash_data_t*) block;
 
     int res = FLASH_ERR_OK;
-    int len = 0;
+    unsigned int len = 0;
     cyg_bool bootblock = false;
     cyg_uint32 *bootblocks = (cyg_uint32 *)0;
 
@@ -282,6 +283,32 @@
     ROM = (volatile flash_data_t*) ((unsigned long)block & flash_dev_info->base_mask);
 
 
+#if defined(CYGHWR_DEVS_FLASH_ATMEL_AT49XXXX_ERASE_BUG_WORKAROUND)
+
+    // Before erasing the data, overwrite it with all zeroes. This is a workaround
+    // for a silicon bug that affects erasing of some devices, see
+    // http://www.atmel.com/dyn/resources/prod_documents/doc6076.pdf.
+    for (len = size; (FLASH_ERR_OK == res) && (len > 0); len--, b_p++) {
+        // Program data [byte] - 4 step sequence
+        ROM[FLASH_Setup_Addr1] = FLASH_Setup_Code1;
+        ROM[FLASH_Setup_Addr2] = FLASH_Setup_Code2;
+        ROM[FLASH_Setup_Addr1] = FLASH_Program;
+        *b_p = 0;
+                
+        res = wait_while_busy(5000000, b_p, 0);
+
+        if (*b_p != 0)
+            // Only update return value if operation was OK
+            if (FLASH_ERR_OK == res) res = FLASH_ERR_DRV_VERIFY;
+    }
+    
+    if (FLASH_ERR_OK != res)
+        return res;
+    
+    b_p = (volatile flash_data_t*) block;
+
+#endif // defined(CYGHWR_DEVS_FLASH_ATMEL_AT49XXXX_ERASE_BUG_WORKAROUND)
+
     // Assume not "boot" sector, full size
     bootblock = false;
     len = flash_dev_info->block_size;

-- 
--------------------------------------------------

Thomas Koeller, Software Development
Basler Vision Technologies

thomas dot koeller at baslerweb dot com
http://www.baslerweb.com

==============================


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]