Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions STM32_CAN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,10 +353,12 @@ void STM32_CAN::begin( bool retransmission ) {
* This lets loopback only tests without external circuitry sill function.
*/
uint32_t rx_func = pinmap_function(rx, PinMap_CAN_RD);
pin_function(rx, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, STM_PIN_AFNUM(rx_func)));
rx_func = (rx_func & ~(STM_PIN_PUPD_MASK << STM_PIN_PUPD_SHIFT))
| (GPIO_PULLUP << STM_PIN_PUPD_SHIFT);
pin_function(rx, fixPinFunction(rx_func));
if(tx != NC)
{
pin_function(tx, pinmap_function(tx, PinMap_CAN_TD));
pin_function(tx, fixPinFunction(pinmap_function(tx, PinMap_CAN_TD)));
}

// Configure CAN
Expand Down Expand Up @@ -1153,6 +1155,25 @@ uint32_t STM32_CAN::getCanPeripheralClock()
return HAL_RCC_GetPCLK1Freq();
}

uint32_t STM32_CAN::fixPinFunction(uint32_t function)
{
#ifdef STM32F1xx
/**
* NOTE: F103 pinmaps defines AFIO_NONE for first (default) pinmaping.
* should be AFIO_CAN1_1.
*/
uint32_t af = STM_PIN_AFNUM(function);
if(af == AFIO_NONE)
{
af = AFIO_CAN1_1;
}

function &= ~(STM_PIN_AFNUM_MASK << STM_PIN_AFNUM_SHIFT);
function |= ((af & STM_PIN_AFNUM_MASK) << STM_PIN_AFNUM_SHIFT);
#endif
return function;
}

void STM32_CAN::enableMBInterrupts()
{
if (_can.handle.Instance == CAN1)
Expand Down
1 change: 1 addition & 0 deletions STM32_CAN.h
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ class STM32_CAN {
void setBaudRateValues(uint16_t prescaler, uint8_t timeseg1,
uint8_t timeseg2, uint8_t sjw);
uint32_t getCanPeripheralClock(void);
uint32_t fixPinFunction(uint32_t function);

volatile CAN_message_t *rx_buffer = nullptr;
volatile CAN_message_t *tx_buffer = nullptr;
Expand Down
32 changes: 31 additions & 1 deletion examples/Read-Write_with_filters/hal_conf_extra.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
#if !defined(HAL_CAN_MODULE_ENABLED)
#define HAL_CAN_MODULE_ENABLED
#define HAL_CAN_MODULE_ENABLED

#if defined(STM32F1xx)
/** NOTE: Enable special alternate function remapping for F1 platform*/
#define AFIO_MAPR_CAN_REMAP1
#endif

#if defined(USBCON) && defined(STM32F1xx)
/** NOTE: On the F1 platform CAN and USB may not be used at the same time.
* To still allow a program to be build that may use both
* but not at the same time this workaround may be enabled.
* Since USB driver is using the shared IRQ handlers, the CAN driver has no access to them.
* To handle Tx events call
*
* STM32_CAN_Poll_IRQ_Handler()
*
* frequently
*/
// #define STM32_CAN_USB_WORKAROUND_POLLING
#endif

#if defined(USBCON) && defined(STM32F3xx)
/** NOTE: On F3 platform CAN and USB share IRQ by default.
* Since USB driver is using the shared IRQ handlers, the CAN driver has no access to them.
*
* Below define maps the USB IRQs to alternate IRQ vectors,
* so USB and CAN IRQs are no longer shared
*/
// #define USE_USB_INTERRUPT_REMAPPED
#endif

#endif
32 changes: 31 additions & 1 deletion examples/Read/hal_conf_extra.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
#if !defined(HAL_CAN_MODULE_ENABLED)
#define HAL_CAN_MODULE_ENABLED
#define HAL_CAN_MODULE_ENABLED

#if defined(STM32F1xx)
/** NOTE: Enable special alternate function remapping for F1 platform*/
#define AFIO_MAPR_CAN_REMAP1
#endif

#if defined(USBCON) && defined(STM32F1xx)
/** NOTE: On the F1 platform CAN and USB may not be used at the same time.
* To still allow a program to be build that may use both
* but not at the same time this workaround may be enabled.
* Since USB driver is using the shared IRQ handlers, the CAN driver has no access to them.
* To handle Tx events call
*
* STM32_CAN_Poll_IRQ_Handler()
*
* frequently
*/
// #define STM32_CAN_USB_WORKAROUND_POLLING
#endif

#if defined(USBCON) && defined(STM32F3xx)
/** NOTE: On F3 platform CAN and USB share IRQ by default.
* Since USB driver is using the shared IRQ handlers, the CAN driver has no access to them.
*
* Below define maps the USB IRQs to alternate IRQ vectors,
* so USB and CAN IRQs are no longer shared
*/
// #define USE_USB_INTERRUPT_REMAPPED
#endif

#endif
32 changes: 31 additions & 1 deletion examples/Sniffer/hal_conf_extra.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
#if !defined(HAL_CAN_MODULE_ENABLED)
#define HAL_CAN_MODULE_ENABLED
#define HAL_CAN_MODULE_ENABLED

#if defined(STM32F1xx)
/** NOTE: Enable special alternate function remapping for F1 platform*/
#define AFIO_MAPR_CAN_REMAP1
#endif

#if defined(USBCON) && defined(STM32F1xx)
/** NOTE: On the F1 platform CAN and USB may not be used at the same time.
* To still allow a program to be build that may use both
* but not at the same time this workaround may be enabled.
* Since USB driver is using the shared IRQ handlers, the CAN driver has no access to them.
* To handle Tx events call
*
* STM32_CAN_Poll_IRQ_Handler()
*
* frequently
*/
// #define STM32_CAN_USB_WORKAROUND_POLLING
#endif

#if defined(USBCON) && defined(STM32F3xx)
/** NOTE: On F3 platform CAN and USB share IRQ by default.
* Since USB driver is using the shared IRQ handlers, the CAN driver has no access to them.
*
* Below define maps the USB IRQs to alternate IRQ vectors,
* so USB and CAN IRQs are no longer shared
*/
// #define USE_USB_INTERRUPT_REMAPPED
#endif

#endif
32 changes: 31 additions & 1 deletion examples/Write/hal_conf_extra.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
#if !defined(HAL_CAN_MODULE_ENABLED)
#define HAL_CAN_MODULE_ENABLED
#define HAL_CAN_MODULE_ENABLED

#if defined(STM32F1xx)
/** NOTE: Enable special alternate function remapping for F1 platform*/
#define AFIO_MAPR_CAN_REMAP1
#endif

#if defined(USBCON) && defined(STM32F1xx)
/** NOTE: On the F1 platform CAN and USB may not be used at the same time.
* To still allow a program to be build that may use both
* but not at the same time this workaround may be enabled.
* Since USB driver is using the shared IRQ handlers, the CAN driver has no access to them.
* To handle Tx events call
*
* STM32_CAN_Poll_IRQ_Handler()
*
* frequently
*/
// #define STM32_CAN_USB_WORKAROUND_POLLING
#endif

#if defined(USBCON) && defined(STM32F3xx)
/** NOTE: On F3 platform CAN and USB share IRQ by default.
* Since USB driver is using the shared IRQ handlers, the CAN driver has no access to them.
*
* Below define maps the USB IRQs to alternate IRQ vectors,
* so USB and CAN IRQs are no longer shared
*/
// #define USE_USB_INTERRUPT_REMAPPED
#endif

#endif