M-atthias

Bit-Bang USB on MSP430G2452

275 posts in this topic

43oh Community USB board development in progress.

 

Dear Geeks and Wizards !

 

I happily invite you to share my joy ! Today, the first MSP430G2452 bit-banged the welcome ceremony of USB successfully. Crystal is 18 MHz.

 

Feel free to contact me via m-atthias@users.sf.net to get in touch with development.


Matthias Koch

--> Experimental Mecrimus-B 0.1 is out on mecrisp.sourceforge.net
 

ike and jrychter like this

Share this post


Link to post
Share on other sites

more info please..

 

is this a v-usb like low speed implementation?

 

how do u use a 18mhz crystal on a g2452? do u feed an 18mhz external clock?

 

what's the footprint like? 2k / 4k?

 

thanks in advance.

Share this post


Link to post
Share on other sites

Dear Geeks and Wizards !

 

I happily invite you to share my joy ! Today, the first MSP430G2452 bit-banged the welcome ceremony of USB successfully. Crystal is 18 MHz.

 

Feel free to contact me via m-atthias@users.sf.net to get in touch with development.

 

Matthias Koch

 

--> Experimental Mecrimus-B 0.1 is out on mecrisp.sourceforge.net

 

That is very good news. It would be nice if you could give us some more info.

Share this post


Link to post
Share on other sites

The file is under the download tab of his sourceforge page, named mecrimus-b-0.1.tar.gz.

 

It's an extension of his Forth on msp430 project.

 

All in Assembly, but the commenting is extensive. Only thing is that the majority of the comments are in (taking a logical guess) German. File is encoded in utf-8, so if you open it in something else (Western encoding) some of the letters don't show up right (mainly accented ones). Not sure if any of the code gets messed up, but the comments do so check that.

 

P2.0 to led anode, p2.1 to same led cathode, for a Sync/Activity Light

Seems that p2.2 is d-, tied to p2.5 as a controllable pullup for the usb connect/disconnect action?

p2.3 for d+.

 

From reading what I can (don't sprechen sie deutsch, and assembly is a pita), this is providing a usb 1.1 low-speed, unknown usb class? The usb descriptors don't seem to make sense.

 

Device_Descriptor:
.byte 18,   012h, 001h, 010h, 001h, 0FFh, 0FFh, 0FFh, 008h, 012h, 034h, 056h, 078h, 042h, 043h, 001h, 002h, 000h, 001h
Array Length, Descriptor Length (18), Descriptor Type (1, Device Descriptor), Usb Spec 0110 (USB 1.1), Class 0xFF (Vendor Specific), SubClass 0xFF, Protocol 0xFF, Max Endpoint Packet Size 8 (Bytes), VID 3412 [maybe 1234] (fake), PID 7856 [maybe 5678] (fake), Device Release Number 4342?, Manufacturer String Index 01, Product String Index 02, Serial Number Index 00, Possible configurations 1
 
Configuration_Descriptor_neun: (nine)
.byte  9,      9,    2,  9+9,    0,    1,    1,    0, 080h,   50
Array Length, Descriptor Length (9), Descriptor Type (2, Configuration), Total Length of Data Returned 9+9+0 (18 Bytes), Number of Interfaces 1, Configuration Value (1), Configuration String Index 0, Attribute Bitmap (0x80, 0b10000000, Bit D7 set, meaning USB 1.0 Bus Powered), Max Power in 2ma units (100ma)
Configuration_Descriptor_achtzehn: (eighteen, first nine identical to above)
.byte 18,      9,    2,  9+9,    0,    1,    1,    0, 080h,   50,    9,    4,    0,    0,    0, 0FFh, 0FFh, 0FFh,    0
 
But I don't see a interface or endpoint descriptor, and an interface descriptor would be needed with that Class code of 0xFF (vendor Specific). Possibly a usb-serial setup, but it's not identifying as a CDC device. The Protokollschleife.asm file has more stuff being done, but the german is heavy there.
 
TLDR; seems legit.

Share this post


Link to post
Share on other sites

if you don't want to wait for matthias to answer your questions, you can post the code lines your courious about and i'll translate the comments for you ;)

Share this post


