mbed library sources
Dependents: frdm_kl05z_gpio_test
Fork of mbed-src by
Diff: targets/cmsis/TARGET_STM/TARGET_NUCLEO_F401RE/stm32f4xx_hal_usart.c
- Revision:
- 226:b062af740e40
- Parent:
- 106:ced8cbb51063
--- a/targets/cmsis/TARGET_STM/TARGET_NUCLEO_F401RE/stm32f4xx_hal_usart.c Wed Jun 11 09:30:07 2014 +0100 +++ b/targets/cmsis/TARGET_STM/TARGET_NUCLEO_F401RE/stm32f4xx_hal_usart.c Wed Jun 11 09:45:09 2014 +0100 @@ -2,8 +2,8 @@ ****************************************************************************** * @file stm32f4xx_hal_usart.c * @author MCD Application Team - * @version V1.0.0 - * @date 18-February-2014 + * @version V1.1.0RC2 + * @date 14-May-2014 * @brief USART HAL module driver. * This file provides firmware functions to manage the following * functionalities of the Universal Synchronous Asynchronous Receiver Transmitter (USART) peripheral: @@ -18,7 +18,7 @@ The USART HAL driver can be used as follows: (#) Declare a USART_HandleTypeDef handle structure. - (#) Initialize the USART low level resources by implement the HAL_USART_MspInit ()API: + (#) Initialize the USART low level resources by implementing the HAL_USART_MspInit () API: (##) Enable the USARTx interface clock. (##) USART pins configuration: (+++) Enable the clock for the USART GPIOs. @@ -40,14 +40,14 @@ flow control and Mode(Receiver/Transmitter) in the husart Init structure. (#) Initialize the USART registers by calling the HAL_USART_Init() API: - (++) These API's configures also the low level Hardware GPIO, CLOCK, CORTEX...etc) + (++) These APIs configures also the low level Hardware GPIO, CLOCK, CORTEX...etc) by calling the customed HAL_USART_MspInit(&husart) API. -@@- The specific USART interrupts (Transmission complete interrupt, RXNE interrupt and Error Interrupts) will be managed using the macros __USART_ENABLE_IT() and __USART_DISABLE_IT() inside the transmit and receive process. - (#) Three mode of operations are available within this driver : + (#) Three operation modes are available within this driver : *** Polling mode IO operation *** ================================= @@ -97,10 +97,10 @@ (+) __HAL_USART_ENABLE: Enable the USART peripheral (+) __HAL_USART_DISABLE: Disable the USART peripheral - (+) __HAL_USART_GET_FLAG : Checks whether the specified USART flag is set or not - (+) __HAL_USART_CLEAR_FLAG : Clears the specified USART pending flag - (+) __HAL_USART_ENABLE_IT: Enables the specified USART interrupt - (+) __HAL_USART_DISABLE_IT: Disables the specified USART interrupt + (+) __HAL_USART_GET_FLAG : Check whether the specified USART flag is set or not + (+) __HAL_USART_CLEAR_FLAG : Clear the specified USART pending flag + (+) __HAL_USART_ENABLE_IT: Enable the specified USART interrupt + (+) __HAL_USART_DISABLE_IT: Disable the specified USART interrupt [..] (@) You can refer to the USART HAL driver header file for more useful macros @@ -150,7 +150,7 @@ #ifdef HAL_USART_MODULE_ENABLED /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ -#define DYMMY_DATA 0xFFFF +#define DUMMY_DATA 0xFFFF #define USART_TIMEOUT_VALUE 22000 /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ @@ -189,18 +189,7 @@ (++) 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), - the possible USART frame formats are as listed in the following table: - +-------------------------------------------------------------+ - | M bit | PCE bit | USART frame | - |---------------------|---------------------------------------| - | 0 | 0 | | SB | 8 bit data | STB | | - |---------|-----------|---------------------------------------| - | 0 | 1 | | SB | 7 bit data | PB | STB | | - |---------|-----------|---------------------------------------| - | 1 | 0 | | SB | 9 bit data | STB | | - |---------|-----------|---------------------------------------| - | 1 | 1 | | SB | 8 bit data | PB | STB | | - +-------------------------------------------------------------+ + please refer to Reference manual for possible USART frame formats. (++) USART polarity (++) USART phase (++) USART LastBit @@ -217,7 +206,8 @@ /** * @brief Initializes the USART mode according to the specified * parameters in the USART_InitTypeDef and create the associated handle. - * @param husart: USART handle + * @param husart: pointer to a USART_HandleTypeDef structure that contains + * the configuration information for the specified USART module. * @retval HAL status */ HAL_StatusTypeDef HAL_USART_Init(USART_HandleTypeDef *husart) @@ -260,7 +250,8 @@ /** * @brief DeInitializes the USART peripheral. - * @param husart: USART handle + * @param husart: pointer to a USART_HandleTypeDef structure that contains + * the configuration information for the specified USART module. * @retval HAL status */ HAL_StatusTypeDef HAL_USART_DeInit(USART_HandleTypeDef *husart) @@ -290,7 +281,8 @@ /** * @brief USART MSP Init. - * @param husart: USART handle + * @param husart: pointer to a USART_HandleTypeDef structure that contains + * the configuration information for the specified USART module. * @retval None */ __weak void HAL_USART_MspInit(USART_HandleTypeDef *husart) @@ -302,7 +294,8 @@ /** * @brief USART MSP DeInit. - * @param husart: USART handle + * @param husart: pointer to a USART_HandleTypeDef structure that contains + * the configuration information for the specified USART module. * @retval None */ __weak void HAL_USART_MspDeInit(USART_HandleTypeDef *husart) @@ -331,7 +324,7 @@ The USART supports master mode only: it cannot receive or send data related to an input clock (SCLK is always an output). - (#) There are two mode of transfer: + (#) 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. @@ -341,28 +334,28 @@ dedicated USART IRQ when using Interrupt mode or the DMA IRQ when using DMA mode. The HAL_USART_TxCpltCallback(), HAL_USART_RxCpltCallback() and HAL_USART_TxRxCpltCallback() - user callbacks + user callbacks will be executed respectivelly at the end of the transmit or Receive process - The HAL_USART_ErrorCallback()user callback will be executed when a communication + The HAL_USART_ErrorCallback() user callback will be executed when a communication error is detected - (#) Blocking mode API's are : - (++) HAL_USART_Transmit()in simplex mode + (#) Blocking mode APIs are : + (++) HAL_USART_Transmit() in simplex mode (++) HAL_USART_Receive() in full duplex receive only (++) HAL_USART_TransmitReceive() in full duplex mode - (#) Non-Blocking mode API's with Interrupt are : + (#) Non Blocking mode APIs with Interrupt are : (++) HAL_USART_Transmit_IT()in simplex mode (++) HAL_USART_Receive_IT() in full duplex receive only - (++) HAL_USART_TransmitReceive_IT()in full duplex mode + (++) HAL_USART_TransmitReceive_IT() in full duplex mode (++) HAL_USART_IRQHandler() - (#) No-Blocking mode functions with DMA are : + (#) Non Blocking mode functions with DMA are : (++) HAL_USART_Transmit_DMA()in simplex mode (++) HAL_USART_Receive_DMA() in full duplex receive only (++) HAL_USART_TransmitReceie_DMA() in full duplex mode - (#) A set of Transfer Complete Callbacks are provided in No_Blocking mode: + (#) A set of Transfer Complete Callbacks are provided in non Blocking mode: (++) HAL_USART_TxCpltCallback() (++) HAL_USART_RxCpltCallback() (++) HAL_USART_ErrorCallback() @@ -374,9 +367,11 @@ /** * @brief Simplex Send an amount of data in blocking mode. - * @param husart: USART handle + * @param husart: pointer to a USART_HandleTypeDef structure that contains + * the configuration information for the specified USART module. * @param pTxData: Pointer to data buffer * @param Size: Amount of data to be sent + * @param Timeout: Timeout duration * @retval HAL status */ HAL_StatusTypeDef HAL_USART_Transmit(USART_HandleTypeDef *husart, uint8_t *pTxData, uint16_t Size, uint32_t Timeout) @@ -449,9 +444,11 @@ /** * @brief Full-Duplex Receive an amount of data in blocking mode. - * @param husart: USART handle + * @param husart: pointer to a USART_HandleTypeDef structure that contains + * the configuration information for the specified USART module. * @param pRxData: Pointer to data buffer * @param Size: Amount of data to be received + * @param Timeout: Timeout duration * @retval HAL status */ HAL_StatusTypeDef HAL_USART_Receive(USART_HandleTypeDef *husart, uint8_t *pRxData, uint16_t Size, uint32_t Timeout) @@ -484,7 +481,7 @@ return HAL_TIMEOUT; } /* Send dummy byte in order to generate clock */ - husart->Instance->DR = (DYMMY_DATA & (uint16_t)0x01FF); + husart->Instance->DR = (DUMMY_DATA & (uint16_t)0x01FF); /* Wait for RXNE Flag */ if(USART_WaitOnFlagUntilTimeout(husart, USART_FLAG_RXNE, RESET, Timeout) != HAL_OK) @@ -512,7 +509,7 @@ } /* Send Dummy Byte in order to generate clock */ - husart->Instance->DR = (DYMMY_DATA & (uint16_t)0x00FF); + husart->Instance->DR = (DUMMY_DATA & (uint16_t)0x00FF); /* Wait until RXNE flag is set to receive the byte */ if(USART_WaitOnFlagUntilTimeout(husart, USART_FLAG_RXNE, RESET, Timeout) != HAL_OK) @@ -548,9 +545,12 @@ /** * @brief Full-Duplex Send receive an amount of data in full-duplex mode (blocking mode). - * @param husart: USART handle - * @param pTxData: Pointer to data buffer + * @param husart: pointer to a USART_HandleTypeDef structure that contains + * the configuration information for the specified USART module. + * @param pTxData: Pointer to data transmitted buffer + * @param pRxData: Pointer to data received buffer * @param Size: Amount of data to be sent + * @param Timeout: Timeout duration * @retval HAL status */ HAL_StatusTypeDef HAL_USART_TransmitReceive(USART_HandleTypeDef *husart, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size, uint32_t Timeout) @@ -656,7 +656,8 @@ /** * @brief Simplex Send an amount of data in non-blocking mode. - * @param husart: USART handle + * @param husart: pointer to a USART_HandleTypeDef structure that contains + * the configuration information for the specified USART module. * @param pTxData: Pointer to data buffer * @param Size: Amount of data to be sent * @retval HAL status @@ -705,7 +706,8 @@ /** * @brief Simplex Receive an amount of data in non-blocking mode. - * @param husart: USART handle + * @param husart: pointer to a USART_HandleTypeDef structure that contains + * the configuration information for the specified USART module. * @param pRxData: Pointer to data buffer * @param Size: Amount of data to be received * @retval HAL status @@ -741,7 +743,7 @@ __HAL_UNLOCK(husart); /* Send dummy byte in order to generate the clock for the slave to send data */ - husart->Instance->DR = (DYMMY_DATA & (uint16_t)0x01FF); + husart->Instance->DR = (DUMMY_DATA & (uint16_t)0x01FF); return HAL_OK; } @@ -753,8 +755,10 @@ /** * @brief Full-Duplex Send receive an amount of data in full-duplex mode (non-blocking). - * @param husart: USART handle - * @param pTxData: Pointer to data buffer + * @param husart: pointer to a USART_HandleTypeDef structure that contains + * the configuration information for the specified USART module. + * @param pTxData: Pointer to data transmitted buffer + * @param pRxData: Pointer to data received buffer * @param Size: Amount of data to be received * @retval HAL status */ @@ -804,8 +808,9 @@ /** * @brief Simplex Send an amount of data in non-blocking mode. - * @param husart: USART handle - * @param pData: Pointer to data buffer + * @param husart: pointer to a USART_HandleTypeDef structure that contains + * the configuration information for the specified USART module. + * @param pTxData: Pointer to data buffer * @param Size: Amount of data to be sent * @retval HAL status */ @@ -859,7 +864,8 @@ /** * @brief Full-Duplex Receive an amount of data in non-blocking mode. - * @param husart: USART handle + * @param husart: pointer to a USART_HandleTypeDef structure that contains + * the configuration information for the specified USART module. * @param pRxData: Pointer to data buffer * @param Size: Amount of data to be received * @retval HAL status @@ -927,8 +933,10 @@ /** * @brief Full-Duplex Transmit Receive an amount of data in non-blocking mode. - * @param husart: USART handle - * @param pRxData: Pointer to data buffer + * @param husart: pointer to a USART_HandleTypeDef structure that contains + * the configuration information for the specified USART module. + * @param pTxData: Pointer to data transmitted buffer + * @param pRxData: Pointer to data received buffer * @param Size: Amount of data to be received * @note When the USART parity is enabled (PCE = 1) the data received contain the parity bit. * @retval HAL status @@ -1001,8 +1009,9 @@ /** * @brief Pauses the DMA Transfer. - * @param husart: USART handle - * @retval None + * @param husart: pointer to a USART_HandleTypeDef structure that contains + * the configuration information for the specified USART module. + * @retval HAL status */ HAL_StatusTypeDef HAL_USART_DMAPause(USART_HandleTypeDef *husart) { @@ -1035,8 +1044,9 @@ /** * @brief Resumes the DMA Transfer. - * @param husart: USART handle - * @retval None + * @param husart: pointer to a USART_HandleTypeDef structure that contains + * the configuration information for the specified USART module. + * @retval HAL status */ HAL_StatusTypeDef HAL_USART_DMAResume(USART_HandleTypeDef *husart) { @@ -1076,8 +1086,9 @@ /** * @brief Stops the DMA Transfer. - * @param husart: USART handle - * @retval None + * @param husart: pointer to a USART_HandleTypeDef structure that contains + * the configuration information for the specified USART module. + * @retval HAL status */ HAL_StatusTypeDef HAL_USART_DMAStop(USART_HandleTypeDef *husart) { @@ -1111,7 +1122,8 @@ /** * @brief This function handles USART interrupt request. - * @param husart: USART handle + * @param husart: pointer to a USART_HandleTypeDef structure that contains + * the configuration information for the specified USART module. * @retval None */ void HAL_USART_IRQHandler(USART_HandleTypeDef *husart) @@ -1195,7 +1207,8 @@ /** * @brief Tx Transfer completed callbacks. - * @param husart: USART handle + * @param husart: pointer to a USART_HandleTypeDef structure that contains + * the configuration information for the specified USART module. * @retval None */ __weak void HAL_USART_TxCpltCallback(USART_HandleTypeDef *husart) @@ -1207,7 +1220,8 @@ /** * @brief Tx Half Transfer completed callbacks. - * @param husart: USART handle + * @param husart: pointer to a USART_HandleTypeDef structure that contains + * the configuration information for the specified USART module. * @retval None */ __weak void HAL_USART_TxHalfCpltCallback(USART_HandleTypeDef *husart) @@ -1219,7 +1233,8 @@ /** * @brief Rx Transfer completed callbacks. - * @param husart: USART handle + * @param husart: pointer to a USART_HandleTypeDef structure that contains + * the configuration information for the specified USART module. * @retval None */ __weak void HAL_USART_RxCpltCallback(USART_HandleTypeDef *husart) @@ -1231,7 +1246,8 @@ /** * @brief Rx Half Transfer completed callbacks. - * @param husart: USART handle + * @param husart: pointer to a USART_HandleTypeDef structure that contains + * the configuration information for the specified USART module. * @retval None */ __weak void HAL_USART_RxHalfCpltCallback(USART_HandleTypeDef *husart) @@ -1243,7 +1259,8 @@ /** * @brief Tx/Rx Transfers completed callback for the non-blocking process. - * @param husart: USART handle + * @param husart: pointer to a USART_HandleTypeDef structure that contains + * the configuration information for the specified USART module. * @retval None */ __weak void HAL_USART_TxRxCpltCallback(USART_HandleTypeDef *husart) @@ -1255,7 +1272,8 @@ /** * @brief USART error callbacks. - * @param husart: USART handle + * @param husart: pointer to a USART_HandleTypeDef structure that contains + * the configuration information for the specified USART module. * @retval None */ __weak void HAL_USART_ErrorCallback(USART_HandleTypeDef *husart) @@ -1279,10 +1297,10 @@ [..] This subsection provides a set of functions allowing to return the State of USART communication - process, return Peripheral Errors occured during communication process + process, return Peripheral Errors occurred during communication process (+) HAL_USART_GetState() API can be helpful to check in run-time the state of the USART peripheral. - (+) HAL_USART_GetError() check in run-time errors that could be occured durung + (+) HAL_USART_GetError() check in run-time errors that could be occurred during communication. @endverbatim * @{ @@ -1290,7 +1308,8 @@ /** * @brief Returns the USART state. - * @param husart: USART handle + * @param husart: pointer to a USART_HandleTypeDef structure that contains + * the configuration information for the specified USART module. * @retval HAL state */ HAL_USART_StateTypeDef HAL_USART_GetState(USART_HandleTypeDef *husart) @@ -1329,7 +1348,7 @@ /* Wait for USART TC Flag */ if(USART_WaitOnFlagUntilTimeout(husart, USART_FLAG_TC, RESET, USART_TIMEOUT_VALUE) != HAL_OK) { - /* Timeout Occured */ + /* Timeout occurred */ husart->State = HAL_USART_STATE_TIMEOUT; HAL_USART_ErrorCallback(husart); } @@ -1352,7 +1371,8 @@ /** * @brief DMA USART transmit process half complete callback - * @param hdma : DMA handle + * @param hdma: pointer to a DMA_HandleTypeDef structure that contains + * the configuration information for the specified DMA module. * @retval None */ static void USART_DMATxHalfCplt(DMA_HandleTypeDef *hdma) @@ -1385,7 +1405,8 @@ /** * @brief DMA USART receive process half complete callback - * @param hdma : DMA handle + * @param hdma: pointer to a DMA_HandleTypeDef structure that contains + * the configuration information for the specified DMA module. * @retval None */ static void USART_DMARxHalfCplt(DMA_HandleTypeDef *hdma) @@ -1414,7 +1435,8 @@ /** * @brief This function handles USART Communication Timeout. - * @param husart: USART handle + * @param husart: pointer to a USART_HandleTypeDef structure that contains + * the configuration information for the specified USART module. * @param Flag: specifies the USART flag to check. * @param Status: The new Flag status (SET or RESET). * @param Timeout: Timeout duration @@ -1483,7 +1505,8 @@ /** * @brief Simplex Send an amount of data in non-blocking mode. - * @param husart: USART handle + * @param husart: pointer to a USART_HandleTypeDef structure that contains + * the configuration information for the specified USART module. * @retval HAL status * @note The USART errors are not managed to avoid the overrun error. */ @@ -1493,9 +1516,6 @@ if(husart->State == HAL_USART_STATE_BUSY_TX) { - /* Process Locked */ - __HAL_LOCK(husart); - if(husart->Init.WordLength == USART_WORDLENGTH_9B) { tmp = (uint16_t*) husart->pTxBuffPtr; @@ -1524,18 +1544,10 @@ husart->State = HAL_USART_STATE_READY; - /* Call the Process Unlocked before calling the Tx callback API to give the possibility to - start again the Transmission under the Tx callback API */ - __HAL_UNLOCK(husart); - HAL_USART_TxCpltCallback(husart); return HAL_OK; } - - /* Process Unlocked */ - __HAL_UNLOCK(husart); - return HAL_OK; } else @@ -1546,7 +1558,8 @@ /** * @brief Simplex Receive an amount of data in non-blocking mode. - * @param husart: USART handle + * @param husart: pointer to a USART_HandleTypeDef structure that contains + * the configuration information for the specified USART module. * @retval HAL status */ static HAL_StatusTypeDef USART_Receive_IT(USART_HandleTypeDef *husart) @@ -1554,9 +1567,6 @@ uint16_t* tmp; if(husart->State == HAL_USART_STATE_BUSY_RX) { - /* Process Locked */ - __HAL_LOCK(husart); - if(husart->Init.WordLength == USART_WORDLENGTH_9B) { tmp = (uint16_t*) husart->pRxBuffPtr; @@ -1573,7 +1583,7 @@ if(--husart->RxXferCount != 0x00) { /* Send dummy byte in order to generate the clock for the slave to send the next data */ - husart->Instance->DR = (DYMMY_DATA & (uint16_t)0x01FF); + husart->Instance->DR = (DUMMY_DATA & (uint16_t)0x01FF); } } else @@ -1590,7 +1600,7 @@ if(--husart->RxXferCount != 0x00) { /* Send dummy byte in order to generate the clock for the slave to send the next data */ - husart->Instance->DR = (DYMMY_DATA & (uint16_t)0x00FF); + husart->Instance->DR = (DUMMY_DATA & (uint16_t)0x00FF); } } @@ -1606,18 +1616,10 @@ __USART_DISABLE_IT(husart, USART_IT_ERR); husart->State = HAL_USART_STATE_READY; - /* Call the Process Unlocked before calling the Rx callback API to give the possibility to - start again the reception under the Rx callback API */ - __HAL_UNLOCK(husart); - HAL_USART_RxCpltCallback(husart); return HAL_OK; } - - /* Process Unlocked */ - __HAL_UNLOCK(husart); - return HAL_OK; } else @@ -1628,7 +1630,8 @@ /** * @brief Full-Duplex Send receive an amount of data in full-duplex mode (non-blocking). - * @param husart: USART handle + * @param husart: pointer to a USART_HandleTypeDef structure that contains + * the configuration information for the specified USART module. * @retval HAL status */ static HAL_StatusTypeDef USART_TransmitReceive_IT(USART_HandleTypeDef *husart) @@ -1738,7 +1741,8 @@ /** * @brief Configures the USART peripheral. - * @param husart: USART handle + * @param husart: pointer to a USART_HandleTypeDef structure that contains + * the configuration information for the specified USART module. * @retval None */ static void USART_SetConfig(USART_HandleTypeDef *husart)