Subversion Repositories DashDisplay

Rev

Rev 50 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 50 Rev 61
Line 19... Line 19...
19
    (#) Declare a UART_HandleTypeDef handle structure (eg. UART_HandleTypeDef huart).
19
    (#) Declare a UART_HandleTypeDef handle structure (eg. UART_HandleTypeDef huart).
20
    (#) Initialize the UART low level resources by implementing the HAL_UART_MspInit() API:
20
    (#) Initialize the UART low level resources by implementing the HAL_UART_MspInit() API:
21
        (##) Enable the USARTx interface clock.
21
        (##) Enable the USARTx interface clock.
22
        (##) UART pins configuration:
22
        (##) UART pins configuration:
23
            (+++) Enable the clock for the UART GPIOs.
23
            (+++) Enable the clock for the UART GPIOs.
24
            (+++) Configure these UART pins (TX as alternate function pull-up, RX as alternate function Input).
24
            (+++) Configure the UART TX/RX pins as alternate function pull-up.
25
        (##) NVIC configuration if you need to use interrupt process (HAL_UART_Transmit_IT()
25
        (##) NVIC configuration if you need to use interrupt process (HAL_UART_Transmit_IT()
26
             and HAL_UART_Receive_IT() APIs):
26
             and HAL_UART_Receive_IT() APIs):
27
            (+++) Configure the USARTx interrupt priority.
27
            (+++) Configure the USARTx interrupt priority.
28
            (+++) Enable the NVIC USART IRQ handle.
28
            (+++) Enable the NVIC USART IRQ handle.
29
        (##) DMA Configuration if you need to use DMA process (HAL_UART_Transmit_DMA()
29
        (##) DMA Configuration if you need to use DMA process (HAL_UART_Transmit_DMA()
Line 103... Line 103...
103
    (+) AbortReceiveCpltCallback  : Abort Receive Complete Callback.
103
    (+) AbortReceiveCpltCallback  : Abort Receive Complete Callback.
104
    (+) MspInitCallback           : UART MspInit.
104
    (+) MspInitCallback           : UART MspInit.
105
    (+) MspDeInitCallback         : UART MspDeInit.
105
    (+) MspDeInitCallback         : UART MspDeInit.
106
 
106
 
107
    [..]
107
    [..]
-
 
108
    For specific callback RxEventCallback, use dedicated registration/reset functions:
-
 
109
    respectively @ref HAL_UART_RegisterRxEventCallback() , @ref HAL_UART_UnRegisterRxEventCallback().
-
 
110
 
-
 
111
    [..]
108
    By default, after the @ref HAL_UART_Init() and when the state is HAL_UART_STATE_RESET
112
    By default, after the @ref HAL_UART_Init() and when the state is HAL_UART_STATE_RESET
109
    all callbacks are set to the corresponding weak (surcharged) functions:
113
    all callbacks are set to the corresponding weak (surcharged) functions:
110
    examples @ref HAL_UART_TxCpltCallback(), @ref HAL_UART_RxHalfCpltCallback().
114
    examples @ref HAL_UART_TxCpltCallback(), @ref HAL_UART_RxHalfCpltCallback().
111
    Exception done for MspInit and MspDeInit functions that are respectively
115
    Exception done for MspInit and MspDeInit functions that are respectively
112
    reset to the legacy weak (surcharged) functions in the @ref HAL_UART_Init()
116
    reset to the legacy weak (surcharged) functions in the @ref HAL_UART_Init()
Line 166... Line 170...
166
            add his own code by customization of function pointer HAL_UART_ErrorCallback
170
            add his own code by customization of function pointer HAL_UART_ErrorCallback
167
       (+) Pause the DMA Transfer using HAL_UART_DMAPause()
171
       (+) Pause the DMA Transfer using HAL_UART_DMAPause()
168
       (+) Resume the DMA Transfer using HAL_UART_DMAResume()
172
       (+) Resume the DMA Transfer using HAL_UART_DMAResume()
169
       (+) Stop the DMA Transfer using HAL_UART_DMAStop()
173
       (+) Stop the DMA Transfer using HAL_UART_DMAStop()
170
 
174
 
-
 
175
 
-
 
176
    [..] This subsection also provides a set of additional functions providing enhanced reception
-
 
177
    services to user. (For example, these functions allow application to handle use cases
-
 
178
    where number of data to be received is unknown).
-
 
179
 
-
 
180
    (#) Compared to standard reception services which only consider number of received
-
 
181
        data elements as reception completion criteria, these functions also consider additional events
-
 
182
        as triggers for updating reception status to caller :
-
 
183
       (+) Detection of inactivity period (RX line has not been active for a given period).
-
 
184
          (++) RX inactivity detected by IDLE event, i.e. RX line has been in idle state (normally high state)
-
 
185
               for 1 frame time, after last received byte.
-
 
186
 
-
 
187
    (#) There are two mode of transfer:
-
 
188
       (+) Blocking mode: The reception is performed in polling mode, until either expected number of data is received,
-
 
189
           or till IDLE event occurs. Reception is handled only during function execution.
-
 
190
           When function exits, no data reception could occur. HAL status and number of actually received data elements,
-
 
191
           are returned by function after finishing transfer.
-
 
192
       (+) Non-Blocking mode: The reception is performed using Interrupts or DMA.
-
 
193
           These API's return the HAL status.
-
 
194
           The end of the data processing will be indicated through the
-
 
195
           dedicated UART IRQ when using Interrupt mode or the DMA IRQ when using DMA mode.
-
 
196
           The HAL_UARTEx_RxEventCallback() user callback will be executed during Receive process
-
 
197
           The HAL_UART_ErrorCallback()user callback will be executed when a reception error is detected.
-
 
198
 
-
 
199
    (#) Blocking mode API:
-
 
200
        (+) HAL_UARTEx_ReceiveToIdle()
-
 
201
 
-
 
202
    (#) Non-Blocking mode API with Interrupt:
-
 
203
        (+) HAL_UARTEx_ReceiveToIdle_IT()
-
 
204
 
-
 
205
    (#) Non-Blocking mode API with DMA:
-
 
206
        (+) HAL_UARTEx_ReceiveToIdle_DMA()
-
 
207
 
-
 
208
 
171
     *** UART HAL driver macros list ***
209
     *** UART HAL driver macros list ***
172
     =============================================
210
     =============================================
173
     [..]
211
     [..]
174
       Below the list of most used macros in UART HAL driver.
212
       Below the list of most used macros in UART HAL driver.
175
 
213
 
Line 184... Line 222...
184
     [..]
222
     [..]
185
       (@) You can refer to the UART HAL driver header file for more useful macros
223
       (@) You can refer to the UART HAL driver header file for more useful macros
186
 
224
 
187
  @endverbatim
225
  @endverbatim
188
     [..]
226
     [..]
189
       (@) Additionnal remark: If the parity is enabled, then the MSB bit of the data written
227
       (@) Additional remark: If the parity is enabled, then the MSB bit of the data written
190
           in the data register is transmitted but is changed by the parity bit.
228
           in the data register is transmitted but is changed by the parity bit.
191
           Depending on the frame length defined by the M bit (8-bits or 9-bits),
229
           Depending on the frame length defined by the M bit (8-bits or 9-bits),
192
           the possible UART frame formats are as listed in the following table:
230
           the possible UART frame formats are as listed in the following table:
193
    +-------------------------------------------------------------+
231
    +-------------------------------------------------------------+
194
    |   M bit |  PCE bit  |            UART frame                 |
232
    |   M bit |  PCE bit  |            UART frame                 |
Line 645... Line 683...
645
#endif /* (USE_HAL_UART_REGISTER_CALLBACKS) */
683
#endif /* (USE_HAL_UART_REGISTER_CALLBACKS) */
646
 
684
 
647
  huart->ErrorCode = HAL_UART_ERROR_NONE;
685
  huart->ErrorCode = HAL_UART_ERROR_NONE;
648
  huart->gState = HAL_UART_STATE_RESET;
686
  huart->gState = HAL_UART_STATE_RESET;
649
  huart->RxState = HAL_UART_STATE_RESET;
687
  huart->RxState = HAL_UART_STATE_RESET;
-
 
688
  huart->ReceptionType = HAL_UART_RECEPTION_STANDARD;
650
 
689
 
651
  /* Process Unlock */
690
  /* Process Unlock */
652
  __HAL_UNLOCK(huart);
691
  __HAL_UNLOCK(huart);
653
 
692
 
654
  return HAL_OK;
693
  return HAL_OK;
Line 918... Line 957...
918
  /* Release Lock */
957
  /* Release Lock */
919
  __HAL_UNLOCK(huart);
958
  __HAL_UNLOCK(huart);
920
 
959
 
921
  return status;
960
  return status;
922
}
961
}
-
 
962
 
-
 
963
/**
-
 
964
  * @brief  Register a User UART Rx Event Callback
-
 
965
  *         To be used instead of the weak predefined callback
-
 
966
  * @param  huart     Uart handle
-
 
967
  * @param  pCallback Pointer to the Rx Event Callback function
-
 
968
  * @retval HAL status
-
 
969
  */
-
 
970
HAL_StatusTypeDef HAL_UART_RegisterRxEventCallback(UART_HandleTypeDef *huart, pUART_RxEventCallbackTypeDef pCallback)
-
 
971
{
-
 
972
  HAL_StatusTypeDef status = HAL_OK;
-
 
973
 
-
 
974
  if (pCallback == NULL)
-
 
975
  {
-
 
976
    huart->ErrorCode |= HAL_UART_ERROR_INVALID_CALLBACK;
-
 
977
 
-
 
978
    return HAL_ERROR;
-
 
979
  }
-
 
980
 
-
 
981
  /* Process locked */
-
 
982
  __HAL_LOCK(huart);
-
 
983
 
-
 
984
  if (huart->gState == HAL_UART_STATE_READY)
-
 
985
  {
-
 
986
    huart->RxEventCallback = pCallback;
-
 
987
  }
-
 
988
  else
-
 
989
  {
-
 
990
    huart->ErrorCode |= HAL_UART_ERROR_INVALID_CALLBACK;
-
 
991
 
-
 
992
    status =  HAL_ERROR;
-
 
993
  }
-
 
994
 
-
 
995
  /* Release Lock */
-
 
996
  __HAL_UNLOCK(huart);
-
 
997
 
-
 
998
  return status;
-
 
999
}
-
 
1000
 
-
 
1001
/**
-
 
1002
  * @brief  UnRegister the UART Rx Event Callback
-
 
1003
  *         UART Rx Event Callback is redirected to the weak HAL_UARTEx_RxEventCallback() predefined callback
-
 
1004
  * @param  huart     Uart handle
-
 
1005
  * @retval HAL status
-
 
1006
  */
-
 
1007
HAL_StatusTypeDef HAL_UART_UnRegisterRxEventCallback(UART_HandleTypeDef *huart)
-
 
1008
{
-
 
1009
  HAL_StatusTypeDef status = HAL_OK;
-
 
1010
 
-
 
1011
  /* Process locked */
-
 
1012
  __HAL_LOCK(huart);
-
 
1013
 
-
 
1014
  if (huart->gState == HAL_UART_STATE_READY)
-
 
1015
  {
-
 
1016
    huart->RxEventCallback = HAL_UARTEx_RxEventCallback; /* Legacy weak UART Rx Event Callback  */
-
 
1017
  }
-
 
1018
  else
-
 
1019
  {
-
 
1020
    huart->ErrorCode |= HAL_UART_ERROR_INVALID_CALLBACK;
-
 
1021
 
-
 
1022
    status =  HAL_ERROR;
-
 
1023
  }
-
 
1024
 
-
 
1025
  /* Release Lock */
-
 
1026
  __HAL_UNLOCK(huart);
-
 
1027
  return status;
-
 
1028
}
923
#endif /* USE_HAL_UART_REGISTER_CALLBACKS */
1029
#endif /* USE_HAL_UART_REGISTER_CALLBACKS */
924
 
1030
 
925
/**
1031
/**
926
  * @}
1032
  * @}
927
  */
1033
  */
Line 983... Line 1089...
983
    (#) For Abort services based on interrupts (HAL_UART_Abortxxx_IT), a set of Abort Complete Callbacks are provided:
1089
    (#) For Abort services based on interrupts (HAL_UART_Abortxxx_IT), a set of Abort Complete Callbacks are provided:
984
        (+) HAL_UART_AbortCpltCallback()
1090
        (+) HAL_UART_AbortCpltCallback()
985
        (+) HAL_UART_AbortTransmitCpltCallback()
1091
        (+) HAL_UART_AbortTransmitCpltCallback()
986
        (+) HAL_UART_AbortReceiveCpltCallback()
1092
        (+) HAL_UART_AbortReceiveCpltCallback()
987
 
1093
 
-
 
1094
    (#) A Rx Event Reception Callback (Rx event notification) is available for Non_Blocking modes of enhanced reception services:
-
 
1095
        (+) HAL_UARTEx_RxEventCallback()
-
 
1096
 
988
    (#) In Non-Blocking mode transfers, possible errors are split into 2 categories.
1097
    (#) In Non-Blocking mode transfers, possible errors are split into 2 categories.
989
        Errors are handled as follows :
1098
        Errors are handled as follows :
990
       (+) Error is considered as Recoverable and non blocking : Transfer could go till end, but error severity is
1099
       (+) Error is considered as Recoverable and non blocking : Transfer could go till end, but error severity is
991
           to be evaluated by user : this concerns Frame Error, Parity Error or Noise Error in Interrupt mode reception .
1100
           to be evaluated by user : this concerns Frame Error, Parity Error or Noise Error in Interrupt mode reception .
992
           Received character is then retrieved and stored in Rx buffer, Error code is set to allow user to identify error type,
1101
           Received character is then retrieved and stored in Rx buffer, Error code is set to allow user to identify error type,
Line 1015... Line 1124...
1015
  * @param  Timeout Timeout duration
1124
  * @param  Timeout Timeout duration
1016
  * @retval HAL status
1125
  * @retval HAL status
1017
  */
1126
  */
1018
HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout)
1127
HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout)
1019
{
1128
{
-
 
1129
  uint8_t  *pdata8bits;
1020
  uint16_t *tmp;
1130
  uint16_t *pdata16bits;
1021
  uint32_t tickstart = 0U;
1131
  uint32_t tickstart = 0U;
1022
 
1132
 
1023
  /* Check that a Tx process is not already ongoing */
1133
  /* Check that a Tx process is not already ongoing */
1024
  if (huart->gState == HAL_UART_STATE_READY)
1134
  if (huart->gState == HAL_UART_STATE_READY)
1025
  {
1135
  {
Line 1032... Line 1142...
1032
    __HAL_LOCK(huart);
1142
    __HAL_LOCK(huart);
1033
 
1143
 
1034
    huart->ErrorCode = HAL_UART_ERROR_NONE;
1144
    huart->ErrorCode = HAL_UART_ERROR_NONE;
1035
    huart->gState = HAL_UART_STATE_BUSY_TX;
1145
    huart->gState = HAL_UART_STATE_BUSY_TX;
1036
 
1146
 
1037
    /* Init tickstart for timeout managment */
1147
    /* Init tickstart for timeout management */
1038
    tickstart = HAL_GetTick();
1148
    tickstart = HAL_GetTick();
1039
 
1149
 
1040
    huart->TxXferSize = Size;
1150
    huart->TxXferSize = Size;
1041
    huart->TxXferCount = Size;
1151
    huart->TxXferCount = Size;
1042
 
1152
 
-
 
1153
    /* In case of 9bits/No Parity transfer, pData needs to be handled as a uint16_t pointer */
-
 
1154
    if ((huart->Init.WordLength == UART_WORDLENGTH_9B) && (huart->Init.Parity == UART_PARITY_NONE))
-
 
1155
    {
-
 
1156
      pdata8bits  = NULL;
-
 
1157
      pdata16bits = (uint16_t *) pData;
-
 
1158
    }
-
 
1159
    else
-
 
1160
    {
-
 
1161
      pdata8bits  = pData;
-
 
1162
      pdata16bits = NULL;
-
 
1163
    }
-
 
1164
 
1043
    /* Process Unlocked */
1165
    /* Process Unlocked */
1044
    __HAL_UNLOCK(huart);
1166
    __HAL_UNLOCK(huart);
1045
 
1167
 
1046
    while (huart->TxXferCount > 0U)
1168
    while (huart->TxXferCount > 0U)
1047
    {
1169
    {
1048
      huart->TxXferCount--;
-
 
1049
      if (huart->Init.WordLength == UART_WORDLENGTH_9B)
1170
      if (UART_WaitOnFlagUntilTimeout(huart, UART_FLAG_TXE, RESET, tickstart, Timeout) != HAL_OK)
1050
      {
1171
      {
1051
        if (UART_WaitOnFlagUntilTimeout(huart, UART_FLAG_TXE, RESET, tickstart, Timeout) != HAL_OK)
-
 
1052
        {
-
 
1053
          return HAL_TIMEOUT;
1172
        return HAL_TIMEOUT;
1054
        }
1173
      }
1055
        tmp = (uint16_t *) pData;
1174
      if (pdata8bits == NULL)
1056
        huart->Instance->DR = (*tmp & (uint16_t)0x01FF);
-
 
1057
        if (huart->Init.Parity == UART_PARITY_NONE)
-
 
1058
        {
1175
      {
1059
          pData += 2U;
1176
        huart->Instance->DR = (uint16_t)(*pdata16bits & 0x01FFU);
1060
        }
-
 
1061
        else
-
 
1062
        {
-
 
1063
          pData += 1U;
1177
        pdata16bits++;
1064
        }
-
 
1065
      }
1178
      }
1066
      else
1179
      else
1067
      {
1180
      {
1068
        if (UART_WaitOnFlagUntilTimeout(huart, UART_FLAG_TXE, RESET, tickstart, Timeout) != HAL_OK)
1181
        huart->Instance->DR = (uint8_t)(*pdata8bits & 0xFFU);
1069
        {
-
 
1070
          return HAL_TIMEOUT;
1182
        pdata8bits++;
1071
        }
-
 
1072
        huart->Instance->DR = (*pData++ & (uint8_t)0xFF);
-
 
1073
      }
1183
      }
-
 
1184
      huart->TxXferCount--;
1074
    }
1185
    }
1075
 
1186
 
1076
    if (UART_WaitOnFlagUntilTimeout(huart, UART_FLAG_TC, RESET, tickstart, Timeout) != HAL_OK)
1187
    if (UART_WaitOnFlagUntilTimeout(huart, UART_FLAG_TC, RESET, tickstart, Timeout) != HAL_OK)
1077
    {
1188
    {
1078
      return HAL_TIMEOUT;
1189
      return HAL_TIMEOUT;
Line 1101... Line 1212...
1101
  * @param  Timeout Timeout duration
1212
  * @param  Timeout Timeout duration
1102
  * @retval HAL status
1213
  * @retval HAL status
1103
  */
1214
  */
1104
HAL_StatusTypeDef HAL_UART_Receive(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout)
1215
HAL_StatusTypeDef HAL_UART_Receive(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout)
1105
{
1216
{
-
 
1217
  uint8_t  *pdata8bits;
1106
  uint16_t *tmp;
1218
  uint16_t *pdata16bits;
1107
  uint32_t tickstart = 0U;
1219
  uint32_t tickstart = 0U;
1108
 
1220
 
1109
  /* Check that a Rx process is not already ongoing */
1221
  /* Check that a Rx process is not already ongoing */
1110
  if (huart->RxState == HAL_UART_STATE_READY)
1222
  if (huart->RxState == HAL_UART_STATE_READY)
1111
  {
1223
  {
Line 1117... Line 1229...
1117
    /* Process Locked */
1229
    /* Process Locked */
1118
    __HAL_LOCK(huart);
1230
    __HAL_LOCK(huart);
1119
 
1231
 
1120
    huart->ErrorCode = HAL_UART_ERROR_NONE;
1232
    huart->ErrorCode = HAL_UART_ERROR_NONE;
1121
    huart->RxState = HAL_UART_STATE_BUSY_RX;
1233
    huart->RxState = HAL_UART_STATE_BUSY_RX;
-
 
1234
    huart->ReceptionType = HAL_UART_RECEPTION_STANDARD;
1122
 
1235
 
1123
    /* Init tickstart for timeout managment */
1236
    /* Init tickstart for timeout management */
1124
    tickstart = HAL_GetTick();
1237
    tickstart = HAL_GetTick();
1125
 
1238
 
1126
    huart->RxXferSize = Size;
1239
    huart->RxXferSize = Size;
1127
    huart->RxXferCount = Size;
1240
    huart->RxXferCount = Size;
1128
 
1241
 
-
 
1242
    /* In case of 9bits/No Parity transfer, pRxData needs to be handled as a uint16_t pointer */
-
 
1243
    if ((huart->Init.WordLength == UART_WORDLENGTH_9B) && (huart->Init.Parity == UART_PARITY_NONE))
-
 
1244
    {
-
 
1245
      pdata8bits  = NULL;
-
 
1246
      pdata16bits = (uint16_t *) pData;
-
 
1247
    }
-
 
1248
    else
-
 
1249
    {
-
 
1250
      pdata8bits  = pData;
-
 
1251
      pdata16bits = NULL;
-
 
1252
    }
-
 
1253
 
1129
    /* Process Unlocked */
1254
    /* Process Unlocked */
1130
    __HAL_UNLOCK(huart);
1255
    __HAL_UNLOCK(huart);
1131
 
1256
 
1132
    /* Check the remain data to be received */
1257
    /* Check the remain data to be received */
1133
    while (huart->RxXferCount > 0U)
1258
    while (huart->RxXferCount > 0U)
1134
    {
1259
    {
1135
      huart->RxXferCount--;
-
 
1136
      if (huart->Init.WordLength == UART_WORDLENGTH_9B)
1260
      if (UART_WaitOnFlagUntilTimeout(huart, UART_FLAG_RXNE, RESET, tickstart, Timeout) != HAL_OK)
1137
      {
1261
      {
1138
        if (UART_WaitOnFlagUntilTimeout(huart, UART_FLAG_RXNE, RESET, tickstart, Timeout) != HAL_OK)
-
 
1139
        {
-
 
1140
          return HAL_TIMEOUT;
1262
        return HAL_TIMEOUT;
1141
        }
1263
      }
1142
        tmp = (uint16_t *) pData;
-
 
1143
        if (huart->Init.Parity == UART_PARITY_NONE)
-
 
1144
        {
-
 
1145
          *tmp = (uint16_t)(huart->Instance->DR & (uint16_t)0x01FF);
-
 
1146
          pData += 2U;
1264
      if (pdata8bits == NULL)
1147
        }
-
 
1148
        else
-
 
1149
        {
1265
      {
1150
          *tmp = (uint16_t)(huart->Instance->DR & (uint16_t)0x00FF);
1266
        *pdata16bits = (uint16_t)(huart->Instance->DR & 0x01FF);
1151
          pData += 1U;
1267
        pdata16bits++;
1152
        }
-
 
1153
 
-
 
1154
      }
1268
      }
1155
      else
1269
      else
1156
      {
1270
      {
1157
        if (UART_WaitOnFlagUntilTimeout(huart, UART_FLAG_RXNE, RESET, tickstart, Timeout) != HAL_OK)
1271
        if ((huart->Init.WordLength == UART_WORDLENGTH_9B) || ((huart->Init.WordLength == UART_WORDLENGTH_8B) && (huart->Init.Parity == UART_PARITY_NONE)))
1158
        {
1272
        {
1159
          return HAL_TIMEOUT;
-
 
1160
        }
-
 
1161
        if (huart->Init.Parity == UART_PARITY_NONE)
-
 
1162
        {
-
 
1163
          *pData++ = (uint8_t)(huart->Instance->DR & (uint8_t)0x00FF);
1273
          *pdata8bits = (uint8_t)(huart->Instance->DR & (uint8_t)0x00FF);
1164
        }
1274
        }
1165
        else
1275
        else
1166
        {
1276
        {
1167
          *pData++ = (uint8_t)(huart->Instance->DR & (uint8_t)0x007F);
1277
          *pdata8bits = (uint8_t)(huart->Instance->DR & (uint8_t)0x007F);
1168
        }
1278
        }
1169
 
-
 
-
 
1279
        pdata8bits++;
1170
      }
1280
      }
-
 
1281
      huart->RxXferCount--;
1171
    }
1282
    }
1172
 
1283
 
1173
    /* At end of Rx process, restore huart->RxState to Ready */
1284
    /* At end of Rx process, restore huart->RxState to Ready */
1174
    huart->RxState = HAL_UART_STATE_READY;
1285
    huart->RxState = HAL_UART_STATE_READY;
1175
 
1286
 
Line 1248... Line 1359...
1248
    }
1359
    }
1249
 
1360
 
1250
    /* Process Locked */
1361
    /* Process Locked */
1251
    __HAL_LOCK(huart);
1362
    __HAL_LOCK(huart);
1252
 
1363
 
1253
    huart->pRxBuffPtr = pData;
1364
    /* Set Reception type to Standard reception */
1254
    huart->RxXferSize = Size;
1365
    huart->ReceptionType = HAL_UART_RECEPTION_STANDARD;
1255
    huart->RxXferCount = Size;
-
 
1256
 
1366
 
1257
    huart->ErrorCode = HAL_UART_ERROR_NONE;
-
 
1258
    huart->RxState = HAL_UART_STATE_BUSY_RX;
-
 
1259
 
-
 
1260
    /* Process Unlocked */
-
 
1261
    __HAL_UNLOCK(huart);
-
 
1262
 
-
 
1263
    /* Enable the UART Parity Error Interrupt */
-
 
1264
    __HAL_UART_ENABLE_IT(huart, UART_IT_PE);
-
 
1265
 
-
 
1266
    /* Enable the UART Error Interrupt: (Frame error, noise error, overrun error) */
-
 
1267
    __HAL_UART_ENABLE_IT(huart, UART_IT_ERR);
-
 
1268
 
-
 
1269
    /* Enable the UART Data Register not empty Interrupt */
-
 
1270
    __HAL_UART_ENABLE_IT(huart, UART_IT_RXNE);
1367
    return(UART_Start_Receive_IT(huart, pData, Size));
1271
 
-
 
1272
    return HAL_OK;
-
 
1273
  }
1368
  }
1274
  else
1369
  else
1275
  {
1370
  {
1276
    return HAL_BUSY;
1371
    return HAL_BUSY;
1277
  }
1372
  }
Line 1356... Line 1451...
1356
  * @note   When the UART parity is enabled (PCE = 1) the received data contains the parity bit.
1451
  * @note   When the UART parity is enabled (PCE = 1) the received data contains the parity bit.
1357
  * @retval HAL status
1452
  * @retval HAL status
1358
  */
1453
  */
1359
HAL_StatusTypeDef HAL_UART_Receive_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)
1454
HAL_StatusTypeDef HAL_UART_Receive_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)
1360
{
1455
{
1361
  uint32_t *tmp;
-
 
1362
 
-
 
1363
  /* Check that a Rx process is not already ongoing */
1456
  /* Check that a Rx process is not already ongoing */
1364
  if (huart->RxState == HAL_UART_STATE_READY)
1457
  if (huart->RxState == HAL_UART_STATE_READY)
1365
  {
1458
  {
1366
    if ((pData == NULL) || (Size == 0U))
1459
    if ((pData == NULL) || (Size == 0U))
1367
    {
1460
    {
Line 1369... Line 1462...
1369
    }
1462
    }
1370
 
1463
 
1371
    /* Process Locked */
1464
    /* Process Locked */
1372
    __HAL_LOCK(huart);
1465
    __HAL_LOCK(huart);
1373
 
1466
 
1374
    huart->pRxBuffPtr = pData;
-
 
1375
    huart->RxXferSize = Size;
-
 
1376
 
-
 
1377
    huart->ErrorCode = HAL_UART_ERROR_NONE;
1467
    /* Set Reception type to Standard reception */
1378
    huart->RxState = HAL_UART_STATE_BUSY_RX;
1468
    huart->ReceptionType = HAL_UART_RECEPTION_STANDARD;
1379
 
-
 
1380
    /* Set the UART DMA transfer complete callback */
-
 
1381
    huart->hdmarx->XferCpltCallback = UART_DMAReceiveCplt;
-
 
1382
 
-
 
1383
    /* Set the UART DMA Half transfer complete callback */
-
 
1384
    huart->hdmarx->XferHalfCpltCallback = UART_DMARxHalfCplt;
-
 
1385
 
-
 
1386
    /* Set the DMA error callback */
-
 
1387
    huart->hdmarx->XferErrorCallback = UART_DMAError;
-
 
1388
 
-
 
1389
    /* Set the DMA abort callback */
-
 
1390
    huart->hdmarx->XferAbortCallback = NULL;
-
 
1391
 
-
 
1392
    /* Enable the DMA channel */
-
 
1393
    tmp = (uint32_t *)&pData;
-
 
1394
    HAL_DMA_Start_IT(huart->hdmarx, (uint32_t)&huart->Instance->DR, *(uint32_t *)tmp, Size);
-
 
1395
 
-
 
1396
    /* Clear the Overrun flag just before enabling the DMA Rx request: can be mandatory for the second transfer */
-
 
1397
    __HAL_UART_CLEAR_OREFLAG(huart);
-
 
1398
 
1469
 
1399
    /* Process Unlocked */
-
 
1400
    __HAL_UNLOCK(huart);
-
 
1401
 
-
 
1402
    /* Enable the UART Parity Error Interrupt */
-
 
1403
    SET_BIT(huart->Instance->CR1, USART_CR1_PEIE);
-
 
1404
 
-
 
1405
    /* Enable the UART Error Interrupt: (Frame error, noise error, overrun error) */
-
 
1406
    SET_BIT(huart->Instance->CR3, USART_CR3_EIE);
1470
    return(UART_Start_Receive_DMA(huart, pData, Size));
1407
 
-
 
1408
    /* Enable the DMA transfer for the receiver request by setting the DMAR bit
-
 
1409
    in the UART CR3 register */
-
 
1410
    SET_BIT(huart->Instance->CR3, USART_CR3_DMAR);
-
 
1411
 
-
 
1412
    return HAL_OK;
-
 
1413
  }
1471
  }
1414
  else
1472
  else
1415
  {
1473
  {
1416
    return HAL_BUSY;
1474
    return HAL_BUSY;
1417
  }
1475
  }
Line 1474... Line 1532...
1474
  if (huart->RxState == HAL_UART_STATE_BUSY_RX)
1532
  if (huart->RxState == HAL_UART_STATE_BUSY_RX)
1475
  {
1533
  {
1476
    /* Clear the Overrun flag before resuming the Rx transfer*/
1534
    /* Clear the Overrun flag before resuming the Rx transfer*/
1477
    __HAL_UART_CLEAR_OREFLAG(huart);
1535
    __HAL_UART_CLEAR_OREFLAG(huart);
1478
 
1536
 
1479
    /* Reenable PE and ERR (Frame error, noise error, overrun error) interrupts */
1537
    /* Re-enable PE and ERR (Frame error, noise error, overrun error) interrupts */
1480
    SET_BIT(huart->Instance->CR1, USART_CR1_PEIE);
1538
    SET_BIT(huart->Instance->CR1, USART_CR1_PEIE);
1481
    SET_BIT(huart->Instance->CR3, USART_CR3_EIE);
1539
    SET_BIT(huart->Instance->CR3, USART_CR3_EIE);
1482
 
1540
 
1483
    /* Enable the UART DMA Rx request */
1541
    /* Enable the UART DMA Rx request */
1484
    SET_BIT(huart->Instance->CR3, USART_CR3_DMAR);
1542
    SET_BIT(huart->Instance->CR3, USART_CR3_DMAR);
Line 1535... Line 1593...
1535
 
1593
 
1536
  return HAL_OK;
1594
  return HAL_OK;
1537
}
1595
}
1538
 
1596
 
1539
/**
1597
/**
-
 
1598
  * @brief Receive an amount of data in blocking mode till either the expected number of data is received or an IDLE event occurs.
-
 
1599
  * @note   HAL_OK is returned if reception is completed (expected number of data has been received)
-
 
1600
  *         or if reception is stopped after IDLE event (less than the expected number of data has been received)
-
 
1601
  *         In this case, RxLen output parameter indicates number of data available in reception buffer.
-
 
1602
  * @note   When UART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M = 01),
-
 
1603
  *         the received data is handled as a set of uint16_t. In this case, Size must indicate the number
-
 
1604
  *         of uint16_t available through pData.
-
 
1605
  * @param huart   UART handle.
-
 
1606
  * @param pData   Pointer to data buffer (uint8_t or uint16_t data elements).
-
 
1607
  * @param Size    Amount of data elements (uint8_t or uint16_t) to be received.
-
 
1608
  * @param RxLen   Number of data elements finally received (could be lower than Size, in case reception ends on IDLE event)
-
 
1609
  * @param Timeout Timeout duration expressed in ms (covers the whole reception sequence).
-
 
1610
  * @retval HAL status
-
 
1611
  */
-
 
1612
HAL_StatusTypeDef HAL_UARTEx_ReceiveToIdle(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint16_t *RxLen, uint32_t Timeout)
-
 
1613
{
-
 
1614
  uint8_t  *pdata8bits;
-
 
1615
  uint16_t *pdata16bits;
-
 
1616
  uint32_t tickstart;
-
 
1617
 
-
 
1618
  /* Check that a Rx process is not already ongoing */
-
 
1619
  if (huart->RxState == HAL_UART_STATE_READY)
-
 
1620
  {
-
 
1621
    if ((pData == NULL) || (Size == 0U))
-
 
1622
    {
-
 
1623
      return  HAL_ERROR;
-
 
1624
    }
-
 
1625
 
-
 
1626
    __HAL_LOCK(huart);
-
 
1627
 
-
 
1628
    huart->ErrorCode = HAL_UART_ERROR_NONE;
-
 
1629
    huart->RxState = HAL_UART_STATE_BUSY_RX;
-
 
1630
    huart->ReceptionType = HAL_UART_RECEPTION_TOIDLE;
-
 
1631
 
-
 
1632
    /* Init tickstart for timeout management */
-
 
1633
    tickstart = HAL_GetTick();
-
 
1634
 
-
 
1635
    huart->RxXferSize  = Size;
-
 
1636
    huart->RxXferCount = Size;
-
 
1637
 
-
 
1638
    /* In case of 9bits/No Parity transfer, pRxData needs to be handled as a uint16_t pointer */
-
 
1639
    if ((huart->Init.WordLength == UART_WORDLENGTH_9B) && (huart->Init.Parity == UART_PARITY_NONE))
-
 
1640
    {
-
 
1641
      pdata8bits  = NULL;
-
 
1642
      pdata16bits = (uint16_t *) pData;
-
 
1643
    }
-
 
1644
    else
-
 
1645
    {
-
 
1646
      pdata8bits  = pData;
-
 
1647
      pdata16bits = NULL;
-
 
1648
    }
-
 
1649
 
-
 
1650
    __HAL_UNLOCK(huart);
-
 
1651
 
-
 
1652
    /* Initialize output number of received elements */
-
 
1653
    *RxLen = 0U;
-
 
1654
 
-
 
1655
    /* as long as data have to be received */
-
 
1656
    while (huart->RxXferCount > 0U)
-
 
1657
    {
-
 
1658
      /* Check if IDLE flag is set */
-
 
1659
      if (__HAL_UART_GET_FLAG(huart, UART_FLAG_IDLE))
-
 
1660
      {
-
 
1661
        /* Clear IDLE flag in ISR */
-
 
1662
        __HAL_UART_CLEAR_IDLEFLAG(huart);
-
 
1663
 
-
 
1664
        /* If Set, but no data ever received, clear flag without exiting loop */
-
 
1665
        /* If Set, and data has already been received, this means Idle Event is valid : End reception */
-
 
1666
        if (*RxLen > 0U)
-
 
1667
        {
-
 
1668
          huart->RxState = HAL_UART_STATE_READY;
-
 
1669
 
-
 
1670
          return HAL_OK;
-
 
1671
        }
-
 
1672
      }
-
 
1673
 
-
 
1674
      /* Check if RXNE flag is set */
-
 
1675
      if (__HAL_UART_GET_FLAG(huart, UART_FLAG_RXNE))
-
 
1676
      {
-
 
1677
        if (pdata8bits == NULL)
-
 
1678
        {
-
 
1679
          *pdata16bits = (uint16_t)(huart->Instance->DR & (uint16_t)0x01FF);
-
 
1680
          pdata16bits++;
-
 
1681
        }
-
 
1682
        else
-
 
1683
        {
-
 
1684
           if ((huart->Init.WordLength == UART_WORDLENGTH_9B) || ((huart->Init.WordLength == UART_WORDLENGTH_8B) && (huart->Init.Parity == UART_PARITY_NONE)))
-
 
1685
           {
-
 
1686
             *pdata8bits = (uint8_t)(huart->Instance->DR & (uint8_t)0x00FF);
-
 
1687
           }
-
 
1688
           else
-
 
1689
           {
-
 
1690
             *pdata8bits = (uint8_t)(huart->Instance->DR & (uint8_t)0x007F);
-
 
1691
           }
-
 
1692
 
-
 
1693
          pdata8bits++;
-
 
1694
        }
-
 
1695
        /* Increment number of received elements */
-
 
1696
        *RxLen += 1U;
-
 
1697
        huart->RxXferCount--;
-
 
1698
      }
-
 
1699
 
-
 
1700
      /* Check for the Timeout */
-
 
1701
      if (Timeout != HAL_MAX_DELAY)
-
 
1702
      {
-
 
1703
        if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U))
-
 
1704
        {
-
 
1705
          huart->RxState = HAL_UART_STATE_READY;
-
 
1706
 
-
 
1707
          return HAL_TIMEOUT;
-
 
1708
        }
-
 
1709
      }
-
 
1710
    }
-
 
1711
 
-
 
1712
    /* Set number of received elements in output parameter : RxLen */
-
 
1713
    *RxLen = huart->RxXferSize - huart->RxXferCount;
-
 
1714
    /* At end of Rx process, restore huart->RxState to Ready */
-
 
1715
    huart->RxState = HAL_UART_STATE_READY;
-
 
1716
 
-
 
1717
    return HAL_OK;
-
 
1718
  }
-
 
1719
  else
-
 
1720
  {
-
 
1721
    return HAL_BUSY;
-
 
1722
  }
-
 
1723
}
-
 
1724
 
-
 
1725
/**
-
 
1726
  * @brief Receive an amount of data in interrupt mode till either the expected number of data is received or an IDLE event occurs.
-
 
1727
  * @note   Reception is initiated by this function call. Further progress of reception is achieved thanks
-
 
1728
  *         to UART interrupts raised by RXNE and IDLE events. Callback is called at end of reception indicating
-
 
1729
  *         number of received data elements.
-
 
1730
  * @note   When UART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M = 01),
-
 
1731
  *         the received data is handled as a set of uint16_t. In this case, Size must indicate the number
-
 
1732
  *         of uint16_t available through pData.
-
 
1733
  * @param huart UART handle.
-
 
1734
  * @param pData Pointer to data buffer (uint8_t or uint16_t data elements).
-
 
1735
  * @param Size  Amount of data elements (uint8_t or uint16_t) to be received.
-
 
1736
  * @retval HAL status
-
 
1737
  */
-
 
1738
HAL_StatusTypeDef HAL_UARTEx_ReceiveToIdle_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)
-
 
1739
{
-
 
1740
  HAL_StatusTypeDef status;
-
 
1741
 
-
 
1742
  /* Check that a Rx process is not already ongoing */
-
 
1743
  if (huart->RxState == HAL_UART_STATE_READY)
-
 
1744
  {
-
 
1745
    if ((pData == NULL) || (Size == 0U))
-
 
1746
    {
-
 
1747
      return HAL_ERROR;
-
 
1748
    }
-
 
1749
 
-
 
1750
    __HAL_LOCK(huart);
-
 
1751
 
-
 
1752
    /* Set Reception type to reception till IDLE Event*/
-
 
1753
    huart->ReceptionType = HAL_UART_RECEPTION_TOIDLE;
-
 
1754
 
-
 
1755
    status =  UART_Start_Receive_IT(huart, pData, Size);
-
 
1756
 
-
 
1757
    /* Check Rx process has been successfully started */
-
 
1758
    if (status == HAL_OK)
-
 
1759
    {
-
 
1760
      if (huart->ReceptionType == HAL_UART_RECEPTION_TOIDLE)
-
 
1761
      {
-
 
1762
        __HAL_UART_CLEAR_IDLEFLAG(huart);
-
 
1763
        SET_BIT(huart->Instance->CR1, USART_CR1_IDLEIE);
-
 
1764
      }
-
 
1765
      else
-
 
1766
      {
-
 
1767
        /* In case of errors already pending when reception is started,
-
 
1768
           Interrupts may have already been raised and lead to reception abortion.
-
 
1769
           (Overrun error for instance).
-
 
1770
           In such case Reception Type has been reset to HAL_UART_RECEPTION_STANDARD. */
-
 
1771
        status = HAL_ERROR;
-
 
1772
      }
-
 
1773
    }
-
 
1774
 
-
 
1775
    return status;
-
 
1776
  }
-
 
1777
  else
-
 
1778
  {
-
 
1779
    return HAL_BUSY;
-
 
1780
  }
-
 
1781
}
-
 
1782
 
-
 
1783
/**
-
 
1784
  * @brief Receive an amount of data in DMA mode till either the expected number of data is received or an IDLE event occurs.
-
 
1785
  * @note   Reception is initiated by this function call. Further progress of reception is achieved thanks
-
 
1786
  *         to DMA services, transferring automatically received data elements in user reception buffer and
-
 
1787
  *         calling registered callbacks at half/end of reception. UART IDLE events are also used to consider
-
 
1788
  *         reception phase as ended. In all cases, callback execution will indicate number of received data elements.
-
 
1789
  * @note   When the UART parity is enabled (PCE = 1), the received data contain
-
 
1790
  *         the parity bit (MSB position).
-
 
1791
  * @note   When UART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M = 01),
-
 
1792
  *         the received data is handled as a set of uint16_t. In this case, Size must indicate the number
-
 
1793
  *         of uint16_t available through pData.
-
 
1794
  * @param huart UART handle.
-
 
1795
  * @param pData Pointer to data buffer (uint8_t or uint16_t data elements).
-
 
1796
  * @param Size  Amount of data elements (uint8_t or uint16_t) to be received.
-
 
1797
  * @retval HAL status
-
 
1798
  */
-
 
1799
HAL_StatusTypeDef HAL_UARTEx_ReceiveToIdle_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)
-
 
1800
{
-
 
1801
  HAL_StatusTypeDef status;
-
 
1802
 
-
 
1803
  /* Check that a Rx process is not already ongoing */
-
 
1804
  if (huart->RxState == HAL_UART_STATE_READY)
-
 
1805
  {
-
 
1806
    if ((pData == NULL) || (Size == 0U))
-
 
1807
    {
-
 
1808
      return HAL_ERROR;
-
 
1809
    }
-
 
1810
 
-
 
1811
    __HAL_LOCK(huart);
-
 
1812
 
-
 
1813
    /* Set Reception type to reception till IDLE Event*/
-
 
1814
    huart->ReceptionType = HAL_UART_RECEPTION_TOIDLE;
-
 
1815
 
-
 
1816
    status =  UART_Start_Receive_DMA(huart, pData, Size);
-
 
1817
 
-
 
1818
    /* Check Rx process has been successfully started */
-
 
1819
    if (status == HAL_OK)
-
 
1820
    {
-
 
1821
      if (huart->ReceptionType == HAL_UART_RECEPTION_TOIDLE)
-
 
1822
      {
-
 
1823
        __HAL_UART_CLEAR_IDLEFLAG(huart);
-
 
1824
        SET_BIT(huart->Instance->CR1, USART_CR1_IDLEIE);
-
 
1825
      }
-
 
1826
      else
-
 
1827
      {
-
 
1828
        /* In case of errors already pending when reception is started,
-
 
1829
           Interrupts may have already been raised and lead to reception abortion.
-
 
1830
           (Overrun error for instance).
-
 
1831
           In such case Reception Type has been reset to HAL_UART_RECEPTION_STANDARD. */
-
 
1832
        status = HAL_ERROR;
-
 
1833
      }
-
 
1834
    }
-
 
1835
 
-
 
1836
    return status;
-
 
1837
  }
-
 
1838
  else
-
 
1839
  {
-
 
1840
    return HAL_BUSY;
-
 
1841
  }
-
 
1842
}
-
 
1843
 
-
 
1844
/**
1540
  * @brief  Abort ongoing transfers (blocking mode).
1845
  * @brief  Abort ongoing transfers (blocking mode).
1541
  * @param  huart UART handle.
1846
  * @param  huart UART handle.
1542
  * @note   This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode.
1847
  * @note   This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode.
1543
  *         This procedure performs following operations :
1848
  *         This procedure performs following operations :
1544
  *           - Disable UART Interrupts (Tx and Rx)
1849
  *           - Disable UART Interrupts (Tx and Rx)
Line 1552... Line 1857...
1552
{
1857
{
1553
  /* Disable TXEIE, TCIE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
1858
  /* Disable TXEIE, TCIE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
1554
  CLEAR_BIT(huart->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_TXEIE | USART_CR1_TCIE));
1859
  CLEAR_BIT(huart->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_TXEIE | USART_CR1_TCIE));
1555
  CLEAR_BIT(huart->Instance->CR3, USART_CR3_EIE);
1860
  CLEAR_BIT(huart->Instance->CR3, USART_CR3_EIE);
1556
 
1861
 
-
 
1862
  /* If Reception till IDLE event was ongoing, disable IDLEIE interrupt */
-
 
1863
  if (huart->ReceptionType == HAL_UART_RECEPTION_TOIDLE)
-
 
1864
  {
-
 
1865
    CLEAR_BIT(huart->Instance->CR1, (USART_CR1_IDLEIE));
-
 
1866
  }
-
 
1867
 
1557
  /* Disable the UART DMA Tx request if enabled */
1868
  /* Disable the UART DMA Tx request if enabled */
1558
  if (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAT))
1869
  if (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAT))
1559
  {
1870
  {
1560
    CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAT);
1871
    CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAT);
1561
 
1872
 
Line 1612... Line 1923...
1612
  huart->ErrorCode = HAL_UART_ERROR_NONE;
1923
  huart->ErrorCode = HAL_UART_ERROR_NONE;
1613
 
1924
 
1614
  /* Restore huart->RxState and huart->gState to Ready */
1925
  /* Restore huart->RxState and huart->gState to Ready */
1615
  huart->RxState = HAL_UART_STATE_READY;
1926
  huart->RxState = HAL_UART_STATE_READY;
1616
  huart->gState = HAL_UART_STATE_READY;
1927
  huart->gState = HAL_UART_STATE_READY;
-
 
1928
  huart->ReceptionType = HAL_UART_RECEPTION_STANDARD;
1617
 
1929
 
1618
  return HAL_OK;
1930
  return HAL_OK;
1619
}
1931
}
1620
 
1932
 
1621
/**
1933
/**
Line 1685... Line 1997...
1685
{
1997
{
1686
  /* Disable RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
1998
  /* Disable RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
1687
  CLEAR_BIT(huart->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE));
1999
  CLEAR_BIT(huart->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE));
1688
  CLEAR_BIT(huart->Instance->CR3, USART_CR3_EIE);
2000
  CLEAR_BIT(huart->Instance->CR3, USART_CR3_EIE);
1689
 
2001
 
-
 
2002
  /* If Reception till IDLE event was ongoing, disable IDLEIE interrupt */
-
 
2003
  if (huart->ReceptionType == HAL_UART_RECEPTION_TOIDLE)
-
 
2004
  {
-
 
2005
    CLEAR_BIT(huart->Instance->CR1, (USART_CR1_IDLEIE));
-
 
2006
  }
-
 
2007
 
1690
  /* Disable the UART DMA Rx request if enabled */
2008
  /* Disable the UART DMA Rx request if enabled */
1691
  if (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAR))
2009
  if (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAR))
1692
  {
2010
  {
1693
    CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAR);
2011
    CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAR);
1694
 
2012
 
Line 1715... Line 2033...
1715
  /* Reset Rx transfer counter */
2033
  /* Reset Rx transfer counter */
1716
  huart->RxXferCount = 0x00U;
2034
  huart->RxXferCount = 0x00U;
1717
 
2035
 
1718
  /* Restore huart->RxState to Ready */
2036
  /* Restore huart->RxState to Ready */
1719
  huart->RxState = HAL_UART_STATE_READY;
2037
  huart->RxState = HAL_UART_STATE_READY;
-
 
2038
  huart->ReceptionType = HAL_UART_RECEPTION_STANDARD;
1720
 
2039
 
1721
  return HAL_OK;
2040
  return HAL_OK;
1722
}
2041
}
1723
 
2042
 
1724
/**
2043
/**
Line 1741... Line 2060...
1741
 
2060
 
1742
  /* Disable TXEIE, TCIE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
2061
  /* Disable TXEIE, TCIE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
1743
  CLEAR_BIT(huart->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_TXEIE | USART_CR1_TCIE));
2062
  CLEAR_BIT(huart->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_TXEIE | USART_CR1_TCIE));
1744
  CLEAR_BIT(huart->Instance->CR3, USART_CR3_EIE);
2063
  CLEAR_BIT(huart->Instance->CR3, USART_CR3_EIE);
1745
 
2064
 
-
 
2065
  /* If Reception till IDLE event was ongoing, disable IDLEIE interrupt */
-
 
2066
  if (huart->ReceptionType == HAL_UART_RECEPTION_TOIDLE)
-
 
2067
  {
-
 
2068
    CLEAR_BIT(huart->Instance->CR1, (USART_CR1_IDLEIE));
-
 
2069
  }
-
 
2070
 
1746
  /* If DMA Tx and/or DMA Rx Handles are associated to UART Handle, DMA Abort complete callbacks should be initialised
2071
  /* If DMA Tx and/or DMA Rx Handles are associated to UART Handle, DMA Abort complete callbacks should be initialised
1747
     before any call to DMA Abort functions */
2072
     before any call to DMA Abort functions */
1748
  /* DMA Tx Handle is valid */
2073
  /* DMA Tx Handle is valid */
1749
  if (huart->hdmatx != NULL)
2074
  if (huart->hdmatx != NULL)
1750
  {
2075
  {
Line 1833... Line 2158...
1833
    huart->ErrorCode = HAL_UART_ERROR_NONE;
2158
    huart->ErrorCode = HAL_UART_ERROR_NONE;
1834
 
2159
 
1835
    /* Restore huart->gState and huart->RxState to Ready */
2160
    /* Restore huart->gState and huart->RxState to Ready */
1836
    huart->gState  = HAL_UART_STATE_READY;
2161
    huart->gState  = HAL_UART_STATE_READY;
1837
    huart->RxState = HAL_UART_STATE_READY;
2162
    huart->RxState = HAL_UART_STATE_READY;
-
 
2163
    huart->ReceptionType = HAL_UART_RECEPTION_STANDARD;
1838
 
2164
 
1839
    /* As no DMA to be aborted, call directly user Abort complete callback */
2165
    /* As no DMA to be aborted, call directly user Abort complete callback */
1840
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
2166
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
1841
    /* Call registered Abort complete callback */
2167
    /* Call registered Abort complete callback */
1842
    huart->AbortCpltCallback(huart);
2168
    huart->AbortCpltCallback(huart);
Line 1944... Line 2270...
1944
{
2270
{
1945
  /* Disable RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
2271
  /* Disable RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
1946
  CLEAR_BIT(huart->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE));
2272
  CLEAR_BIT(huart->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE));
1947
  CLEAR_BIT(huart->Instance->CR3, USART_CR3_EIE);
2273
  CLEAR_BIT(huart->Instance->CR3, USART_CR3_EIE);
1948
 
2274
 
-
 
2275
  /* If Reception till IDLE event was ongoing, disable IDLEIE interrupt */
-
 
2276
  if (huart->ReceptionType == HAL_UART_RECEPTION_TOIDLE)
-
 
2277
  {
-
 
2278
    CLEAR_BIT(huart->Instance->CR1, (USART_CR1_IDLEIE));
-
 
2279
  }
-
 
2280
 
1949
  /* Disable the UART DMA Rx request if enabled */
2281
  /* Disable the UART DMA Rx request if enabled */
1950
  if (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAR))
2282
  if (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAR))
1951
  {
2283
  {
1952
    CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAR);
2284
    CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAR);
1953
 
2285
 
Line 1970... Line 2302...
1970
      /* Reset Rx transfer counter */
2302
      /* Reset Rx transfer counter */
1971
      huart->RxXferCount = 0x00U;
2303
      huart->RxXferCount = 0x00U;
1972
 
2304
 
1973
      /* Restore huart->RxState to Ready */
2305
      /* Restore huart->RxState to Ready */
1974
      huart->RxState = HAL_UART_STATE_READY;
2306
      huart->RxState = HAL_UART_STATE_READY;
-
 
2307
      huart->ReceptionType = HAL_UART_RECEPTION_STANDARD;
1975
 
2308
 
1976
      /* As no DMA to be aborted, call directly user Abort complete callback */
2309
      /* As no DMA to be aborted, call directly user Abort complete callback */
1977
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
2310
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
1978
      /* Call registered Abort Receive Complete Callback */
2311
      /* Call registered Abort Receive Complete Callback */
1979
      huart->AbortReceiveCpltCallback(huart);
2312
      huart->AbortReceiveCpltCallback(huart);
Line 1988... Line 2321...
1988
    /* Reset Rx transfer counter */
2321
    /* Reset Rx transfer counter */
1989
    huart->RxXferCount = 0x00U;
2322
    huart->RxXferCount = 0x00U;
1990
 
2323
 
1991
    /* Restore huart->RxState to Ready */
2324
    /* Restore huart->RxState to Ready */
1992
    huart->RxState = HAL_UART_STATE_READY;
2325
    huart->RxState = HAL_UART_STATE_READY;
-
 
2326
    huart->ReceptionType = HAL_UART_RECEPTION_STANDARD;
1993
 
2327
 
1994
    /* As no DMA to be aborted, call directly user Abort complete callback */
2328
    /* As no DMA to be aborted, call directly user Abort complete callback */
1995
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
2329
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
1996
    /* Call registered Abort Receive Complete Callback */
2330
    /* Call registered Abort Receive Complete Callback */
1997
    huart->AbortReceiveCpltCallback(huart);
2331
    huart->AbortReceiveCpltCallback(huart);
Line 2133... Line 2467...
2133
      }
2467
      }
2134
    }
2468
    }
2135
    return;
2469
    return;
2136
  } /* End if some error occurs */
2470
  } /* End if some error occurs */
2137
 
2471
 
-
 
2472
  /* Check current reception Mode :
-
 
2473
     If Reception till IDLE event has been selected : */
-
 
2474
  if (  (huart->ReceptionType == HAL_UART_RECEPTION_TOIDLE)
-
 
2475
      &&((isrflags & USART_SR_IDLE) != 0U)
-
 
2476
      &&((cr1its & USART_SR_IDLE) != 0U))
-
 
2477
  {
-
 
2478
    __HAL_UART_CLEAR_IDLEFLAG(huart);
-
 
2479
 
-
 
2480
    /* Check if DMA mode is enabled in UART */
-
 
2481
    if (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAR))
-
 
2482
    {
-
 
2483
      /* DMA mode enabled */
-
 
2484
      /* Check received length : If all expected data are received, do nothing,
-
 
2485
         (DMA cplt callback will be called).
-
 
2486
         Otherwise, if at least one data has already been received, IDLE event is to be notified to user */
-
 
2487
      uint16_t nb_remaining_rx_data = (uint16_t) __HAL_DMA_GET_COUNTER(huart->hdmarx);
-
 
2488
      if (  (nb_remaining_rx_data > 0U)
-
 
2489
          &&(nb_remaining_rx_data < huart->RxXferSize))
-
 
2490
      {
-
 
2491
        /* Reception is not complete */
-
 
2492
        huart->RxXferCount = nb_remaining_rx_data;
-
 
2493
 
-
 
2494
        /* In Normal mode, end DMA xfer and HAL UART Rx process*/
-
 
2495
        if (huart->hdmarx->Init.Mode != DMA_CIRCULAR)
-
 
2496
        {
-
 
2497
          /* Disable PE and ERR (Frame error, noise error, overrun error) interrupts */
-
 
2498
          CLEAR_BIT(huart->Instance->CR1, USART_CR1_PEIE);
-
 
2499
          CLEAR_BIT(huart->Instance->CR3, USART_CR3_EIE);
-
 
2500
 
-
 
2501
          /* Disable the DMA transfer for the receiver request by resetting the DMAR bit
-
 
2502
             in the UART CR3 register */
-
 
2503
          CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAR);
-
 
2504
 
-
 
2505
          /* At end of Rx process, restore huart->RxState to Ready */
-
 
2506
          huart->RxState = HAL_UART_STATE_READY;
-
 
2507
          huart->ReceptionType = HAL_UART_RECEPTION_STANDARD;
-
 
2508
 
-
 
2509
          CLEAR_BIT(huart->Instance->CR1, USART_CR1_IDLEIE);
-
 
2510
 
-
 
2511
          /* Last bytes received, so no need as the abort is immediate */
-
 
2512
          (void)HAL_DMA_Abort(huart->hdmarx);
-
 
2513
        }
-
 
2514
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
-
 
2515
        /*Call registered Rx Event callback*/
-
 
2516
        huart->RxEventCallback(huart, (huart->RxXferSize - huart->RxXferCount));
-
 
2517
#else
-
 
2518
        /*Call legacy weak Rx Event callback*/
-
 
2519
        HAL_UARTEx_RxEventCallback(huart, (huart->RxXferSize - huart->RxXferCount));
-
 
2520
#endif
-
 
2521
      }
-
 
2522
      return;
-
 
2523
    }
-
 
2524
    else
-
 
2525
    {
-
 
2526
      /* DMA mode not enabled */
-
 
2527
      /* Check received length : If all expected data are received, do nothing.
-
 
2528
         Otherwise, if at least one data has already been received, IDLE event is to be notified to user */
-
 
2529
      uint16_t nb_rx_data = huart->RxXferSize - huart->RxXferCount;
-
 
2530
      if (  (huart->RxXferCount > 0U)
-
 
2531
          &&(nb_rx_data > 0U) )
-
 
2532
      {
-
 
2533
        /* Disable the UART Parity Error Interrupt and RXNE interrupts */
-
 
2534
        CLEAR_BIT(huart->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE));
-
 
2535
 
-
 
2536
        /* Disable the UART Error Interrupt: (Frame error, noise error, overrun error) */
-
 
2537
        CLEAR_BIT(huart->Instance->CR3, USART_CR3_EIE);
-
 
2538
 
-
 
2539
        /* Rx process is completed, restore huart->RxState to Ready */
-
 
2540
        huart->RxState = HAL_UART_STATE_READY;
-
 
2541
        huart->ReceptionType = HAL_UART_RECEPTION_STANDARD;
-
 
2542
 
-
 
2543
        CLEAR_BIT(huart->Instance->CR1, USART_CR1_IDLEIE);
-
 
2544
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
-
 
2545
        /*Call registered Rx complete callback*/
-
 
2546
        huart->RxEventCallback(huart, nb_rx_data);
-
 
2547
#else
-
 
2548
        /*Call legacy weak Rx Event callback*/
-
 
2549
        HAL_UARTEx_RxEventCallback(huart, nb_rx_data);
-
 
2550
#endif
-
 
2551
      }
-
 
2552
      return;
-
 
2553
    }
-
 
2554
  }
-
 
2555
 
2138
  /* UART in mode Transmitter ------------------------------------------------*/
2556
  /* UART in mode Transmitter ------------------------------------------------*/
2139
  if (((isrflags & USART_SR_TXE) != RESET) && ((cr1its & USART_CR1_TXEIE) != RESET))
2557
  if (((isrflags & USART_SR_TXE) != RESET) && ((cr1its & USART_CR1_TXEIE) != RESET))
2140
  {
2558
  {
2141
    UART_Transmit_IT(huart);
2559
    UART_Transmit_IT(huart);
2142
    return;
2560
    return;
Line 2269... Line 2687...
2269
            the HAL_UART_AbortReceiveCpltCallback can be implemented in the user file.
2687
            the HAL_UART_AbortReceiveCpltCallback can be implemented in the user file.
2270
   */
2688
   */
2271
}
2689
}
2272
 
2690
 
2273
/**
2691
/**
-
 
2692
  * @brief  Reception Event Callback (Rx event notification called after use of advanced reception service).
-
 
2693
  * @param  huart UART handle
-
 
2694
  * @param  Size  Number of data available in application reception buffer (indicates a position in
-
 
2695
  *               reception buffer until which, data are available)
-
 
2696
  * @retval None
-
 
2697
  */
-
 
2698
__weak void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size)
-
 
2699
{
-
 
2700
  /* Prevent unused argument(s) compilation warning */
-
 
2701
  UNUSED(huart);
-
 
2702
  UNUSED(Size);
-
 
2703
 
-
 
2704
  /* NOTE : This function should not be modified, when the callback is needed,
-
 
2705
            the HAL_UARTEx_RxEventCallback can be implemented in the user file.
-
 
2706
   */
-
 
2707
}
-
 
2708
 
-
 
2709
/**
2274
  * @}
2710
  * @}
2275
  */
2711
  */
2276
 
2712
 
2277
/** @defgroup UART_Exported_Functions_Group3 Peripheral Control functions
2713
/** @defgroup UART_Exported_Functions_Group3 Peripheral Control functions
2278
  *  @brief   UART control functions
2714
  *  @brief   UART control functions
Line 2519... Line 2955...
2519
  huart->RxCpltCallback            = HAL_UART_RxCpltCallback;            /* Legacy weak RxCpltCallback            */
2955
  huart->RxCpltCallback            = HAL_UART_RxCpltCallback;            /* Legacy weak RxCpltCallback            */
2520
  huart->ErrorCallback             = HAL_UART_ErrorCallback;             /* Legacy weak ErrorCallback             */
2956
  huart->ErrorCallback             = HAL_UART_ErrorCallback;             /* Legacy weak ErrorCallback             */
2521
  huart->AbortCpltCallback         = HAL_UART_AbortCpltCallback;         /* Legacy weak AbortCpltCallback         */
2957
  huart->AbortCpltCallback         = HAL_UART_AbortCpltCallback;         /* Legacy weak AbortCpltCallback         */
2522
  huart->AbortTransmitCpltCallback = HAL_UART_AbortTransmitCpltCallback; /* Legacy weak AbortTransmitCpltCallback */
2958
  huart->AbortTransmitCpltCallback = HAL_UART_AbortTransmitCpltCallback; /* Legacy weak AbortTransmitCpltCallback */
2523
  huart->AbortReceiveCpltCallback  = HAL_UART_AbortReceiveCpltCallback;  /* Legacy weak AbortReceiveCpltCallback  */
2959
  huart->AbortReceiveCpltCallback  = HAL_UART_AbortReceiveCpltCallback;  /* Legacy weak AbortReceiveCpltCallback  */
-
 
2960
  huart->RxEventCallback           = HAL_UARTEx_RxEventCallback;         /* Legacy weak RxEventCallback           */
2524
 
2961
 
2525
}
2962
}
2526
#endif /* USE_HAL_UART_REGISTER_CALLBACKS */
2963
#endif /* USE_HAL_UART_REGISTER_CALLBACKS */
2527
 
