Main Site Documentation

Update Arduino Firmware from NetMF


#1

I have a project where I am using a G120 for my main execution but I want to do some realtime sampling from a gyro sensor so I was considering using an arduino to process the data and then send it over serial uart to my G120.

I am going to be implementing the in field update features of the G120 to manage the firmware on it and I was wondering if anyone knows how to update the firmware on an arduino over the uart connection?


#2

There is no direct way of doing this but this is actually simple if you have done boot loaders in the past. An easier way would be to use the actual arduino boot loader and send the arduino firmware from G120. This is very interesting, now that I think about this idea.

Anyone seen documentation on how the arduino loader accepts new firmware? Either way, the loader is open source so one can read the code and figure it out.


#3

I have something I have tried in the past. I will find it and share tonight or tomorrow.


#4

@ Architect - was it to flash using ISP or though UART and the loader?


#5

I was using uart and loader.


#6

@ architect any update on this?


#7

Oh man, I am sorry. I got carried away and forgot about it. Will take a look tonight for sure.


#8

@ jschneck - I can’t find the whole project, but I found some bits and pieces.

Function to read Arduino hex file from resource (the file should be included as a text file)


        private static byte[] GetArduinoBinary(Resources.StringResources resourceId, ref int sketchSize)
        {

            Resources r = new Resources();

            string file = Resources.GetString(resourceId);
            string[] lines = file.Split(new char[] { '\n' });

            //approximate the size of the data buffer (it is slightly bigger, by (lines.Length-1) bytes)
            byte[] buffer = new byte[(file.Length - 11 * (lines.Length - 1)) >> 1];

            int bufferLength = 0;

            for (int i = 0; i < lines.Length; i++)
            {
                if (lines[i].Length == 0 || lines[i][0] != ':')
                    continue;
                byte length = HexStringToByte(lines[i].Substring(1, 2));
                byte recordType = HexStringToByte(lines[i].Substring(7, 2));

                //Skip non data records
                if (recordType != 0)
                    continue;

                for (int j = 0; j < length; j++)
                {
                    byte dataByte = HexStringToByte(lines[i].Substring(9 + (j << 1), 2));
                    buffer[bufferLength++] = dataByte;
                }
            }

            sketchSize = bufferLength;

            return buffer;
        }

HexStringToByte is the function from @ BlueHairBob on codeshare.

After you get the hex file bytes you will have to push them through uart to arduino, similar to what is done here: