Device Drivers

NuttX supports a variety of device drivers, which can be broadly divided in three classes:

Note

Device driver support depends on the in-memory, pseudo file system that is enabled by default.

Lower-half and upper-half

Drivers in NuttX generally work in two distinct layers:

  • An upper half which registers itself to NuttX using a call such as register_driver() or register_blockdriver() and implements the corresponding high-level interface (read, write, close, etc.). implements the interface. This upper half calls into the lower half via callbacks.

  • A “lower half” which is typically hardware-specific. This is usually implemented at the architecture or board level.

Details about drivers implementation can be found in OS Drivers Design and Device Drivers.

Subdirectories of nuttx/drivers

Skeleton Files

Skeleton files are “empty” frameworks for NuttX drivers. They are provided to give you a good starting point if you want to create a new NuttX driver. The following skeleton files are available:

  • drivers/lcd/skeleton.c Skeleton LCD driver

  • drivers/mtd/skeleton.c Skeleton memory technology device drivers

  • drivers/net/skeleton.c Skeleton network/Ethernet drivers

  • drivers/usbhost/usbhost_skeleton.c Skeleton USB host class driver

Drivers Early Initialization

To initialize drivers early in the boot process, the drivers_early_initialize() function is introduced. This is particularly beneficial for certain drivers, such as SEGGER SystemView, or others that require initialization before the system is fully operational.

It is important to note that during this early initialization phase, system resources are not yet available for use. This includes memory allocation, file systems, and any other system resources.