Subversion Repositories FuelGauge

Rev

Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2 Rev 6
Line 33... Line 33...
33
             (+++) Declare a DMA handle structure for the Tx/Rx channel.
33
             (+++) Declare a DMA handle structure for the Tx/Rx channel.
34
             (+++) Enable the DMAx interface clock.
34
             (+++) Enable the DMAx interface clock.
35
             (+++) Configure the declared DMA handle structure with the required Tx/Rx parameters.
35
             (+++) Configure the declared DMA handle structure with the required Tx/Rx parameters.
36
             (+++) Configure the DMA Tx/Rx channel.
36
             (+++) Configure the DMA Tx/Rx channel.
37
             (+++) Associate the initialized DMA handle to the SMARTCARD DMA Tx/Rx handle.
37
             (+++) Associate the initialized DMA handle to the SMARTCARD DMA Tx/Rx handle.
38
             (+++) Configure the priority and enable the NVIC for the transfer complete interrupt on the DMA Tx/Rx channel.
38
             (+++) Configure the priority and enable the NVIC for the transfer complete
-
 
39
                   interrupt on the DMA Tx/Rx channel.
39
 
40
 
40
    (#) Program the Baud Rate, Parity, Mode(Receiver/Transmitter), clock enabling/disabling and accordingly,
41
    (#) Program the Baud Rate, Parity, Mode(Receiver/Transmitter), clock enabling/disabling and accordingly,
41
        the clock parameters (parity, phase, last bit), prescaler value, guard time and NACK on transmission
42
        the clock parameters (parity, phase, last bit), prescaler value, guard time and NACK on transmission
42
        error enabling or disabling in the hsmartcard handle Init structure.
43
        error enabling or disabling in the hsmartcard handle Init structure.
43
 
44
 
Line 105... Line 106...
105
    [..]
106
    [..]
106
    The compilation define USE_HAL_SMARTCARD_REGISTER_CALLBACKS when set to 1
107
    The compilation define USE_HAL_SMARTCARD_REGISTER_CALLBACKS when set to 1
107
    allows the user to configure dynamically the driver callbacks.
108
    allows the user to configure dynamically the driver callbacks.
108
 
109
 
109
    [..]
110
    [..]
110
    Use Function @ref HAL_SMARTCARD_RegisterCallback() to register a user callback.
111
    Use Function HAL_SMARTCARD_RegisterCallback() to register a user callback.
111
    Function @ref HAL_SMARTCARD_RegisterCallback() allows to register following callbacks:
112
    Function HAL_SMARTCARD_RegisterCallback() allows to register following callbacks:
112
    (+) TxCpltCallback            : Tx Complete Callback.
113
    (+) TxCpltCallback            : Tx Complete Callback.
113
    (+) RxCpltCallback            : Rx Complete Callback.
114
    (+) RxCpltCallback            : Rx Complete Callback.
114
    (+) ErrorCallback             : Error Callback.
115
    (+) ErrorCallback             : Error Callback.
115
    (+) AbortCpltCallback         : Abort Complete Callback.
116
    (+) AbortCpltCallback         : Abort Complete Callback.
116
    (+) AbortTransmitCpltCallback : Abort Transmit Complete Callback.
117
    (+) AbortTransmitCpltCallback : Abort Transmit Complete Callback.
Line 119... Line 120...
119
    (+) MspDeInitCallback         : SMARTCARD MspDeInit.
120
    (+) MspDeInitCallback         : SMARTCARD MspDeInit.
120
    This function takes as parameters the HAL peripheral handle, the Callback ID
121
    This function takes as parameters the HAL peripheral handle, the Callback ID
121
    and a pointer to the user callback function.
122
    and a pointer to the user callback function.
122
 
123
 
123
    [..]
124
    [..]
124
    Use function @ref HAL_SMARTCARD_UnRegisterCallback() to reset a callback to the default
125
    Use function HAL_SMARTCARD_UnRegisterCallback() to reset a callback to the default
125
    weak (surcharged) function.
126
    weak (surcharged) function.
126
    @ref HAL_SMARTCARD_UnRegisterCallback() takes as parameters the HAL peripheral handle,
127
    HAL_SMARTCARD_UnRegisterCallback() takes as parameters the HAL peripheral handle,
127
    and the Callback ID.
128
    and the Callback ID.
128
    This function allows to reset following callbacks:
129
    This function allows to reset following callbacks:
129
    (+) TxCpltCallback            : Tx Complete Callback.
130
    (+) TxCpltCallback            : Tx Complete Callback.
130
    (+) RxCpltCallback            : Rx Complete Callback.
131
    (+) RxCpltCallback            : Rx Complete Callback.
131
    (+) ErrorCallback             : Error Callback.
132
    (+) ErrorCallback             : Error Callback.
Line 134... Line 135...
134
    (+) AbortReceiveCpltCallback  : Abort Receive Complete Callback.
135
    (+) AbortReceiveCpltCallback  : Abort Receive Complete Callback.
135
    (+) MspInitCallback           : SMARTCARD MspInit.
136
    (+) MspInitCallback           : SMARTCARD MspInit.
136
    (+) MspDeInitCallback         : SMARTCARD MspDeInit.
137
    (+) MspDeInitCallback         : SMARTCARD MspDeInit.
137
 
138
 
138
    [..]
139
    [..]
139
    By default, after the @ref HAL_SMARTCARD_Init() and when the state is HAL_SMARTCARD_STATE_RESET
140
    By default, after the HAL_SMARTCARD_Init() and when the state is HAL_SMARTCARD_STATE_RESET
140
    all callbacks are set to the corresponding weak (surcharged) functions:
141
    all callbacks are set to the corresponding weak (surcharged) functions:
141
    examples @ref HAL_SMARTCARD_TxCpltCallback(), @ref HAL_SMARTCARD_RxCpltCallback().
142
    examples HAL_SMARTCARD_TxCpltCallback(), HAL_SMARTCARD_RxCpltCallback().
142
    Exception done for MspInit and MspDeInit functions that are respectively
143
    Exception done for MspInit and MspDeInit functions that are respectively
143
    reset to the legacy weak (surcharged) functions in the @ref HAL_SMARTCARD_Init()
144
    reset to the legacy weak (surcharged) functions in the HAL_SMARTCARD_Init()
144
    and @ref HAL_SMARTCARD_DeInit() only when these callbacks are null (not registered beforehand).
145
    and HAL_SMARTCARD_DeInit() only when these callbacks are null (not registered beforehand).
145
    If not, MspInit or MspDeInit are not null, the @ref HAL_SMARTCARD_Init() and @ref HAL_SMARTCARD_DeInit()
146
    If not, MspInit or MspDeInit are not null, the HAL_SMARTCARD_Init() and HAL_SMARTCARD_DeInit()
146
    keep and use the user MspInit/MspDeInit callbacks (registered beforehand).
147
    keep and use the user MspInit/MspDeInit callbacks (registered beforehand).
147
 
148
 
148
    [..]
149
    [..]
149
    Callbacks can be registered/unregistered in HAL_SMARTCARD_STATE_READY state only.
150
    Callbacks can be registered/unregistered in HAL_SMARTCARD_STATE_READY state only.
150
    Exception done MspInit/MspDeInit that can be registered/unregistered
151
    Exception done MspInit/MspDeInit that can be registered/unregistered
151
    in HAL_SMARTCARD_STATE_READY or HAL_SMARTCARD_STATE_RESET state, thus registered (user)
152
    in HAL_SMARTCARD_STATE_READY or HAL_SMARTCARD_STATE_RESET state, thus registered (user)
152
    MspInit/DeInit callbacks can be used during the Init/DeInit.
153
    MspInit/DeInit callbacks can be used during the Init/DeInit.
153
    In that case first register the MspInit/MspDeInit user callbacks
154
    In that case first register the MspInit/MspDeInit user callbacks
154
    using @ref HAL_SMARTCARD_RegisterCallback() before calling @ref HAL_SMARTCARD_DeInit()
155
    using HAL_SMARTCARD_RegisterCallback() before calling HAL_SMARTCARD_DeInit()
155
    or @ref HAL_SMARTCARD_Init() function.
156
    or HAL_SMARTCARD_Init() function.
156
 
157
 
157
    [..]
158
    [..]
158
    When The compilation define USE_HAL_SMARTCARD_REGISTER_CALLBACKS is set to 0 or
159
    When The compilation define USE_HAL_SMARTCARD_REGISTER_CALLBACKS is set to 0 or
159
    not defined, the callback registration feature is not available
160
    not defined, the callback registration feature is not available
160
    and weak (surcharged) callbacks are used.
161
    and weak (surcharged) callbacks are used.
Line 192... Line 193...
192
/* Private typedef -----------------------------------------------------------*/
193
/* Private typedef -----------------------------------------------------------*/
193
/* Private define ------------------------------------------------------------*/
194
/* Private define ------------------------------------------------------------*/
194
/** @defgroup SMARTCARD_Private_Constants SMARTCARD Private Constants
195
/** @defgroup SMARTCARD_Private_Constants SMARTCARD Private Constants
195
  * @{
196
  * @{
196
  */
197
  */
197
#define SMARTCARD_TEACK_REACK_TIMEOUT               1000U      /*!< SMARTCARD TX or RX enable acknowledge time-out value  */
198
#define SMARTCARD_TEACK_REACK_TIMEOUT  1000U       /*!< SMARTCARD TX or RX enable acknowledge time-out value */
198
 
199
 
199
#define USART_CR1_FIELDS      ((uint32_t)(USART_CR1_M | USART_CR1_PCE | USART_CR1_PS   | \
200
#define USART_CR1_FIELDS  ((uint32_t)(USART_CR1_M | USART_CR1_PCE | USART_CR1_PS | USART_CR1_TE | \
200
                                          USART_CR1_TE | USART_CR1_RE | USART_CR1_OVER8))             /*!< USART CR1 fields of parameters set by SMARTCARD_SetConfig API */
