Skip to content

STM32 CAN API: correct format and type #3828

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 9, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 26 additions & 16 deletions targets/TARGET_STM/can_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,14 +261,14 @@ int can_read(can_t *obj, CAN_Message *msg, int handle)
}

/* Get the Id */
msg->format = (CANFormat)((uint8_t)0x04 & can->sFIFOMailBox[handle].RIR);
msg->format = (CANFormat)(((uint8_t)0x04 & can->sFIFOMailBox[handle].RIR) >> 2);
if (!msg->format) {
msg->id = (uint32_t)0x000007FF & (can->sFIFOMailBox[handle].RIR >> 21);
} else {
msg->id = (uint32_t)0x1FFFFFFF & (can->sFIFOMailBox[handle].RIR >> 3);
}

msg->type = (CANType)((uint8_t)0x02 & can->sFIFOMailBox[handle].RIR);
msg->type = (CANType)(((uint8_t)0x02 & can->sFIFOMailBox[handle].RIR) >> 1);
/* Get the DLC */
msg->len = (uint8_t)0x0F & can->sFIFOMailBox[handle].RDTR;
/* Get the FMI */
Expand Down Expand Up @@ -374,10 +374,10 @@ int can_mode(can_t *obj, CanMode mode)
return success;
}

int can_filter(can_t *obj, uint32_t id, uint32_t mask, CANFormat format, int32_t handle)
int can_filter(can_t *obj, uint32_t id, uint32_t mask, CANFormat format, int32_t handle)
{
int retval = 0;

// filter for CANAny format cannot be configured for STM32
if ((format == CANStandard) || (format == CANExtended)) {
CanHandle.Instance = (CAN_TypeDef *)(obj->can);
Expand All @@ -397,11 +397,11 @@ int can_filter(can_t *obj, uint32_t id, uint32_t mask, CANFormat format, int32_t
sFilterConfig.FilterMaskIdHigh = mask >> 13;
sFilterConfig.FilterMaskIdLow = (0x00FF & (mask << 3)) | (1 << 2);
}

sFilterConfig.FilterFIFOAssignment = 0;
sFilterConfig.FilterActivation = ENABLE;
sFilterConfig.BankNumber = 14 + handle;

HAL_CAN_ConfigFilter(&CanHandle, &sFilterConfig);
retval = handle;
}
Expand Down Expand Up @@ -460,37 +460,47 @@ static void can_irq(CANName name, int id)
}

#if defined(TARGET_STM32F0)
void CAN_IRQHandler(void) {
void CAN_IRQHandler(void)
{
can_irq(CAN_1, 0);
}
#elif defined(TARGET_STM32F3)
void CAN_RX0_IRQHandler(void) {
void CAN_RX0_IRQHandler(void)
{
can_irq(CAN_1, 0);
}
void CAN_TX_IRQHandler(void) {
void CAN_TX_IRQHandler(void)
{
can_irq(CAN_1, 0);
}
void CAN_SCE_IRQHandler(void) {
void CAN_SCE_IRQHandler(void)
{
can_irq(CAN_1, 0);
}
#else
void CAN1_RX0_IRQHandler(void) {
void CAN1_RX0_IRQHandler(void)
{
can_irq(CAN_1, 0);
}
void CAN1_TX_IRQHandler(void) {
void CAN1_TX_IRQHandler(void)
{
can_irq(CAN_1, 0);
}
void CAN1_SCE_IRQHandler(void) {
void CAN1_SCE_IRQHandler(void)
{
can_irq(CAN_1, 0);
}
#if defined(CAN2_BASE) && (CAN_NUM == 2)
void CAN2_RX0_IRQHandler(void) {
void CAN2_RX0_IRQHandler(void)
{
can_irq(CAN_2, 1);
}
void CAN2_TX_IRQHandler(void) {
void CAN2_TX_IRQHandler(void)
{
can_irq(CAN_2, 1);
}
void CAN2_SCE_IRQHandler(void) {
void CAN2_SCE_IRQHandler(void)
{
can_irq(CAN_2, 1);
}
#endif // defined(CAN2_BASE) && (CAN_NUM == 2)
Expand Down