Spark Logic

CAN Bus Library for STM32F103

watswat5 Mon May 04, 2015 9:19 pm

I’m looking for a working CAN library for the stm32f103. I know it has the hardware for it, but looking at some example code (found here: https://www.olimex.com/Products/Duino/S … e-hardware), I’m totally lost.

Can someone create a CAN library similar to the MCP2515 library for Arduino? That library is intuitive and easy to use, even for users who know almost nothing about CAN.

The MCP2515 Library can be found here: https://github.com/coryjfowler/MCP_CAN_lib

Replies

Phono Tue May 05, 2015 9:08 pm

Hi,
the maple world already has a CAN library that eventually worked with some effort and various contributions, including mine.
you can have a look here : http://forums.leaflabs.com/topic.php?id=802
I think I will try to port it to Arduino when I have the time to do it. So far, the Maple version works pretty well.

phantom_tss Thu Jul 23, 2015 5:11 pm

I need this :roll:

RogerClark Thu Jul 23, 2015 9:25 pm

you probably need to see if you can contact the author of this link

http://akb77.com/g/files/media/Maple.Ha … 0.0.12.rar

as its been over a year since anyone was active on the maple forum, discussing this, and there may also be updates in the forum not incorporated into this code.

It may not even compile

phantom_tss Fri Jul 24, 2015 8:08 am

Can I use this library for stm32f103cbt6 board?

RogerClark Fri Jul 24, 2015 8:29 am

I’ve just downloaded that file, and its more than just a library, it has replacement for some core files including RCC and USB, so basically I suspect its not going to work.

i.e Its unlikely that you can just replace the rcc.c and usb.c files with the ones from that download, as almost certainly rcc.c has been updated since those files were crated (in 2012) and I suspect so has usb.c

You’d need to diff those files against the ones shipped as part of the maple IDE back in 2012 (the IDE can still be download), and determine what changes were made by the author, then you’d need to apply the same changes to the current copies of usb.c and rcc.c and .h

Without actually doing all that myself, I have no idea how easy or complex, it would be to merge in the changes.

Please feel free to work out what needs to be updated and preferably send me a pull request when you’ve updated the core.
But I don’t have time to add CAN support at the moment, and I’m not even sure I have any CAN devices to test with, even if I did have time to look at this.

Thanks

Roger

phantom_tss Fri Jul 24, 2015 12:01 pm

Thanks a lot :)

peppeve Sat Jul 25, 2015 9:08 am

I’m interested too to this library, i try to build a Nmea2000 interface with maple mini (arduino uno is too slow for handle all data on the can bus). Please keep me updated about this.

Phono Sat Jul 25, 2015 11:38 am

Hi,
I am sorry I had no time yet to work on this port. If you browse the thread in the Maple forum (http://forums.leaflabs.com/topic.php?id=802), you will find mentions of changes in USB and RCC.
This is because in the stm32f103cbt6 used in Maple and Olimexino boards, the USB and the CAN are mutually exclusive, since they use a shared portion or the memory (which is a pity, for you cannot debug a CAN application by writing information to the SerialUSB channel).
In addition, the CAN and the USB share a common interrupt vector.
In the original library, they had forgotten to add the switch to route the interrupt either to the USB or to the CAN processing. Which I added.
The drawback is that I had to declare an identifier in the core, which belongs to the CAN library. So far, I have to include the CAN library in every project, even if it does not use the CAN, just because the lacking identifier would produce a compile error.
In my contribution in the forum, you will see the lines that are changed in both USB.c and RCC.c and .h.
Roger Clark is right saying these files are likely to have changed since the version I used; but if you only do the mentioned changes in the current core files, I guess it will work.
If by the way you find a means to relieve the user from the need to include the CAN library when it is not needed, It would be great.
Regards,
Jean-Marc

RogerClark Sat Jul 25, 2015 12:34 pm

Jean-Marc

Did you try using a weak reference to a dummy identifer?

The core code does this quite a lot for default ISRs

peppeve Sat Jul 25, 2015 4:07 pm

I understand, i had suspect about USB/CAN pins and memory sharing, now you confirm me my worry. By the way i think that the best and easy solution is the use of a standard mcp2515 board with integrated transceiver like this. With 3usd we have transceiver and can controller in little module (in any case we must add the transceiver for interface the maple mini with can bus). I have tested the Flori1989 MCP2515 library and it compile without errors the maple mini sketch , the library communicate with mcp2515 by SPI (all problems with SPI seem to be solved with the last version of stm32 arduino). I don’t have canbus or nmea2000 hardware at moment for testing (i wait too the maple mini baite boards).

Phono Sat Jul 25, 2015 4:32 pm

To Roger Clark : please explain the technique of weak reference to a dummy identifier.
To peppeve : I know the sharing is annoying, but with olimexino boards it is very convenient to use the built-in CAN without any shield or extension. If you need a serial port you still can use a physical port plus a FTDI adapter. Which I did recently because I needed a data rate of 115,200 bps on the serial port, and the fake serial port via USB is very slow.

peppeve Sat Jul 25, 2015 4:49 pm

Phono wrote:the fake serial port via USB is very slow.

RogerClark Sat Jul 25, 2015 9:34 pm

@Phono

The Due core code makes some use of weak references which is easy to understand

see

https://github.com/arduino/Arduino/blob … Serial.cpp

starting at line 38

then on line 66

Perhaps the same technique can be used for CAN.

i.e add weak refs to the core, and checks in the core, that only call the CAN function if it really exists ?.

Phono Sat Jul 25, 2015 9:44 pm

To peppeve: I do not have exact figures, but the bit rate of the built-in USB-COM converter is in the range of 9600 bps.
Yes, the Olimexino STM32 board has the CAN transceiver built-in and a screw header for directly connecting the CAN bus. Very nice !

JohnL Tue Nov 17, 2015 9:23 am

BUMP

Any updates on CAN Library?

Phono Sat Nov 21, 2015 7:37 pm

I would very much like to participate in supplying a CAN library, but actually the investment required to jump in the bandwagon of this new environment is a bit high for me to start working on it.
However, if someone could handle the integration of the library into the new environment, I am available to help with the CAN side of the things.
So if someone is willing to try and port the Maple-compatible CAN library to Arduino, let him call on me, and I will give him support for this task.
Sorry for not being able to do more so far.

DrBanana Thu Oct 20, 2016 10:39 am

any update ?

Phono Thu Oct 20, 2016 5:23 pm

I have eventually found the time to port this library and I have ported some of my projects to Arduino for STM32. The CAN library works satisfactorily (I even fixed bugs that existed in the original Maple version by X893). I allowed myself some time to ensure it is bug free, and my intent was to submit it in the next weeks.
I am not familiar with the push request stuff, which held me from submitting it so far.
If someone would like to help me, I could send him the files.

DrBanana Thu Oct 20, 2016 5:37 pm

Im also not very familiar with source control either. But I think you can just upload all the files at once in github ?

martinayotte Thu Oct 20, 2016 6:29 pm

A quick guide to github :

– create your own account on github
– log into it
– navigate to Roger’s github
– click on Fork button on upper right corner (this will create a fork into your account)
– use “git clone <you forked github URL>” in a location of your choice on your local disk.
– add the new library into the tree, then do “git add <the library folder>”
– git commit -m “the comment describing the new lib”
– git push (it will push the change into github web)
– navigate back on you github web and press “compare” button, it will show diffs against Roger’s main branch.
– click on “Create a Pull Request” and provide comments to Roger.

Sign in to reply