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

39
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)

description

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. - PowerPoint PPT Presentation

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

Page 1: 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)

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

www.elektor-labs.com/low-cost-debugging

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

October 24, 2013

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

www.elektor-labs.com/low-cost-debugging

Presented byClemens Valens• CEO Elektor.Labs• Contributing editor

October 24, 2013

mmmh!

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

www.elektor-labs.com/low-cost-debugging

About ElektorElectronics magazine for people passionate

about electronics• 5 main editions:

– English, Spanish, German, French & Dutch

• We publish projects• We have our own lab• We design our own PCBs

October 24, 2013

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

www.elektor-labs.com/low-cost-debugging

Elektor.Labs

• Sharing electronics• Be an expert, get

rewarded• Get more out of your

passion

October 24, 2013

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

www.elektor-labs.com/low-cost-debugging

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

October 24, 2013

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

www.elektor-labs.com/low-cost-debugging

Programming means Debugging• Time-consuming• Good tools are expensive• Effective debugging requires skills

October 24, 2013

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

www.elektor-labs.com/low-cost-debugging

Use Your Brain →

October 24, 2013

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

www.elektor-labs.com/low-cost-debugging

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!

October 24, 2013

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

www.elektor-labs.com/low-cost-debugging

Train Your Debug Muscle

October 24, 2013

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

www.elektor-labs.com/low-cost-debugging

Enter the LED

October 24, 2013

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

www.elektor-labs.com/low-cost-debugging

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

October 24, 2013

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

www.elektor-labs.com/low-cost-debugging

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)

October 24, 2013

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

www.elektor-labs.com/low-cost-debugging

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

October 24, 2013

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

www.elektor-labs.com/low-cost-debugging

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; } }}

October 24, 2013

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

www.elektor-labs.com/low-cost-debugging

Don’t Blink from ISRs

Interrupts may continue to tick even if the main program crashed.

Exception: when testing ISR functionality.

October 24, 2013

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

www.elektor-labs.com/low-cost-debugging

LEDs are Really Fast• They can reveal activity on (serial) ports• Brightness is a measure for duty-cycle

October 24, 2013

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

www.elektor-labs.com/low-cost-debugging

Build a Logic Level Probe

October 24, 2013

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

www.elektor-labs.com/low-cost-debugging

No LEDs?• Use a logic level probe• Use a multimeter• Use an oscilloscope• Use your ears• Use your smartphone

October 24, 2013

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

www.elektor-labs.com/low-cost-debugging

Serial Sound

October 24, 2013

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

www.elektor-labs.com/low-cost-debugging

Demo!

October 24, 2013

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

www.elektor-labs.com/low-cost-debugging

The Serial PortUse a solid connection, f.i. like this:

October 24, 2013

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

www.elektor-labs.com/low-cost-debugging

The Serial Port• Create a working putch• Create a debug putch:

– #define DEBUG_PUTCH putch• Only send printable ASCII characters• Exception: Bell (0x07)

October 24, 2013

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

www.elektor-labs.com/low-cost-debugging

The Serial Port• Create a working puts• Create a debug puts:

– #define DEBUG_PUTS puts• Use meaningful strings• Print program name & version

October 24, 2013

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

www.elektor-labs.com/low-cost-debugging

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

October 24, 2013

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

www.elektor-labs.com/low-cost-debugging

Following the Call Stack• Be verbose• Print real function names• Print at function entry and exit• Cover all exit points

October 24, 2013

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

www.elektor-labs.com/low-cost-debugging

Following Execution Paths• Be concise• Use single characters like numbers or letters• Increase character along path• Cover all paths

October 24, 2013

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

www.elektor-labs.com/low-cost-debugging

Exampleint16_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;}

October 24, 2013

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

www.elektor-labs.com/low-cost-debugging

printf• Comfortable• Needs a lot of memory• Slow• Partly implemented• Platform dependent• Undefined behavior

October 24, 2013

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

www.elektor-labs.com/low-cost-debugging

printf Coprocessor

October 24, 2013

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

www.elektor-labs.com/low-cost-debugging

MCU:void my_printf(int int_count, char *format, ...){ va_list ap; 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,'$');

October 24, 2013

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

www.elektor-labs.com/low-cost-debugging

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); } } }}

October 24, 2013

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

www.elektor-labs.com/low-cost-debugging

Complications

October 24, 2013

• How to handle fast data streams?• How to handle errors?

As always: use with care

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

www.elektor-labs.com/low-cost-debugging

One Step Beyond

October 24, 2013

• Build a €$£10,- debug coprocessor:– Use a proven platform– Use known good libraries– Debug communications (SPI, I²C, other)– Provide stimuli– Measure voltages

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

www.elektor-labs.com/low-cost-debugging

Debug Coprocessor

October 24, 2013

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

www.elektor-labs.com/low-cost-debugging

The Next Level

October 24, 2013

• JTAG pod• In-circuit debugger (ICD)• In-circuit emulator (ICE)

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

www.elektor-labs.com/low-cost-debuggingOctober 24, 2013

Any questions?

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

www.elektor-labs.com/low-cost-debugging

Next Elektor Webinar

Automation and Test using Flowcode presented by Ben Rowland and Jonathan Woodrow

Thursday November 21, 2013 (15:00 GMT / 16:00 CET)

Check www.elektor.com/webinar for details or subscribe to our newsletter

www.elektor.com

October 24, 2013

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

www.elektor-labs.com/low-cost-debugging

Code available atwww.elektor-labs.com/low-cost-debugging

October 24, 2013

Thank you for attending!