blob: 6d60a217c5c0dfff4039330b0b59ecabe7f63b7f (
plain)
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
#include "Logger.hpp"
#include "ExitCodes.hpp"
#include "McuSt10f168.hpp"
#include "fw_st10f168.hpp"
#include <sstream>
using FwSt10f168::fw_st10f168;
using FwSt10f168::fw_st10f168_length;
#define ST10F168_FLASH_SIZE (256 * 1024)
#define ST10F168_IDMANUF 0x0400
#define ST10F168_IDCHIP 0x0A80
#define ST10F168_ERASE_TIMEOUT 15000 // Ms
#define ST10F168_MIN_PERIOD 30 // ns
#define ST10F168_MAX_PERIOD 199 // ns
#define ST10F168_MAX_FREQ 25 // MHz
using std::ostringstream;
bool
CMcuSt10f168::hasThisId(uint16_t idmanuf, uint16_t idchip)
{
// Mask out revision bits 3 - 0 from idchip value
return ((idmanuf == ST10F168_IDMANUF)
&& ((idchip & 0xfff0) == ST10F168_IDCHIP));
}
CMcuSt10f168::CMcuSt10f168()
{
mBlockSizes.push_back(16);
mBlockSizes.push_back(48);
mBlockSizes.push_back(96);
mBlockSizes.push_back(96);
}
CMcuSt10f168::~CMcuSt10f168()
{
;
}
string
CMcuSt10f168::getName()
{
return string("ST10F168");
}
uint8_t *
CMcuSt10f168::getFirmware()
{
return fw_st10f168;
}
int
CMcuSt10f168::getFirmwareLength()
{
return fw_st10f168_length;
}
const list<uint32_t>
CMcuSt10f168::getBlockSizes()
{
return mBlockSizes;
}
uint32_t
CMcuSt10f168::getFlashSize()
{
return ST10F168_FLASH_SIZE;
}
int
CMcuSt10f168::getEraseTimeout()
{
return ST10F168_ERASE_TIMEOUT;
}
string
CMcuSt10f168::getMessageForRetCode(uint16_t ret)
{
string s;
switch (ret) {
case 0x00:
s = "Operation was successful";
break;
case 0x01:
s = "Flash Protection is active";
break;
case 0x02:
s = "Vpp voltage not present";
break;
case 0x03:
s = "Programming operation failed";
break;
case 0x04:
s = "Address value (R1) incorrect; not in Flash address area or odd";
break;
case 0x05:
s = "CPU period out of range (must be between 30 ns and 199 ns)";
break;
case 0x06:
s = "Not enough free space on system stack for proper operation";
break;
case 0x07:
s = "Incorrect bank number (R2,R3) specified";
break;
case 0x08:
s = "Erase operation failed (phase 1)";
break;
case 0x09:
s = "Bad source address for Multiple Word programming command";
break;
case 0x0A:
s = "Bad number of words to be copied in Multiple Word programming command; one destination will be out of FLASH";
break;
case 0x0B:
s = "PLL Unlocked or Oscilator watchdog overflow occured during programming or erasing the FLASH";
break;
case 0x0C:
s = "Erase operation failed (phase 2)";
break;
case 0x0D:
s = "MCU serial buffer overrun, use lower serial speed";
break;
case 0xFF:
s = "Unknown or bad command";
break;
default:
s = "";
break;
}
return s;
}
const list<uint16_t>
CMcuSt10f168::getConfigData(float mcuFrequency)
{
list<uint16_t> ret;
ret.push_back(get2TclConst(mcuFrequency));
return ret;
}
uint16_t
CMcuSt10f168::get2TclConst(float mcuFrequency)
{
if (mcuFrequency > ST10F168_MAX_FREQ) {
ostringstream os;
os << "User-entered CPU frequency " << mcuFrequency << " MHz is outside range ";
os << "(0, " << ST10F168_MAX_FREQ << "]";
CLogger::error(os.str(), EXIT_MCU);
}
uint16_t t = ((uint16_t) (1000.0 / mcuFrequency)) + 1;
if (t > 200) {
ostringstream os;
os << "For user-entered CPU frequency " << mcuFrequency << "MHz";
os << " the period is " << t << " ns which is greater than maximal allowed ";
os << "period " << ST10F168_MAX_PERIOD << " ns. Setting period to ";
os << ST10F168_MAX_PERIOD << " ns";
CLogger::warning(os.str());
t = ST10F168_MAX_PERIOD;
} else if (t < 30) {
ostringstream os;
os << "For user-entered CPU frequency " << mcuFrequency << "MHz";
os << " the period is " << t << " ns which is lower than minmal allowed ";
os << "period " << ST10F168_MIN_PERIOD << " ns. Setting period to ";
os << ST10F168_MIN_PERIOD << " ns";
CLogger::warning(os.str());
t = ST10F168_MIN_PERIOD;
}
return t;
}
|