cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F373 CAN troubleshooting

ing
Associate II
Posted on June 16, 2014 at 19:57

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 June 16, 2014 at 20:30

Your #defines are what?

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Posted on June 16, 2014 at 20:40

/* Enable GPIO clock */
RCC_AHBPeriphClockCmd(CAN_GPIO_CLK, ENABLE);
GPIO_DeInit(CAN_GPIO_PORT); //sarah, if you must, do it first, it'll break everything on the port
/* Connect CAN pins to AF7 */
GPIO_PinAFConfig(CAN_GPIO_PORT, CAN_RX_SOURCE, CAN_AF_PORT);
GPIO_PinAFConfig(CAN_GPIO_PORT, CAN_TX_SOURCE, CAN_AF_PORT); 
/* Configure CAN RX and TX pins */
GPIO_InitStructure.GPIO_Pin = CAN_RX_PIN | CAN_TX_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(CAN_GPIO_PORT, &GPIO_InitStructure);

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
ing
Associate II
Posted on June 17, 2014 at 01:04

Hello clive1,

I really hoped you'd reply!! 🙂

I saw you're the expert here.

I already tried your configuration, but nothing happens.

My defines are (sorry):

/* Exported constants --------------------------------------------------------*/

//#define CANx                       CAN1

//#define CAN_CLK                    RCC_APB1Periph_CAN1

//#define CAN_RX_PIN                 GPIO_Pin_0

//#define CAN_TX_PIN                 GPIO_Pin_1

//#define CAN_GPIO_PORT              GPIOD

//#define CAN_GPIO_CLK               RCC_AHBPeriph_GPIOD

//#define CAN_AF_PORT                GPIO_AF_7

//#define CAN_RX_SOURCE              GPIO_PinSource0

//#define CAN_TX_SOURCE              GPIO_PinSource1

#define CANx                       CAN1

#define CAN_CLK                    RCC_APB1Periph_CAN1

#define CAN_RX_PIN                 GPIO_Pin_11

#define CAN_TX_PIN                 GPIO_Pin_12

#define CAN_GPIO_PORT              GPIOA

#define CAN_GPIO_CLK               RCC_AHBPeriph_GPIOA

#define CAN_AF_PORT                GPIO_AF_7

#define CAN_RX_SOURCE              GPIO_PinSource11

#define CAN_TX_SOURCE              GPIO_PinSource12

the commented out #defines are from the example, and the actual ones are to use the PA11-12 pins instead. Where am I doing wrong?

Posted on June 17, 2014 at 02:14

#define CAN_AF_PORT                GPIO_AF_9

It's not AF7

You have to pay attention to pin functions described in the Data Sheet

http://www.st.com/st-web-ui/static/active/en/resource/technical/document/datasheet/DM00046749.pdf

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
ing
Associate II
Posted on June 17, 2014 at 02:17

Hello clive1!!

 After reading nearly every single post in the forum, I think I've found (part of) the solution:

https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=https%3a%2f%2fmy%2est%2ecom%2fpublic%2fSTe2ecommunities%2fmcu%2fLists%2fcortex_mx_stm32%2fSTM32F3%20CAN%20Init&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&currentviews...

basically to use PA11/12 pins I have to set  GPIO_AF_9 instead of GPIO_AF_7.

Now the CAN initialization DOES NOT fail, even if after that I have some problems in transmission. I'll check what's going wrong, hopefully it shouldn't take this long.

Thanks a lot for you quick response!! :D

koszo
Associate
Posted on November 06, 2015 at 16:55

Helo gaijingeek!

I have problem with stm32f373.  I wrote a CAN application that works on the R8 (64k flash) version, but the RB (128k flash)  and RC(256k) versions do not.

I checked the alternate setups, CAN setups, etc...

static void CAN_Config(void)

