USB CDC and CAN not running together on STM32F103 (imported from CubeMX)
Hey, I’m sorry to disappoint you, but in F103 chip you cannot use USB and CAN at the same time. It is not clear from Reference Manual, but that’s the reality. Out of F1 family only F105/107 (Connectivity line) have a different USB peripheral arhitecture (USB OTG) so that allows to use it with CAN bus simultaneously. F3\F4 serial almost all have USB OTG so no problem with that. Out of F0 family only F072 series can have both at the same time, rest are just as limited as F103.
The reason behind this limitation is the following: there’s an internal 512b RAM buffer for storing received and sent data (since both CAN and USB are highly loaded protocols and asynchronous) which can be used either only for USB or only for CAN. CubeMX though still allows to check both peripherals for use at the same time, but in reality you will be able to use only one (only one can be initialized at the time) - the shared RAM is accessed through CAN and USB exclusively.
My suggestion is to use UART instead of USB and then add an external USB-UART converted (either smth like FT232, CH340, CP2102 or you can use another F103 chip)
Screenshot from F10x reference manual, page 622 (USB) see below