2964
 
2528
/**
2965
/**
Line 2601... Line 3038...
2601
       in the UART CR3 register */
3038
       in the UART CR3 register */
2602
    CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAR);
3039
    CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAR);
2603
 
3040
 
2604
    /* At end of Rx process, restore huart->RxState to Ready */
3041
    /* At end of Rx process, restore huart->RxState to Ready */
2605
    huart->RxState = HAL_UART_STATE_READY;
3042
    huart->RxState = HAL_UART_STATE_READY;
-
 
3043
 
-
 
3044
    /* If Reception till IDLE event has been selected, Disable IDLE Interrupt */
-
 
3045
    if (huart->ReceptionType == HAL_UART_RECEPTION_TOIDLE)
-
 
3046
    {
-
 
3047
      CLEAR_BIT(huart->Instance->CR1, USART_CR1_IDLEIE);
-
 
3048
    }
2606
  }
3049
  }
-
 
3050
 
-
 
3051
  /* Check current reception Mode :
-
 
3052
     If Reception till IDLE event has been selected : use Rx Event callback */
-
 
3053
  if (huart->ReceptionType == HAL_UART_RECEPTION_TOIDLE)
-
 
3054
  {  
2607
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
3055
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
2608
  /*Call registered Rx complete callback*/
3056
    /*Call registered Rx Event callback*/
2609
  huart->RxCpltCallback(huart);
3057
    huart->RxEventCallback(huart, huart->RxXferSize);
2610
#else
3058
#else
2611
  /*Call legacy weak Rx complete callback*/
3059
    /*Call legacy weak Rx Event callback*/
2612
  HAL_UART_RxCpltCallback(huart);
3060
    HAL_UARTEx_RxEventCallback(huart, huart->RxXferSize);
2613
#endif /* USE_HAL_UART_REGISTER_CALLBACKS */
3061
#endif /* USE_HAL_UART_REGISTER_CALLBACKS */
-
 
3062
  }
