Skip to content

Commit

Permalink
Fixed some big bugs!
Browse files Browse the repository at this point in the history
There were bugs to do with the write functions and buffers, I had to reduce the block send to 50 bytes as the Arduino Mega was dropping data. Get the associated updated sketch too or you'll have some major issues.
Almost complete now!!
  • Loading branch information
danriches authored Sep 21, 2022
1 parent c3f849d commit 2c5893f
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 10 deletions.
4 changes: 2 additions & 2 deletions FlashProgrammer/WindowsFormsApp1/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 15 additions & 8 deletions FlashProgrammer/WindowsFormsApp1/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public Form1()
private void Form1_Load(object sender, EventArgs e)
{
//Find last com port and list it in the control.

_continue = false;
}

private void AddToMessageLog(string textToAdd)
Expand Down Expand Up @@ -87,6 +87,8 @@ private void Serial_DataReceived(object sender, SerialDataReceivedEventArgs e)
//try
//{
string data = serial.ReadLine(); //This line is problematic and maybe should be serial.ReadBytes???
if (data.StartsWith("OK"))
_continue = true;
if (data.StartsWith("0x"))
this.BeginInvoke(new SetTextDeleg(SerialIn_DataReceived), new object[] { data });
else
Expand Down Expand Up @@ -171,7 +173,7 @@ private void btnWrite_Click(object sender, EventArgs e)
string WriteFileToFlash(string filename)
{
string result = "FAILED!";

//Open the file and read into a byte array
byte[] dataArray = File.ReadAllBytes(filename);

Expand All @@ -182,32 +184,37 @@ string WriteFileToFlash(string filename)
txtMessages.Text += "Writing Flash starting at address 0x0000. Please Wait...";
int addressCounter = 0;

//send <X,0,0> then <Z,x,0> where x is 256 or the number of bytes to write, lastly send <Y> and then the full amount of bytes in sequence
//send <X,0,0> then <Z,x,y> where x is 256 or the number of bytes to write, lastly send <Y> and then the full amount of bytes in sequence
//- Arduino side seems to work just need this side to
int totalSize = dataArray.Length;

serial.WriteLine("<X," + txtStartAddress.Text + ",0>");
serial.WriteLine("<Z," + totalSize.ToString() + ",0>");
serial.WriteLine("<Z," + "50," + totalSize.ToString() + ">");
serial.Write("<Y>");

int offset = 0;
int block = 256;
int block = 50;
if (block > totalSize)
block = totalSize;

//This part needs checking before allowing a write to Flash!!!!!!!
while(offset < totalSize)
{
{
_continue = false;
if ((offset + block) > totalSize)
block = totalSize - offset;
serial.Write(dataArray, offset, block);
if (offset + block > totalSize)
offset = totalSize - (offset + block);
else
offset += block;
Application.DoEvents();

while(_continue == false)
Application.DoEvents();
}
//Read the bytes back and compare, using a dump command, ignore and don't read data past where it was written...

return "Success: Wrote " + (addressCounter + 1).ToString() + " bytes to Flash." + Environment.NewLine;
return "Success: Wrote " + totalSize.ToString() + " bytes to Flash." + Environment.NewLine;
}

private void btnErase_Click(object sender, EventArgs e)
Expand Down
Binary file modified FlashProgrammer/WindowsFormsApp1/bin/Debug/WindowsFormsApp1.exe
Binary file not shown.
Binary file modified FlashProgrammer/WindowsFormsApp1/bin/Debug/WindowsFormsApp1.pdb
Binary file not shown.
Binary file not shown.
Binary file modified FlashProgrammer/WindowsFormsApp1/obj/Debug/WindowsFormsApp1.exe
Binary file not shown.
Binary file modified FlashProgrammer/WindowsFormsApp1/obj/Debug/WindowsFormsApp1.pdb
Binary file not shown.

0 comments on commit 2c5893f

Please sign in to comment.