{"id":1226,"date":"2013-09-14T01:00:00","date_gmt":"2013-09-13T23:00:00","guid":{"rendered":"https:\/\/www.fussylogic.co.uk\/blog\/?p=1226"},"modified":"2013-09-12T20:00:07","modified_gmt":"2013-09-12T19:00:07","slug":"stm32f4-based-logic-analyser","status":"publish","type":"post","link":"https:\/\/www.fussylogic.co.uk\/blog\/?p=1226","title":{"rendered":"STM32F4-based Logic Analyser"},"content":{"rendered":"<p>I\u00e2\u20ac\u2122ve been meaning to try <a href=\"https:\/\/code.google.com\/p\/logicdiscovery\/\">this project<\/a> out for a while\u00e2\u20ac\u00a6 It\u00e2\u20ac\u2122s a basic logic analyser built on the <code>STM32F4DISCOVERY<\/code> board.<\/p>\n<p>The <code>STM32F4<\/code> runs at 168MHz, so we\u00e2\u20ac\u2122ve got a fair bit of bandwidth available. Nothing like a real logic analyser, but the project page reports 20MHz. For most of the microcontroller-based work I do, that will be more than sufficient.<\/p>\n<p>The author of LogicDiscovery is Russian, so documentation isn\u00e2\u20ac\u2122t easy to find; however Google translate does a good enough job on his descriptive <a href=\"http:\/\/translate.google.com\/translate?sl=auto&amp;tl=en&amp;js=n&amp;prev=_t&amp;hl=en&amp;ie=UTF-8&amp;u=http%3A%2F%2Fhabrahabr.ru%2Fpost%2F165853%2F&amp;act=url\">blog<\/a> that it\u00e2\u20ac\u2122s possible to work out how to get started.<\/p>\n<p>While it\u00e2\u20ac\u2122s possible to download and compile the source yourself; I didn\u00e2\u20ac\u2122t bother. The author has supplied a binary image; so I just downloaded that and flashed it to my discovery board.<\/p>\n<pre><code>$ openocd \\\n   -f \/usr\/share\/openocd\/scripts\/board\/stm32f4discovery.cfg \\\n   -c &quot;init&quot; \\\n   -c &quot;reset halt&quot; \\\n   -c &quot;sleep 100&quot; \\\n   -c &quot;wait_halt 2&quot; \\\n   -c &quot;echo \\&quot;--- Writing LogicDiscovery-r12.bin\\&quot;&quot; \\\n   -c &quot;flash write_image erase LogicDiscovery-r12.bin 0x08000000&quot; \\\n   -c &quot;sleep 100&quot; \\\n   -c &quot;echo \\&quot;--- Verifying\\&quot;&quot; \\\n   -c &quot;verify_image LogicDiscovery-r12.bin 0x08000000&quot; \\\n   -c &quot;sleep 100&quot; \\\n   -c &quot;echo \\&quot;--- Done\\&quot;&quot; \\\n   -c &quot;resume&quot; \\\n   -c &quot;shutdown&quot;\nOpen On-Chip Debugger 0.7.0 (2013-05-15-12:03)\nLicensed under GNU GPL v2\nFor bug reports, read\n        http:\/\/openocd.sourceforge.net\/doc\/doxygen\/bugs.html\nsrst_only separate srst_nogate srst_open_drain connect_deassert_srst\nInfo : This adapter doesn&#39;t support configurable speed\nInfo : STLINK v2 JTAG v14 API v2 SWIM v0 VID 0x0483 PID 0x3748\nInfo : Target voltage: 2.868772\nInfo : stm32f4x.cpu: hardware has 6 breakpoints, 4 watchpoints\ntarget state: halted\ntarget halted due to debug-request, current mode: Thread \nxPSR: 0x01000000 pc: 0x080038b4 msp: 0x10010000\n--- Writing LogicDiscovery-r12.bin\nauto erase enabled\nInfo : device id = 0x10016413\nInfo : flash size = 1024kbytes\nwrote 65536 bytes from file LogicDiscovery-r12.bin in 3.865705s (16.556 KiB\/s)\n--- Verifying\nverified 50196 bytes in 0.579957s (84.523 KiB\/s)\n--- Done\nshutdown command invoked<\/code><\/pre>\n<p>You can now connect the micro USB cable to your PC and you\u00e2\u20ac\u2122ll see a CDC serial port appear.<\/p>\n<pre><code>usb 2-3: USB disconnect, device number 16\nusb 2-3: new full-speed USB device number 17 using ohci_hcd\nusb 2-3: New USB device found, idVendor=0483, idProduct=5740\nusb 2-3: New USB device strings: Mfr=1, Product=2, SerialNumber=3\nusb 2-3: Product: STM32 Virtual ComPort in FS Mode\nusb 2-3: Manufacturer: STMicroelectronics\nusb 2-3: SerialNumber: 00000000050C\ncdc_acm 2-3:1.0: This device cannot do calls on its own. It is not a modem.\ncdc_acm 2-3:1.0: ttyACM0: USB ACM device<\/code><\/pre>\n<p>Now we need a way of controlling and reading back the captured data. Fortunately <em>LogicDiscovery<\/em> implements the standardised <em>SUMP<\/em> protocol; and even more fortunately there is a nice SUMP client, <a href=\"http:\/\/www.lxtreme.nl\/ols\/\">Open Logic Sniffer<\/a> (or OLS) that talks that protocol. It\u00e2\u20ac\u2122s a Java application, so you\u00e2\u20ac\u2122ll need a JDK installed \u00e2\u20ac\u201c I had OpenJDK from Debian installed already, and it worked out of the box with the <code>run.sh<\/code> script that comes with OLS.<\/p>\n<p>You need to be aware of a few limitations that LogicDiscovery imposes, and set up OLS accordingly. In the <em>Begin Capture<\/em> dialog, do this:<\/p>\n<ul>\n<li>Port speed, 115200.<\/li>\n<li>Set <em>Device type<\/em> to \u00e2\u20ac\u0153Open Bench Logic Sniffer\u00e2\u20ac\u009d. You can use \u00e2\u20ac\u0153show device metadata\u00e2\u20ac\u009d to check LogicDiscovery on the STM32F4 is detected.<\/li>\n<li>In \u00e2\u20ac\u02dcAcquisition\u00e2\u20ac\u2122 sampling rate cannot exceed 20MHz. Setting it higher will sample at 20MHz anyway, but will report all the times wrong.<\/li>\n<li><em>Channel Groups<\/em>, set to \u00e2\u20ac\u01530\u00e2\u20ac\u009d for <code>PD0<\/code>&#8211;<code>PD7<\/code>; or \u00e2\u20ac\u01530\u00e2\u20ac\u009d and \u00e2\u20ac\u01531\u00e2\u20ac\u009d for <code>PD0<\/code>&#8211;<code>PD15<\/code>.<\/li>\n<li>The author says that you can only use 12kB for <em>Recording Size<\/em>, but it worked okay for me at 24kB. This determines how long your sample buffer is, and OLS tells you the size of the interval in brackets after the selection. This is obviously a function of the buffer size and the sample rate.<\/li>\n<li>Don\u00e2\u20ac\u2122t set any of <em>Test mode<\/em>, <em>Noise Filter<\/em> or <em>Run Length Encoding<\/em>. None of them are (apparently) supported.<\/li>\n<li>On the \u00e2\u20ac\u0153Triggers\u00e2\u20ac\u009d tab, you must choose the \u00e2\u20ac\u0153SIMPLE\u00e2\u20ac\u009d type of trigger, in \u00e2\u20ac\u0153Parallel\u00e2\u20ac\u009d mode; but other than that you are free to pick anything. The <em>mask<\/em> field tells the board which pins to detect, and <em>value<\/em> what edge to match. Only bits 0-15 will be of use because only <code>PD0<\/code>&#8211;<code>PD15<\/code> are supported.<\/li>\n<\/ul>\n<p>As a client, OLS is excellent.<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/54d\/569\/b5e\/54d569b5e26799c9371960900ffd8664.png\" alt=\"ols\" \/><br \/> This is it doing a UART decode on a sampled stream. It has analysers for I2C, SPI, JTAG and some others too; but I\u00e2\u20ac\u2122ve not got sources of those signals around so I can\u00e2\u20ac\u2122t test them. The really high rate implementations of these are out of LogicDiscovery\u00e2\u20ac\u2122s league (remember a 20MHz sample rate means 10MHz signals at best); but most microcontrollers won\u00e2\u20ac\u2122t use those sorts of rates; and many devices don\u00e2\u20ac\u2122t support high rates even if the microcontroller would do it.<\/p>\n<p>One final useful bit of information: the discovery board is not wired for powering from the application USB port that we would use for talking to LogicDiscovery. That means as soon as you unplug the programmer USB port, the board will be powerless. It\u00e2\u20ac\u2122s a bit inconvenient to have to plug two USB cables in. You can get around this by looking at the STM32F4DISCOVERY schematic and noting that the <code>VBUS<\/code> pin from the Micro USB port is connected to <code>PA9<\/code>. If you connect a jumper wire from PA9 to one of the 5V pins (be careful not to connect to one of the 3V pins), you can power the board from your computer, without needing the programmer USB connected.<\/p>\n<p>In all; I\u00e2\u20ac\u2122m delighted. Another tool for the tool box.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I\u00e2\u20ac\u2122ve been meaning to try this project out for a while\u00e2\u20ac\u00a6 It\u00e2\u20ac\u2122s a basic logic analyser built on the STM32F4DISCOVERY board. The STM32F4 runs at 168MHz, so we\u00e2\u20ac\u2122ve got a fair bit of bandwidth available. Nothing like a real logic analyser, but the project page reports 20MHz. For most of the microcontroller-based work I do,\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.fussylogic.co.uk\/blog\/?p=1226\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[115,114,6],"_links":{"self":[{"href":"https:\/\/www.fussylogic.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1226"}],"collection":[{"href":"https:\/\/www.fussylogic.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.fussylogic.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.fussylogic.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.fussylogic.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1226"}],"version-history":[{"count":8,"href":"https:\/\/www.fussylogic.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1226\/revisions"}],"predecessor-version":[{"id":1237,"href":"https:\/\/www.fussylogic.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1226\/revisions\/1237"}],"wp:attachment":[{"href":"https:\/\/www.fussylogic.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1226"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fussylogic.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1226"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fussylogic.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1226"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}