18#ifndef BOOT_COM_CAN_CHANNEL_INDEX
19 #error BOOT_COM_CAN_CHANNEL_INDEX is not defined.
20#elif (BOOT_COM_CAN_CHANNEL_INDEX == 0)
21 #ifndef STM32_CAN_USE_CAN1
22 #error STM32_CAN_USE_CAN1 is not enabled for CAN index 0
25 #define OPENBLT_CAND CAND1
26#elif (BOOT_COM_CAN_CHANNEL_INDEX == 1)
27 #ifndef STM32_CAN_USE_CAN2
28 #error STM32_CAN_USE_CAN2 is not enabled for CAN index 1
31 #define OPENBLT_CAND CAND2
33 #error Unknown BOOT_COM_CAN_CHANNEL_INDEX.
36#if !defined(OPENBLT_CAN_RX_PIN) || !defined(OPENBLT_CAN_RX_PORT) || !defined(OPENBLT_CAN_TX_PIN) || !defined(OPENBLT_CAN_TX_PORT)
37#if (BOOT_COM_CAN_CHANNEL_INDEX == 0)
39 #define OPENBLT_CAN_RX_PORT GPIOB
40 #define OPENBLT_CAN_RX_PIN 8
41 #define OPENBLT_CAN_TX_PORT GPIOB
42 #define OPENBLT_CAN_TX_PIN 9
43#elif (BOOT_COM_CAN_CHANNEL_INDEX == 1)
45 #define OPENBLT_CAN_RX_PORT GPIOB
46 #define OPENBLT_CAN_RX_PIN 5
47 #define OPENBLT_CAN_TX_PORT GPIOB
48 #define OPENBLT_CAN_TX_PIN 13
61 palSetPadMode(OPENBLT_CAN_TX_PORT, OPENBLT_CAN_TX_PIN, PAL_MODE_ALTERNATE(EFI_CAN_TX_AF));
62 palSetPadMode(OPENBLT_CAN_RX_PORT, OPENBLT_CAN_RX_PIN, PAL_MODE_ALTERNATE(EFI_CAN_RX_AF));
65 canStart(&OPENBLT_CAND, cfg);
81 if ((txMsgId & 0x80000000) == 0)
85 frame.
IDE = CAN_IDE_STD;
89 txMsgId &= ~0x80000000;
92 frame.
IDE = CAN_IDE_EXT;
97 memcpy(frame.
data8, data, len);
99 canTransmitTimeout(&OPENBLT_CAND, CAN_ANY_MAILBOX, &frame, TIME_MS2I(100));
110#ifdef BOOTLOADER_CAN_LISTENER
116 constexpr blt_int32u rxMsgId = BOOT_COM_CAN_RX_MSG_ID;
119 if (MSG_OK != canReceiveTimeout(&OPENBLT_CAND, CAN_ANY_MAILBOX, &frame, TIME_IMMEDIATE)) {
125 constexpr bool configuredAsExt = (rxMsgId & 0x80000000) != 0;
126 if (configuredAsExt != frame.
IDE) {
133 if (frame.
EID != (rxMsgId & ~0x80000000)) {
138 if (frame.
SID != rxMsgId) {
146 memcpy(data, frame.
data8, frame.
DLC);
152#ifdef BOOTLOADER_CAN_LISTENER
void CanInit(void)
Initializes the CAN controller and synchronizes it to the CAN bus.
void boardCanListener(CANRxFrame *frame)
Receives a communication interface packet if one is present.
const CANConfig * findCanConfig(can_baudrate_e rate)
blt_bool CanReceivePacket(blt_int8u *data, blt_int8u *len)
void CanTransmitPacket(blt_int8u *data, blt_int8u len)
Transmits a packet formatted for the communication interface.
uint32_t SID
Standard identifier.
uint8_t IDE
Identifier type.
uint32_t EID
Extended identifier.
uint8_t data8[8]
Frame data.
uint8_t data8[8]
Frame data.
uint32_t SID
Standard identifier.
uint32_t EID
Extended identifier.
uint8_t IDE
Identifier type.