Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed USBMSD_SD USBDevice
Diff: USBDevice/USBMSD/AT45.h
- Revision:
- 2:27a7e7f8d399
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/USBDevice/USBMSD/AT45.h Fri Nov 11 15:22:53 2011 +0000
@@ -0,0 +1,103 @@
+/* mbed Library - AT45
+ * Copyright (c) 2008, cstyles
+
+
+Class to make the AT45 SPI flash parts from ATMEL appear as SRAM or 512 byte block devices
+
+This class supports 011,021,041,081,161,321,641 variants of the AT45DBxxx family
+
+|| Code || Density || Page size || Pages || Package ||
+|| 011 || 1 || 256 || 512 || 8 SOIC ||
+|| 021 || 2 || 256 || 1024 || 8 SOIC ||
+|| 041 || 4 || 256 || 2048 || 8 SOIC ||
+|| 081 || 8 || 256 || 4096 || 8 SOIC ||
+|| 161 || 16 || 512 || 4096 || 8 SOIC ||
+|| 321 || 32 || 512 || 8192 || 8 SOIC ||
+|| 641 || 64 || 1024 || 8192 || 28 TSOP ||
+
+To do :
+
+ - Check for current status on Erase Chip command not working.
+
+ */
+
+#ifndef MBED_AT45_H
+#define MBED_AT45_H
+
+#include "mbed.h"
+
+class AT45 {
+
+ // Public functions
+ public:
+
+ AT45(PinName mosi = p5, PinName miso = p6, PinName clk = p7, PinName ncs = p8);
+
+ void erase (void);
+
+ // Integer RAM access
+ char read (int address); // read int from address. Automatically word-aligns address
+ void write (int address, char data); // Write int to address. Automatically world-aligns address
+
+ // Block device access
+ int blocks (void); // returns the number of 512 byte blocks
+ int blockread (char* data, int block); // read a block
+ int blockwrite (char* data, int block); // write a block
+ int blockerase (int block); // erase a block
+
+ // Part interrogation
+ int size (void); // Device size in bytes
+ int pages (void); // Device size in bytes
+ int pagesize (void); // Device size in bytes
+
+ int id (void); // ID of part
+ int status (void); // Status register
+ void pollbusy (void); // Wait until Flash is not busy
+
+ // Private variables
+ private :
+
+ SPI _spi;
+ DigitalOut _ncs;
+
+ int _pages; // Integer number of pages
+ int _pagesize; // page size, in bytes
+ int _devicesize; // device size in bytes
+ int _blocks; // Number of 512 byte blocks
+
+ // Some flags for buffering
+ int _buffer1address;
+ int _buffer2address;
+ int _lru;
+
+ // Helper routunes
+ void _reset();
+ void _select();
+ void _deselect();
+ void _pollbusy (void);
+
+ // accessing SRAM buffers
+ void _sramwrite (int buffer, int address, int data);
+ int _sramread (int buffer, int address);
+
+ // Transferring SRAM buffers to/from FLASH
+ void _flashwrite (int buffer, int paddr);
+ void _flashread (int buffer, int paddr);
+
+ // Allocate buffer
+ int _allocatebuffer(int address);
+ void _flushbuffer(int buffer);
+
+ // Reading FLASH directly
+ int _memread (int address);
+
+ // Calculate page/subpage addresses
+ int _getpaddr (int);
+ int _getbaddr (int);
+
+ // Send 3 byte address
+ void _sendaddr (int address);
+
+};
+
+#endif