cancel
Showing results for 
Search instead for 
Did you mean: 

Can fails to initialize on STM32F0RB Nucleo board

fma23
Associate II
Posted on May 12, 2016 at 09:24

The original post was too long to process during our migration. Please click on the attachment to read the original post.
8 REPLIES 8
Posted on May 12, 2016 at 09:44

Pasting in stock library code provides no insight into how you initialize the pins, clocks, etc from your own code, or call this or other library functions.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
fma23
Associate II
Posted on May 12, 2016 at 22:07

Yeah you are right!

The issue I see after debugging is that bit 0 of MSR register does not get reset by the hardware after software reset of bit 0 of the MCR register ( exiting initialization state). Any clue as to why the hardware does not reset INK ( bit 0 ) of the MSR?

fma23
Associate II
Posted on May 12, 2016 at 22:36

This is how I configured my CAN hardware:

void HAL_CAN_MspInit(CAN_HandleTypeDef *hcan)

{

  GPIO_InitTypeDef   GPIO_InitStruct;

  /*##-1- Enable peripherals and GPIO Clocks #################################*/

  /* CAN1 Periph clock enable */

  CAN_CLK_ENABLE();

  /* Enable GPIO clock ****************************************/

  CAN_GPIO_CLK_ENABLE();

  /*##-2- Configure peripheral GPIO ##########################################*/

  /* CAN1 TX GPIO pin configuration */

  GPIO_InitStruct.Pin = GPIO_Pin_CAN_RX;

  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;

  GPIO_InitStruct.Pull = GPIO_PULLUP;

  GPIO_InitStruct.Alternate =  GPIO_AF0_CAN;

  HAL_GPIO_Init(CAN_TX_GPIO_PORT, &GPIO_InitStruct);

  /* CAN1 RX GPIO pin configuration */

  GPIO_InitStruct.Pin =  GPIO_Pin_CAN_RX;

  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;

  GPIO_InitStruct.Pull = GPIO_PULLUP;

  GPIO_InitStruct.Alternate =  GPIO_AF0_CAN;

  HAL_GPIO_Init(CAN_RX_GPIO_PORT, &GPIO_InitStruct);

  /*##-3- Configure the NVIC #################################################*/

  /* NVIC configuration for CAN1 Reception complete interrupt */

  HAL_NVIC_SetPriority(CAN_RX_IRQn, 1, 0);

  HAL_NVIC_EnableIRQ(CAN_RX_IRQn);

}

Posted on May 12, 2016 at 22:48

Are you mixing SPL and HAL code?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
fma23
Associate II
Posted on May 12, 2016 at 23:25

I am sorry what is SPL? 

Posted on May 13, 2016 at 00:03

Standard Peripheral Library

STM32F072B-Discovery_FW_V1.0.1\Libraries\STM32F0xx_StdPeriph_Driver\src\stm32f0xx_can.c

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
fma23
Associate II
Posted on May 13, 2016 at 06:37

I am just using the SPL, exactly from the link you stated below

Posted on May 13, 2016 at 16:08

Ok, but you've presented HAL code being used for initialization.

I would be concerned about mixing the include files from one to the other, as the library code often uses internal bit flags, and shift settings, and not explicitly the bits used is the registers.

Present complete/concise worked examples of code if you expect others to review/replicate tests

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..