Thursday, February 7, 2013

Worst bug ever! (in ST's USB CDC driver)

Today a lot has been done for the preparations to do the first controlled "flight test", "flight test" as in a Quadrotor strapped to a frame and trying the rate and attitude controller. However during the development of the controller I noticed a very strange thing happening (it actually started when I sent a lot of data over the USB VCP (Virtual Com Port), after some time the board just stopped doing anything. But it happened very sporadically, from within minutes to hours. But today I finally caught it with he debugger (I've been trying for two weeks)!
     The program got stuck in a function called " DCD_WriteEmptyTxFifo" - one of the USB interrupt handlers and for some reason it got in an infinite loop here. I can directly tell you all that I'm no expert in USB, I have just adapted the ST drivers to fit my purpose, so I started to wonder how I should fix this but Google is you friend. After some research I found this post where one had solved the problem! Apparently ST had a bug in the driver where they had forgotten to clear the interrupt and this was causing the infinite interrupt loop. After adding those lines of code my system stopped to hang randomly!

Now that's one good thorn out of my paw! But I must say I expected ST's drivers to work, not to have a bug like this.

No comments:

Post a Comment