Projets S4 IUT de Cachan / CANnucleo

Fork of CANnucleo by Zoltan Hudak

Files at this revision

API Documentation at this revision

Comitter:
hudakz
Date:
Sun Dec 27 09:02:47 2015 +0000
Parent:
13:a3e2be3d49a2
Child:
15:5123ead7b002
Commit message:
Updated.

Changed in this revision

CAN.cpp Show annotated file Show diff for this revision Revisions of this file
CAN.h Show annotated file Show diff for this revision Revisions of this file
can_api.c Show annotated file Show diff for this revision Revisions of this file
can_api.h Show annotated file Show diff for this revision Revisions of this file
stm32f1xx_hal_msp.c Show annotated file Show diff for this revision Revisions of this file
stm32f1xx_hal_msp.h Show annotated file Show diff for this revision Revisions of this file
stm32f3xx_hal_msp.c Show annotated file Show diff for this revision Revisions of this file
stm32f3xx_hal_msp.h Show annotated file Show diff for this revision Revisions of this file
--- a/CAN.cpp	Wed Dec 23 10:37:01 2015 +0000
+++ b/CAN.cpp	Sun Dec 27 09:02:47 2015 +0000
@@ -177,6 +177,10 @@
  *
  * To compare only the bits representing STID we set the filter mask adequately:
  * Filter mask = 11111111 11100000 00000000 00000100 = 0xFFE00004
+ *               |||||||| |||                    |
+ *               -------- ---                    |
+ *                   |     |                     |
+ *            STID[10:3]  STID[2:0]             IDE   
  *
  * Keep in mind that filter #0 was already set up in the constructor to receive all CAN messages by default.
  * So we have to reconfigure it. If we were set up filter #1 here then filter #0 would receive all the messages
@@ -185,7 +189,7 @@
  * To set up filter #0 we call:
  *     can.filter(0x0207 << 21, 0xFFE00004, CANAny, 0);
  *
- *             Only these bits of filter id are compared with the corresponding
+ *             Only these bits (set to 1) of filter id are compared with the corresponding
  *             bits of received message (the others are disregarded)
  *                                |
  *                 ---------------------------------
@@ -205,7 +209,7 @@
  *                             ||||| |||||||| ||||| ||
  *                             -----------------------
  *                                         |
- *                          These bits are disregarded (masked).
+ *                          These bits (set to 0 in filter mask) are disregarded (masked).
  *                          They can have arbitrary values.
  *
  * NOTE: For the meaning of individual bits see the mapping of 32-bits explained above.
@@ -229,20 +233,12 @@
  * @retval
  */
 void CAN::attach(void (*fptr) (void), IrqType type) {
-#if defined(TARGET_NUCLEO_F103RB)
-    HAL_NVIC_DisableIRQ(USB_LP_CAN1_RX0_IRQn);
-#elif defined(TARGET_NUCLEO_F303RE)
-    HAL_NVIC_DisableIRQ(CAN_RX1_IRQn);
-#endif
+    HAL_NVIC_DisableIRQ(CAN_IRQ);
     if(fptr) {
         can_irq_set(fptr);
     }
     can_irq_init(&_can, &CAN::_irq_handler, (uint32_t) this);
-#if defined(TARGET_NUCLEO_F103RB)
-     HAL_NVIC_EnableIRQ(USB_LP_CAN1_RX0_IRQn);
-#elif defined(TARGET_NUCLEO_F303RE)
-    HAL_NVIC_EnableIRQ(CAN_RX1_IRQn);
-#endif
+    HAL_NVIC_EnableIRQ(CAN_IRQ);
 }
 
 /**
--- a/CAN.h	Wed Dec 23 10:37:01 2015 +0000
+++ b/CAN.h	Sun Dec 27 09:02:47 2015 +0000
@@ -25,8 +25,6 @@
 
 #if DEVICE_CAN
 
-#undef CAN
-
 #include "can_api.h"
 #include "can_helper.h"
 #include "FunctionPointer.h"
@@ -322,3 +320,4 @@
 
 
 
+
--- a/can_api.c	Wed Dec 23 10:37:01 2015 +0000
+++ b/can_api.c	Sun Dec 27 09:02:47 2015 +0000
@@ -25,15 +25,6 @@
  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.
   */
