Compile error while importing <mcp_can.h> for Arduino GIGA

Hi, I am currently transitioning from STM32CubeIDE to Arduino IDE so I am not yet too familiar with Arduino IDE. I have difficulties setting up the programming environment to use a SPI-based CAN shield with Arduino GIGA R1 WiFi.

Hardware:

Software:

To get started, I grabbed an example code included in seeedstudio's library, however I get compiling errors right away. Narrowing it down, this barebone code will not compile. The target device is set as Arduino GIGA R1 WiFi (M7 (default) core).

#include "mcp_can.h"

void setup() {
}

void loop() {
}

This is the compile error log:

In file included from C:\Users\(user)\AppData\Local\Arduino15\packages\arduino\hardware\mbed_giga\4.3.1\cores\arduino/mbed/targets/TARGET_STM/TARGET_STM32H7/STM32Cube_FW/stm32h7xx_hal_conf.h:402:0,
                 from C:\Users\(user)\AppData\Local\Arduino15\packages\arduino\hardware\mbed_giga\4.3.1\cores\arduino/mbed/targets/TARGET_STM/TARGET_STM32H7/STM32Cube_FW/STM32H7xx_HAL_Driver/stm32h7xx_hal.h:30,
                 from C:\Users\(user)\AppData\Local\Arduino15\packages\arduino\hardware\mbed_giga\4.3.1\cores\arduino/mbed/targets/TARGET_STM/TARGET_STM32H7/STM32Cube_FW/CMSIS/stm32h7xx.h:223,
                 from C:\Users\(user)\AppData\Local\Arduino15\packages\arduino\hardware\mbed_giga\4.3.1\cores\arduino/mbed/targets/TARGET_STM/TARGET_STM32H7/cmsis.h:22,
                 from C:\Users\(user)\AppData\Local\Arduino15\packages\arduino\hardware\mbed_giga\4.3.1\cores\arduino/mbed/targets/TARGET_STM/PinNamesTypes.h:33,
                 from C:\Users\(user)\AppData\Local\Arduino15\packages\arduino\hardware\mbed_giga\4.3.1\variants\GIGA/pinmode_arduino.h:24,
                 from C:\Users\(user)\AppData\Local\Arduino15\packages\arduino\hardware\mbed_giga\4.3.1\cores\arduino/Arduino.h:26,
                 from c:\Users\(user)\Documents\Arduino\libraries\CAN_BUS_Shield\src/mcp_can.h:4,
                 from c:\Users\(user)\Documents\Arduino\libraries\CAN_BUS_Shield\src/can-serial.h:24,
                 from C:\Users\(user)\Documents\Arduino\arduino_can\driver_CAN.cpp:1:
C:\Users\(user)\AppData\Local\Arduino15\packages\arduino\hardware\mbed_giga\4.3.1\cores\arduino/mbed/targets/TARGET_STM/TARGET_STM32H7/STM32Cube_FW/STM32H7xx_HAL_Driver/stm32h7xx_hal_gpio.h:86:36: error: expected identifier before '(' token
 #define GPIO_PIN_0                 ((uint16_t)0x0001)  /* Pin 0 selected    */
                                    ^
c:\Users\(user)\Documents\Arduino\libraries\CAN_BUS_Shield\src/mcp2518fd_can_dfs.h:663:16: note: in expansion of macro 'GPIO_PIN_0'
 typedef enum { GPIO_PIN_0, GPIO_PIN_1 } GPIO_PIN_POS;
                ^
C:\Users\(user)\AppData\Local\Arduino15\packages\arduino\hardware\mbed_giga\4.3.1\cores\arduino/mbed/targets/TARGET_STM/TARGET_STM32H7/STM32Cube_FW/STM32H7xx_HAL_Driver/stm32h7xx_hal_gpio.h:86:36: error: expected '}' before '(' token
 #define GPIO_PIN_0                 ((uint16_t)0x0001)  /* Pin 0 selected    */
                                    ^
c:\Users\(user)\Documents\Arduino\libraries\CAN_BUS_Shield\src/mcp2518fd_can_dfs.h:663:16: note: in expansion of macro 'GPIO_PIN_0'
 typedef enum { GPIO_PIN_0, GPIO_PIN_1 } GPIO_PIN_POS;
                ^
