Page 1 of 1

h7 CAN not available

Posted: Thu May 09, 2019 9:38 am
by inno
Hello everyone,

I am currently in the process of switching from the M7 to the H7. However it seems there
is no CAN module builtin to the H7 firmware. CAN however is crucial for my current project.

from pyb import CAN
-> ImportError: cannot import name CAN

Note that this works flawlessly on the M7

Also help(pyb) shows no can module whatsoever.
I tested the same with both v3.41 as well as v3.2 but no difference.
Looking at the firmware revealed, that there is no stm32h7xx_hal_can.h available in the sthal.

So I wondered if CAN is available for the H7 as described on the product page?
If yes, how can I get a firmware which supports CAN?
Since it's important to me, minor changes and compiling the firmware myself if necessary is an option.

Thanks,
Stefan

Re: h7 CAN not available

Posted: Thu May 09, 2019 10:30 am
by iabdalkader
Unfortunately CAN has changed significantly from F7 to H7 and there's No driver in MicroPython. I started the support for H7 in upstream MicroPython but no one else has contributed a CAN driver yet. I could look into implementing a CAN driver for H7 soon.

Re: h7 CAN not available

Posted: Thu May 09, 2019 1:54 pm
by kwagyeman
We will have a CAN shield on sale soon so we can get this fixed. Please create a bug report on the github for this. The peripheral hasn't changed much so it's just some clock stuff that has to be dealt with.

Re: h7 CAN not available

Posted: Fri May 10, 2019 6:18 am
by inno
Since we require CAN functionality as soon as possible (think next week) depending on what you mean by "soon" we would be willing to contribute.
iabdalkader - can you maybe pinpoint me to the location of the work you have already done?

Thanks for the quick replies

Re: h7 CAN not available

Posted: Fri May 10, 2019 8:37 am
by iabdalkader
inno wrote:
Fri May 10, 2019 6:18 am
Since we require CAN functionality as soon as possible (think next week) depending on what you mean by "soon" we would be willing to contribute.
iabdalkader - can you maybe pinpoint me to the location of the work you have already done?

Thanks for the quick replies
That would be great! Note no work has been done on the new CAN driver at all, anyway, here's the STHAL FDCAN driver (it's called FDCAN on H7):

https://github.com/openmv/openmv/blob/m ... al_fdcan.h
https://github.com/openmv/openmv/blob/m ... al_fdcan.c

This is our fork of MicroPython (all work is done in the openmv branch):

https://github.com/openmv/micropython

This is the old CAN driver you can base your work on this:

https://github.com/openmv/micropython/b ... tm32/can.h
https://github.com/openmv/micropython/b ... tm32/can.c


You can either fork our MicroPython and send a PR or send it upstream. If you send it to us it will get merged a lot faster, and I'll send it upstream.

Re: h7 CAN not available

Posted: Fri May 10, 2019 5:57 pm
by travist
Hello,

I am also very interested in CAN/CANFD on the H7. I have spoken with Damien at Micropython several times about this, and his time and focus has been on short supply to work on the new peripheral. As it has been pointed out the H7 is much more advanced and supports the CAN Flexible Data Rate, which many systems and devices to not utilize. My hope is there can be two stages where standard CAN 2.0A/B is supported with the new peripheral before full CAN FD functionality is worried about.

I personally do not have the time to work on the libraries, but willing to contribute to funding at least some of the efforts. CAN is used in almost all my products and projects and need it on a device to consider it.

While waiting to hear back from Damien on the next step with this I created an issue in their repo to help show support for the efforts on CAN for the H7.
https://github.com/micropython/micropython/issues/4774

If there are things I can do to help speed this up I would like to know. The price on the H7 chip is sometimes cheaper than the F7, and the CAN peripheral is the main thing in the way of me using it and working in the OpenMV H7 into some of my vision work.

Thanks

Re: h7 CAN not available

Posted: Fri May 10, 2019 8:03 pm
by iabdalkader
Hi, there's not much to do right now (unless you want start writing the driver) I've ordered some CAN transceivers and I'm going to work on adding basic CAN support for the H7 over the next weekend.

Re: h7 CAN not available

Posted: Sat May 11, 2019 3:42 pm
by kwagyeman
Hi, I can work on getting the CAN operational. I already have the new CAN shield prototypes at home we are about to release. I'll just make the default normal CAN stuff work.

