Skip to content

Commit e6894ad

Browse files
Vitaliy Livnovdanieldegrasse
authored andcommitted
drivers: can: sam0: fix clock configuration for SAM0 series
Fixed a bug where unconfigured clocks were connected to the can interface in the device tree for SAM0, causing the interface to work incorrectly. Fixed by adding the correct index when calling GENCTRL. Also, the default divider has been reduced to 6 to allow setting the bitrate to 500 kbps. Tested on a canopennode sample on a board with an ATSAMC21E18A microcontroller. Signed-off-by: Vitaliy Livnov <vitaliy.livnov@devkit.agency>
1 parent e1248ef commit e6894ad

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

drivers/can/can_sam0.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,20 +113,22 @@ static int can_sam0_get_core_clock(const struct device *dev, uint32_t *rate)
113113

114114
static void can_sam0_clock_enable(const struct can_sam0_config *cfg)
115115
{
116+
uint8_t gen_index = cfg->gclk_gen;
117+
116118
*cfg->mclk |= cfg->mclk_mask;
117119

118120
GCLK->PCHCTRL[cfg->gclk_id].reg = GCLK_PCHCTRL_CHEN
119-
| GCLK_PCHCTRL_GEN(cfg->gclk_gen);
121+
| GCLK_PCHCTRL_GEN(gen_index);
120122

121-
/* Enable the GLCK7 with DIV*/
123+
/* Enable the GLCK<gen_index> with DIV*/
122124
#if defined(CONFIG_SOC_SERIES_SAME51) || defined(CONFIG_SOC_SERIES_SAME54)
123125
/*DFFL has to be used as clock source for the ATSAME51/54 family of SoCs*/
124-
GCLK->GENCTRL[7].reg = GCLK_GENCTRL_SRC(GCLK_GENCTRL_SRC_DFLL)
126+
GCLK->GENCTRL[gen_index].reg = GCLK_GENCTRL_SRC(GCLK_GENCTRL_SRC_DFLL)
125127
| GCLK_GENCTRL_DIV(cfg->divider)
126128
| GCLK_GENCTRL_GENEN;
127129
#elif defined(CONFIG_SOC_SERIES_SAMC21)
128130
/*OSC48M has to be used as clock source for the ATSAMC21 family of SoCs*/
129-
GCLK->GENCTRL[7].reg = GCLK_GENCTRL_SRC(GCLK_GENCTRL_SRC_OSC48M)
131+
GCLK->GENCTRL[gen_index].reg = GCLK_GENCTRL_SRC(GCLK_GENCTRL_SRC_OSC48M)
130132
| GCLK_GENCTRL_DIV(cfg->divider)
131133
| GCLK_GENCTRL_GENEN;
132134
#endif

dts/arm/atmel/samc21.dtsi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@
6161
interrupt-names = "int0";
6262
clocks = <&gclk 26>, <&mclk 0x10 8>;
6363
clock-names = "GCLK", "MCLK";
64-
atmel,assigned-clocks = <&gclk 0>;
64+
atmel,assigned-clocks = <&gclk 7>;
6565
atmel,assigned-clock-names = "GCLK";
6666
status = "disabled";
6767

6868
bosch,mram-cfg = <0x0 28 8 3 3 0 1 1>;
69-
divider = <12>;
69+
divider = <1>;
7070
};
7171

7272
can1: can@42002000 {
@@ -76,12 +76,12 @@
7676
interrupt-names = "int0";
7777
clocks = <&gclk 27>, <&mclk 0x10 9>;
7878
clock-names = "GCLK", "MCLK";
79-
atmel,assigned-clocks = <&gclk 0>;
79+
atmel,assigned-clocks = <&gclk 7>;
8080
atmel,assigned-clock-names = "GCLK";
8181
status = "disabled";
8282

8383
bosch,mram-cfg = <0x0 28 8 3 3 0 1 1>;
84-
divider = <12>;
84+
divider = <1>;
8585
};
8686
};
8787
};

dts/arm/atmel/same5x.dtsi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@
3737
interrupt-names = "int0", "int1";
3838
clocks = <&gclk 27>, <&mclk 0x10 17>;
3939
clock-names = "GCLK", "MCLK";
40-
atmel,assigned-clocks = <&gclk 0>;
40+
atmel,assigned-clocks = <&gclk 7>;
4141
atmel,assigned-clock-names = "GCLK";
4242
status = "disabled";
4343

4444
bosch,mram-cfg = <0x0 128 64 64 64 64 32 32>;
45-
divider = <12>;
45+
divider = <1>;
4646
};
4747

4848
can1: can@42000400 {
@@ -52,12 +52,12 @@
5252
interrupt-names = "int0", "int1";
5353
clocks = <&gclk 28>, <&mclk 0x10 18>;
5454
clock-names = "GCLK", "MCLK";
55-
atmel,assigned-clocks = <&gclk 0>;
55+
atmel,assigned-clocks = <&gclk 7>;
5656
atmel,assigned-clock-names = "GCLK";
5757
status = "disabled";
5858

5959
bosch,mram-cfg = <0x0 128 64 64 64 64 32 32>;
60-
divider = <12>;
60+
divider = <1>;
6161
};
6262
};
6363
};

0 commit comments

Comments
 (0)