Main Page | Modules | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

# spiflash.h

Go to the documentation of this file.

    00001 /*! \file spiflash.h \brief SPI Flash Memory Driver (M25Pxx/AT25Fxxx/etc). */
    00002 //*****************************************************************************
    00003 //
    00004 // File Name    : 'spiflash.h'
    00005 // Title        : SPI Flash Memory Driver (M25Pxx/AT25Fxxx/etc)
    00006 // Author       : Pascal Stang - Copyright (C) 2006
    00007 // Created      : 2006-04-15
    00008 // Revised      : 2006-07-02
    00009 // Version      : 0.1
    00010 // Target MCU   : ARM processors
    00011 // Editor Tabs  : 4
    00012 //
    00013 // NOTE: This code is currently below version 1.0, and therefore is considered
    00014 // to be lacking in some functionality or documentation, or may not be fully
    00015 // tested.  Nonetheless, you can expect most functions to work.
    00016 //
    00017 //*****************************************************************************
    00018
    00019 #ifndef ARMLIB_SPIFLASH_H
    00020 #define ARMLIB_SPIFLASH_H
    00021
    00022 #include "global.h"
    00023
    00024 // Compatible with:
    00025 // - ST M25Pxx devices
    00026 // - Atmel AT25Fxxx devices
    00027 // - many more
    00028
    00029 // device commands
    00030 #define SPIFLASH_CMD_WREN       0x06    // write enable
    00031 #define SPIFLASH_CMD_WRDI       0x04    // write disable
    00032 #define SPIFLASH_CMD_RDID       0x9F    // read ID register
    00033 #define SPIFLASH_CMD_RDSR       0x05    // read status register
    00034 #define SPIFLASH_CMD_WRSR       0x01    // write status register
    00035 #define SPIFLASH_CMD_READ       0x03    // read
    00036 #define SPIFLASH_CMD_FASTREAD   0x0B    // high-speed read
    00037 #define SPIFLASH_CMD_PAGEPROG   0x02    // page program
    00038 #define SPIFLASH_CMD_SECTERASE  0xD8    // sector erase
    00039 #define SPIFLASH_CMD_CHIPERASE  0xC7    // chip erase
    00040
    00041 // status register bits
    00042 #define SPIFLASH_STATUS_BUSY    0x01    // busy, write in progress
    00043 #define SPIFLASH_STATUS_WEN     0x02    // write enable
    00044 #define SPIFLASH_STATUS_BP0     0x04    // block protect 0
    00045 #define SPIFLASH_STATUS_BP1     0x08    // block protect 1
    00046 #define SPIFLASH_STATUS_BP2     0x10    // block protect 2
    00047 #define SPIFLASH_STATUS_WPEN    0x80    // write protect enabled
    00048
    00049 // device constants
    00050 #define SPIFLASH_PAGESIZE       256     // 256 bytes/page
    00051
    00052 // functions
    00053
    00054 // Initializes spiflash for operation
    00055 void spiflashInit(void);
    00056
    00057 // Get spiflash ID
    00058 // NOTE: supported only on some flash memories
    00059 unsigned short spiflashGetID(void);
    00060
    00061 // Erase entire flash chip
    00062 void spiflashChipErase(void);
    00063
    00064 // Read flash memory
    00065 // - addr may be any value
    00066 // - nbytes may be any value
    00067 void spiflashRead(unsigned long addr, unsigned long nbytes, unsigned char *data);
    00068
    00069 // Write flash memory (automatic handling of page writes)
    00070 // - memory must be previously erased
    00071 // - addr MUST start at a page break
    00072 //  OR
    00073 // - nbytes must be small enough such that page boundary is not crossed
    00074 void spiflashWrite(unsigned long addr, unsigned long nbytes, unsigned char *data);
    00075
    00076 #endif