{"id":172,"date":"2016-12-18T15:39:08","date_gmt":"2016-12-18T23:39:08","guid":{"rendered":"https:\/\/www.falatic.com\/?p=172"},"modified":"2016-12-18T19:52:24","modified_gmt":"2016-12-19T03:52:24","slug":"usb-serial-devices-and-the-unexpected-side-effects-of-serial-enumeration-bsod-with-solutions","status":"publish","type":"post","link":"https:\/\/www.falatic.com\/index.php\/172\/usb-serial-devices-and-the-unexpected-side-effects-of-serial-enumeration-bsod-with-solutions","title":{"rendered":"USB serial devices and the unexpected side-effects of serial enumeration (BSOD, with solutions!)"},"content":{"rendered":"<p><a href=\"https:\/\/www.falatic.com\/wp-content\/uploads\/2016\/12\/Thats-no-mouse.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-173 size-full\" src=\"https:\/\/www.falatic.com\/wp-content\/uploads\/2016\/12\/Thats-no-mouse.jpg\" width=\"620\" height=\"482\" data-wp-pid=\"173\" srcset=\"https:\/\/www.falatic.com\/wp-content\/uploads\/2016\/12\/Thats-no-mouse.jpg 620w, https:\/\/www.falatic.com\/wp-content\/uploads\/2016\/12\/Thats-no-mouse-300x233.jpg 300w, https:\/\/www.falatic.com\/wp-content\/uploads\/2016\/12\/Thats-no-mouse-600x466.jpg 600w\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" \/><\/a><\/p>\n<p>I got a WDF_VIOLATION BSOD (0x0000010D) in Windows 7 (x64) when I connected a dev board via USB serial today. It was an alarming error I&#8217;ve never seen before&#8230;<\/p>\n<p>&#8230; but I suspect it&#8217;s more common for those in the hardware community and not always well-understood.<\/p>\n<p>Note: While the discussion below centers around the ESP32 with the CP210x USB to UART bridge, it&#8217;s a general problem if your COM drivers allow &#8220;serial enumeration&#8221; of a serially connected device (a way to detect old, legacy input devices like mice). The ESP32 happens to be particularly &#8220;chatty&#8221; when it&#8217;s connected via USB, which is why it was more likely to trigger this issue. That said, the ESP32 isn&#8217;t the problem &#8211; it&#8217;s just more likely to trigger this latent issue.<\/p>\n<p>This isn&#8217;t the first time I&#8217;ve connected my new ESP32 but I&#8217;ve been doing more with it, including reset tests. However, that triggered something unexpected last night &#8211; Windows tried to install a Microsoft Mouse HID driver for the board when I plugged it in, which seemed very odd as it&#8217;s definitely not emulating a mouse. Today, I plugged it in again, reset the board, tried opening the COM port in PuTTY (which\u00a0I use for serial comms) and boom &#8211; BSOD 0x0000010D (WDF_VIOLATION &#8211; Windows Driver Framework violation)!<\/p>\n<p>For whatever reason the minidump didn&#8217;t save, but I noted the fault number and determined it was probably some recently changed or added driver. Since that spurious mouse driver was the last one I noticed, and since it was noted as mis-installed (which is why it was even more memorable), I focused on that (and the board itself).<\/p>\n<p>I learned that Windows (7\u00a0for sure and probably other releases) installs the driver for the CP210x USB to UART bridge with &#8220;serial enumeration&#8221; functionality: if it sees &#8220;M&#8221; in the initial COM stream for a newly connected device, it tries to enumerate that device as a mouse:<\/p>\n<p><a href=\"http:\/\/community.silabs.com\/t5\/Interface-Knowledge-Base\/What-is-the-serial-enumeration-driver-and-why-would-I-need-it\/ta-p\/160921\" target=\"_blank\" rel=\"nofollow\">http:\/\/community.silabs.com\/t5\/Interface-Knowledge-Base\/What-is-the-serial-enumeration-driver-and-why-would-I-need-it\/ta-p\/160921<\/a><\/p>\n<p>This can go very, very wrong for a serial device that isn&#8217;t a mouse, particularly for something like the ESP32 which sends a lot of data when it resets. That the ESP32 (or other such devices) would do this isn&#8217;t a problem &#8211; it just happens to trigger this unwanted side-effect more readily than most. For an <em>enumerating<\/em> driver this data is interpreted as coming from a serial mouse, and that&#8217;s when the problems start. The system then tries (and partially or wholly fails) to install a mouse driver for the non-mouse USB device. It filters that stream as if it were a mouse and can eventually lead to a BSOD.<\/p>\n<p>Updating the driver via Windows&#8217; device manager (automatic download) didn&#8217;t help: I got a newer version that still enumerated the ESP32 as a mouse as soon as it interpreted an &#8220;M&#8221; in the initial data stream. (It&#8217;s not clear if the enumerator is reading an actual &#8220;M&#8221; at 115200 baud or interpreting an &#8220;M&#8221; from the garbage it sees at the 1200 baud speed such enumeration normally occurs at&#8230; either way, it&#8217;s the driver, not the board.)<\/p>\n<p>Some COM port drivers will allow you to selectively disable the serial enumeration feature, but not the ones for this Silicon Labs chip. So I installed the latest VCP driver <em>without serial enumeration<\/em>\u00a0directly from their website:<\/p>\n<p><a href=\"http:\/\/www.silabs.com\/products\/mcu\/pages\/usbtouartbridgevcpdrivers.aspx#windows\" target=\"_blank\" rel=\"nofollow\">http:\/\/www.silabs.com\/products\/mcu\/pages\/usbtouartbridgevcpdrivers.aspx#windows<\/a><\/p>\n<p>Now the ESP32 is no longer enumerated as a mouse. This should prevent future BSODs of this unique and cryptic nature (as well as a more obscure effect &#8211; &#8220;crazy mouse&#8221;: depending on the data stream, the system may manage to install a mouse driver and read random data from a non-mouse device as valid mouse inputs).<\/p>\n<p>There are a few things one can do to alleviate this sort of issue. As noted, if the advanced settings for the COM port driver have a direct way to disable serial enumeration, try that first. In the present case, updating to a non-enumerating driver was the simplest route. If neither of these is an option there are other ways, but they may or may not work as well:<\/p>\n<p><a href=\"http:\/\/stackoverflow.com\/questions\/9226082\/device-misdetected-as-serial-mouse\" target=\"_blank\" rel=\"nofollow\">http:\/\/stackoverflow.com\/questions\/9226082\/device-misdetected-as-serial-mouse<\/a><\/p>\n<p>As an aside, the fact that this caused a BSOD at all is cause for concern&#8230; I&#8217;d expect the enumerator (and\/or the partially-installed mouse driver) to handle spurious data more gracefully. It&#8217;s not clear in what exact driver my BSOD got triggered, but it seems unnecessary for a misunderstood &#8220;mouse&#8221; to crash a system.<\/p>\n<p>(Theoretically, if you transmitted data that was properly formatted valid mouse data over the COM interface, you could emulate a mouse, but normally you don&#8217;t want a dev board being misunderstood as a HID (human interface device) like this. At best, garbage in &#8211; garbage out. At worse, a crashed system.)<\/p>\n<p>You can learn more about serial enumeration here:<\/p>\n<p>https:\/\/blogs.msdn.microsoft.com\/doronh\/2006\/11\/13\/what-is-the-serial-enumeration-protocol\/<\/p>\n<!-- wpsso rrssb get buttons: buttons on archive option not enabled -->\n","protected":false},"excerpt":{"rendered":"<p>I got a WDF_VIOLATION BSOD (0x0000010D) in Windows 7 (x64) when I connected a dev board via USB serial today. It was an alarming error I&#8217;ve never seen before&#8230; &#8230; <a href=\"https:\/\/www.falatic.com\/index.php\/172\/usb-serial-devices-and-the-unexpected-side-effects-of-serial-enumeration-bsod-with-solutions\" class=\"more-link\">[&hellip;]<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"Layout":"","footnotes":"","_links_to":"","_links_to_target":""},"categories":[85,86],"tags":[139,133,141,137,132,138,135,136,134,140],"class_list":["entry","author-marty","post-172","post","type-post","status-publish","format-standard","category-electronics","category-software-and-hardware-development","tag-0x0000010d","tag-bsod","tag-cp210x","tag-enumeration","tag-esp32","tag-mouse","tag-serial","tag-uart","tag-usb","tag-wdf_violation"],"_links":{"self":[{"href":"https:\/\/www.falatic.com\/index.php\/wp-json\/wp\/v2\/posts\/172","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.falatic.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.falatic.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.falatic.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.falatic.com\/index.php\/wp-json\/wp\/v2\/comments?post=172"}],"version-history":[{"count":0,"href":"https:\/\/www.falatic.com\/index.php\/wp-json\/wp\/v2\/posts\/172\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.falatic.com\/index.php\/wp-json\/wp\/v2\/media?parent=172"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.falatic.com\/index.php\/wp-json\/wp\/v2\/categories?post=172"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.falatic.com\/index.php\/wp-json\/wp\/v2\/tags?post=172"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}