{

  CAN_FilterConfTypeDef  sFilterConfig;

  static CanTxMsgTypeDef        TxMessage;

  static CanRxMsgTypeDef        RxMessage;

  /*##-1- Configure the CAN peripheral #######################################*/

  CanHandle.Instance = CANx;

  CanHandle.pTxMsg = &TxMessage;

  CanHandle.pRxMsg = &RxMessage;

  CanHandle.Init.TTCM   = DISABLE;

  CanHandle.Init.ABOM   = ENABLE;

  CanHandle.Init.AWUM   = ENABLE;

  CanHandle.Init.NART   = ENABLE;

  CanHandle.Init.RFLM   = DISABLE;

  CanHandle.Init.TXFP   = DISABLE;

  CanHandle.Init.Mode   = CAN_MODE_NORMAL;

  CanHandle.Init.SJW    = CAN_SJW_1TQ;

  CanHandle.Init.BS1    = CAN_BS1_8TQ;

  CanHandle.Init.BS2    = CAN_BS2_1TQ;

  CanHandle.Init.Prescaler = 2;

  if (HAL_CAN_Init(&CanHandle) != HAL_OK)

  {

    /* Initiliazation Error */

    Error_Handler();

  }

  /*##-2- Configure the CAN Filter ###########################################*/

  sFilterConfig.FilterNumber = 0;

  sFilterConfig.FilterMode = CAN_FILTERMODE_IDMASK;

  sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;

  sFilterConfig.FilterIdHigh = 0x0000;

  sFilterConfig.FilterIdLow = 0x0000;

  sFilterConfig.FilterMaskIdHigh = 0x0000;

  sFilterConfig.FilterMaskIdLow = 0x0000;

  sFilterConfig.FilterFIFOAssignment = 0;

  sFilterConfig.FilterActivation = ENABLE;

  sFilterConfig.BankNumber = 14;

  if (HAL_CAN_ConfigFilter(&CanHandle, &sFilterConfig) != HAL_OK)

  {

    /* Filter configuration Error */

    Error_Handler();

  }

  /*##-3- Configure Transmission process #####################################*/

  CanHandle.pTxMsg->StdId = 0x321;

  CanHandle.pTxMsg->ExtId = 0x01;

  CanHandle.pTxMsg->RTR = CAN_RTR_DATA;

  CanHandle.pTxMsg->IDE = CAN_ID_STD;

  CanHandle.pTxMsg->DLC = 2;

}

  **

  * @brief CAN MSP Initialization

  *        This function configures the hardware resources used in this example:

  *           - Peripheral's clock enable

  *           - Peripheral's GPIO Configuration

  *           - NVIC configuration for DMA interrupt request enable

  * @param hcan: CAN handle pointer

  * @retval None

  */

void HAL_CAN_MspInit(CAN_HandleTypeDef *hcan)

{

  GPIO_InitTypeDef   GPIO_InitStruct;

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

  /* CAN1 Periph clock enable */

  CANx_CLK_ENABLE();

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

  CANx_GPIO_CLK_ENABLE();

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

  /* CAN1 TX GPIO pin configuration */

  GPIO_InitStruct.Pin = CANx_TX_PIN;

  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

  GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;

  GPIO_InitStruct.Pull = GPIO_PULLUP;

  GPIO_InitStruct.Alternate =  CANx_TX_AF;

  HAL_GPIO_Init(CANx_TX_GPIO_PORT, &GPIO_InitStruct);

  /* CAN1 RX GPIO pin configuration */

  GPIO_InitStruct.Pin = CANx_RX_PIN;

  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

  GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;

  GPIO_InitStruct.Pull = GPIO_PULLUP;

  GPIO_InitStruct.Alternate =  CANx_RX_AF;

  HAL_GPIO_Init(CANx_RX_GPIO_PORT, &GPIO_InitStruct);

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

  /* NVIC configuration for CAN1 Reception complete interrupt */

  HAL_NVIC_SetPriority(CANx_RX_IRQn, 1, 0);

  HAL_NVIC_EnableIRQ(CANx_RX_IRQn);

}

/* Exported types ------------------------------------------------------------*/

/* Exported constants --------------------------------------------------------*/

/* User can use this section to tailor CANx instance used and associated

   resources */

/* Definition for CANx clock resources */

#define CANx                            CAN

#define CANx_CLK_ENABLE()               __CAN_CLK_ENABLE()

#define CANx_GPIO_CLK_ENABLE()          __GPIOB_CLK_ENABLE()

#define CANx_FORCE_RESET()              __CAN_FORCE_RESET()

#define CANx_RELEASE_RESET()            __CAN_RELEASE_RESET()

/* Definition for USARTx Pins */

#define CANx_TX_PIN                    GPIO_PIN_9

#define CANx_TX_GPIO_PORT              GPIOB

#define CANx_TX_AF                     GPIO_AF9_CAN

#define CANx_RX_PIN                    GPIO_PIN_8

#define CANx_RX_GPIO_PORT              GPIOB

#define CANx_RX_AF                     GPIO_AF9_CAN

/* Definition for USARTx's NVIC */

#define CANx_RX_IRQn                   CAN_RX0_IRQn

#define CANx_RX_IRQHandler             CAN_RX0_IRQHandler

Please help me.

Posted on November 06, 2015 at 17:29

Check the vector table in startup.s, there may be additional IRQ Handlers, and different naming, double check those.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
koszo
Associate
Posted on November 09, 2015 at 08:08

Hello clive1!

Thanks for the idea, but one-to-oneI compile the

STM32Cube_FW_F3_V1.3.0\Projects\STM32373C_EVAL\Examples\CAN\CAN_Networking\project and the legacySTM32F37x_DSP_StdPeriph_Lib_V1.0.0\Project\STM32F37x_StdPeriph_Examples\CAN\CAN_Networking\ project.

One does not work.

Initialization error-free, I get an timeouterror when sending.

I checked the startup fileand the vector table is the same as in the documentation.Use 64-foot version number, I use 64-foot version number, so I can not try the same project.

________________

Attachments :

STM32Cube_FW_F3_V1.3.0.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I0aW&d=%2Fa%2F0X0000000bdw%2FBoUlFDswv9EAZGMK0mNmprsrM8t2VupOWBVIf_h43D4&asPdf=false