201
                                        USART_CR1_RE | USART_CR1_OVER8)) /*!< USART CR1 fields of parameters set by SMARTCARD_SetConfig API */
201
 
202
 
202
#define USART_CR2_CLK_FIELDS  ((uint32_t)(USART_CR2_CLKEN | USART_CR2_CPOL | USART_CR2_CPHA | \
203
#define USART_CR2_CLK_FIELDS  ((uint32_t)(USART_CR2_CLKEN | USART_CR2_CPOL | \
203
                                          USART_CR2_LBCL))                                            /*!< SMARTCARD clock-related USART CR2 fields of parameters */
204
                                          USART_CR2_CPHA | USART_CR2_LBCL)) /*!< SMARTCARD clock-related USART CR2 fields of parameters */
204
 
205
 
-
 
206
#define USART_CR2_FIELDS  ((uint32_t)(USART_CR2_RTOEN | USART_CR2_CLK_FIELDS | \
205
#define USART_CR2_FIELDS      ((uint32_t)(USART_CR2_RTOEN | USART_CR2_CLK_FIELDS | USART_CR2_STOP))   /*!< USART CR2 fields of parameters set by SMARTCARD_SetConfig API */
207
                                      USART_CR2_STOP)) /*!< USART CR2 fields of parameters set by SMARTCARD_SetConfig API */
206
 
208
 
-
 
209
#define USART_CR3_FIELDS  ((uint32_t)(USART_CR3_ONEBIT | USART_CR3_NACK | \
207
#define USART_CR3_FIELDS      ((uint32_t)(USART_CR3_ONEBIT | USART_CR3_NACK | USART_CR3_SCARCNT))     /*!< USART CR3 fields of parameters set by SMARTCARD_SetConfig API */
210
                                      USART_CR3_SCARCNT)) /*!< USART CR3 fields of parameters set by SMARTCARD_SetConfig API */
208
 
211
 
209
#define USART_BRR_MIN    0x10U        /*!< USART BRR minimum authorized value */
212
#define USART_BRR_MIN  0x10U        /*!< USART BRR minimum authorized value */
210
 
213
 
211
#define USART_BRR_MAX    0x0000FFFFU  /*!< USART BRR maximum authorized value */
214
#define USART_BRR_MAX  0x0000FFFFU  /*!< USART BRR maximum authorized value */
212
/**
215
/**
213
  * @}
216
  * @}
214
  */
217
  */
215
 
218
 
216
/* Private macros ------------------------------------------------------------*/
219
/* Private macros ------------------------------------------------------------*/
Line 471... Line 474...
471
  *           @arg @ref HAL_SMARTCARD_MSPDEINIT_CB_ID MspDeInit Callback ID
474
  *           @arg @ref HAL_SMARTCARD_MSPDEINIT_CB_ID MspDeInit Callback ID
472
  * @param  pCallback pointer to the Callback function
475
  * @param  pCallback pointer to the Callback function
473
  * @retval HAL status
476
  * @retval HAL status
474
  */
477
  */
475
HAL_StatusTypeDef HAL_SMARTCARD_RegisterCallback(SMARTCARD_HandleTypeDef *hsmartcard,
478
HAL_StatusTypeDef HAL_SMARTCARD_RegisterCallback(SMARTCARD_HandleTypeDef *hsmartcard,
476
                                                 HAL_SMARTCARD_CallbackIDTypeDef CallbackID, pSMARTCARD_CallbackTypeDef pCallback)
479
                                                 HAL_SMARTCARD_CallbackIDTypeDef CallbackID,
-
 
480
                                                 pSMARTCARD_CallbackTypeDef pCallback)
