From 094ca973732d679a6bc36f5b07ccc3b99edf3819 Mon Sep 17 00:00:00 2001 From: andreika-git Date: Tue, 12 Mar 2024 14:38:52 +0200 Subject: [PATCH] Enable CAN for OpenBLT https://github.com/rusefi/rusefi/issues/6043 --- .../openblt_chibios/openblt_can.cpp | 20 ++++++++++++++++++- firmware/hw_layer/openblt/blt_conf.h | 6 +++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/firmware/bootloader/openblt_chibios/openblt_can.cpp b/firmware/bootloader/openblt_chibios/openblt_can.cpp index fca58ffed5..62fcbe16e0 100644 --- a/firmware/bootloader/openblt_chibios/openblt_can.cpp +++ b/firmware/bootloader/openblt_chibios/openblt_can.cpp @@ -15,8 +15,26 @@ extern "C" { // CAN1_RX: { PI9, PA11, PH14, PD0, PB8 }, CAN1_TX: { PA12, PH13, PD1, PB9 } // CAN2_RX: { PB5, PB12 }, CAN2_TX: { PB6, PB13 } +#ifndef BOOT_COM_CAN_CHANNEL_INDEX + #error BOOT_COM_CAN_CHANNEL_INDEX is not defined. +#elif (BOOT_COM_CAN_CHANNEL_INDEX == 0) + #ifndef STM32_CAN_USE_CAN1 + #error STM32_CAN_USE_CAN1 is not enabled for CAN index 0 + #endif + #undef OPENBLT_CAND + #define OPENBLT_CAND CAND1 +#elif (BOOT_COM_CAN_CHANNEL_INDEX == 1) + #ifndef STM32_CAN_USE_CAN2 + #error STM32_CAN_USE_CAN2 is not enabled for CAN index 1 + #endif + #undef OPENBLT_CAND + #define OPENBLT_CAND CAND2 +#else + #error Unknown BOOT_COM_CAN_CHANNEL_INDEX. +#endif + #if !defined(OPENBLT_CAND) || !defined(OPENBLT_CAN_RX_PIN) || !defined(OPENBLT_CAN_RX_PORT) || !defined(OPENBLT_CAN_TX_PIN) || !defined(OPENBLT_CAN_TX_PORT) -#ifndef STM32_CAN_USE_CAN2 +#ifdef STM32_CAN_USE_CAN2 #define OPENBLT_CAND CAND2 #define OPENBLT_CAN_RX_PORT GPIOB #define OPENBLT_CAN_RX_PIN 5 diff --git a/firmware/hw_layer/openblt/blt_conf.h b/firmware/hw_layer/openblt/blt_conf.h index 0a89dd69f3..f62887419c 100644 --- a/firmware/hw_layer/openblt/blt_conf.h +++ b/firmware/hw_layer/openblt/blt_conf.h @@ -84,7 +84,7 @@ * */ /** \brief Enable/disable CAN transport layer. */ -#define BOOT_COM_CAN_ENABLE (0) +#define BOOT_COM_CAN_ENABLE (1) /** \brief Configure the desired CAN baudrate. */ #define BOOT_COM_CAN_BAUDRATE (500000) /** \brief Configure CAN message ID target->host. */ @@ -95,6 +95,10 @@ #define BOOT_COM_CAN_RX_MSG_ID (0x667 /*| 0x80000000*/) /** \brief Configure number of bytes in the host->target CAN message. */ #define BOOT_COM_CAN_RX_MAX_DATA (8) +/** \brief Select the desired CAN peripheral as a zero based index. */ +#ifndef BOOT_COM_CAN_CHANNEL_INDEX +#define BOOT_COM_CAN_CHANNEL_INDEX (0) +#endif /* BOOT_COM_CAN_CHANNEL_INDEX */ /* The RS232 communication interface is selected by setting the BOOT_COM_RS232_ENABLE * configurable to 1. Configurable BOOT_COM_RS232_BAUDRATE selects the communication speed