Sensorian  1.0
C API Reference Guide Library
S25FL204K.h
Go to the documentation of this file.
1 /****************************************************************************
2  * Copyright (C) 2015 Sensorian
3  * *
4  * This file is part of Sensorian. *
5  * *
6  * Sensorian is free software: you can redistribute it and/or modify it *
7  * under the terms of the GNU Lesser General Public License as published *
8  * by the Free Software Foundation, either version 3 of the License, or *
9  * (at your option) any later version. *
10  * *
11  * Sensorian is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14  * GNU Lesser General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU Lesser General Public *
17  * License along with Sensorian. *
18  * If not, see <http://www.gnu.org/licenses/>. *
19  ****************************************************************************/
20 
28 #ifndef S25FL204K_H
29 #define S25FL204K_H
30 
31 #include "bcm2835.h"
32 
33 /******************************* Commands ************************************/
34 #define CMD_RDSR1 (unsigned char) 0x05
35 #define CMD_RDSR2 (unsigned char) 0x35
36 #define CMD_RDSR3 (unsigned char) 0x33
37 #define CMD_WREN (unsigned char) 0x06
38 #define CMD_EWSR (unsigned char) 0x50 //write enable volatile
39 #define CMD_WRDI (unsigned char) 0x04
40 #define CMD_SETBURST (unsigned char) 0x77
41 #define PAGE_PROGRAM (unsigned char) 0x02
42 
43 #define CMD_READ_DATA (unsigned char) 0x03
44 #define CMD_READ_HS (unsigned char) 0x0B
45 
46 #define ERASE_SECTOR (unsigned char) 0x20
47 #define ERASE_BLOCK32 (unsigned char) 0x52
48 #define ERASE_BLOCK64 (unsigned char) 0xD8
49 #define ERASE_CHIP (unsigned char) 0x60
50 
51 #define CMD_DEEPSLP (unsigned char) 0xB9
52 #define CMD_RESDPD (unsigned char) 0xAB //release from sleep
53 #define CMD_RDID (unsigned char) 0x90
54 #define JEDEC (unsigned char) 0x9F
55 #define CMD_RDSFDP (unsigned char) 0x5A
56 #define CMD_RDSECREG (unsigned char) 0x48
57 #define CMD_ERSECREG (unsigned char) 0x44 //erase security reg
58 #define CMD_EHLD (unsigned char) 0xAA
59 
60 #define S64MANID (unsigned char) 0x01
61 #define S64DEVID (unsigned char) 0x16
62 
63 #define CMD_RSID (unsigned char) 0x88
64 #define CMD_PSID (unsigned char) 0xA5
65 #define CMD_LSID (unsigned char) 0x85
66 
67  //resume from deep sleep
68 #define CMD_WRSR (unsigned char) 0x01 //write status register
69 #define STAT_REG1 (unsigned char) 0x05 //status register number one
70 #define STAT_REG2 (unsigned char) 0x35 //status register number two
71 #define STAT_REG3 (unsigned char) 0x33 //status register mumber three
72 
73 /***********************Memory map*********************************************/
74 
75 //sector 4 kbyte
76 //block 64 kbyte
77 
78 #define SECTOR_SIZE 4096 //0x000-0xfff
79 #define SECTOR_COUNT 128
80 #define PAGE_NUM 2048 //16 pages per sector
81 #define PAGE_INCR 0x100 //256 bytes
82 
83 
84 /******************************** Chip Pins ***********************************/
85 
86 #define CE_OUTPUT() bcm2835_gpio_fsel(RPI_V2_GPIO_P1_26,BCM2835_GPIO_FSEL_OUTP); //Set CE0 as output
87 #define CE_DESELECT() bcm2835_gpio_write(RPI_V2_GPIO_P1_26, HIGH);
88 #define CE_SELECT() bcm2835_gpio_write(RPI_V2_GPIO_P1_26, LOW);
89 
90 
91 void S25FL_Setup(void);
92 void S25FL_WriteByte(unsigned char data, unsigned long address);
93 unsigned char S25FL_ReadByte(unsigned long address);
94 void S25FL_WriteArray(unsigned long address, unsigned char* pData, unsigned int arrayLength);
95 void S25FL_ReadArray(unsigned long address, unsigned char* pData, unsigned int arrayLength);
96 
97 void S25FL_ReadPage(unsigned long page,unsigned char buffer[]);
98 
99 unsigned long S25FL_Jedec_ID_Read();
100 unsigned int S25FL_ReadID();
101 
102 void S25FL_ChipErase(void);
103 void S25FL_SectorErase(unsigned long address);
104 void S25FL_BlockErase(unsigned long address);
105 
106 void S25FL_SetBlockProtection(unsigned char prot);
107 void S25FL_WriteEnable();
108 unsigned char S25FL_IsWriteBusy();
109 
110 unsigned char S25FL_SReg_Read(unsigned char statReg);
111 void S25FL_SReg_Write(unsigned char statReg);
112 
113 void S25FL_DeepSleep(void);
114 void S25FL_WakeUp(void);
115 
116 #endif /* S25FL204K_H */
117 
void S25FL_WriteEnable()
unsigned char buffer[256]
Definition: main.c:74
void S25FL_ChipErase(void)
Erase all chip contents. Erase is slow on flash chips.
Definition: S25FL204K.c:195
void S25FL_Setup(void)
Setup SPI and IOs connected to Serial FLASH.
Definition: S25FL204K.c:39
void S25FL_WakeUp(void)
Wakes the flash memory chip from deep sleep mode.
Definition: S25FL204K.c:306
void S25FL_SectorErase(unsigned long address)
This function erases a 4Kb sector (it erase a page actually)
Definition: S25FL204K.c:211
void S25FL_SetBlockProtection(unsigned char prot)
Sets the block protection of the chip.
Definition: S25FL204K.c:318
void S25FL_WriteArray(unsigned long address, unsigned char *pData, unsigned int arrayLength)
Write data array at the specified address , this procedure does page programming. The destination add...
Definition: S25FL204K.c:97
unsigned int S25FL_ReadID()
This function reads the Manufacturer ID code This procedure Reads the manufacturer's ID and device ID...
Definition: S25FL204K.c:156
void S25FL_ReadPage(unsigned long page, unsigned char buffer[])
void S25FL_WriteByte(unsigned char data, unsigned long address)
Write a byte to the address specified (24 bit address)
Definition: S25FL204K.c:51
unsigned char S25FL_IsWriteBusy()
This function reads status register and checks BUSY bit for a write in progress operation.It waits until the device is no longer busy.
Definition: S25FL204K.c:248
unsigned char S25FL_ReadByte(unsigned long address)
Read a byte from the specified 24 bit address.
Definition: S25FL204K.c:76
void S25FL_SReg_Write(unsigned char statReg)
This procedure writes a byte to the Status Register.
Definition: S25FL204K.c:279
unsigned char S25FL_SReg_Read(unsigned char statReg)
Read specific Status Register depending on value of statReg.
Definition: S25FL204K.c:264
void S25FL_BlockErase(unsigned long address)
This function erases a 64Kb block.
Definition: S25FL204K.c:230
unsigned long S25FL_Jedec_ID_Read()
This procedure Reads the manufacturer's ID (BFh), memory type (25h) and device ID (4Bh)...
Definition: S25FL204K.c:177
void S25FL_ReadArray(unsigned long address, unsigned char *pData, unsigned int arrayLength)
Read an array of data from the given address.
Definition: S25FL204K.c:129
void S25FL_DeepSleep(void)
Puts the flash chip into deep sleep mode.
Definition: S25FL204K.c:295
unsigned long address
Definition: main.c:76