-
 
3063
  else
-
 
3064
  {
-
 
3065
    /* In other cases : use Rx Complete callback */
-
 
3066
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
-
 
3067
    /*Call registered Rx complete callback*/
-
 
3068
    huart->RxCpltCallback(huart);
-
 
3069
#else
-
 
3070
    /*Call legacy weak Rx complete callback*/
-
 
3071
    HAL_UART_RxCpltCallback(huart);
-
 
3072
#endif /* USE_HAL_UART_REGISTER_CALLBACKS */
-
 
3073
  }
2614
}
3074
}
2615
 
3075
 
2616
/**
3076
/**
2617
  * @brief DMA UART receive process half complete callback
3077
  * @brief DMA UART receive process half complete callback
2618
  * @param  hdma  Pointer to a DMA_HandleTypeDef structure that contains
3078
  * @param  hdma  Pointer to a DMA_HandleTypeDef structure that contains
Line 2621... Line 3081...
2621
  */
3081
  */
2622
static void UART_DMARxHalfCplt(DMA_HandleTypeDef *hdma)
3082
static void UART_DMARxHalfCplt(DMA_HandleTypeDef *hdma)
2623
{
3083
{
2624
  UART_HandleTypeDef *huart = (UART_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
3084
  UART_HandleTypeDef *huart = (UART_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
2625
 
3085
 
-
 
3086
  /* Check current reception Mode :
-
 
3087
     If Reception till IDLE event has been selected : use Rx Event callback */
-
 
3088
  if (huart->ReceptionType == HAL_UART_RECEPTION_TOIDLE)
-
 
3089
  {
-
 
3090
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
-
 
3091
    /*Call registered Rx Event callback*/
-
 
3092
    huart->RxEventCallback(huart, huart->RxXferSize/2U);
-
 
3093
#else
-
 
3094
    /*Call legacy weak Rx Event callback*/
-
 
3095
    HAL_UARTEx_RxEventCallback(huart, huart->RxXferSize/2U);
-
 
3096
#endif /* USE_HAL_UART_REGISTER_CALLBACKS */
-
 
3097
  }
-
 
3098
  else
-
 
3099
  {
-
 
3100
    /* In other cases : use Rx Half Complete callback */
2626
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
3101
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
2627
  /*Call registered Rx Half complete callback*/
3102
    /*Call registered Rx Half complete callback*/
2628
  huart->RxHalfCpltCallback(huart);
3103
    huart->RxHalfCpltCallback(huart);
2629
#else
3104
#else
2630
  /*Call legacy weak Rx Half complete callback*/
3105
    /*Call legacy weak Rx Half complete callback*/
2631
  HAL_UART_RxHalfCpltCallback(huart);
3106
    HAL_UART_RxHalfCpltCallback(huart);
2632
#endif /* USE_HAL_UART_REGISTER_CALLBACKS */
3107
#endif /* USE_HAL_UART_REGISTER_CALLBACKS */
-
 
3108
  }
2633
}
3109
}
2634
 
3110
 
2635
/**
3111
/**
2636
  * @brief  DMA UART communication error callback.
3112
  * @brief  DMA UART communication error callback.
2637
  * @param  hdma  Pointer to a DMA_HandleTypeDef structure that contains
3113
  * @param  hdma  Pointer to a DMA_HandleTypeDef structure that contains
Line 2705... Line 3181...
2705
  }
3181
  }
2706
  return HAL_OK;
3182
  return HAL_OK;
2707
}
3183
}
2708
 
3184
 
2709
/**
3185
/**
-
 
3186
  * @brief  Start Receive operation in interrupt mode.
-
 
3187
  * @note   This function could be called by all HAL UART API providing reception in Interrupt mode.
-
 
3188
  * @note   When calling this function, parameters validity is considered as already checked,
-
 
3189
  *         i.e. Rx State, buffer address, ...
-
 
3190
  *         UART Handle is assumed as Locked.
-
 
3191
  * @param  huart UART handle.
-
 
3192
  * @param  pData Pointer to data buffer (u8 or u16 data elements).
-
 
3193
  * @param  Size  Amount of data elements (u8 or u16) to be received.
-
 
3194
  * @retval HAL status
-
 
3195
  */
-
 
3196
HAL_StatusTypeDef UART_Start_Receive_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)
-
 
3197
{
-
 
3198
  huart->pRxBuffPtr = pData;
-
 
3199
  huart->RxXferSize = Size;
-
 
3200
  huart->RxXferCount = Size;
-
 
3201
 
-
 
3202
  huart->ErrorCode = HAL_UART_ERROR_NONE;
-
 
3203
  huart->RxState = HAL_UART_STATE_BUSY_RX;
-
 
3204
 
-
 
3205
  /* Process Unlocked */
-
 
3206
  __HAL_UNLOCK(huart);
-
 
3207
 
-
 
3208
  /* Enable the UART Parity Error Interrupt */
-
 
3209
  __HAL_UART_ENABLE_IT(huart, UART_IT_PE);
-
 
3210
 
-
 
3211
  /* Enable the UART Error Interrupt: (Frame error, noise error, overrun error) */
-
 
3212
  __HAL_UART_ENABLE_IT(huart, UART_IT_ERR);
-
 
3213
 
-
 
3214
  /* Enable the UART Data Register not empty Interrupt */
-
 
3215
  __HAL_UART_ENABLE_IT(huart, UART_IT_RXNE);
-
 
3216
 
-
 
3217
  return HAL_OK;
-
 
3218
}
-
 
3219
 
-
 
3220
/**
-
 
3221
  * @brief  Start Receive operation in DMA mode.
-
 
3222
  * @note   This function could be called by all HAL UART API providing reception in DMA mode.
-
 
3223
  * @note   When calling this function, parameters validity is considered as already checked,
-
 
3224
  *         i.e. Rx State, buffer address, ...
-
 
3225
  *         UART Handle is assumed as Locked.
-
 
3226
  * @param  huart UART handle.
-
 
3227
  * @param  pData Pointer to data buffer (u8 or u16 data elements).
-
 
3228
  * @param  Size  Amount of data elements (u8 or u16) to be received.
-
 
3229
  * @retval HAL status
-
 
3230
  */
-
 
3231
HAL_StatusTypeDef UART_Start_Receive_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)
-
 
