Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
cubexHal.pdf
Скачиваний:
111
Добавлен:
10.02.2016
Размер:
16.16 Mб
Скачать

UM1725

HAL SAI Generic Driver

DMA_HandleTypeDef * hdmatx

DMA_HandleTypeDef * hdmarx

SAIcallback mutecallback

void(* InterruptServiceRoutine

HAL_LockTypeDef Lock

__IO HAL_SAI_StateTypeDef State

__IO uint32_t ErrorCode

Field Documentation

SAI_Block_TypeDef* __SAI_HandleTypeDef::Instance

SAI Blockx registers base address

SAI_InitTypeDef __SAI_HandleTypeDef::Init

SAI communication parameters

SAI_FrameInitTypeDef __SAI_HandleTypeDef::FrameInit

SAI Frame configuration parameters

SAI_SlotInitTypeDef __SAI_HandleTypeDef::SlotInit

SAI Slot configuration parameters

uint8_t* __SAI_HandleTypeDef::pBuffPtr

Pointer to SAI transfer Buffer

uint16_t __SAI_HandleTypeDef::XferSize

SAI transfer size

uint16_t __SAI_HandleTypeDef::XferCount

SAI transfer counter

DMA_HandleTypeDef* __SAI_HandleTypeDef::hdmatx

SAI Tx DMA handle parameters

DMA_HandleTypeDef* __SAI_HandleTypeDef::hdmarx

SAI Rx DMA handle parameters

SAIcallback __SAI_HandleTypeDef::mutecallback

SAI mute callback

void(* __SAI_HandleTypeDef::InterruptServiceRoutine)(struct __SAI_HandleTypeDef *hsai)

HAL_LockTypeDef __SAI_HandleTypeDef::Lock

SAI locking object

__IO HAL_SAI_StateTypeDef __SAI_HandleTypeDef::State

SAI communication state

__IO uint32_t __SAI_HandleTypeDef::ErrorCode

SAI Error code

50.2SAI Firmware driver API description

50.2.1How to use this driver

The SAI HAL driver can be used as follows:

1.Declare a SAI_HandleTypeDef handle structure.

2.Initialize the SAI low level resources by implementing the HAL_SAI_MspInit() API:

a.Enable the SAI interface clock.

b.SAI pins configuration:

Enable the clock for the SAI GPIOs.

Configure these SAI pins as alternate function pull-up.

c.NVIC configuration if you need to use interrupt process (HAL_SAI_Transmit_IT() and HAL_SAI_Receive_IT() APIs):

DOCID025834 Rev 2

669/900

HAL SAI Generic Driver

UM1725

Configure the SAI interrupt priority.

Enable the NVIC SAI IRQ handle.

d.DMA Configuration if you need to use DMA process (HAL_SAI_Transmit_DMA() and HAL_SAI_Receive_DMA() APIs):

Declare a DMA handle structure for the Tx/Rx stream.

Enable the DMAx interface clock.

Configure the declared DMA handle structure with the required Tx/Rx parameters.

Configure the DMA Tx/Rx Stream.

Associate the initialized DMA handle to the SAI DMA Tx/Rx handle.

Configure the priority and enable the NVIC for the transfer complete interrupt on the DMA Tx/Rx Stream.

3.Program the SAI Mode, Standard, Data Format, MCLK Output, Audio frequency and Polarity using HAL_SAI_Init() function. The specific SAI interrupts (FIFO request and Overrun underrun interrupt) will be managed using the macros __SAI_ENABLE_IT() and __SAI_DISABLE_IT() inside the transmit and receive process.

SAI Clock Source configuration is managed differently depending on the selected STM32F4 devices :

For STM32F446xx devices, the configuration is managed through RCCEx_PeriphCLKConfig() function in the HAL RCC drivers

For STM32F439xx/STM32F437xx/STM32F429xx/STM32F427xx devices, the configuration is managed within HAL SAI drivers through HAL_SAI_Init() function using ClockSource field of SAI_InitTypeDef structure.

Make sure that either:

I2S PLL is configured or

SAI PLL is configured or

External clock source is configured after setting correctly the define constant EXTERNAL_CLOCK_VALUE in the stm32f4xx_hal_conf.h file.

In master Tx mode: enabling the audio block immediately generates the bit clock for the external slaves even if there is no data in the FIFO, However FS signal generation is conditioned by the presence of data in the FIFO.

In master Rx mode: enabling the audio block immediately generates the bit clock and FS signal for the external slaves.

It is mandatory to respect the following conditions in order to avoid bad SAI behavior:

First bit Offset <= (SLOT size - Data size)

Data size <= SLOT size

Number of SLOT x SLOT size = Frame length

The number of slots should be even when

SAI_FS_CHANNEL_IDENTIFICATION is selected.

670/900

DOCID025834 Rev 2

UM1725

HAL SAI Generic Driver

Three operation modes are available within this driver :

Polling mode IO operation

 

Send an amount of data in blocking mode using HAL_SAI_Transmit()

 

Receive an amount of data in blocking mode using HAL_SAI_Receive()

Interrupt mode IO operation

Send an amount of data in non blocking mode using HAL_SAI_Transmit_IT()

At transmission end of transfer HAL_SAI_TxCpltCallback is executed and user can add his own code by customization of function pointer HAL_SAI_TxCpltCallback

Receive an amount of data in non blocking mode using HAL_SAI_Receive_IT()

At reception end of transfer HAL_SAI_RxCpltCallback is executed and user can add his own code by customization of function pointer HAL_SAI_RxCpltCallback

In case of transfer Error, HAL_SAI_ErrorCallback() function is executed and user can add his own code by customization of function pointer HAL_SAI_ErrorCallback

DMA mode IO operation

Send an amount of data in non blocking mode (DMA) using HAL_SAI_Transmit_DMA()

At transmission end of transfer HAL_SAI_TxCpltCallback is executed and user can add his own code by customization of function pointer HAL_SAI_TxCpltCallback

Receive an amount of data in non blocking mode (DMA) using

HAL_SAI_Receive_DMA()

At reception end of transfer HAL_SAI_RxCpltCallback is executed and user can add his own code by customization of function pointer HAL_SAI_RxCpltCallback

In case of transfer Error, HAL_SAI_ErrorCallback() function is executed and user can add his own code by customization of function pointer HAL_SAI_ErrorCallback

Pause the DMA Transfer using HAL_SAI_DMAPause()

Resume the DMA Transfer using HAL_SAI_DMAResume()

Stop the DMA Transfer using HAL_SAI_DMAStop()

SAI HAL driver macros list

Below the list of most used macros in USART HAL driver :

__HAL_SAI_ENABLE: Enable the SAI peripheral

__HAL_SAI_DISABLE: Disable the SAI peripheral

__HAL_SAI_ENABLE_IT : Enable the specified SAI interrupts

__HAL_SAI_DISABLE_IT : Disable the specified SAI interrupts

__HAL_SAI_GET_IT_SOURCE: Check if the specified SAI interrupt source is enabled or disabled

__HAL_SAI_GET_FLAG: Check whether the specified SAI flag is set or not

50.2.2Initialization and de-initialization functions

This subsection provides a set of functions allowing to initialize and de-initialize the SAIx peripheral:

DOCID025834 Rev 2

671/900

HAL SAI Generic Driver

UM1725

User must implement HAL_SAI_MspInit() function in which he configures all related peripherals resources (CLOCK, GPIO, DMA, IT and NVIC ).

Call the function HAL_SAI_Init() to configure the selected device with the selected configuration:

Mode (Master/slave TX/RX)

Protocol

Data Size

MCLK Output

Audio frequency

FIFO Threshold

Frame Config

Slot Config

Call the function HAL_SAI_DeInit() to restore the default configuration of the selected SAI peripheral.

This section contains the following APIs:

HAL_SAI_InitProtocol()

HAL_SAI_Init()

HAL_SAI_DeInit()

HAL_SAI_MspInit()

HAL_SAI_MspDeInit()

50.2.3IO operation functions

This subsection provides a set of functions allowing to manage the SAI data transfers.

There are two modes of transfer:

Blocking mode : The communication is performed in the polling mode. The status of all data processing is returned by the same function after finishing transfer.

No-Blocking mode : The communication is performed using Interrupts or DMA. These functions return the status of the transfer startup. The end of the data processing will be indicated through the dedicated SAI IRQ when using Interrupt mode or the DMA IRQ when using DMA mode.

Blocking mode functions are :

HAL_SAI_Transmit()

HAL_SAI_Receive()

HAL_SAI_TransmitReceive()

Non Blocking mode functions with Interrupt are :

HAL_SAI_Transmit_IT()

HAL_SAI_Receive_IT()

HAL_SAI_TransmitReceive_IT()

Non Blocking mode functions with DMA are :

HAL_SAI_Transmit_DMA()

HAL_SAI_Receive_DMA()

HAL_SAI_TransmitReceive_DMA()

A set of Transfer Complete Callbacks are provided in non Blocking mode:

HAL_SAI_TxCpltCallback()

HAL_SAI_RxCpltCallback()

HAL_SAI_ErrorCallback()

This section contains the following APIs:

HAL_SAI_Transmit()

HAL_SAI_Receive()

672/900

DOCID025834 Rev 2

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]