Skip to content

Commit 7e0b4fe

Browse files
committed
Fix can_read() return value for STM32 boards
1 parent e7361eb commit 7e0b4fe

File tree

7 files changed

+42
-0
lines changed

7 files changed

+42
-0
lines changed

targets/TARGET_STM/TARGET_STM32F0/can_api.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,12 @@ int can_read(can_t *obj, CAN_Message *msg, int handle)
235235

236236
CAN_TypeDef *can = (CAN_TypeDef *)(obj->can);
237237

238+
// check FPM0 which holds the pending message count in FIFO 0
239+
// if no message is pending, return 0
240+
if ((can->RF0R & CAN_RF0R_FMP0) == 0) {
241+
return 0;
242+
}
243+
238244
/* Get the Id */
239245
msg->format = (CANFormat)((uint8_t)0x04 & can->sFIFOMailBox[handle].RIR);
240246
if (!msg->format) {

targets/TARGET_STM/TARGET_STM32F1/can_api.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,12 @@ int can_read(can_t *obj, CAN_Message *msg, int handle)
238238

239239
CAN_TypeDef *can = (CAN_TypeDef *)(obj->can);
240240

241+
// check FPM0 which holds the pending message count in FIFO 0
242+
// if no message is pending, return 0
243+
if ((can->RF0R & CAN_RF0R_FMP0) == 0) {
244+
return 0;
245+
}
246+
241247
/* Get the Id */
242248
msg->format = (CANFormat)((uint8_t)0x04 & can->sFIFOMailBox[handle].RIR);
243249
if (!msg->format) {

targets/TARGET_STM/TARGET_STM32F2/can_api.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,12 @@ int can_read(can_t *obj, CAN_Message *msg, int handle)
248248

249249
CAN_TypeDef *can = (CAN_TypeDef *)(obj->can);
250250

251+
// check FPM0 which holds the pending message count in FIFO 0
252+
// if no message is pending, return 0
253+
if ((can->RF0R & CAN_RF0R_FMP0) == 0) {
254+
return 0;
255+
}
256+
251257
/* Get the Id */
252258
msg->format = (CANFormat)((uint8_t)0x04 & can->sFIFOMailBox[handle].RIR);
253259
if (!msg->format) {

targets/TARGET_STM/TARGET_STM32F3/can_api.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,12 @@ int can_read(can_t *obj, CAN_Message *msg, int handle)
238238

239239
CAN_TypeDef *can = (CAN_TypeDef *)(obj->can);
240240

241+
// check FPM0 which holds the pending message count in FIFO 0
242+
// if no message is pending, return 0
243+
if ((can->RF0R & CAN_RF0R_FMP0) == 0) {
244+
return 0;
245+
}
246+
241247
/* Get the Id */
242248
msg->format = (CANFormat)((uint8_t)0x04 & can->sFIFOMailBox[handle].RIR);
243249
if (!msg->format) {

targets/TARGET_STM/TARGET_STM32F4/can_api.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,12 @@ int can_read(can_t *obj, CAN_Message *msg, int handle)
251251

252252
CAN_TypeDef *can = (CAN_TypeDef *)(obj->can);
253253

254+
// check FPM0 which holds the pending message count in FIFO 0
255+
// if no message is pending, return 0
256+
if ((can->RF0R & CAN_RF0R_FMP0) == 0) {
257+
return 0;
258+
}
259+
254260
/* Get the Id */
255261
msg->format = (CANFormat)((uint8_t)0x04 & can->sFIFOMailBox[handle].RIR);
256262
if (!msg->format) {

targets/TARGET_STM/TARGET_STM32F7/can_api.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,12 @@ int can_read(can_t *obj, CAN_Message *msg, int handle)
251251

252252
CAN_TypeDef *can = (CAN_TypeDef *)(obj->can);
253253

254+
// check FPM0 which holds the pending message count in FIFO 0
255+
// if no message is pending, return 0
256+
if ((can->RF0R & CAN_RF0R_FMP0) == 0) {
257+
return 0;
258+
}
259+
254260
/* Get the Id */
255261
msg->format = (CANFormat)((uint8_t)0x04 & can->sFIFOMailBox[handle].RIR);
256262
if (!msg->format) {

targets/TARGET_STM/TARGET_STM32L4/can_api.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,12 @@ int can_read(can_t *obj, CAN_Message *msg, int handle)
238238

239239
CAN_TypeDef *can = (CAN_TypeDef *)(obj->can);
240240

241+
// check FPM0 which holds the pending message count in FIFO 0
242+
// if no message is pending, return 0
243+
if ((can->RF0R & CAN_RF0R_FMP0) == 0) {
244+
return 0;
245+
}
246+
241247
/* Get the Id */
242248
msg->format = (CANFormat)((uint8_t)0x04 & can->sFIFOMailBox[handle].RIR);
243249
if (!msg->format) {

0 commit comments

Comments
 (0)