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

UM1725

HAL IRDA Generic Driver

uint16_t RxXferSize

uint16_t RxXferCount

DMA_HandleTypeDef * hdmatx

DMA_HandleTypeDef * hdmarx

HAL_LockTypeDef Lock

__IO HAL_IRDA_StateTypeDef State

__IO uint32_t ErrorCode

Field Documentation

USART_TypeDef* IRDA_HandleTypeDef::Instance

IRDA_InitTypeDef IRDA_HandleTypeDef::Init

uint8_t* IRDA_HandleTypeDef::pTxBuffPtr

uint16_t IRDA_HandleTypeDef::TxXferSize

uint16_t IRDA_HandleTypeDef::TxXferCount

uint8_t* IRDA_HandleTypeDef::pRxBuffPtr

uint16_t IRDA_HandleTypeDef::RxXferSize

uint16_t IRDA_HandleTypeDef::RxXferCount

DMA_HandleTypeDef* IRDA_HandleTypeDef::hdmatx

DMA_HandleTypeDef* IRDA_HandleTypeDef::hdmarx

HAL_LockTypeDef IRDA_HandleTypeDef::Lock

__IO HAL_IRDA_StateTypeDef IRDA_HandleTypeDef::State

__IO uint32_t IRDA_HandleTypeDef::ErrorCode

34.2IRDA Firmware driver API description

34.2.1How to use this driver

The IRDA HAL driver can be used as follows:

1.Declare a IRDA_HandleTypeDef handle structure.

2.Initialize the IRDA low level resources by implementing the HAL_IRDA_MspInit() API:

a.Enable the USARTx interface clock.

b.IRDA pins configuration:

Enable the clock for the IRDA GPIOs.

Configure these IRDA pins as alternate function pull-up.

c.NVIC configuration if you need to use interrupt process

(HAL_IRDA_Transmit_IT() and HAL_IRDA_Receive_IT() APIs):

Configure the USARTx interrupt priority.

Enable the NVIC USART IRQ handle.

d. DMA Configuration if you need to use DMA process

(HAL_IRDA_Transmit_DMA() and HAL_IRDA_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 IRDA 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 Baud Rate, Word Length, Parity, IrDA Mode, Prescaler and Mode(Receiver/Transmitter) in the hirda Init structure.

DOCID025834 Rev 2

437/900

HAL IRDA Generic Driver

UM1725

4.Initialize the IRDA registers by calling the HAL_IRDA_Init() API:

This API configures also the low level Hardware GPIO, CLOCK, CORTEX...etc) by calling the customized HAL_IRDA_MspInit() API. The specific IRDA interrupts (Transmission complete interrupt, RXNE interrupt and Error Interrupts) will be managed using the macros __HAL_IRDA_ENABLE_IT() and __HAL_IRDA_DISABLE_IT() inside the transmit and receive process.

5.Three operation modes are available within this driver :

Polling mode IO operation

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

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

Interrupt mode IO operation

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

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

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

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

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

DMA mode IO operation

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

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

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

HAL_IRDA_Receive_DMA()

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

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

IRDA HAL driver macros list

You can refer to the IRDA HAL driver header file for more useful macros

34.2.2Initialization and Configuration functions

This subsection provides a set of functions allowing to initialize the USARTx or the UARTy in IrDA mode.

For the asynchronous mode only these parameters can be configured:

BaudRate

438/900

DOCID025834 Rev 2

UM1725

HAL IRDA Generic Driver

WordLength

Parity: If the parity is enabled, then the MSB bit of the data written in the data register is transmitted but is changed by the parity bit. Depending on the frame length defined by the M bit (8-bits or 9-bits), please refer to Reference manual for possible IRDA frame formats.

Prescaler: A pulse of width less than two and greater than one PSC period(s) may or may not be rejected. The receiver set up time should be managed by software. The IrDA physical layer specification specifies a minimum of 10 ms delay between transmission and reception (IrDA is a half duplex protocol).

Mode: Receiver/transmitter modes

