Marlin: v2.0.x FLASH DISK SUPPORT for RAMPS + MINI USB HOST ?

Created on 6 Dec 2018  Â·  34Comments  Â·  Source: MarlinFirmware/Marlin

ramps ---> mini usb shield
miso  ---> miso
mosi  ---> mosi
sck    ----> sck
cs      ----> ss
5V    -----> vbus
3.3v  ----> 3.3
gnd  ----> gnd/gnd

Marlin settings

      #define SD_DETECT_PIN     53 
  #define USB_FLASH_DRIVE_SUPPORT
  #if ENABLED(USB_FLASH_DRIVE_SUPPORT)
    #define USB_CS_PIN         SDSS
    #define USB_INTR_PIN       SD_DETECT_PIN
  #endif

Serial Log ...

Starting USB host
OSCOKIRQ hasn't asserted in time

=========================
got usb initialized by connecting reset pin to 3.3v

Starting USB host
USB host initialized
USB drive inserted
LUN Capacity (in blocks): 16251904
Error:volume.init failed

LUN Capacity (in blocks): 3915776
echo:SD card ok

Can get usb flash disk connected with 2GB size but not 8GB?
is there any size limit, or with only FAT16 file system, but not FAT32, NTFS, vfat and others ?

Thanks a lot

SD Card Printing

Most helpful comment

I am using this shield too and not using VBUS and left it empty

image

All 34 comments

See if this makes any difference, in usb_host.cpp…

+ delay(200);
  if (!reset()) {
    SERIAL_ECHOLNPGM("OSCOKIRQ hasn't asserted in time");
    return false;
  }

CC: @marcio-ao

OSCOKIRQ hasn't asserted in time

@fred2088: A few of our prototypes exhibited this issue. Our electrical engineer said it had to do with the crystal oscillator not firing up. He fiddled around with the value of some capacitor on the board in order to make it more reliable.

If you are using a pre-manufactured board, then adding the delay @thinkyhead mentioned might be the only workaround.

is there any size limit, or with only FAT16 file system, but not FAT32, NTFS, vfat and others ?

@fred2088: All the USB code does is read raw blocks and for file system access it piggybacks on Marlin's FAT implementation for SD cards. So it should support whatever size and formats that Marlin can support on a SD card. I do not know the details of what Marlin supports, but I suspect it is only FAT16. If you have a larger drive, you could try breaking it up into multiple partitions.

@fred2088: Also, just curious, where did you buy your USB host? Is it this one?

Yes, we use mini USB host shield from taobao from china, need more test on usb disk, currently we got 2gb, 8gb, 16gb (FAT32) on hand and work fine, but some of the usb disk have problem, may be need to format it again

