From 2c27655ea9debd706afc26437788d3ec8cc81e12 Mon Sep 17 00:00:00 2001 From: Firas Hamdi Date: Wed, 21 Jun 2023 21:57:59 +0200 Subject: [PATCH] cpu/samd5x: minor fixes --- boards/same54-xpro/include/periph_conf.h | 5 +++-- cpu/samd5x/include/candev_samd5x.h | 8 +++++--- cpu/samd5x/periph/can.c | 13 +++++++++++-- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/boards/same54-xpro/include/periph_conf.h b/boards/same54-xpro/include/periph_conf.h index 6b09dc77c3b7b..74f746af79628 100644 --- a/boards/same54-xpro/include/periph_conf.h +++ b/boards/same54-xpro/include/periph_conf.h @@ -110,12 +110,12 @@ static const tc32_conf_t timer_config[] = { * @name CAN configuration * @{ */ +/** Available CAN interfaces */ static const can_conf_t candev_conf[] = { { .can = CAN1, .rx_pin = GPIO_PIN(PB, 13), .tx_pin = GPIO_PIN(PB, 12), - .mux = GPIO_MUX_H, .tdc_ctrl = false, .dar_ctrl = false, .tx_fifo_queue_ctrl = false, @@ -123,9 +123,10 @@ static const can_conf_t candev_conf[] = { } }; -/* CAN 1 configuration */ +/** CAN 1 configuration */ #define ISR_CAN1 isr_can1 +/** Number of CAN interfaces */ #define CAN_NUMOF ARRAY_SIZE(candev_conf) /** @} */ diff --git a/cpu/samd5x/include/candev_samd5x.h b/cpu/samd5x/include/candev_samd5x.h index 3ddafb37a478d..40039efcac499 100644 --- a/cpu/samd5x/include/candev_samd5x.h +++ b/cpu/samd5x/include/candev_samd5x.h @@ -71,7 +71,6 @@ typedef struct { Can *can; /**< CAN device handler */ gpio_t rx_pin; /**< CAN Rx pin */ gpio_t tx_pin; /**< CAN Tx pin */ - gpio_mux_t mux; bool tdc_ctrl; /**< Enable/Disable Transceiver Delay Compensation */ bool dar_ctrl; /**< Enable/Disable Automatic Retransmission */ bool tx_fifo_queue_ctrl; /**< False to use Tx FIFO operation @@ -85,7 +84,7 @@ typedef struct { * @brief CAN message RAM accessible to the CAN controller */ typedef struct { - /** Standard filters space in the CAN message RAM */ + /** Standard filters space in the CAN message RAM */ CanMramSidfe std_filter[CANDEV_SAMD5X_DEFAULT_STD_FILTER_NUM]; /** Extended filters space in the CAN message RAM */ CanMramXifde ext_filter[CANDEV_SAMD5X_DEFAULT_EXT_FILTER_NUM]; @@ -105,8 +104,11 @@ typedef struct { * @brief CAN device descriptor */ typedef struct { + /** Structure to hold driver state */ candev_t candev; + /** CAN device configuration descriptor */ const can_conf_t *conf; + /** CAN message RAM accessible to the CAN controller */ msg_ram_conf_t msg_ram_conf; } can_t; #define HAVE_CAN_T @@ -151,4 +153,4 @@ void candev_samd5x_enter_sleep_mode(candev_t *candev); */ void candev_samd5x_exit_sleep_mode(candev_t *candev); -#endif +#endif /* CANDEV_SAMD5X_H */ diff --git a/cpu/samd5x/periph/can.c b/cpu/samd5x/periph/can.c index 6edd92682e373..cf8935c04cbe9 100644 --- a/cpu/samd5x/periph/can.c +++ b/cpu/samd5x/periph/can.c @@ -183,8 +183,17 @@ void candev_samd5x_set_pins(can_t *dev) gpio_init(dev->conf->tx_pin, GPIO_OUT); gpio_init(dev->conf->rx_pin, GPIO_IN); - gpio_init_mux(dev->conf->tx_pin, dev->conf->mux); - gpio_init_mux(dev->conf->rx_pin, dev->conf->mux); + if (dev->conf->can == CAN0) { + gpio_init_mux(dev->conf->tx_pin, GPIO_MUX_I); + gpio_init_mux(dev->conf->rx_pin, GPIO_MUX_I); + } + else if (dev->conf->can == CAN1) { + gpio_init_mux(dev->conf->tx_pin, GPIO_MUX_H); + gpio_init_mux(dev->conf->rx_pin, GPIO_MUX_H); + } + else { + DEBUG_PUTS("Unsupported can channel"); + } } void candev_samd5x_enter_sleep_mode(candev_t *candev)