IrDAMode: the IrDA can operate in the Normal mode or in the Low power mode.

The HAL_IRDA_Init() API follows IRDA configuration procedures (details for the procedures are available in reference manual).

This section contains the following APIs:

HAL_IRDA_Init()

HAL_IRDA_DeInit()

HAL_IRDA_MspInit()

HAL_IRDA_MspDeInit()

34.2.3IO operation functions

IrDA is a half duplex communication protocol. If the Transmitter is busy, any data on the IrDA receive line will be ignored by the IrDA decoder and if the Receiver is busy, data on the TX from the USART to IrDA will not be encoded by IrDA. While receiving data, transmission should be avoided as the data to be transmitted could be corrupted.

1.There are two modes of transfer:

Blocking mode: The communication is performed in polling mode. The HAL 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 APIs return the HAL status. The end of the data processing will be indicated through the dedicated IRDA IRQ when using Interrupt mode or the DMA IRQ when using DMA mode. The HAL_IRDA_TxCpltCallback(), HAL_IRDA_RxCpltCallback() user callbacks will be executed respectively at the end of the transmit or Receive process The HAL_IRDA_ErrorCallback() user callback will be executed when a communication error is detected

2.Blocking mode API's are :

HAL_IRDA_Transmit()

HAL_IRDA_Receive()

3.Non Blocking mode APIs with Interrupt are :

HAL_IRDA_Transmit_IT()

HAL_IRDA_Receive_IT()

HAL_IRDA_IRQHandler()

4.Non Blocking mode functions with DMA are :

HAL_IRDA_Transmit_DMA()

HAL_IRDA_Receive_DMA()

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

HAL_IRDA_TxCpltCallback()

HAL_IRDA_RxCpltCallback()

HAL_IRDA_ErrorCallback()

This section contains the following APIs:

HAL_IRDA_Transmit()

DOCID025834 Rev 2

439/900

HAL IRDA Generic Driver

UM1725

HAL_IRDA_Receive()

HAL_IRDA_Transmit_IT()

HAL_IRDA_Receive_IT()

HAL_IRDA_Transmit_DMA()

HAL_IRDA_Receive_DMA()

HAL_IRDA_DMAPause()

HAL_IRDA_DMAResume()

HAL_IRDA_DMAStop()

HAL_IRDA_IRQHandler()

HAL_IRDA_TxCpltCallback()

HAL_IRDA_TxHalfCpltCallback()

HAL_IRDA_RxCpltCallback()

HAL_IRDA_RxHalfCpltCallback()

HAL_IRDA_ErrorCallback()

34.2.4Peripheral State and Errors functions

This subsection provides a set of functions allowing to return the State of IrDA communication process and also return Peripheral Errors occurred during communication process

HAL_IRDA_GetState() API can be helpful to check in run-time the state of the IrDA peripheral.

HAL_IRDA_GetError() check in run-time errors that could be occurred during communication.

This section contains the following APIs:

HAL_IRDA_GetState()

HAL_IRDA_GetError()

34.2.5HAL_IRDA_Init

Function Name

HAL_StatusTypeDef HAL_IRDA_Init (IRDA_HandleTypeDef *

 

hirda)

Function Description

Initializes the IRDA mode according to the specified parameters in

 

the IRDA_InitTypeDef and create the associated handle.

Parameters

 

hirda: pointer to a IRDA_HandleTypeDef structure that

 

 

contains the configuration information for the specified IRDA

 

 

module.

Return values

 

HAL status

34.2.6HAL_IRDA_DeInit

Function Name

HAL_StatusTypeDef HAL_IRDA_DeInit (IRDA_HandleTypeDef

 

* hirda)

Function Description

DeInitializes the IRDA peripheral.

Parameters

 

hirda: pointer to a IRDA_HandleTypeDef structure that

 

 

contains the configuration information for the specified IRDA

 

 

module.

Return values

 

HAL status

34.2.7HAL_IRDA_MspInit

440/900

DOCID025834 Rev 2

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