@fred2088 Is it possible to get some pictures of the wiring and how you connected everything to the ramps? i bought myself one of the modules @marcio-ao linked but i am not quite sure how to connect the vbus (called vbcomp (??) in the chips datasheet: https://datasheets.maximintegrated.com/en/ds/MAX3421E.pdf )

@th33xitus: VBUS is simply 5V. The reason it is that the chip itself runs at 3.3V, so it needs a separate 5V for supply for the USB bus.

@marcio-ao Thanks for the fast response!
I struggle a little bit to find the right place on the breakout board to connect the 5V to.
Can you point out where to connect those 5V the right way?

Is it that pin i circled here in red? 5V?
I am not quite sure if this is the right connection because it is connected to INT (Pin 18) of the chip and therefore the INT hole i need to connect to the RAMPS.

@th33xitus: I have not used that particular board, so I'm probably not the best person to be giving you advice. But I can tell you that it is NOT the hole connected to the INT pin, as that is a 3.3V pin and would be damaged by 5V.

If you find a hole labeled VBUS that is electrically connected to the VBUSCOMP pin (perhaps through resistors or other components), that would be okay, since VBUSCOMP is used by the chip to monitor the voltage on VBUS.

@th33xitus: That board is confusing as heck. It seems to have a bunch of through-holes that don't go anywhere ...

Here is another diagram, this seems to be the board the Chinese clones are based on:

https://www.circuitsathome.com/wp/wp-content/uploads/2011/02/uhm11_manual.jpg

I think your original diagram was correct, although you might have been mistaken about what pad was running to INT.

@marcio-ao Yes it is indeed confusing!
The labeling in general is confusing AND not 100% correct. The MOSI and CLK Pins are switched (MISO is CLK and CLK is MOSI), i found that out by measuring the pins before connecting anything.

I will take a closer look and go measure all of the holes again. There is a VBUS label on the back, but the label is not assigned to any hole directly. Look at this Ali-Link, there is a picture of the backside: https://de.aliexpress.com/item/Free-shipping-5PCS-LOT-Mini-USB-Host-Shield-2-0-for-Arduino-ADK-SLR-development-tool/32735946108.html

The image you posted is helpful, i already found it myself yesterday. But the difference to my board are those jumper pads. I don't have jumper pads but direct connections like in the picture i posted above. That would cause the 5V go into the 3.3V. Which don't sound healthy for the chip. That makes it pretty hard for me to try and find a valid connection between my marked hole and another one anywhere on that pcb. I probably have to cut the trace to INT for that, hm?

@th33xitus: For the moment, I suggest you not connect anything to VBUS. The important thing to realize is that on the picture above, there is a VBUS jumper which isn't populated. I don't know where that jumper is on the Chinese clone. My worry is that the VBUS may actually be connected to the 3.3V supply with the jumper populated and if you feed 5V there, you might burn something out.

I suggest hooking everything up and then check to see if there is any voltage on the VBUS pin. If you find it has 3.3V, then one of those resistors probably needs to be removed before you attempt to connect 5V.

Or, to avoid having to modify anything, you could try using a powered USB hub. Since the hub would provide its own 5V to the downstream devices and won't draw power from the USB port, it probably would work fine with an unmodified board.

@marcio-ao Okay! Thank you for your help so far. Maybe we have luck and @fred2088 will answer here and tells us how he solved the "issue". If he uses the exact same board i use (and of which you posted the banggood link in the past) then he shouldn't have some VBUS jumper on his board as well.

@th33xitus: Yeah, it seems like some sleuthing would be required to get it to work properly.

Take a look at this page:

https://www.circuitsathome.com/usb-host-shield-hardware-manual/

They say:

"VBUS pad and jumper can be used to provide 5V to VBUS. By default, VBUS is connected to 3.3V; certain USB devices may have issues with this."

My guess is that the AliExpress one does not have the jumper as a cost saving measure. You should probably first try it with a USB drive unmodified (it may work) and if not, you might have to cut a trace to allow you to feed it 5V on the VBUS.

Thank you for the article, it is really helpfull. Yes you probably need to make sure that you dont simply connect 5V onto this PCB since it's obviously made for dedicated 3.3V use (at least the one i have without any jumper pads). Especially i should make sure to not feed 5V into the INT connection or any other connection as well since i try to get it to run with an Arduino Due. It will surely die too when it accidentially gets 5V into it's 3,3V rail...

https://www.circuitsathome.com/wp/wp-content/uploads/2011/02/uhm_5V_VBUS.jpg

On this picture you can see that the jumper pad (in my case a direct trace) is not populated, the red wire probably feed 5V to the pcb, wired with the blue on to VBUS.
On the page it says: "Mini shield lacks flexibility of its full size brother; however, here is one simple way to get 5V to VBUS using Arduino Pro Mini’s 3.3V on-board LDO. Power the board with 5V on RAW pin, cut the trace inside VBUS jumper, provide 5V from RAW to VBUS and get 3.3V from Arduino to the shield in the usual manner via 3.3V pin. While making this mod be extra careful and don’t short VBUS pad to USB connector shield."

Whats "funny" there is, that the so called "jumper" is actually a trace?! So it doesn't matter if the jumper pad there is populated or not, you have to cut the trace BETWEEN the two pads anyways.

Whats "funny" there is, that the so called "jumper" is actually a trace?! So it doesn't matter if the jumper pad there is populated or not, you have to cut the trace BETWEEN the two pads anyways.

That makes sense, actually. The board would cost more if they had to put a zero ohm resistor in there to bridge two separate pads. So I guess they made it into a trace you have to cut manually. Chinese ingenuity at work.

My general experience with Chinese clones is that they generally work, but they often cut a lot of corners to save money.

Especially i should make sure to not feed 5V into the INT connection or any other connection as well since i try to get it to run with an Arduino Due.

The Due is a 3.3V board, is it not? You would need level shifters if you were using a 5V board, such as a Arduino Mega on RAMPS, for example. For what it is worth, we are using our USB adapters on the Archim 2, which is a 3.3V board. We designed a much nicer USB board, BTW.

https://code.alephobjects.com/diffusion/GREEN/browse/master/KiCad_Files/USB_Reader_Rev_C.png

The Due is a 3.3V board, is it not? You would need level shifters if you were using a 5V board, such as a Arduino Mega on RAMPS, for example.

Yes it is a 3.3V board. It actually uses the exact same processor (SAM3X8E) as your Archim 2 board.
I am using the Due with a modified RAMPS 1.6 Plus (its PCB has integrated SPI connection for TMC driver).
So you are saying it should work, right? Since it is NOT a 5V board i don't need level shifters, correct?
(sorry for asking maybe some basic stuff here, i teach all this electronics stuff myself).

Your PCB looks nice! Looks like you are able to directly connect it to an EXP header on the one end without a lot of fiddling around?

So you are saying it should work, right? Since it is NOT a 5V board i don't need level shifters, correct?
(sorry for asking maybe some basic stuff here, i teach all this electronics stuff myself).

Yes, you should be fine without level shifters. The only place you need 5V is the VBUS, and even there, it may not be necessary (depending on whether USB flash drives can operate under 3.3V, which is rather likely these days).

Yeah, our board can connect directly to the EXP header. That was the idea -- no futzing with GPIO headers. We did require a modification to the Archim 2 to provide 5V on that connector as ordinarily it would not have been there. So we're not 100% sure whether it would work with any board with an EXP header, but it will work with the Archim 2 once that is released. The USB board can work in conjunction with a color touch screen board we have also developed. The color touch screen board has two EXP connectors to allow the USB board to be daisy-chained along with the touch screen off a single EXP connector on the Archim 2. Kinda clever! :)

Okay good. I think i will have to try my USB drives then if it can operate under 3.3V or needs 5V.

Your idea is nice! I saw your first "babysteps" (if you want to call them like that) here on github with this USB stuff (i think you used a sainsmart usb host shield - a red one) with probably one of your touchscreens you mentioned? That was the reason i wanted to try implementing USB in my setup as well :D for me, USB drives are so much more handy than SD or microSD cards, i really wonder why there is so few hardware around for extending your DIY printer with stuff like that. (or maybe i just did not searched well enough).

Ah, that brings back memories :) The red one was actually from SparkFun. Anyhow, it's nice that you are doing the work to get the AliExpress one to work. Having choices is always good! Once you get it all working, please share what you learned!

