Problem with CAN after firmware update

The official PYBD running MicroPython, and its accessories.
Target audience: Users with a PYBD
Post Reply
kalimbamusmatta
Posts: 4
Joined: Thu Apr 09, 2020 7:24 am

Problem with CAN after firmware update

Post by kalimbamusmatta » Thu Apr 09, 2020 10:57 am

Hello, after updating the firmware from:
MicroPython v1.10-445-ga9b1d3ca3 on 2019-05-29; PYBD_SF2W with STM32F722IEK
to:
MicroPython v1.12-351-gbd5633778 on 2020-04-08; PYBD-SF2W with STM32F722IEK
CAN communication stopped working. I have the older firmware on another pyboard and that works fine with the same pyboard<->transceiver<->CAN-bus setup.
Is there anyway to get the old firmware ( v1.10-445-ga9b1d3ca3 ) so I can try flashing the pyboard with that again and see if that works? I have tried cloning the github and checking out v1.1 but that version doesn't include the PYBD_SF2 directory inside ports/stm32.

I'm testing using the following code, which works on the v1.10 pyboard

Code: Select all

import pyb
from pyb import CAN
#f_clock=8000000, nom_brp=4, nom_tseg1=13, nom_tseg2=2, nom_sjw=1, nom_sam=0
pyb.freq(64000000, 64000000, 8000000, 32000000)
can = pyb.CAN(1)
can.init(mode=pyb.CAN.NORMAL, extframe=True, prescaler=4, sjw=1, bs1=13, bs2=2)
can.setfilter(0, CAN.MASK32, 0, (0, 0)) #allows all ID's
Then in REPL I type

Code: Select all

can.send('test',123)
Is there anything else I can do to troubleshoot/debug this?

Thank you.

Edit:
Both version work in loopback mode.

Damien
Site Admin
Posts: 635
Joined: Mon Dec 09, 2013 5:02 pm

Re: Problem with CAN after firmware update

Post by Damien » Thu Apr 09, 2020 1:17 pm

You can obtain the old firmware here: https://micropython.org/resources/firmw ... 1d3ca3.dfu

If that firmware works but the latest doesn't, then it should be possible to track down the bug and fix it.

kalimbamusmatta
Posts: 4
Joined: Thu Apr 09, 2020 7:24 am

Re: Problem with CAN after firmware update

Post by kalimbamusmatta » Thu Apr 09, 2020 1:54 pm

Damien wrote:
Thu Apr 09, 2020 1:17 pm
You can obtain the old firmware here: https://micropython.org/resources/firmw ... 1d3ca3.dfu

If that firmware works but the latest doesn't, then it should be possible to track down the bug and fix it.
Thank you very much, the old firmware worked!

Unfortunately I needed to modify the CAN library to give me information about if the received can frame is extended frame or not. Is there any build instructions for PYBD-SF2 with version v1.10 so I can modify that version or would you mind telling me how I can do it myself?

Thank you again for helping me.

Damien
Site Admin
Posts: 635
Joined: Mon Dec 09, 2013 5:02 pm

Re: Problem with CAN after firmware update

Post by Damien » Sun Apr 12, 2020 1:40 pm

Is it possible to tell standard vs extended frames from the ID? (eg extended IDs would be larger than 11 bits)

The early version of the PYBD firmware was from this pull request on github: https://github.com/micropython/micropython/pull/4669

To build it (or any version) do the following (after installing the relevant toolchain):

Code: Select all

$ git submodule update --init
$ make -C mpy-cross
$ make -C ports/stm32 BOARD=PYBD_SF2
$ make -C ports/stm32 BOARD=PYBD_SF2 deploy
The best thing to do here would be fix the bug with the CAN driver. Can you describe in more detail what the steps are to reproduce the bug and exactly how the bug manifests / what the problem is?

kalimbamusmatta
Posts: 4
Joined: Thu Apr 09, 2020 7:24 am

Re: Problem with CAN after firmware update

Post by kalimbamusmatta » Tue Apr 14, 2020 10:19 am

Thank you, that worked :)
Damien wrote:
Sun Apr 12, 2020 1:40 pm
Is it possible to tell standard vs extended frames from the ID? (eg extended IDs would be larger than 11 bits)
I'm just reading the rx_msg.IDE variable in the pyb_can_recv() function in ports/stm32/can.c
When casting it like this:

Code: Select all

MP_OBJ_NEW_SMALL_INT(rx_msg.IDE)
it returns 0 for standard frame and 4 for extended frame.
One problem though is that to get anything on the FIFO for both types of frame I need to init the can object with extframe=False and set the filter as CAN.MASK16.
I also need to reinit the can object with extframe=True whenever I want to send an extended frame message and then reinit with extframe=False afterwards to be able to recive standard frames on the FIFO.
Damien wrote:
Sun Apr 12, 2020 1:40 pm
The best thing to do here would be fix the bug with the CAN driver. Can you describe in more detail what the steps are to reproduce the bug and exactly how the bug manifests / what the problem is?
When I flashed my Pyboard as I described in op it stopped being able to receive and send can messages with an CAN interface for USB.
When using can.send() the USB interface doesn't see the message, and no messages sent from the USB interface show up on the FIFO. No acknowledgement signal is sent from the Pyboard either. I haven't looked at the pins with an oscilloscope to see if the Pyboard sends anything at all.
When I init the can object with mode=pyb.CAN.LOOPBACK, send and recv works as normal.

Damien
Site Admin
Posts: 635
Joined: Mon Dec 09, 2013 5:02 pm

Re: Problem with CAN after firmware update

Post by Damien » Thu Apr 16, 2020 3:17 am

I tried the latest PYBD-SF2 firmware, MicroPython v1.12-371-gf534b9976 on 2020-04-16; PYBD-SF2W with STM32F722IEK, and I am able to get the CAN bus working (communicating with a PYBv1.0 via CAN transceivers).

The two main things I needed to do to get it working were:
  1. enable the PYBD 3.3V rail for the transceiver to work: pyb.Pin('EN_3V3').on()
  2. make sure the bitrate for the CAN was the same on all devices, eg prescaler = pyb.freq()[2] / bitrate

kalimbamusmatta
Posts: 4
Joined: Thu Apr 09, 2020 7:24 am

Re: Problem with CAN after firmware update

Post by kalimbamusmatta » Thu Apr 16, 2020 8:40 am

Damien wrote:
Thu Apr 16, 2020 3:17 am
enable the PYBD 3.3V rail for the transceiver to work: pyb.Pin('EN_3V3').on()
Thanks that was it! That was stupid of me not checking the voltage.

Post Reply