From 189747f8fde9eb3d02508a9098f295a764df2b04 Mon Sep 17 00:00:00 2001 From: Adrien Chardon Date: Wed, 21 Dec 2016 15:02:39 +0100 Subject: [PATCH] Fix can_read() return value for STM32 boards --- targets/TARGET_STM/TARGET_STM32F0/can_api.c | 6 ++++++ targets/TARGET_STM/TARGET_STM32F1/can_api.c | 6 ++++++ targets/TARGET_STM/TARGET_STM32F2/can_api.c | 6 ++++++ targets/TARGET_STM/TARGET_STM32F3/can_api.c | 6 ++++++ targets/TARGET_STM/TARGET_STM32F4/can_api.c | 6 ++++++ targets/TARGET_STM/TARGET_STM32F7/can_api.c | 6 ++++++ targets/TARGET_STM/TARGET_STM32L4/can_api.c | 6 ++++++ 7 files changed, 42 insertions(+) diff --git a/targets/TARGET_STM/TARGET_STM32F0/can_api.c b/targets/TARGET_STM/TARGET_STM32F0/can_api.c index d6483cede1..d8938fca7d 100644 --- a/targets/TARGET_STM/TARGET_STM32F0/can_api.c +++ b/targets/TARGET_STM/TARGET_STM32F0/can_api.c @@ -235,6 +235,12 @@ int can_read(can_t *obj, CAN_Message *msg, int handle) CAN_TypeDef *can = (CAN_TypeDef *)(obj->can); + // check FPM0 which holds the pending message count in FIFO 0 + // if no message is pending, return 0 + if ((can->RF0R & CAN_RF0R_FMP0) == 0) { + return 0; + } + /* Get the Id */ msg->format = (CANFormat)((uint8_t)0x04 & can->sFIFOMailBox[handle].RIR); if (!msg->format) { diff --git a/targets/TARGET_STM/TARGET_STM32F1/can_api.c b/targets/TARGET_STM/TARGET_STM32F1/can_api.c index 6f3f265a5c..2b16c47953 100644 --- a/targets/TARGET_STM/TARGET_STM32F1/can_api.c +++ b/targets/TARGET_STM/TARGET_STM32F1/can_api.c @@ -238,6 +238,12 @@ int can_read(can_t *obj, CAN_Message *msg, int handle) CAN_TypeDef *can = (CAN_TypeDef *)(obj->can); + // check FPM0 which holds the pending message count in FIFO 0 + // if no message is pending, return 0 + if ((can->RF0R & CAN_RF0R_FMP0) == 0) { + return 0; + } + /* Get the Id */ msg->format = (CANFormat)((uint8_t)0x04 & can->sFIFOMailBox[handle].RIR); if (!msg->format) { diff --git a/targets/TARGET_STM/TARGET_STM32F2/can_api.c b/targets/TARGET_STM/TARGET_STM32F2/can_api.c index 1a1aeec10b..e1097e2d2b 100644 --- a/targets/TARGET_STM/TARGET_STM32F2/can_api.c +++ b/targets/TARGET_STM/TARGET_STM32F2/can_api.c @@ -248,6 +248,12 @@ int can_read(can_t *obj, CAN_Message *msg, int handle) CAN_TypeDef *can = (CAN_TypeDef *)(obj->can); + // check FPM0 which holds the pending message count in FIFO 0 + // if no message is pending, return 0 + if ((can->RF0R & CAN_RF0R_FMP0) == 0) { + return 0; + } + /* Get the Id */ msg->format = (CANFormat)((uint8_t)0x04 & can->sFIFOMailBox[handle].RIR); if (!msg->format) { diff --git a/targets/TARGET_STM/TARGET_STM32F3/can_api.c b/targets/TARGET_STM/TARGET_STM32F3/can_api.c index a0416a61c4..7bccf28639 100644 --- a/targets/TARGET_STM/TARGET_STM32F3/can_api.c +++ b/targets/TARGET_STM/TARGET_STM32F3/can_api.c @@ -238,6 +238,12 @@ int can_read(can_t *obj, CAN_Message *msg, int handle) CAN_TypeDef *can = (CAN_TypeDef *)(obj->can); + // check FPM0 which holds the pending message count in FIFO 0 + // if no message is pending, return 0 + if ((can->RF0R & CAN_RF0R_FMP0) == 0) { + return 0; + } + /* Get the Id */ msg->format = (CANFormat)((uint8_t)0x04 & can->sFIFOMailBox[handle].RIR); if (!msg->format) { diff --git a/targets/TARGET_STM/TARGET_STM32F4/can_api.c b/targets/TARGET_STM/TARGET_STM32F4/can_api.c index 446b4fdfbb..1bad14ac5d 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/can_api.c +++ b/targets/TARGET_STM/TARGET_STM32F4/can_api.c @@ -251,6 +251,12 @@ int can_read(can_t *obj, CAN_Message *msg, int handle) CAN_TypeDef *can = (CAN_TypeDef *)(obj->can); + // check FPM0 which holds the pending message count in FIFO 0 + // if no message is pending, return 0 + if ((can->RF0R & CAN_RF0R_FMP0) == 0) { + return 0; + } + /* Get the Id */ msg->format = (CANFormat)((uint8_t)0x04 & can->sFIFOMailBox[handle].RIR); if (!msg->format) { diff --git a/targets/TARGET_STM/TARGET_STM32F7/can_api.c b/targets/TARGET_STM/TARGET_STM32F7/can_api.c index 3e716fa7b9..7c4cac4010 100644 --- a/targets/TARGET_STM/TARGET_STM32F7/can_api.c +++ b/targets/TARGET_STM/TARGET_STM32F7/can_api.c @@ -251,6 +251,12 @@ int can_read(can_t *obj, CAN_Message *msg, int handle) CAN_TypeDef *can = (CAN_TypeDef *)(obj->can); + // check FPM0 which holds the pending message count in FIFO 0 + // if no message is pending, return 0 + if ((can->RF0R & CAN_RF0R_FMP0) == 0) { + return 0; + } + /* Get the Id */ msg->format = (CANFormat)((uint8_t)0x04 & can->sFIFOMailBox[handle].RIR); if (!msg->format) { diff --git a/targets/TARGET_STM/TARGET_STM32L4/can_api.c b/targets/TARGET_STM/TARGET_STM32L4/can_api.c index e5cb5db98b..363cfe245f 100644 --- a/targets/TARGET_STM/TARGET_STM32L4/can_api.c +++ b/targets/TARGET_STM/TARGET_STM32L4/can_api.c @@ -238,6 +238,12 @@ int can_read(can_t *obj, CAN_Message *msg, int handle) CAN_TypeDef *can = (CAN_TypeDef *)(obj->can); + // check FPM0 which holds the pending message count in FIFO 0 + // if no message is pending, return 0 + if ((can->RF0R & CAN_RF0R_FMP0) == 0) { + return 0; + } + /* Get the Id */ msg->format = (CANFormat)((uint8_t)0x04 & can->sFIFOMailBox[handle].RIR); if (!msg->format) {