Jump to content
M-atthias

Bit-Bang USB on MSP430G2452

Recommended Posts

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!

16 MHz is impossible unless you are using an MSP with an FLL, which can bump-up the frequency to 48MHz and then divide it down.  Of course, if you are using an FLL MSP, you can use a 4MHz clock just as well, and even better you could change your design to one of the F5 series devices that includes HW USB.

 

The spec for low-speed USB is 1.5 MHz with 2% clock tolerance (this is from my memory... might be *slightly* different).  If you used a 16 MHz crystal, the clock error could not be better than 4.2%, which is out of spec for USB low-speed.

 

In any case, it seems now that Matthias has built a version for 15MHz, so you can use it with sub-16MHz MSPs now.

Share this post


Link to post
Share on other sites

Hallo Joseph !

Your sync code looks very interesting ! For code size, this really wins. Drawback is that USB lines have to be connected to SPI pins. A hint, if you are in hurry: Instead of bit.b #0x08, &P1IN which takes 4 cycles, you could store both values to registers and use bit.b @r9, r10 instead, which is only 2 cycles. I will dive deeper into it as I get more time.

Note that my synchronization catches every packet, too ! It has one rough and three fine stages, because other interrupts or atomic blocks may occour that disable interrupts for some cycles and change latency. With late start and only one fine stage, it will synchronize to within 2 cycles, an earlier start with time for two or three fine stages will result to sync within 1 cycle. You can check this with an oscilloscope and the Syncled output.

I use the macro assembler AS from Alfred Arnold, Release 1.42 Beta [bld 55].
You get it and its documentation here http://john.ccac.rwth-aachen.de:8000/as/

Note that you need the current beta
http://john.ccac.rwth-aachen.de:8000/ftp/as/source/c_version/asl-current.tar.gz
as proper MSP430 support has been added AFTER the last stable release.

I am happy to have introduced you to assembly with my initial mail :-) For help, at the moment, I wish for testing. Try it ! And please tell me of your results, unlike the others that have downloaded Mecrimus-B without any testing feedback yet. Can I give you hints for better understanding my source ?

For me, I am trying to make the code more readable, more portable (current is 0.4, in which ports and lines are already easily interchangeable) and my destination is to make it ready for "dropping in" into other projects that could benefit from usb connectivity. Soon I will assemble this forum posts into a proper README file that contains most relevant stuff.

Best wishes from snowy Germany,
Matthias
 

Share this post


Link to post
Share on other sites

Actually, 16 MHz isn't impossible. Christian Starkjohanns V-USB shows us how to handle this in usbdrvasm16.inc: Insert leap cycles here and there to stay in sync... But as this is really tricky, I am not going to tackle it now. MSP430 chips are more likely to have 32768 Hz crystals, aren't they ? And, unlike AVR, the MSP430 has finer DCO frequency adjustment steps that reach the needed accuracy of about 0.3% without the need for a PLL in receiver. Note that USB specification has much broader ranges for clock frequency, but it specifies a hardware PLL that copes with it !

@JPNorair: By the way: Are your CC430F5137 boards finished ? Have you included Mecrisp Forth into your real time operating system yet ?
 

Share this post


Link to post
Share on other sites

works under windows.

i use windows version of as (asw) to compile and mspdebug to download, done under cygwin.

windows detects it immediately, try to find a driver for a little while and installed a mouse driver.

it makes my mouse pointer moves sideway to the right continously.

 

 

 

IMAG0296.jpg

 

i replace the two Vdrop diodes w/ a 78L33 and no indicator led.

 

i am starting to play w/ the code. they are quite different from gas (from gcc).

 

now can u tell me which one is timing critical so i would try to move them to gcc (and redo others w/ C)

 

 

Mecrimus-B-15MHz.asm
Mecrimus-B-32768Hz.asm
Mecrimus-B.asm
PacketGenerator.asm
Protocolhandler.asm
Receiver-15MHz.asm
Receiver-Common.asm
Sync-15MHz.asm
Transmitter-15MHz.asm
datastack.asm
messages.asm
mspregister.asm
rs232-over-led-15MHz.asm
rs232-over-led.asm
(i took away the 18mhz ones)
 

do i just need to preserve the "sync" and "receiver" routines? or more.

 

thanks.

 

 

Share this post


Link to post
Share on other sites

Wow ! Cool :-) Thank you for testing !

Basically, you should preserve all interrupt handlers as they are.

The 32768 Hz code needs the following absolutely cycle accurate timing critical parts:

- Sync-15MHz.asm
- Receiver-15MHz.asm
- Transmitter-15MHz.asm

Not cycle accurate, but also very timing critical:

- Receiver-Common.asm
- Frequency_Adjust_Irq in Mecrimus-B-32768Hz.asm

Matthias
 

Share this post


Link to post
Share on other sites

@matthias

 

what is a "nop2"? i am trying to move tiny bits from as to gas.

 

 

sync.S:126: Error: unknown opcode `nop2'
 
 
/EDIT nevermind (it's a macro, i.e. nop2 = 2 nops,  nop3 = nop2 + nop; nop4...) OK,... macros..

Share this post


Link to post
Share on other sites

Is there simple "Hello world" example for Windows using Winapi to interface HID device (HID class does not require separate drivers admin rights and digital certificates, and it's allowed to be used with Low Speed USB, unlike ACM/CDC classes)?

Share this post


Link to post
Share on other sites

@JPNorair: By the way: Are your CC430F5137 boards finished ? Have you included Mecrisp Forth into your real time operating system yet ?

The boards are finished, but manufacturing is not finished.  Mecrisp is not yet integrated as a scripting language for OpenTag, but one thing at a time!  These boards make arduino and launchpad look like junk, but the extra level of design takes more time.  I spent a long time fixing the hardware USB system of MSPF55xx...  Now you have a SW lib... it is probably more reliable!  If I find myself in your town, we should have a beer.  I will buy. 

 

On 16MHz for USB: Technically, I don't think this meets the USB spec.  Of course, most USB hosts are designed to be more tolerant than the spec dictates.  So, impossible to get certification, but apparently possible to get functionality.

Share this post


Link to post
Share on other sites

I am going to start translating the assembly into the CCS assembly version for the critical files he listed.

 

I am starting with the 15MHZ sync file

I don't have it compiled and loaded yet but that is on the to do list

Share this post


Link to post
Share on other sites

Last I checked, CCS assembly is basically just the regular assembly... Is there something I'm missing?  In fact, I've made some hacks in CCS based on the fact that inline assembly to CCS (CL430) is not the restructured variant as used by GCC.

Share this post


Link to post
Share on other sites

Directives, labels, memory allocation, case sensitivity, other stuff...

 

I am also refactoring the code. The original source uses #includes that essentially make the whole thing one big *.asm file. The refactored version assembles each source file independently and uses the linker to resolve imports/exports. This will hopefully allow some of the code that is not timing sensitive to be written in C.

 

I have code that assembles with CCS v4 - will be testing soon.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...