STM32L4xx_HAL_Driver  1.14.0
stm32l4xx_hal_smartcard_ex.c
Go to the documentation of this file.
1 
43 /* Includes ------------------------------------------------------------------*/
44 #include "stm32l4xx_hal.h"
45 
54 #ifdef HAL_SMARTCARD_MODULE_ENABLED
55 
56 /* Private typedef -----------------------------------------------------------*/
57 /* Private define ------------------------------------------------------------*/
58 /* UART RX FIFO depth */
59 #define RX_FIFO_DEPTH 8U
60 
61 /* UART TX FIFO depth */
62 #define TX_FIFO_DEPTH 8U
63 
64 /* Private macros ------------------------------------------------------------*/
65 /* Private variables ---------------------------------------------------------*/
66 /* Private function prototypes -----------------------------------------------*/
67 #if defined(USART_CR1_FIFOEN)
69 
70 #endif /* USART_CR1_FIFOEN */
71 /* Exported functions --------------------------------------------------------*/
100 void HAL_SMARTCARDEx_BlockLength_Config(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t BlockLength)
101 {
102  MODIFY_REG(hsmartcard->Instance->RTOR, USART_RTOR_BLEN, ((uint32_t)BlockLength << USART_RTOR_BLEN_Pos));
103 }
104 
112 void HAL_SMARTCARDEx_TimeOut_Config(SMARTCARD_HandleTypeDef *hsmartcard, uint32_t TimeOutValue)
113 {
114  assert_param(IS_SMARTCARD_TIMEOUT_VALUE(hsmartcard->Init.TimeOutValue));
115  MODIFY_REG(hsmartcard->Instance->RTOR, USART_RTOR_RTO, TimeOutValue);
116 }
117 
124 {
125  if (hsmartcard->gState == HAL_SMARTCARD_STATE_READY)
126  {
127  /* Process Locked */
128  __HAL_LOCK(hsmartcard);
129 
130  hsmartcard->gState = HAL_SMARTCARD_STATE_BUSY;
131 
132  /* Set the USART RTOEN bit */
133  SET_BIT(hsmartcard->Instance->CR2, USART_CR2_RTOEN);
134 
135  hsmartcard->gState = HAL_SMARTCARD_STATE_READY;
136 
137  /* Process Unlocked */
138  __HAL_UNLOCK(hsmartcard);
139 
140  return HAL_OK;
141  }
142  else
143  {
144  return HAL_BUSY;
145  }
146 }
147 
154 {
155  if (hsmartcard->gState == HAL_SMARTCARD_STATE_READY)
156  {
157  /* Process Locked */
158  __HAL_LOCK(hsmartcard);
159 
160  hsmartcard->gState = HAL_SMARTCARD_STATE_BUSY;
161 
162  /* Clear the USART RTOEN bit */
163  CLEAR_BIT(hsmartcard->Instance->CR2, USART_CR2_RTOEN);
164 
165  hsmartcard->gState = HAL_SMARTCARD_STATE_READY;
166 
167  /* Process Unlocked */
168  __HAL_UNLOCK(hsmartcard);
169 
170  return HAL_OK;
171  }
172  else
173  {
174  return HAL_BUSY;
175  }
176 }
177 
200 #if defined(USART_CR1_FIFOEN)
201 
208 {
209  /* Prevent unused argument(s) compilation warning */
210  UNUSED(hsmartcard);
211 
212  /* NOTE : This function should not be modified, when the callback is needed,
213  the HAL_SMARTCARDEx_RxFifoFullCallback can be implemented in the user file.
214  */
215 }
216 
224 {
225  /* Prevent unused argument(s) compilation warning */
226  UNUSED(hsmartcard);
227 
228  /* NOTE : This function should not be modified, when the callback is needed,
229  the HAL_SMARTCARDEx_TxFifoEmptyCallback can be implemented in the user file.
230  */
231 }
232 
233 #endif /* USART_CR1_FIFOEN */
234 
255 #if defined(USART_CR1_FIFOEN)
256 
262 {
263  uint32_t tmpcr1;
264 
265  /* Check parameters */
266  assert_param(IS_UART_FIFO_INSTANCE(hsmartcard->Instance));
267 
268  /* Process Locked */
269  __HAL_LOCK(hsmartcard);
270 
271  hsmartcard->gState = HAL_SMARTCARD_STATE_BUSY;
272 
273  /* Save actual SMARTCARD configuration */
274  tmpcr1 = READ_REG(hsmartcard->Instance->CR1);
275 
276  /* Disable SMARTCARD */
277  __HAL_SMARTCARD_DISABLE(hsmartcard);
278 
279  /* Enable FIFO mode */
280  SET_BIT(tmpcr1, USART_CR1_FIFOEN);
281  hsmartcard->FifoMode = SMARTCARD_FIFOMODE_ENABLE;
282 
283  /* Restore SMARTCARD configuration */
284  WRITE_REG(hsmartcard->Instance->CR1, tmpcr1);
285 
286  /* Determine the number of data to process during RX/TX ISR execution */
287  SMARTCARDEx_SetNbDataToProcess(hsmartcard);
288 
289  hsmartcard->gState = HAL_SMARTCARD_STATE_READY;
290 
291  /* Process Unlocked */
292  __HAL_UNLOCK(hsmartcard);
293 
294  return HAL_OK;
295 }
296 
303 {
304  uint32_t tmpcr1;
305 
306  /* Check parameters */
307  assert_param(IS_UART_FIFO_INSTANCE(hsmartcard->Instance));
308 
309  /* Process Locked */
310  __HAL_LOCK(hsmartcard);
311 
312  hsmartcard->gState = HAL_SMARTCARD_STATE_BUSY;
313 
314  /* Save actual SMARTCARD configuration */
315  tmpcr1 = READ_REG(hsmartcard->Instance->CR1);
316 
317  /* Disable SMARTCARD */
318  __HAL_SMARTCARD_DISABLE(hsmartcard);
319 
320  /* Enable FIFO mode */
321  CLEAR_BIT(tmpcr1, USART_CR1_FIFOEN);
322  hsmartcard->FifoMode = SMARTCARD_FIFOMODE_DISABLE;
323 
324  /* Restore SMARTCARD configuration */
325  WRITE_REG(hsmartcard->Instance->CR1, tmpcr1);
326 
327  hsmartcard->gState = HAL_SMARTCARD_STATE_READY;
328 
329  /* Process Unlocked */
330  __HAL_UNLOCK(hsmartcard);
331 
332  return HAL_OK;
333 }
334 
348 HAL_StatusTypeDef HAL_SMARTCARDEx_SetTxFifoThreshold(SMARTCARD_HandleTypeDef *hsmartcard, uint32_t Threshold)
349 {
350  uint32_t tmpcr1;
351 
352  /* Check parameters */
353  assert_param(IS_UART_FIFO_INSTANCE(hsmartcard->Instance));
354  assert_param(IS_SMARTCARD_TXFIFO_THRESHOLD(Threshold));
355 
356  /* Process Locked */
357  __HAL_LOCK(hsmartcard);
358 
359  hsmartcard->gState = HAL_SMARTCARD_STATE_BUSY;
360 
361  /* Save actual SMARTCARD configuration */
362  tmpcr1 = READ_REG(hsmartcard->Instance->CR1);
363 
364  /* Disable SMARTCARD */
365  __HAL_SMARTCARD_DISABLE(hsmartcard);
366 
367  /* Update TX threshold configuration */
368  MODIFY_REG(hsmartcard->Instance->CR3, USART_CR3_TXFTCFG, Threshold);
369 
370  /* Determine the number of data to process during RX/TX ISR execution */
371  SMARTCARDEx_SetNbDataToProcess(hsmartcard);
372 
373  /* Restore SMARTCARD configuration */
374  MODIFY_REG(hsmartcard->Instance->CR1, USART_CR1_UE, tmpcr1);
375 
376  hsmartcard->gState = HAL_SMARTCARD_STATE_READY;
377 
378  /* Process Unlocked */
379  __HAL_UNLOCK(hsmartcard);
380 
381  return HAL_OK;
382 }
383 
397 HAL_StatusTypeDef HAL_SMARTCARDEx_SetRxFifoThreshold(SMARTCARD_HandleTypeDef *hsmartcard, uint32_t Threshold)
398 {
399  uint32_t tmpcr1;
400 
401  /* Check parameters */
402  assert_param(IS_UART_FIFO_INSTANCE(hsmartcard->Instance));
403  assert_param(IS_SMARTCARD_RXFIFO_THRESHOLD(Threshold));
404 
405  /* Process Locked */
406  __HAL_LOCK(hsmartcard);
407 
408  hsmartcard->gState = HAL_SMARTCARD_STATE_BUSY;
409 
410  /* Save actual SMARTCARD configuration */
411  tmpcr1 = READ_REG(hsmartcard->Instance->CR1);
412 
413  /* Disable SMARTCARD */
414  __HAL_SMARTCARD_DISABLE(hsmartcard);
415 
416  /* Update RX threshold configuration */
417  MODIFY_REG(hsmartcard->Instance->CR3, USART_CR3_RXFTCFG, Threshold);
418 
419  /* Determine the number of data to process during RX/TX ISR execution */
420  SMARTCARDEx_SetNbDataToProcess(hsmartcard);
421 
422  /* Restore SMARTCARD configuration */
423  MODIFY_REG(hsmartcard->Instance->CR1, USART_CR1_UE, tmpcr1);
424 
425  hsmartcard->gState = HAL_SMARTCARD_STATE_READY;
426 
427  /* Process Unlocked */
428  __HAL_UNLOCK(hsmartcard);
429 
430  return HAL_OK;
431 }
432 #endif /* USART_CR1_FIFOEN */
433 
446 #if defined(USART_CR1_FIFOEN)
447 
455 {
456  uint8_t rx_fifo_depth;
457  uint8_t tx_fifo_depth;
458  uint8_t rx_fifo_threshold;
459  uint8_t tx_fifo_threshold;
460  /* 2 0U/1U added for MISRAC2012-Rule-18.1_b and MISRAC2012-Rule-18.1_d */
461  uint8_t numerator[] = {1U, 1U, 1U, 3U, 7U, 1U, 0U, 0U};
462  uint8_t denominator[] = {8U, 4U, 2U, 4U, 8U, 1U, 1U, 1U};
463 
464  if (hsmartcard->FifoMode == SMARTCARD_FIFOMODE_DISABLE)
465  {
466  hsmartcard->NbTxDataToProcess = 1U;
467  hsmartcard->NbRxDataToProcess = 1U;
468  }
469  else
470  {
471  rx_fifo_depth = RX_FIFO_DEPTH;
472  tx_fifo_depth = TX_FIFO_DEPTH;
473  rx_fifo_threshold = (uint8_t)(READ_BIT(hsmartcard->Instance->CR3, USART_CR3_RXFTCFG) >> USART_CR3_RXFTCFG_Pos);
474  tx_fifo_threshold = (uint8_t)(READ_BIT(hsmartcard->Instance->CR3, USART_CR3_TXFTCFG) >> USART_CR3_TXFTCFG_Pos);
475  hsmartcard->NbTxDataToProcess = ((uint16_t)tx_fifo_depth * numerator[tx_fifo_threshold]) / (uint16_t)denominator[tx_fifo_threshold];
476  hsmartcard->NbRxDataToProcess = ((uint16_t)rx_fifo_depth * numerator[rx_fifo_threshold]) / (uint16_t)denominator[rx_fifo_threshold];
477  }
478 }
479 
480 #endif /* USART_CR1_FIFOEN */
481 
485 #endif /* HAL_SMARTCARD_MODULE_ENABLED */
486 
495 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
__IO HAL_SMARTCARD_StateTypeDef gState
void HAL_SMARTCARDEx_TxFifoEmptyCallback(SMARTCARD_HandleTypeDef *hsmartcard)
SMARTCARD TX Fifo empty callback.
void HAL_SMARTCARDEx_BlockLength_Config(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t BlockLength)
Update on the fly the SMARTCARD block length in RTOR register.
This file contains all the functions prototypes for the HAL module driver.
HAL_StatusTypeDef HAL_SMARTCARDEx_EnableFifoMode(SMARTCARD_HandleTypeDef *hsmartcard)
Enable the FIFO mode.
__HAL_UNLOCK(hrtc)
HAL_StatusTypeDef HAL_SMARTCARDEx_SetRxFifoThreshold(SMARTCARD_HandleTypeDef *hsmartcard, uint32_t Threshold)
Set the RXFIFO threshold.
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
__HAL_LOCK(hrtc)
return HAL_OK
HAL_StatusTypeDef HAL_SMARTCARDEx_DisableFifoMode(SMARTCARD_HandleTypeDef *hsmartcard)
Disable the FIFO mode.
HAL_StatusTypeDef HAL_SMARTCARDEx_SetTxFifoThreshold(SMARTCARD_HandleTypeDef *hsmartcard, uint32_t Threshold)
Set the TXFIFO threshold.
void HAL_SMARTCARDEx_RxFifoFullCallback(SMARTCARD_HandleTypeDef *hsmartcard)
SMARTCARD RX Fifo full callback.
MODIFY_REG(hrtc->Instance->CR, RTC_CR_WUCKSEL,(uint32_t) WakeUpClock)
static void SMARTCARDEx_SetNbDataToProcess(SMARTCARD_HandleTypeDef *hsmartcard)
Calculate the number of data to process in RX/TX ISR.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))
SMARTCARD handle Structure definition.
HAL_StatusTypeDef HAL_SMARTCARDEx_DisableReceiverTimeOut(SMARTCARD_HandleTypeDef *hsmartcard)
Disable the SMARTCARD receiver timeout feature.
HAL_StatusTypeDef HAL_SMARTCARDEx_EnableReceiverTimeOut(SMARTCARD_HandleTypeDef *hsmartcard)
Enable the SMARTCARD receiver timeout feature.
void HAL_SMARTCARDEx_TimeOut_Config(SMARTCARD_HandleTypeDef *hsmartcard, uint32_t TimeOutValue)
Update on the fly the receiver timeout value in RTOR register.