-#if defined(TARGET_NUCLEO_F103RB)
-    #include "stm32f1xx_hal.h"
-#elif defined(TARGET_NUCLEO_F302R8) || \
-    defined(TARGET_NUCLEO_F303RE) || \
-    defined(TARGET_NUCLEO_F303K8) || \
-    defined(TARGET_NUCLEO_F334R8) || \
-    defined(TARGET_DISCO_F334C8)
-    #include "stm32f3xx_hal.h"
-#endif
 #include "can_api.h"
 #include "can_helper.h"
 #include "pinmap.h"
@@ -329,3 +320,4 @@
 
 
 
+
--- a/can_api.h	Wed Dec 23 10:37:01 2015 +0000
+++ b/can_api.h	Sun Dec 27 09:02:47 2015 +0000
@@ -24,7 +24,19 @@
 #include "PeripheralNames.h"
 #include "can_helper.h"
 
-#define DEBUG 1
+//#define DEBUG 1
+
+#undef CAN
+
+#if defined(TARGET_NUCLEO_F103RB)
+    #include "stm32f1xx_hal_msp.h"
+#elif defined(TARGET_NUCLEO_F302R8) || \
+    defined(TARGET_NUCLEO_F303RE) || \
+    defined(TARGET_NUCLEO_F303K8) || \
+    defined(TARGET_NUCLEO_F334R8) || \
+    defined(TARGET_DISCO_F334C8)
+    #include "stm32f3xx_hal_msp.h"
+#endif
 
 #ifdef __cplusplus
 extern "C" {
@@ -85,3 +97,4 @@
 #endif
 
 #endif    // MBED_CAN_API_H
+
--- a/stm32f1xx_hal_msp.c	Wed Dec 23 10:37:01 2015 +0000
+++ b/stm32f1xx_hal_msp.c	Sun Dec 27 09:02:47 2015 +0000
@@ -39,7 +39,7 @@
   ******************************************************************************
   */
 #if defined(TARGET_NUCLEO_F103RB)
-#include "stm32f1xx_hal.h"
+
 #include "can_api.h"
 #include "pinmap.h"
 
@@ -63,7 +63,7 @@
     _rxPin = rxPin;
     _txPin = txPin;
 
-    _canHandle.Instance = ((CAN_TypeDef *) CAN1_BASE);
+    _canHandle.Instance = ((CAN_TypeDef*)CAN1_BASE);
     _canHandle.pTxMsg = &_canTxMsg;
     _canHandle.pRxMsg = &_canRxMsg;
 
--- a/stm32f1xx_hal_msp.h	Wed Dec 23 10:37:01 2015 +0000
+++ b/stm32f1xx_hal_msp.h	Sun Dec 27 09:02:47 2015 +0000
@@ -36,6 +36,8 @@
 #ifndef stm32f1xx_hal_H
 #define stm32f1xx_hal_H
 
+#define CAN_IRQ  USB_LP_CAN1_RX0_IRQn
+
 #include "pinmap.h"
 
 typedef struct can_s    can_t;
@@ -92,4 +94,4 @@
 
 #endif
 
-#endif
\ No newline at end of file
+#endif
--- a/stm32f3xx_hal_msp.c	Wed Dec 23 10:37:01 2015 +0000
+++ b/stm32f3xx_hal_msp.c	Sun Dec 27 09:02:47 2015 +0000
@@ -44,7 +44,6 @@
     defined(TARGET_NUCLEO_F334R8) || \
     defined(TARGET_DISCO_F334C8)
 
-#include "stm32f3xx_hal.h"
 #include "can_api.h"
 #include "pinmap.h"
 
@@ -68,7 +67,7 @@
     _rxPin = rxPin;
     _txPin = txPin;
 
-    _canHandle.Instance = ((CAN_TypeDef *) CAN_BASE);
+    _canHandle.Instance = ((CAN_TypeDef*)CAN_BASE);
     _canHandle.pTxMsg = &_canTxMsg;
     _canHandle.pRxMsg = &_canRxMsg;
 
@@ -111,14 +110,7 @@
         GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
         GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
         GPIO_InitStruct.Pull = GPIO_PULLUP;
-#if defined(TARGET_NUCLEO_F302R8) || \
-        defined(TARGET_NUCLEO_F303RE)       
-        GPIO_InitStruct.Alternate =  GPIO_AF7_CAN;
-#elif defined(TARGET_NUCLEO_F303K8) || \
-        defined(TARGET_NUCLEO_F334R8) || \
-        defined(TARGET_DISCO_F334C8)
         GPIO_InitStruct.Alternate =  GPIO_AF9_CAN;
-#endif
         HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
         
         /* CAN1 TX GPIO pin configuration */
@@ -126,18 +118,13 @@
         GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
         GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
         GPIO_InitStruct.Pull = GPIO_PULLUP;
-#if defined(TARGET_NUCLEO_F302R8) || \
-        defined(TARGET_NUCLEO_F303RE)       
-        GPIO_InitStruct.Alternate =  GPIO_AF7_CAN;
-#elif defined(TARGET_NUCLEO_F303K8) || \
-        defined(TARGET_NUCLEO_F334R8) || \
-        defined(TARGET_DISCO_F334C8)
         GPIO_InitStruct.Alternate =  GPIO_AF9_CAN;
-#endif
-
         HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
     }
