DN Staff

August 22, 2015

5 Min Read
DN Webcast Preview: Writing Portable and Robust Firmware in C

In an era when budgets are tight, development timelines are shrinking, and customers are demanding high-quality products, the ability to write portable and robust firmware is in high demand. Most C developers recognize that it is easy to write code, but what techniques should be followed to maximize portability of the code without compromising its integrity? My next free Design News Continuing Education Center (CEC) course, starting Aug. 31, sponsored by Digi-Key, will cover those techniques, using an ARM-based STM32L0 Nucleo board from STMicroelectronics. Until then, here is a short preview of the techniques, tips, and tricks that I’ll be covering.

Session 1 – Portable C Concepts – Sign-up here

Writing embedded software that is portable in C is not a trivial endeavor. A developer needs to be disciplined and take the time up front to create a design that will be scalable and easily adaptable. One critical component to portability is that all firmware should adhere strictly to the ANSI-C standard. It is the globally recognized C standard, and if a construct isn’t defined in the standard (or properly defined in it), then it shouldn’t be used if the code is going to be reused.

A second and nearly just as important portability point is the use of hardware abstraction layers (HAL) and application programming interfaces (API). Properly defined interfaces can be the difference between spaghetti code and a beautifully architected system. The tricks on how to define interfaces will be discussed at length in this first session and the sessions that follow will build upon it.

Session 2 – Doxygen and PC-Lint – Sign-up here

Robust and portable code requires two important aspects of software. First, it needs to be well documented, and second, it needs to be bug free. The Doxygen tool provides a great way for developers to write comments that can then be automatically turned into an up-to-date manual. One of my favorite tricks, which will be discussed in the course’s second session, is how to use Doxygen in the design phase to create the architecture of the software, pre-documented with behavior that can then act as scaffolding for the code.

PC-Lint is a popular and low-cost solution for performing static code analysis. PC-Lint has the ability to detect syntax and code errors that are overlooked by the C compiler. I’ve never seen anyone describe how to set the tool up, so this session will walk through how to setup PC-Lint with Keil, the associated configuration files and run the analyzer. The exercises from my previous CEC course, “Mastering the ARM Coretex-M,” will serve as the baseline code and reveal some interesting potential bugs that attendees will get the opportunity to resolve.

Session 3 – Uart Driver and Stm32CubeMx – Sign-up here

Terminal output is critical in many debugging and data logging applications. Starting driver development from scratch can be a time-consuming activity. Getting the STM32L0 Nucleo board up and running with a Uart will be one of the first orders of business in this session. A fast way to do this will be to use the Stm32CubeMx software to configure an application. A walk-through of the Uart interface and HAL design will be a must, along with a few simple tests to make sure that the Uart driver is functional.

Session 4 – Assertions and printf – Sign-up here

Once the Uart driver interface has been created and tested, one of the most commonly used debugging tools, printf, will be examined. The printf function can be helpful to debug a system, but it can also affect system timing and performance. A few tricks on how to modify printf, such as the use of a non-blocking circular buffer, will be explored. Source code will be provided, as well, so that developers can implement and explore the concepts on their own time and systems.

The ASSERT macro is one of the least understood tools that embedded software developers have available to them. For this reason, a fair amount of time will be spent during the course to go through what an assertion is, how to apply assertions, and some neat tricks that can be used help improve the robustness of a system.

Session 5 – Robust Firmware Concepts – Sign-up here

With a number of tools available now to attendees, the last session will walk through a sampling of robust firmware techniques that can be applied to an embedded system. Concepts such as proper watchdog implementation, stack monitors, application checksums, and linker files will be discussed in detail. Most of the concepts examined are those that developers tend to not think about until the end of the development cycle, when it is too late to implement or easily fit into their software architecture.

These are just a few of the highlights of what will be covered in the “Writing Portable and Robust Firmware” CEC course. I hope that these topics pique your interest and look forward to interacting with you starting Aug. 31.

DMPhillylogo.png

Jacob Beningo is a Certified Software Development Professional (CSDP) whose expertise is in embedded software. He works with companies to decrease costs and time to market while maintaining a quality and robust product. He is an avid tweeter, a tip and trick guru, a homebrew connoisseur and a fan of pineapple! Feel free to contact him at [email protected], at his website www.beningo.com, and sign-up for his monthly Embedded Bytes Newsletter here.

Sign up for the Design News Daily newsletter.

You May Also Like