CAN support for NUCLEO-F446RE board

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Post Reply
Jim_Merkle
Posts: 3
Joined: Wed Apr 28, 2021 11:24 pm

CAN support for NUCLEO-F446RE board

Post by Jim_Merkle » Sun May 02, 2021 7:05 pm

I just received a batch of CAN bus transceivers this weekend, and was going to test CAN between a STM32F407G-DISC1 and a NUCLEO-F446RE board. I seems the image: "NUCLEO_F446RE-20210418-v1.15.dfu" doesn't support CAN.

Using the "Getting Started" guild (nice work), I was able to build my own MicroPython image for the NUCLEO-F446RE. Although the image runs well, this new image (1.15 flavor) still doesn't have CAN support.

MicroPython v1.15-64-g1e2f0d280 on 2021-05-02; NUCLEO-F446RE with STM32F446xx
Type "help()" for more information.
>>>
>>> help(pyb)
...
SPI -- <class 'SPI'>
UART -- <class 'UART'>
ADC -- <class 'ADC'>
ADCAll -- <class 'ADCAll'>
DAC -- <class 'DAC'>
>>>
Although the processor and MicroPython support CAN, I'm trying to determine how to add support for CAN to my image...

Thanks!
(A special thanks to Dave Hylands for his help recently, and recommending "rshell" !)

Jim_Merkle
Posts: 3
Joined: Wed Apr 28, 2021 11:24 pm

Re: CAN support for NUCLEO-F446RE board

Post by Jim_Merkle » Mon May 03, 2021 3:33 pm

After modifying micropython/ports/stm32/boards/NUCLEO_F446RE/mpconfigboard.h

I wanted both CAN bus interfaces available, so I commented out the SPI2 pins...
+//#define MICROPY_HW_SPI2_NSS (pin_B12) // pin 16 on CN10
+//#define MICROPY_HW_SPI2_SCK (pin_B13) // pin 30 on CN10
+//#define MICROPY_HW_SPI2_MISO (pin_B14) // pin 28 on CN10
+//#define MICROPY_HW_SPI2_MOSI (pin_B15) // pin 26 on CN10

I then added pins for the two CAN bus interfaces...
+// CAN busses
+#define MICROPY_HW_CAN1_TX (pin_B9)
+#define MICROPY_HW_CAN1_RX (pin_B8)
+#define MICROPY_HW_CAN2_TX (pin_B13)
+#define MICROPY_HW_CAN2_RX (pin_B12)

I then deleted the micropython/ports/stm32/build-NUCLEO_F446RE directory and rebuilt the image for the NUCLEO_F446RE board.
It looks like we have CAN support now...

MicroPython v1.15-64-g1e2f0d280-dirty on 2021-05-03; NUCLEO-F446RE with STM32F446xx
Type "help()" for more information.
>>> help(pyb)
....
UART -- <class 'UART'>
CAN -- <class 'CAN'>
ADC -- <class 'ADC'>
ADCAll -- <class 'ADCAll'>
DAC -- <class 'DAC'>

And, I can create a CAN object.
>>> can=pyb.CAN(1)
>>>

Hopefully, this will help someone with a similar issue.

Post Reply