HAL USB HCD Overview

Introducing USB HCD

group HCD_Introduction

USB Host Controller Driver (HCD) hardware abstraction layer provides all required APIs to interface with the USB peripheral in host mode. It simplifies the initialization, configuration, and management of the USB depending on the user’s required host function.

This abstraction layer ensures portability and ease of use across different STM32 series. The HCD HAL abstracts different USB hardware instances that can be present (depending on the STM32 MCU): USB OTG FS (On-The-GO Full Speed) USB OTG HS (On-The-GO High Speed) USB DRD FS (Dual Role Device Full Speed)

Module and files

The following diagram illustrates the HAL USB HCD module and its associated files.

Module and files diagram

Component diagram

The following diagram illustrates the software components involved in the HAL USB HCD module. It shows the interactions between the user application, HAL drivers, low-level drivers, and the hardware components.


@startuml
<style>
componentDiagram {
   arrow {
      FontSize 8
   }
}
</style>

title HCD Software Component Diagram

package "MW" {
    [USB_Host_MW]
}

package "HAL" {
    [HAL_SERVICE]
    [HAL_HCD]
}

package "Core Layer" {
    [usb_drd_core]
    [CMSIS]
    [HCD DRD Interrupt routine service]
}

package "HW" {
    [STM32_HW]
}

[Appli] --> [HAL_HCD] : HAL HCD Init & Config
[Appli] --> [USB_Host_MW]: HAL HCD Start & Stop
[USB_Host_MW] --> [HAL_HCD]: HAL HCD Start & Stop
[USB_Host_MW] <-- [HAL_HCD] : HCD callback
[HAL_HCD] --> [usb_drd_core] : USB core HCD API
[HAL_HCD] -l-> [HAL_SERVICE] : HAL_GetTick
[HAL_HCD] <-- [HCD DRD Interrupt routine service]
[usb_drd_core] --> [CMSIS]:HCD register def
[STM32_HW] -u--> [HCD DRD Interrupt routine service]: HCDx DRD Irq
[STM32_HW] <-u-- [usb_drd_core] : HCD registers R/W

@enduml

Configuration table

The following table lists the configuration defines for the HAL USB HCD module, specifying their locations, default values, and descriptions:

group HCD_Configuration_Table

Configuration inside the USB HCD driver:

Config defines

Description

Default value

Note

USE_ASSERT_DBG_PARAM

from IDE

NA

Enable the parameter assert.

USE_ASSERT_DBG_STATE

from IDE

NA

Enable the state assert.

USE_HAL_HCD_MODULE

from hal_conf.h

1

Enable the HAL USB HCD module.

USE_HAL_HCD_REGISTER_CALLBACKS

from hal_conf.h

0

Enable the register callbacks.

USE_HAL_HCD_MAX_CHANNEL_NB

from hal_conf.h

16

Maximum number of USB HCD channels.

USE_HAL_HCD_USB_EP_TYPE_ISOC

from hal_conf.h

1

Enable support for isochronous endpoints.

USE_HAL_HCD_USB_DOUBLE_BUFFER

from hal_conf.h

1

Enable double-buffering for USB transfers.

USE_HAL_HCD_USER_DATA

from hal_conf.h

0

Add user data to the HAL USB HCD handle.

USE_HAL_HCD_GET_LAST_ERRORS

from hal_conf.h

0

Add an error value to the HAL USB HCD handle.

USE_HAL_CHECK_PARAM

from hal_conf.h

0

Enable checking of HCD API parameters at runtime.