Loading...
 

Zephyr project on STM32

   Zephyr Workbench, a VSCode extension to manage Zephyr on STM32.
It enables users to easily create, develop, and debug Zephyr applications.
Main features:
  • Install host dependencies.
  • Import toolchain and SDK.
  • Create, configure, build and manage apps.
  • Debug STM32.
You can directly download it from the VSCode marketplace
For more details, visit the Zephyr Workbench

System Workbench for STM32


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.

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
Reference Manual


 

Newest Forum Posts

  1. SPI on Nucleo_STMH533RE by royjamil, 2025-05-04 20:13
  2. SPI on Nucleo_STMH533RE by higginsa1, 2025-03-25 07:37
  3. SPI on Nucleo_STMH533RE by royjamil, 2025-03-23 11:31
  4. SPI on Nucleo_STMH533RE by higginsa1, 2025-03-23 09:33
  5. Configuring DMA for ADC in SW? by sam.hodgson, 2025-03-04 12:58
  6. Build a project in "release" mode by info@creosrl.it, 2025-02-20 18:12
  7. Build a project in "release" mode by info@creosrl.it, 2025-02-20 17:05
  8. Build a project in "release" mode by tang, 2025-02-20 10:36
  9. Build a project in "release" mode by info@creosrl.it, 2025-02-19 17:35
  10. Fail to debug in Win 11 C/C++ by mortenlund, 2024-12-26 20:27

Last-Modified Blogs