(Looks like Ibrahim might get to this before me).

Re: h7 CAN not available

Posted: Sun May 12, 2019 8:50 pm
by travist
Hello thanks for he help with supporting this.

Whether it is buying some boards or donating a little bit of funds to make this a higher priority I am happy to do one or both.

I hope the goal is that we can mimic the CAN capability of the F4/F7 on with Micropython, that would be ideal. FD functionality is probably needed by few at the moment, and where I believe most of the new complexity would come in.

Right now I am swamped with little projects I am already committed to, and for now the F7 and F4 chips work, so I do not have to move to the H7... but I want to :-)

I also want to use the new H7 OpenMV with some basic automation tools I am working on, and knowing the performance gain (latest silicon goes up to 480MHz now) This would be many times better than the current platforms that have CAN support.

Which transceivers are you planning to use/test with?

Thanks again and If we want/need to move a conversation off the forums just message me your email.

Thanks

Re: h7 CAN not available

Posted: Sun May 12, 2019 10:24 pm
by iabdalkader
I ordered MCP2551 but I think we're using something else in our CAN shields.

Re: h7 CAN not available

Posted: Sun May 12, 2019 10:43 pm
by kwagyeman
Here's the design. It's tested and works.

https://github.com/openmv/openmv-boards ... an/can.pdf

Re: h7 CAN not available

Posted: Tue May 14, 2019 5:41 am
by inno
iabdalkader wrote:
Fri May 10, 2019 8:03 pm
Hi, there's not much to do right now (unless you want start writing the driver) I've ordered some CAN transceivers and I'm going to work on adding basic CAN support for the H7 over the next weekend.
Sounds great :-)
Can you keep us posted on how things are turning out?
Especially if you don't find the time to work on it, so we know if we have to find a plan B to finish our project on time.

Best
Stefan

Re: h7 CAN not available

Posted: Wed May 15, 2019 12:37 am
by kwagyeman
The production run of the CAN shields are done. I will get samples soon. I'll send some to Ibrahim so he can write his driver.

Re: h7 CAN not available

Posted: Sat May 18, 2019 7:06 pm
by iabdalkader
Hi can anyone help me test the FDCAN driver ? If you have 2x H7 and 2x CAN transceivers let me know and I'll send you a firmware image for testing.

Re: h7 CAN not available

Posted: Tue May 21, 2019 4:54 am
by inno
Great :-)
I have two h7 and two can transceiver which were working with the M7 here.

Best
Stefan

Re: h7 CAN not available

Posted: Tue May 21, 2019 10:05 am
by iabdalkader
Great, attached a firmware image that enables FDCAN. You just need to test with something like this:

Code: Select all

from pyb import CAN
can = CAN(2, CAN.LOOPBACK)
can.send('Hello', 123)# send message with id 123

Code: Select all

from pyb import CAN
can = CAN(2, CAN.LOOPBACK)
print(can.recv(0, timeout=10000))  # receive message on FIFO 0

Re: h7 CAN not available

Posted: Fri May 24, 2019 3:42 am
by inno
Hi,

I'm afraid the image does not work yet. At least there is no signal appearing on neither the GPIOs nor the transceiver output, when sending data.
Could you maybe push your changes to a branch on your fork, so we can debug what's happening?

Best
Stefan

Re: h7 CAN not available

Posted: Fri May 24, 2019 10:09 am
by iabdalkader
Hi Stefan,

There's an open PR here with all my changes:

https://github.com/micropython/micropython/pull/4793

Re: h7 CAN not available

Posted: Thu Jun 20, 2019 11:21 am
by garivetm
Hello there,

I'm currently using a M7 cam and I am planning to switch to the new H7. However CAN is mandatory in my application.
Could you give me an update about the work you are doing on implementing CAN bus on the new H7 ?

I see this comment in the PR : "This driver has been tested in loopback mode and with a two node transceiver-less network. However, it could use a lot of improvements especially with filters, interrupts and error handling, rxcallback etc..." Does it mean that filter is not yet implemented at all ? Because, in my opinion, filtering is a necessary feature when dealing with CAN.

Thank you for your answer.

Re: h7 CAN not available

