reset device via bootloader?

General discussions about V-USB, our firmware-only implementation of a low speed USB device on Atmel's AVR microcontrollers
Post Reply
ulao
Rank 4
Rank 4
Posts: 480
Joined: Mon Aug 25, 2008 8:45 pm

reset device via bootloader?

Post by ulao » Fri Jan 27, 2012 3:00 am

I'm guessing this can be done since the flash app does it. I want to reset my device via a tool or bat file. Is this possible?

Daid
Rank 2
Rank 2
Posts: 55
Joined: Mon Apr 18, 2011 12:19 pm

Re: reset device via bootloader?

Post by Daid » Fri Jan 27, 2012 11:11 am

Yes.

ulao
Rank 4
Rank 4
Posts: 480
Joined: Mon Aug 25, 2008 8:45 pm

Re: reset device via bootloader?

Post by ulao » Sat Jan 28, 2012 2:34 am

Hi David, could you elaborate please? Or are you saying you just know its possible?

Daid
Rank 2
Rank 2
Posts: 55
Joined: Mon Apr 18, 2011 12:19 pm

Re: reset device via bootloader?

Post by Daid » Mon Jan 30, 2012 3:03 pm

My answer is as good as your question. You didn't give much info, so I couldn't give much info.

Micha

Re: reset device via bootloader?

Post by Micha » Mon Jan 30, 2012 11:09 pm

E.g. you could enable the watchdog and let the device run into a while(1)/for(;;)

ulao
Rank 4
Rank 4
Posts: 480
Joined: Mon Aug 25, 2008 8:45 pm

Re: reset device via bootloader?

Post by ulao » Tue Jan 31, 2012 2:00 am

uhh, wow ok "I want to reset my device via a tool or bat file" Can anyone tell me how?

Thx to Davie I know know its possible but I'm still looking for a way to do it?

Hi Micha, yes I know it can be done in the firmware, but I want to do it via the OS.

I use an atmega328 and the bootloader provided by object dev.

Micha

Re: reset device via bootloader?

Post by Micha » Tue Jan 31, 2012 9:55 pm

To me it looks like

Code: Select all

static void (*nullVector)(void) __attribute__((__noreturn__));

static void leaveBootloader()
{
    //...
    nullVector();
    //...
}
doesn't reset the device but only jumps to the beginning of the code. So either try this code or reset the controller via the watchdog after receiving a specific piece of code. Or be more precise what exactly you want and what exactly not.

ulao
Rank 4
Rank 4
Posts: 480
Joined: Mon Aug 25, 2008 8:45 pm

Re: reset device via bootloader?

Post by ulao » Wed Feb 01, 2012 2:50 am

in this case that would work, Micha. So how do you call leaveBootloader from a bat file, or exe?

Guest

Re: reset device via bootloader?

Post by Guest » Wed Feb 01, 2012 8:56 am

You have to add some code to the firmware, it's impossible to do this only with OS functionality. As you don't want to edit the firmware it is not possible.

Code: Select all

    if(rq->bRequest == USBRQ_HID_SET_REPORT){
        if(rq->wValue.bytes[0] == 2){
            offset = 0;
            return USB_NO_MSG;
        }
#if BOOTLOADER_CAN_EXIT
        else{
            exitMainloop = 1;
        }
#endif

If there's a message with a report ID != 2 it will exit. But with this code you can also do a watchdog reset not only a restart. So we're back at my first answer again.

ulao
Rank 4
Rank 4
Posts: 480
Joined: Mon Aug 25, 2008 8:45 pm

Re: reset device via bootloader?

Post by ulao » Thu Feb 02, 2012 6:14 am

I definitely follow you here. I guess if I developed an app to communicate with my usb descriptor I could simply send a report id to indicate this. I would not really need the bootloader for that at all, this could be done in my normal code area. I already have an out interrupt for my FFB that has plenty of unused report I could hijack. I guess the thing that got me wondering is my flash tool ( HIDBootFlash) somehow does this already.
http://vusb.wikidot.com/project:hidbootflash
Unfortunately its not open source --

jcassidento_atmel
Posts: 2
Joined: Thu Feb 02, 2012 5:58 pm

Re: reset device via bootloader?

Post by jcassidento_atmel » Thu Feb 02, 2012 6:54 pm

Micha suggested "E.g. you could enable the watchdog and let the device run into a while(1)/for(;;)"

I have used this method for other cases of transitioning between application and bootloader, and it works fine. It is actually particularly good since the WDT reset is a hard reset, and will result in all the registers being at their default so you don't have to worry about any artifacts from previous code in case the bootloader code makes any assumptions. Just set the WDT timeout as short as possible, and spin in a delay loop for a little longer than this. This might be better for debugging than an infinite while in case you don't set the WDT correctly since it will eventually time out instead of spinning forever.

- john

ulao
Rank 4
Rank 4
Posts: 480
Joined: Mon Aug 25, 2008 8:45 pm

Re: reset device via bootloader?

Post by ulao » Fri Feb 03, 2012 6:36 am

Hi John, as addressed that is not what the topic is about and as I said I already use the WD method for device resets. This topic is about how to reset the device externally. That is to say how can one communicate with the device to reset it or call a reset function from the OS. The proposed solution is using an out interrupt and looking for a report ID. Though the flash tool does it without looking for a report id, so I wonder how it does this?

Off topic . Since there is so much talk on WD timers I better chime in encase someone searches for this. First off this trick will not work as suggested with a boot loader. You must tell it where to jump. There are a few ways to do this but below I find is the best,

// this is assuming you have a atmega328

Code: Select all

void reboot() 
{
   wdt_disable();
   cli();
   typedef void (*f_ptr_t)(void);
   f_ptr_t boot_entry = (f_ptr_t) 0x7800; //adjust this to fit your needs.
   boot_entry();
}

Post Reply