Skip to content

Commit

Permalink
drivers: can: stm32: fix bus-speed
Browse files Browse the repository at this point in the history
Set the prescaler in register BTR according to the configured bitrate in DTS.
This bug appeared in commit 8b6c1bd

Signed-off-by: Julien D'Ascenzio <[email protected]>
  • Loading branch information
jdascenzio authored and nashif committed Jan 10, 2021
1 parent 71b3ce2 commit f1963dd
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions drivers/can/can_stm32.c
Original file line number Diff line number Diff line change
Expand Up @@ -374,9 +374,11 @@ int can_stm32_set_timing(const struct device *dev,
can->BTR &= ~(CAN_BTR_BRP_Msk | CAN_BTR_TS1_Msk |
CAN_BTR_TS2_Msk | CAN_BTR_SJW_Msk);

can->BTR |= (((timing->phase_seg1 - 1) & 0x0F) << CAN_BTR_TS1_Pos) |
(((timing->phase_seg2 - 1) & 0x07) << CAN_BTR_TS2_Pos) |
(((timing->sjw - 1) & 0x07) << CAN_BTR_SJW_Pos);
can->BTR |=
(((timing->phase_seg1 - 1) << CAN_BTR_TS1_Pos) & CAN_BTR_TS1_Msk) |
(((timing->phase_seg2 - 1) << CAN_BTR_TS2_Pos) & CAN_BTR_TS2_Msk) |
(((timing->sjw - 1) << CAN_BTR_SJW_Pos) & CAN_BTR_SJW_Msk) |
(((timing->prescaler - 1) << CAN_BTR_BRP_Pos) & CAN_BTR_BRP_Msk);

ret = can_leave_init_mode(can);
if (ret) {
Expand Down

0 comments on commit f1963dd

Please sign in to comment.