Every designer needs sooner or later to know, what is going on inside
the device he is designing. The simplest possibility
which can be used on almost every microcontroller is outputting the debug information over
one of its serial lines. But what to do if all of them are busy?
The answer is simple. Debug over Ethernet!
Note: The following example is rather fresh and dirty which means that there is still a lot of space for improvements.
However it does its job well.
If we program PC and can use a console for debug output, debug messages
look usually like this one:
fprintf(stderr,"This is %dth time I'm doing just this\n",++count);We can split this action into two steps:
sprintf(txt,"This is %dth time I'm doing just this\n",++count); fpritnf(stderr,txt);We obviously don't have the console in a small system therefore txt must go to different device, for instance to a LCD display:
sprintf(txt,"This is %dth time I'm doing just this\n",++count); lcd_text_at(LCD_L1,txt);Or it can go somewhere else:
sprintf(txt,"This is %dth time I'm doing just this\n",++count); udpdebug(txt); //network output is finally here!The udpdebug() function can look like this:
void udpdebug(char *txtb) { uint8_t _reip[4]={192,168,0,2}; udpsend(_reip,2001,20010,txtb,strlen(txtb)+1); }The udpsend() function sends the packet over Ethernet network to destination IP address 192.168.0.2 and port 20010. We use UDP protocol instead of TCP because of its smaller overhead. It "sends and forgets" and this is much faster because it doesn't use "reliability" mechanism used by TCP. In most cases it is fast enough to debug in the realtime.
c:\nc -u -l -p 20010