C:\Users\(user)\AppData\Local\Arduino15\packages\arduino\hardware\mbed_giga\4.3.1\cores\arduino/mbed/targets/TARGET_STM/TARGET_STM32H7/STM32Cube_FW/STM32H7xx_HAL_Driver/stm32h7xx_hal_gpio.h:86:47: error: expected ')' before numeric constant
 #define GPIO_PIN_0                 ((uint16_t)0x0001)  /* Pin 0 selected    */
                                               ^
c:\Users\(user)\Documents\Arduino\libraries\CAN_BUS_Shield\src/mcp2518fd_can_dfs.h:663:16: note: in expansion of macro 'GPIO_PIN_0'
 typedef enum { GPIO_PIN_0, GPIO_PIN_1 } GPIO_PIN_POS;
                ^
In file included from c:\Users\(user)\Documents\Arduino\libraries\CAN_BUS_Shield\src/mcp2518fd_can.h:6:0,
                 from C:\Users\(user)\Documents\Arduino\arduino_can\driver_CAN.cpp:4:
c:\Users\(user)\Documents\Arduino\libraries\CAN_BUS_Shield\src/mcp2518fd_can_dfs.h:663:41: error: 'GPIO_PIN_POS' does not name a type; did you mean 'GPIO_PIN_SET'?
 typedef enum { GPIO_PIN_0, GPIO_PIN_1 } GPIO_PIN_POS;
                                         ^~~~~~~~~~~~
                                         GPIO_PIN_SET
In file included from C:\Users\(user)\AppData\Local\Arduino15\packages\arduino\hardware\mbed_giga\4.3.1\cores\arduino/mbed/targets/TARGET_STM/TARGET_STM32H7/STM32Cube_FW/CMSIS/stm32h7xx.h:136:0,
                 from C:\Users\(user)\AppData\Local\Arduino15\packages\arduino\hardware\mbed_giga\4.3.1\cores\arduino/mbed/targets/TARGET_STM/TARGET_STM32H7/cmsis.h:22,
                 from C:\Users\(user)\AppData\Local\Arduino15\packages\arduino\hardware\mbed_giga\4.3.1\cores\arduino/mbed/targets/TARGET_STM/PinNamesTypes.h:33,
                 from C:\Users\(user)\AppData\Local\Arduino15\packages\arduino\hardware\mbed_giga\4.3.1\variants\GIGA/pinmode_arduino.h:24,
                 from C:\Users\(user)\AppData\Local\Arduino15\packages\arduino\hardware\mbed_giga\4.3.1\cores\arduino/Arduino.h:26,
                 from c:\Users\(user)\Documents\Arduino\libraries\CAN_BUS_Shield\src/mcp_can.h:4,
                 from c:\Users\(user)\Documents\Arduino\libraries\CAN_BUS_Shield\src/can-serial.h:24,
                 from C:\Users\(user)\Documents\Arduino\arduino_can\driver_CAN.cpp:1:
C:\Users\(user)\AppData\Local\Arduino15\packages\arduino\hardware\mbed_giga\4.3.1\cores\arduino/mbed/targets/TARGET_STM/TARGET_STM32H7/STM32Cube_FW/CMSIS/stm32h747xx.h:2698:43: error: expected ')' before '*' token
 #define CRC                 ((CRC_TypeDef *) CRC_BASE)
                                           ^
c:\Users\(user)\Documents\Arduino\libraries\CAN_BUS_Shield\src/mcp2518fd_can_dfs.h:1487:14: note: in expansion of macro 'CRC'
     uint32_t CRC : 16;
              ^
C:\Users\(user)\AppData\Local\Arduino15\packages\arduino\hardware\mbed_giga\4.3.1\cores\arduino/mbed/targets/TARGET_STM/TARGET_STM32H7/STM32Cube_FW/CMSIS/stm32h747xx.h:2698:43: error: expected ')' before '*' token
 #define CRC                 ((CRC_TypeDef *) CRC_BASE)
                                           ^
c:\Users\(user)\Documents\Arduino\libraries\CAN_BUS_Shield\src/mcp2518fd_can_dfs.h:1487:14: note: in expansion of macro 'CRC'
     uint32_t CRC : 16;
              ^
In file included from c:\Users\(user)\Documents\Arduino\libraries\CAN_BUS_Shield\src/mcp2518fd_can.h:6:0,
                 from C:\Users\(user)\Documents\Arduino\arduino_can\driver_CAN.cpp:4:
