Gi7mo / TinyFan

GNU General Public License v3.0
51 stars 3 forks source link

Everytime I reboot the Raspberry Pi the serial id for the TinyFAN PCB get lost #8

Open GadgetAngel opened 2 years ago

GadgetAngel commented 2 years ago

I have built the TinyFAN PCB. I am using a waveshare RP2040-zero and everytime I reboot the Raspberry Pi 4B, the pi after reboot does not see the serial USB ID for the RP2040-zero processor.

I have to press the "RESET" button on the RP2040-zero to get the USB ID back (the Raspberry Pi 4B, can see the USB ID again). Is there a way to remotely "RESET" the RP2040.

My TinyFAN PCB is located on the bottom of the printer and I do not want to have to turn the printer over each time the Raspberry Pi 4B needs to be powered off and back on again.

GadgetAngel commented 2 years ago

I am implementing the TinyFAN PCB on my Voron 2.4 build to control PWM fans for my Voron build. I have the Octopus Pro on USB-A to the Raspberry Pi 4B and the TinyFAN's RP2040-zero on port two of the USB-A of the Raspberry Pi 4B.

The instability of the USB connection from the RP2040 device to the Raspberry Pi is due to the RP2040. See https://github.com/Klipper3d/klipper/pull/4748#issue-1013362088 : I quote: “RP2040 datasheet better explains the issue, but in a nutshell the USB controller requires800us of J-state(D+ high, D- low) to transition from RESET to CONNECTED. On a busy USB bus, e.g. on a single-TT hub with other 12Mbps USB devices, this might never happen”.

Here are two work-a-rounds to this problem:

  1. add a remote physical "RESET" button to the Skirt on the Voron 2.4 build
  2. install "uhubctl" on the Pi to power off and them power on the USB-A ports (basically to "RESET" the RP2040 usb-c por which is really a USB-A port on the Pi)

To do #1 work-a-round a couple of items are needed:

  1. wire
  2. Skirt mount for a 16mm button :
  3. https://github.com/hartk1213/MISC/blob/main/Voron%20Mods/Voron%202/2.4/Voron2.4_16mm_button_skirt/STLs/16mm_button_skirt_insert_front.stl
  4. I had to trim the "16mm_button_skirt_insert_front.stl" piece down with my Dremel tool so that I could use the retaining "screw on" collar that came with the 16mm momentary button I bought off of Amazon
  5. buy a 16mm momentary button from of Amazon at https://www.amazon.com/dp/B01MQV6NJR
  6. Hot Glue Gun and Hot Glue to secure the 16mm momentary button from of Amazon mounted on to "16mm_button_skirt_insert_front.stl" piece with the provided screw on collar. The screw on collar will secure the button to the "16mm_button_skirt_insert_front.stl" piece but not to the skirt. So use some hot glue to ensure the "16mm_button_skirt_insert_front.stl" piece stays on the Skirt. I placed hot glue on the backside of the Skirt.
  7. one "Short USB-A to USB-C" cable : https://www.amazon.com/gp/product/B08933P982
  8. cut the "Short USB-A to USB-C" cable so that you can wire the 16mm button in between the cut pieces.
  9. There are 4 wires inside the "Short USB-A to USB-C" cable. Strip the cut ends to gain access to the wires. There is a BLACK (GND), RED (5V), GREEN (Data+) and White (Data-) wires inside. Follow the below diagram on how to hookup the switch between the two halves of the short USB-A to USB-C cable.

RESET TinyPCB board switch wiring

To do #2 work-a-round a couple of items are needed:

  1. see, https://klipper.discourse.group/t/rp2040-pico-suddenly-unable-to-connect-usb-issue/2554
  2. see https://funprojects.blog/2021/04/26/control-usb-powered-devices/
  3. To install uhubctl:
       $sudo apt-get install libusb-1.0-0-dev
       $git clone https://github.com/mvp/uhubctl
       $cd uhubctl
       $make
       $sudo make install

Edit: 10/16/2022 I just tried using uhubctl to power off and power on the USB port for the RP2040.

