STM32F103 (Maple) USB and CAN together?

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderators: barthess, RoccoMarco

moxon
Posts: 3
Joined: Wed Mar 12, 2014 7:35 pm

STM32F103 (Maple) USB and CAN together?

Postby moxon » Mon Mar 24, 2014 11:24 pm

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

User avatar
Giovanni
Site Admin
Posts: 14704
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1146 times
Been thanked: 960 times

Re: STM32F103 (Maple) USB and CAN together?

Postby Giovanni » Mon Mar 24, 2014 11:48 pm

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

moxon
Posts: 3
Joined: Wed Mar 12, 2014 7:35 pm

Re: STM32F103 (Maple) USB and CAN together?

Postby moxon » Tue Mar 25, 2014 12:03 am

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

User avatar
Giovanni
Site Admin
Posts: 14704
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1146 times
Been thanked: 960 times

Re: STM32F103 (Maple) USB and CAN together?

Postby Giovanni » Tue Mar 25, 2014 9:07 am

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

madprogrammer
Posts: 4
Joined: Tue Oct 28, 2014 7:40 pm

Re: STM32F103 (Maple) USB and CAN together?

Postby madprogrammer » Mon Nov 07, 2016 12:19 pm

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.

User avatar
Giovanni
Site Admin
Posts: 14704
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1146 times
Been thanked: 960 times

Re: STM32F103 (Maple) USB and CAN together?

Postby Giovanni » Mon Nov 07, 2016 1:18 pm

Hi,

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

Giovanni

madprogrammer
Posts: 4
Joined: Tue Oct 28, 2014 7:40 pm

Re: STM32F103 (Maple) USB and CAN together?

Postby madprogrammer » Mon Nov 07, 2016 4:30 pm

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


Return to “STM32 Support”

Who is online

Users browsing this forum: No registered users and 106 guests