3232
{
-
 
3233
  uint32_t *tmp;
-
 
3234
 
-
 
3235
  huart->pRxBuffPtr = pData;
-
 
3236
  huart->RxXferSize = Size;
-
 
3237
 
-
 
3238
  huart->ErrorCode = HAL_UART_ERROR_NONE;
-
 
3239
  huart->RxState = HAL_UART_STATE_BUSY_RX;
-
 
3240
 
-
 
3241
  /* Set the UART DMA transfer complete callback */
-
 
3242
  huart->hdmarx->XferCpltCallback = UART_DMAReceiveCplt;
-
 
3243
 
-
 
3244
  /* Set the UART DMA Half transfer complete callback */
-
 
3245
  huart->hdmarx->XferHalfCpltCallback = UART_DMARxHalfCplt;
-
 
3246
 
-
 
3247
  /* Set the DMA error callback */
-
 
3248
  huart->hdmarx->XferErrorCallback = UART_DMAError;
-
 
3249
 
-
 
3250
  /* Set the DMA abort callback */
-
 
3251
  huart->hdmarx->XferAbortCallback = NULL;
-
 
3252
 
-
 
3253
  /* Enable the DMA stream */
-
 
3254
  tmp = (uint32_t *)&pData;
-
 
3255
  HAL_DMA_Start_IT(huart->hdmarx, (uint32_t)&huart->Instance->DR, *(uint32_t *)tmp, Size);
-
 
3256
 
-
 
3257
  /* Clear the Overrun flag just before enabling the DMA Rx request: can be mandatory for the second transfer */
-
 
3258
  __HAL_UART_CLEAR_OREFLAG(huart);
-
 
3259
 
-
 
3260
  /* Process Unlocked */
-
 
3261
  __HAL_UNLOCK(huart);
-
 
3262
 
-
 
3263
  /* Enable the UART Parity Error Interrupt */
-
 
3264
  SET_BIT(huart->Instance->CR1, USART_CR1_PEIE);
-
 
3265
 
-
 
3266
  /* Enable the UART Error Interrupt: (Frame error, noise error, overrun error) */
-
 
3267
  SET_BIT(huart->Instance->CR3, USART_CR3_EIE);
-
 
3268
 
-
 
3269
  /* Enable the DMA transfer for the receiver request by setting the DMAR bit
-
 
3270
  in the UART CR3 register */
-
 
3271
  SET_BIT(huart->Instance->CR3, USART_CR3_DMAR);
-
 
3272
 
-
 
3273
  return HAL_OK;
-
 
3274
}
-
 
