Release v4.15864 - Radium
[RRG-proxmark3.git] / armsrc / flashmem.h
blob2b829c3780887f3bbeeaea1cbfbc42e99d2ce7b2
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_DEVID 0x11
59 #define PAGESIZE 0x100
60 #define WINBOND_WRITE_DELAY 0x02
62 #define SPI_CLK 48000000
64 #define BUSY 0x01
65 #define WRTEN 0x02
66 #define SUS 0x40
68 #define DUMMYBYTE 0xEE
69 #define NULLBYTE 0x00
70 #define NULLINT 0x0000
71 #define NO_CONTINUE 0x00
72 #define PASS 0x01
73 #define FAIL 0x00
74 #define maxAddress capacity
76 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
77 // List of Error codes //
78 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
79 #define SUCCESS 0x00
80 #define CALLBEGIN 0x01
81 #define UNKNOWNCHIP 0x02
82 #define UNKNOWNCAP 0x03
83 #define CHIPBUSY 0x04
84 #define OUTOFBOUNDS 0x05
85 #define CANTENWRITE 0x06
86 #define PREVWRITTEN 0x07
87 #define LOWRAM 0x08
88 #define NOSUSPEND 0x09
89 #define UNKNOWNERROR 0xFF
91 // List of blocks
92 #define MAX_BLOCKS 4
93 #define MAX_SECTORS 16
95 //#define FLASH_BAUD 24000000
96 #define FLASH_MINFAST 24000000 //33000000
97 #define FLASH_BAUD MCK/2
98 #define FLASH_FASTBAUD MCK
99 #define FLASH_MINBAUD FLASH_FASTBAUD
101 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
103 void FlashmemSetSpiBaudrate(uint32_t baudrate);
104 bool FlashInit(void);
105 void FlashSetup(uint32_t baudrate);
106 void FlashStop(void);
107 bool Flash_WaitIdle(void);
108 uint8_t Flash_ReadStat1(void);
109 uint8_t Flash_ReadStat2(void);
110 uint16_t FlashSendByte(uint32_t data);
111 void Flash_TransferAdresse(uint32_t address);
113 bool Flash_CheckBusy(uint32_t timeout);
115 void Flash_WriteEnable(void);
116 bool Flash_WipeMemoryPage(uint8_t page);
117 bool Flash_WipeMemory(void);
118 bool Flash_Erase4k(uint8_t block, uint8_t sector);
119 //bool Flash_Erase32k(uint32_t address);
120 bool Flash_Erase64k(uint8_t block);
122 void Flash_UniqueID(uint8_t *uid);
123 uint8_t Flash_ReadID(void);
124 uint16_t Flash_ReadData(uint32_t address, uint8_t *out, uint16_t len);
125 uint16_t Flash_ReadDataCont(uint32_t address, uint8_t *out, uint16_t len);
126 uint16_t Flash_Write(uint32_t address, uint8_t *in, uint16_t len);
127 uint16_t Flash_WriteData(uint32_t address, uint8_t *in, uint16_t len);
128 uint16_t Flash_WriteDataCont(uint32_t address, uint8_t *in, uint16_t len);
129 void Flashmem_print_status(void);
130 void Flashmem_print_info(void);
131 uint16_t FlashSendLastByte(uint32_t data);
133 #endif