Skip to content

Commit

Permalink
fixed error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Dylan Donahue committed Dec 7, 2023
1 parent 5109618 commit ccefb31
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
4 changes: 2 additions & 2 deletions platforms/stm32f405/include/can.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ typedef struct{
uint8_t size;
} can_msg_t;

void can_init(can_t *can);
void can_send_msg(can_t *can, can_msg_t *msg);
HAL_StatusTypeDef can_init(can_t *can);
HAL_StatusTypeDef can_send_msg(can_t *can, can_msg_t *msg);



Expand Down
16 changes: 12 additions & 4 deletions platforms/stm32f405/src/can.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "can.h"

void can_init(can_t *can)
HAL_StatusTypeDef can_init(can_t *can)
{
/* set up filter */
uint16_t high_id = can->id_list[0];
Expand Down Expand Up @@ -37,8 +37,7 @@ void can_init(can_t *can)

if (HAL_CAN_ConfigFilter(&hcan, &sFilterConfig) != HAL_OK)
{
// Filter Configuration Error
Error_Handler();
return HAL_ERROR;
}

/* set up interrupt & activate CAN */
Expand All @@ -47,9 +46,11 @@ void can_init(can_t *can)
// Override the default callback for CAN_IT_RX_FIFO0_MSG_PENDING
HAL_CAN_RegisterCallback(can->hcan, HAL_CAN_RX_FIFO0_MSG_PENDING_CB_ID, can->can_callback);
HAL_CAN_ActivateNotification(can->hcan, CAN_IT_RX_FIFO0_MSG_PENDING);

return HAL_OK;
}

void can_send_msg(can_t *can, can_msg_t *msg)
HAL_StatusTypeDef can_send_msg(can_t *can, can_msg_t *msg)
{
CAN_TxHeaderTypeDef tx_header;
tx_header.StdId = msg->id;
Expand All @@ -61,4 +62,11 @@ void can_send_msg(can_t *can, can_msg_t *msg)

uint32_t tx_mailbox;
HAL_CAN_AddTxMessage(can->hcan, &tx_header, msg->data, &tx_mailbox);

if (HAL_CAN_GetTxMailboxesFreeLevel(can->hcan) == 0)
{
return HAL_ERROR;
}

return HAL_OK;
}

0 comments on commit ccefb31

Please sign in to comment.