1 / 17

Writing Portable and Robust Firmware in C

Embedded System Design Techniques™. Writing Portable and Robust Firmware in C. Class 5: Robust Firmware Concepts. September 4, 2015 Jacob Beningo, CSDP. Course Overview. Portable C Concepts Doxygen and PC-Lint Uart Driver and Stm32CubeMx Assertions and printf Robust Firmware Concepts.

saltz
Download Presentation

Writing Portable and Robust Firmware in C

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. Embedded System Design Techniques™ Writing Portable and Robust Firmware in C Class 5: Robust Firmware Concepts September 4, 2015Jacob Beningo, CSDP

  2. Course Overview • Portable C Concepts • Doxygen and PC-Lint • Uart Driver and Stm32CubeMx • Assertions and printf • Robust Firmware Concepts

  3. Session Overview • Watchdog Timers • Watchdog API • Watchdogs use • Stack Monitor • Cyclomatic Complexity • Robust application features

  4. Watchdog Overview Characteristics of a Good Watchdog • Watchdog and subsystem being monitored should have separate clocks • Watchdog refresh should be done such that the changes of run-a-way code refreshing the watchdog are minimized • Run-away code should be detected quickly to prevent system damage • Critical control and configuration registers should have write protection so that once set they cannot be changed • Should be able to detect what has caused the time-out • Task flagging for proper operation

  5. Watchdog Types • Internal • Timer Based • External • Heartbeat • Smart • Dumb eWatchdog HB COMMS RST MCU COMMS "A Review of Watchdog Architectures" http://www.beningo.com/category/white-papers/

  6. Watchdog API

  7. Watchdog Firmware

  8. Watchdog Firmware

  9. Watchdog Firmware

  10. Watchdog Firmware

  11. Watchdog Firmware

  12. Stack Monitor Design Calculating stack size can be difficult! • What is on the stack? • Creating a stack monitor / guard manually • Write known pattern into the Guard area • Monitor the Guard area for changes • Alternatively use the MPU void main(void) { uint32_t * GuardPtr = (uint32_t *) GUARD_START; for(Index = 0; Index < GUARD_SIZE; Index++) { if(*GuardPtr == 0xC0DE) {//DO NOTHING} else { //flag error! Attempt recovery } } } GUARD_SIZE = DEFINED(__guard_size__) ? __guard_size__ : 0x00000100; .guard: { . = ALIGN(8); FILL(0xC0DE); . += GUARD_SIZE - 1; BYTE(0xE) } > m_data

  13. Cyclomatic Complexity Limiting Function Complexity • Helps to ensure readability • Bounds number of test cases • Forces breaking up into smaller more manageable pieces • Reduces bugs

  14. Filling ROM What happens if … • Buffer overrun occurs? • Dereference a bad pointer? • System upset occurs? • What is the status of none programmed ROM? .fillsection : { FILL(0xAA55AA55); . = ORIGIN(m_text) + LENGTH(m_text) – 1; BYTE(0xAA) } > m_text

  15. Robust Application Features • ROM Checksum and validation • RAM check performed periodically • Robust watchdog system • 1 – 3 % code are assertions • Empty ROM is filled • Validating inputs/outputs and error conditions

  16. Additional Resources • Download Course Material for • Updated C Doxygen Templates (May 2015) • Example source code • Templates • Microcontroller API Standard • EDN Embedded Basics Articles • Embedded Bytes Newsletter From www.beningo.com under - Blog and Articles > Software Techniques > CEC Writing Portable and Robust Firmware in C

  17. Newsletters • Embedded Bytes • http://bit.ly/1BAHYXm • Training • MicroPython • Bootloaders • Low Power Design • Real-time Software • C/C++ Embedded P.O. Box 400 Linden, Michigan 48451 www.beningo.com : jacob@beningo.com : 810-844-1522 : Jacob_Beningo : Beningo Engineering : JacobBeningo : Embedded Basics Jacob Beningo Principal Consultant

More Related