cancel
Showing results for 
Search instead for 
Did you mean: 

How do I implement CAN bus code for STM32F446 using CubeMX and uVision 5?

Hidekazu
Associate II

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.

1 ACCEPTED SOLUTION

Accepted Solutions

"x" in "__HAL_RCC_GPIOx_CLK_ENABLE" stands for 'A', 'B','C', etc. as in GPIOA, GPIOB, GPIOC, etc. - use the one you need for initialization of the pins you intend to use.

__GPIOx_CLK_ENABLE() is an older, deprecated form, aliased to __HAL_RCC_GPIOx_CLK_ENABLE() in [Cube]\Drivers\STM32F4xx_HAL_Driver\Inc\Legacy\stm32_hal_legacy.h

JW

View solution in original post

3 REPLIES 3

"x" in "__HAL_RCC_GPIOx_CLK_ENABLE" stands for 'A', 'B','C', etc. as in GPIOA, GPIOB, GPIOC, etc. - use the one you need for initialization of the pins you intend to use.

__GPIOx_CLK_ENABLE() is an older, deprecated form, aliased to __HAL_RCC_GPIOx_CLK_ENABLE() in [Cube]\Drivers\STM32F4xx_HAL_Driver\Inc\Legacy\stm32_hal_legacy.h

JW

Hidekazu
Associate II

Thanks very much for your help! the IDE recognizes the function!

smaha.0
Associate II

hi ,

i m new user of this board using Nucleo-f207zg. can you give steps to follow instruction for how to start CAN bus . Already i know about the logic of CAN protocol. But i am new using of CubeMx i just started cubeMx just enable pin and generate code in Keil version 5.the page was apper with hal library file.

i studied each library and one library give steps for this lib-> stm32fxx_hal_can.h .

the work is still pending from this area ..after what can i do?pls tell procedure and quick start..

thanking you

sirnajeevi