477
{
481
{
478
  HAL_StatusTypeDef status = HAL_OK;
482
  HAL_StatusTypeDef status = HAL_OK;
479
 
483
 
480
  if (pCallback == NULL)
484
  if (pCallback == NULL)
481
  {
485
  {
Line 597... Line 601...
597
  if (HAL_SMARTCARD_STATE_READY == hsmartcard->gState)
601
  if (HAL_SMARTCARD_STATE_READY == hsmartcard->gState)
598
  {
602
  {
599
    switch (CallbackID)
603
    switch (CallbackID)
600
    {
604
    {
601
      case HAL_SMARTCARD_TX_COMPLETE_CB_ID :
605
      case HAL_SMARTCARD_TX_COMPLETE_CB_ID :
602
        hsmartcard->TxCpltCallback = HAL_SMARTCARD_TxCpltCallback;                       /* Legacy weak TxCpltCallback            */
606
        hsmartcard->TxCpltCallback = HAL_SMARTCARD_TxCpltCallback;                 /* Legacy weak TxCpltCallback */
603
        break;
607
        break;
604
 
608
 
605
      case HAL_SMARTCARD_RX_COMPLETE_CB_ID :
609
      case HAL_SMARTCARD_RX_COMPLETE_CB_ID :
606
        hsmartcard->RxCpltCallback = HAL_SMARTCARD_RxCpltCallback;                       /* Legacy weak RxCpltCallback            */
610
        hsmartcard->RxCpltCallback = HAL_SMARTCARD_RxCpltCallback;                 /* Legacy weak RxCpltCallback */
607
        break;
611
        break;
608
 
612
 
609
      case HAL_SMARTCARD_ERROR_CB_ID :
613
      case HAL_SMARTCARD_ERROR_CB_ID :
610
        hsmartcard->ErrorCallback = HAL_SMARTCARD_ErrorCallback;                         /* Legacy weak ErrorCallback             */
614
        hsmartcard->ErrorCallback = HAL_SMARTCARD_ErrorCallback;                   /* Legacy weak ErrorCallback  */
611
        break;
615
        break;
612
 
616
 
613
      case HAL_SMARTCARD_ABORT_COMPLETE_CB_ID :
617
      case HAL_SMARTCARD_ABORT_COMPLETE_CB_ID :
614
        hsmartcard->AbortCpltCallback = HAL_SMARTCARD_AbortCpltCallback;                 /* Legacy weak AbortCpltCallback         */
618
        hsmartcard->AbortCpltCallback = HAL_SMARTCARD_AbortCpltCallback;           /* Legacy weak AbortCpltCallback */
615
        break;
619
        break;
616
 
620
 
617
      case HAL_SMARTCARD_ABORT_TRANSMIT_COMPLETE_CB_ID :
621
      case HAL_SMARTCARD_ABORT_TRANSMIT_COMPLETE_CB_ID :
618
        hsmartcard->AbortTransmitCpltCallback = HAL_SMARTCARD_AbortTransmitCpltCallback; /* Legacy weak AbortTransmitCpltCallback */
622
        hsmartcard->AbortTransmitCpltCallback = HAL_SMARTCARD_AbortTransmitCpltCallback; /* Legacy weak
-
 
623
                                                                                            AbortTransmitCpltCallback*/
619
        break;
624
        break;
620
 
625
 
621
      case HAL_SMARTCARD_ABORT_RECEIVE_COMPLETE_CB_ID :
626
      case HAL_SMARTCARD_ABORT_RECEIVE_COMPLETE_CB_ID :
622
        hsmartcard->AbortReceiveCpltCallback = HAL_SMARTCARD_AbortReceiveCpltCallback;   /* Legacy weak AbortReceiveCpltCallback  */
627
        hsmartcard->AbortReceiveCpltCallback = HAL_SMARTCARD_AbortReceiveCpltCallback;  /* Legacy weak
-
 
628
                                                                                           AbortReceiveCpltCallback */
623
        break;
629
        break;
624
 
630
 
625
 
631
 
626
      case HAL_SMARTCARD_MSPINIT_CB_ID :
632
      case HAL_SMARTCARD_MSPINIT_CB_ID :
627
        hsmartcard->MspInitCallback = HAL_SMARTCARD_MspInit;                             /* Legacy weak MspInitCallback           */
633
        hsmartcard->MspInitCallback = HAL_SMARTCARD_MspInit;                       /* Legacy weak MspInitCallback  */
628
        break;
634
        break;
629
 
635
 
630
      case HAL_SMARTCARD_MSPDEINIT_CB_ID :
636
      case HAL_SMARTCARD_MSPDEINIT_CB_ID :
631
        hsmartcard->MspDeInitCallback = HAL_SMARTCARD_MspDeInit;                         /* Legacy weak MspDeInitCallback         */
637
        hsmartcard->MspDeInitCallback = HAL_SMARTCARD_MspDeInit;                   /* Legacy weak MspDeInitCallback */
632
        break;
638
        break;
633
 
639
 
634
      default :
640
      default :
635
        /* Update the error code */
641
        /* Update the error code */
636
        hsmartcard->ErrorCode |= HAL_SMARTCARD_ERROR_INVALID_CALLBACK;
642
        hsmartcard->ErrorCode |= HAL_SMARTCARD_ERROR_INVALID_CALLBACK;
Line 697... Line 703...
697
    defined in the ISO 7816-3 standard. The USART should be configured as:
703
    defined in the ISO 7816-3 standard. The USART should be configured as:
698
    (+) 8 bits plus parity: where M=1 and PCE=1 in the USART_CR1 register
704
    (+) 8 bits plus parity: where M=1 and PCE=1 in the USART_CR1 register
699
    (+) 1.5 stop bits when transmitting and receiving: where STOP=11 in the USART_CR2 register.
705
    (+) 1.5 stop bits when transmitting and receiving: where STOP=11 in the USART_CR2 register.
700
 
706
 
701
  [..]
707
  [..]
702
    (+) There are two modes of transfer:
708
    (#) There are two modes of transfer:
703
        (++) Blocking mode: The communication is performed in polling mode.
709
        (##) Blocking mode: The communication is performed in polling mode.
704
             The HAL status of all data processing is returned by the same function
710
             The HAL status of all data processing is returned by the same function
705
             after finishing transfer.
711
             after finishing transfer.
706
        (++) Non-Blocking mode: The communication is performed using Interrupts
712
        (##) Non-Blocking mode: The communication is performed using Interrupts
707
             or DMA, the relevant API's return the HAL status.
713
             or DMA, the relevant API's return the HAL status.
708
             The end of the data processing will be indicated through the
714
             The end of the data processing will be indicated through the
709
             dedicated SMARTCARD IRQ when using Interrupt mode or the DMA IRQ when
715
             dedicated SMARTCARD IRQ when using Interrupt mode or the DMA IRQ when
710
             using DMA mode.
716
             using DMA mode.
711
        (++) The HAL_SMARTCARD_TxCpltCallback(), HAL_SMARTCARD_RxCpltCallback() user callbacks
717
        (##) The HAL_SMARTCARD_TxCpltCallback(), HAL_SMARTCARD_RxCpltCallback() user callbacks
712
             will be executed respectively at the end of the Transmit or Receive process
718
             will be executed respectively at the end of the Transmit or Receive process
713
             The HAL_SMARTCARD_ErrorCallback() user callback will be executed when a communication
719
             The HAL_SMARTCARD_ErrorCallback() user callback will be executed when a communication
714
             error is detected.
720
             error is detected.
715
 
721
 
716
    (+) Blocking mode APIs are :
722
    (#) Blocking mode APIs are :
717
        (++) HAL_SMARTCARD_Transmit()
723
        (##) HAL_SMARTCARD_Transmit()
718
        (++) HAL_SMARTCARD_Receive()
724
        (##) HAL_SMARTCARD_Receive()
719
 
725
 
720
    (+) Non Blocking mode APIs with Interrupt are :
726
    (#) Non Blocking mode APIs with Interrupt are :
721
        (++) HAL_SMARTCARD_Transmit_IT()
727
        (##) HAL_SMARTCARD_Transmit_IT()
722
        (++) HAL_SMARTCARD_Receive_IT()
728
        (##) HAL_SMARTCARD_Receive_IT()
723
        (++) HAL_SMARTCARD_IRQHandler()
729
        (##) HAL_SMARTCARD_IRQHandler()
724
 
730
 
725
    (+) Non Blocking mode functions with DMA are :
731
    (#) Non Blocking mode functions with DMA are :
726
        (++) HAL_SMARTCARD_Transmit_DMA()
732
        (##) HAL_SMARTCARD_Transmit_DMA()
727
        (++) HAL_SMARTCARD_Receive_DMA()
733
        (##) HAL_SMARTCARD_Receive_DMA()
728
 
734
 
729
    (+) A set of Transfer Complete Callbacks are provided in non Blocking mode:
735
    (#) A set of Transfer Complete Callbacks are provided in non Blocking mode:
730
        (++) HAL_SMARTCARD_TxCpltCallback()
736
        (##) HAL_SMARTCARD_TxCpltCallback()
731
        (++) HAL_SMARTCARD_RxCpltCallback()
737
        (##) HAL_SMARTCARD_RxCpltCallback()
732
        (++) HAL_SMARTCARD_ErrorCallback()
738
        (##) HAL_SMARTCARD_ErrorCallback()
733
 
739
 
734
  [..]
740
  [..]
735
    (#) Non-Blocking mode transfers could be aborted using Abort API's :
741
    (#) Non-Blocking mode transfers could be aborted using Abort API's :
736
        (++) HAL_SMARTCARD_Abort()
742
        (##) HAL_SMARTCARD_Abort()
737
        (++) HAL_SMARTCARD_AbortTransmit()
743
        (##) HAL_SMARTCARD_AbortTransmit()
738
        (++) HAL_SMARTCARD_AbortReceive()
744
        (##) HAL_SMARTCARD_AbortReceive()
739
        (++) HAL_SMARTCARD_Abort_IT()
745
        (##) HAL_SMARTCARD_Abort_IT()
740
        (++) HAL_SMARTCARD_AbortTransmit_IT()
746
        (##) HAL_SMARTCARD_AbortTransmit_IT()
741
        (++) HAL_SMARTCARD_AbortReceive_IT()
747
        (##) HAL_SMARTCARD_AbortReceive_IT()
742
 
748
 
743
    (#) For Abort services based on interrupts (HAL_SMARTCARD_Abortxxx_IT), a set of Abort Complete Callbacks are provided:
749
    (#) For Abort services based on interrupts (HAL_SMARTCARD_Abortxxx_IT),
-
 
750
        a set of Abort Complete Callbacks are provided:
744
        (++) HAL_SMARTCARD_AbortCpltCallback()
751
        (##) HAL_SMARTCARD_AbortCpltCallback()
745
        (++) HAL_SMARTCARD_AbortTransmitCpltCallback()
752
        (##) HAL_SMARTCARD_AbortTransmitCpltCallback()
746
        (++) HAL_SMARTCARD_AbortReceiveCpltCallback()
753
        (##) HAL_SMARTCARD_AbortReceiveCpltCallback()
747
 
754
 
748
    (#) In Non-Blocking mode transfers, possible errors are split into 2 categories.
755
    (#) In Non-Blocking mode transfers, possible errors are split into 2 categories.
749
        Errors are handled as follows :
756
        Errors are handled as follows :
750
       (++) Error is considered as Recoverable and non blocking : Transfer could go till end, but error severity is
757
       (##) Error is considered as Recoverable and non blocking : Transfer could go till end, but error severity is
-
 
758
           to be evaluated by user : this concerns Frame Error,
751
            to be evaluated by user : this concerns Frame Error, Parity Error or Noise Error in Interrupt mode reception .
759
           Parity Error or Noise Error in Interrupt mode reception .
752
            Received character is then retrieved and stored in Rx buffer, Error code is set to allow user to identify error type,
760
           Received character is then retrieved and stored in Rx buffer,
-
 
761
           Error code is set to allow user to identify error type,
753
            and HAL_SMARTCARD_ErrorCallback() user callback is executed. Transfer is kept ongoing on SMARTCARD side.
762
           and HAL_SMARTCARD_ErrorCallback() user callback is executed. Transfer is kept ongoing on SMARTCARD side.
754
            If user wants to abort it, Abort services should be called by user.
763
           If user wants to abort it, Abort services should be called by user.
755
       (++) Error is considered as Blocking : Transfer could not be completed properly and is aborted.
764
       (##) Error is considered as Blocking : Transfer could not be completed properly and is aborted.
756
            This concerns Frame Error in Interrupt mode tranmission, Overrun Error in Interrupt mode reception and all errors in DMA mode.
765
           This concerns Frame Error in Interrupt mode transmission, Overrun Error in Interrupt
-
 
766
           mode reception and all errors in DMA mode.
-
 
767
           Error code is set to allow user to identify error type,
757
            Error code is set to allow user to identify error type, and HAL_SMARTCARD_ErrorCallback() user callback is executed.
768
           and HAL_SMARTCARD_ErrorCallback() user callback is executed.
758
 
769
 
759
@endverbatim
770
@endverbatim
760
  * @{
771
  * @{
761
  */
772
  */
762
 
773
 
Line 792... Line 803...
792
    tickstart = HAL_GetTick();
803
    tickstart = HAL_GetTick();
793
 
804
 
794
    /* Disable the Peripheral first to update mode for TX master */
805
    /* Disable the Peripheral first to update mode for TX master */
795
    CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_UE);
806
    CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_UE);
796
 
807
 
-
 
808
    /* In case of TX only mode, if NACK is enabled, the USART must be able to monitor
-
 
809
       the bidirectional line to detect a NACK signal in case of parity error.
-
 
810
       Therefore, the receiver block must be enabled as well (RE bit must be set). */
797
    /* Disable Rx, enable Tx */
811
    if ((hsmartcard->Init.Mode == SMARTCARD_MODE_TX)
798
    CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_RE);
812
        && (hsmartcard->Init.NACKEnable == SMARTCARD_NACK_ENABLE))
-
 
813
    {
799
    SET_BIT(hsmartcard->Instance->RQR, (uint16_t)SMARTCARD_RXDATA_FLUSH_REQUEST);
814
      SET_BIT(hsmartcard->Instance->CR1, USART_CR1_RE);
-
 
815
    }
-
 
816
    /* Enable Tx */
800
    SET_BIT(hsmartcard->Instance->CR1, USART_CR1_TE);
817
    SET_BIT(hsmartcard->Instance->CR1, USART_CR1_TE);
801
 
818
 
802
    /* Enable the Peripheral */
819
    /* Enable the Peripheral */
803
    SET_BIT(hsmartcard->Instance->CR1, USART_CR1_UE);
820
    SET_BIT(hsmartcard->Instance->CR1, USART_CR1_UE);
804
 
821
 
-
 
822
    /* Perform a TX/RX FIFO Flush */
-
 
823
    __HAL_SMARTCARD_FLUSH_DRREGISTER(hsmartcard);
-
 
824
 
805
    hsmartcard->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
825
    hsmartcard->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
806
    hsmartcard->TxXferSize = Size;
826
    hsmartcard->TxXferSize = Size;
807
    hsmartcard->TxXferCount = Size;
827
    hsmartcard->TxXferCount = Size;
808
 
828
 
809
    while (hsmartcard->TxXferCount > 0U)
829
    while (hsmartcard->TxXferCount > 0U)
Line 814... Line 834...
814
        return HAL_TIMEOUT;
834
        return HAL_TIMEOUT;
815
      }
835
      }
816
      hsmartcard->Instance->TDR = (uint8_t)(*ptmpdata & 0xFFU);
836
      hsmartcard->Instance->TDR = (uint8_t)(*ptmpdata & 0xFFU);
817
      ptmpdata++;
837
      ptmpdata++;
818
    }
838
    }
819
    if (SMARTCARD_WaitOnFlagUntilTimeout(hsmartcard, SMARTCARD_TRANSMISSION_COMPLETION_FLAG(hsmartcard), RESET, tickstart,
839
    if (SMARTCARD_WaitOnFlagUntilTimeout(hsmartcard, SMARTCARD_TRANSMISSION_COMPLETION_FLAG(hsmartcard), RESET,
820
                                         Timeout) != HAL_OK)
840
                                         tickstart, Timeout) != HAL_OK)
821
    {
841
    {
822
      return HAL_TIMEOUT;
842
      return HAL_TIMEOUT;
823
    }
843
    }
-
 
844
 
824
    /* Re-enable Rx at end of transmission if initial mode is Rx/Tx */
845
    /* Disable the Peripheral first to update mode */
-
 
846
    CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_UE);
825
    if (hsmartcard->Init.Mode == SMARTCARD_MODE_TX_RX)
847
    if ((hsmartcard->Init.Mode == SMARTCARD_MODE_TX)
-
 
848
        && (hsmartcard->Init.NACKEnable == SMARTCARD_NACK_ENABLE))
826
    {
849
    {
827
      /* Disable the Peripheral first to update modes */
850
      /* In case of TX only mode, if NACK is enabled, receiver block has been enabled
828
      CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_UE);
-
 
829
      SET_BIT(hsmartcard->Instance->CR1, USART_CR1_RE);
-
 
830
      /* Enable the Peripheral */
851
         for Transmit phase. Disable this receiver block. */
831
      SET_BIT(hsmartcard->Instance->CR1, USART_CR1_UE);
852
      CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_RE);
832
    }
853
    }
-
 
854
    if ((hsmartcard->Init.Mode == SMARTCARD_MODE_TX_RX)
-
 
855
        || (hsmartcard->Init.NACKEnable == SMARTCARD_NACK_ENABLE))
-
 
856
    {
-
 
857
      /* Perform a TX FIFO Flush at end of Tx phase, as all sent bytes are appearing in Rx Data register */
-
 
858
      __HAL_SMARTCARD_FLUSH_DRREGISTER(hsmartcard);
-
 
859
    }
-
 
860
    SET_BIT(hsmartcard->Instance->CR1, USART_CR1_UE);
833
 
861
 
834
    /* At end of Tx process, restore hsmartcard->gState to Ready */
862
    /* At end of Tx process, restore hsmartcard->gState to Ready */
835
    hsmartcard->gState = HAL_SMARTCARD_STATE_READY;
863
    hsmartcard->gState = HAL_SMARTCARD_STATE_READY;
836
 
864
 
837
    /* Process Unlocked */
865
    /* Process Unlocked */
Line 937... Line 965...
937
    hsmartcard->TxISR       = NULL;
965
    hsmartcard->TxISR       = NULL;
938
 
966
 
939
    /* Disable the Peripheral first to update mode for TX master */
967
    /* Disable the Peripheral first to update mode for TX master */
940
    CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_UE);
968
    CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_UE);
941
 
969
 
-
 
970
    /* In case of TX only mode, if NACK is enabled, the USART must be able to monitor
-
 
971
       the bidirectional line to detect a NACK signal in case of parity error.
-
 
972
       Therefore, the receiver block must be enabled as well (RE bit must be set). */
942
    /* Disable Rx, enable Tx */
973
    if ((hsmartcard->Init.Mode == SMARTCARD_MODE_TX)
943
    CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_RE);
974
        && (hsmartcard->Init.NACKEnable == SMARTCARD_NACK_ENABLE))
-
 
975
    {
944
    SET_BIT(hsmartcard->Instance->RQR, (uint16_t)SMARTCARD_RXDATA_FLUSH_REQUEST);
976
      SET_BIT(hsmartcard->Instance->CR1, USART_CR1_RE);
-
 
977
    }
-
 
978
    /* Enable Tx */
945
    SET_BIT(hsmartcard->Instance->CR1, USART_CR1_TE);
979
    SET_BIT(hsmartcard->Instance->CR1, USART_CR1_TE);
946
 
980
 
947
    /* Enable the Peripheral */
981
    /* Enable the Peripheral */
948
    SET_BIT(hsmartcard->Instance->CR1, USART_CR1_UE);
982
    SET_BIT(hsmartcard->Instance->CR1, USART_CR1_UE);
949
 
983
 
-
 
984
    /* Perform a TX/RX FIFO Flush */
-
 
985
    __HAL_SMARTCARD_FLUSH_DRREGISTER(hsmartcard);
-
 
986
 
950
    /* Configure Tx interrupt processing */
987
    /* Configure Tx interrupt processing */
951
    /* Set the Tx ISR function pointer */
988
    /* Set the Tx ISR function pointer */
952
    hsmartcard->TxISR = SMARTCARD_TxISR;
989
    hsmartcard->TxISR = SMARTCARD_TxISR;
953
 
990
 
954
    /* Process Unlocked */
991
    /* Process Unlocked */
Line 1046... Line 1083...
1046
    hsmartcard->TxXferCount = Size;
1083
    hsmartcard->TxXferCount = Size;
1047
 
1084
 
1048
    /* Disable the Peripheral first to update mode for TX master */
1085
    /* Disable the Peripheral first to update mode for TX master */
1049
    CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_UE);
1086
    CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_UE);
1050
 
1087
 
-
 
1088
    /* In case of TX only mode, if NACK is enabled, the USART must be able to monitor
-
 
1089
       the bidirectional line to detect a NACK signal in case of parity error.
-
 
1090
       Therefore, the receiver block must be enabled as well (RE bit must be set). */
1051
    /* Disable Rx, enable Tx */
1091
    if ((hsmartcard->Init.Mode == SMARTCARD_MODE_TX)
1052
    CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_RE);
1092
        && (hsmartcard->Init.NACKEnable == SMARTCARD_NACK_ENABLE))
-
 
1093
    {
1053
    SET_BIT(hsmartcard->Instance->RQR, (uint16_t)SMARTCARD_RXDATA_FLUSH_REQUEST);
1094
      SET_BIT(hsmartcard->Instance->CR1, USART_CR1_RE);
-
 
1095
    }
-
 
1096
    /* Enable Tx */
1054
    SET_BIT(hsmartcard->Instance->CR1, USART_CR1_TE);
1097
    SET_BIT(hsmartcard->Instance->CR1, USART_CR1_TE);
1055
 
1098
 
1056
    /* Enable the Peripheral */
1099
    /* Enable the Peripheral */
1057
    SET_BIT(hsmartcard->Instance->CR1, USART_CR1_UE);
1100
    SET_BIT(hsmartcard->Instance->CR1, USART_CR1_UE);
1058
 
1101
 
-
 
1102
    /* Perform a TX/RX FIFO Flush */
-
 
1103
    __HAL_SMARTCARD_FLUSH_DRREGISTER(hsmartcard);
-
 
1104
 
1059
    /* Set the SMARTCARD DMA transfer complete callback */
1105
    /* Set the SMARTCARD DMA transfer complete callback */
1060
    hsmartcard->hdmatx->XferCpltCallback = SMARTCARD_DMATransmitCplt;
1106
    hsmartcard->hdmatx->XferCpltCallback = SMARTCARD_DMATransmitCplt;
1061
 
1107
 
1062
    /* Set the SMARTCARD error callback */
1108
    /* Set the SMARTCARD error callback */
1063
    hsmartcard->hdmatx->XferErrorCallback = SMARTCARD_DMAError;
1109
    hsmartcard->hdmatx->XferErrorCallback = SMARTCARD_DMAError;
Line 1196... Line 1242...
1196
  */
1242
  */
1197
HAL_StatusTypeDef HAL_SMARTCARD_Abort(SMARTCARD_HandleTypeDef *hsmartcard)
1243
HAL_StatusTypeDef HAL_SMARTCARD_Abort(SMARTCARD_HandleTypeDef *hsmartcard)
1198
{
1244
{
1199
  /* Disable RTOIE, EOBIE, TXEIE, TCIE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
1245
  /* Disable RTOIE, EOBIE, TXEIE, TCIE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
1200
  CLEAR_BIT(hsmartcard->Instance->CR1,
1246
  CLEAR_BIT(hsmartcard->Instance->CR1,
1201
            (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_TXEIE | USART_CR1_TCIE | USART_CR1_RTOIE | USART_CR1_EOBIE));
1247
            (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_TXEIE | USART_CR1_TCIE | USART_CR1_RTOIE |
-
 
1248
             USART_CR1_EOBIE));
1202
  CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE);
1249
  CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE);
1203
 
1250
 
1204
  /* Disable the SMARTCARD DMA Tx request if enabled */
1251
  /* Disable the SMARTCARD DMA Tx request if enabled */
1205
  if (HAL_IS_BIT_SET(hsmartcard->Instance->CR3, USART_CR3_DMAT))
1252
  if (HAL_IS_BIT_SET(hsmartcard->Instance->CR3, USART_CR3_DMAT))
1206
  {
1253
  {
Line 1255... Line 1302...
1255
  hsmartcard->TxXferCount = 0U;
1302
  hsmartcard->TxXferCount = 0U;
1256
  hsmartcard->RxXferCount = 0U;
1303
  hsmartcard->RxXferCount = 0U;
1257
 
1304
 
1258
  /* Clear the Error flags in the ICR register */
1305
  /* Clear the Error flags in the ICR register */
1259
  __HAL_SMARTCARD_CLEAR_FLAG(hsmartcard,
1306
  __HAL_SMARTCARD_CLEAR_FLAG(hsmartcard,
1260
                             SMARTCARD_CLEAR_OREF | SMARTCARD_CLEAR_NEF | SMARTCARD_CLEAR_PEF | SMARTCARD_CLEAR_FEF | SMARTCARD_CLEAR_RTOF |
1307
                             SMARTCARD_CLEAR_OREF | SMARTCARD_CLEAR_NEF | SMARTCARD_CLEAR_PEF | SMARTCARD_CLEAR_FEF |
1261
                             SMARTCARD_CLEAR_EOBF);
1308
                             SMARTCARD_CLEAR_RTOF | SMARTCARD_CLEAR_EOBF);
1262
 
1309
 
1263
  /* Restore hsmartcard->gState and hsmartcard->RxState to Ready */
1310
  /* Restore hsmartcard->gState and hsmartcard->RxState to Ready */
1264
  hsmartcard->gState  = HAL_SMARTCARD_STATE_READY;
1311
  hsmartcard->gState  = HAL_SMARTCARD_STATE_READY;
1265
  hsmartcard->RxState = HAL_SMARTCARD_STATE_READY;
1312
  hsmartcard->RxState = HAL_SMARTCARD_STATE_READY;
1266
 
1313
 
Line 1386... Line 1433...
1386
  /* Reset Rx transfer counter */
1433
  /* Reset Rx transfer counter */
1387
  hsmartcard->RxXferCount = 0U;
1434
  hsmartcard->RxXferCount = 0U;
1388
 
1435
 
1389
  /* Clear the Error flags in the ICR register */
1436
  /* Clear the Error flags in the ICR register */
1390
  __HAL_SMARTCARD_CLEAR_FLAG(hsmartcard,
1437
  __HAL_SMARTCARD_CLEAR_FLAG(hsmartcard,
1391
                             SMARTCARD_CLEAR_OREF | SMARTCARD_CLEAR_NEF | SMARTCARD_CLEAR_PEF | SMARTCARD_CLEAR_FEF | SMARTCARD_CLEAR_RTOF |
1438
                             SMARTCARD_CLEAR_OREF | SMARTCARD_CLEAR_NEF | SMARTCARD_CLEAR_PEF | SMARTCARD_CLEAR_FEF |
1392
                             SMARTCARD_CLEAR_EOBF);
1439
                             SMARTCARD_CLEAR_RTOF | SMARTCARD_CLEAR_EOBF);
1393
 
1440
 
1394
  /* Restore hsmartcard->RxState to Ready */
1441
  /* Restore hsmartcard->RxState to Ready */
1395
  hsmartcard->RxState = HAL_SMARTCARD_STATE_READY;
1442
  hsmartcard->RxState = HAL_SMARTCARD_STATE_READY;
1396
 
1443
 
1397
  return HAL_OK;
1444
  return HAL_OK;
Line 1416... Line 1463...
1416
{
1463
{
1417
  uint32_t abortcplt = 1U;
1464
  uint32_t abortcplt = 1U;
1418
 
1465
 
1419
  /* Disable RTOIE, EOBIE, TXEIE, TCIE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
1466
  /* Disable RTOIE, EOBIE, TXEIE, TCIE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
1420
  CLEAR_BIT(hsmartcard->Instance->CR1,
1467
  CLEAR_BIT(hsmartcard->Instance->CR1,
1421
            (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_TXEIE | USART_CR1_TCIE | USART_CR1_RTOIE | USART_CR1_EOBIE));
1468
            (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_TXEIE | USART_CR1_TCIE | USART_CR1_RTOIE |
-
 
1469
             USART_CR1_EOBIE));
1422
  CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE);
1470
  CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE);
1423
 
1471
 
1424
  /* If DMA Tx and/or DMA Rx Handles are associated to SMARTCARD Handle, DMA Abort complete callbacks should be initialised
1472
  /* If DMA Tx and/or DMA Rx Handles are associated to SMARTCARD Handle,
-
 
1473
     DMA Abort complete callbacks should be initialised before any call
1425
     before any call to DMA Abort functions */
1474
     to DMA Abort functions */
1426
  /* DMA Tx Handle is valid */
1475
  /* DMA Tx Handle is valid */
1427
  if (hsmartcard->hdmatx != NULL)
1476
  if (hsmartcard->hdmatx != NULL)
1428
  {
1477
  {
1429
    /* Set DMA Abort Complete callback if SMARTCARD DMA Tx request if enabled.
1478
    /* Set DMA Abort Complete callback if SMARTCARD DMA Tx request if enabled.
1430
       Otherwise, set it to NULL */
1479
       Otherwise, set it to NULL */
Line 1514... Line 1563...
1514
    /* Reset errorCode */
1563
    /* Reset errorCode */
1515
    hsmartcard->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
1564
    hsmartcard->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
1516
 
1565
 
1517
    /* Clear the Error flags in the ICR register */
1566
    /* Clear the Error flags in the ICR register */
1518
    __HAL_SMARTCARD_CLEAR_FLAG(hsmartcard,
1567
    __HAL_SMARTCARD_CLEAR_FLAG(hsmartcard,
1519
                               SMARTCARD_CLEAR_OREF | SMARTCARD_CLEAR_NEF | SMARTCARD_CLEAR_PEF | SMARTCARD_CLEAR_FEF | SMARTCARD_CLEAR_RTOF |
1568
                               SMARTCARD_CLEAR_OREF | SMARTCARD_CLEAR_NEF | SMARTCARD_CLEAR_PEF |
1520
                               SMARTCARD_CLEAR_EOBF);
1569
                               SMARTCARD_CLEAR_FEF | SMARTCARD_CLEAR_RTOF | SMARTCARD_CLEAR_EOBF);
1521
 
1570
 
1522
    /* Restore hsmartcard->gState and hsmartcard->RxState to Ready */
1571
    /* Restore hsmartcard->gState and hsmartcard->RxState to Ready */
1523
    hsmartcard->gState  = HAL_SMARTCARD_STATE_READY;
1572
    hsmartcard->gState  = HAL_SMARTCARD_STATE_READY;
1524
    hsmartcard->RxState = HAL_SMARTCARD_STATE_READY;
1573
    hsmartcard->RxState = HAL_SMARTCARD_STATE_READY;
1525
 
1574
 
Line 1685... Line 1734...
1685
      /* Clear RxISR function pointer */
1734
      /* Clear RxISR function pointer */
1686
      hsmartcard->RxISR = NULL;
1735
      hsmartcard->RxISR = NULL;
1687
 
1736
 
1688
      /* Clear the Error flags in the ICR register */
1737
      /* Clear the Error flags in the ICR register */
1689
      __HAL_SMARTCARD_CLEAR_FLAG(hsmartcard,
1738
      __HAL_SMARTCARD_CLEAR_FLAG(hsmartcard,
1690
                                 SMARTCARD_CLEAR_OREF | SMARTCARD_CLEAR_NEF | SMARTCARD_CLEAR_PEF | SMARTCARD_CLEAR_FEF | SMARTCARD_CLEAR_RTOF |
1739
                                 SMARTCARD_CLEAR_OREF | SMARTCARD_CLEAR_NEF | SMARTCARD_CLEAR_PEF |
1691
                                 SMARTCARD_CLEAR_EOBF);
1740
                                 SMARTCARD_CLEAR_FEF | SMARTCARD_CLEAR_RTOF | SMARTCARD_CLEAR_EOBF);
1692
 
1741
 
1693
      /* Restore hsmartcard->RxState to Ready */
1742
      /* Restore hsmartcard->RxState to Ready */
1694
      hsmartcard->RxState = HAL_SMARTCARD_STATE_READY;
1743
      hsmartcard->RxState = HAL_SMARTCARD_STATE_READY;
1695
 
1744
 
1696
      /* As no DMA to be aborted, call directly user Abort complete callback */
1745
      /* As no DMA to be aborted, call directly user Abort complete callback */
Line 1711... Line 1760...
1711
    /* Clear RxISR function pointer */
1760
    /* Clear RxISR function pointer */
1712
    hsmartcard->RxISR = NULL;
1761
    hsmartcard->RxISR = NULL;
1713
 
1762
 
1714
    /* Clear the Error flags in the ICR register */
1763
    /* Clear the Error flags in the ICR register */
1715
    __HAL_SMARTCARD_CLEAR_FLAG(hsmartcard,
1764
    __HAL_SMARTCARD_CLEAR_FLAG(hsmartcard,
1716
                               SMARTCARD_CLEAR_OREF | SMARTCARD_CLEAR_NEF | SMARTCARD_CLEAR_PEF | SMARTCARD_CLEAR_FEF | SMARTCARD_CLEAR_RTOF |
1765
                               SMARTCARD_CLEAR_OREF | SMARTCARD_CLEAR_NEF | SMARTCARD_CLEAR_PEF |
1717
                               SMARTCARD_CLEAR_EOBF);
1766
                               SMARTCARD_CLEAR_FEF | SMARTCARD_CLEAR_RTOF | SMARTCARD_CLEAR_EOBF);
1718
 
1767
 
1719
    /* Restore hsmartcard->RxState to Ready */
1768
    /* Restore hsmartcard->RxState to Ready */
1720
    hsmartcard->RxState = HAL_SMARTCARD_STATE_READY;
1769
    hsmartcard->RxState = HAL_SMARTCARD_STATE_READY;
1721
 
1770
 
1722
    /* As no DMA to be aborted, call directly user Abort complete callback */
1771
    /* As no DMA to be aborted, call directly user Abort complete callback */
Line 2154... Line 2203...
2154
  * @retval none
2203
  * @retval none
2155
  */
2204
  */
2156
void SMARTCARD_InitCallbacksToDefault(SMARTCARD_HandleTypeDef *hsmartcard)
2205
void SMARTCARD_InitCallbacksToDefault(SMARTCARD_HandleTypeDef *hsmartcard)
2157
{
2206
{
2158
  /* Init the SMARTCARD Callback settings */
2207
  /* Init the SMARTCARD Callback settings */
2159
  hsmartcard->TxCpltCallback            = HAL_SMARTCARD_TxCpltCallback;            /* Legacy weak TxCpltCallback            */
2208
  hsmartcard->TxCpltCallback            = HAL_SMARTCARD_TxCpltCallback;            /* Legacy weak TxCpltCallback    */
2160
  hsmartcard->RxCpltCallback            = HAL_SMARTCARD_RxCpltCallback;            /* Legacy weak RxCpltCallback            */
2209
  hsmartcard->RxCpltCallback            = HAL_SMARTCARD_RxCpltCallback;            /* Legacy weak RxCpltCallback    */
2161
  hsmartcard->ErrorCallback             = HAL_SMARTCARD_ErrorCallback;             /* Legacy weak ErrorCallback             */
2210
  hsmartcard->ErrorCallback             = HAL_SMARTCARD_ErrorCallback;             /* Legacy weak ErrorCallback     */
2162
  hsmartcard->AbortCpltCallback         = HAL_SMARTCARD_AbortCpltCallback;         /* Legacy weak AbortCpltCallback         */
2211
  hsmartcard->AbortCpltCallback         = HAL_SMARTCARD_AbortCpltCallback;         /* Legacy weak AbortCpltCallback */
2163
  hsmartcard->AbortTransmitCpltCallback = HAL_SMARTCARD_AbortTransmitCpltCallback; /* Legacy weak AbortTransmitCpltCallback */
2212
  hsmartcard->AbortTransmitCpltCallback = HAL_SMARTCARD_AbortTransmitCpltCallback; /* Legacy weak
-
 
2213
                                                                                      AbortTransmitCpltCallback     */
2164
  hsmartcard->AbortReceiveCpltCallback  = HAL_SMARTCARD_AbortReceiveCpltCallback;  /* Legacy weak AbortReceiveCpltCallback  */
2214
  hsmartcard->AbortReceiveCpltCallback  = HAL_SMARTCARD_AbortReceiveCpltCallback;  /* Legacy weak
-
 
2215
                                                                                      AbortReceiveCpltCallback      */
2165
 
2216
 
2166
}
2217
}
2167
#endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACKS */
2218
#endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACKS */
2168
 
2219
 
2169
/**
2220
/**
Line 2198... Line 2249...
2198
  /* In SmartCard mode, M and PCE are forced to 1 (8 bits + parity).
2249
  /* In SmartCard mode, M and PCE are forced to 1 (8 bits + parity).
2199
   * Oversampling is forced to 16 (OVER8 = 0).
2250
   * Oversampling is forced to 16 (OVER8 = 0).
2200
   * Configure the Parity and Mode:
2251
   * Configure the Parity and Mode:
2201
   *  set PS bit according to hsmartcard->Init.Parity value
2252
   *  set PS bit according to hsmartcard->Init.Parity value
2202
   *  set TE and RE bits according to hsmartcard->Init.Mode value */
2253
   *  set TE and RE bits according to hsmartcard->Init.Mode value */
2203
  tmpreg = (uint32_t)(hsmartcard->Init.Parity | hsmartcard->Init.Mode | hsmartcard->Init.WordLength);
2254
  tmpreg = (((uint32_t)hsmartcard->Init.Parity) | ((uint32_t)hsmartcard->Init.Mode) |
-
 
2255
            ((uint32_t)hsmartcard->Init.WordLength));
2204
  MODIFY_REG(hsmartcard->Instance->CR1, USART_CR1_FIELDS, tmpreg);
2256
  MODIFY_REG(hsmartcard->Instance->CR1, USART_CR1_FIELDS, tmpreg);
2205
 
2257
 
2206
  /*-------------------------- USART CR2 Configuration -----------------------*/
2258
  /*-------------------------- USART CR2 Configuration -----------------------*/
2207
  tmpreg = hsmartcard->Init.StopBits;
2259
  tmpreg = hsmartcard->Init.StopBits;
2208
  /* Synchronous mode is activated by default */
2260
  /* Synchronous mode is activated by default */
Line 2410... Line 2462...
2410
    /* Check for the Timeout */
2462
    /* Check for the Timeout */
2411
    if (Timeout != HAL_MAX_DELAY)
2463
    if (Timeout != HAL_MAX_DELAY)
2412
    {
2464
    {
2413
      if (((HAL_GetTick() - Tickstart) > Timeout) || (Timeout == 0U))
2465
      if (((HAL_GetTick() - Tickstart) > Timeout) || (Timeout == 0U))
2414
      {
2466
      {
2415
        /* Disable TXE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts for the interrupt process */
2467
        /* Disable TXE, RXNE, PE and ERR (Frame error, noise error, overrun error)
-
 
2468
           interrupts for the interrupt process */
2416
        CLEAR_BIT(hsmartcard->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_TXEIE));
2469
        CLEAR_BIT(hsmartcard->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_TXEIE));
2417
        CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE);
2470
        CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE);
2418
 
2471
 
2419
        hsmartcard->gState  = HAL_SMARTCARD_STATE_READY;
2472
        hsmartcard->gState  = HAL_SMARTCARD_STATE_READY;
2420
        hsmartcard->RxState = HAL_SMARTCARD_STATE_READY;
2473
        hsmartcard->RxState = HAL_SMARTCARD_STATE_READY;
Line 2604... Line 2657...
2604
  /* Reset errorCode */
2657
  /* Reset errorCode */
2605
  hsmartcard->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
2658
  hsmartcard->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
2606
 
2659
 
2607
  /* Clear the Error flags in the ICR register */
2660
  /* Clear the Error flags in the ICR register */
2608
  __HAL_SMARTCARD_CLEAR_FLAG(hsmartcard,
2661
  __HAL_SMARTCARD_CLEAR_FLAG(hsmartcard,
2609
                             SMARTCARD_CLEAR_OREF | SMARTCARD_CLEAR_NEF | SMARTCARD_CLEAR_PEF | SMARTCARD_CLEAR_FEF | SMARTCARD_CLEAR_RTOF |
2662
                             SMARTCARD_CLEAR_OREF | SMARTCARD_CLEAR_NEF | SMARTCARD_CLEAR_PEF | SMARTCARD_CLEAR_FEF |
2610
                             SMARTCARD_CLEAR_EOBF);
2663
                             SMARTCARD_CLEAR_RTOF | SMARTCARD_CLEAR_EOBF);
2611
 
2664
 
2612
  /* Restore hsmartcard->gState and hsmartcard->RxState to Ready */
2665
  /* Restore hsmartcard->gState and hsmartcard->RxState to Ready */
2613
  hsmartcard->gState  = HAL_SMARTCARD_STATE_READY;
2666
  hsmartcard->gState  = HAL_SMARTCARD_STATE_READY;
2614
  hsmartcard->RxState = HAL_SMARTCARD_STATE_READY;
2667
  hsmartcard->RxState = HAL_SMARTCARD_STATE_READY;
2615
 
2668
 
Line 2653... Line 2706...
2653
  /* Reset errorCode */
2706
  /* Reset errorCode */
2654
  hsmartcard->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
2707
  hsmartcard->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
2655
 
2708
 
2656
  /* Clear the Error flags in the ICR register */
2709
  /* Clear the Error flags in the ICR register */
2657
  __HAL_SMARTCARD_CLEAR_FLAG(hsmartcard,
2710
  __HAL_SMARTCARD_CLEAR_FLAG(hsmartcard,
2658
                             SMARTCARD_CLEAR_OREF | SMARTCARD_CLEAR_NEF | SMARTCARD_CLEAR_PEF | SMARTCARD_CLEAR_FEF | SMARTCARD_CLEAR_RTOF |
2711
                             SMARTCARD_CLEAR_OREF | SMARTCARD_CLEAR_NEF | SMARTCARD_CLEAR_PEF | SMARTCARD_CLEAR_FEF |
2659
                             SMARTCARD_CLEAR_EOBF);
2712
                             SMARTCARD_CLEAR_RTOF | SMARTCARD_CLEAR_EOBF);
2660
 
2713
 
2661
  /* Restore hsmartcard->gState and hsmartcard->RxState to Ready */
2714
  /* Restore hsmartcard->gState and hsmartcard->RxState to Ready */
2662
  hsmartcard->gState  = HAL_SMARTCARD_STATE_READY;
2715
  hsmartcard->gState  = HAL_SMARTCARD_STATE_READY;
2663
  hsmartcard->RxState = HAL_SMARTCARD_STATE_READY;
2716
  hsmartcard->RxState = HAL_SMARTCARD_STATE_READY;
2664
 
2717
 
Line 2715... Line 2768...
2715
 
2768
 
2716
  hsmartcard->RxXferCount = 0U;
2769
  hsmartcard->RxXferCount = 0U;
2717
 
2770
 
2718
  /* Clear the Error flags in the ICR register */
2771
  /* Clear the Error flags in the ICR register */
2719
  __HAL_SMARTCARD_CLEAR_FLAG(hsmartcard,
2772
  __HAL_SMARTCARD_CLEAR_FLAG(hsmartcard,
2720
                             SMARTCARD_CLEAR_OREF | SMARTCARD_CLEAR_NEF | SMARTCARD_CLEAR_PEF | SMARTCARD_CLEAR_FEF | SMARTCARD_CLEAR_RTOF |
2773
                             SMARTCARD_CLEAR_OREF | SMARTCARD_CLEAR_NEF | SMARTCARD_CLEAR_PEF | SMARTCARD_CLEAR_FEF |
2721
                             SMARTCARD_CLEAR_EOBF);
2774
                             SMARTCARD_CLEAR_RTOF | SMARTCARD_CLEAR_EOBF);
2722
 
2775
 
2723
  /* Restore hsmartcard->RxState to Ready */
2776
  /* Restore hsmartcard->RxState to Ready */
2724
  hsmartcard->RxState = HAL_SMARTCARD_STATE_READY;
2777
  hsmartcard->RxState = HAL_SMARTCARD_STATE_READY;
2725
 
2778
 
2726
#if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1)
2779
#if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1)
Line 2778... Line 2831...
2778
  {
2831
  {
2779
    /* Disable the SMARTCARD Error Interrupt: (Frame error) */
2832
    /* Disable the SMARTCARD Error Interrupt: (Frame error) */
2780
    CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE);
2833
    CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE);
2781
  }
2834
  }
2782
 
2835
 
2783
  /* Re-enable Rx at end of transmission if initial mode is Rx/Tx */
2836
  /* Disable the Peripheral first to update mode */
-
 
2837
  CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_UE);
2784
  if (hsmartcard->Init.Mode == SMARTCARD_MODE_TX_RX)
2838
  if ((hsmartcard->Init.Mode == SMARTCARD_MODE_TX)
-
 
2839
      && (hsmartcard->Init.NACKEnable == SMARTCARD_NACK_ENABLE))
2785
  {
2840
  {
2786
    /* Disable the Peripheral first to update modes */
2841
    /* In case of TX only mode, if NACK is enabled, receiver block has been enabled
2787
    CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_UE);
-
 
2788
    SET_BIT(hsmartcard->Instance->CR1, USART_CR1_RE);
-
 
2789
    /* Enable the Peripheral */
2842
       for Transmit phase. Disable this receiver block. */
2790
    SET_BIT(hsmartcard->Instance->CR1, USART_CR1_UE);
2843
    CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_RE);
2791
  }
2844
  }
-
 
2845
  if ((hsmartcard->Init.Mode == SMARTCARD_MODE_TX_RX)
-
 
2846
      || (hsmartcard->Init.NACKEnable == SMARTCARD_NACK_ENABLE))
-
 
2847
  {
-
 
2848
    /* Perform a TX FIFO Flush at end of Tx phase, as all sent bytes are appearing in Rx Data register */
-
 
2849
    __HAL_SMARTCARD_FLUSH_DRREGISTER(hsmartcard);
-
 
2850
  }
-
 
2851
  SET_BIT(hsmartcard->Instance->CR1, USART_CR1_UE);
2792
 
2852
 
2793
  /* Tx process is ended, restore hsmartcard->gState to Ready */
2853
  /* Tx process is ended, restore hsmartcard->gState to Ready */
2794
  hsmartcard->gState = HAL_SMARTCARD_STATE_READY;
2854
  hsmartcard->gState = HAL_SMARTCARD_STATE_READY;
2795
 
2855
 
2796
  /* Clear TxISR function pointer */
2856
  /* Clear TxISR function pointer */