Author Topic: Changing Vendor ID  (Read 48769 times)

natarajan

  • Newbie
  • *
  • Posts: 11
Changing Vendor ID
« on: June 25, 2014, 01:12:49 am »
Hi,

I am using micro-nucleus bootloader for a personal project of mine. However, I was trying to mess with the code and changed the Vendor ID to default USBAsp vendor id which is provided free by obdev. I compiled and burnt the code into attiny45. It does give a "ding" sound saying that it is connected. I used the default USBAsp windows driver and all went well. However, I am not able to load any code through USB once connected. I am able to do it using the default vendor ID provided by Digispark (through micro-nucleus). Does anyone please let me know why?

Thanks,
Natarajan

gogol

  • Sr. Member
  • ****
  • Posts: 398
Re: Changing Vendor ID
« Reply #1 on: June 25, 2014, 09:11:11 am »
Why it should work?  Micronucleus is no USBAsp.
USBASP is a ISP-programmer, which is capable to load programs to blank AVR chips. With USBASP you need at least two chips. That one, whioch acts as programmer and the target, which will be programmed.

You can load littlewire on the digispark and use that as an ISP, which works very close to USBASP.

Micronucleus is a piece of software, which need to be present on the target device, when you wish to write programs to it. The benefit is, that you need no extra programmer.  However you need either an USBASP or USBtinyISP, ot STK500, ... programmer, to write the micronucleus on a blank chip.

When you have an USBASP VID/PID on a USB-device, avrdude assumes to speak the USBASP protocol, which is totally different from the micronucleus. (vice versa the same)

natarajan

  • Newbie
  • *
  • Posts: 11
Re: Changing Vendor ID
« Reply #2 on: June 25, 2014, 07:56:20 pm »
Thanks for the response. Ofcourse it should work. Why not?

The drivers for windows tell the computer that there is a device with xx vid connected which belongs to this manufacturer and the name of device is xx.

When I use the drivers of obdev and use usbasp drivers, the reason is because it uses that same vendor id. Since the bootloader is still micronucleus, that should take care of it.

Secondly, I tried littlewire. For some reason it never works for me. Once the fitst issue is sorted, I thought of looking over it.

I may be wrong in understanding. Someone can shed some light please.

Thanks.

dougal

  • Sr. Member
  • ****
  • Posts: 289
Re: Changing Vendor ID
« Reply #3 on: June 26, 2014, 05:01:47 am »
Just because you slap a Porche sticker on a Hyundai, it doesn't make the car go faster.

Likewise, changing the USB VendorID to the one for USBAsp, it doesn't magically make your device act like a USBAsp. Basically, you're lying to the computer, telling it that your device is one thing, when it's really another thing.

gogol

  • Sr. Member
  • ****
  • Posts: 398
Re: Changing Vendor ID
« Reply #4 on: June 26, 2014, 07:47:01 am »
micronucleus doesn't take care of anything for a running application.
USBASP has its own VID/PID   littlewire as well.

Both program can be run on a AVR without any bootloader involved.  However in many cases, there is an bootloader below.

When you start an digispark with littlewire loaded, the digispark fist enumerates with the VID/PID of micronucleus, waiting for the command line client to connect.
When the command line client does not connect within some seconds, micronucleus disconnects from the USB bus and starts the installed application. In case of littlewire or USBASP the application itself takes over the USB bus and enumerates with their VID/PID, ready to talk e.g. with avrdude.


gogol

  • Sr. Member
  • ****
  • Posts: 398
Re: Changing Vendor ID
« Reply #5 on: June 26, 2014, 08:10:16 am »
One more example:

When I use a digispark with littlewire as USBtinyISP, i it enumerates with a VID/PID which is registered by Adafruit Technologies.  I uses the libusb32-USB driver (http://sourceforge.net/apps/trac/libusb-win32/wiki) and I can flash code to an AVR, which is connected to the digispark, using USBtinyISP as programmer.
----+        +----------------+     +--------------------+
    |        | digispark with |     |  target            |
PC  +---USB--+ littlewire     +-----+  AVR chip          |
    |        | as ISP         |     |  e.g. blank tiny85 |
----*        +----------------+     +--------------------+


When I however select in the same setup accidently the digispark as programmer,
----+        +----------------+     +--------------------+
    |        | digispark with |     |  no target :-(     |
PC  +---USB--+ micronucleus   +     +  AVR chip          |
    |        |                |     |  e.g. blank tiny85 |
----*        +----------------+     +--------------------+

and reset the digispark in the right moment, that micronucleus can enumerate with the USB bus, i overwrite littlewire on my digispark with that program, I planned to send to the target chip.

natarajan

  • Newbie
  • *
  • Posts: 11
Re: Changing Vendor ID
« Reply #6 on: June 26, 2014, 10:27:57 am »
Thanks for the responses. I think I am complicating the issue than what I need to say. Just trying to make it more clear.
My question - How do I change the VID given by Digispark to free VID given by Obdev?

First, I have this micronucleus bootloader. I edit usbconfig.h file to insert a new USB_CFG_VENDOR_ID  and USB_CFG_DEVICE_ID which is (0xc0, 0x16) and (0xdc, 0x05) and compile it successfully. This is the one provided for free by Obdev. Now, I use libusb-win32 to create an INF file, dll's and supporting files for this particular vendor ID which means that Windows should be able to recognize the usb device. I replace the micronucleus windows drivers with this one. So, to my understanding, the device id, vendor ID and dll files are used as a handshake between the computer and usb device. (to enumerate) Am I correct in this?

After doing all this, I upload the modified micronucleus code into the device, connect the device through a USB cable and open command window. I get the ubiquitous "ding" sound which means it is connected and asks for drivers. I provide the new driver location. The install succeeds and says "your new device is ready... " and so on. Now I open micronucleus command window and pass a new "blinking LED" hex file to upload. It stays there and does not go further. Why is this?

Some guesses:
1. There is something in the command line window code of micronucleus which is connecting only to particular VID.
2. The VID is present in more than one place in the actual code.
3. I am getting it all wrong which means somebody can please guide me.

Quote
micronucleus doesn't take care of anything for a running application.
I understand. It is used only as a bootloader which helps load custom firmware through *usb*.
Quote
When I use a digispark with littlewire as USBtinyISP, i it enumerates with a VID/PID which is registered by Adafruit Technologies.
I have tried littlewire, but somehow it does not work. Maybe because I have reset the reset pin to work as reset pin rather than normal IO pin. Still not sure though. By the way, are you using Digispark Arduino to program and selecting USBTinyISP, or is it that you are using AVRDude directly?

I am using AVRDude with this commands : "-pt85 -cusbtiny -Uflash:w:SIMPLEBLINK.hex:a" and failed. It says:

avrdude: initialization failed, rc=-1
avrdude: AVR device initialized and ready to accept instructions
avrdude: Device signature = 0x000000
avrdude: Yikes!  Invalid device signature.
avrdude: Expected signature for ATtiny85 is 1E 93 0B
avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed

Clearly, it is not able to flash or recognize Littlewire firmware as USBTinyISP.

« Last Edit: June 26, 2014, 11:00:23 am by natarajan »

dougal

  • Sr. Member
  • ****
  • Posts: 289
Re: Changing Vendor ID
« Reply #7 on: June 26, 2014, 11:29:23 am »
What are you trying to accomplish? Why are you changing the VenderID in the micronucleus bootloader?

You didn't say anything about recompiling the micronucleus command line utilities to match the VendorID, so I assume that's the problem. As far as I know, the command line tools will look for the predefined VendorID/ProductID to recognize which device to program.

natarajan

  • Newbie
  • *
  • Posts: 11
Re: Changing Vendor ID
« Reply #8 on: June 26, 2014, 11:37:47 am »
Quote
What are you trying to accomplish? Why are you changing the VenderID in the micronucleus bootloader?
I am trying to learn how this entire concept of VUSB, USB Enumeration works.
Quote
As far as I know, the command line tools will look for the predefined VendorID/ProductID to recognize which device to program.
I did find it in micronucleus command line code. Will recompile and update you all soon.

natarajan

  • Newbie
  • *
  • Posts: 11
Re: Changing Vendor ID
« Reply #9 on: June 26, 2014, 12:06:16 pm »
Well. Failed again. This time, it did compile properly, but failed in micronucleus_lib.c with error:
I modified the vendor ID in micronucleus_lib.h to reflect:

#define MICRONUCLEUS_VENDOR_ID   0x16C0
#define MICRONUCLEUS_PRODUCT_ID  0x05DC

Assertion failed: res >= 4, file library/micronucleus_lib.c, line 66

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

Why is modifying this code so difficult?

natarajan

  • Newbie
  • *
  • Posts: 11
Re: Changing Vendor ID
« Reply #10 on: June 26, 2014, 12:18:56 pm »
It seems like I have to give up learning this. The code is too difficult for my first project. For god's sake, I do not know where all they have modified it and why is it not working. Maybe the author of this micronucleus can show the way.

gogol

  • Sr. Member
  • ****
  • Posts: 398
Re: Changing Vendor ID
« Reply #11 on: June 26, 2014, 12:22:29 pm »
It still looks, that you are making things ways to complicated and are generating a mess:

Micronucleus and USBASP are totally different things. Its like ssh and telnet, if you are familiar with that. In ssh the server listens on port 22, the telnet server on port 23.
If you patch the telnet server to listen on port 22, and the telnet client, that it connects by default as well to port 22, they still speak telnet and no ssh!

When you are patching now micronucleus (bootloader and command line client) that they use USBASPs VID/PID you are creating a mess.  Sure, YOUR micronucleus client is now able to talk to YOUR micronucleus loader, but your avrdude will fail, when you are trying to use USBASP, as that device which claims to be by VID/PID a USBASP is still a micronucleus.

The original USBASP runs on atmegas, and has no bootloader below.  There is an USBASPLOADER avaliable, which can be installed on atmegas but not on attinies.  This loader behaves from protocol like an USBASP-ISP, but is included in the target.

With the digispark I use littlewire very often, as I have described in the wiki (http://digistump.com/wiki/digispark/tutorials/programming#using_littlewire_as_usbtinyisp).
I use it to flash several AVRs without any problem from linux and windows, from the command line and embedded in the Arduino-IDE (which also only calls the command line).

What you have to understand, is, that a digispark with littlewire has TWO VID/PID paits, depending on its running state.  In the very first seconds after reset it uses the micronucleus pair, and is ready to accept new code for itself.  Later, when littlewire is started, it uses the littlewire VID/PID and behaves as ISP.

For Windows/linux it looks like, that you are connecting/disconnecting two different devices to your USB port. Both devices will get different COM-ports associated as well!

The next point, where you also need to take care, that you should use always a micronucleus client, which is has the same or a more recent version, than the loader. As the protocol has changed, older clients can't talk to newer loaders.  Newer clients are however backwards compatible.


gogol

  • Sr. Member
  • ****
  • Posts: 398
Re: Changing Vendor ID
« Reply #12 on: June 26, 2014, 12:26:31 pm »
It seems like I have to give up learning this. The code is too difficult for my first project. For god's sake, I do not know where all they have modified it and why is it not working. Maybe the author of this micronucleus can show the way.

I don't think, that the current author will show you the way, even when he (cpldcpu) is member of this board.

It makes IT systems very unstable, when you change VID/PIDs, which are assigned to a very specific device to those of other devices, which are incompatible. 

natarajan

  • Newbie
  • *
  • Posts: 11
Re: Changing Vendor ID
« Reply #13 on: June 26, 2014, 01:24:47 pm »
Then why in the device description of usbconfig.h they have mentioned this? This is what led me to start learning about VUSB and then further came to this conclusion:

#define USB_CFG_VENDOR_ID 0xD0, 0x16 /* = 0x16d0 */
/* USB vendor ID for the device, low byte first. If you have registered your
 * own Vendor ID, define it here. Otherwise you may use one of obdev's free
 * shared VID/PID pairs. Be sure to read USB-IDs-for-free.txt for rules!
 */

I thought open source is all about sharing and learning. If it is tied to a particular vendor and project, then it should be closed source as it cannot be modified further. Also, I have read a lot about VUSB and there are a thousand projects which use shared VID/PID. Maybe yes, I am new to this and may not understand it fully, but if I ever recreate one like this, I am sure to make it as customizable as possible such that anyone can just change VID/PID and use it for their own purposes (no harm in dreaming I guess :)

BTW gogol, thanks for all the kind assistance you provide. I know it may not have solved the problem, but atleast you are  helpful.

Edit:
Just missed your previous post. Reading it to understand it properly :)

Edit again: Ok. Just read the entire thing you wrote and kind of understood. So now the conclusion is that there is no way I can change VID/PID (though the documentation says in the code). Even If I do, I need to get a VID/PID which is purchased to act as a USBTinyISP and there seems to be no free VID/PID which I can use to demonstrate at. I guess this is where it ends. Thanks for all the support. I seriously need to learn a lot yet.
« Last Edit: June 26, 2014, 01:53:05 pm by natarajan »

natarajan

  • Newbie
  • *
  • Posts: 11
Re: Changing Vendor ID
« Reply #14 on: June 26, 2014, 02:35:15 pm »
Ok, just if someone is interested, all devices using libusb (includes USBASP also) uses the same free VID/PID pair. Here is an extract of these pairs:

PID dec (hex) | VID dec (hex) | Description of use
==============+===============+===================
1500 (0x05dc) | 5824 (0x16c0) | For Vendor Class devices with libusb
-------------------+-------------------+--------------------------------------------
1503 (0x05df) | 5824 (0x16c0) | For generic HID class devices (which are
                       |                         | NOT mice, keyboards or joysticks)
------------------+-------------------+--------------------------------------------
1505 (0x05e1) | 5824 (0x16c0) | For CDC-ACM class devices (modems)
-------------------+-------------------+--------------------------------------------
1508 (0x05e4) | 5824 (0x16c0) | For MIDI class devices
-------------------+-------------------+--------------------------------------------

Also, for ones information, micronucleus depends on libusb too I guess. I may stop today, but will keep my research on. If in case I succeed, will share it across with all of you
« Last Edit: June 26, 2014, 02:37:47 pm by natarajan »