Link to post
Share on other sites

Good morning !

This has been directly from my bench, but I wanted to share this immediately with you before going to sleep. Of course, the next days I will provide a translation and more documentation, as most of you are not speaking German.

- Yes, this is similar to the efforts of V-USB for AVR, but in a very early stage. I am in contact with Christian Starkjohann who wrote V-USB, and he helped me with valuable comments. Thank you !

- For now, Mecrimus-B implements a "vendor specific" do-nothing low speed USB 1.1 device, which essentially only connects and gives back its descriptors, which are quite small. But as this is a test for receiver, transmitter, checksum generation and protocol handling, I am very happy with that yet.

- I feed in clock with an external 18 MHz crystal oscillator; I choosed this so that I can hook up an oscilloscope probe without detuning.

- Memory footprint is 2,5kb now, as there are debug message routines included and an halt-disconnect-and-dump-packet point for unknown requests. USB alone should fit in 2kb code.

Connections are:

(P1.0 LED Anode for Bit-Banged RS232 sinal for outputting debug messages)

P2.0 Sync-LED Anode
P2.1 Sync-LED Cathode (unimportant, only soldered it in this way to be able to measure brightness later)

P2.2 D- over about 50 Ohms (two 100 Ohms resistors in parallel in my case)
P2.3 D+ over about 50 Ohms

P2.5 Resistor 1.5kOhms to D- as switchable connect/disconnect simulator

XIN feeded with digital external 18 MHz clock. Note that the XO runs with same voltage as MSP430, altough rated for 5V, it works.

D- has to be on a pin that for clock cycle reasons is accessible with the constant generator (the lower four pins) and D+ only has to be on the same port as D-.

Included is a picture of the current hardware setup, you will see:
post-25024-0-89182700-1354441605_thumb.jpg
-The test platform with msp430g2452 and external XO, connected with usb and spy-bi-wire
-Two 1N4148 diodes as voltage droppers for roughly 3.6V Vcc
-Optical coupled Lego-based-rs232 ;-)
-Screw terminals for whole Port 1 and power
-My own variant of a spy-bi-wire adapter

Tested with Linux 2.6.26-2-686 and UHCI Host Controller.

Questions are welcome !

Matthias Koch
 

larsie, cde, JWoodrell and 3 others like this

Share this post


Link to post
Share on other sites

lsusb -v gives:

 

Bus 003 Device 002: ID 3412:7856
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               1.10
  bDeviceClass          255 Vendor Specific Class
  bDeviceSubClass       255 Vendor Specific Subclass
  bDeviceProtocol       255 Vendor Specific Protocol
  bMaxPacketSize0         8
  idVendor           0x3412
  idProduct          0x7856
  bcdDevice           43.42
  iManufacturer           1 Matthias Koch
  iProduct                2 Mecrimus-B
  iSerial                 0
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength           18
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0
    bmAttributes         0x80
      (Bus Powered)
    MaxPower              100mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           0
      bInterfaceClass       255 Vendor Specific Class
      bInterfaceSubClass    255 Vendor Specific Subclass
      bInterfaceProtocol    255 Vendor Specific Protocol
      iInterface              0
Device Status:     0x0000
  (Bus Powered)
 

Share this post


Link to post
Share on other sites

 

 

This has been directly from my bench, but I wanted to share this immediately with you before going to sleep. Of course, the next days I will provide a translation and more documentation, as most of you are not speaking German.

 

 

 

thanks for the quick reply. if i am to achieve something like u did, i would be as eager to announce it.

 

such implementation would boost the popularity of the msp430 especially if it can run on dip package value series. thanks for your work.

 

my next question is, will it be possible to use internal clock or the low speed 32khz crystal for timing? that will allow for a more compact deployment. i.e. something like the v-usb attiny85 setup.

 

 

Share this post


Link to post
Share on other sites

For short: Perhaps.

With an 32768 Hz crystal we could determine the internal DCO frequency with good accuracy. So altough we can precisely determine current clock and do adjustments, it is questionable if its step sizes will be small enough for direct use as accurate clock in USB. One more problem left is temperature stability - the DCO is specified to drift with temperature, but USB devices may be in operation for hours next to the stream of warm air from ventilation.

