Skip to main content
SegmentFault
Associate II
December 29, 2020
Solved

error: 'CAN2' undeclared in standard peripheral library for STM32F103

  • December 29, 2020
  • 1 reply
  • 1263 views

I am porting a project from STM32F105 to STM32F103 using the standard peripheral library. During the compilation process I get the following error:

In file included from ../Drivers/STM32F10x_StdPeriph_Driver/src/stm32f10x_can.c:23:0:
../Drivers/STM32F10x_StdPeriph_Driver/inc/stm32f10x_can.h:47:49: error: 'CAN2' undeclared (first use in this function); did you mean 'CANx'?
 ((PERIPH) == CAN2))

And if I go to stm32f10x_can.h file I can find:

#define IS_CAN_ALL_PERIPH(PERIPH) (((PERIPH) == CAN1) || \
 ((PERIPH) == CAN2))

However, STM32F103 only define CAN1 in stm32f103xe.h.

The question is how can I compile the standard library for STM32F103? One workaround is to delete all references to CAN2 but this is strange because the standard peripheral library is supposed to be standard for all mcu's in F1 family. In other words, no modification in source code of the library is needed to compile for those mcu's.

Regards.

This topic has been closed for replies.
Best answer by TDK

> The question is how can I compile the standard library for STM32F103?

The file you should be including is "stm32f10x.h" which includes definitions for both CAN1 and CAN2, not "stm32f103xe.h". You're mixing and matching files, which is causing the issue.

https://my.st.com/content/my_st_com/en/products/embedded-software/mcu-mpu-embedded-software/stm32-embedded-software/stm32-standard-peripheral-libraries/stsw-stm32054.license=1609251240803.product=STSW-STM32054.version=3.5.0.html

1 reply

TDK
TDKBest answer
December 29, 2020

> The question is how can I compile the standard library for STM32F103?

The file you should be including is "stm32f10x.h" which includes definitions for both CAN1 and CAN2, not "stm32f103xe.h". You're mixing and matching files, which is causing the issue.

https://my.st.com/content/my_st_com/en/products/embedded-software/mcu-mpu-embedded-software/stm32-embedded-software/stm32-standard-peripheral-libraries/stsw-stm32054.license=1609251240803.product=STSW-STM32054.version=3.5.0.html

"If you feel a post has answered your question, please click ""Accept as Solution""."