Posted: Thu Jun 20, 2019 11:25 am
by iabdalkader
garivetm wrote:
Thu Jun 20, 2019 11:21 am
Does it mean that filter is not yet implemented at all ? Because, in my opinion, filtering is a necessary feature when dealing with CAN.
No basic filtering has been implemented, however the driver still needs some more work. I'll continue working on the driver this month, should be ready with the next release. Also MicroPython developers will help with the driver hopefully after they finish up their release.

Re: h7 CAN not available

Posted: Thu Jun 20, 2019 11:38 am
by garivetm
Ok, then which repo should I follow to be kept update on the upcoming improvements ?

Re: h7 CAN not available

Posted: Thu Jun 20, 2019 12:15 pm
by iabdalkader
I'll update this thread as soon as we have any news about this.

Re: h7 CAN not available

Posted: Tue Jul 02, 2019 6:24 am
by inno
Hi,

We got everything working for our project, so it is possible to use H7 with CAN, although it is not "smooth" as of yet.
Basically we are using the stock micropython form openmv with the changes from the PR from iabdalkader with a few changes.
1. the filters seemed not to work for me. After some troubleshooting, I found out, that first all packages have to be rejected to then allow only those specified by the filter
-> we added this line to ports/stm32/fdcan.c:154 after HAL_FDCAN_Init
HAL_FDCAN_ConfigGlobalFilter(&can_obj->fdcan, 3, 3, 0, 1);
2. can.any always returns true, this is because ports/stm32/fdcan.c:540 both options return true.
You can however work around it by using something like
while True:
try:
can.recv(0, lst, timeout=1)
except OsError:
break

can.recv only works with the list argument. not providing one results in an empty list being returned. Filling the list however works fine. Its not too bad, but weird.
-> do this
buf=bytearray(8)
lst = [0, 0, 0, memoryview(buf)]
and give lst as second argument to can.recv


Filtering with range filters is totally sufficient for us because you can set multiple filters with them.
E.g.
can.setfilter(0, 0, (0xe1, 0xe2)
can.setfilter(2, 0, (0xf1, 0xf2)
to get both 0xe1 and 0xf1 in FIFO 0.

When synchronizing to our can bus we found another issue when reading:
We had to set prescaler=16, sjw=1, bs1=8, bs2=3 in can.init although we expected prescaler=18 according to stm32 cube mx.
According to pyb.freq we would have calculated a frequency of 41, sjw=4, bs1=12, bs2=5
I am not too familiar with this issue, so I can't give any more details.

oh and don't forget to add fdcan.c to the Makefile in openmv/src.

Hope this is helpful

Oh and big shout out to iabdalkader for making it possible, that we completed our project on time. Thanks :-)

Re: h7 CAN not available

Posted: Tue Jul 02, 2019 8:28 am
by iabdalkader
Wow thank you, this is very useful indeed. I just got our CAN shields and will be working on this next weekend and I'll add these changes the code.
We had to set prescaler=16, sjw=1, bs1=8, bs2=3 in can.init although we expected prescaler=18 according to stm32 cube mx.
I'm guessing maybe the project is set to 400MHz (the H7 runs at 480MHz now).

Re: h7 CAN not available

Posted: Mon Sep 16, 2019 11:34 am
by iabdalkader
Hi, CAN is now supported on the H7, and I fixed the timing, setfilter() and any() bugs. The next release will be out in a day or two.

Re: h7 CAN not available

Posted: Wed Oct 02, 2019 6:16 pm
by travist
This is great!

I am surprised I did not get a notification, luckily I saw that Damien closed the issue on the Micropython github repo.

This was a big gating item for me, and it appears that most other functionality has been working well with the H7, so this means I can prototype moving from a F7 to a H7 and double most of my capability (oddly for less money).

Re: h7 CAN not available

Posted: Thu Oct 03, 2019 1:21 am
by kwagyeman
Yeah, I just updated the resources in the IDE so then you open the IDE the new firmware will be downloaded.

It's a huge amount of work to release the whole IDE. So, just updating the resources is a lot easier.

Re: h7 CAN not available

Posted: Wed Oct 16, 2019 6:29 am
by garivetm
iabdalkader wrote:
Mon Sep 16, 2019 11:34 am
Hi, CAN is now supported on the H7, and I fixed the timing, setfilter() and any() bugs. The next release will be out in a day or two.
That's a great news !!! I will get a H7 cam asap and test it.

Thank you !