c:\Users\(user)\Documents\Arduino\libraries\CAN_BUS_Shield\src/mcp2518fd_can_dfs.h:1590:1: error: expected declaration before '}' token
 }
 ^
exit status 1

Compilation error: exit status 1Downloading ESP32Servo@3.0.8
ESP32Servo@3.0.8
Installing ESP32Servo@3.0.8
Replacing ESP32Servo@3.0.7 with ESP32Servo@3.0.8
Installed ESP32Servo@3.0.8

Does someone know if that is a known issue (mcp_can incompatibility?), or perhaps have I missed something that I should have done ?

Reading the error messages, the problem is crystal clear. Both a Giga platform header and the Seeed CAN library are trying to define GPIO_PIN_0, as well as other similar instances. That's not going to work. And since neither of the conflicting files have been updated in at least a couple of years, apparently no one has tried that library with that board in that time.

As a workaround, you could try renaming the offending enums in the library. But you may be opening a can of worms that you're better off leaving closed.

1 Like

Thank you for your answer, I will try quickly without going too much in depth.

1 Like

the GIGA is based on the STM32H747XI micro which has two onboard CAN controllers
see section 3.40 Controller area network (FDCAN1, FDCAN2)

EDIT: have a look at CAN bus Library for Arduino STM32

not used the CAN controller on the STM32 but have used the equivalent Two-Wire Automotive Interface (TWAI) on the ESP32 which only requires a external CAN transceiver such as the TJA1051

did you manage to get the CANbus library for the STM32 working?
I experimented with a STM32F103 bluepill but so far have failed to get it to communicate with other devices on my canbus test rig

  1. Can.setBaudRate() appears to have no effcet - baudrate is always 125K
  2. other working CAN devices set to 125K show nothing received

EDIT: ignore above comments - had wiring problem - see post 8

no problem with ESP32 TWAI interface!

