Embedded Software, Programming & Debugging
Syllabus
This module will cover the following aspects
• Software for embedded systems
• Embedded systems programming
• Embedded systems debugging
2 © 2020 Arm Limited
Embedded software
Software incorporated into/aiming to control machines or devices
• Usually specialized for a specific hardware platform and specific purpose
• Simple, limited memory requirements
• Often does not require OS support → firmware
• Subject to timing constraints
• Many control functions not tied to human interaction
• Often built into one (or more) microcontrollers
3 © 2020 Arm Limited
Embedded software constraints
Lack of abstraction
developer directly exposed to underlying hardware
Efficiency
given energy & timing budgets, optimization is required
Responsiveness
system needs to react to external triggers in a timely manner
Concurrency
multiple physical events happening at the same time must be handled
Reliability
code errors can have catastrophic events in practice
Q. Why do you think there is a lack of abstraction for embedded software?
4 © 2020 Arm Limited
Embedded systems programming and debugging
Different options to upload/debug code on a microcontroller
• A range of interfaces are used to program embedded systems, including Joint Test Action Group (JTAG), Serial Wire Debug (SWD), Single Wire Interface Module (SWIM), etc.
• Programming consists of writing program code to non-volatile memory (e.g., Electrically Erasable Programmable Read-Only Memory, EEPROM) and configuring the system via fuses.
• Fuses are configuration bits that control key behavior of embedded hardware, e.g., clock rate, power-up timer, etc.
5 © 2020 Arm Limited
Bootloaders
Initialisation and firmware programming
• A bootloader is a special (tiny) application that prepares a microcontroller for execution of the main program, by initialising memory and peripherals.
• It is the first piece of code executed when the microcontroller comes out of reset.
• It can also provide a firmware programming method, i.e. expose functionality to enable
writing to program and data memory.
Bootloaders may be generic (coreboot, U-boot) and configured to the hardware, or supplied by a board or microcontroller manufacturer.
6
© 2020 Arm Limited
Configuration via fuses
• Configuration fuses are a non-volatile memory used to configure the fundamental behaviour of a microcontroller, e.g. the clock source, clock rate, watchdog timer, brown-out detect, etc.
7
© 2020 Arm Limited
Over-the-air programming
• Useful to update wireless devices after product release.
• A risk of rendering the device unusable exists, if programming is
interrupted or inappropriate software is uploaded → recovery.
• Ideally, a separate chip would handle OTA programming, but this
increases the footprint and cost of the device.
• More often, the bootloader may handle OTA and in case of update failure, revert the firmware to the previous version.
Q. Besides the risk of “bricking” what other issues may there be with OTA updates?
8 © 2020 Arm Limited
Embedded software debugging
Much more complicated than debugging regular software and involves some hardware interface Challenging to debug code involving interactions with peripherals
Debug pins could be made available for programming and testing during manufacturing
Sometime convenient to implement a command-line interface (CLI) that can enable real-time inspection of registers and memory contents
Integrated Development Environments (IDEs) frequently used to simplify debugging
9 © 2020 Arm Limited
Simulation
• Simulation of a hardware platform is very useful, as you get to work with a virtual version of device that might not yet physically exist.
• There is no need to deploy the application to hardware, which takes time, but also may degrade flash memory.
• Simulation lets you work on the hardware design in parallel to software, or implement hardware/software co-design. Levels of simulation give different insights into the behaviour of the device:
10
• Functional Simulation
• Cycle-accurate Simulation • RTL simulation
Fast
Slow Very slow
© 2020 Arm Limited
Application Frameworks and Embedded OSes
Frameworks introduce a level of maintainability to an application. By re-using common code, it reduces maintenance burden, improves code quality, and you benefit from (possibly) more scrutinised and tuned implementations.
Drawbacks are security issues, which when discovered in a framework will impact all devices using that framework, and obsolescence when a developer stops supporting it.
Also, performance can be an issue, if core functionality is implemented as function calls, e.g. a HAL which makes calls to toggle GPIO, such as Arduino’s digitalWrite().
Example application frameworks include: Arduino, PlatformIO. Increasing complexity/reach of frameworks, they become more like Oses, e.g. RTOS, mbedOS.
11
© 2020 Arm Limited
Standard Interfaces
Serial interfaces are typically found on Microcontrollers, e.g. UARTs. These can be used for application-specific communication, debugging or other purposes.
FTDI design and manufacture ICs for bridging a USB serial-port to UART, an extremely straightforward way to get USB connectivity to a device.
JTAG – Joint Test Action Group – is an industry standard for testing and debugging circuits after manufacture. It specifies a serial debug port that can be used to interrogate various chips, and even upload data to flash memory.
Q. Since USB is very common, why don’t we simply use USB directly for this purpose?
12
© 2020 Arm Limited
Joint Test Action Group (JTAG)
JTAG is a standardised interface for programming and debugging (IEEE 1149.1)
It connects between multiple chips on a bus, and allows commands and data to be sent to any chip on the bus.
Based on TDI/TDO/TCK/TMS/TRST lines.
Boundary scanning allows a direct view of chip state over JTAG, so internal aspects or pin connections between chips (that are difficult to probe) can be tested.
13
© 2020 Arm Limited
JTAG Test Access Port
The JTAG TAP controller state machine specifies how a device should interpret JTAG communications, using
• DR: Data Registers
• IR: Instruction Registers
Holding TMS high for at least 5 TCK cycles returns to test logic reset state.
(TRST is an optional reset.) 14
© 2020 Arm Limited
Summary
• Embedded software has constraints, unique to each application/environment
• Hardware restricted, often by power / cost
• Special mechanisms for setup: bootloader, programming, OTA updates
• Special mechanisms for debugging: JTAG, SWD, software support
• Most cases use frameworks or cut-down/embedded operating systems
15
© 2020 Arm Limited