mbed library sources, include can_api for nucleo-f091rc

Dependents:   CanNucleoF0_example

Fork of mbed-src by mbed official

Files at this revision

API Documentation at this revision

Comitter:
ptpaterson
Date:
Mon Dec 14 16:23:14 2015 +0000
Parent:
637:909ea77f86f8
Child:
639:15f853e90e6b
Commit message:
don't use CAN definition

Changed in this revision

targets/hal/TARGET_STM/TARGET_STM32F0/can_api.c Show annotated file Show diff for this revision Revisions of this file
--- a/targets/hal/TARGET_STM/TARGET_STM32F0/can_api.c	Mon Dec 14 15:51:51 2015 +0000
+++ b/targets/hal/TARGET_STM/TARGET_STM32F0/can_api.c	Mon Dec 14 16:23:14 2015 +0000
@@ -95,9 +95,6 @@
           PinName rd,
           PinName td)
 {
-    printf ("function: can_init()\r\n");
-
-    
     /* file scope so that they can be referenced in the MSP functions */
     pinRd = rd;
     pinTd = td;
@@ -105,7 +102,7 @@
     /* initialize the static data */
     static CAN_HandleTypeDef hcan;
     obj->hcan = &hcan;
-    obj->hcan->Instance = CAN;
+    obj->hcan->Instance = ((CAN_TypeDef *) CAN_BASE);
     
     static CanTxMsgTypeDef txMessage;
     static CanRxMsgTypeDef rxMessage; 
@@ -130,15 +127,14 @@
     obj->hcan->Init.BS1 = CAN_BS1_11TQ;  // sample point at (1 + 11) / 16 * 100 = 75%
     obj->hcan->Init.BS2 = CAN_BS2_4TQ;
  
-    int result = HAL_CAN_Init(obj->hcan);
+    int result = HAL_CAN_Init (obj->hcan);
     if (result != HAL_OK)
     {
-        printf("could not initialize the can device : %i\r\n", result);
-        printf("MSR value = %i\r\n",  (int) obj->hcan->Instance->MSR);
+        // TODO: handle issues   
     }
     
     /* minimum filter required to make this work */
-    can_filter(obj, 0, 0, CANAny, 0);
+    can_filter (obj, 0, 0, CANAny, 0);
     
     return;            
 }
@@ -246,8 +242,9 @@
     irq_handler = handler;
     can_irq_id = id;
     
-    if (HAL_CAN_Receive_IT (obj->hcan, CAN_FIFO0) != HAL_OK) {
-        printf("CAN reception initialization error\r\n");
+    if (HAL_CAN_Receive_IT (obj->hcan, CAN_FIFO0) != HAL_OK) 
+    {
+        // TODO: handle issues    
     }
 }
 
@@ -426,7 +423,11 @@
  * @param
  * @retval
  */
-void          can_reset    (can_t *obj){}
+void
+can_reset (can_t *obj)
+{
+    __HAL_CAN_RESET_HANDLE_STATE(obj->hcan);
+}
 
 /**
  * @brief
@@ -434,7 +435,11 @@
  * @param
  * @retval
  */
-unsigned char can_rderror  (can_t *obj){ return 1; }
+unsigned char 
+can_rderror (can_t *obj)
+{
+    return HAL_CAN_GetError(obj->hcan);
+}
 
 /**
  * @brief
@@ -442,7 +447,11 @@
  * @param
  * @retval
  */
-unsigned char can_tderror  (can_t *obj){ return 1; }
+unsigned char
+can_tderror (can_t *obj)
+{
+    return HAL_CAN_GetError(obj->hcan);
+}
 
 /**
  * @brief
@@ -450,7 +459,12 @@
  * @param
  * @retval
  */
- void          can_monitor  (can_t *obj, int silent){}
+ void
+ can_monitor (can_t *obj, 
+              int silent)
+{
+    // TODO: implement
+}
 
 /*=============================================================================
  * HAL_MSP
@@ -465,9 +479,7 @@
 void 
 HAL_CAN_MspInit(CAN_HandleTypeDef* hcan) 
 {
-
-    printf ("function: HAL_CAN_MspInit()\r\n");
-
+    /* derived from STM32CubeMX */
     
     GPIO_InitTypeDef    GPIO_InitStruct;
     if (hcan->Instance == CAN)
@@ -529,10 +541,8 @@
 void 
 HAL_CAN_MspDeInit (CAN_HandleTypeDef* hcan)
 {
-
-    printf ("function: HAL_CAN_MspDeInit()\r\n");
-
- 
+    /* derived from STM32CubeMX */
+    
     if (hcan->Instance == CAN)
     {
         /* Peripheral clock disable */
@@ -549,7 +559,6 @@
         }
         else if ((pinRd == PB_8) && (pinTd == PB_9))
         {
-     
             /**CAN GPIO Configuration    
             PB8     ------> CAN_RX
             PB9     ------> CAN_TX 
@@ -572,7 +581,7 @@
 void HAL_CAN_RxCpltCallback(CAN_HandleTypeDef* hcan) {
     // if(HAL_CAN_Receive_IT(hcan, CAN_FIFO0) == HAL_OK) {
     //     if(rxCompleteCallback != NULL)
-    //         rxCompleteCallback();
+    //         // call user callbacks
     // }
     // else {
     //     error_handler(error);
@@ -587,7 +596,7 @@
     // had already locked the handle when the receive interrupt occurred - so we do what
     // HAL_CAN_Receive_IT() would do
  
-    /* Call user routines */
+    /* Call user callbacks */
     irq_handler (can_irq_id, IRQ_RX);
     
     /* perform HAL_CAN_Receive_IT() fix */