2017-04-25 05:10 AM
I use CAN1 and CAN3 on the nucleo board and generate CAN code with stmCube version 4.20.
After automatic init CAN1 and CAN3 I deinit the can and then I try to init CAN1 again.
CAN1 is not working.
I'm looking in the can.c code and found ther I think a bug.
I have change the following in the code.
void
HAL_CAN_MspDeInit(
CAN_HandleTypeDef
* canHandle)
{
if
(canHandle->
Instance
==CAN1)
{
/* USER CODE BEGIN CAN1_MspDeInit 0 */
//*******************************************************
//*******************************************************
HAL_RCC_CAN1_CLK_ENABLED--;
// MY CHANGE in the code
//*******************************************************
//*******************************************************
/* USER CODE END CAN1_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_CAN1_CLK_DISABLE();
/**CAN1 GPIO Configuration
PD0 ------> CAN1_RX
PD1 ------> CAN1_TX
*/
HAL_GPIO_DeInit
(GPIOD, CAN_1_RX_Pin|CAN_1_TX_Pin);
/* Peripheral interrupt
Deinit
*/HAL_NVIC_DisableIRQ
(
CAN1_TX_IRQn);
HAL_NVIC_DisableIRQ
(
CAN1_RX0_IRQn);
HAL_NVIC_DisableIRQ
(
CAN1_RX1_IRQn);
HAL_NVIC_DisableIRQ
(
CAN1_SCE_IRQn);
/* USER CODE BEGIN CAN1_MspDeInit 1 */
/* USER CODE END CAN1_MspDeInit 1 */
}
else if
(canHandle->
Instance
==CAN3)
{
/* USER CODE BEGIN CAN3_MspDeInit 0 */
/* USER CODE END CAN3_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_CAN3_CLK_DISABLE();
__HAL_RCC_CAN2_CLK_DISABLE();
HAL_RCC_CAN1_CLK_ENABLED--;
if
(HAL_RCC_CAN1_CLK_ENABLED==0){
__HAL_RCC_CAN1_CLK_DISABLE();
}
/**CAN3 GPIO Configuration
PA8 ------> CAN3_RX
PB4 ------> CAN3_TX
*/
HAL_GPIO_DeInit
(CAN_2_RX_GPIO_Port, CAN_2_RX_Pin);
HAL_GPIO_DeInit
(CAN_2_TX_GPIO_Port, CAN_2_TX_Pin);
/* Peripheral interrupt
Deinit
*/HAL_NVIC_DisableIRQ
(
CAN3_TX_IRQn);
HAL_NVIC_DisableIRQ
(
CAN3_RX0_IRQn);
HAL_NVIC_DisableIRQ
(
CAN3_RX1_IRQn);
HAL_NVIC_DisableIRQ
(
CAN3_SCE_IRQn);
/* USER CODE BEGIN CAN3_MspDeInit 1 */
/* USER CODE END CAN3_MspDeInit 1 */
}
}
After that it is working. but I do not understand why CAN2 and CAN1 clock is needed
for CAN3. I hope in next cube version the code is corrected.