CAN Bus Library for STM32F103

Can someone help me port this library?
Phono
Posts: 92
Joined: Tue May 05, 2015 6:08 am
Location: Ermont, France

Re: CAN Bus Library for STM32F103

Post by Phono » Wed Sep 27, 2017 7:57 am

Hi,
I did not use this board, but there is no reason why it should not work.
You just have to connect it to PA11 and PA12, and adapt the example in the HardwareCAN library to select these pins.
(Actually this library is under construction, and it will be available soon, I hope).
So far this library requires changes in the core, so either you do them manually, or you wait until the new version of the STM32 environment is available.
In the mean time, you can read the files you will find here :
https://github.com/megadrifter/Arduino_ ... ardwareCAN

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 13, 2017 11:41 am

Hi Roger,
RogerClark wrote:
Wed Sep 13, 2017 9:54 pm
did anyone generate a PR??
I've just made PR with core files change. Please check if this is what all we need.
https://github.com/rogerclarkmelbourne/ ... 2/pull/355

also I added CAN speeds 33 and 95; CAN_GPIO_PA11_PA12 mapping.

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 13, 2017 12:17 pm

Phono wrote:
Wed Sep 27, 2017 7:57 am
Hi
I think there could be some improvements for your library.
For example, F1 board have only one CAN interface, so out of these two

Code: Select all

/* peripheral addresses */
#define CAN1_BASE		((CAN_Port*)0x40006400)
#define CAN2_BASE		((CAN_Port*)0x40006800)
only "CAN1_BASE" is used. So, this constructor

Code: Select all

HardwareCAN::HardwareCAN(CAN_Port* CANx)
{
	Port = CANx;
}
may be just

Code: Select all

HardwareCAN::HardwareCAN()
{
	Port = &CAN1_BASE;
}
??

Also I would say that some functions from your Example arelikely to be added into the ibrary:
CANSetup() - with few parameters as CAN_GPIO_, CAN_SPEED_, CAN_MODE_, maybe filter
CAN_TX_MBX CANsend (or even function SendCanMessage from my example)

Best regards!

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

Re: CAN Bus Library for STM32F103

Post by RogerClark » Sat Oct 14, 2017 8:25 pm

I see the PR includes changes to things like the Hardware timers etc

This would need to be extensively tested by people using these timers

I could potentially push a branch with these changes, but it will take a while to get this complexity and risk of this change into the master, because everyone is "time poor" and its unlikely to get fully tested in the short term.

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 » Tue Oct 17, 2017 3:10 pm

RogerClark wrote:
Sat Oct 14, 2017 8:25 pm
I see the PR includes changes to things like the Hardware timers etc

This would need to be extensively tested by people using these timers

I could potentially push a branch with these changes, but it will take a while to get this complexity and risk of this change into the master, because everyone is "time poor" and its unlikely to get fully tested in the short term.
Hello Roger,

Actually only three files of the core are changed:
1) STM32F1\cores\maple\libmaple\rcc_f1.c
2) STM32F1\cores\maple\libmaple\usb\stm32f1\usb.c
3) STM32F1\system\libmaple\stm32f1\include\series\rcc.h

Others may be just out of date because of old fork.

I should add also:
tjb12345 wrote:
Wed Sep 13, 2017 4:40 am
My project only uses EXT ID's but I opted to add a parameter to the filter function to indicate whether is ext ID filter or standard. That parameter needs to be added in 4 places, can.h, can.c, HardwareCAN.h and HardwareCan.cpp.
Should I do another PR and cancell current, or just update my branch?
Sorry, github is still new for me.

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

Re: CAN Bus Library for STM32F103

Post by RogerClark » Tue Oct 17, 2017 7:28 pm

Guys

I have a big merge pendinb to add USB HID etc, which may impact on your PR, also I would need to give your changes more visibility, as only a few people resd this thread.

I will need to start 2 new threads in general discussion about the proposed changes to USB and also for CAN.

As we now have thousands of users for thIs Core, I have to be careful when changing things at its heart.

bobc
Posts: 32
Joined: Mon Apr 27, 2015 11:20 pm

Re: CAN Bus Library for STM32F103

Post by bobc » Tue Oct 17, 2017 9:26 pm

I'm hoping to have a play with CAN when I get some more hardware, I've got some projects where I could use it. I'll have a look more into proposed changes for CAN.

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

Re: CAN Bus Library for STM32F103

Post by RogerClark » Tue Oct 17, 2017 11:11 pm

I think I have a CAN compass from a DJI drone, but I've no idea exactly what type it is (and I'll have to find where I put it, as I removed it from the drone in order to fit a non CAN compass to make it compatible with a non-DJI flight controller)

So.. Until I find it, I would not be able to test the CAN code :-(

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

Re: CAN Bus Library for STM32F103

Post by stevestrong » Wed Oct 18, 2017 7:34 am

Hm, I only had a short look into the PR, it seems to have changes really deep in the well optimized USB CDC part.
I am not happy to see this, I rate the risk to something go wrong on serial USB quite high.

User avatar
RogerClark
Posts: 7545
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 10:01 am

I agree

It does look risky

Post Reply