3275
 
-
 
3276
/**
2710
  * @brief  End ongoing Tx transfer on UART peripheral (following error detection or Transmit completion).
3277
  * @brief  End ongoing Tx transfer on UART peripheral (following error detection or Transmit completion).
2711
  * @param  huart UART handle.
3278
  * @param  huart UART handle.
2712
  * @retval None
3279
  * @retval None
2713
  */
3280
  */
2714
static void UART_EndTxTransfer(UART_HandleTypeDef *huart)
3281
static void UART_EndTxTransfer(UART_HandleTypeDef *huart)
Line 2729... Line 3296...
2729
{
3296
{
2730
  /* Disable RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
3297
  /* Disable RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
2731
  CLEAR_BIT(huart->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE));
3298
  CLEAR_BIT(huart->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE));
2732
  CLEAR_BIT(huart->Instance->CR3, USART_CR3_EIE);
3299
  CLEAR_BIT(huart->Instance->CR3, USART_CR3_EIE);
2733
 
3300
 
-
 
3301
  /* In case of reception waiting for IDLE event, disable also the IDLE IE interrupt source */
-
 
3302
  if (huart->ReceptionType == HAL_UART_RECEPTION_TOIDLE)
-
 
3303
  {
-
 
3304
    CLEAR_BIT(huart->Instance->CR1, USART_CR1_IDLEIE);
-
 
3305
  }
-
 
3306
 
2734
  /* At end of Rx process, restore huart->RxState to Ready */
3307
  /* At end of Rx process, restore huart->RxState to Ready */
2735
  huart->RxState = HAL_UART_STATE_READY;
3308
  huart->RxState = HAL_UART_STATE_READY;
-
 
3309
  huart->ReceptionType = HAL_UART_RECEPTION_STANDARD;
2736
}
3310
}
2737
 
