Skip to content

Commit 8d0c5ed

Browse files
added can support
1 parent 46e8b78 commit 8d0c5ed

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

threadX/inc/u_can.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#ifndef _U_CAN_H
2+
#define _U_CAN_H
3+
4+
#include "stm32h5xx.h"
5+
#include <stdint.h>
6+
#include "fdcan.h"
7+
8+
uint8_t can_filter_init(FDCAN_HandleTypeDef *hcan, can_t *can, uint16_t standard_ids[2], uint32_t extended_ids[2]);
9+
10+
#endif

threadX/src/u_can.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include "u_can.h"
2+
#include "u_debug.h"
3+
#include "fdcan.h"
4+
5+
uint8_t can_filter_init(FDCAN_HandleTypeDef *hcan, can_t *can, uint16_t standard_ids[2], uint32_t extended_ids[2]) {
6+
/* Init CAN interface */
7+
HAL_StatusTypeDef status = can_init(can, hcan);
8+
if(status != HAL_OK) {
9+
DEBUG_PRINTLN("Failed to execute can_init() when initializing can1 (Status: %d/%s).", status, hal_status_toString(status));
10+
return U_ERROR;
11+
}
12+
13+
/* Add filters for standard IDs */
14+
status = can_add_filter_standard(can, standard_ids);
15+
if(status != HAL_OK) {
16+
DEBUG_PRINTLN("Failed to add standard filter to can1 (Status: %d/%s, ID1: %d, ID2: %d).", status, hal_status_toString(status), standard_ids[0], standard_ids[1]);
17+
return U_ERROR;
18+
}
19+
20+
/* Add fitlers for extended IDs */
21+
status = can_add_filter_extended(can, extended_ids);
22+
if (status != HAL_OK) {
23+
DEBUG_PRINTLN("Failed to add extended filter to can1 (Status: %d/%s, ID1: %ld, ID2: %ld).", status, hal_status_toString(status), extended_ids[0], extended_ids[1]);
24+
return U_ERROR;
25+
}
26+
27+
DEBUG_PRINTLN("Ran can1_init().");
28+
29+
return U_SUCCESS;
30+
}

0 commit comments

Comments
 (0)