chipKIT® Development Platform

Inspired by Arduino™

Fubarino Software Reset

Created Wed, 01 Nov 2017 13:37:29 +0000 by cb725


cb725

Wed, 01 Nov 2017 13:37:29 +0000

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

Wed, 01 Nov 2017 15:10:04 +0000

Hi cb,

I'd try using the function

executeSoftReset(RUN_SKETCH_ON_BOOT);

and see if that does it for you.

*Brian


cb725

Wed, 01 Nov 2017 18:24:33 +0000

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

Thu, 02 Nov 2017 08:32:25 +0000

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

Thu, 02 Nov 2017 13:42:33 +0000

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

Thu, 02 Nov 2017 14:13:45 +0000

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

Thu, 02 Nov 2017 18:58:23 +0000

cp,

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

*Brian


EmbeddedMan

Thu, 02 Nov 2017 19:20:23 +0000

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

Thu, 02 Nov 2017 20:09:53 +0000

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.

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

cb


EmbeddedMan

Sun, 05 Nov 2017 13:59:28 +0000

cb,

OK, here is the sketch I used to test:

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


cb725

Tue, 07 Nov 2017 13:11:16 +0000

Brian

Thanks for taking the time to test this and help me out, I really appreciate it.

I was able to more or less synchronize the disconnect of the FBMini using the soft reset command in the Arduino IDE and the disconnect of the COM port in my program. I then waited for about half a second which allowed windows to recognize what was going on and allowed me to connect to it again.

Again, I really appreciate the help. Sounds like moving forward on future projects, the better option is to hopefully persuade my IT department to upgrade to Windows 10.

cb