1 / 39

Thank you for joining this Elektor Academy webinar. The session will start soon.

Thank you for joining this Elektor Academy webinar. The session will start soon. Please note that the audio broadcast is switched off for now and will start at 15:00 BST (16:00 CEST ). Low-Cost Debugging.

talon
Download Presentation

Thank you for joining this Elektor Academy webinar. The session will start soon.

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Thank you for joining this Elektor Academy webinar. The session will start soon. Please note that the audio broadcast is switched off for now and will start at 15:00 BST (16:00 CEST)

  2. Low-Cost Debugging for the poor who are not rich nor wealthy and who do not have a lot of money to spend, even on food www.elektor-labs.com/low-cost-debugging

  3. Presented by Clemens Valens • CEO Elektor.Labs • Contributing editor mmmh! www.elektor-labs.com/low-cost-debugging

  4. About Elektor Electronics magazine for people passionate about electronics • 5main editions: • English, Spanish, German, French & Dutch • We publish projects • We have our own lab • We design our own PCBs www.elektor-labs.com/low-cost-debugging

  5. Elektor.Labs • Sharing electronics • Be an expert, get rewarded • Get more out of your passion www.elektor-labs.com/low-cost-debugging

  6. MCU Debugging on a shoestring • Lots of cheap microcontroller boards are available • Hobbyists are no longer frowned upon by MCU manufacturers • Anyone can create embedded applications www.elektor-labs.com/low-cost-debugging

  7. Programming means Debugging • Time-consuming • Good tools are expensive • Effective debugging requires skills www.elektor-labs.com/low-cost-debugging

  8. Use Your Brain → www.elektor-labs.com/low-cost-debugging

  9. Utopia • Programmers spend 90% of their time thinking, the remaining 10% is used for typing code • Debuggers spend 90% of their time thinking and only 10% is used for single-stepping through code Code for testing! www.elektor-labs.com/low-cost-debugging

  10. Train Your Debug Muscle www.elektor-labs.com/low-cost-debugging

  11. Enter the LED www.elektor-labs.com/low-cost-debugging

  12. Using the LED • Make sure it works • Know which leg is the anode • Keep its brightness low • Use dedicated MCU pins • Write a test program to prove that you master the LED www.elektor-labs.com/low-cost-debugging

  13. Use Macros (or Functions) Example: #define DEBUG_LED0_ON PORTB |= 0x01 #define DEBUG_LED0_OFF PORTB &= 0xfe (or something nicer but with a similar effect) Done debugging: #define DEBUG_LED0_ON /* PORTB |= 0x01 */ #define DEBUG_LED0_OFF /* PORTB &= 0xfe */ (or something nicer but with a similar effect) www.elektor-labs.com/low-cost-debugging

  14. Using LEDs • Set LEDs to a known state at start-up • Use well-defined animations • Activate/deactivate at strategic positions • One debug function per LED per session • Only one well-defined execution path www.elektor-labs.com/low-cost-debugging

  15. Blink from main() void main(void) { // Increment delta_time by timer; delta_time = 0ms; DEBUG_LED_OFF; while (1) { if (delta_time==250ms) DEBUG_LED_ON; else if (delta_time==500ms) { DEBUG_LED_OFF; delta_time = 0ms; } } } www.elektor-labs.com/low-cost-debugging

  16. Don’t Blink from ISRs Interrupts may continue to tick even if the main program crashed. Exception: when testing ISR functionality. www.elektor-labs.com/low-cost-debugging

  17. LEDs are Really Fast • They can reveal activity on (serial) ports • Brightness is a measure for duty-cycle www.elektor-labs.com/low-cost-debugging

  18. Build a Logic Level Probe www.elektor-labs.com/low-cost-debugging

  19. No LEDs? • Use a logic level probe • Use a multimeter • Use an oscilloscope • Use your ears • Use your smartphone www.elektor-labs.com/low-cost-debugging

  20. Serial Sound www.elektor-labs.com/low-cost-debugging

  21. Demo! www.elektor-labs.com/low-cost-debugging

  22. The Serial Port Use a solid connection, f.i. like this: www.elektor-labs.com/low-cost-debugging

  23. The Serial Port • Create a working putch • Create a debug putch: • #define DEBUG_PUTCH putch • Only send printable ASCII characters • Exception: Bell (0x07) www.elektor-labs.com/low-cost-debugging

  24. The Serial Port • Create a working puts • Create a debug puts: • #define DEBUG_PUTS puts • Use meaningful strings • Print program name & version www.elektor-labs.com/low-cost-debugging

  25. The Serial Port • Keep debug strings short • Format cleverly • Use brackets: <>, (), [], {} • Prefer separators to whitespace • Use CR/LF • Lower-case is easier to read • ‘B8’ looks like ’88’, write ‘b8’ instead www.elektor-labs.com/low-cost-debugging

  26. Following the Call Stack • Be verbose • Print real function names • Print at function entry and exit • Cover all exit points www.elektor-labs.com/low-cost-debugging

  27. Following Execution Paths • Be concise • Use single characters like numbers or letters • Increase character along path • Cover all paths www.elektor-labs.com/low-cost-debugging

  28. Example int16_t foo(int8_t value) { DEBUG_PUTCH('0'); if (value<0) { DEBUG_PUTCH('1'); if (value<-5) { DEBUG_PUTCH('2'); } else if (value<-3) { DEBUG_PUTCH('3'); } DEBUG_PUTCH('4'); } DEBUG_PUTCH('5'); return -10*value; } www.elektor-labs.com/low-cost-debugging

  29. printf • Comfortable • Needs a lot of memory • Slow • Partly implemented • Platform dependent • Undefined behavior www.elektor-labs.com/low-cost-debugging

  30. printf Coprocessor www.elektor-labs.com/low-cost-debugging

  31. MCU: void my_printf(intint_count, char *format, ...) { va_listap; va_start(ap,format); puts("printf"); // Send keyword word. puts(format); // Send format string. putch('\0'); // Terminate format string. putch(sizeof(int)); // Send size of int. putch(int_count); // Send number of integers. while (int_count>0) // Send the arguments. { send_int(va_arg(ap,int)); int_count -= 1; } va_end(ap); } my_printf(3,"u=%05u, p=%p, c=%c\r\n",234,0x4321,'$'); www.elektor-labs.com/low-cost-debugging

  32. Coprocessor: void main(void) { while (serial_data_available==true) { uint8_t ch= read_serial_input(); if (keyword_found(ch)==false) { write_serial_output(ch); } else { if (printf_statement_complete==true) { printf(received_format_string,received_arguments); } } } } www.elektor-labs.com/low-cost-debugging

  33. Complications • How to handle fast data streams? • How to handle errors? As always: use with care www.elektor-labs.com/low-cost-debugging

  34. One Step Beyond • Build a €$£10,- debug coprocessor: • Use a proven platform • Use known good libraries • Debug communications (SPI, I²C, other) • Provide stimuli • Measure voltages www.elektor-labs.com/low-cost-debugging

  35. Debug Coprocessor www.elektor-labs.com/low-cost-debugging

  36. The Next Level • JTAG pod • In-circuit debugger (ICD) • In-circuit emulator (ICE) www.elektor-labs.com/low-cost-debugging

  37. Any questions? www.elektor-labs.com/low-cost-debugging

  38. Next Elektor Webinar Automation and Test using Flowcodepresented by Ben RowlandandJonathan Woodrow Thursday November 21, 2013 (15:00 GMT / 16:00 CET) Check www.elektor.com/webinarfor details or subscribe to our newsletter www.elektor.com www.elektor-labs.com/low-cost-debugging

  39. Code available at www.elektor-labs.com/low-cost-debugging Thank you for attending! www.elektor-labs.com/low-cost-debugging

More Related