Skip to content

Commit

Permalink
atsam: Add support for CAN on atsame70 (#6366)
Browse files Browse the repository at this point in the history
Signed-off-by: Luke Vuksta <[email protected]>
  • Loading branch information
Wulfsta authored Oct 19, 2023
1 parent b1f597c commit dd01e99
Show file tree
Hide file tree
Showing 6 changed files with 359 additions and 5 deletions.
29 changes: 29 additions & 0 deletions src/atsam/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ config MACH_SAM4E
select MACH_SAM4
config MACH_SAME70
bool
config HAVE_SAM_CANBUS
bool
default y if MACH_SAME70

config MCU
string
Expand Down Expand Up @@ -101,6 +104,32 @@ choice
config ATSAM_SERIAL
bool "Serial"
select SERIAL
config ATSAM_MMENU_CANBUS_PC12_PD12
bool "CAN bus (on PC12/PD12)"
depends on HAVE_SAM_CANBUS
select CANSERIAL
config ATSAM_MMENU_CANBUS_PB3_PB2
bool "CAN bus (on PB3/PB2)"
depends on HAVE_SAM_CANBUS
select CANSERIAL
config ATSAM_USBCANBUS
bool "USB to CAN bus bridge"
depends on HAVE_SAM_CANBUS
select USBCANBUS
endchoice
choice
prompt "CAN bus interface" if USBCANBUS
config ATSAM_CMENU_CANBUS_PC12_PD12
bool "CAN bus (on PC12/PD12)"
config ATSAM_CMENU_CANBUS_PB3_PB2
bool "CAN bus (on PB3/PB2)"
endchoice

config ATSAM_CANBUS_PC12_PD12
bool
default y if ATSAM_MMENU_CANBUS_PC12_PD12 || ATSAM_CMENU_CANBUS_PC12_PD12
config ATSAM_CANBUS_PB3_PB2
bool
default y if ATSAM_MMENU_CANBUS_PB3_PB2 || ATSAM_CMENU_CANBUS_PB3_PB2

endif
8 changes: 6 additions & 2 deletions src/atsam/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Setup the toolchain
CROSS_PREFIX=arm-none-eabi-

dirs-y += src/atsam src/generic
dirs-y += src/atsam src/generic lib/fast-hash
dirs-$(CONFIG_MACH_SAM3X) += lib/sam3x/gcc
dirs-$(CONFIG_MACH_SAM4S) += lib/sam4s/gcc
dirs-$(CONFIG_MACH_SAM4E) += lib/sam4e/gcc
Expand All @@ -18,7 +18,7 @@ CFLAGS-$(CONFIG_MACH_SAM3X) += -Ilib/sam3x/include
CFLAGS-$(CONFIG_MACH_SAM4S) += -Ilib/sam4s/include
CFLAGS-$(CONFIG_MACH_SAM4E) += -Ilib/sam4e/include
CFLAGS-$(CONFIG_MACH_SAME70) += -Ilib/same70b/include
CFLAGS += $(CFLAGS-y) -D__$(MCU)__ -mthumb -Ilib/cmsis-core
CFLAGS += $(CFLAGS-y) -D__$(MCU)__ -mthumb -Ilib/cmsis-core -Ilib/fast-hash

CFLAGS_klipper.elf += --specs=nano.specs --specs=nosys.specs
CFLAGS_klipper.elf += -T $(OUT)src/generic/armcm_link.ld
Expand All @@ -33,6 +33,10 @@ usb-src-$(CONFIG_MACH_SAM4) := atsam/sam4_usb.c
usb-src-$(CONFIG_MACH_SAME70) := atsam/sam3_usb.c
src-$(CONFIG_USBSERIAL) += $(usb-src-y) atsam/chipid.c generic/usb_cdc.c
src-$(CONFIG_SERIAL) += atsam/serial.c generic/serial_irq.c
canbus-src-y := generic/canserial.c ../lib/fast-hash/fasthash.c
canbus-src-y += atsam/fdcan.c atsam/chipid.c
src-$(CONFIG_USBCANBUS) += $(canbus-src-y) $(usb-src-y) generic/usb_canbus.c
src-$(CONFIG_CANSERIAL) += $(canbus-src-y) generic/canbus.c
src-$(CONFIG_MACH_SAM3X) += atsam/adc.c atsam/hard_pwm.c
src-$(CONFIG_MACH_SAM4) += atsam/hard_pwm.c
src-$(CONFIG_MACH_SAM4S) += atsam/adc.c
Expand Down
9 changes: 7 additions & 2 deletions src/atsam/chipid.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// This file may be distributed under the terms of the GNU GPLv3 license.

#include "generic/irq.h" // irq_disable
#include "generic/canserial.h" // canserial_set_uuid
#include "generic/usb_cdc.h" // usb_fill_serial
#include "generic/usbstd.h" // usb_string_descriptor
#include "internal.h" // EFC0
Expand Down Expand Up @@ -61,14 +62,18 @@ read_chip_id(uint32_t *id)
void
chipid_init(void)
{
if (!CONFIG_USB_SERIAL_NUMBER_CHIPID)
if (!CONFIG_USB_SERIAL_NUMBER_CHIPID && !CONFIG_CANBUS)
return;

uint32_t id[4];
irq_disable();
read_chip_id(id);
irq_enable();

usb_fill_serial(&cdc_chipid.desc, ARRAY_SIZE(cdc_chipid.data), id);
if (CONFIG_USB_SERIAL_NUMBER_CHIPID)
usb_fill_serial(&cdc_chipid.desc, ARRAY_SIZE(cdc_chipid.data), id);

if (CONFIG_CANBUS)
canserial_set_uuid((void*)id, CHIP_UID_LEN);
}
DECL_INIT(chipid_init);
Loading

0 comments on commit dd01e99

Please sign in to comment.