@@ -57,14 +57,14 @@ void can_init_freq (can_t *obj, PinName rd, PinName td, int hz)
57
57
__HAL_RCC_CAN1_CLK_ENABLE ();
58
58
obj -> index = 0 ;
59
59
}
60
- #if defined(CAN2_BASE ) && defined( CAN_2 )
60
+ #if defined(CAN2_BASE ) && ( CAN_NUM > 1 )
61
61
else if (can == CAN_2 ) {
62
62
__HAL_RCC_CAN1_CLK_ENABLE (); // needed to set filters
63
63
__HAL_RCC_CAN2_CLK_ENABLE ();
64
64
obj -> index = 1 ;
65
65
}
66
66
#endif
67
- #if defined(CAN3_BASE ) && defined( CAN_3 )
67
+ #if defined(CAN3_BASE ) && ( CAN_NUM > 2 )
68
68
else if (can == CAN_3 ) {
69
69
__HAL_RCC_CAN3_CLK_ENABLE ();
70
70
obj -> index = 2 ;
@@ -103,7 +103,13 @@ void can_init_freq (can_t *obj, PinName rd, PinName td, int hz)
103
103
104
104
can_registers_init (obj );
105
105
106
+ /* Bits 27:14 are available for dual CAN configuration and are reserved for
107
+ single CAN configuration: */
108
+ #if defined(CAN3_BASE ) && (CAN_NUM > 2 )
109
+ uint32_t filter_number = (can == CAN_1 || can == CAN_3 ) ? 0 : 14 ;
110
+ #else
106
111
uint32_t filter_number = (can == CAN_1 ) ? 0 : 14 ;
112
+ #endif
107
113
can_filter (obj , 0 , 0 , CANStandard , filter_number );
108
114
}
109
115
@@ -132,14 +138,14 @@ void can_free(can_t *obj)
132
138
__HAL_RCC_CAN1_RELEASE_RESET ();
133
139
__HAL_RCC_CAN1_CLK_DISABLE ();
134
140
}
135
- #if defined(CAN2_BASE ) && defined( CAN_2 )
141
+ #if defined(CAN2_BASE ) && ( CAN_NUM > 1 )
136
142
if (can == CAN_2 ) {
137
143
__HAL_RCC_CAN2_FORCE_RESET ();
138
144
__HAL_RCC_CAN2_RELEASE_RESET ();
139
145
__HAL_RCC_CAN2_CLK_DISABLE ();
140
146
}
141
147
#endif
142
- #if defined(CAN3_BASE ) && defined( CAN_3 )
148
+ #if defined(CAN3_BASE ) && ( CAN_NUM > 2 )
143
149
if (can == CAN_3 ) {
144
150
__HAL_RCC_CAN3_FORCE_RESET ();
145
151
__HAL_RCC_CAN3_RELEASE_RESET ();
@@ -562,7 +568,7 @@ void CAN1_SCE_IRQHandler(void)
562
568
{
563
569
can_irq (CAN_1 , 0 );
564
570
}
565
- #if defined(CAN2_BASE ) && defined( CAN_2 )
571
+ #if defined(CAN2_BASE ) && ( CAN_NUM > 1 )
566
572
void CAN2_RX0_IRQHandler (void )
567
573
{
568
574
can_irq (CAN_2 , 1 );
@@ -576,18 +582,18 @@ void CAN2_SCE_IRQHandler(void)
576
582
can_irq (CAN_2 , 1 );
577
583
}
578
584
#endif
579
- #if defined(CAN3_BASE ) && defined( CAN_3 )
585
+ #if defined(CAN3_BASE ) && ( CAN_NUM > 2 )
580
586
void CAN3_RX0_IRQHandler (void )
581
587
{
582
- can_irq (CAN_3 , 1 );
588
+ can_irq (CAN_3 , 2 );
583
589
}
584
590
void CAN3_TX_IRQHandler (void )
585
591
{
586
- can_irq (CAN_3 , 1 );
592
+ can_irq (CAN_3 , 2 );
587
593
}
588
594
void CAN3_SCE_IRQHandler (void )
589
595
{
590
- can_irq (CAN_3 , 1 );
596
+ can_irq (CAN_3 , 2 );
591
597
}
592
598
#endif
593
599
#endif // else
@@ -630,7 +636,7 @@ void can_irq_set(can_t *obj, CanIrqType type, uint32_t enable)
630
636
return ;
631
637
}
632
638
}
633
- #if defined(CAN2_BASE ) && defined( CAN_2 )
639
+ #if defined(CAN2_BASE ) && ( CAN_NUM > 1 )
634
640
else if ((CANName ) can == CAN_2 ) {
635
641
switch (type ) {
636
642
case IRQ_RX :
@@ -663,7 +669,7 @@ void can_irq_set(can_t *obj, CanIrqType type, uint32_t enable)
663
669
}
664
670
}
665
671
#endif
666
- #if defined(CAN3_BASE ) && defined( CAN_3 )
672
+ #if defined(CAN3_BASE ) && ( CAN_NUM > 2 )
667
673
else if ((CANName ) can == CAN_3 ) {
668
674
switch (type ) {
669
675
case IRQ_RX :
@@ -711,4 +717,3 @@ void can_irq_set(can_t *obj, CanIrqType type, uint32_t enable)
711
717
}
712
718
713
719
#endif // DEVICE_CAN
714
-
0 commit comments