-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathFM25Q16A_SS.pas
76 lines (59 loc) · 1.62 KB
/
FM25Q16A_SS.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// FM25Q16A
// Modified https://github.com/nofeletru/UsbAsp-flash/blob/master/scripts/GPR25L3203F_OTP.pas
{$readUID} // Read Unique ID
begin
if not SPIEnterProgMode(_SPI_SPEED_MAX) then LogPrint('Error setting SPI speed');
SPIWrite(0, 5, $4B, 0,0,0,0);
SPIReadToEditor(1, 8);
SPIExitProgMode();
end
{$eraseSS} // Erase Security Sector
begin
if not SPIEnterProgMode(_SPI_SPEED_MAX) then LogPrint('Error setting SPI speed');
SPIWrite(1, 1, $06); // Write Enable
SPIWrite(0, 4, $44, 0,0,0);
//Busy?
sreg := 0;
repeat
SPIWrite(0, 1, $05);
SPIRead(1, 1, sreg);
until((sreg and 1) <> 1);
SPIExitProgMode();
end
{$readSS} // Read Security Sector
begin
if not SPIEnterProgMode(_SPI_SPEED_MAX) then LogPrint('Error setting SPI speed');
PageSize := 256;
SectorSize := 1024;
ProgressBar(0, (SectorSize / PageSize)-1, 0);
for i:=0 to (SectorSize / PageSize)-1 do
begin
SPIWrite(0, 5, $48, 0,0,i,0);
SPIReadToEditor(1, PageSize);
ProgressBar(1);
end;
ProgressBar(0, 0, 0);
SPIExitProgMode();
end
{$writeSS} // Write Security Sector
begin
if not SPIEnterProgMode(_SPI_SPEED_MAX) then LogPrint('Error setting SPI speed');
PageSize := 256;
SectorSize := 1024;
ProgressBar(0, (SectorSize / PageSize)-1, 0);
for i:=0 to (SectorSize / PageSize)-1 do
begin
SPIWrite(1, 1, $06); // Write Enable
SPIWrite(0, 4, $42, 0,0,i);
SPIWriteFromEditor(1, PageSize, i*PageSize); // Write Data
//Busy?
sreg := 0;
repeat
SPIWrite(0, 1, $05);
SPIRead(1, 1, sreg);
until((sreg and 1) <> 1);
ProgressBar(1);
end;
ProgressBar(0, 0, 0);
SPIExitProgMode();
end