Changes for CAN bus support

Post Reply
User avatar
RogerClark
Posts: 7455
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Changes for CAN bus support

Post by RogerClark » Mon Jul 03, 2017 7:02 am

https://github.com/rogerclarkmelbourne/ ... 2/pull/223

I don't have any CAN bus hardware or knowledge of how it works etc

stevestrong
Posts: 1814
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: Changes for CAN bus support

Post by stevestrong » Mon Jul 03, 2017 9:51 am

I don't quite understand why must the USB module changed for the CAN to work, someone please explain.

User avatar
RogerClark
Posts: 7455
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Changes for CAN bus support

Post by RogerClark » Mon Jul 03, 2017 11:27 am

I think CAN and USB share an interrupt, or something else in the hardware.

I am not sure if it's possible to have USB and CAN at the same time.

Phono
Posts: 92
Joined: Tue May 05, 2015 6:08 am
Location: Ermont, France

Re: Changes for CAN bus support

Post by Phono » Mon Jul 03, 2017 7:31 pm

Excerpt from the STM32 user's manual :
In low, medium, high and XL-density devices, the USB and CAN share a dedicated 512-byte
SRAM memory for data transmission and reception, and so they cannot be used
concurrently (the shared RAM is accessed through CAN and USB exclusively). The USB
and CAN can be used in the same application but not at the same time.

In addition, the USB and CAN receive interrupts share the same vector, thus the alteration in the core code.

User avatar
RogerClark
Posts: 7455
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Changes for CAN bus support

Post by RogerClark » Mon Jul 03, 2017 9:23 pm

Phono wrote:
Mon Jul 03, 2017 7:31 pm
Excerpt from the STM32 user's manual :
In low, medium, high and XL-density devices, the USB and CAN share a dedicated 512-byte
SRAM memory for data transmission and reception, and so they cannot be used
concurrently (the shared RAM is accessed through CAN and USB exclusively). The USB
and CAN can be used in the same application but not at the same time.

In addition, the USB and CAN receive interrupts share the same vector, thus the alteration in the core code.
Thanks....

As USB seems to get interrupts all the time, I don't see how CAN can be used without shutting down USB.

Perhaps the CAN bus code could be conditionally included only for Serial uploads when USB is already disabled

User avatar
Vassilis
Posts: 320
Joined: Thu May 21, 2015 6:42 am
Location: Thessaloniki, Greece
Contact:

Re: Changes for CAN bus support

Post by Vassilis » Tue Jul 04, 2017 7:23 am

I have never used CAN bus on STM32F103 but I saw at the STM32CubeMX (v 4.21.0) that both USB and CAN bus can be enabled at the same time.
It seems very interesting for me to do some test on the CAN bus (I have also a scheduled project that must be working with CAN bus).

Phono
Posts: 92
Joined: Tue May 05, 2015 6:08 am
Location: Ermont, France

Re: Changes for CAN bus support

Post by Phono » Tue Jul 04, 2017 8:15 pm

It is not only the receive interrupt vector that is shared, but 512 bytes of memory used, on the CAN side, for fifos and filters.
I do not know their use with USB, but clearly USB and CAN cannot be used at the same time, though it is possible to write a code that uses both.
In the CAN library, the Initialize function starts with "Serial.end();", as well as several statements to stop USB, disconnect the AMBA bus clock supply to the USB block, etc., to shutdown all USB activity.
It is possible to switch between CAN an USB in an application, though I do not see which application could need this.

User avatar
RogerClark
Posts: 7455
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Changes for CAN bus support

Post by RogerClark » Tue Jul 04, 2017 9:00 pm

I think there are currently problems with restarting the USB after it's been stopped using Serial.end()

So as these two interfaces are mutually exclusive, I don't think it's worth wasting a lot of time trying to get the core to switch between using one and then the other.
I writimg a host application to communicate with a USB device which keeps disconnecting and reconnecting would be a pain

Phono
Posts: 92
Joined: Tue May 05, 2015 6:08 am
Location: Ermont, France

Re: Changes for CAN bus support

Post by Phono » Thu Jul 20, 2017 12:17 pm

@RogerClark: please have a look at my post :
http://www.stm32duino.com/viewtopic.php ... =70#p31679
We definitely need that the three changes in the core be performed for the sake of compatibility with the HardwareCAN library, even if it never will be added to the master branch of the package. It will do no harm to the other users, anyway.
Thanks.

Post Reply