0

I'm trying to program the STM32F446 using the CubeMX code generator and the uVision 5 IDE on Windows 10 in order to use the CAN bus.

I've configured my CubeMX project for the STM32-F446RE Nucleo board. I have PA12 configured as CAN1TX and PA11 configured as CAN1RX. The rest of the pins are on default for the STM32-F446RE Nucleo board. I've generated the code for the uVision 5 IDE.

To get started, I'm trying to follow the instructions on how to use the HAL and driver by following the instructions in the comments of stm32f4xx_hal_can.c as well as the instructions on page 120 of the HAL documentation DocID025834 Rev 5. This page gives the following instructions:

  1. Enable the CAN controller interface clock using __HAL_RCC_CAN1_CLK_ENABLE() for CAN1, __HAL_RCC_CAN2_CLK_ENABLE() for CAN2 and __HAL_RCC_CAN3_CLK_ENABLE() for CAN3 In case you are using CAN2 only, you have to enable the CAN1 clock.
  2. CAN pins configuration  **Enable the clock for the CAN GPIOs using the following function: __GPIOx_CLK_ENABLE() ** .... The first substep of step 2 is the problem. I cannot find the function __GPIOx_CLK_ENABLE(). I've noticed in some other forum that there may be an alternate name for the function, __HAL_RCC_GPIOx_CLK_ENABLE(); but it is not recognized by the IDE either. Am I missing an include file? Is the "x" supposed to be replaced by some number like the pin number of the pin I want to use? If so, what format should the pin be expressed?

To my further confusion, I've looked at various youtube videos and none of them seem to mention the steps above mentioned in the HAL manual.

I have installed on my IDE the following, amongst others: Generic: ARM::CMISS-Driver version 2.3.0 and 2.2.0, ARM::CMISS version 5.4.0 and version 5.3.0. Device Specific info: Keil::STM32F4xx_DFP version 2.13.0. Keil::STM32NuceloBSP version 1.6.0.

I've been looking around for information but without success, and would very much appreciate your help.

ComputerNerd
  • 63
  • 10
  • Thanks to those who took a look at this question. I've found the answer to the question. I'll share it here in case there are others who are wondering the same thing: `__HAL_RCC_GPIOx_CLK_ENABLE();` is the right format, and the "x" should be the name of the port group such as A, B or C...etc. – ComputerNerd Oct 30 '18 at 14:51
  • The generated code should already take care of initializing the GPIO ports and the CAN module if you haven't changed anything in the init routines. Look at the msp init functions for CAN, everything you need should be there. – A.R.C. Nov 05 '18 at 09:43
  • Thanks for the input! Indeed, that is the case! I discovered, taking a deep look at the code. The comments that are put in the code automatically threw me off though! I still can't get it to send messages properly though...not sure what is going on. I have the MPC2562 connected to the TX and RX.... I only have one CAN device on the bus though, connected to an oscilloscope and two termination resistors. I'm going to try connecting a second STM32F446 and a second MPC2562 to the bus and see what happens. – ComputerNerd Nov 05 '18 at 13:02
  • You need at least one receiver node on your CAN bus to generate the acknowledge bit. Otherwise you will run into communication timeouts. – A.R.C. Nov 05 '18 at 13:28
  • 1
    You can try the internal CAN loopback mode. You can test your communication without the external transceiver circuit. – A.R.C. Nov 05 '18 at 13:29
  • Thanks! I've tried it but unfortunately no luck so far. I realized that I was calling `HAL_CAN_MspInit ()` before its time despite the fact that it is called automatically by the generated code later on. I eliminated that redundant function call but still no luck. I just get the SOF bit and then nothing... :( I'm not using interrupts, btw. Do I need to call something continuously? I discovered the function `HAL_CAN_IsTxMessagePending()`...now I wait for the pending to clear, but no luck so far... – ComputerNerd Nov 05 '18 at 14:41
  • Sorry for putting the spotlight on this question again, but did you manage to make it work ? I am having the same issue this the SOF bit. Thank you ! – Johan B Jul 28 '20 at 13:25

0 Answers0