Nội dung text main.pdf
Public Draft - a30953f.
Public Draft - a30953f. Letter to the reader Why this book? A bunch of us were discussing over coffee how each one of us came about having a career in Embedded Systems engineering and how fulfilling it is. The joy of having an LED (light emitting diode) blink as a result of the code cannot be described in plain words. There is something magical and powerful about it. The magical part is - The hardware is doing something as a result of software, and the powerful part is - You can influence the physical world. People talked about how difficult it was for them to search for the right resources and learn - find the right book, the websites, the resource, the hardware, get the right cables etc, and hope-n-pray that everything will work as expected. Each one described in great details various debugs they had to do to get simple things working. The question towards the end was - what resources can you recommend to a young aspiring embedded engineer? Their journies ressembled a lot like my own, I was a lot junior to them but seemed like not much had changed in terms of learning Embedded Systems. I had the advantage of the internet, but the information is scattered! The answer to what recommendations we have for the young and aspiring engineers seemed a lot convoluted, none of us seemed to have a good goto resource as a recommendation, to... if not anything become useful for a team already working on some embedded systems. It dwaned on us that having had the experience we have had, we might be well positioned to contribute back to the community and fill the gap! This book aims to be that goto resource. We hope this book gives the reader the insights and vocabulary needed to be useful when working on a team, developing embedded systems based solutions. One of the ways to be useful is to - Know the C programming language and be able to reason about the software down to how it effects the hardware. The first part is relatively easy and tons of resources are available online already. The second part is tricky to learn. That is where we figured we can help with our experience, and that is also where there are no structured resources (that we are aware of) available to learn from. This book starts with the hardware, reasons about the usefulness of the C language in programming it and then teaches everything about the language and tools required to be able to program the hardware. We’ve focused mainly on the machine and the tools around it and reasoned about the C language and it’s syntax. Embedded C doesn’t exist! We have had the good fortune of mentoring dozens of junior engineers who were just starting their careers. One common myth they seemed to have accidently bought into seemed to be this - Embedded C is a different language! and the common complain being - I don’t understand the difference between C and Embedded C!
Public Draft - a30953f. Embedded C is not a separate language! There is no such thing as "Embedded C" actually. There is only C programming language that is used to write lower level code that is deployed on CPUs in embedded systems based solutions. That’s all! It is plain old C language as appiled to Embedded systems programming. C for Embedded Systems is the same old C programming language used specifically for programming embedded systems, which are computer systems that form a part of larger systems or devices. The mindset and thinking involved in writing code for embedded stytems is slightly different from the conventional systems/app development using the C language, primarily in the sense that lower level hardware interactions are involved. Direct control over peripherals, sensors, actuators, and other hardware devices is essential for embedded systems, as it enables precise control and customization tailored to specific requirements. When compared to using C for systems/app development, using it for embedded systems requires developers to have a more thorough understanding of hardware architecture and constraints - something we have tried to cover as part of the journey through the chapters in this book. This deeper knowledge allows programmers to design and implement efficient and reliable software for embedded systems. This book will introduce you to (and potentially help master) the C language (as it is used for developing embedded systems) and all other details that would need to have a tight control on the software. You will gain the skills necessary to develop software for embedded systems, opening up diverse career opportunities in industries such as automotive, aerospace, telecommunications, consumer electronics, and medical devices etc. Who this is for? This is book is targeted for begineers, those intending to revisit the lower level details like assembly and machine code or those seeking to randomly try their hands at Embedded Systems as hobby. The book is hands-on and takes a casual approach in introducing the concepts, the end goal being - The reader become more capable at writing code for Embedded systems. That said, we are sure that the content will also help the general software engineers/students by introducing them to the underlying details of how the machine and code works. Hopefully, that will enable better reasoning and writing optimised software in other high level lanaguges. Approach As you read through the book, please do remember that when working on any embedded systems - The system is the center of the universe! Everything else - the tools, the language, the processor etc are secondary. We have structured the content to take you on a journey from Systems as they were in 1970s to outputting Hello, World! on UART (universal asynchronous receiver and transmitter) hardware. Along the way, we introduce the tools, assembly language, C language and CPU boot process. Why emulator? We have used an Emulator (a software that mimics the hardware) to run all the experiments and do the debug on, our intention with this to ensure everyone can follow along and don’t have to necessarily invtest into a hardware board. Why RISC-V architecture? RISC-V is an open architecture and a lot of documentation and forums are available around it to be able to self learn more. Besides, it is also getting rapidly adopted and we feel it will have a great futher. We felt it makes