3311
 
2738
/**
3312
/**
2739
  * @brief  DMA UART communication abort callback, when initiated by HAL services on Error
3313
  * @brief  DMA UART communication abort callback, when initiated by HAL services on Error
2740
  *         (To be called at end of DMA Abort procedure following error occurrence).
3314
  *         (To be called at end of DMA Abort procedure following error occurrence).
Line 2789... Line 3363...
2789
  huart->ErrorCode = HAL_UART_ERROR_NONE;
3363
  huart->ErrorCode = HAL_UART_ERROR_NONE;
2790
 
3364
 
2791
  /* Restore huart->gState and huart->RxState to Ready */
3365
  /* Restore huart->gState and huart->RxState to Ready */
2792
  huart->gState  = HAL_UART_STATE_READY;
3366
  huart->gState  = HAL_UART_STATE_READY;
2793
  huart->RxState = HAL_UART_STATE_READY;
3367
  huart->RxState = HAL_UART_STATE_READY;
-
 
3368
  huart->ReceptionType = HAL_UART_RECEPTION_STANDARD;
2794
 
3369
 
2795
  /* Call user Abort complete callback */
3370
  /* Call user Abort complete callback */
2796
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
3371
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
2797
  /* Call registered Abort complete callback */
3372
  /* Call registered Abort complete callback */
