Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2 | Rev 6 | ||
---|---|---|---|
Line 118... | Line 118... | ||
118 | Note that the CAN state (accessible from the API HAL_CAN_GetState()) |
118 | Note that the CAN state (accessible from the API HAL_CAN_GetState()) |
119 | is HAL_CAN_STATE_SLEEP_PENDING as soon as the sleep mode request is |
119 | is HAL_CAN_STATE_SLEEP_PENDING as soon as the sleep mode request is |
120 | submitted (the sleep mode is not yet entered), and become |
120 | submitted (the sleep mode is not yet entered), and become |
121 | HAL_CAN_STATE_SLEEP_ACTIVE when the sleep mode is effective. |
121 | HAL_CAN_STATE_SLEEP_ACTIVE when the sleep mode is effective. |
122 | 122 | ||
123 | (#) The wake-up from sleep mode can be trigged by two ways: |
123 | (#) The wake-up from sleep mode can be triggered by two ways: |
124 | (++) Using HAL_CAN_WakeUp(). When returning from this function, |
124 | (++) Using HAL_CAN_WakeUp(). When returning from this function, |
125 | the sleep mode is exited (if return status is HAL_OK). |
125 | the sleep mode is exited (if return status is HAL_OK). |
126 | (++) When a start of Rx CAN frame is detected by the CAN peripheral, |
126 | (++) When a start of Rx CAN frame is detected by the CAN peripheral, |
127 | if automatic wake up mode is enabled. |
127 | if automatic wake up mode is enabled. |
128 | 128 | ||
129 | *** Callback registration *** |
129 | *** Callback registration *** |
130 | ============================================= |
130 | ============================================= |
131 | 131 | ||
132 | The compilation define USE_HAL_CAN_REGISTER_CALLBACKS when set to 1 |
132 | The compilation define USE_HAL_CAN_REGISTER_CALLBACKS when set to 1 |
133 | allows the user to configure dynamically the driver callbacks. |
133 | allows the user to configure dynamically the driver callbacks. |
134 | Use Function @ref HAL_CAN_RegisterCallback() to register an interrupt callback. |
134 | Use Function HAL_CAN_RegisterCallback() to register an interrupt callback. |
135 | 135 | ||
136 | Function @ref HAL_CAN_RegisterCallback() allows to register following callbacks: |
136 | Function HAL_CAN_RegisterCallback() allows to register following callbacks: |
137 | (+) TxMailbox0CompleteCallback : Tx Mailbox 0 Complete Callback. |
137 | (+) TxMailbox0CompleteCallback : Tx Mailbox 0 Complete Callback. |
138 | (+) TxMailbox1CompleteCallback : Tx Mailbox 1 Complete Callback. |
138 | (+) TxMailbox1CompleteCallback : Tx Mailbox 1 Complete Callback. |
139 | (+) TxMailbox2CompleteCallback : Tx Mailbox 2 Complete Callback. |
139 | (+) TxMailbox2CompleteCallback : Tx Mailbox 2 Complete Callback. |
140 | (+) TxMailbox0AbortCallback : Tx Mailbox 0 Abort Callback. |
140 | (+) TxMailbox0AbortCallback : Tx Mailbox 0 Abort Callback. |
141 | (+) TxMailbox1AbortCallback : Tx Mailbox 1 Abort Callback. |
141 | (+) TxMailbox1AbortCallback : Tx Mailbox 1 Abort Callback. |
Line 150... | Line 150... | ||
150 | (+) MspInitCallback : CAN MspInit. |
150 | (+) MspInitCallback : CAN MspInit. |
151 | (+) MspDeInitCallback : CAN MspDeInit. |
151 | (+) MspDeInitCallback : CAN MspDeInit. |
152 | This function takes as parameters the HAL peripheral handle, the Callback ID |
152 | This function takes as parameters the HAL peripheral handle, the Callback ID |
153 | and a pointer to the user callback function. |
153 | and a pointer to the user callback function. |
154 | 154 | ||
155 | Use function @ref HAL_CAN_UnRegisterCallback() to reset a callback to the default |
155 | Use function HAL_CAN_UnRegisterCallback() to reset a callback to the default |
156 | weak function. |
156 | weak function. |
157 | @ref HAL_CAN_UnRegisterCallback takes as parameters the HAL peripheral handle, |
157 | HAL_CAN_UnRegisterCallback takes as parameters the HAL peripheral handle, |
158 | and the Callback ID. |
158 | and the Callback ID. |
159 | This function allows to reset following callbacks: |
159 | This function allows to reset following callbacks: |
160 | (+) TxMailbox0CompleteCallback : Tx Mailbox 0 Complete Callback. |
160 | (+) TxMailbox0CompleteCallback : Tx Mailbox 0 Complete Callback. |
161 | (+) TxMailbox1CompleteCallback : Tx Mailbox 1 Complete Callback. |
161 | (+) TxMailbox1CompleteCallback : Tx Mailbox 1 Complete Callback. |
162 | (+) TxMailbox2CompleteCallback : Tx Mailbox 2 Complete Callback. |
162 | (+) TxMailbox2CompleteCallback : Tx Mailbox 2 Complete Callback. |
Line 171... | Line 171... | ||
171 | (+) WakeUpFromRxMsgCallback : Wake Up From Rx Message Callback. |
171 | (+) WakeUpFromRxMsgCallback : Wake Up From Rx Message Callback. |
172 | (+) ErrorCallback : Error Callback. |
172 | (+) ErrorCallback : Error Callback. |
173 | (+) MspInitCallback : CAN MspInit. |
173 | (+) MspInitCallback : CAN MspInit. |
174 | (+) MspDeInitCallback : CAN MspDeInit. |
174 | (+) MspDeInitCallback : CAN MspDeInit. |
175 | 175 | ||
176 | By default, after the @ref HAL_CAN_Init() and when the state is HAL_CAN_STATE_RESET, |
176 | By default, after the HAL_CAN_Init() and when the state is HAL_CAN_STATE_RESET, |
177 | all callbacks are set to the corresponding weak functions: |
177 | all callbacks are set to the corresponding weak functions: |
178 | example @ref HAL_CAN_ErrorCallback(). |
178 | example HAL_CAN_ErrorCallback(). |
179 | Exception done for MspInit and MspDeInit functions that are |
179 | Exception done for MspInit and MspDeInit functions that are |
180 | reset to the legacy weak function in the @ref HAL_CAN_Init()/ @ref HAL_CAN_DeInit() only when |
180 | reset to the legacy weak function in the HAL_CAN_Init()/ HAL_CAN_DeInit() only when |
181 | these callbacks are null (not registered beforehand). |
181 | these callbacks are null (not registered beforehand). |
182 | if not, MspInit or MspDeInit are not null, the @ref HAL_CAN_Init()/ @ref HAL_CAN_DeInit() |
182 | if not, MspInit or MspDeInit are not null, the HAL_CAN_Init()/ HAL_CAN_DeInit() |
183 | keep and use the user MspInit/MspDeInit callbacks (registered beforehand) |
183 | keep and use the user MspInit/MspDeInit callbacks (registered beforehand) |
184 | 184 | ||
185 | Callbacks can be registered/unregistered in HAL_CAN_STATE_READY state only. |
185 | Callbacks can be registered/unregistered in HAL_CAN_STATE_READY state only. |
186 | Exception done MspInit/MspDeInit that can be registered/unregistered |
186 | Exception done MspInit/MspDeInit that can be registered/unregistered |
187 | in HAL_CAN_STATE_READY or HAL_CAN_STATE_RESET state, |
187 | in HAL_CAN_STATE_READY or HAL_CAN_STATE_RESET state, |
188 | thus registered (user) MspInit/DeInit callbacks can be used during the Init/DeInit. |
188 | thus registered (user) MspInit/DeInit callbacks can be used during the Init/DeInit. |
189 | In that case first register the MspInit/MspDeInit user callbacks |
189 | In that case first register the MspInit/MspDeInit user callbacks |
190 | using @ref HAL_CAN_RegisterCallback() before calling @ref HAL_CAN_DeInit() |
190 | using HAL_CAN_RegisterCallback() before calling HAL_CAN_DeInit() |
191 | or @ref HAL_CAN_Init() function. |
191 | or HAL_CAN_Init() function. |
192 | 192 | ||
193 | When The compilation define USE_HAL_CAN_REGISTER_CALLBACKS is set to 0 or |
193 | When The compilation define USE_HAL_CAN_REGISTER_CALLBACKS is set to 0 or |
194 | not defined, the callback registration feature is not available and all callbacks |
194 | not defined, the callback registration feature is not available and all callbacks |
195 | are set to the corresponding weak functions. |
195 | are set to the corresponding weak functions. |
196 | 196 | ||
Line 328... | Line 328... | ||
328 | /* Init the low level hardware: CLOCK, NVIC */ |
328 | /* Init the low level hardware: CLOCK, NVIC */ |
329 | HAL_CAN_MspInit(hcan); |
329 | HAL_CAN_MspInit(hcan); |
330 | } |
330 | } |
331 | #endif /* (USE_HAL_CAN_REGISTER_CALLBACKS) */ |
331 | #endif /* (USE_HAL_CAN_REGISTER_CALLBACKS) */ |
332 | 332 | ||
333 | /* Exit from sleep mode */ |
333 | /* Request initialisation */ |
334 | CLEAR_BIT(hcan->Instance->MCR, CAN_MCR_SLEEP); |
334 | SET_BIT(hcan->Instance->MCR, CAN_MCR_INRQ); |
335 | 335 | ||
336 | /* Get tick */ |
336 | /* Get tick */ |
337 | tickstart = HAL_GetTick(); |
337 | tickstart = HAL_GetTick(); |
338 | 338 | ||
339 | /* Check Sleep mode leave acknowledge */ |
339 | /* Wait initialisation acknowledge */ |
340 | while ((hcan->Instance->MSR & CAN_MSR_SLAK) != 0U) |
340 | while ((hcan->Instance->MSR & CAN_MSR_INAK) == 0U) |
341 | { |
341 | { |
342 | if ((HAL_GetTick() - tickstart) > CAN_TIMEOUT_VALUE) |
342 | if ((HAL_GetTick() - tickstart) > CAN_TIMEOUT_VALUE) |
343 | { |
343 | { |
344 | /* Update error code */ |
344 | /* Update error code */ |
345 | hcan->ErrorCode |= HAL_CAN_ERROR_TIMEOUT; |
345 | hcan->ErrorCode |= HAL_CAN_ERROR_TIMEOUT; |
Line 349... | Line 349... | ||
349 | 349 | ||
350 | return HAL_ERROR; |
350 | return HAL_ERROR; |
351 | } |
351 | } |
352 | } |
352 | } |
353 | 353 | ||
354 | /* Request initialisation */ |
354 | /* Exit from sleep mode */ |
355 | SET_BIT(hcan->Instance->MCR, CAN_MCR_INRQ); |
355 | CLEAR_BIT(hcan->Instance->MCR, CAN_MCR_SLEEP); |
356 | 356 | ||
357 | /* Get tick */ |
357 | /* Get tick */ |
358 | tickstart = HAL_GetTick(); |
358 | tickstart = HAL_GetTick(); |
359 | 359 | ||
360 | /* Wait initialisation acknowledge */ |
360 | /* Check Sleep mode leave acknowledge */ |
361 | while ((hcan->Instance->MSR & CAN_MSR_INAK) == 0U) |
361 | while ((hcan->Instance->MSR & CAN_MSR_SLAK) != 0U) |
362 | { |
362 | { |
363 | if ((HAL_GetTick() - tickstart) > CAN_TIMEOUT_VALUE) |
363 | if ((HAL_GetTick() - tickstart) > CAN_TIMEOUT_VALUE) |
364 | { |
364 | { |
365 | /* Update error code */ |
365 | /* Update error code */ |
366 | hcan->ErrorCode |= HAL_CAN_ERROR_TIMEOUT; |
366 | hcan->ErrorCode |= HAL_CAN_ERROR_TIMEOUT; |
Line 535... | Line 535... | ||
535 | * To be used instead of the weak predefined callback |
535 | * To be used instead of the weak predefined callback |
536 | * @param hcan pointer to a CAN_HandleTypeDef structure that contains |
536 | * @param hcan pointer to a CAN_HandleTypeDef structure that contains |
537 | * the configuration information for CAN module |
537 | * the configuration information for CAN module |
538 | * @param CallbackID ID of the callback to be registered |
538 | * @param CallbackID ID of the callback to be registered |
539 | * This parameter can be one of the following values: |
539 | * This parameter can be one of the following values: |
540 | * @arg @ref HAL_CAN_TX_MAILBOX0_COMPLETE_CALLBACK_CB_ID Tx Mailbox 0 Complete callback ID |
540 | * @arg @ref HAL_CAN_TX_MAILBOX0_COMPLETE_CB_ID Tx Mailbox 0 Complete callback ID |
541 | * @arg @ref HAL_CAN_TX_MAILBOX1_COMPLETE_CALLBACK_CB_ID Tx Mailbox 1 Complete callback ID |
541 | * @arg @ref HAL_CAN_TX_MAILBOX1_COMPLETE_CB_ID Tx Mailbox 1 Complete callback ID |
542 | * @arg @ref HAL_CAN_TX_MAILBOX2_COMPLETE_CALLBACK_CB_ID Tx Mailbox 2 Complete callback ID |
542 | * @arg @ref HAL_CAN_TX_MAILBOX2_COMPLETE_CB_ID Tx Mailbox 2 Complete callback ID |
543 | * @arg @ref HAL_CAN_TX_MAILBOX0_ABORT_CALLBACK_CB_ID Tx Mailbox 0 Abort callback ID |
543 | * @arg @ref HAL_CAN_TX_MAILBOX0_ABORT_CB_ID Tx Mailbox 0 Abort callback ID |
544 | * @arg @ref HAL_CAN_TX_MAILBOX1_ABORT_CALLBACK_CB_ID Tx Mailbox 1 Abort callback ID |
544 | * @arg @ref HAL_CAN_TX_MAILBOX1_ABORT_CB_ID Tx Mailbox 1 Abort callback ID |
545 | * @arg @ref HAL_CAN_TX_MAILBOX2_ABORT_CALLBACK_CB_ID Tx Mailbox 2 Abort callback ID |
545 | * @arg @ref HAL_CAN_TX_MAILBOX2_ABORT_CB_ID Tx Mailbox 2 Abort callback ID |
546 | * @arg @ref HAL_CAN_RX_FIFO0_MSG_PENDING_CALLBACK_CB_ID Rx Fifo 0 message pending callback ID |
546 | * @arg @ref HAL_CAN_RX_FIFO0_MSG_PENDING_CB_ID Rx Fifo 0 message pending callback ID |
547 | * @arg @ref HAL_CAN_RX_FIFO0_FULL_CALLBACK_CB_ID Rx Fifo 0 full callback ID |
547 | * @arg @ref HAL_CAN_RX_FIFO0_FULL_CB_ID Rx Fifo 0 full callback ID |
548 | * @arg @ref HAL_CAN_RX_FIFO1_MSGPENDING_CALLBACK_CB_ID Rx Fifo 1 message pending callback ID |
548 | * @arg @ref HAL_CAN_RX_FIFO1_MSG_PENDING_CB_ID Rx Fifo 1 message pending callback ID |
549 | * @arg @ref HAL_CAN_RX_FIFO1_FULL_CALLBACK_CB_ID Rx Fifo 1 full callback ID |
549 | * @arg @ref HAL_CAN_RX_FIFO1_FULL_CB_ID Rx Fifo 1 full callback ID |
550 | * @arg @ref HAL_CAN_SLEEP_CALLBACK_CB_ID Sleep callback ID |
550 | * @arg @ref HAL_CAN_SLEEP_CB_ID Sleep callback ID |
551 | * @arg @ref HAL_CAN_WAKEUP_FROM_RX_MSG_CALLBACK_CB_ID Wake Up from Rx message callback ID |
551 | * @arg @ref HAL_CAN_WAKEUP_FROM_RX_MSG_CB_ID Wake Up from Rx message callback ID |
552 | * @arg @ref HAL_CAN_ERROR_CALLBACK_CB_ID Error callback ID |
552 | * @arg @ref HAL_CAN_ERROR_CB_ID Error callback ID |
553 | * @arg @ref HAL_CAN_MSPINIT_CB_ID MspInit callback ID |
553 | * @arg @ref HAL_CAN_MSPINIT_CB_ID MspInit callback ID |
554 | * @arg @ref HAL_CAN_MSPDEINIT_CB_ID MspDeInit callback ID |
554 | * @arg @ref HAL_CAN_MSPDEINIT_CB_ID MspDeInit callback ID |
555 | * @param pCallback pointer to the Callback function |
555 | * @param pCallback pointer to the Callback function |
556 | * @retval HAL status |
556 | * @retval HAL status |
557 | */ |
557 | */ |
Line 678... | Line 678... | ||
678 | * CAN callabck is redirected to the weak predefined callback |
678 | * CAN callabck is redirected to the weak predefined callback |
679 | * @param hcan pointer to a CAN_HandleTypeDef structure that contains |
679 | * @param hcan pointer to a CAN_HandleTypeDef structure that contains |
680 | * the configuration information for CAN module |
680 | * the configuration information for CAN module |
681 | * @param CallbackID ID of the callback to be unregistered |
681 | * @param CallbackID ID of the callback to be unregistered |
682 | * This parameter can be one of the following values: |
682 | * This parameter can be one of the following values: |
683 | * @arg @ref HAL_CAN_TX_MAILBOX0_COMPLETE_CALLBACK_CB_ID Tx Mailbox 0 Complete callback ID |
683 | * @arg @ref HAL_CAN_TX_MAILBOX0_COMPLETE_CB_ID Tx Mailbox 0 Complete callback ID |
684 | * @arg @ref HAL_CAN_TX_MAILBOX1_COMPLETE_CALLBACK_CB_ID Tx Mailbox 1 Complete callback ID |
684 | * @arg @ref HAL_CAN_TX_MAILBOX1_COMPLETE_CB_ID Tx Mailbox 1 Complete callback ID |
685 | * @arg @ref HAL_CAN_TX_MAILBOX2_COMPLETE_CALLBACK_CB_ID Tx Mailbox 2 Complete callback ID |
685 | * @arg @ref HAL_CAN_TX_MAILBOX2_COMPLETE_CB_ID Tx Mailbox 2 Complete callback ID |
686 | * @arg @ref HAL_CAN_TX_MAILBOX0_ABORT_CALLBACK_CB_ID Tx Mailbox 0 Abort callback ID |
686 | * @arg @ref HAL_CAN_TX_MAILBOX0_ABORT_CB_ID Tx Mailbox 0 Abort callback ID |
687 | * @arg @ref HAL_CAN_TX_MAILBOX1_ABORT_CALLBACK_CB_ID Tx Mailbox 1 Abort callback ID |
687 | * @arg @ref HAL_CAN_TX_MAILBOX1_ABORT_CB_ID Tx Mailbox 1 Abort callback ID |
688 | * @arg @ref HAL_CAN_TX_MAILBOX2_ABORT_CALLBACK_CB_ID Tx Mailbox 2 Abort callback ID |
688 | * @arg @ref HAL_CAN_TX_MAILBOX2_ABORT_CB_ID Tx Mailbox 2 Abort callback ID |
689 | * @arg @ref HAL_CAN_RX_FIFO0_MSG_PENDING_CALLBACK_CB_ID Rx Fifo 0 message pending callback ID |
689 | * @arg @ref HAL_CAN_RX_FIFO0_MSG_PENDING_CB_ID Rx Fifo 0 message pending callback ID |
690 | * @arg @ref HAL_CAN_RX_FIFO0_FULL_CALLBACK_CB_ID Rx Fifo 0 full callback ID |
690 | * @arg @ref HAL_CAN_RX_FIFO0_FULL_CB_ID Rx Fifo 0 full callback ID |
691 | * @arg @ref HAL_CAN_RX_FIFO1_MSGPENDING_CALLBACK_CB_ID Rx Fifo 1 message pending callback ID |
691 | * @arg @ref HAL_CAN_RX_FIFO1_MSG_PENDING_CB_ID Rx Fifo 1 message pending callback ID |
692 | * @arg @ref HAL_CAN_RX_FIFO1_FULL_CALLBACK_CB_ID Rx Fifo 1 full callback ID |
692 | * @arg @ref HAL_CAN_RX_FIFO1_FULL_CB_ID Rx Fifo 1 full callback ID |
693 | * @arg @ref HAL_CAN_SLEEP_CALLBACK_CB_ID Sleep callback ID |
693 | * @arg @ref HAL_CAN_SLEEP_CB_ID Sleep callback ID |
694 | * @arg @ref HAL_CAN_WAKEUP_FROM_RX_MSG_CALLBACK_CB_ID Wake Up from Rx message callback ID |
694 | * @arg @ref HAL_CAN_WAKEUP_FROM_RX_MSG_CB_ID Wake Up from Rx message callback ID |
695 | * @arg @ref HAL_CAN_ERROR_CALLBACK_CB_ID Error callback ID |
695 | * @arg @ref HAL_CAN_ERROR_CB_ID Error callback ID |
696 | * @arg @ref HAL_CAN_MSPINIT_CB_ID MspInit callback ID |
696 | * @arg @ref HAL_CAN_MSPINIT_CB_ID MspInit callback ID |
697 | * @arg @ref HAL_CAN_MSPDEINIT_CB_ID MspDeInit callback ID |
697 | * @arg @ref HAL_CAN_MSPDEINIT_CB_ID MspDeInit callback ID |
698 | * @retval HAL status |
698 | * @retval HAL status |
699 | */ |
699 | */ |
700 | HAL_StatusTypeDef HAL_CAN_UnRegisterCallback(CAN_HandleTypeDef *hcan, HAL_CAN_CallbackIDTypeDef CallbackID) |
700 | HAL_StatusTypeDef HAL_CAN_UnRegisterCallback(CAN_HandleTypeDef *hcan, HAL_CAN_CallbackIDTypeDef CallbackID) |
Line 1867... | Line 1867... | ||
1867 | if ((interrupts & CAN_IT_RX_FIFO0_MSG_PENDING) != 0U) |
1867 | if ((interrupts & CAN_IT_RX_FIFO0_MSG_PENDING) != 0U) |
1868 | { |
1868 | { |
1869 | /* Check if message is still pending */ |
1869 | /* Check if message is still pending */ |
1870 | if ((hcan->Instance->RF0R & CAN_RF0R_FMP0) != 0U) |
1870 | if ((hcan->Instance->RF0R & CAN_RF0R_FMP0) != 0U) |
1871 | { |
1871 | { |
1872 | /* Receive FIFO 0 mesage pending Callback */ |
1872 | /* Receive FIFO 0 message pending Callback */ |
1873 | #if USE_HAL_CAN_REGISTER_CALLBACKS == 1 |
1873 | #if USE_HAL_CAN_REGISTER_CALLBACKS == 1 |
1874 | /* Call registered callback*/ |
1874 | /* Call registered callback*/ |
1875 | hcan->RxFifo0MsgPendingCallback(hcan); |
1875 | hcan->RxFifo0MsgPendingCallback(hcan); |
1876 | #else |
1876 | #else |
1877 | /* Call weak (surcharged) callback */ |
1877 | /* Call weak (surcharged) callback */ |
Line 1916... | Line 1916... | ||
1916 | if ((interrupts & CAN_IT_RX_FIFO1_MSG_PENDING) != 0U) |
1916 | if ((interrupts & CAN_IT_RX_FIFO1_MSG_PENDING) != 0U) |
1917 | { |
1917 | { |
1918 | /* Check if message is still pending */ |
1918 | /* Check if message is still pending */ |
1919 | if ((hcan->Instance->RF1R & CAN_RF1R_FMP1) != 0U) |
1919 | if ((hcan->Instance->RF1R & CAN_RF1R_FMP1) != 0U) |
1920 | { |
1920 | { |
1921 | /* Receive FIFO 1 mesage pending Callback */ |
1921 | /* Receive FIFO 1 message pending Callback */ |
1922 | #if USE_HAL_CAN_REGISTER_CALLBACKS == 1 |
1922 | #if USE_HAL_CAN_REGISTER_CALLBACKS == 1 |
1923 | /* Call registered callback*/ |
1923 | /* Call registered callback*/ |
1924 | hcan->RxFifo1MsgPendingCallback(hcan); |
1924 | hcan->RxFifo1MsgPendingCallback(hcan); |
1925 | #else |
1925 | #else |
1926 | /* Call weak (surcharged) callback */ |
1926 | /* Call weak (surcharged) callback */ |