Hw reset and/or reboot?

Discussion related to "under the hood" OpenMV topics.
User avatar
petri
Posts: 15
Joined: Tue Jul 05, 2016 11:52 am
Location: Finland

Hw reset and/or reboot?

Postby petri » Fri Aug 26, 2016 9:26 am

I could not find any explanation of how to do hardware reset of the camera, effectively making it reboot.

Is it as simple as grounding the RST pin?

If so, what is the BOOT pin for, then, what's the difference?

Thanks.
User avatar
kwagyeman
Posts: 2202
Joined: Sun May 24, 2015 2:10 pm

Re: Hw reset and/or reboot?

Postby kwagyeman » Fri Aug 26, 2016 11:36 am

Yes, just ground the RST pin. The BOOT pin controls if the default STM DFU bootloader turns on. The STM bootloader allows you to get out of being bricked if the flash gets completely corrupted.
Nyamekye,
User avatar
cagiva
Posts: 78
Joined: Thu Jan 05, 2017 9:23 pm

Re: Hw reset and/or reboot?

Postby cagiva » Thu Jan 19, 2017 1:53 pm

Let me see if I understand this. Since the OpenMV board doesn't have a physical RST button like the Pyboard so do I need to ground the RST pin to trigger a hard reset?
User avatar
kwagyeman
Posts: 2202
Joined: Sun May 24, 2015 2:10 pm

Re: Hw reset and/or reboot?

Postby kwagyeman » Thu Jan 19, 2017 2:09 pm

Yes.
Nyamekye,
User avatar
dhylands
Posts: 33
Joined: Sun May 31, 2015 1:27 pm
Location: Shuswap, BC, Canada
Contact:

Re: Hw reset and/or reboot?

Postby dhylands » Fri Jan 20, 2017 12:55 am

You can also do either of the following:

Code: Select all

import machine
machine.reset()
or

Code: Select all

import pyb
pyb.hard_reset()
User avatar
cagiva
Posts: 78
Joined: Thu Jan 05, 2017 9:23 pm

Re: Hw reset and/or reboot?

Postby cagiva » Fri Jan 20, 2017 1:17 am

dhylands wrote:

Code: Select all

import pyb
pyb.hard_reset()
Hum! It's good to know that one can also trigger a hard reset via command prompt. Thanks for that info.

I have a main.py that imports another file from the sd card (import sensor) and everytime I made changes to the sensor.py file in my local laptop, I have to copy it into the sd card and do a hard reset so the main.py can pick up the latest changes. Is this the normal behavior? It seems that files loaded by main, are loaded only once and stay in the memory.
User avatar
kwagyeman
Posts: 2202
Joined: Sun May 24, 2015 2:10 pm

Re: Hw reset and/or reboot?

Postby kwagyeman » Fri Jan 20, 2017 12:21 pm

"sensor" is a built-in module we use... not sure if you should be shadowing that. Maybe rename that file?

As for the requirement of reset behavior. That's a deeper issue into how MP works. I can't tell you that exactly from my knowledge. Could be a bug with the system, or not. Maybe Ibrahim knows more.
Nyamekye,
User avatar
cagiva
Posts: 78
Joined: Thu Jan 05, 2017 9:23 pm

Re: Hw reset and/or reboot?

Postby cagiva » Fri Jan 20, 2017 12:27 pm

I used sensor.py to simplify things. We do use a different name. It seems that is how MP work. Loads imported modules and cache them in memory, which forces you to hard reset the board if you need test new changes in those modules.
User avatar
kwagyeman
Posts: 2202
Joined: Sun May 24, 2015 2:10 pm

Re: Hw reset and/or reboot?

Postby kwagyeman » Fri Jan 20, 2017 12:29 pm

Mmm, okay, well, you should at least be able to use the IDE to update the main script easily.
Nyamekye,
User avatar
dhylands
Posts: 33
Joined: Sun May 31, 2015 1:27 pm
Location: Shuswap, BC, Canada
Contact:

Re: Hw reset and/or reboot?

Postby dhylands » Fri Jan 20, 2017 9:27 pm

I noticed that Control-D *looks* like it does a soft-reset, but doesn't. The heap doesn't get reinitialized and everything seems to still be in memory.

If you create a simple module (say bar.py) with just a single line:

Code: Select all

print('bar.py')
and you try and import it twice, then you'll notice that the second time it doesn't do anything because the module is already loaded.

Code: Select all

>>> import bar
bar.py
>>> import bar
>>> 
By deleting the module from sys.modules then you can make import reload it:

Code: Select all

>>> import sys
>>> import bar
bar.py
>>> import bar
>>> del sys.modules['bar']
>>> import bar
bar.py
>>> 
The only downside to this, is that you now have a reference to the new module. If some other module imported bar, it would still have a reference to the old module. Which is one reason I really like the soft-reset functionality on the pyboard. I'd really like to see that on the openmv, but there may be a reason its not implemented.

You can create a function called reload:

Code: Select all

def reload(mod):
    import sys
    mod_name = mod.__name__
    del sys.modules[mod_name]
    return __import__(mod_name)
in say your boot.py or main.py and then do:

Code: Select all

>>> import bar
bar.py
>>> reload(bar)
bar.py
<module 'bar' from 'bar.py'>
>>> 
User avatar
kwagyeman
Posts: 2202
Joined: Sun May 24, 2015 2:10 pm

Re: Hw reset and/or reboot?

Postby kwagyeman » Fri Jan 20, 2017 11:55 pm

Mmm, put a bug on it in the openmv repo.
Nyamekye,
User avatar
iabdalkader
Posts: 526
Joined: Sun May 24, 2015 3:53 pm

Re: Hw reset and/or reboot?

Postby iabdalkader » Thu Feb 23, 2017 8:23 am

dhylands wrote:
Fri Jan 20, 2017 9:27 pm
I noticed that Control-D *looks* like it does a soft-reset, but doesn't. The heap doesn't get reinitialized and everything seems to still be in memory.
Fixed, initially I just didn't think REPL will be used that much with the IDE.
User avatar
dhylands
Posts: 33
Joined: Sun May 31, 2015 1:27 pm
Location: Shuswap, BC, Canada
Contact:

Re: Hw reset and/or reboot?

Postby dhylands » Thu Feb 23, 2017 6:44 pm

I like to use rshell to copy files onto and off of my MicroPython boards, and it relies on pyboard.py which also relies on Control-D doing a soft-reset actually working.

Return to “Technical Discussion”

Who is online

Users browsing this forum: No registered users and 3 guests