Skip to content

Commit 67a75d9

Browse files
committed
STM32 CAN API: correct format and type
astyle done
1 parent b0a1fd9 commit 67a75d9

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
@@ -261,14 +261,14 @@ int can_read(can_t *obj, CAN_Message *msg, int handle)
261261
}
262262

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

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

377-
int can_filter(can_t *obj, uint32_t id, uint32_t mask, CANFormat format, int32_t handle)
377+
int can_filter(can_t *obj, uint32_t id, uint32_t mask, CANFormat format, int32_t handle)
378378
{
379379
int retval = 0;
380-
380+
381381
// filter for CANAny format cannot be configured for STM32
382382
if ((format == CANStandard) || (format == CANExtended)) {
383383
CanHandle.Instance = (CAN_TypeDef *)(obj->can);
@@ -397,11 +397,11 @@ int can_filter(can_t *obj, uint32_t id, uint32_t mask, CANFormat format, int32_t
397397
sFilterConfig.FilterMaskIdHigh = mask >> 13;
398398
sFilterConfig.FilterMaskIdLow = (0x00FF & (mask << 3)) | (1 << 2);
399399
}
400-
400+
401401
sFilterConfig.FilterFIFOAssignment = 0;
402402
sFilterConfig.FilterActivation = ENABLE;
403403
sFilterConfig.BankNumber = 14 + handle;
404-
404+
405405
HAL_CAN_ConfigFilter(&CanHandle, &sFilterConfig);
406406
retval = handle;
407407
}
@@ -460,37 +460,47 @@ static void can_irq(CANName name, int id)
460460
}
461461

462462
#if defined(TARGET_STM32F0)
463-
void CAN_IRQHandler(void) {
463+
void CAN_IRQHandler(void)
464+
{
464465
can_irq(CAN_1, 0);
465466
}
466467
#elif defined(TARGET_STM32F3)
467-
void CAN_RX0_IRQHandler(void) {
468+
void CAN_RX0_IRQHandler(void)
469+
{
468470
can_irq(CAN_1, 0);
469471
}
470-
void CAN_TX_IRQHandler(void) {
472+
void CAN_TX_IRQHandler(void)
473+
{
471474
can_irq(CAN_1, 0);
472475
}
473-
void CAN_SCE_IRQHandler(void) {
476+
void CAN_SCE_IRQHandler(void)
477+
{
474478
can_irq(CAN_1, 0);
475479
}
476480
#else
477-
void CAN1_RX0_IRQHandler(void) {
481+
void CAN1_RX0_IRQHandler(void)
482+
{
478483
can_irq(CAN_1, 0);
479484
}
480-
void CAN1_TX_IRQHandler(void) {
485+
void CAN1_TX_IRQHandler(void)
486+
{
481487
can_irq(CAN_1, 0);
482488
}
483-
void CAN1_SCE_IRQHandler(void) {
489+
void CAN1_SCE_IRQHandler(void)
490+
{
484491
can_irq(CAN_1, 0);
485492
}
486493
#if defined(CAN2_BASE) && (CAN_NUM == 2)
487-
void CAN2_RX0_IRQHandler(void) {
494+
void CAN2_RX0_IRQHandler(void)
495+
{
488496
can_irq(CAN_2, 1);
489497
}
490-
void CAN2_TX_IRQHandler(void) {
498+
void CAN2_TX_IRQHandler(void)
499+
{
491500
can_irq(CAN_2, 1);
492501
}
493-
void CAN2_SCE_IRQHandler(void) {
502+
void CAN2_SCE_IRQHandler(void)
503+
{
494504
can_irq(CAN_2, 1);
495505
}
496506
#endif // defined(CAN2_BASE) && (CAN_NUM == 2)

0 commit comments

Comments
 (0)