V-USB calibrates the internal DCO with the 1kHz frame clock, just as we would do with our 32768 Hz crystal in place; but then keeps track with a software phase locked loop which can cope with about +- 1%. Perhaps a dive deeper into the usbdrvasm165.inc of V-USB and some more correspondence with Christian Starkjohann could give an idea on how to implement that.

For now, my next steps are: Add comments for English speaking developers and implement some demo functionality. Perhaps a HID keyboard ? After that, I concentrate to perform the same with 15 MHz, which looks possible. This is within spec for MSP430 DIP parts, and a simple 15MHz crystal could be connected to XIN and XOUT.

If I have wishes free:

Now: I wish for testers and testing !

For spring 2013: I wish for someone with experience with V-USB and the mspgcc compiler who would like to merge my assembly efforts with the stable and proven C protocol handling code base and interface of V-USB.

Matthias
 

Share this post


Link to post
Share on other sites

 

For now, my next steps are: Add comments for English speaking developers and implement some demo functionality. Perhaps a HID keyboard ? After that, I concentrate to perform the same with 15 MHz, which looks possible. This is within spec for MSP430 DIP parts, and a simple 15MHz crystal could be connected to XIN and XOUT.

 

If I have wishes free:

 

Now: I wish for testers and testing !

 

For spring 2013: I wish for someone with experience with V-USB and the mspgcc compiler who would like to merge my assembly efforts with the stable and proven C protocol handling code base and interface of V-USB.

 

Matthias

 

 

if u are to make available some english comments, i am interested in studying the code and may be contribute. not sure if i am skillful enough but i can be a tester.

 

i don't have o-scope and such but i worked w/ v-usb before so i am familiar w/ the high level mechanisms at least.

 

 

M-atthias likes this

Share this post


Link to post
Share on other sites

Mecrimus-B 0.2 is out.

English translations are included.
This time, it emulates an HID mouse that moves your pointer to the right.
Tested on Linux 2.6.26-2-686 with UHCI Host Controller.

lsusb -v:

Bus 003 Device 005: ID 3412:7856
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               1.10
  bDeviceClass            0 (Defined at Interface level)
  bDeviceSubClass         0
  bDeviceProtocol         0
  bMaxPacketSize0         8
  idVendor           0x3412
  idProduct          0x7856
  bcdDevice           43.42
  iManufacturer           1 Matthias Koch
  iProduct                2 Mecrimus-B
  iSerial                 0
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength           34
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0
    bmAttributes         0x80
      (Bus Powered)
    MaxPower              100mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           1
      bInterfaceClass         3 Human Interface Device
      bInterfaceSubClass      1 Boot Interface Subclass
      bInterfaceProtocol      2 Mouse
      iInterface              0
        HID Device Descriptor:
          bLength                 9
          bDescriptorType        33
          bcdHID               1.10
          bCountryCode            0 Not supported
          bNumDescriptors         1
          bDescriptorType        34 Report
          wDescriptorLength      52
         Report Descriptors:
           ** UNAVAILABLE **
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0004  1x 4 bytes
        bInterval              10
Device Status:     0x0000
  (Bus Powered)
 

JWoodrell, simpleavr, xpg and 3 others like this

Share this post


Link to post
Share on other sites

Oh  man, usb HID (mainly joystick/gamepad) and usb-cdc would be the best things to work on honestly. Those two would have the most use of a v-usb like project.

Share this post


Link to post
Share on other sites

I would like to see an C implementation of this. Also if it is possible to modify the code for this to operate with 16 MHz crystal it would be great too, because I think 16M is more common frequency than 18M. 

 

Anyways, great job!

Share this post


Link to post
Share on other sites

This project is spectacularly important. I could really use an inexpensive USB interface in many MSP430 projects, where an FT232RL is simply out of the question because of the price! Most of the time I only really need a simple UART.

 

Congratulations on your first successes, and I'm hoping to see more soon.

Share this post


Link to post
Share on other sites

I reached the next milestone !

Mecrimus-B 0.3 is out and freshly supports clocking with 15 MHz.

Because bit clock is 1.5 MHz, frequencies for Mecrimus-B have to be an integer multiply of that. 16 MHz would be REALLY tricky.