2798
  huart->AbortCpltCallback(huart);
3373
  huart->AbortCpltCallback(huart);
Line 2834... Line 3409...
2834
  huart->ErrorCode = HAL_UART_ERROR_NONE;
3409
  huart->ErrorCode = HAL_UART_ERROR_NONE;
2835
 
3410
 
2836
  /* Restore huart->gState and huart->RxState to Ready */
3411
  /* Restore huart->gState and huart->RxState to Ready */
2837
  huart->gState  = HAL_UART_STATE_READY;
3412
  huart->gState  = HAL_UART_STATE_READY;
2838
  huart->RxState = HAL_UART_STATE_READY;
3413
  huart->RxState = HAL_UART_STATE_READY;
-
 
3414
  huart->ReceptionType = HAL_UART_RECEPTION_STANDARD;
2839
 
3415
 
2840
  /* Call user Abort complete callback */
3416
  /* Call user Abort complete callback */
2841
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
3417
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
2842
  /* Call registered Abort complete callback */
3418
  /* Call registered Abort complete callback */
2843
  huart->AbortCpltCallback(huart);
3419
  huart->AbortCpltCallback(huart);
Line 2890... Line 3466...
2890
 
3466
 
2891
  huart->RxXferCount = 0x00U;
3467
  huart->RxXferCount = 0x00U;
