Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
luni64 committed Jul 5, 2015
1 parent 98013e9 commit e844594
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion 01_TeensyWatcherConsole/Program.cs
Expand Up @@ -24,7 +24,7 @@ static void Main(string[] args)
}

// Here is a good place to construct a SerialPort Object
// for the sake of simplicity lets take the first one from the list
// For the sake of simplicity lets take the first one from the list
var myTeensy = Watcher.ConnectedDevices.FirstOrDefault();
if (myTeensy != null && myTeensy.Type == USB_Device.type.UsbSerial)
{
Expand Down
8 changes: 5 additions & 3 deletions TeensySharp/SharpUploader.cs
Expand Up @@ -39,12 +39,14 @@ public static int Upload(byte[] Image, PJRC_Board board, uint Serialnumber, bool

var BoardDef = BoardDefinitions[board];
int addr = 0;

//Slice the flash image in dataBlocks and transfer the blocks if they are not empty (!=0xFF)
foreach (var dataBlock in Image.Batch(BoardDef.BlockSize))
{
if (dataBlock.Any(d => d != 0xFF) || addr == 0) //skip empty blocks but always write first block to erase chip
{
var report = PrepareReport(addr, dataBlock.ToArray(), BoardDef);
if (!device.WriteReport(report)) //if first write fails (happens) wait and retry once
if (!device.WriteReport(report)) //if write fails (happens if teensy still busy) wait and retry once
{
Thread.Sleep(10);
if (!device.WriteReport(report)) return 2;
Expand All @@ -55,6 +57,7 @@ public static int Upload(byte[] Image, PJRC_Board board, uint Serialnumber, bool
addr += BoardDef.BlockSize;
}

// Reboot the device to start the downloaded firmware
if (reboot)
{
var rebootReport = device.CreateReport();
Expand Down Expand Up @@ -85,8 +88,7 @@ public static bool StartHalfKay(uint Serialnumber)
//Start HalfKay
using (var port = new SerialPort(Teensy.Port))
{
port.Open();
int previousBR = port.BaudRate;
port.Open();
port.BaudRate = 134; //This will switch the board to HalfKay. Don't try to access port after this...
}
}
Expand Down

0 comments on commit e844594

Please sign in to comment.