TinyUSB-based logic analyzer code for Sigrok
Make it easy to use a microcontroller board as a logic analyzer.
- A driver for sigrok that can communicate with a wide array of microcontroller boards.
- Use tinyUSB to create easy-to-modify embedded code that can be adapted to various chip families.
- A basic list of human-readable (SCPI) commands for communication between sigrok and the tinyLogicFriend microcontroller board.
- libsigrok: sigrok device driver to communicate with tinyLogicFriend, this runs on the host computer
- tinyLogicFriend (This repository): microcontroller code that can be adapted to each board family, this runs on the microcontroller board
- uses tinyUSB for handling communication to sigrok
- has parsing for handling SCPI commands from the host computer
- include an outline for adding the board-specific to:
- setup channels, triggers, sampling rates and sample counts
- Read signals and send back to the host computer
- a basic communication protocol between sigrok and tinyLogicFriend to set up the instrument and to initiate and read measurements
-
Install the sigrok suite. This can be run at the command line using
sigrok-cli
or using thePulseView
graphical interface. You will need to get a version that includes the tinyLogicFriend sigrok driver. Right now, you need to build it for yourself using the tinyLogicFriend driver from my githublibsigrok
repository. I strongly recommend using sigrok-util to build for your platform. You will need to replace the baselinelibsigrok
library with this version that includes the tinyLogicFriend driver. Then build everything, includinglibsigrok
,sigrok-cli
andPulseView
. So far, I have succesfully built PulseView with tinyLogicFriend on an iMac running MacOS Big Sur. -
If your board is supported: Download the appropriate
.UF2
file from the\boards
directory. -
Connect your tinyLogicFriend to your host computer via USB (be sure you are using a USB cable with the signal lines connected).
-
Put your board into bootloader mode (usually by double-clicking.
-
Copy to your board the appropriate
.UF2
file (the one named the same as your board). -
Start up
sigrok-cli
orPulseView
and confirm that your tinyLogicFriend is detected.
- Download the example file and update the following sections of these files according to your board's requirements:
- Add entry in
boards/
- If your chip is not supported, create the
logic_capture.c
andlogic_capture.h
under the directorymcu/(VENDOR)/(CHIP_FAMILY)
- Add entry in
- Run make with the board, chip VENDOR and CHIP_FAMILY for example:
make BOARD=itsybitsy_m4 VENDOR=microchip CHIP_FAMILY=samd51
- Connect to the host computer via USB and put your board into bootloader mode (usually by double-clicking the reset button).
- Build the UF2 file (from the
.bin
file that is created in the_build
directory) and copy the UF2 file onto the board's boot drive, for example:python uf2conv.py -c -b 0x4000 -o _build/itsybitsy_m4/itsybitsy_m4-tinylogicfriend.uf2 _build/itsybitsy_m4/itsybitsy_m4-tinylogicfriend.bin; cp _build/itsybitsy_m4/itsybitsy_m4-tinylogicfriend.uf2 /Volumes/ITSYM4BOOT
- Includes a basic set of SCPI (Standard Commands for Programmable Instruments) commands suitable for basic digital logic analysis
- Uses a USB TMC (Test and Measurement Class) to connect between sigrok and tinyLogicFriend
- Code is available for ATMEL-SAMD Cortex M4, currently with builds for two boards
- Adafruit ItsyBitsy M4 Express
- Adafruit Metro M4 Express
- Utilizes the board's available pins that correspond to these M4 chip pins: PA08-PA23
- The sampling uses interrupts and Run Length Encoding, with a clock running at 48 MHz
- Can decode I2C signals running at 100 kHz
- Current Limitations (for future improvement):
- Triggers are set on all channels for both edges
- Fastest square wave measurement is around 200 kHz
-
IDN?
Get identification details of the board -
CHANnel:COUNT?
Get number of channels -
CHANnel<n>:NAME?
Get channel number <n> name -
CHANnel<n>:STATus
eitherOFF
orON
Set channel reading status (Implemented in parser, but not hooked up to chip controls.) -
CHANnel<n>:STATus?
Get channel read status (Implemented in parser, but not hooked up to chip controls.) -
CHANnel<n>:FILTer
eitherOFF
orON
For Run-length encoding mode, whether filtering is placed on the interrupt pin. (Is interrupt filtering applied for all pins or each individually?) -
CHANnel<n>:FILTer?
Get filter status, only relevant whenMODE RLE
-
TRIGger:OPTions?
(Implemented in parser, but not hooked up to chip controls.)Get trigger options
<v>
- X=trigger off
- 0=on zero
- 1=on one
- R=rising
- F=falling
- E=any edge
-
CHANnel<n>:TRIGger <v>
Set trigger type (Implemented in parser, but not hooked up to chip controls.) -
CHANnel<n>:TRIGger?
Get trigger type for channel<n>
(Implemented in parser, but not hooked up to chip controls.) -
RATE:MIN?
Get minimum sampling rate (in Hz) -
RATE:MAX?
Get maximum sampling rate (in Hz) -
RATE:STEP?
Get sampling rate step size (in Hz) -
RATE <xxxx>
Set sampling rate -
RATE?
Get sampling rate -
SAMPles <xxx>
Set number of samples to be captured. Set to 0 for continuous sampling. Sample count is relative to the sampling rate clock, even when run-length encoding is used -
SAMPles?
Get number of samples -
SAMPles:MAX?
Get maximum number of samples -
MODE <Y>
EitherRLE
orCLOCK
. Run-length encoded or sample at configured sampling rate. -
MODE?
EitherRLE
orCLOCK
-
Run
Start measurement -
STOP
Stop measurement -
DATA?
Request a data packet