reset device via bootloader?
reset device via bootloader?
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?
Re: reset device via bootloader?
Hi David, could you elaborate please? Or are you saying you just know its possible?
Re: reset device via bootloader?
My answer is as good as your question. You didn't give much info, so I couldn't give much info.
Re: reset device via bootloader?
E.g. you could enable the watchdog and let the device run into a while(1)/for(;;)
Re: reset device via bootloader?
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.
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.
Re: reset device via bootloader?
To me it looks like
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.
Code: Select all
static void (*nullVector)(void) __attribute__((__noreturn__));
static void leaveBootloader()
{
//...
nullVector();
//...
}
Re: reset device via bootloader?
in this case that would work, Micha. So how do you call leaveBootloader from a bat file, or exe?
Re: reset device via bootloader?
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.
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.
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.
Re: reset device via bootloader?
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 --
http://vusb.wikidot.com/project:hidbootflash
Unfortunately its not open source --
-
- Posts: 2
- Joined: Thu Feb 02, 2012 5:58 pm
Re: reset device via bootloader?
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
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
Re: reset device via bootloader?
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
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();
}