Do you already have testing results for me ?

Matthias
 

Share this post


Link to post
Share on other sites

@matthias

 

i am busy w/ other things. i downloaded and study the code a bit. will find time to play w/ it.

 

thanks for the update.

Share this post


Link to post
Share on other sites

One question here has been very interesting:

 

Would it possible to run Mecrimus-B with a common 32768 Hz crystal in place ?

 

 

For that, I measured the DCO frequency steps with Timer-A capture relative to 32768 Hz ACLK in a spare MSP430G2553 with RSEL=15:

 

DCOCTL  kHz     Difference  (Frequency-15MHz)/15MHz

                to 15MHz

                in kHz

 

120     14352   -648    -0.0432

121     14397   -603    -0.0402

122     14438   -562    -0.0375

123     14454   -546    -0.0364

124     14483   -517    -0.0345

125     14528   -472    -0.0315

126     14581   -419    -0.0279

127     14614   -386    -0.0257

128     14639   -361    -0.0241

129     14675   -325    -0.0217

130     14700   -300    -0.0200

131     14741   -259    -0.0173

132     14774   -226    -0.0151

133     14819   -181    -0.0121

134     14843   -157    -0.0105

135     14868   -132    -0.0088

136     14901   -99     -0.0066

137     14933   -67     -0.0045

138     14983   -17     -0.0011

139     15020   20      0.0013

140     15048   48      0.0032

141     15089   89      0.0059

142     15101   101     0.0067

143     15134   134     0.0089

144     15183   183     0.0122

145     15232   232     0.0155

146     15273   273     0.0182

147     15294   294     0.0196

148     15339   339     0.0226

149     15396   396     0.0264

150     15417   417     0.0278

151     15470   470     0.0313

152     15511   511     0.0341

153     15568   568     0.0379

154     15589   589     0.0393

155     15654   654     0.0436

156     15691   691     0.0461

157     15724   724     0.0483

158     15790   790     0.0527

159     15814   814     0.0543

 

 

The longest packets to receive are 11 Bytes, and within 88 Bytes, there may be 15 stuffing bits, which gives a total of 103 Bits.

For keeping sync stable, there may be an error of roughly 1/3 of bittime.

 

This gives for the required accuracy:

103*Accuracy=1/3 --> 0.0032.

We have three steps in DCOCTL that match this requirement.

 

If DCOCTL frequency step sizes are roughly equal in different msp430 microcontrollers (absolute DCOCTL values are not the same and fluctuate with temperature and Vcc), then this opens up a possibility.

 

A quick test with SMCLK output on P1.4 and manual adjusting the DCOCTL register values in my msp430g2452 to get frequency right allowed Mecrimus-B 15 MHz to work as long as temperature and VCC were kept constant.

 

As you can configure Timer-A to capture SMCLK on egdes of ACLK, which I did to measure the DCO step frequencies, you can implement a frequency control loop which is called in regular intervals to keep track with slowly changing temperature and Vcc.

 

For 18 MHz, the step resolution of DCOCTL is more coarse, and I would prefer the finer tuning possibilities around 15 MHz.

 

Would you like to see this implemented ? If Mecrimus-B proves its stability with accurate crystal clock, then this idea could be the next step.

Share this post


Link to post
Share on other sites

Would you like a surprise ? A very special one indeed ?

Mecrimus-B 0.4 runs on a MSP430F2012 with a 32768 Hz crystal !


post-25024-0-17377800-1355190599_thumb.jpg


D+ with 50 Ohms on P1.0
D- with 50 Ohms on P1.1

Pullup with 1.5 kOhms for D- hardwired to Vcc
Sync-LED on P1.2 (Anode with 100 Ohms) and P1.3 (Cathode)
SMCLK for measurements on P1.4

32768 Hz crystal on XIN/XOUT

lunakid and simpleavr like this

Share this post


Link to post
Share on other sites

sweet...

 

how much flash got left. u got to do a simple demo to show this off. something like blinking / cycling the keyboard leds, etc.

 

will definitely attract testers / developers.

 

/EDIT.. is the clock stable enough for prolong operation?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now