image

As you can see from the above picture, my RP2040 is on port 4 of 1-1 USB hub:

$sudo uhubctl -l 1-1 -p 4 -a off
$sudo uhubctl -l 1-1 -p 4 -a on

But when I try to cycle the power on the port 4, the power will be turn off and then on again but the RP2040 will not go through the USB enumeration process again. All I get is the power is on but the USB-ID is not shown:

image

But if I hit the 'physical "RESET"' button I installed the RP2040, will now display a USB-ID:

image

Conclusion: the only work-around to this is to just install a physical "RESET" button that interrupts the 5V line going to the USB-C of the RP2040 board! Unfortunately, every time you power up your printer you will need to hit this physical "RESET" button to get the RP2040 USB-ID to appear to the Raspberry Pi.

My next idea is to attach a Digital Relay to the button to see if I can remotely control this action via software. I will update if I can get this accomplished.

GadgetAngel commented 2 years ago

To be able to RESET the RP2040 chip on the TinyFAN PCB you will need to purchase a couple of items. Some are stated in my previous comments but here is the list again with a Relay I purchased from Amazon.

1.buy a 16mm momentary button from of Amazon at https://www.amazon.com/dp/B01MQV6NJR

  1. one "Short USB-A to USB-C" cable : https://www.amazon.com/gp/product/B08933P982
  2. buy a 5V Relay from Amazon that allows for NO and NC connections: https://www.amazon.com/gp/product/B00LW15A4W

Now wire this all up as shown in the following diagram Hookup for RESETting the RP2040

Follow the instruction in "Instructions for Software RESET of RP2040 chip.txt" file Instructions for Software RESET of RP2040 chip.txt

In the end, if you follow all the instructions: every time you power off the printer and turn it back on; or reboot the printer the RP2040 USB communications will be automatically reset so that when the printer finished booting up the link to the USB serial will be present. You will also have access to a web page and additional URL so that you can control the relay via software.

You will also have access to three HTML button at URL: http:[Your Raspberry PI IP address]:7990/resetrp2040.html

You will see the following three buttons: image

GadgetAngel commented 1 year ago

Instead of using rc.local to reset the RP2040 I am now using a created service called "resetrp2040"

To determine which path my python call would use I did the following: which python

pi@LDO300kit:~ $which python /usr/bin/python3

To create the resetrp2040.service file: sudo touch /etc/systemd/system/resetrp2040.service

To edit the resetrp2040.service file: sudo nano /etc/systemd/system/resetrp2040.service

Add the following to the resetrp2040.service file:

[Unit]
Description=Reset RP2040 chip USB comms
DefaultDependencies=no
After=klipper.service

[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=/usr/bin/python3 /home/pi/rp2040/reset_rp2040.py & > /home/pi/rp2040/log.txt 2>&1

[Install]
WantedBy=multi-user.target

To enable the service do the following: sudo systemctl enable resetrp2040.service

Now add the resetrp2040.service to the list of services that moonraker can maintain so that you can manually control the resetrp2040 services via the UI. Go to ~/printer_data/moonraker.asvc and edit the filename moonraker.asvc.

At the end of the file called " moonraker.asvc" place the following: resetrp2040

Now reboot your raspberry pi.

Now the resetrp2040 service will run automatically on reboot

To test it out run the following: sudo service resetrp2040 restart

Ramalama2 commented 1 year ago

Hey @GadgetAngel There is actually a solution, you can simply flash the can bootloader, check the "skr pico" issue thread. Then you can still use simply the usb connection to the pico. Means you just need the can bootloader but you don't have to use can.

I didn't tested personally that approach, but im pretty sure it solves the issue.

Otherwise afterwards, the rp2040 wasn't the best decision with this usb bug, but there aren't any/many stm32 based alternatives.

Here is the direct link to the solution, just keep in mind that the flashchip on the waveshare is the "Generic_03H". https://github.com/bigtreetech/SKR-Pico/issues/2#issuecomment-1500925079