Skip to content

Commit

Permalink
boards/same54-xpro: add CAN periph
Browse files Browse the repository at this point in the history
  • Loading branch information
firas-hamdi committed Jun 20, 2023
1 parent 198bf9d commit 5bb6628
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 36 deletions.
24 changes: 24 additions & 0 deletions boards/same54-xpro/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,30 @@ static const tc32_conf_t timer_config[] = {
#define TIMER_NUMOF ARRAY_SIZE(timer_config)
/** @} */

/**
* @name CAN configuration
* @{
*/
static const can_conf_t candev_conf[] = {
{
/* SAME54-xpro pins */
.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,
.global_filter_cfg = CAN_REJECT,
}
};

/* CAN 1 configuration */
#define ISR_CAN1 isr_can1

#define CAN_NUMOF ARRAY_SIZE(candev_conf)
/** @} */

/**
* @name UART configuration
* @{
Expand Down
27 changes: 1 addition & 26 deletions cpu/samd5x/include/can_params.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,7 @@
extern "C" {
#endif

#include "candev_samd5x.h"

/** Default SAMD5x CAN devices config */
static const can_conf_t candev_conf[] = {
{
.can = CAN0,
.rx_pin = GPIO_PIN(PA, 23),
.tx_pin = GPIO_PIN(PA, 22),
.mux = GPIO_MUX_I,
.tdc_ctrl = false,
.dar_ctrl = false,
.tx_fifo_queue_ctrl = false,
.global_filter_cfg = CAN_ACCEPT_RX_FIFO_0,
},
{
/* SAME54-xpro pins */
.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,
.global_filter_cfg = CAN_REJECT,
}
};
#include "can/device.h"

/** Default SAMD5x CAN devices parameters */
static const candev_params_t candev_params[] = {
Expand Down
6 changes: 0 additions & 6 deletions cpu/samd5x/include/candev_samd5x.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ extern "C" {
#endif

#include "can/candev.h"
#include "periph/gpio.h"
#include "can/device.h"

#ifndef CANDEV_SAMD5X_DEFAULT_BITRATE
/** Default bitrate */
Expand Down Expand Up @@ -113,10 +111,6 @@ typedef struct {
} can_t;
#define HAVE_CAN_T

/* Interrupt service routine functions */
#define ISR_CAN0 isr_can0
#define ISR_CAN1 isr_can1

/**
* @brief Set the pins of the CAN physical transceiver
*
Expand Down
1 change: 1 addition & 0 deletions cpu/samd5x/include/periph_cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "macros/units.h"
#include "periph_cpu_common.h"

#include "candev_samd5x.h"
#ifdef __cplusplus
extern "C" {
#endif
Expand Down
10 changes: 8 additions & 2 deletions cpu/samd5x/periph/can.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
#include <assert.h>
#include <string.h>

#include "candev_samd5x.h"
#include "periph/can.h"
#include "periph/gpio.h"
#include "can/device.h"

#define ENABLE_DEBUG 0
#include "debug.h"
Expand Down Expand Up @@ -559,6 +561,7 @@ static void _isr(candev_t *candev)
}
}

#ifdef ISR_CAN1
void ISR_CAN1(void)
{
DEBUG_PUTS("ISR CAN1");
Expand All @@ -568,12 +571,15 @@ void ISR_CAN1(void)
}

}
#endif

#ifdef ISR_CAN0
void ISR_CAN0(void)
{
DEBUG_PUTS("ISR CAN0");

if (_can->candev.event_callback) {
_can->candev.event_callback(&(_can->candev), CANDEV_EVENT_ISR, NULL);
}
}
}
#endif
4 changes: 2 additions & 2 deletions tests/can_samd5x/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#include <stdio.h>

#include "can_params.h"
#include "periph/gpio.h"
#include "periph/can.h"

static can_t can_samd5x;
Expand Down Expand Up @@ -86,7 +86,7 @@ int main(void)
puts("candev test application\n");

gpio_init(GPIO_PIN(PC, 13), GPIO_IN);
can_init(&can_samd5x, &candev_conf[1]);
can_init(&can_samd5x, &candev_conf[0]);

candev = &(can_samd5x.candev);
candev->event_callback = _can_event_callback;
Expand Down

0 comments on commit 5bb6628

Please sign in to comment.