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
77
78
79
80
81
82
83
|
#include "main.h"
#include "dumper.h"
#include "comm.h"
#include "led.h"
static void unrom512_cmd_write(uint32_t address, uint8_t data)
{
PRG(0xC000) = address >> 14;
PRG(0x8000 | (address & 0x3FFF)) = data;
}
static uint8_t unrom512_cmd_read(uint32_t address)
{
PRG(0xC000) = address >> 14;
return PRG(0x8000 | (address & 0x3FFF));
}
void erase_unrom512()
{
led_yellow();
unrom512_cmd_write(0x0000, 0xF0);
unrom512_cmd_write(0x5555, 0xAA);
unrom512_cmd_write(0x2AAA, 0x55);
unrom512_cmd_write(0x5555, 0x80);
unrom512_cmd_write(0x5555, 0xAA);
unrom512_cmd_write(0x2AAA, 0x55);
unrom512_cmd_write(0x5555, 0x10);
uint32_t start_time = HAL_GetTick();
// waiting for result
uint8_t ff_count = 0;
while (1)
{
if (HAL_GetTick() >= start_time + 5000) // 5 seconds timeout
{
// timeout
comm_start(COMMAND_FLASH_ERASE_TIMEOUT, 0);
break;
}
if (PRG(0x8000) != 0xFF)
ff_count = 0;
else
ff_count++;
if (ff_count >= 2)
{
// OK
comm_start(COMMAND_PRG_WRITE_DONE, 0);
break;
}
}
}
void write_unrom512(uint32_t address, uint16_t len, uint8_t *data)
{
led_red();
PRG(0x8000 | 0x0000) = 0xF0;
while (len > 0)
{
unrom512_cmd_write(0x5555, 0xAA);
unrom512_cmd_write(0x2AAA, 0x55);
unrom512_cmd_write(0x5555, 0xA0);
unrom512_cmd_write(address, *data);
uint32_t start_time = HAL_GetTick();
// waiting for result
while (1)
{
if (HAL_GetTick() >= start_time + 50) // 50 ms timeout
{
// timeout
comm_start(COMMAND_FLASH_WRITE_TIMEOUT, 0);
return;
}
uint8_t read_1 = unrom512_cmd_read(address);
uint8_t read_2 = unrom512_cmd_read(address);
if ((read_1 == read_2) && (read_2 == *data)) break; // OK
}
address++;
data++;
len--;
}
comm_start(COMMAND_PRG_WRITE_DONE, 0);
}
|