CAN Bus Library for STM32F103

Can someone help me port this library?
bobc
Posts: 32
Joined: Mon Apr 27, 2015 11:20 pm

Re: CAN Bus Library for STM32F103

Post by bobc » Wed Oct 18, 2017 10:07 am

And_Ru wrote:
Tue Oct 17, 2017 3:10 pm
Others may be just out of date because of old fork.
...
Sorry, github is still new for me.
I think your PR has pulled in several other changes that are unnecessary or incorrect. I would start again with a clean branch of the current Arduino_STM32 repo, and apply only the changes needed for CAN.

It seems some changes in USB are inevitable, because in the F1 the USB shares an ISR and other things with CAN. According to the comments in the PR, USB cannot run at the same time as CAN, but I'm not sure that is true in general. I think it is possible to run both USB and CAN but it may take some careful coding.

Edit; I quickly skimmed the thread and the shared buffer was mentioned at the start. The quote from the reference manual is (RM0008, pg.655)
Note: 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 SRAM is accessed through CAN and USB exclusively). The USB
and CAN can be used in the same application but not at the same time.
I think ST are being disingenuous here. The nature of comms is that you create a connection, then unsolicited data can arrive any time. ST seem to be suggested that you do some USB for a bit, then close it, do some CAN, close it, re-enumerate the USB and do some USB. I suppose in theory if you control the protocol on USB and CAN you could arrange for a strict ping-pong controlled by the F103, but that is a very special case and not practical.

I think practically speaking, USB and CAN can not be used in the same application on F103. Certainly in our Arduino case, we try to present an easy to use API for the user. I can't think of a sensible way to prevent users trying to use USB and CAN concurrently. Any run time co-existence is going to tie USB and CAN fundamentally together, and generating a run time error is quite confusing for unsuspecting users.

So I'm not sure how to proceed with this. USB is pretty baked in to the Arduino_STM32 core. Enabling CAN means disabling USB, so operation of USB code becomes moot after that. I think the best we could do is minimise changes to USB, and as long as the user does not enable CAN those changes have no impact. The least change is to call a CAN interrupt hook in the USB interrupt, CAN without interrupts is pretty useless.

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

Re: CAN Bus Library for STM32F103

Post by RogerClark » Wed Oct 18, 2017 8:56 pm

Thanks @bobc

That seems a sensible approach.

BTW.

The change to merge USB HID into the master seems just as contentious, so I would advise that the dust left to settle on that, before CAN could be merged.
However, as USB HID PR seems to currently be in the process of updating and bug fixing by its author, I think CAN may have to wait quite a while

My preference is to integrate HID before CAN as the number of people who want HID is higher than the number of people who want CAN, and the number of people with CAN hardware is a small percentage of members, where as most people use USB ( even if only for Serial CDCACM)

User avatar
And_Ru
Posts: 25
Joined: Thu Nov 10, 2016 1:16 pm
Location: Russia, Moscow

Re: CAN Bus Library for STM32F103

Post by And_Ru » Fri Oct 20, 2017 8:33 am

bobc wrote:
Wed Oct 18, 2017 10:07 am
I think your PR has pulled in several other changes that are unnecessary or incorrect. I would start again with a clean branch of the current Arduino_STM32 repo, and apply only the changes needed for CAN.
Yes, I will do so. Just let me know wnen to start.
bobc wrote:
Wed Oct 18, 2017 10:07 am
I think practically speaking, USB and CAN can not be used in the same application on F103.
Maybe I understand you wrong, but did you see this example: http://stm32duino.com/viewtopic.php?f=1 ... =90#p33946 ?
I'm able either to start my usual CAN script, or start USB as UART Serial port. Suggest how should I test using USB and CAN in one application?

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

Re: CAN Bus Library for STM32F103

Post by stevestrong » Fri Oct 20, 2017 9:32 am

And_Ru wrote:
Fri Oct 20, 2017 8:33 am
I'm able either to start my usual CAN script, or start USB as UART Serial port.
That is a nice feature. But...
Does anybody need it? I doubt. I think one uses one or the other, but I cannot imagine any application in which USB and CAN should be alternatively used.
So in order to keep the original version used by many users safe and intact, I can only suggest to use a separate branch for CAN.

Post Reply