10
10
11
11
namespace QA350
12
12
{
13
- /*
14
- static class Crc16
15
- {
16
- const ushort polynomial = 0xA001;
17
- static readonly ushort[] table = new ushort[256];
18
-
19
- public static ushort ComputeChecksum(byte[] bytes, int len)
20
- {
21
- ushort crc = 0;
22
- for (int i = 0; i < len; ++i)
23
- {
24
- byte index = (byte)(crc ^ bytes[i]);
25
- crc = (ushort)((crc >> 8) ^ table[index]);
26
- }
27
- return crc;
28
- }
29
-
30
- static Crc16()
31
- {
32
- ushort value;
33
- ushort temp;
34
- for (ushort i = 0; i < table.Length; ++i)
35
- {
36
- value = 0;
37
- temp = i;
38
- for (byte j = 0; j < 8; ++j)
39
- {
40
- if (((value ^ temp) & 0x0001) != 0)
41
- {
42
- value = (ushort)((value >> 1) ^ polynomial);
43
- }
44
- else
45
- {
46
- value >>= 1;
47
- }
48
- temp >>= 1;
49
- }
50
- table[i] = value;
51
- }
52
- }
53
- }*/
13
+
54
14
55
15
static class Bootloader
56
16
{
@@ -69,18 +29,6 @@ static class Bootloader
69
29
70
30
static public void EnterBootloader ( )
71
31
{
72
- /*
73
- // 1 + 51 bytes
74
- byte[] data = new byte[1 + 51];
75
-
76
- data[0] = 0x11; // CMD = RX Password
77
-
78
- for (int i=1; i<1+51; i++)
79
- {
80
- data[i] = 0xFF;
81
- }
82
- */
83
-
84
32
OpenFileDialog ofd = new OpenFileDialog ( ) ;
85
33
ofd . Filter = "Text Files|*.txt" ;
86
34
ofd . Title = "Enter flash file" ;
@@ -113,7 +61,7 @@ static public void EnterBootloader()
113
61
Thread . Sleep ( 4000 ) ;
114
62
Hardware . OpenBSL ( ) ;
115
63
Thread . Sleep ( 1000 ) ;
116
- Console . WriteLine ( "BSL Version: " + GetBSLVersion ( ) . ToString ( "X" ) ) ;
64
+ Debug . WriteLine ( "BSL Version: " + GetBSLVersion ( ) . ToString ( "X" ) ) ;
117
65
118
66
// Erase everything
119
67
MassErase ( ) ;
@@ -179,7 +127,6 @@ static int GetBSLVersion()
179
127
Debug . WriteLine ( "GetBSLVersion() failed" ) ;
180
128
return 0 ;
181
129
}
182
-
183
130
}
184
131
185
132
static void MassErase ( )
@@ -203,6 +150,15 @@ static void MassErase()
203
150
204
151
}
205
152
153
+ /// <summary>
154
+ /// Parses the specified ram-based bootloader file (provided by TI) and sends
155
+ /// it down to the MSP430, and then execute the ram-based file. This is needed
156
+ /// because the resident bootloader in the MSP430F5529 doesn't have all the
157
+ /// functionality needed for a full-reflash.
158
+ /// </summary>
159
+ /// <param name="fileName"></param>
160
+ /// <param name="fastWrite"></param>
161
+ /// <returns></returns>
206
162
static bool WriteFlash ( string fileName , Boolean fastWrite )
207
163
{
208
164
byte [ ] lastArray = null ;
@@ -243,7 +199,7 @@ static bool WriteFlash(string fileName, Boolean fastWrite)
243
199
{
244
200
if ( WriteBytesFast ( address , data ) )
245
201
{
246
- //Console .WriteLine(string.Format("Fast Write Line: {0} Address: 0x{1:X}", i, address));
202
+ //Debug .WriteLine(string.Format("Fast Write Line: {0} Address: 0x{1:X}", i, address));
247
203
}
248
204
}
249
205
else
@@ -253,19 +209,19 @@ static bool WriteFlash(string fileName, Boolean fastWrite)
253
209
{
254
210
lastAddress = address ;
255
211
lastArray = data ;
256
- Console . WriteLine ( string . Format ( "Reset vector found: 0x{0:X}" , lastAddress ) ) ;
212
+ Debug . WriteLine ( string . Format ( "Reset vector found: 0x{0:X}" , lastAddress ) ) ;
257
213
258
214
resetAddr = ( data [ 0xFFFF - address ] << 8 ) + ( data [ 0xFFFE - address ] ) ;
259
215
}
260
216
else
261
217
{
262
218
if ( WriteBytes ( address , data ) )
263
219
{
264
- Console . WriteLine ( string . Format ( "Line: {0} Address: 0x{1:X} Len: {2}" , i , address , data . Length ) ) ;
220
+ Debug . WriteLine ( string . Format ( "Line: {0} Address: 0x{1:X} Len: {2}" , i , address , data . Length ) ) ;
265
221
}
266
222
else
267
223
{
268
- Console . WriteLine ( string . Format ( "ERROR: Line: {0} Address: 0x{1:X}" , i , address ) ) ;
224
+ Debug . WriteLine ( string . Format ( "ERROR: Line: {0} Address: 0x{1:X}" , i , address ) ) ;
269
225
}
270
226
}
271
227
}
@@ -278,12 +234,12 @@ static bool WriteFlash(string fileName, Boolean fastWrite)
278
234
{
279
235
if ( WriteBytes ( lastAddress , lastArray ) )
280
236
{
281
- Console . WriteLine ( string . Format ( "Reset vector written. Address: 0x{0:X} Len: {1}" , lastAddress , lastArray . Length ) ) ;
237
+ Debug . WriteLine ( string . Format ( "Reset vector written. Address: 0x{0:X} Len: {1}" , lastAddress , lastArray . Length ) ) ;
282
238
Thread . Sleep ( 100 ) ;
283
239
SetPC ( resetAddr ) ;
284
240
}
285
241
else
286
- Console . WriteLine ( "Failed to write reset vector" ) ;
242
+ Debug . WriteLine ( "Failed to write reset vector" ) ;
287
243
}
288
244
289
245
return true ;
@@ -361,7 +317,7 @@ static bool WriteBytes(int address, byte[] data)
361
317
}
362
318
else
363
319
{
364
- Console . WriteLine ( string . Format ( "Write failed. Message0 0x{0:x} Message1 0x{1:x}" , recvBuf [ 0 ] , recvBuf [ 1 ] ) ) ;
320
+ Debug . WriteLine ( string . Format ( "Write failed. Message0 0x{0:x} Message1 0x{1:x}" , recvBuf [ 0 ] , recvBuf [ 1 ] ) ) ;
365
321
}
366
322
367
323
0 commit comments