Posts

Running USB Host code on Digilent chipKIT board

chipKIT Uno32 with USB Host Shield

ChipKIT Uno32 with USB Host Shield


Andrew Kroll and I were talking a lot about running USB Host Shield at higher SPI speeds. We were discussing one peculiar case of seemingly defective SPI master module and were needed full sized shield-compatible host board with fast SPI to check our theories when I realized that I have two Digilent ChipKIT Uno32 boards sitting in my ever expanding “to-do” pile of projects. I sent one to Andrew and soon he made a port which compiles under Digilent’s IDE and runs on chipKIT boards, although we only tested on Uno32 (rev.B).

It should be noted that another good candidate for the host board capable of high-speed SPI would be Arduino DUE. It is supported by the library and presumably runs at up to 24 MHz SPI speed with full-size shield. Incidentally, none of us have a DUE so we can’t test. Donations are gladly accepted.

The chipKIT support is currently in beta. At the moment, the only code example I have verified is Board QC routine – a program I’m using to test the shields before selling them to people. The port lives in xxxajk branch. Making other examples work should be a simple matter of (quoting Andrew) “including the right SPI.h”. Indeed, nothing in the library relies on SPI speed so increasing it would simply allow data to be sent faster.

In this article I will show how I modified a standard full size USB Host shield rev.2.0 to run on chipKIT Uno32 board at high SPI speed. I was able to run up to 20 MHz; unfortunately, the next available SPI rate on Uno32 is 40 MHz which is too high for the MAX3421E chip. The modded shield can be seen on a title picture (click on it to make it larger). Uno32 is 3.3V board; even though the inputs on PIC32 on-board MCU are 5V tolerant and it is likely possible to run the shield as-is I removed the level shifting ICs, which are unnecessary when interfacing the shield with 3.3V boards and could decrease error margin. Also, the RESET line on the ICSP connector on Uno32 has been replaced with CS by Uno32 designer, perhaps to make it look more like SPI, so I also needed to disconnect and reroute it. Here is the implementation, step-by-step.

ICSP Mod var.1

ICSP Mod var.1

First step is to disconnect pin 5 of the ICSP connector. It is connected to the reset line of USB Host controller on the shield and CS line on Uno32 SPI module – this will never work. The easiest way to break the connection is to remove a contact from pin 5. This can be done from either side, Uno32 or the shield. On Uno32 it is quite trivial: pin 5 can be simply cut off. However, this will also remove CS signal which could be useful for other shields. Removing the contact from the shield side is just slightly harder. Since I’m starting with a shield with 2×3 connector un-soldered, I first pull the contact from pin 5 and then solder on the connector. Picture on the left shows modified connector ready to be put in place.

For those who has the ICSP connector already in place the procedure is again just slightly harder. The trick is to deal with individual contacts rather than the whole assembly. In order to achieve this you can pull the plastic cover off the contacts grabbing it with a pair of pliers or prying it off with a pair of flat screwdrivers. The contact on pin 5 can then be de-soldered without much difficulty and connector reassembled. Take a look at the picture on the right to see the connector with pin 5 removed and ready to be put back together.

After this was done I removed two level-shifting ICs using hot air and closed the 6 solder jumpers situated around the ICs. I don’t have a closeup of it, please refer to the title picture.

The next step is to provide a reset line to the MAX3421E. I ran a wire from now vacant pin 5 of the ICSP connector and reset pin on the side of Uno32 board. This gives me properly functioning reset button. The reset can also be simply pulled up to 3.3V through 10K resistor. One end of the resistor can be soldered to pin 5 and the other one to the pin 14 of now vacant footprint of AHC level shifter.

ICSP Mod var.2

ICSP Mod var.2

This concludes the shield modification. The Uno32 will work as-is, with the JP4 jumper set to RD4 position. Curiously, this is also a setting for CS signal – in order for the shield to function CS must be routed to pin 10. After this is done the shield can be connected to Uno32 as usual. The code is on github in ‘xxxajk’ branch and will compile in the current revision of MPIDE. One thing I’d like to point out is SPI speed setting. In order to run at speeds higher than 8 MHz a SPI.setClockDivider(x); shall be placed after this line. X could be ‘1’ or ‘2’. This oscilloscope screenshot shows SPI SCK signal with clock divider set to ‘1’ and it looks like 20 MHz to me.

The code and shield modification described in this article were made for the problem we were solving and I’m not even sure anyone will be interested in it – as far as I can see Digilent boards are not particularly popular. If you think further development could be useful please let us know – github issue tracker is perhaps the best place for that.

Thank you for your interest!

Oleg.

11 comments to Running USB Host code on Digilent chipKIT board

  • I’m glad this is done, thank you. Please let us not forget that I ported the old library over two years ago…

    Jacob

    • Long time no see :-). Yes, I remember you; this port was made partly because I knew it would work, thanks to your previous work.

      • I can’t wait to try the new port. I am pretty busy at the moment but last week I got some other pieces to the original puzzle I was working that motivated me to port the old lib to chipKIT in the first place. Now I want to throw it together with this new port. I am trying to get a link from chipKIT.net to this post as well.

        Jacob

  • Hartwig

    Hi Oleg,

    I’m glad to read this news.

    Some month a go, I’ve made a quick and dirty port as well. My test installation works with your USB Host Shield Mini and an Fubarino SD, without any hardware modification, because both boards are 3.3V boards.
    I will switch to your port asap.

    Do you have any timeline for a PTP 2.0 library port as well?

    thanks
    Hartwig

  • Hartwig

    In MPIDE I’ve got a error…
    nkeventparser.cpp:In member function ‘virtual void NKEventParser::Parse(uint16_t, const uint8_t*, const uint32_t&)’
    nkeventparser.cpp:50:26: error: cast from ‘uint16_t*’ to ‘uint16_t’ loses precision

  • Peter Morgenthaler

    Hi, I like the idea of this project. I am wondering if this could be used to host USB UVC compatible webcams. There are lots of people out there who want to do this through a microcontroller butthe UNO/WF32 is probably one of the only ones powerful enough to do it. Would like to hear your thoughts on the possibility. Thanks

  • David Aparicio

    In general, PIC32MX2 chips have USB host capabilities. In the ChipKit case, they did not designed the Uno32 with proper USB host circuit, but it is done with Max32 and DP32 which are both full OTG. The Olimex Piguino has same capabilities too.

    In those cases the USB Shield is redundant and would make sense to have a chipKit library that drives the PIC32 host capability. Do you have notice anyone doing this initiative?

    thank you