Tips and Tricks (11)

Previous T&T

This tip deals with the upload of firmware from a VB.NET application. Take the time to read the avrdude instructions manual and copy paste the following code in your application. It is presented in its minmalist form in order to be self explanatory:

  Private Sub UploadFirmware( _
    ByVal HexFile As String, _
    Optional ByVal Product As String = "m328p", _
    Optional ByVal CommPort As String = "COM1", _
    Optional ByVal Baudrate As Integer = 57600 _

    ' Build arguments string
    Dim Arguments As String = Nothing
    Arguments &= "-F" ' Override device signature check
    Arguments &= " "
    Arguments &= "-v" ' Enable verbose output
    Arguments &= " "
    Arguments &= "-p" ' Product type
    Arguments &= Product
    Arguments &= " "
    Arguments &= "-c" ' Controller type (upload through serial comm port)
    Arguments &= "stk500v1"
    Arguments &= " "
    ' If the avrdude.conf is not located where avrdude.exe expects it to be, uncomment and fill in next lines
    'Arguments &= "-C" ' Specify the configuration file
    'Arguments &= Chr(34) & My.Application.Info.DirectoryPath & "avravrdude.conf" & Chr(34)
    'Arguments &= " "
    Arguments &= "-P"  ' Serial port name
    Arguments &= "\." & CommPort
    Arguments &= " "
    Arguments &= "-b"  ' Baud rate
    Arguments &= CStr(Baudrate)
    Arguments &= " "
    Arguments &= "-D"  ' Disable auto erase for flash
    Arguments &= " "
    Arguments &= "-U" ' Uploaded file to flash memory
    Arguments &= "flash:w:" & Chr(34) & HexFile & Chr(34) & ":i"
    ' Start application
    Dim MyProcess As New Process()
    With MyProcess
      With .StartInfo
        .FileName = My.Application.Info.DirectoryPath & "avrdude.exe"
        .Arguments = Arguments
        .WindowStyle = ProcessWindowStyle.Normal
      End With
    End With

  End Sub

Next T&T


  1. […] Next T&T Tags: Programming, Tips & Tricks Comment (RSS)  |  Trackback […]

  2. buddhafragt says:

    Hello, this code is exactly what I am looking for, but I cant get it run…
    At: .Start() debugging stop with the error message:
    “the sytem cant find the specified file”.

    I think the error is here…..
    FileName = My.Application.Info.DirectoryPath & “avravrdude.exe”
    I double checked the path and names, but no success….

  3. Didier says:

    You are absolutely right. Firstly there is a @*%$#ยง typo in the name of the application. Please read “avrdude.exe”. Also, the example given is extracted from a whole application where “My.Application.Info.DirectoryPath & “avrdude.exe” is even taking the form of a variable which is set prior to the execution of the upload routine itself.
    If you want to keep the code as simple as it is, just specify the correct location of the “avrdude.exe” application in its file path, typically “C:\Program Files (x86)\arduino-1.0.5-r2-windows\hardware\tools\avr\bin”
    Thanks for your comment.

  4. buddhafragt says:

    I foud the error:
    .FileName = My.Application.Info.DirectoryPath & “\avrdude.exe”
    is working… the \ was missing….

Leave a Reply

You must be logged in to post a comment.