DL40 - Firmware update Issue

[title]UPDATE: The information in this post is no longer required. The code on the wiki has been updated.[/title]

I started playing with my shiny new DL40, but I hit a snag when trying to upload the standard firmware, it would either hang at the ‘Connecting…’ stage or fail the ‘Verification Stage’. Investigating the code I realized that the issue is with the Read method in the SerialPortToNXP class or rather with the code that calls Read and assumes that the read would get all the data in a single call.

When retrieving larger buffers, sometimes multiple reads are required to fetch the requested amount of data. Since there are many different places in the code that call read I opted to make the read function read until it as received all the data or has timed-out.

The original code is as follows

public void Read(byte[] buffer, int offset, int size, int timeout)
  //serial.ReadTimeout = timeout;
  int count;
  if ((count = serial.Read(buffer, offset, size)) < size)
    throw new Exception("Timeout");

I have modified it to the following, which seems to work fine.

public void Read(byte[] buffer, int offset, int size, int timeout)
  DateTime startTime = DateTime.Now;
    int bytesRead = serial.Read(buffer, offset, size);
    offset += bytesRead;
    size -= bytesRead;
    if ((DateTime.Now - startTime).Milliseconds > timeout)
      throw new Exception("Timeout");
  } while (size > 0);

  if (size != 0) throw new Exception("Data size mismatch");

1 Like

Where do you see this code?

Hi Gus,

I downloaded the code to handle the reflash from the following wiki page at http://wiki.tinyclr.com/index.php?title=OpenDaisyLink
The link for the zip is http://wiki.tinyclr.com/index.php?title=File:Reflash_a_daisylink_module.zip

The class SerialPortToNXP is in the Program.cs file in that zip.

Now I understand. Microsoft changed the serial port drivers in 4.2 which broke a lot of our code, including the one you just found.

On 4.1, the read returned only when all data was reviewed. It was better before but they changed it to match the big .NET

Thanks for the update, we will fix on our end.

Thanks Gus, everything else is working great.

One thing that caught me, and I did not find mentioned anywhere (I hope I did not stupidly miss it) is that when flashing the DL40 must be connected to the main board on the ‘’ socket and when running it is connected on the ’ XY’ socket, I found that by trail and error, so I hope that is actually correct.

This is by design. We will double check all info.

Thank you for the confirmation, as long as I know I am doing the right thing it is all good.