Skip to content

Commit 274d8aa

Browse files
committed
The default FIFO for can by hardware is FIFO0 as set by the CAN STM API in configuration. Hence the read api is modified to access FIFO0 only
1 parent 14e5d30 commit 274d8aa

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

targets/TARGET_STM/can_api.c

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,8 @@ void can_irq_set(can_t *obj, CanIrqType type, uint32_t enable)
646646
#include <string.h>
647647
#include <inttypes.h>
648648

649+
#define DEFAULT_RXFIFO 0 // default rx fifo for can by hardware is FIFO0
650+
649651
static uint32_t can_irq_ids[CAN_NUM] = {0};
650652
static can_irq_handler irq_handler;
651653

@@ -956,8 +958,10 @@ int can_write(can_t *obj, CAN_Message msg, int cc)
956958

957959
int can_read(can_t *obj, CAN_Message *msg, int handle)
958960
{
961+
959962
//handle is the FIFO number
960963

964+
int rxfifo_default = DEFAULT_RXFIFO; //FIFO selection cannot be controlled by software for STM32, default FIFO is 0
961965
CAN_TypeDef *can = obj->CanHandle.Instance;
962966

963967
// check FPM0 which holds the pending message count in FIFO 0
@@ -967,36 +971,30 @@ int can_read(can_t *obj, CAN_Message *msg, int handle)
967971
}
968972

969973
/* Get the Id */
970-
msg->format = (CANFormat)(((uint8_t)0x04 & can->sFIFOMailBox[handle].RIR) >> 2);
974+
msg->format = (CANFormat)(((uint8_t)0x04 & can->sFIFOMailBox[rxfifo_default].RIR) >> 2);
971975
if (!msg->format) {
972-
msg->id = (uint32_t)0x000007FF & (can->sFIFOMailBox[handle].RIR >> 21);
976+
msg->id = (uint32_t)0x000007FF & (can->sFIFOMailBox[rxfifo_default].RIR >> 21);
973977
} else {
974-
msg->id = (uint32_t)0x1FFFFFFF & (can->sFIFOMailBox[handle].RIR >> 3);
978+
msg->id = (uint32_t)0x1FFFFFFF & (can->sFIFOMailBox[rxfifo_default].RIR >> 3);
975979
}
976980

977-
msg->type = (CANType)(((uint8_t)0x02 & can->sFIFOMailBox[handle].RIR) >> 1);
981+
msg->type = (CANType)(((uint8_t)0x02 & can->sFIFOMailBox[rxfifo_default].RIR) >> 1);
978982
/* Get the DLC */
979-
msg->len = (uint8_t)0x0F & can->sFIFOMailBox[handle].RDTR;
983+
msg->len = (uint8_t)0x0F & can->sFIFOMailBox[rxfifo_default].RDTR;
980984
/* Get the FMI */
981-
// msg->FMI = (uint8_t)0xFF & (can->sFIFOMailBox[handle].RDTR >> 8);
985+
// msg->FMI = (uint8_t)0xFF & (can->sFIFOMailBox[rxfifo_default].RDTR >> 8);
982986
/* Get the data field */
983-
msg->data[0] = (uint8_t)0xFF & can->sFIFOMailBox[handle].RDLR;
984-
msg->data[1] = (uint8_t)0xFF & (can->sFIFOMailBox[handle].RDLR >> 8);
985-
msg->data[2] = (uint8_t)0xFF & (can->sFIFOMailBox[handle].RDLR >> 16);
986-
msg->data[3] = (uint8_t)0xFF & (can->sFIFOMailBox[handle].RDLR >> 24);
987-
msg->data[4] = (uint8_t)0xFF & can->sFIFOMailBox[handle].RDHR;
988-
msg->data[5] = (uint8_t)0xFF & (can->sFIFOMailBox[handle].RDHR >> 8);
989-
msg->data[6] = (uint8_t)0xFF & (can->sFIFOMailBox[handle].RDHR >> 16);
990-
msg->data[7] = (uint8_t)0xFF & (can->sFIFOMailBox[handle].RDHR >> 24);
987+
msg->data[0] = (uint8_t)0xFF & can->sFIFOMailBox[rxfifo_default].RDLR;
988+
msg->data[1] = (uint8_t)0xFF & (can->sFIFOMailBox[rxfifo_default].RDLR >> 8);
989+
msg->data[2] = (uint8_t)0xFF & (can->sFIFOMailBox[rxfifo_default].RDLR >> 16);
990+
msg->data[3] = (uint8_t)0xFF & (can->sFIFOMailBox[rxfifo_default].RDLR >> 24);
991+
msg->data[4] = (uint8_t)0xFF & can->sFIFOMailBox[rxfifo_default].RDHR;
992+
msg->data[5] = (uint8_t)0xFF & (can->sFIFOMailBox[rxfifo_default].RDHR >> 8);
993+
msg->data[6] = (uint8_t)0xFF & (can->sFIFOMailBox[rxfifo_default].RDHR >> 16);
994+
msg->data[7] = (uint8_t)0xFF & (can->sFIFOMailBox[rxfifo_default].RDHR >> 24);
991995

992996
/* Release the FIFO */
993-
if (handle == CAN_FIFO0) {
994-
/* Release FIFO0 */
995-
can->RF0R |= CAN_RF0R_RFOM0;
996-
} else { /* FIFONumber == CAN_FIFO1 */
997-
/* Release FIFO1 */
998-
can->RF1R |= CAN_RF1R_RFOM1;
999-
}
997+
can->RF0R |= CAN_RF0R_RFOM0;
1000998

1001999
return 1;
10021000
}

0 commit comments

Comments
 (0)