Start application command from avrdude

Go To Last Post
10 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hey,

I am using xmega256a3u with DFU Bootloader.

In the DFU Flip datasheet, in page 13: http://www.atmel.com/images/doc8457.pdf

There is a command Start Application.

How can I trigger it from avrdude?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I could be missing it but looking at the avrdude source that handles DFU:

 

http://svn.savannah.nongnu.org/v...

 

I don't see support for any such function. You'd probably need to pull the avrdude source and study it in more detail to be absolutely sure but I think it's quite modular and anything relating to DFU is likely to be in dfu.c

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Avrdude always started the application when finished in the past.  Then along came DFU.  Avrdude never starts the application for me when using DFU. 

 

I don't use DFU unless I want to remind myself how bizarre things can be.

Last Edited: Sat. Jan 16, 2016 - 11:19 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

steve17 wrote:

Avrdude always started the application when finished in the past.  Then along came DFU.  Avrdude never starts the application for me when using DFU. 

 

I don't use DFU unless I want to remind myself how bizarre things can be.

 

Hey Steve, I'm in the middle of building a DFU Bootloader so I will stick to it :)

Do you know which command avrdude use to start application in other programmers?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

arkadi wrote:

Do you know which command avrdude use to start application in other programmers?

In the traditional "serial port" protocols like avr911 etc.,  the commands are single letters.  The exit bootloader command is 'E' (capital letter E).  I have no idea how this is done with DFU or even if there is any convention for it.   I believe Atmel uses a subset of DFU and it seems DFU was invented in an insane asylum anyway.  Now you know all I know about the subject.

 

By the way, I was able to get most of Atmel's DFU commands working.  For instance I can use it to read flash.  I was stumped trying to figure out how to write flash.  In particular, how the Xmega device knows where the data ends when it receives the flash data.  It seems there is more, apparently useless, data sent after the actual flash data, and the contents and size of this extraneous data can vary.

 

Besides avrdude, there is another PC program that uses DFU.  That one is called dfu-programmer.  You might try that and see what you get.  It works for me but I don't remember if it causes the bootloader to exit to the application.

Last Edited: Sun. Jan 17, 2016 - 01:27 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
   reset
      Resets microcontroller using watchdog timer

    start
      Starts the application firmware by  having  the  microcontroller
      jump to address zero.

... that's from the dfu-programmer manual page.

Mike

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The dfu-programmer source is here:

 

https://github.com/dfu-programme...

 

It looks like arguments.c returns com_start_app when the "start" command is used. The commands are handled in commands.c where the effect of that is simply:

        case com_start_app:
            args->com_launch_config.noreset = true;

So next one needs to find access to "com_launch_config". That appears to be here:

static int32_t execute_launch( dfu_device_t *device,
                                  struct programmer_arguments *args ) {
    if( args->device_type & GRP_STM32 ) {
        return stm32_start_app( device, args->quiet );
    } else if( args->com_launch_config.noreset ) {
        return atmel_start_app_noreset( device );
    } else {
        return atmel_start_app_reset( device );
    }
}

So it's calling atmel_start_app_noreset() when it starts the app code:

 

int32_t atmel_start_app_noreset( dfu_device_t *device ) {
    uint8_t command[5] = { 0x04, 0x03, 0x01, 0x00, 0x00 };

    TRACE( "%s( %p )\n", __FUNCTION__, device );

    if( 5 != dfu_download(device, 5, command) ) {
        DEBUG( "dfu_download failed.\n" );
        return -1;
    }

    if( 0 != dfu_download(device, 0, NULL) ) {
        DEBUG( "dfu_download failed.\n" );
        return -2;
    }

    return 0;
}

Of that the key part would appear to be:

    uint8_t command[5] = { 0x04, 0x03, 0x01, 0x00, 0x00 };

So you send that 5 byte command sequence and it starts the app ;-)

 

PS I then went back to the avrdude source I linked to in #2 and notice it does stuff like:

  result = usb_control_msg(dfu->dev_handle,
    USB_TYPE_CLASS | USB_RECIP_INTERFACE, DFU_DNLOAD, wIndex++, 0,
    ptr, size, dfu->timeout);
  result = usb_control_msg(dfu->dev_handle,
    USB_TYPE_CLASS | USB_RECIP_INTERFACE, DFU_ABORT, 0, 0,
    NULL, 0, dfu->timeout);
  result = usb_control_msg(dfu->dev_handle,
    0x80 | USB_TYPE_CLASS | USB_RECIP_INTERFACE, DFU_GETSTATUS, 0, 0,
    (char*) status, sizeof(struct dfu_status), dfu->timeout);

So those DF_* macros look "interesting". At the top of the file is:

#define DFU_DNLOAD 1
#define DFU_UPLOAD 2
#define DFU_GETSTATUS 3
#define DFU_CLRSTATUS 4
#define DFU_GETSTATE 5          /* FLIPv1 only; not used */
#define DFU_ABORT 6             /* FLIPv1 only */

so those would appear to be the supported commands. I guess the question is how those relate to:

   uint8_t command[5] = { 0x04, 0x03, 0x01, 0x00, 0x00 };

cheeky

Last Edited: Mon. Jan 18, 2016 - 11:15 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks, it sends the "Start application" command. smiley

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Is that documented somewhere then?

 

My point (I guess) is that while it looks like it doesn't do, the avrdude source is probably only about a 10 line patch away from being able to do it. So someone could easily add it and push a patch back to Joerg.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, in page 13, 7.5.2 Starting the application: http://www.atmel.com/images/doc8...

 

My point (I guess) is that while it looks like it doesn't do, the avrdude source is probably only about a 10 line patch away from being able to do it. So someone could easily add it and push a patch back to Joerg.

I have some technical problem, but when I figure it out I will push it to Joerg