Skip to content

Commit 2dbd665

Browse files
author
QuantAsylum
committed
Various cleanup
Signed-off-by: QuantAsylum <git@quantasylum.com>
1 parent 89f5c28 commit 2dbd665

File tree

7 files changed

+30
-570
lines changed

7 files changed

+30
-570
lines changed

Application/QA350/QA350/Bootloader.cs

Lines changed: 18 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -10,47 +10,7 @@
1010

1111
namespace QA350
1212
{
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+
5414

5515
static class Bootloader
5616
{
@@ -69,18 +29,6 @@ static class Bootloader
6929

7030
static public void EnterBootloader()
7131
{
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-
8432
OpenFileDialog ofd = new OpenFileDialog();
8533
ofd.Filter = "Text Files|*.txt";
8634
ofd.Title = "Enter flash file";
@@ -113,7 +61,7 @@ static public void EnterBootloader()
11361
Thread.Sleep(4000);
11462
Hardware.OpenBSL();
11563
Thread.Sleep(1000);
116-
Console.WriteLine("BSL Version: " + GetBSLVersion().ToString("X"));
64+
Debug.WriteLine("BSL Version: " + GetBSLVersion().ToString("X"));
11765

11866
// Erase everything
11967
MassErase();
@@ -179,7 +127,6 @@ static int GetBSLVersion()
179127
Debug.WriteLine("GetBSLVersion() failed");
180128
return 0;
181129
}
182-
183130
}
184131

185132
static void MassErase()
@@ -203,6 +150,15 @@ static void MassErase()
203150

204151
}
205152

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>
206162
static bool WriteFlash(string fileName, Boolean fastWrite)
207163
{
208164
byte[] lastArray = null;
@@ -243,7 +199,7 @@ static bool WriteFlash(string fileName, Boolean fastWrite)
243199
{
244200
if (WriteBytesFast(address, data))
245201
{
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));
247203
}
248204
}
249205
else
@@ -253,19 +209,19 @@ static bool WriteFlash(string fileName, Boolean fastWrite)
253209
{
254210
lastAddress = address;
255211
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));
257213

258214
resetAddr = (data[0xFFFF - address] << 8) + (data[0xFFFE - address]);
259215
}
260216
else
261217
{
262218
if (WriteBytes(address, data))
263219
{
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));
265221
}
266222
else
267223
{
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));
269225
}
270226
}
271227
}
@@ -278,12 +234,12 @@ static bool WriteFlash(string fileName, Boolean fastWrite)
278234
{
279235
if (WriteBytes(lastAddress, lastArray))
280236
{
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));
282238
Thread.Sleep(100);
283239
SetPC(resetAddr);
284240
}
285241
else
286-
Console.WriteLine("Failed to write reset vector");
242+
Debug.WriteLine("Failed to write reset vector");
287243
}
288244

289245
return true;
@@ -361,7 +317,7 @@ static bool WriteBytes(int address, byte[] data)
361317
}
362318
else
363319
{
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]));
365321
}
366322

367323

Application/QA350/QA350/Extensions.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ public static string ToEngineeringNotation(this double d)
2121

2222
public static string ToEngineeringNotation(this double d, string formatString)
2323
{
24-
//string formatString = "F3";
2524
double exponent = Math.Log10(Math.Abs(d));
2625
if (Math.Abs(d) >= 1)
2726
{

Application/QA350/QA350/Hardware.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ static public bool Open()
4646
return false;
4747
}
4848

49+
/// <summary>
50+
/// Opens a connection to the device for re-flashing. Prior to calling this
51+
/// method, the MSP430 needs to have entered its bootlaoder. Note below
52+
/// that the product ID differs when in bootloader mode
53+
/// </summary>
54+
/// <returns></returns>
4955
static public bool OpenBSL()
5056
{
5157
// See if we can see the USB ID of this product

0 commit comments

Comments
 (0)