diff --git a/boards/arm/mppt_2420_rc/mppt_2420_rc.dts b/boards/arm/mppt_2420_rc/mppt_2420_rc.dts index 0c7f2c4..8c355d2 100644 --- a/boards/arm/mppt_2420_rc/mppt_2420_rc.dts +++ b/boards/arm/mppt_2420_rc/mppt_2420_rc.dts @@ -44,6 +44,15 @@ }; }; + outputs { + compatible = "outputs"; + + can_en { + label = "CAN disable / standby"; + gpios = <&gpiob 14 GPIO_ACTIVE_LOW>; + }; + }; + adc-inputs { compatible = "adc-inputs"; @@ -191,3 +200,16 @@ timeout = <7>; }; }; + +/* +// This requires https://github.com/zephyrproject-rtos/zephyr/pull/22832 +&can1 { + bus-speed = <250000>; + bus-speed-data = <250000>; + sjw = <1>; + sjw-data = <1>; + sample-point = <875>; + sample-point-data = <875>; + status = "okay"; +}; +*/ diff --git a/boards/arm/mppt_2420_rc/mppt_2420_rc_defconfig b/boards/arm/mppt_2420_rc/mppt_2420_rc_defconfig index 98e4952..9acb4eb 100644 --- a/boards/arm/mppt_2420_rc/mppt_2420_rc_defconfig +++ b/boards/arm/mppt_2420_rc/mppt_2420_rc_defconfig @@ -60,3 +60,7 @@ CONFIG_I2C=y CONFIG_I2C_1=y CONFIG_EEPROM=y CONFIG_EEPROM_AT24=y + +# don't enable CAN by default until PR #22832 is merged to upstream Zephyr +#CONFIG_CAN=y +#CONFIG_EXT_THINGSET_CAN=y diff --git a/boards/arm/mppt_2420_rc/pinmux.c b/boards/arm/mppt_2420_rc/pinmux.c index d269754..798b1d1 100644 --- a/boards/arm/mppt_2420_rc/pinmux.c +++ b/boards/arm/mppt_2420_rc/pinmux.c @@ -30,6 +30,13 @@ static const struct pin_config pinconf[] = { {STM32_PIN_PA11, STM32G4X_PINMUX_FUNC_PA11_USB_DM}, {STM32_PIN_PA12, STM32G4X_PINMUX_FUNC_PA12_USB_DP}, #endif /* CONFIG_USB_DC_STM32 */ +#if DT_NODE_HAS_STATUS(DT_NODELABEL(can1), okay) + {STM32_PIN_PA11, STM32G4X_PINMUX_FUNC_PA11_FDCAN1_RX}, + {STM32_PIN_PA12, STM32G4X_PINMUX_FUNC_PA12_FDCAN1_TX}, +#endif +#if defined(CONFIG_USB_DC_STM32) && DT_NODE_HAS_STATUS(DT_NODELABEL(can1), okay) +#error "PINMUX does not allow concurrent USB and CAN." +#endif }; static int pinmux_stm32_init(struct device *port) diff --git a/src/ext/can.cpp b/src/ext/can.cpp index 996af15..8a96931 100644 --- a/src/ext/can.cpp +++ b/src/ext/can.cpp @@ -14,7 +14,6 @@ #include #include #include -#include // needed for debug printing of register contents #include "board.h" #include "thingset.h" @@ -114,11 +113,9 @@ int ThingSetCAN::pub() int start_pos = 0; while ((data_len = ts.bin_pub_can(start_pos, PUB_CAN, node_id, can_id, can_data)) != -1) { - struct zcan_frame frame = { - .id_type = CAN_EXTENDED_IDENTIFIER, - .rtr = CAN_DATAFRAME - }; - + struct zcan_frame frame = {0}; + frame.id_type = CAN_STANDARD_IDENTIFIER; + frame.rtr = CAN_DATAFRAME; frame.ext_id = can_id; memcpy(frame.data, can_data, 8);