HI, sorry for not having answered you. An issue appeared since then (see Can't program arduino GIGA R1 WiFi anymore), so I have not played with the shield since then.

I have not bought a separate CAN transceiver, as the shield should have done the trick. But well, I should probably go with that direct approach instead when I can program my board again.

cannot help there - I don't have a GIGA
I assume you have done all the usual things

  1. pressing RESET and BOOT etc
  2. changing the USB port and cable
  3. rebooting the host computer

when doing serious work with STM32 devices I tend to use STM32CubeIDE - I find the Arduino STM support rather hit-and-miss, e.g. there is no official ST library for the onboard CAN controller

update on test STM32_CAN library using STM32F103 bluepill

dismantled test setup and rewired - problems reported in post 5 went away and the STM32-CAM library works OK with a cjmcu-1051 CAN transceiver

running modified version of test File>Examples>STM32_CAN>Write

// STM32_CAN test using STM32F103 bluepill witha cjmcu-1051 CAN transceiver

// File>Examples>STM32_CAN>Write

/*
This is simple example to send random data to CAN bus in 20Hz rate, using delay (not recommended in real implementations).
*/

#include "STM32_CAN.h"
// STM32_CAN Can( CAN1, DEF );  //Use PA11/12 pins for CAN1.
STM32_CAN Can(CAN1, ALT);  //Use PB8/9 pins for CAN1. <<<< changed
//STM32_CAN Can( CAN1, ALT_2 );  //Use PD0/1 pins for CAN1.
//STM32_CAN Can( CAN2, DEF );  //Use PB12/13 pins for CAN2.
//STM32_CAN Can( CAN2, ALT );  //Use PB5/6 pins for CAN2
//STM32_CAN Can( CAN3, DEF );  //Use PA8/15 pins for CAN3.
//STM32_CAN Can( CAN3, ALT );  //Use PB3/4 pins for CAN3

static CAN_message_t CAN_TX_msg;

void setup() {
  Serial.begin(115200);
  Can.begin();
  //Can.setBaudRate(250000);  //250KBPS
  //Can.setBaudRate(500000);  //500KBPS
  Can.setBaudRate(125000);  //125KBPS  <<< changed
  //Can.setBaudRate(1000000);  //1000KBPS
}

void loop() {
  uint8_t Counter = 0;
  while (1) {
    if (Counter > 255) { Counter = 0; }
    delay(50);
    CAN_TX_msg.id = (0x1A5);
    CAN_TX_msg.len = 8;
    CAN_TX_msg.buf[0] = 0x03;
    CAN_TX_msg.buf[1] = 0x41;
    CAN_TX_msg.buf[2] = 0x11;
    CAN_TX_msg.buf[3] = Counter;
    CAN_TX_msg.buf[4] = 0x00;
    CAN_TX_msg.buf[5] = 0x00;
    CAN_TX_msg.buf[6] = 0x00;
    CAN_TX_msg.buf[7] = 0x00;

    Can.write(CAN_TX_msg);
    delay(50);  //  <<< added delay otherwise last two messages missing

    CAN_TX_msg.id = (0x1AC32CF5);
    CAN_TX_msg.flags.extended = 1;  // To enable extended ID.
    CAN_TX_msg.len = 8;
    CAN_TX_msg.buf[0] = 0x03;
    CAN_TX_msg.buf[1] = 0x41;
    CAN_TX_msg.buf[3] = 0x21;
    CAN_TX_msg.buf[4] = 0x00;
    CAN_TX_msg.buf[5] = Counter;
    CAN_TX_msg.buf[6] = 0x00;
    CAN_TX_msg.buf[7] = 0xFF;

    Can.write(CAN_TX_msg);
    delay(50);  //  <<< added

    CAN_TX_msg.id = (0xA63);
    CAN_TX_msg.len = 8;
    CAN_TX_msg.buf[0] = 0x63;
    CAN_TX_msg.buf[1] = 0x49;
    CAN_TX_msg.buf[2] = 0x11;
    CAN_TX_msg.buf[3] = 0x22;
    CAN_TX_msg.buf[4] = 0x00;
    CAN_TX_msg.buf[5] = 0x00;
    CAN_TX_msg.buf[6] = Counter;
    CAN_TX_msg.buf[7] = 0x00;

    Can.write(CAN_TX_msg);
    delay(50);

    CAN_TX_msg.id = (0x23);
    CAN_TX_msg.flags.extended = 0;  // Back to standard ID.
    CAN_TX_msg.len = 8;
    CAN_TX_msg.buf[0] = 0x03;
    CAN_TX_msg.buf[1] = 0x41;
    CAN_TX_msg.buf[2] = 0x11;
    CAN_TX_msg.buf[3] = 0x33;
    CAN_TX_msg.buf[4] = 0x00;
    CAN_TX_msg.buf[5] = 0x00;
    CAN_TX_msg.buf[6] = 0x00;
    CAN_TX_msg.buf[7] = Counter;

    Can.write(CAN_TX_msg);
    delay(50);

    CAN_TX_msg.id = (0x55);
    CAN_TX_msg.len = 8;
    CAN_TX_msg.buf[0] = 0x03;
    CAN_TX_msg.buf[1] = 0x44;
    CAN_TX_msg.buf[2] = 0x31;
    CAN_TX_msg.buf[3] = 0x53;
    CAN_TX_msg.buf[4] = 0x00;
    CAN_TX_msg.buf[5] = Counter;
    CAN_TX_msg.buf[6] = 0x00;
    CAN_TX_msg.buf[7] = 0x00;

    Can.write(CAN_TX_msg);
    Serial.print("Sent: ");
    Serial.println(Counter, HEX);
    Counter++;
    delay(10000);
  }
}

test setup

UNO serial monitor output

Standard ID: 0x1A5       DLC: 8  Data: 0x03 0x41 0x11 0x02 0x00 0x00 0x00 0x00 A
Extended ID: 0x1AC32CF5  DLC: 8  Data:0x03 0x41 0x11 0x21 0x00 0x02 0x00 0xFF A!
Extended ID: 0x00000A63  DLC: 8  Data:0x63 0x49 0x11 0x22 0x00 0x00 0x02 0x00 I"
Standard ID: 0x023       DLC: 8  Data: 0x03 0x41 0x11 0x33 0x00 0x00 0x00 0x02 A3
Standard ID: 0x055       DLC: 8  Data: 0x03 0x44 0x31 0x53 0x00 0x02 0x00 0x00 D1S
Standard ID: 0x1A5       DLC: 8  Data: 0x03 0x41 0x11 0x03 0x00 0x00 0x00 0x00 A
Extended ID: 0x1AC32CF5  DLC: 8  Data:0x03 0x41 0x11 0x21 0x00 0x03 0x00 0xFF A!
Extended ID: 0x00000A63  DLC: 8  Data:0x63 0x49 0x11 0x22 0x00 0x00 0x03 0x00 I"
Standard ID: 0x023       DLC: 8  Data: 0x03 0x41 0x11 0x33 0x00 0x00 0x00 0x03 A3
Standard ID: 0x055       DLC: 8  Data: 0x03 0x44 0x31 0x53 0x00 0x03 0x00 0x00 D1S
Standard ID: 0x1A5       DLC: 8  Data: 0x03 0x41 0x11 0x04 0x00 0x00 0x00 0x00 A
Extended ID: 0x1AC32CF5  DLC: 8  Data:0x03 0x41 0x11 0x21 0x00 0x04 0x00 0xFF A!
Extended ID: 0x00000A63  DLC: 8  Data:0x63 0x49 0x11 0x22 0x00 0x00 0x04 0x00 I"
Standard ID: 0x023       DLC: 8  Data: 0x03 0x41 0x11 0x33 0x00 0x00 0x00 0x04 A3
Standard ID: 0x055       DLC: 8  Data: 0x03 0x44 0x31 0x53 0x00 0x04 0x00 0x00 D1S

USB-CAN module output

ESP32 Serial monitor output

Received frame: 1A5:  0x03 0x41 0x11 0x0E 0x00 0x00 0x00 0x00 A
Received frame: 1AC32CF5:  0x03 0x41 0x11 0x21 0x00 0x0E 0x00 0xFF A!
Received frame: A63:  0x63 0x49 0x11 0x22 0x00 0x00 0x0E 0x00 I"
Received frame: 023:  0x03 0x41 0x11 0x33 0x00 0x00 0x00 0x0E A3
Received frame: 055:  0x03 0x44 0x31 0x53 0x00 0x0E 0x00 0x00 D1S
Transmit frame: 7DF:  0x02 0x54 0x57 0x41 0x49 0x00 0xAA 0xAA
Transmit frame: 7DF:  0x03 0x54 0x57 0x41 0x49 0x00 0xAA 0xAA
Received frame: 1A5:  0x03 0x41 0x11 0x0F 0x00 0x00 0x00 0x00 A
Received frame: 1AC32CF5:  0x03 0x41 0x11 0x21 0x00 0x0F 0x00 0xFF A!
Received frame: A63:  0x63 0x49 0x11 0x22 0x00 0x00 0x0F 0x00 I"
Received frame: 023:  0x03 0x41 0x11 0x33 0x00 0x00 0x00 0x0F A3
Received frame: 055:  0x03 0x44 0x31 0x53 0x00 0x0F 0x00 0x00 D1S
Received frame: 1A5:  0x03 0x41 0x11 0x10 0x00 0x00 0x00 0x00 A
Received frame: 1AC32CF5:  0x03 0x41 0x11 0x21 0x00 0x10 0x00 0xFF A!
Received frame: A63:  0x63 0x49 0x11 0x22 0x00 0x00 0x10 0x00 I"
Received frame: 023:  0x03 0x41 0x11 0x33 0x00 0x00 0x00 0x10 A3
Received frame: 055:  0x03 0x44 0x31 0x53 0x00 0x10 0x00 0x00 D1S
Transmit frame: 100:  0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
Transmit frame: 7DF:  0x04 0x54 0x57 0x41 0x49 0x00 0xAA 0xAA

a problem with the STM32F103 bluepill used in post 6 is indicated by the compiler warning

STM32_CAN.h:138:2: warning: #warning "CAN IRQ Handler is used by USBDevice driver

using USB Serial Monitor IO with the CAN interface is difficult (in practice one would probably use the Serial1 interface)

running STM32-CAN library example file>Examples>STM32_CAN/Read-Write_with_filters on a STM32F746ZG nucleo board

// STM32F746ZG nucleo board STM32-CAN library read/write test

// file>Examples>STM32_CAN/Read-Write_with_filters

/*
This example shows how to read filtered CAN messages from the bus and send data out using timers.
*/

#include "STM32_CAN.h"

static CAN_message_t CAN_outMsg_1;
static CAN_message_t CAN_outMsg_2;
static CAN_message_t CAN_outMsg_3;
static CAN_message_t CAN_inMsg;

// This will use PA11/12 pins for CAN1 and set RX-buffer size to 64-messages. TX-buffer size is kept at default 16.
//STM32_CAN Can( CAN1, DEF, RX_SIZE_64, TX_SIZE_16 );
STM32_CAN Can(CAN1, ALT, RX_SIZE_64, TX_SIZE_16);  //Use PB8/9 pins for CAN1.

uint8_t Counter;

void printData(CAN_message_t CAN_outMsg) {
  Serial.printf("Transmit frame: %03X: ", CAN_outMsg.id);
  for (byte i = 0; i < 8; i++)
    Serial.printf(" 0x%.2X", CAN_outMsg.buf[i]);
  Serial.printf("\n");
}

void SendData()  // Send can messages in 50Hz phase from timer interrupt.
{
  Serial.print("\nSending frame: ");
  Serial.println(Counter, HEX);
  //if (Counter >= 255){ Counter = 0;}
  // Only the counter value is updated to the 3 messages sent out.
  CAN_outMsg_1.buf[3] = Counter;
  Can.write(CAN_outMsg_1);
  printData(CAN_outMsg_1);
  CAN_outMsg_2.buf[5] = Counter;
  Can.write(CAN_outMsg_2);
  printData(CAN_outMsg_2);
  CAN_outMsg_3.buf[6] = Counter;
  Can.write(CAN_outMsg_3);
  printData(CAN_outMsg_3);
  Counter++;
}

void readCanMessage()  // Read data from CAN bus and print out the messages to serial bus. Note that only message ID's that pass filters are read.
{
  Serial.print("Channel:");
  Serial.print(CAN_inMsg.bus);
  if (CAN_inMsg.flags.extended == false) {
    Serial.print(" Standard ID:");
  } else {
    Serial.print(" Extended ID:");
  }
  Serial.print(CAN_inMsg.id, HEX);

  Serial.print(" DLC: ");
  Serial.print(CAN_inMsg.len);
  if (CAN_inMsg.flags.remote == false) {
    Serial.print(" buf: ");
    for (int i = 0; i < CAN_inMsg.len; i++) {
      Serial.print("0x");
      Serial.print(CAN_inMsg.buf[i], HEX);
      if (i != (CAN_inMsg.len - 1)) Serial.print(" ");
    }
    Serial.println();
  } else {
    Serial.println(" Data: REMOTE REQUEST FRAME");
  }
}

void setup() {
  Counter = 0;
  Serial.begin(115200);
  delay(2000);
  Serial.println("\n\nSTM32F746ZG nucleo board STM32-CAN library read/write test");
  Can.begin();
  Can.setBaudRate(125000);
  //Can.setBaudRate(500000);
  Can.setMBFilterProcessing(MB0, 0x100, 0x1FFFFFFF);
  Can.setMBFilterProcessing(MB1, 0x7DF, 0x1FFFFFFF);
  // You can also set that is the ID Standard or Extended
  Can.setMBFilterProcessing(MB2, 0x615, 0x1FFFFFFF, STD);
  Can.setMBFilterProcessing(MB3, 0x1F0, 0x1FFFFFFF, EXT);

  // We set the data that is static for the three different message structs once here.
  CAN_outMsg_1.id = (0x1A5);
  CAN_outMsg_1.len = 8;
  CAN_outMsg_1.buf[0] = 0x03;
  CAN_outMsg_1.buf[1] = 0x41;
  CAN_outMsg_1.buf[2] = 0x11;
  CAN_outMsg_1.buf[3] = 0x00;
  CAN_outMsg_1.buf[4] = 0x00;
  CAN_outMsg_1.buf[5] = 0x00;
  CAN_outMsg_1.buf[6] = 0x00;
  CAN_outMsg_1.buf[7] = 0x00;

  CAN_outMsg_2.id = (0x7E8);
  CAN_outMsg_2.len = 8;
  CAN_outMsg_2.buf[0] = 0x03;
  CAN_outMsg_2.buf[1] = 0x41;
  CAN_outMsg_2.buf[3] = 0x21;
  CAN_outMsg_2.buf[4] = 0x00;
  CAN_outMsg_2.buf[5] = 0x00;
  CAN_outMsg_2.buf[6] = 0x00;
  CAN_outMsg_2.buf[7] = 0xFF;

  CAN_outMsg_3.id = (0xA63);
  CAN_outMsg_3.len = 8;
  CAN_outMsg_3.buf[0] = 0x63;
  CAN_outMsg_3.buf[1] = 0x49;
  CAN_outMsg_3.buf[2] = 0x11;
  CAN_outMsg_3.buf[3] = 0x22;
  CAN_outMsg_3.buf[4] = 0x00;
  CAN_outMsg_3.buf[5] = 0x00;
  CAN_outMsg_3.buf[6] = 0x00;
  CAN_outMsg_3.buf[7] = 0x00;
  /*
  // setup hardware timer to send data in 50Hz pace
  #if defined(TIM1)
  TIM_TypeDef *Instance = TIM1;
#else
  TIM_TypeDef *Instance = TIM2;
#endif
  HardwareTimer *SendTimer = new HardwareTimer(Instance);
  SendTimer->setOverflow(50000, HERTZ_FORMAT); // 50 Hz
#if ( STM32_CORE_VERSION_MAJOR < 2 )
  SendTimer->attachInterrupt(1, SendData);
  SendTimer->setMode(1, TIMER_OUTPUT_COMPARE);
#else //2.0 forward
  SendTimer->attachInterrupt(SendData);
#endif
  SendTimer->resume();
  */
  SendData(); // send initial frame
}

// main loop
void loop() {
  // if key entered send a frame
  if (Serial.available()) {
    while (Serial.available()) Serial.read();
    SendData();
  }
  // The actual code that is being used will be done to main loop as usual.
  // We only read data from CAN bus if there is frames received, so that main code can do it's thing efficiently.
  while (Can.read(CAN_inMsg)) {
    readCanMessage();
  }
}

Serail monitor output

STM32F746ZG nucleo board STM32-CAN library read/write test

Sending frame: 0
Transmit frame: 1A5:  0x03 0x41 0x11 0x00 0x00 0x00 0x00 0x00
Transmit frame: 7E8:  0x03 0x41 0x00 0x21 0x00 0x00 0x00 0xFF
Transmit frame: A63:  0x63 0x49 0x11 0x22 0x00 0x00 0x00 0x00
Channel:1 Standard ID:100 DLC: 8 buf: 0x0 0x4D 0x45 0x47 0x41 0x0 0x7 0x8
Channel:1 Standard ID:100 DLC: 8 buf: 0x1 0x4D 0x45 0x47 0x41 0x0 0x7 0x8
Channel:1 Standard ID:7DF DLC: 8 buf: 0x2 0x54 0x57 0x41 0x49 0x0 0xAA 0xAA
Channel:1 Standard ID:7DF DLC: 8 buf: 0x3 0x54 0x57 0x41 0x49 0x0 0xAA 0xAA

Sending frame: 1
Transmit frame: 1A5:  0x03 0x41 0x11 0x01 0x00 0x00 0x00 0x00
Transmit frame: 7E8:  0x03 0x41 0x00 0x21 0x00 0x01 0x00 0xFF
Transmit frame: A63:  0x63 0x49 0x11 0x22 0x00 0x00 0x01 0x00

Sending frame: 2
Transmit frame: 1A5:  0x03 0x41 0x11 0x02 0x00 0x00 0x00 0x00
Transmit frame: 7E8:  0x03 0x41 0x00 0x21 0x00 0x02 0x00 0xFF
Transmit frame: A63:  0x63 0x49 0x11 0x22 0x00 0x00 0x02 0x00
Channel:1 Standard ID:100 DLC: 8 buf: 0x2 0x4D 0x45 0x47 0x41 0x0 0x7 0x8
Channel:1 Standard ID:100 DLC: 8 buf: 0x3 0x4D 0x45 0x47 0x41 0x0 0x7 0x8
Channel:1 Standard ID:7DF DLC: 8 buf: 0x4 0x54 0x57 0x41 0x49 0x0 0xAA 0xAA
Channel:1 Standard ID:7DF DLC: 8 buf: 0x5 0x54 0x57 0x41 0x49 0x0 0xAA 0xAA
Channel:1 Standard ID:7DF DLC: 8 buf: 0x6 0x54 0x57 0x41 0x49 0x0 0xAA 0xAA

Sending frame: 3
Transmit frame: 1A5:  0x03 0x41 0x11 0x03 0x00 0x00 0x00 0x00
Transmit frame: 7E8:  0x03 0x41 0x00 0x21 0x00 0x03 0x00 0xFF
Transmit frame: A63:  0x63 0x49 0x11 0x22 0x00 0x00 0x03 0x00

test setup (included a STM32F746ZG nucleo board, Adafruit RP2040 CAN Bus Feather, ESP32 and UNO+CAN shield)