Author Topic: USBTMC/USB488 class implementation for microcontrollers  (Read 3274 times)

0 Members and 1 Guest are viewing this topic.

Offline pigrewTopic starter

  • Frequent Contributor
  • **
  • Posts: 680
  • Country: us
USBTMC/USB488 class implementation for microcontrollers
« on: September 22, 2019, 11:55:41 pm »
I have written a USBTMC/USB488 class driver for microcontrollers (link updated 2020-07-10), based on the TinyUSB library. I'm hoping it'll be merged into the TinyUSB stack soon.

USBTMC/USB488 (in case you don't know) is the USB protocol used by test and measurement equipment (like oscilloscopes/DMM/etc...). In the market, it's in the process of replacing GPIB (IEEE488) interfaces. In hobby projects, USB CDC is the most common interface, often implemented via FTDI USB interface ICs.

I started writing it after searching for prior art. I was unable to find any open-source implementations which are standards compliant (or every mostly complete). TinyUSB won my vote due to its goal of compatibility with many different MCUs. I didn't want to have to ever port my code between USB stacks when switching MCUs. It also is developing with a goal of thread-safety so it can be used with a RTOS. "Tiny" is a good feature too; I can fit my implementation on a STM32F042 with 6 kB of RAM and 16 kB of flash with enough space left for application code. In the near future, I think the project will be limited to 16/32-bit little-endian MCUs, but this may expand in the future.

The USBTMC class driver implements most of the USB488 protocol (read STB, flash a light, clear, trigger, write, read, abort read or write, etc...), though some optional features are presently missing (like changing between remote/local states). Performance may also be somewhat lacking (I've not been optimizing for throughput), though it can be improved. There's also only a minimal application layer at the moment, it'll be up to you to implement a IEEE 488.2 state machine, SCPI (or perhaps use the scpi-parser library), and your actual product code.

So, if you are working on a micro-controller project which needs a message-based command interface, you may want to look into using this library.

USBTMC specification download page(zip file)

-Nathan

PS: This protocol seems difficult enough that many products have non-conforming implementations. (Last time I checked my Siglent SDG2042X, it didn't support CLEAR, as an example.)
« Last Edit: July 10, 2021, 02:45:21 pm by pigrew »
 
The following users thanked this post: oPossum, ajb, ebclr, artag, prasimix

Offline mTron47

  • Newbie
  • Posts: 9
  • Country: ch
Re: USBTMC/USB488 class implementation for microcontrollers
« Reply #1 on: June 08, 2021, 06:41:20 pm »
Hi Nathan
What you wrote seems to be exactly what I have been looking for: a USBTMS device running on e.g. a Atmel SAMD21. Up to now i have fiddled using Atmel Studio 7.0 and ASF. The USB example implementations seem to kind of work for the basic classes such as USB CDC, but not for TMC. The same seems to be true for TinyUSB which supports SAMD21 among many other architectures. Indeed it is my goal to learn more about USB in general, but a working USBTMC implementation seems to be a good starting point.
Problem is that your link to your GitHub runs a 404-error. Coincidence or intent?
Cheers
Peter
 

Offline voltsandjolts

  • Supporter
  • ****
  • Posts: 2300
  • Country: gb
Re: USBTMC/USB488 class implementation for microcontrollers
« Reply #2 on: June 08, 2021, 07:06:24 pm »
Looks like it managed to swim upstream:
https://github.com/hathach/tinyusb/pull/160
So should be part of the tinyusb project now.
Disclaimer: I've never tried it
 

Offline mTron47

  • Newbie
  • Posts: 9
  • Country: ch
Re: USBTMC/USB488 class implementation for microcontrollers
« Reply #3 on: June 08, 2021, 07:50:31 pm »
@voltsandjolts
Thank you for your super-quick and helpful response!  :clap:

Peter
 

Offline pigrewTopic starter

  • Frequent Contributor
  • **
  • Posts: 680
  • Country: us
Re: USBTMC/USB488 class implementation for microcontrollers
« Reply #4 on: July 07, 2021, 02:29:46 pm »
Yes,

The USBTMC code was merged upstream a while ago, as mentioned. My "standard" workflow for GitHub is to delete branches after they are merged, so that's why the link broke.

https://github.com/hathach/tinyusb/tree/master/src/class/usbtmc is a working link to the class implementation.

I've not personally used the SAMD21, but it should work and many people use TinyUSB on the SAMD21.
 

Offline jancumps

  • Supporter
  • ****
  • Posts: 1272
  • Country: be
  • New Low
Re: USBTMC/USB488 class implementation for microcontrollers
« Reply #5 on: January 29, 2023, 05:39:07 pm »
update: I've tested it for the Raspberry Pico controller and it works there too.
And someone has tested the integration with the scpi-parser lib that's mentioned in the original post.

edit: I've tested the integration with SCPI-parser too yesterday. I made the integration a bit simpler than the link I gave above. Stayed as close as possible to the example of pigrew, and only adapted the state machine in the place where the SCPI command arrives and when the parser is ready and replies can be sent.
« Last Edit: January 30, 2023, 01:39:37 pm by jancumps »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf