Previous Next

The Embedded Project Cookbook A Step-by-Step Guide for Microcontroller Projects (John T. Taylor, Wayne T. Taylor) (z-library.sk, 1lib.sk, z-lib.sk)

Author: John T. Taylor, Wayne T. Taylor

教育

Learn how to create and release an embedded system in a fast and reliable manner. This book will help you build and release a commercially viable product that meets industry standards for quality. The book is not just about code: it covers non-code artifacts such as software processes, requirements, software documentation, continuous integration, design reviews, and code reviews. While specifically targeting microcontroller applications, the processes in this book can be applied to most software projects, big or small. Additionally, the book provides an open-source C++ framework that can be used to quick start any embedded project. This framework has an OSAL (OS Abstraction Layer) and essential middleware that is needed for many embedded systems. Using a hands-on approach of building-and-testing the software application first allows you to develop a significant amount of production quality code even before the hardware is available, dramatically reducing the start-to-release duration for a project. As you follow the recipes in this book, you will learn essential software development processes, perform just in time design, create testable modules, and incorporate continuous integration (CI) into your day-to-day developer workflow. The end-result is quality code that is maintainable and extensible, and can be reused for other projects, even when presented with changing or new requirements. The Embedded Project Cookbook is focused on the how of developing embedded software. For a discussion of the why, readers are invited to refer to the optional companion book Patterns in the Machine: A Software Engineering Guide to Embedded Development. Who This Book Is For Mid-level developers and software leads who are looking to get up and running without all the underlying theories. This book is also for professionals looking to learn how to productize a concept or technology and sell the results to a customer.

📄 File Format: PDF
💾 File Size: 12.5 MB
13
Views
0
Downloads
0.00
Total Donations

📄 Text Preview (First 20 pages)

ℹ️

Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

📄 Page 1
The Embedded Project Cookbook A Step-by-Step Guide for Microcontroller Projects — John T. Taylor Wayne T. Taylor
📄 Page 2
The Embedded Project Cookbook A Step-by-Step Guide for Microcontroller Projects John T. Taylor Wayne T. Taylor
📄 Page 3
The Embedded Project Cookbook: A Step-by-Step Guide for Microcontroller Projects ISBN-13 (pbk): 979-8-8688-0326-0 ISBN-13 (electronic): 979-8-8688-0327-7 https://doi.org/10.1007/979-8-8688-0327-7 Copyright © 2024 by The Editor(s) (if applicable) and The Author(s), under exclusive license to APress Media, LLC, part of Springer Nature This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed. Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights. While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein. Managing Director, Apress Media LLC: Welmoed Spahr Acquisitions Editor: Melissa Duffy Development Editor: James Markham Editorial Project Manager: Gryffin Winkler Cover designed by eStudioCalamar Cover image designed by Tom Christensen from Pixabay Distributed to the book trade worldwide by Springer Science+Business Media New York, 1 New York Plaza, Suite 4600, New York, NY 10004-1562, USA. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer-sbm.com, or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation. For information on translations, please e-mail booktranslations@springernature.com; for reprint, paperback, or audio rights, please e-mail bookpermissions@springernature.com. Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales web page at http://www.apress.com/bulk-sales. Any source code or other supplementary material referenced by the author in this book is available to readers on GitHub. For more detailed information, please visit https://www.apress. com/gp/services/source-code. If disposing of this product, please recycle the paper John T. Taylor Covington, GA, USA Wayne T. Taylor Golden, CO, USA
📄 Page 4
To Sally, Bailey, Kelly, and Todd. —J.T.
📄 Page 5
v Table of Contents About the Authors ������������������������������������������������������������������������������xiii About the Technical Reviewer ������������������������������������������������������������xv Preface ���������������������������������������������������������������������������������������������xvii Chapter 1: Introduction�������������������������������������������������������������������������1 Software Development Processes ������������������������������������������������������������������������2 Software Development Life Cycle �������������������������������������������������������������������������5 Outputs and Artifacts ��������������������������������������������������������������������������������������������7 What You’ll Need to Know �������������������������������������������������������������������������������������8 Coding in C and C++ ���������������������������������������������������������������������������������������������9 What Toys You Will Need ���������������������������������������������������������������������������������������9 Regulated Industries �������������������������������������������������������������������������������������������10 What Is Not Covered ��������������������������������������������������������������������������������������������11 Conclusion ����������������������������������������������������������������������������������������������������������12 Chapter 2: Requirements ��������������������������������������������������������������������13 Formal Requirements������������������������������������������������������������������������������������������14 Functional vs� Nonfunctional�������������������������������������������������������������������������������16 Sources for Requirements ����������������������������������������������������������������������������������16 Challenges in Collecting Requirements ��������������������������������������������������������������18 Exiting the Requirements Step����������������������������������������������������������������������������19 GM6000 ���������������������������������������������������������������������������������������������������������������19 Summary�������������������������������������������������������������������������������������������������������������22
📄 Page 6
vi Chapter 3: Analysis�����������������������������������������������������������������������������25 System Engineering ��������������������������������������������������������������������������������������������26 GM6000 System Architecture ������������������������������������������������������������������������26 Software Architecture �����������������������������������������������������������������������������������������28 Moving from Inputs to Outputs ���������������������������������������������������������������������������30 Hardware Interfaces ��������������������������������������������������������������������������������������31 Performance Constraints �������������������������������������������������������������������������������32 Programming Languages ������������������������������������������������������������������������������34 Subsystems ���������������������������������������������������������������������������������������������������35 Subsystem Interfaces ������������������������������������������������������������������������������������40 Process Model �����������������������������������������������������������������������������������������������42 Functional Simulator �������������������������������������������������������������������������������������45 Cybersecurity�������������������������������������������������������������������������������������������������48 Memory Allocation �����������������������������������������������������������������������������������������49 Inter-thread and Inter-process Communication ��������������������������������������������50 File and Directory Organization ���������������������������������������������������������������������51 Localization and Internationalization �������������������������������������������������������������52 Requirement Traceability ������������������������������������������������������������������������������������54 Summary�������������������������������������������������������������������������������������������������������������56 Chapter 4: Software Development Plan ����������������������������������������������59 Project-Independent Processes and Standards ��������������������������������������������������60 Project-Specific Processes and Standards ���������������������������������������������������������61 Additional Guidelines ������������������������������������������������������������������������������������������62 Care and Feeding of Your SDP ����������������������������������������������������������������������������62 SDP for the GM6000 ��������������������������������������������������������������������������������������������63 Housekeeping �����������������������������������������������������������������������������������������������������64 Table of ConTenTs
📄 Page 7
vii Roles and Responsibilities ����������������������������������������������������������������������������������64 Software Items ����������������������������������������������������������������������������������������������������65 Documentation Outputs ��������������������������������������������������������������������������������������66 Requirements ������������������������������������������������������������������������������������������������������68 Software Development Life Cycle Processes ������������������������������������������������������69 Cybersecurity ������������������������������������������������������������������������������������������������������70 Tools ��������������������������������������������������������������������������������������������������������������������71 Software Configuration Management (SCM) �������������������������������������������������������71 Testing�����������������������������������������������������������������������������������������������������������������73 Deliverables ��������������������������������������������������������������������������������������������������������74 Summary�������������������������������������������������������������������������������������������������������������75 Chapter 5: Preparation �����������������������������������������������������������������������77 GitHub Projects ���������������������������������������������������������������������������������������������������78 GitHub Wiki ����������������������������������������������������������������������������������������������������������79 Continuous Integration Requirements ����������������������������������������������������������������82 Jenkins����������������������������������������������������������������������������������������������������������������84 Summary�������������������������������������������������������������������������������������������������������������86 Chapter 6: Foundation ������������������������������������������������������������������������89 SCM Repositories ������������������������������������������������������������������������������������������������90 Source Code Organization �����������������������������������������������������������������������������������90 Build System and Scripts ������������������������������������������������������������������������������������92 Skeleton Applications ������������������������������������������������������������������������������������������94 CI “Build-All” Script ���������������������������������������������������������������������������������������������94 Software Detailed Design������������������������������������������������������������������������������������95 Summary�������������������������������������������������������������������������������������������������������������98 Table of ConTenTs
📄 Page 8
viii Chapter 7: Building Applications with the Main Pattern ������������������101 About the Main Pattern �������������������������������������������������������������������������������������102 Operating System Abstraction Layer �����������������������������������������������������������103 Hardware Abstraction Layer ������������������������������������������������������������������������104 More About Main �����������������������������������������������������������������������������������������������105 Implementing Main �������������������������������������������������������������������������������������������106 Application Variant ���������������������������������������������������������������������������������������110 Marketing Abstraction Layer �����������������������������������������������������������������������������112 Ajax Main and Eros Main ����������������������������������������������������������������������������������113 Build Scripts ������������������������������������������������������������������������������������������������������115 Preprocessor �����������������������������������������������������������������������������������������������������119 Simulator�����������������������������������������������������������������������������������������������������������119 The Fine Print ����������������������������������������������������������������������������������������������������120 Summary�����������������������������������������������������������������������������������������������������������121 Chapter 8: Continuous Integration Builds �����������������������������������������123 Example Build-All Scripts for GM6000 ��������������������������������������������������������������125 The CI Server �����������������������������������������������������������������������������������������������125 Directory Organization ���������������������������������������������������������������������������������125 Naming Conventions������������������������������������������������������������������������������������126 Windows build_all Script �����������������������������������������������������������������������������129 Linux build_all Script �����������������������������������������������������������������������������������133 Summary�����������������������������������������������������������������������������������������������������������135 Chapter 9: Requirements Revisited ��������������������������������������������������137 Analysis �������������������������������������������������������������������������������������������������������������138 Requirements vs� Design Statements ���������������������������������������������������������������139 Design Statement for Control Algorithm ������������������������������������������������������140 Table of ConTenTs
📄 Page 9
ix Design Statement for User Interface �����������������������������������������������������������142 Missing Formal Requirements ��������������������������������������������������������������������������144 Requirements Tracing ���������������������������������������������������������������������������������������146 Summary�����������������������������������������������������������������������������������������������������������149 Chapter 10: Tasks �����������������������������������������������������������������������������153 1) Requirements ������������������������������������������������������������������������������������������������154 2) Detailed Design ���������������������������������������������������������������������������������������������155 3) Source Code and Unit Tests ��������������������������������������������������������������������������155 4) Code Review �������������������������������������������������������������������������������������������������156 5) Merge ������������������������������������������������������������������������������������������������������������156 The Definition of Done���������������������������������������������������������������������������������������156 Task Granularity ������������������������������������������������������������������������������������������������158 Tasks, Tickets, and Agile �����������������������������������������������������������������������������������160 Summary�����������������������������������������������������������������������������������������������������������162 Chapter 11: Just-in-Time Detailed Design ����������������������������������������165 Examples�����������������������������������������������������������������������������������������������������������168 Subsystem Design ���������������������������������������������������������������������������������������168 I2C Driver Design �����������������������������������������������������������������������������������������173 Button Driver Design �����������������������������������������������������������������������������������174 Fuzzy Logic Controller Design ���������������������������������������������������������������������175 Graphics Library ������������������������������������������������������������������������������������������177 Screen Manager Design ������������������������������������������������������������������������������178 Design Reviews �������������������������������������������������������������������������������������������������182 Review Artifacts�������������������������������������������������������������������������������������������182 Summary�����������������������������������������������������������������������������������������������������������184 Table of ConTenTs
📄 Page 10
x Chapter 12: Coding, Unit Tests, and Pull Requests ���������������������������187 Check-In Strategies ������������������������������������������������������������������������������������������189 Pull Requests ����������������������������������������������������������������������������������������������������189 Granularity ��������������������������������������������������������������������������������������������������������191 Examples�����������������������������������������������������������������������������������������������������������191 I2C Driver �����������������������������������������������������������������������������������������������������191 Screen Manager ������������������������������������������������������������������������������������������196 Summary�����������������������������������������������������������������������������������������������������������200 Chapter 13: Integration Testing ��������������������������������������������������������203 Smoke Tests ������������������������������������������������������������������������������������������������������208 Simulator �����������������������������������������������������������������������������������������������������208 Summary�����������������������������������������������������������������������������������������������������������210 Chapter 14: Board Support Package ������������������������������������������������213 Compiler Toolchain ��������������������������������������������������������������������������������������������214 Encapsulating the Datasheet ����������������������������������������������������������������������������215 Encapsulating the Board Schematic �����������������������������������������������������������������216 BSPs in Practice ������������������������������������������������������������������������������������������������217 Structure ������������������������������������������������������������������������������������������������������218 Dos and Don’ts ��������������������������������������������������������������������������������������������220 Bootloader ���������������������������������������������������������������������������������������������������������222 Summary�����������������������������������������������������������������������������������������������������������223 Chapter 15: Drivers ���������������������������������������������������������������������������225 Binding Times ���������������������������������������������������������������������������������������������������226 Public Interface �������������������������������������������������������������������������������������������������227 Hardware Abstract Layer (HAL) �������������������������������������������������������������������������231 Facade ���������������������������������������������������������������������������������������������������������231 Table of ConTenTs
📄 Page 11
xi Separation of Concerns �������������������������������������������������������������������������������238 Polymorphism ����������������������������������������������������������������������������������������������256 Dos and Don’ts ��������������������������������������������������������������������������������������������������263 Summary�����������������������������������������������������������������������������������������������������������265 Chapter 16: Release ��������������������������������������������������������������������������267 About Builds and Releases �������������������������������������������������������������������������������270 Tightening Up the Change Control Process �������������������������������������������������������273 Software Bill of Materials (SBOM) ���������������������������������������������������������������������274 Anomalies List ���������������������������������������������������������������������������������������������������276 Release Notes ���������������������������������������������������������������������������������������������������276 Deployment �������������������������������������������������������������������������������������������������������277 Over-the-Air (OTA) Updates ��������������������������������������������������������������������������278 QMS Deliverables ����������������������������������������������������������������������������������������������280 Archiving Build Tools �����������������������������������������������������������������������������������������282 Summary�����������������������������������������������������������������������������������������������������������283 Appendix A: Getting Started with the Source Code ��������������������������285 Appendix B: Running the Example Code �������������������������������������������313 Appendix C: Introduction to the Data Model Architecture ����������������349 Appendix D: LHeader and LConfig Patterns ��������������������������������������353 Appendix E: CPL C++ Framework �����������������������������������������������������363 Appendix F: NQBP2 Build System �����������������������������������������������������411 Appendix G: RATT ������������������������������������������������������������������������������437 Appendix H: GM6000 Requirements �������������������������������������������������449 Appendix I: GM6000 System Architecture ����������������������������������������467 Table of ConTenTs
📄 Page 12
xii Appendix J: GM6000 Software Architecture ������������������������������������473 Appendix K: GM6000 Software Development Plan ���������������������������507 Appendix L: GM6000 Software Detailed Design (Initial Draft) ����������533 Appendix M: GM6000 Software Detailed Design (Final Draft) ����������545 Appendix N: GM6000 Fuzzy Logic Temperature Control �������������������611 Appendix O: Software C/C++ Embedded Coding Standard ���������������621 Appendix P: GM6000 Software Requirements Trace Matrix �������������645 Appendix Q: GM6000 Software Bill of Materials �������������������������������659 Appendix R: GM6000 Software Release Notes ���������������������������������665 Index �������������������������������������������������������������������������������������������������671 Table of ConTenTs
📄 Page 13
xiii John Taylor has been an embedded developer for over 30 years. He has worked as a firmware engineer, technical lead, system engineer, software architect, and software development manager for companies such as Ingersoll Rand, Carrier, Allen-Bradley, Hitachi Telecom, Emerson, AMD, and several startup companies. He has developed firmware for products that include HVAC control systems, telecom SONET nodes, IoT devices, microcode for communication chips, and medical devices. He is the co-author of five US patents and holds a bachelor’s degree in mathematics and computer science. Wayne Taylor has been a technical writer for 27 years. He has worked with companies such as IBM, Novell, Compaq, HP, EMC, SanDisk, and Western Digital. He has documented compilers, LAN driver development, storage system deployment and maintenance, and dozens of low-level and system management APIs. He also has ten years of experience as a software development manager. He is the co-author of two US patents and holds master’s degrees in English and human factors. About the Authors
📄 Page 14
xv Jeff Gable is an embedded software consultant for the medical device industry, where he helps medical device startups develop bullet-proof software to take their prototypes through FDA submission and into production. Combining his expertise in embedded software, FDA design controls, and practical Agile methodologies, Jeff helps existing software teams be more effective and efficient or handles the entire software development and documentation effort for a new device. Jeff has spent his entire career doing safety-critical product development in small, cross-disciplinary teams. After stints in aerospace, automotive, and medical, he founded Gable Technology, Inc. in 2019 to focus on medical device startups. He also co-hosts the Agile Embedded podcast, where he discusses how device developers don't have to choose between time-to-market and quality. In his spare time, Jeff enjoys rock climbing, woodworking, and spending time with his wife and two small children. About the Technical Reviewer
📄 Page 15
xvii Preface My personal motivation for writing this cookbook is so that I never have to start an embedded project from scratch again. I am tired of reinventing the wheel every time I move to a new project, or new team, or new company. I have started over many times, and every time I find myself doing all the same things over again. This, then, is a cookbook for all the “same things” I do—all the same things that I inevitably have to do. In a sense, these are my recipes for success. On my next “new project,” I plan to literally copy and paste from the code and documentation templates I have created for this book. And for those bits that are so different that a literal copy and paste won’t work, I plan to use this cookbook as a “reference design” for generating the new content. For example, suppose for my next project I need a hash table (i.e., a dictionary) that does not use dynamic memory allocation. My options would be 1. Reuse or copy an existing module from this framework. 2. Adapt an existing module to meet my specific requirements. 3. Design and write the code from scratch. For me, the perfect world choice is option one—copy, paste into a new file, and then “save as” with a new file name. Option two would be to use the material in this book as a reference design. Start with one of the code or documentation templates and adapt it to the needs of the new project. And option three would be the last resort. Been there; done that; don’t want to do it ever again.
📄 Page 16
xviii Even though nothing is ever a perfect world choice, I know from experience that I can reuse some of this code wholesale with hardly any changes. In fact, the entire impetus behind my early GitHub projects was to have a reusable repository of source code that was not owned by someone else that I could freely use as needed—both professionally and personally. And because you bought this book, I’m providing you with a BSD license to all the source code so you can use and reuse just as freely. And, in addition to the raw, reusable blocks of source code, I also have the building blocks for the framework, which is the automated test tools and simulators required for building and releasing embedded projects. In some ways, I think of this cookbook as the user manual for all my GitHub toys. Beyond the obvious advantage of not having to rewrite code, there is also the advantage of having example documents and other materials that I can use when mentoring or training other engineers. In the past, when I’ve been trying to explain these concepts to new team members, it involved a lot of hand waving and hastily drawn boxes and arrows on the whiteboard. But now I have tangible examples of what I’m talking about at my fingertips. It’s yet another thing I don’t have to start from scratch. The next time I need to train or explain any of the best practices contained in this cookbook, I plan to say, “And if you want a better example of what I’m talking about, I know a really great book on this topic….” —John Taylor, Covington, Georgia, March 2024 PrefaCe
📄 Page 17
1© The Editor(s) (if applicable) and The Author(s), under exclusive license to APress Media, LLC, part of Springer Nature 2024 J. T. Taylor and W. T. Taylor, The Embedded Project Cookbook, https://doi.org/10.1007/979-8-8688-0327-7_1 CHAPTER 1 Introduction The purpose of this cookbook is to enable the reader to never have to develop a microcontroller software project from scratch. By a project, I mean everything that is involved in releasing a commercially viable product that meets industry standards for quality. A project, therefore, includes noncode artifacts such as software processes, software documentation, continuous integration, design reviews and code reviews, etc. Of course, source code is included in this as well. And it is production- quality source code; it incorporates essential middleware such as an OS abstraction layer (OSAL), containers that don’t use dynamic memory, inter-thread communication modules, a command-line console, and support for a functional simulator. The book is organized in the approximate chronological order of a software development life cycle. In fact, it begins with a discussion of the software development process and the software development life cycle. However, the individual chapters are largely independent and can stand alone. Or, said another way, you are encouraged to navigate the chapters in whatever order seems most interesting to you. Note The focus of this cookbook is on software development—not the processes or deliverables of other disciplines. Other disciplines that participate in the process are typically only discussed in the context of their providing inputs for project artifacts or their consuming of project artifacts.
📄 Page 18
2 Software Development Processes Software development processes are different everywhere. No two organizations create software the same way, and in some organizations and companies, no two teams do it the same way. Additionally, processes that are intended to improve quality are not uniformly implemented: neither by companies in the same industry segment, nor, sometimes, by members of the same team. Consequently, there is no one-size-fits- all model or solution for professional software development. And yet, everybody ends up doing the same things. For example, Figure 1-1 shows a straightforward model for developing a bit of software for an embedded system. Figure 1-1. A simple development model for embedded software At your discretion, you could add additional steps, or your organization might require additional processes. So the model might be expanded to something like what is shown in Figure 1-2. ChapTer 1 InTrOduCTIOn
📄 Page 19
3 Figure 1-2. Additional steps and processes for a simple development model The more additional processes and steps you add, the more sophisticated your development process becomes, and—if you add the right additional processes—the better the results. Figure 1-3 illustrates this continuum. ChapTer 1 InTrOduCTIOn
📄 Page 20
4 Figure 1-3. A continuum of software development processes and practices There is no perfect set of processes. However, in my career, I have found myself using the same processes and steps over and over again. This book, then, is a collection of the steps and processes that I have found essential for developing embedded software in a commercial environment. I recommend them to you as an effective, efficient way to develop great code. Of course, you can skip any of these recommended steps or phases, but every time you do, there’s a good chance that you’re buying yourself pain, frustration, and extra work down the road. It is easy to say, “Oh, I can just clean up and refactor this module later so it meets our standards and conventions,” but for me, clean-up refactoring is painful, and I have found it often gets skipped for the sake of schedule pressure. Personally, I try very hard not to skip steps because if I do, things don’t get done any faster, and all I’ve done is start the project with technical debt. In the end, it will come down to how willing you are to take on and adopt the engineering disciplines that these “software recipes” embody. Unfortunately, many people equate discipline with “doing stuff they don’t ChapTer 1 InTrOduCTIOn
The above is a preview of the first 20 pages. Register to read the complete e-book.

💝 Support Author

0.00
Total Amount (¥)
0
Donation Count

Login to support the author

Login Now

Recommended for You

Loading recommended books...
Failed to load, please try again later
Back to List