That was the reason i wanted to try implementing USB in my setup as well :D for me, USB drives are so much more handy than SD or microSD cards, i really wonder why there is so few hardware around for extending your DIY printer with stuff like that.

I think the major stumbling block was the lack of support in Marlin. Although the USB host library already existed out there, it took us several months to get licensing issues squared away and to get the code integrated with Marlin. I'm fairly sure that now that we did the heavy-lifting, there will other printers coming out with USB sooner or later.

Ahhh true, sparkfun, not sainsmart haha :D
Yes of course i will share my results :)

I see, but i am glad it's sorted now and we all can profit from the work you guys did there. Thanks a lot for that!

You're welcome!

I am using this shield too and not using VBUS and left it empty

image

@fred2088: Thanks Fred! That's great info to know!

My guess is that since most chips now a days are 3.3V, the chips in USB flash drives are 3.3V too. So long as the voltage regulator used inside them is of the LDO variety, it will probably work just fine. There may be lesser quality USB drives out there that don't work, but I'm sure many will.

I guess I'll just say if you want maximum compatibility and are planning to sell printers, you want 5V on VBUS. If you're just making a printer for home use, the default 3.3V is probably fine.

@fred2088 Thank you for posting your information! I will soon test it myself again. I somehow managed to kill my chip. I don't know how but magic smoke never lies. Glad i hasn't my Arduino Due connected to it. But my USB drive seems dead now as well. But okay, shit happens. A new board is already ordered. :)

@th33xitus: Bummer!

Learning the hard way :D next time i will check everything over ANOTHER time before putting any power
into the circuit at all. Maybe my AMS1117 was faulty and i fed 5V into it or whatever. That was something i didn't check before <.< So learning progress so far: always triplecheck all output voltages. lol

@fred2088 problem fixed?

@marcio-ao
It is possible to purchase a USB BOARD from you

@marcio-ao: Please contact our sales team. Contact info here.

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Roxy-3D picture Roxy-3D  Â·  497Comments

weed2all picture weed2all  Â·  312Comments

kAdonis picture kAdonis  Â·  169Comments

thinkyhead picture thinkyhead  Â·  1715Comments

d2crafty picture d2crafty  Â·  212Comments