From a30339c524dbbae23391ab18555f1532fa733d73 Mon Sep 17 00:00:00 2001 From: Pasi Kemppainen <48950874+pazi88@users.noreply.github.com> Date: Thu, 21 Mar 2024 13:27:28 +0200 Subject: [PATCH] Fix for F303 --- .github/workflows/compile-examples.yml | 1 + STM32_CAN.cpp | 15 --------------- STM32_CAN.h | 15 +++++++++++++++ 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index bfd3c13..9c711e4 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -16,6 +16,7 @@ jobs: - fqbn: "Nucleo_144" - fqbn: "GenF0:pnum=GENERIC_F042F6PX" - fqbn: "GenF1:pnum=GENERIC_F103C8TX" + - fqbn: "GenF3:pnum=GENERIC_F303RETX" - fqbn: "GenF4:pnum=GENERIC_F412RETX" - fqbn: "GenF4:pnum=GENERIC_F407VETX" diff --git a/STM32_CAN.cpp b/STM32_CAN.cpp index b1bfe2c..d05f8dd 100644 --- a/STM32_CAN.cpp +++ b/STM32_CAN.cpp @@ -145,19 +145,12 @@ void STM32_CAN::begin( bool retransmission ) { } #endif - - #if defined(STM32F0xx) - // NVIC configuration for CAN1 - HAL_NVIC_SetPriority(CEC_CAN_IRQn, 15, 0); - HAL_NVIC_EnableIRQ(CEC_CAN_IRQn); - #else // NVIC configuration for CAN1 Reception complete interrupt HAL_NVIC_SetPriority(CAN1_RX0_IRQn, 15, 0); // 15 is lowest possible priority HAL_NVIC_EnableIRQ(CAN1_RX0_IRQn ); // NVIC configuration for CAN1 Transmission complete interrupt HAL_NVIC_SetPriority(CAN1_TX_IRQn, 15, 0); // 15 is lowest possible priority HAL_NVIC_EnableIRQ(CAN1_TX_IRQn); - #endif n_pCanHandle->Instance = CAN1; } @@ -767,11 +760,7 @@ void STM32_CAN::enableMBInterrupts() { if (n_pCanHandle->Instance == CAN1) { - #if defined(STM32F0xx) - HAL_NVIC_EnableIRQ(CEC_CAN_IRQn); - #else HAL_NVIC_EnableIRQ(CAN1_TX_IRQn); - #endif } #ifdef CAN2 else if (n_pCanHandle->Instance == CAN2) @@ -791,11 +780,7 @@ void STM32_CAN::disableMBInterrupts() { if (n_pCanHandle->Instance == CAN1) { - #if defined(STM32F0xx) - HAL_NVIC_EnableIRQ(CEC_CAN_IRQn); - #else HAL_NVIC_DisableIRQ(CAN1_TX_IRQn); - #endif } #ifdef CAN2 else if (n_pCanHandle->Instance == CAN2) diff --git a/STM32_CAN.h b/STM32_CAN.h index 9b5344b..841c5b6 100644 --- a/STM32_CAN.h +++ b/STM32_CAN.h @@ -19,6 +19,21 @@ to same folder with sketch and haven #define HAL_CAN_MODULE_ENABLED there. See e #ifndef STM32_CAN_H #define STM32_CAN_H +// couple of workarounds +#if defined(STM32F3xx) + #define GPIO_AF9_CAN1 GPIO_AF9_CAN + #define CAN1_RX0_IRQn CAN_RX0_IRQn + #define CAN1_TX_IRQn CAN_TX_IRQn + #define GPIO_SPEED_FREQ_VERY_HIGH GPIO_SPEED_FREQ_HIGH + #define CAN1_TX_IRQHandler CAN_TX_IRQHandler + #define CAN1_RX0_IRQHandler CAN_RX0_IRQHandler +#endif + +#if defined(STM32F0xx) + #define CAN1_TX_IRQn CEC_CAN_IRQn + #define CAN1_RX0_IRQn CEC_CAN_IRQn +#endif + #include // This struct is directly copied from Teensy FlexCAN library to retain compatibility with it. Not all are in use with STM32.