-#if !defined(TARGET_NUCLEO_F303K8)
+#if defined(TARGET_NUCLEO_F302R8) || \
+    defined(TARGET_NUCLEO_F303RE) || \
+    defined(TARGET_NUCLEO_F334R8) || \
+    defined(TARGET_DISCO_F334C8)
     else
     if((_rxPin == PB_8) && (_txPin == PB_9)) {
         /* CAN1 Periph clock enable */
@@ -151,13 +138,7 @@
         GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
         GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
         GPIO_InitStruct.Pull = GPIO_PULLUP;
-#if defined(TARGET_NUCLEO_F302R8) || \
-        defined(TARGET_NUCLEO_F303RE)
-        GPIO_InitStruct.Alternate =  GPIO_AF7_CAN;
-#elif defined(TARGET_NUCLEO_F334R8) || \
-        defined(TARGET_DISCO_F334C8)
         GPIO_InitStruct.Alternate =  GPIO_AF9_CAN;
-#endif
         HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
         
         /* CAN1 TX GPIO pin configuration */
@@ -165,13 +146,7 @@
         GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
         GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
         GPIO_InitStruct.Pull = GPIO_PULLUP;
-#if defined(TARGET_NUCLEO_F302R8) || \
-        defined(TARGET_NUCLEO_F303RE)
-        GPIO_InitStruct.Alternate =  GPIO_AF7_CAN;
-#elif defined(TARGET_NUCLEO_F334R8) || \
-        defined(TARGET_DISCO_F334C8)
         GPIO_InitStruct.Alternate =  GPIO_AF9_CAN;
-#endif
         HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
     }
 #endif
--- a/stm32f3xx_hal_msp.h	Wed Dec 23 10:37:01 2015 +0000
+++ b/stm32f3xx_hal_msp.h	Sun Dec 27 09:02:47 2015 +0000
@@ -36,6 +36,8 @@
 #ifndef stm32f3xx_hal_H
 #define stm32f3xx_hal_H
 
+#define CAN_IRQ  CAN_RX1_IRQn
+
 #include "pinmap.h"
 
 typedef struct can_s    can_t;