Skip to content

Commit dd01e99

Browse files
authored
atsam: Add support for CAN on atsame70 (#6366)
Signed-off-by: Luke Vuksta <[email protected]>
1 parent b1f597c commit dd01e99

File tree

6 files changed

+359
-5
lines changed

6 files changed

+359
-5
lines changed

src/atsam/Kconfig

+29
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ config MACH_SAM4E
5050
select MACH_SAM4
5151
config MACH_SAME70
5252
bool
53+
config HAVE_SAM_CANBUS
54+
bool
55+
default y if MACH_SAME70
5356

5457
config MCU
5558
string
@@ -101,6 +104,32 @@ choice
101104
config ATSAM_SERIAL
102105
bool "Serial"
103106
select SERIAL
107+
config ATSAM_MMENU_CANBUS_PC12_PD12
108+
bool "CAN bus (on PC12/PD12)"
109+
depends on HAVE_SAM_CANBUS
110+
select CANSERIAL
111+
config ATSAM_MMENU_CANBUS_PB3_PB2
112+
bool "CAN bus (on PB3/PB2)"
113+
depends on HAVE_SAM_CANBUS
114+
select CANSERIAL
115+
config ATSAM_USBCANBUS
116+
bool "USB to CAN bus bridge"
117+
depends on HAVE_SAM_CANBUS
118+
select USBCANBUS
119+
endchoice
120+
choice
121+
prompt "CAN bus interface" if USBCANBUS
122+
config ATSAM_CMENU_CANBUS_PC12_PD12
123+
bool "CAN bus (on PC12/PD12)"
124+
config ATSAM_CMENU_CANBUS_PB3_PB2
125+
bool "CAN bus (on PB3/PB2)"
104126
endchoice
105127

128+
config ATSAM_CANBUS_PC12_PD12
129+
bool
130+
default y if ATSAM_MMENU_CANBUS_PC12_PD12 || ATSAM_CMENU_CANBUS_PC12_PD12
131+
config ATSAM_CANBUS_PB3_PB2
132+
bool
133+
default y if ATSAM_MMENU_CANBUS_PB3_PB2 || ATSAM_CMENU_CANBUS_PB3_PB2
134+
106135
endif

src/atsam/Makefile

+6-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Setup the toolchain
44
CROSS_PREFIX=arm-none-eabi-
55

6-
dirs-y += src/atsam src/generic
6+
dirs-y += src/atsam src/generic lib/fast-hash
77
dirs-$(CONFIG_MACH_SAM3X) += lib/sam3x/gcc
88
dirs-$(CONFIG_MACH_SAM4S) += lib/sam4s/gcc
99
dirs-$(CONFIG_MACH_SAM4E) += lib/sam4e/gcc
@@ -18,7 +18,7 @@ CFLAGS-$(CONFIG_MACH_SAM3X) += -Ilib/sam3x/include
1818
CFLAGS-$(CONFIG_MACH_SAM4S) += -Ilib/sam4s/include
1919
CFLAGS-$(CONFIG_MACH_SAM4E) += -Ilib/sam4e/include
2020
CFLAGS-$(CONFIG_MACH_SAME70) += -Ilib/same70b/include
21-
CFLAGS += $(CFLAGS-y) -D__$(MCU)__ -mthumb -Ilib/cmsis-core
21+
CFLAGS += $(CFLAGS-y) -D__$(MCU)__ -mthumb -Ilib/cmsis-core -Ilib/fast-hash
2222

2323
CFLAGS_klipper.elf += --specs=nano.specs --specs=nosys.specs
2424
CFLAGS_klipper.elf += -T $(OUT)src/generic/armcm_link.ld
@@ -33,6 +33,10 @@ usb-src-$(CONFIG_MACH_SAM4) := atsam/sam4_usb.c
3333
usb-src-$(CONFIG_MACH_SAME70) := atsam/sam3_usb.c
3434
src-$(CONFIG_USBSERIAL) += $(usb-src-y) atsam/chipid.c generic/usb_cdc.c
3535
src-$(CONFIG_SERIAL) += atsam/serial.c generic/serial_irq.c
36+
canbus-src-y := generic/canserial.c ../lib/fast-hash/fasthash.c
37+
canbus-src-y += atsam/fdcan.c atsam/chipid.c
38+
src-$(CONFIG_USBCANBUS) += $(canbus-src-y) $(usb-src-y) generic/usb_canbus.c
39+
src-$(CONFIG_CANSERIAL) += $(canbus-src-y) generic/canbus.c
3640
src-$(CONFIG_MACH_SAM3X) += atsam/adc.c atsam/hard_pwm.c
3741
src-$(CONFIG_MACH_SAM4) += atsam/hard_pwm.c
3842
src-$(CONFIG_MACH_SAM4S) += atsam/adc.c

src/atsam/chipid.c

+7-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// This file may be distributed under the terms of the GNU GPLv3 license.
66

77
#include "generic/irq.h" // irq_disable
8+
#include "generic/canserial.h" // canserial_set_uuid
89
#include "generic/usb_cdc.h" // usb_fill_serial
910
#include "generic/usbstd.h" // usb_string_descriptor
1011
#include "internal.h" // EFC0
@@ -61,14 +62,18 @@ read_chip_id(uint32_t *id)
6162
void
6263
chipid_init(void)
6364
{
64-
if (!CONFIG_USB_SERIAL_NUMBER_CHIPID)
65+
if (!CONFIG_USB_SERIAL_NUMBER_CHIPID && !CONFIG_CANBUS)
6566
return;
6667

6768
uint32_t id[4];
6869
irq_disable();
6970
read_chip_id(id);
7071
irq_enable();
7172

72-
usb_fill_serial(&cdc_chipid.desc, ARRAY_SIZE(cdc_chipid.data), id);
73+
if (CONFIG_USB_SERIAL_NUMBER_CHIPID)
74+
usb_fill_serial(&cdc_chipid.desc, ARRAY_SIZE(cdc_chipid.data), id);
75+
76+
if (CONFIG_CANBUS)
77+
canserial_set_uuid((void*)id, CHIP_UID_LEN);
7378
}
7479
DECL_INIT(chipid_init);

0 commit comments

Comments
 (0)