Page 1 of 1

STM32F103 (Maple) USB and CAN together?

Posted: Mon Mar 24, 2014 11:24 pm
by moxon
Hi,

I working to get both USB and CAN working together on a STM32F103 (Leaflabs Maple).
I have the USB Shell example (ChibiOS_2.6.3\testhal\STM32F1xx\USB_CDC) working nicely,
and I would like to start adding the CAN interface to that example.

However, if I enable both CAN and USB I get the following compile errors :

$ make all
Compiling main.c
Linking build/MoxiUSB.elf
build/obj/usb_lld.o: In function `usb_pm_alloc':
C:\ChibiStudio\workspace\MoxiUSB/../../chibios/os/hal/platforms/STM32/USBv1/usb_lld.c:276: multiple definition of `Vector8C'
build/obj/can_lld.o:C:\ChibiStudio\workspace\MoxiUSB/../../chibios/os/hal/platforms/STM32/can_lld.c:248: first defined here
build/obj/usb_lld.o: In function `Vector90':
C:\ChibiStudio\workspace\MoxiUSB/../../chibios/os/hal/platforms/STM32/USBv1/usb_lld.c:291: multiple definition of `Vector90'
build/obj/can_lld.o:C:\ChibiStudio\workspace\MoxiUSB/../../chibios/os/hal/platforms/STM32/can_lld.c:262: first defined here
collect2.exe: error: ld returned 1 exit status
../../chibios/os/ports/GCC/ARMCMx/rules.mk:181: recipe for target `build/MoxiUSB.elf' failed
make: *** [build/MoxiUSB.elf] Error 1

I imagine that I need to tell the HAL to move the CAN to the alternate pins in the configuration files -
Could someone please point me to an example for that?
I'm sure it's likely something simple that I'm missing...

thanks,
Tom

Re: STM32F103 (Maple) USB and CAN together?

Posted: Mon Mar 24, 2014 11:48 pm
by Giovanni
Hi,

USB and CAN together is not possible on the STM32F1, it is an HW limitation. USB and CAN share IRQ, pins and also an internal RAM area.

Giovanni

Re: STM32F103 (Maple) USB and CAN together?

Posted: Tue Mar 25, 2014 12:03 am
by moxon
Giovanni,

Thank you for the fast response and the explanation.
(I was beginning to think that was the case...)

I'm really enjoying working with ChibiOS - thank you for all your excellent work!
I've been programming for over thirty years, and your code is some of the cleanest
and most readable that I have had the pleasure to work with.

cheers,
Tom

Re: STM32F103 (Maple) USB and CAN together?

Posted: Tue Mar 25, 2014 9:07 am
by Giovanni
Hi,

I am glad you like ChibiOS :)

Note that newer STM32 devices do not have that limitation, for example, the STM32F30x is pretty much a superset of the F1 using updated peripherals.

Giovanni

Re: STM32F103 (Maple) USB and CAN together?

Posted: Mon Nov 07, 2016 12:19 pm
by madprogrammer
Hi,

I came across this topic as I was also trying to add both drivers (CAN & USB) to a single project:

Code: Select all

Symbol Vector90 multiply defined (by usb_lld.o and can_lld.o).


However, while I do understand USB and CAN cannot be used simultaneously on STM32F103, it is possible to use one of them at a given time (e.g. enable USB and disable CAN, or enable CAN and disable USB), which would require to write a shared IRQ handler and dispatch the IRQ to the currently active peripherial. Is is possible to implement such function in "mainline" ChibiOS or is it unlikely to be useful? I will probably need to implement something like that anyway, because I need to use CAN & USB + STM32F103 in my project, but I'm not sure how to implement this in a clean and nice way so that it could be contributed upstream.

Re: STM32F103 (Maple) USB and CAN together?

Posted: Mon Nov 07, 2016 1:18 pm
by Giovanni
Hi,

There is also a pin conflict so you can't use USB and CAN on the same board.

Giovanni

Re: STM32F103 (Maple) USB and CAN together?

Posted: Mon Nov 07, 2016 4:30 pm
by madprogrammer
Giovanni wrote:Hi,

There is also a pin conflict so you can't use USB and CAN on the same board.

Giovanni


No, there's no pin conflict as CAN TX/RX ports are remappable to PORTB pins. So the only trouble is the ISR, I tested it with STM32CUBEMX generated code and USB can be used when CAN is disabled and vice versa.

Thanks