USB CDC and CAN not running together on STM32F103 (imported from CubeMX)
I’ve taken a quick look at your configuration and I don’t have any definitive answer for you, just a few observations and suggestions.
My first guess at the problem is that there’s some sort of undesired interaction between the CAN and USB controllers due to the fact that they both share interrupt vector(s).
Observations:
- On this device, USB “low priority” events and CAN receive (FIFO 0) share an interrupt vector. The USB device stack is definitely using this interrupt, if the Cube configuration UI is to be believed.
- I presume you’re using the Cube HAL to configure and operate the CAN bus. I can’t tell from just the Cube .ioc file if the HAL uses interrupts for CAN or not, nor can I tell if it is enabling interrupt sources on the CAN controller.
- The NVIC configuration for this project is setting all enabled interrupt sources to the highest priority (0 = highest priority I think, 15 = lowest).
Suggestions:
- Fix the NVIC priority settings so SysTick is running at the lowest priority (15). USB/CAN priority should be something other than 0 (highest).
- Make sure you’re not accidentally turning on any CAN interrupts. If you (or the HAL) are using CAN interrupts, you’ll need to determine if the HAL code is dealing with the shared interrupt properly - i.e. invoking an appropriate sub-ISR specific to USB or CAN depending on which peripheral generated the interrupt.
I’ve not used the F103 or the (Cube HAL) USB code so I’m afraid I can’t offer any more advice based on direct experience. I have used CAN (on the F091), but wrote my own custom low level drivers for it; I did not use the Cube HAL routines.