Skip to content

Commit 6aa62c1

Browse files
authored
Merge pull request #3828 from jeromecoutant/PR_CAN_TYPE
STM32 CAN API: correct format and type
2 parents fd6fdd5 + 67a75d9 commit 6aa62c1

File tree

1 file changed

+26
-16
lines changed

1 file changed

+26
-16
lines changed

targets/TARGET_STM/can_api.c

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -262,14 +262,14 @@ int can_read(can_t *obj, CAN_Message *msg, int handle)
262262
}
263263

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

272-
msg->type = (CANType)((uint8_t)0x02 & can->sFIFOMailBox[handle].RIR);
272+
msg->type = (CANType)(((uint8_t)0x02 & can->sFIFOMailBox[handle].RIR) >> 1);
273273
/* Get the DLC */
274274
msg->len = (uint8_t)0x0F & can->sFIFOMailBox[handle].RDTR;
275275
/* Get the FMI */
@@ -375,10 +375,10 @@ int can_mode(can_t *obj, CanMode mode)
375375
return success;
376376
}
377377

378-
int can_filter(can_t *obj, uint32_t id, uint32_t mask, CANFormat format, int32_t handle)
378+
int can_filter(can_t *obj, uint32_t id, uint32_t mask, CANFormat format, int32_t handle)
379379
{
380380
int retval = 0;
381-
381+
382382
// filter for CANAny format cannot be configured for STM32
383383
if ((format == CANStandard) || (format == CANExtended)) {
384384
CanHandle.Instance = (CAN_TypeDef *)(obj->can);
@@ -398,11 +398,11 @@ int can_filter(can_t *obj, uint32_t id, uint32_t mask, CANFormat format, int32_t
398398
sFilterConfig.FilterMaskIdHigh = mask >> 13;
399399
sFilterConfig.FilterMaskIdLow = (0x00FF & (mask << 3)) | (1 << 2);
400400
}
401-
401+
402402
sFilterConfig.FilterFIFOAssignment = 0;
403403
sFilterConfig.FilterActivation = ENABLE;
404404
sFilterConfig.BankNumber = 14 + handle;
405-
405+
406406
HAL_CAN_ConfigFilter(&CanHandle, &sFilterConfig);
407407
retval = handle;
408408
}
@@ -461,37 +461,47 @@ static void can_irq(CANName name, int id)
461461
}
462462

463463
#if defined(TARGET_STM32F0)
464-
void CAN_IRQHandler(void) {
464+
void CAN_IRQHandler(void)
465+
{
465466
can_irq(CAN_1, 0);
466467
}
467468
#elif defined(TARGET_STM32F3)
468-
void CAN_RX0_IRQHandler(void) {
469+
void CAN_RX0_IRQHandler(void)
470+
{
469471
can_irq(CAN_1, 0);
470472
}
471-
void CAN_TX_IRQHandler(void) {
473+
void CAN_TX_IRQHandler(void)
474+
{
472475
can_irq(CAN_1, 0);
473476
}
474-
void CAN_SCE_IRQHandler(void) {
477+
void CAN_SCE_IRQHandler(void)
478+
{
475479
can_irq(CAN_1, 0);
476480
}
477481
#else
478-
void CAN1_RX0_IRQHandler(void) {
482+
void CAN1_RX0_IRQHandler(void)
483+
{
479484
can_irq(CAN_1, 0);
480485
}
481-
void CAN1_TX_IRQHandler(void) {
486+
void CAN1_TX_IRQHandler(void)
487+
{
482488
can_irq(CAN_1, 0);
483489
}
484-
void CAN1_SCE_IRQHandler(void) {
490+
void CAN1_SCE_IRQHandler(void)
491+
{
485492
can_irq(CAN_1, 0);
486493
}
487494
#if defined(CAN2_BASE) && (CAN_NUM == 2)
488-
void CAN2_RX0_IRQHandler(void) {
495+
void CAN2_RX0_IRQHandler(void)
496+
{
489497
can_irq(CAN_2, 1);
490498
}
491-
void CAN2_TX_IRQHandler(void) {
499+
void CAN2_TX_IRQHandler(void)
500+
{
492501
can_irq(CAN_2, 1);
493502
}
494-
void CAN2_SCE_IRQHandler(void) {
503+
void CAN2_SCE_IRQHandler(void)
504+
{
495505
can_irq(CAN_2, 1);
496506
}
497507
#endif // defined(CAN2_BASE) && (CAN_NUM == 2)

0 commit comments

Comments
 (0)