Chapter 6

Microcontrollers, Zephyr, hardware, and debugging

This chapter describes the hardware and system software of small embedded devices, with the Arm Cortex-M4 §6.3 processor, the nRF52840 §6.4 microcontroller §6.1 and the Zephyr real-time operating system §6.33 as examples. It begins with the parts of a microcontroller and its memories, then the hardware that confines code: the memory protection unit §6.8, the memory management unit §6.9 that larger processors have instead, and privilege levels §6.10. Next come interrupts §6.11 and their handlers, faults, watchdog timers §6.16, resets and power loss, and the clocks and counters with which a device measures time, including how those clocks drift and how counters wrap around.

The middle of the chapter covers the interfaces through which engineers observe and control a device: general-purpose pins, serial ports, USB, and the debug ports and tools that can halt the processor and rewrite its memory. It then explains how a device starts, through bootloaders §6.30, secure boot §6.31 and measured boot §6.32. The last entries describe Zephyr itself, its threads, work queues §6.36 and scheduling rules, what makes a requirement a real-time requirement, and how drivers, hardware descriptions and build options assemble one firmware image.

In this chapter

  1. 6.1 Microcontroller (MCU)
  2. 6.2 System on chip (SoC)
  3. 6.3 Arm Cortex-M4
  4. 6.4 nRF52840
  5. 6.5 Development kit versus dongle
  6. 6.6 Flash memory
  7. 6.7 SRAM
  8. 6.8 Memory protection unit (MPU)
  9. 6.9 Memory management unit (MMU)
  10. 6.10 Privilege level
  11. 6.11 Interrupt
  12. 6.12 Interrupt service routine (ISR)
  13. 6.13 NVIC
  14. 6.14 Vector table
  15. 6.15 Exception and fault handler
  16. 6.16 Watchdog timer
  17. 6.17 Brownout and power-on reset
  18. 6.18 Clock source and drift
  19. 6.19 RTC versus cycle counter
  20. 6.20 DWT cycle counter
  21. 6.21 Counter wraparound
  22. 6.22 GPIO
  23. 6.23 UART
  24. 6.24 USB CDC ACM
  25. 6.25 SWD
  26. 6.26 JTAG
  27. 6.27 J-Link
  28. 6.28 GDB
  29. 6.29 OpenOCD
  30. 6.30 Bootloader
  31. 6.31 Secure boot
  32. 6.32 Measured boot and attestation
  33. 6.33 Zephyr RTOS
  34. 6.34 Real-time system
  35. 6.35 Zephyr thread
  36. 6.36 Zephyr workqueue
  37. 6.37 Cooperative and preemptive scheduling
  38. 6.38 Device driver
  39. 6.39 Devicetree
  40. 6.40 Kconfig
  41. 6.41 Board overlay
  42. 6.42 Hardware abstraction layer (HAL)
  43. 6.43 CMSIS
  44. 6.44 Firmware build profile