text
[RRG-proxmark3.git] / armsrc / flashmem.h
blob54a101ea6c7657b4fbab9e2b4f8ffd8dc1e9b9f0
1 /* Arduino SPIFlash Library v.2.5.0
2 * Copyright (C) 2015 by Prajwal Bhattaram
3 * Modified by Prajwal Bhattaram - 13/11/2016
5 * This file is part of the Arduino SPIFlash Library. This library is for
6 * Winbond NOR flash memory modules. In its current form it enables reading
7 * and writing individual data variables, structs and arrays from and to various locations;
8 * reading and writing pages; continuous read functions; sector, block and chip erase;
9 * suspending and resuming programming/erase and powering down for low power operation.
11 * This Library is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
16 * This Library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License v3.0
22 * along with the Arduino SPIFlash Library. If not, see
23 * <http://www.gnu.org/licenses/>.
25 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
26 // Common Instructions //
27 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
28 #ifndef __FLASHMEM_H
29 #define __FLASHMEM_H
31 #include "common.h"
33 // Used Command
34 #define ID 0x90
35 #define MANID 0x90
36 #define JEDECID 0x9F
38 #define READSTAT1 0x05
39 #define READSTAT2 0x35
40 #define WRITESTAT 0x01
42 #define WRITEDISABLE 0x04
43 #define WRITEENABLE 0x06
45 #define READDATA 0x03
46 #define FASTREAD 0x0B
47 #define PAGEPROG 0x02
49 #define SECTORERASE 0x20
50 #define BLOCK32ERASE 0x52
51 #define BLOCK64ERASE 0xD8
52 #define CHIPERASE 0xC7
54 #define UNIQUE_ID 0x4B
56 // Not used or not support command
57 #define RELEASE 0xAB
58 #define POWERDOWN 0xB9
59 #define SUSPEND 0x75
60 #define RESUME 0x7A
62 // Flash busy timeout: 20ms is the strict minimum when writing 256kb
63 #define BUSY_TIMEOUT 200000L
65 #define WINBOND_MANID 0xEF
66 #define WINBOND_DEVID 0x11
67 #define PAGESIZE 0x100
68 #define WINBOND_WRITE_DELAY 0x02
70 #define SPI_CLK 48000000
72 #define BUSY 0x01
73 #define WRTEN 0x02
74 #define SUS 0x40
76 #define DUMMYBYTE 0xEE
77 #define NULLBYTE 0x00
78 #define NULLINT 0x0000
79 #define NO_CONTINUE 0x00
80 #define PASS 0x01
81 #define FAIL 0x00
82 #define maxAddress capacity
84 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
85 // List of Error codes //
86 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
87 #define SUCCESS 0x00
88 #define CALLBEGIN 0x01
89 #define UNKNOWNCHIP 0x02
90 #define UNKNOWNCAP 0x03
91 #define CHIPBUSY 0x04
92 #define OUTOFBOUNDS 0x05
93 #define CANTENWRITE 0x06
94 #define PREVWRITTEN 0x07
95 #define LOWRAM 0x08
96 #define NOSUSPEND 0x09
97 #define UNKNOWNERROR 0xFF
99 // List of blocks
100 #define MAX_BLOCKS 4
101 #define MAX_SECTORS 16
103 //#define FLASH_BAUD 24000000
104 #define FLASH_MINFAST 24000000 //33000000
105 #define FLASH_BAUD MCK/2
106 #define FLASH_FASTBAUD MCK
107 #define FLASH_MINBAUD FLASH_FASTBAUD
109 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
111 void FlashmemSetSpiBaudrate(uint32_t baudrate);
112 bool FlashInit(void);
113 void FlashSetup(uint32_t baudrate);
114 void FlashStop(void);
115 bool Flash_WaitIdle(void);
116 uint8_t Flash_ReadStat1(void);
117 uint8_t Flash_ReadStat2(void);
118 uint16_t FlashSendByte(uint32_t data);
119 void Flash_TransferAdresse(uint32_t address);
121 bool Flash_CheckBusy(uint32_t timeout);
123 void Flash_WriteEnable(void);
124 bool Flash_WipeMemoryPage(uint8_t page);
125 bool Flash_WipeMemory(void);
126 bool Flash_Erase4k(uint8_t block, uint8_t sector);
127 //bool Flash_Erase32k(uint32_t address);
128 bool Flash_Erase64k(uint8_t block);
130 void Flash_UniqueID(uint8_t *uid);
131 uint8_t Flash_ReadID(void);
132 uint16_t Flash_ReadData(uint32_t address, uint8_t *out, uint16_t len);
133 uint16_t Flash_ReadDataCont(uint32_t address, uint8_t *out, uint16_t len);
134 uint16_t Flash_Write(uint32_t address, uint8_t *in, uint16_t len);
135 uint16_t Flash_WriteData(uint32_t address, uint8_t *in, uint16_t len);
136 uint16_t Flash_WriteDataCont(uint32_t address, uint8_t *in, uint16_t len);
137 void Flashmem_print_status(void);
138 void Flashmem_print_info(void);
139 uint16_t FlashSendLastByte(uint32_t data);
141 #endif