22#include "fdcan.h"
33#include <stdint.h>
44#include <string.h>
5+ #include <stdio.h>
56
67/* Initializes CAN */
7- HAL_StatusTypeDef can_init (can_t * can )
8+ HAL_StatusTypeDef can_init (can_t * can , FDCAN_HandleTypeDef * hcan )
89{
910
10- /* Init these guys to 0 */
11+ /* Init these guys */
1112 can -> standard_filter_index = 0 ;
1213 can -> extended_filter_index = 0 ;
14+ can -> hcan = hcan ;
1315
1416 /* Config interrupts */
1517 HAL_StatusTypeDef status = HAL_FDCAN_ConfigInterruptLines (can -> hcan , FDCAN_IT_RX_FIFO0_NEW_MESSAGE , FDCAN_INTERRUPT_LINE0 );
@@ -55,7 +57,7 @@ HAL_StatusTypeDef can_add_filter_standard(can_t *can, uint16_t can_ids[2])
5557 HAL_StatusTypeDef status = HAL_FDCAN_ConfigFilter (can -> hcan , & filter );
5658 if (status != HAL_OK )
5759 {
58- printf ("[fdcan.c/can_add_filter_standard()] ERROR: Failed to config standard FDCAN filter (Status: %d, Filter Index: %d ).\n" , status , filter .FilterIndex );
60+ printf ("[fdcan.c/can_add_filter_standard()] ERROR: Failed to config standard FDCAN filter (Status: %d, Filter Index: %ld ).\n" , status , filter .FilterIndex );
5961 return status ;
6062 }
6163
@@ -81,7 +83,7 @@ HAL_StatusTypeDef can_add_filter_extended(can_t *can, uint32_t can_ids[2])
8183 HAL_StatusTypeDef status = HAL_FDCAN_ConfigFilter (can -> hcan , & filter );
8284 if (status != HAL_OK )
8385 {
84- printf ("[fdcan.c/can_add_filter_extended()] ERROR: Failed to config extended FDCAN filter (Status: %d, Filter Index: %d ). \n" , status , filter .FilterIndex );
86+ printf ("[fdcan.c/can_add_filter_extended()] ERROR: Failed to config extended FDCAN filter (Status: %d, Filter Index: %ld ). \n" , status , filter .FilterIndex );
8587 return status ;
8688 }
8789
@@ -96,7 +98,7 @@ HAL_StatusTypeDef can_send_msg(can_t *can, can_msg_t *msg)
9698 /* Validate message length */
9799 if (msg -> len > 8 )
98100 {
99- printf ("[fdcan.c/can_send_msg()] ERROR: FDCAN message length exceeds 8 bytes (Length: %d, Message ID: %d ).\n" , msg -> len , msg -> id );
101+ printf ("[fdcan.c/can_send_msg()] ERROR: FDCAN message length exceeds 8 bytes (Length: %d, Message ID: %ld ).\n" , msg -> len , msg -> id );
100102 return HAL_ERROR ;
101103 }
102104
@@ -119,7 +121,7 @@ HAL_StatusTypeDef can_send_msg(can_t *can, can_msg_t *msg)
119121
120122 HAL_StatusTypeDef status = HAL_FDCAN_AddMessageToTxFifoQ (can -> hcan , & tx_header , msg -> data );
121123 if (status != HAL_OK ) {
122- printf ("[fdcan.c/can_send_msg()] ERROR: HAL_FDCAN_AddMessageToTxFifoQ() failed (Status: %d, Message ID: %d ).\n" , status , msg -> id );
124+ printf ("[fdcan.c/can_send_msg()] ERROR: HAL_FDCAN_AddMessageToTxFifoQ() failed (Status: %d, Message ID: %ld ).\n" , status , msg -> id );
123125 return status ;
124126 }
125127
0 commit comments