Fubarino Software Reset

cb725
Posts: 7
Joined: Wed Nov 01, 2017 2:26 pm

Fubarino Software Reset

Post by cb725 » Wed Nov 01, 2017 2:37 pm

Is there an equivalent software reset on the Fubarino as there is on the Arduino platform?

For example, using void(* resetFunc) (void) = 0;

I am currently using the Fubarino Mini as a controller for a stepper that will be tucked away inside a box for a test bench I am designing. The reset button will not be very accessible, so I was wondering if I could reset it using the serial instead.

Or, if I could wire a new button fairly easy to the reset, that would work as well.

I have not had any luck finding anything on resets, so any help would be appreciated.

cb

EmbeddedMan
Posts: 597
Joined: Tue May 24, 2011 9:24 pm
Location: Minneapolis, MN
Contact:

Re: Fubarino Software Reset

Post by EmbeddedMan » Wed Nov 01, 2017 4:10 pm

Hi cb,

I'd try using the function

Code: Select all

executeSoftReset(RUN_SKETCH_ON_BOOT);
and see if that does it for you.

*Brian

cb725
Posts: 7
Joined: Wed Nov 01, 2017 2:26 pm

Re: Fubarino Software Reset

Post by cb725 » Wed Nov 01, 2017 7:24 pm

Brian, thank you for the quick response.

This function seems to just disconnect the Fubarino from the computer all together. When it is called, serial stops working and Windows no longer recognizes that the Fubarino is even plugged in.

cb

GrahamM242
Posts: 65
Joined: Fri Feb 21, 2014 6:48 pm

Re: Fubarino Software Reset

Post by GrahamM242 » Thu Nov 02, 2017 9:32 am

I suspect you've found out that Windows doesn't like USB serial devices going away and coming back again when they are in use. If the com port is open at the time the device disappears, Windows has problems reconnecting the device when it comes back - this happens even if you manually reset. I've been bitten by this on different targets, including dedicated USB to serial adaptors.

If you really want to use a reset, I'd suggest that you add a device side short pause before reset to give your host side code a chance to close the serial port before the reset happens. Your host side code should then wait for the device to re-enumerate before attempting to re-open the serial port. You could probably get away with a pause here, but it's less robust.

EmbeddedMan
Posts: 597
Joined: Tue May 24, 2011 9:24 pm
Location: Minneapolis, MN
Contact:

Re: Fubarino Software Reset

Post by EmbeddedMan » Thu Nov 02, 2017 2:42 pm

Ahh, OK, I will look into that. Graham may be right though - this may be an issue with Windows. (BTW, Windows 10 is _far_ better about this type of thing than any previous version. What version of Windows are you running?)

So, something for you to try quick: If you simply press and release the RESET button on the FBMini, does the exact same problem happen with Windows? Or do you observe different behavior between the software reset and pussing the RESET button?

*Brian

cb725
Posts: 7
Joined: Wed Nov 01, 2017 2:26 pm

Re: Fubarino Software Reset

Post by cb725 » Thu Nov 02, 2017 3:13 pm

I am running Windows 7. I do not have the option of upgrading to windows 10 though.

By pressing the reset button on the mini, everything works as intended. When looking at the device manager, the COM port goes away and comes back. Doing the same thing with the software reset, the COM port goes away and does not come back.

Any time the computer that is connected to the mini, sleeps or is shut down/restarted, the COM port shows; and I can connect to the mini through my software. However, I cannot communicate with it as the serial does not want to work.

cb

EmbeddedMan
Posts: 597
Joined: Tue May 24, 2011 9:24 pm
Location: Minneapolis, MN
Contact:

Re: Fubarino Software Reset

Post by EmbeddedMan » Thu Nov 02, 2017 7:58 pm

cp,

OK, perfect. That's the info I need to solve this. I've got a Win7 machine I will experiment with.

*Brian

EmbeddedMan
Posts: 597
Joined: Tue May 24, 2011 9:24 pm
Location: Minneapolis, MN
Contact:

Re: Fubarino Software Reset

Post by EmbeddedMan » Thu Nov 02, 2017 8:20 pm

cp,

What version of chipKIT-core are you using, and what version of Arduino IDE? (If any.)

When I run under IDE 1.8.5 and chipKIT-core 1.4.3, the call to executeSoftReset() doesn't appear to have any effect on my FBMini.

Maybe if you can include your sketch too that would help me debug.

*Brian

cb725
Posts: 7
Joined: Wed Nov 01, 2017 2:26 pm

Re: Fubarino Software Reset

Post by cb725 » Thu Nov 02, 2017 9:09 pm

I am running Arduino 1.8.3 with chipKit-core 1.4.3.

My program communicates with the FBMini using a known format "<int, float>". The code parses the int and float when serial information is received.

Based on what int is received, I tell the FBMini what to do, so the code that it sees to do the reset is the following.

Code: Select all

if (motorInt == 5)
{
   executeSoftReset(RUN_SKETCH_ON_BOOT);
}
cb

EmbeddedMan
Posts: 597
Joined: Tue May 24, 2011 9:24 pm
Location: Minneapolis, MN
Contact:

Re: Fubarino Software Reset

Post by EmbeddedMan » Sun Nov 05, 2017 2:59 pm

cb,

OK, here is the sketch I used to test:

Code: Select all

void setup() {
  Serial.begin(9600);
  delay(5000);
  Serial.println("Starting");
  delay(5000);
}

void loop() {
  Serial.println("In Loop");
  delay(5000);
  executeSoftReset(RUN_SKETCH_ON_BOOT);
}
When I run this on Windows 7 on a Fubarino Mini, the behavior that I see is:

A) Board powers up, creates serial port.
B) Waits 5 seconds
C) Board sends out "starting"
D) Waits 5 seconds
E) Sends out "In Loop"
F) Waits 5 seconds
G) serialport goes away.
H) go back to step A)

Now, if I use Tera Term to open up the created com port (72 in my case) during step B), and then close that same com port from Tera Term during step F), then I can repeat this cycle an infinite amount of times. (note - only tested 5, infinity assumed)

It's critical that you close the com port from within the PC app during step F (i.e. you MUST close it from within the PC app BEFORE the FBMini reboots), otherwise Windows will hold that port and won't let you reconnect to it when it comes back after the reset.

I wonder if that's what's happening to you. You're sending your command, and then immediately rebooting the FBMini, which doesn't give the PC time to close it's side of the COM port. Try adding a delay right before the softreset() command, and then making sure the PC side shuts down its side of the connection during that time.

Hopefully that's the problem.

NOTE: This problem does not exists under Windows 10 - Microsoft finally fixed this bug (after it existing in XP all thew way through 8.1) in Windows 10. There, the COM port will go away when the FBMini reboots, but Windows realizes this, and closes the PC side of the port automagically. So for example, in Tera Term, you will just see [disconnected] in the window title bar when the FBMini reboots. Also, it will reconnect automagically, so once the reboot is done, Tera Term opens the port up for you and you don't have to do anything manually. It's really nice. I know that's not an option for you, but I thought I'd let you know anyway.

*Brian

Post Reply