2892
 
3468
 
2893
  /* Restore huart->RxState to Ready */
3469
  /* Restore huart->RxState to Ready */
2894
  huart->RxState = HAL_UART_STATE_READY;
3470
  huart->RxState = HAL_UART_STATE_READY;
-
 
3471
  huart->ReceptionType = HAL_UART_RECEPTION_STANDARD;
2895
 
3472
 
2896
  /* Call user Abort complete callback */
3473
  /* Call user Abort complete callback */
2897
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
3474
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
2898
  /* Call registered Abort Receive Complete Callback */
3475
  /* Call registered Abort Receive Complete Callback */
2899
  huart->AbortReceiveCpltCallback(huart);
3476
  huart->AbortReceiveCpltCallback(huart);
Line 2914... Line 3491...
2914
  uint16_t *tmp;
3491
  uint16_t *tmp;
2915
 
3492
 
2916
  /* Check that a Tx process is ongoing */
3493
  /* Check that a Tx process is ongoing */
2917
  if (huart->gState == HAL_UART_STATE_BUSY_TX)
3494
  if (huart->gState == HAL_UART_STATE_BUSY_TX)
2918
  {
3495
  {
2919
    if (huart->Init.WordLength == UART_WORDLENGTH_9B)
3496
    if ((huart->Init.WordLength == UART_WORDLENGTH_9B) && (huart->Init.Parity == UART_PARITY_NONE))
2920
    {
3497
    {
2921
      tmp = (uint16_t *) huart->pTxBuffPtr;
3498
      tmp = (uint16_t *) huart->pTxBuffPtr;
2922
      huart->Instance->DR = (uint16_t)(*tmp & (uint16_t)0x01FF);
3499
      huart->Instance->DR = (uint16_t)(*tmp & (uint16_t)0x01FF);
2923
      if (huart->Init.Parity == UART_PARITY_NONE)
-
 
2924
      {
-
 
2925
        huart->pTxBuffPtr += 2U;
3500
      huart->pTxBuffPtr += 2U;
2926
      }
-
 
2927
      else
-
 
2928
      {
-
 
2929
        huart->pTxBuffPtr += 1U;
-
 
2930
      }
-
 
2931
    }
3501
    }
2932
    else
3502
    else
2933
    {
3503
    {
2934
      huart->Instance->DR = (uint8_t)(*huart->pTxBuffPtr++ & (uint8_t)0x00FF);
3504
      huart->Instance->DR = (uint8_t)(*huart->pTxBuffPtr++ & (uint8_t)0x00FF);
2935
    }
3505
    }
Line 2981... Line 3551...
2981
  *                the configuration information for the specified UART module.
3551
  *                the configuration information for the specified UART module.
2982
  * @retval HAL status
3552
  * @retval HAL status
2983
  */
3553
  */
2984
static HAL_StatusTypeDef UART_Receive_IT(UART_HandleTypeDef *huart)
3554
static HAL_StatusTypeDef UART_Receive_IT(UART_HandleTypeDef *huart)
2985
{
3555
{
-
 
3556
  uint8_t  *pdata8bits;
2986
  uint16_t *tmp;
3557
  uint16_t *pdata16bits;
2987
 
3558
 
2988
  /* Check that a Rx process is ongoing */
3559
  /* Check that a Rx process is ongoing */
2989
  if (huart->RxState == HAL_UART_STATE_BUSY_RX)
3560
  if (huart->RxState == HAL_UART_STATE_BUSY_RX)
2990
  {
3561
  {
2991
    if (huart->Init.WordLength == UART_WORDLENGTH_9B)
3562
    if ((huart->Init.WordLength == UART_WORDLENGTH_9B) && (huart->Init.Parity == UART_PARITY_NONE))
2992
    {
3563
    {
2993
      tmp = (uint16_t *) huart->pRxBuffPtr;
3564
      pdata8bits  = NULL;
2994
      if (huart->Init.Parity == UART_PARITY_NONE)
-
 
2995
      {
-
 
2996
        *tmp = (uint16_t)(huart->Instance->DR & (uint16_t)0x01FF);
3565
      pdata16bits = (uint16_t *) huart->pRxBuffPtr;
2997
        huart->pRxBuffPtr += 2U;
-
 
2998
      }
-
 
2999
      else
-
 
3000
      {
-
 
3001
        *tmp = (uint16_t)(huart->Instance->DR & (uint16_t)0x00FF);
3566
      *pdata16bits = (uint16_t)(huart->Instance->DR & (uint16_t)0x01FF);
3002
        huart->pRxBuffPtr += 1U;
3567
      huart->pRxBuffPtr += 2U;
3003
      }
-
 
3004
    }
3568
    }
3005
    else
3569
    else
3006
    {
3570
    {
3007
      if (huart->Init.Parity == UART_PARITY_NONE)
3571
      pdata8bits = (uint8_t *) huart->pRxBuffPtr;
-
 
3572
      pdata16bits  = NULL;
-
 
3573
 
-
 
3574
      if ((huart->Init.WordLength == UART_WORDLENGTH_9B) || ((huart->Init.WordLength == UART_WORDLENGTH_8B) && (huart->Init.Parity == UART_PARITY_NONE)))
3008
      {
3575
      {
3009
        *huart->pRxBuffPtr++ = (uint8_t)(huart->Instance->DR & (uint8_t)0x00FF);
3576
        *pdata8bits = (uint8_t)(huart->Instance->DR & (uint8_t)0x00FF);
3010
      }
3577
      }
3011
      else
3578
      else
3012
      {
3579
      {
3013
        *huart->pRxBuffPtr++ = (uint8_t)(huart->Instance->DR & (uint8_t)0x007F);
3580
        *pdata8bits = (uint8_t)(huart->Instance->DR & (uint8_t)0x007F);
3014
      }
3581
      }
-
 
3582
      huart->pRxBuffPtr += 1U;
3015
    }
3583
    }
3016
 
3584
 
3017
    if (--huart->RxXferCount == 0U)
3585
    if (--huart->RxXferCount == 0U)
3018
    {
3586
    {
3019
      /* Disable the UART Data Register not empty Interrupt */
3587
      /* Disable the UART Data Register not empty Interrupt */
Line 3026... Line 3594...
3026
      __HAL_UART_DISABLE_IT(huart, UART_IT_ERR);
3594
      __HAL_UART_DISABLE_IT(huart, UART_IT_ERR);
3027
 
3595
 
3028
      /* Rx process is completed, restore huart->RxState to Ready */
3596
      /* Rx process is completed, restore huart->RxState to Ready */
3029
      huart->RxState = HAL_UART_STATE_READY;
3597
      huart->RxState = HAL_UART_STATE_READY;
3030
 
3598
 
-
 
3599
      /* Check current reception Mode :
-
 
3600
         If Reception till IDLE event has been selected : */
-
 
3601
      if (huart->ReceptionType == HAL_UART_RECEPTION_TOIDLE)
-
 
3602
      {
-
 
3603
        /* Set reception type to Standard */
-
 
3604
        huart->ReceptionType = HAL_UART_RECEPTION_STANDARD;
-
 
3605
 
-
 
3606
        /* Disable IDLE interrupt */
-
 
3607
        CLEAR_BIT(huart->Instance->CR1, USART_CR1_IDLEIE);
-
 
3608
 
-
 
3609
        /* Check if IDLE flag is set */
-
 
3610
        if (__HAL_UART_GET_FLAG(huart, UART_FLAG_IDLE))
-
 
3611
        {
-
 
3612
          /* Clear IDLE flag in ISR */
-
 
3613
          __HAL_UART_CLEAR_IDLEFLAG(huart);
-
 
3614
        }
-
 
3615
 
3031
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
3616
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
-
 
3617
        /*Call registered Rx Event callback*/
-
 
3618
        huart->RxEventCallback(huart, huart->RxXferSize);
-
 
3619
#else
-
 
3620
        /*Call legacy weak Rx Event callback*/
-
 
3621
        HAL_UARTEx_RxEventCallback(huart, huart->RxXferSize);
-
 
3622
#endif
-
 
3623
      }
-
 
3624
      else
-
 
3625
      {
-
 
3626
       /* Standard reception API called */
-
 
3627
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)                
3032
      /*Call registered Rx complete callback*/
3628
       /*Call registered Rx complete callback*/
3033
      huart->RxCpltCallback(huart);
3629
       huart->RxCpltCallback(huart);
3034
#else
3630
#else
3035
      /*Call legacy weak Rx complete callback*/
3631
       /*Call legacy weak Rx complete callback*/
3036
      HAL_UART_RxCpltCallback(huart);
3632
       HAL_UART_RxCpltCallback(huart);
3037
#endif /* USE_HAL_UART_REGISTER_CALLBACKS */
3633
#endif /* USE_HAL_UART_REGISTER_CALLBACKS */
-
 
3634
      }
3038
 
3635
 
3039
      return HAL_OK;
3636
      return HAL_OK;
3040
    }
3637
    }
3041
    return HAL_OK;
3638
    return HAL_OK;
3042
  }
3639
  }