Can you reverse storage.disable_usb_drive

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Post Reply
User avatar
anthonycastiglia
 
Posts: 9
Joined: Tue Jul 04, 2017 12:23 am

Can you reverse storage.disable_usb_drive

Post by anthonycastiglia »

Adafruit KB2040 - RP2040 - PRODUCT ID: 5302
CircuitPython 9.0.4

Hello, I'm using a KB2040 to run simple HID code to move the mouse periodically, like a mouse jiggler. The code works perfectly and for extended periods of time. I wanted to hide the USB storage feature when connected but still run the code. Adding storage.disable_usb_drive() to boot.py was the solution and again, works perfectly. Now, I can't figure out how to disable this feature and enable the usb drive, or at least delete the contents of boot.py. Using the Mu editor, I am able to see the device in the serial console. How do I enable the usb drive feature?\

User avatar
danhalbert
 
Posts: 4747
Joined: Tue Aug 08, 2017 12:37 pm

Re: Can you reverse storage.disable_usb_drive

Post by danhalbert »

You can get into safe mode by pressing the reset button when the RGB LED flashes during boot. That will prevent boot.py from running. See https://learn.adafruit.com/circuitpytho ... de-3138649. It's a little difficult to react to the flashing in time, so think of it as a "slow" double-click.

If you are running CircuitPython 9.0.0 or later, you should also be able to do, from the REPL:

Code: Select all

import os
os.remove("boot.py")
In earlier versions, CIRCUITPY is not writable unless you remount it.

Finally, you can also load the "nuke.uf2" which will erase everything, including CircuitPython, and you can start over:
https://learn.adafruit.com/adafruit-kb2 ... f2-3106963

When you write a new boot.py, the usual trick is to not disable USB if an external button is pressed:
https://learn.adafruit.com/customizing- ... ut-3096636

User avatar
anthonycastiglia
 
Posts: 9
Joined: Tue Jul 04, 2017 12:23 am

Re: Can you reverse storage.disable_usb_drive

Post by anthonycastiglia »

Excellent, the os.remove code worked for me. Appreciate the help, thank you!

User avatar
Timeline
 
Posts: 197
Joined: Sun Feb 18, 2024 7:13 pm

Re: Can you reverse storage.disable_usb_drive

Post by Timeline »

danhalbert wrote: Wed May 15, 2024 9:25 am When you write a new boot.py, the usual trick is to not disable USB if an external button is pressed:
https://learn.adafruit.com/customizing- ... ut-3096636
I assume this method would also work to disable setting up a watchdog? This could be especially useful when using a wdt set to RESET vs RAISE with a short timeout making it difficult in some cases to catch it in time with a Ctrl-C in the serial window. I don't have a board handy at the moment to simply test it out myself, so thought I would post the question in the meantime.

User avatar
danhalbert
 
Posts: 4747
Joined: Tue Aug 08, 2017 12:37 pm

Re: Can you reverse storage.disable_usb_drive

Post by danhalbert »

I think so, if you are setting up the watchdog in boot.py. Basically, make the board go into "debug" mode if a button is held down.

User avatar
Timeline
 
Posts: 197
Joined: Sun Feb 18, 2024 7:13 pm

Re: Can you reverse storage.disable_usb_drive

Post by Timeline »

Oh in the boot.py file. I missed that detail. So won't work if you put it in the normal code.py file then? So a benefit of using boot.py instead would be for doing this sort of thing?

User avatar
danhalbert
 
Posts: 4747
Joined: Tue Aug 08, 2017 12:37 pm

Re: Can you reverse storage.disable_usb_drive

Post by danhalbert »

Oh, for a watchdog, yes, put it in code.py, sorry. The watchdog is reset after boot.py or code.py ends. You could still check a button in code.py to not set the watchdog.

User avatar
Timeline
 
Posts: 197
Joined: Sun Feb 18, 2024 7:13 pm

Re: Can you reverse storage.disable_usb_drive

Post by Timeline »

Got it. Thanks for clearing that up. I may start implementing a "push to disable WDT" in my code for when I need to start up for some code changes or whatever and don't want the WDT rebooting the board on me.

Post Reply
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”