HAL DAC Overview

Introducing DAC

group DAC_Introduction

  • The DAC (Digital-to-Analog Converter) hardware abstraction layer provides a set of APIs to interface with the STM32 DAC peripheral.

  • It simplifies the configuration, initialization, and management of analog output functionality, supporting various modes such as polling, interrupt, and DMA for efficient data transfer.

  • This abstraction layer ensures portability and ease of use across different STM32 series. The HAL DAC driver abstracts device-specific features.

The HAL DAC driver includes the following features:

  • Output buffer management for driving external loads

  • Calibration features for improved analog output accuracy

  • Support for single and dual-channel operation

  • Advanced signal generation:

    • Noise

    • Triangle

User-defined buffer transfer via DMA

  • Sample-and-hold mode for low-power applications

Module and files

The following diagram illustrates the DAC module and its associated files.

Module and files diagram

Component diagram

The following diagram illustrates the software components involved in the DAC 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 DAC Software Component Diagram

package "HAL" {
    [HAL_SERVICE]
    [HAL_DAC]
    [HAL_DMA]
}

package "Low Layer" {
    [LL_DAC]
    [CMSIS]
    [DAC Interrupt routine service]
    [DMA Interrupt routine service]
}

package "HW" {
    [STM32_HW]
}

[Appli] --> [HAL_DAC] : HAL DAC API
[Appli] <-- [HAL_DAC] : DAC callback
[HAL_DAC] --> [LL_DAC] : LL DAC API
[HAL_DAC] -r-> [HAL_DMA] : HAL DMA_Start_IT\nHAL_DMA_Abort_IT
[HAL_DAC] -l-> [HAL_SERVICE] : HAL_GetTick
[HAL_DAC] <-- [DAC Interrupt routine service]
[HAL_DAC] <-r- [HAL_DMA]:Half transfer complete\nTransfer complete\nError
[LL_DAC] --> [CMSIS]:DAC register def
[HAL_DMA] <-d- [DMA Interrupt routine service]
[STM32_HW] -u--> [DAC Interrupt routine service]: DACx Irq
[STM32_HW] -u--> [DMA Interrupt routine service] : DMA Channel Irq
[STM32_HW] <-u-- [LL_DAC] : DAC registers R/W
@enduml

Configuration table

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

group DAC_Configuration_Table

Configuration in the DAC driver

Config defines

Description

Default value

Note

USE_HAL_DAC_MODULE

hal_conf.h

1

HAL DAC module is enabled.

USE_HAL_DAC_USER_DATA

hal_conf.h

0

Enable user data.

USE_HAL_DAC_REGISTER_CALLBACKS

hal_conf.h

0

Enable register callback assertions.

USE_HAL_DAC_CLK_ENABLE_MODEL

hal_conf.h

HAL_CLK_ENABLE_NO

Otherwise, the clock is enabled inside HAL_DAC_Init().

USE_HAL_DAC_DMA

hal_conf.h

1

Use DMA with the DAC.

USE_HAL_CHECK_PARAM

hal_conf.h

0

Enable run-time checks on function parameters.

USE_HAL_CHECK_PROCESS_STATE

hal_conf.h

0

Enable run-time checks on the state during processing.

USE_HAL_DAC_GET_LAST_ERRORS

hal_conf.h

0

Record errors that occur during DAC channel processing.

USE_HAL_DAC_DUAL_CHANNEL

hal_conf.h

1

Enable DAC dual channel mode (if DAC_NB_OF_CHANNEL > 1).

USE_ASSERT_DBG_PARAM

Pre-processor env

None

Enable assert checks on function parameters.

USE_ASSERT_DBG_STATE

Pre-processor env

None

Enable assert checks on module state.

DAC_NB_OF_CHANNEL

DFP

NA

DAC channel count (value “2” allows dual mode).