hf mf sim: remove mention of non-existing option
[RRG-proxmark3.git] / common_arm / flashmem.h
blob127ea43b09dce4038693e009e42a97365ed35b3f
1 //-----------------------------------------------------------------------------
2 // Borrowed initially from Arduino SPIFlash Library v.2.5.0
3 // Copyright (C) 2015 by Prajwal Bhattaram.
4 //
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // See LICENSE.txt for the text of the license.
16 //-----------------------------------------------------------------------------
17 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
18 // Common Instructions //
19 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
20 #ifndef __FLASHMEM_H
21 #define __FLASHMEM_H
23 #include "common.h"
25 // Used Command
26 #define ID 0x90
27 #define MANID 0x90
28 #define JEDECID 0x9F
30 #define READSTAT1 0x05
31 #define READSTAT2 0x35
32 #define WRITESTAT 0x01
34 #define WRITEDISABLE 0x04
35 #define WRITEENABLE 0x06
37 #define READDATA 0x03
38 #define FASTREAD 0x0B
39 #define PAGEPROG 0x02
41 #define SECTORERASE 0x20
42 #define BLOCK32ERASE 0x52
43 #define BLOCK64ERASE 0xD8
44 #define CHIPERASE 0xC7
46 #define UNIQUE_ID 0x4B
48 // Not used or not support command
49 #define RELEASE 0xAB
50 #define POWERDOWN 0xB9
51 #define SUSPEND 0x75
52 #define RESUME 0x7A
54 // Flash busy timeout: 20ms is the strict minimum when writing 256kb
55 #define BUSY_TIMEOUT 200000L
57 #define WINBOND_MANID 0xEF
58 #define WINBOND_32MB_DEVID 0x15
59 #define WINBOND_16MB_DEVID 0x14
60 #define WINBOND_8MB_DEVID 0x13
61 #define WINBOND_4MB_DEVID 0x12
62 #define WINBOND_2MB_DEVID 0x11
63 #define WINBOND_1MB_DEVID 0x10
64 #define WINBOND_512KB_DEVID 0x05
66 #define PAGESIZE 0x100
67 #define WINBOND_WRITE_DELAY 0x02
69 #define SPI_CLK 48000000
71 #define BUSY 0x01
72 #define WRTEN 0x02
73 #define SUS 0x40
75 #define DUMMYBYTE 0xEE
76 #define NULLBYTE 0x00
77 #define NULLINT 0x0000
78 #define NO_CONTINUE 0x00
79 #define PASS 0x01
80 #define FAIL 0x00
81 #define maxAddress capacity
83 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
84 // List of Error codes //
85 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
86 #define SUCCESS 0x00
87 #define CALLBEGIN 0x01
88 #define UNKNOWNCHIP 0x02
89 #define UNKNOWNCAP 0x03
90 #define CHIPBUSY 0x04
91 #define OUTOFBOUNDS 0x05
92 #define CANTENWRITE 0x06
93 #define PREVWRITTEN 0x07
94 #define LOWRAM 0x08
95 #define NOSUSPEND 0x09
96 #define UNKNOWNERROR 0xFF
98 // List of blocks
99 #define MAX_BLOCKS 4
100 #define MAX_SECTORS 16
102 //#define FLASH_BAUD 24000000
103 #define FLASH_MINFAST 24000000 //33000000
104 #define FLASH_BAUD MCK/2
105 #define FLASH_FASTBAUD MCK
106 #define FLASH_MINBAUD FLASH_FASTBAUD
108 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
110 bool FlashInit(void);
111 void Flash_UniqueID(uint8_t *uid);
112 void FlashStop(void);
114 void FlashSetup(uint32_t baudrate);
115 bool Flash_CheckBusy(uint32_t timeout);
116 uint8_t Flash_ReadStat1(void);
117 uint16_t FlashSendByte(uint32_t data);
118 uint16_t FlashSendLastByte(uint32_t data);
121 #ifndef AS_BOOTROM
122 void FlashmemSetSpiBaudrate(uint32_t baudrate);
123 bool Flash_WaitIdle(void);
124 void Flash_TransferAdresse(uint32_t address);
126 void Flash_WriteEnable(void);
127 bool Flash_WipeMemoryPage(uint8_t page);
128 bool Flash_WipeMemory(void);
129 bool Flash_Erase4k(uint8_t block, uint8_t sector);
130 //bool Flash_Erase32k(uint32_t address);
131 bool Flash_Erase64k(uint8_t block);
133 typedef struct {
134 uint8_t manufacturer_id;
135 uint8_t device_id;
136 uint8_t device_id2;
137 } flash_device_type_t; // extra device_id used for the JEDEC ID read via cmd 9F
138 bool Flash_ReadID(flash_device_type_t *result, bool read_jedec);
140 uint16_t Flash_ReadData(uint32_t address, uint8_t *out, uint16_t len);
141 uint16_t Flash_ReadDataCont(uint32_t address, uint8_t *out, uint16_t len);
142 uint16_t Flash_Write(uint32_t address, uint8_t *in, uint16_t len);
143 uint16_t Flash_WriteData(uint32_t address, uint8_t *in, uint16_t len);
144 uint16_t Flash_WriteDataCont(uint32_t address, uint8_t *in, uint16_t len);
145 void Flashmem_print_status(void);
146 void Flashmem_print_info(void);
148 #endif // #ifndef AS_BOOTROM
151 #endif