36 #include <libopencm3/stm32/rcc.h>
37 #include <libopencm3/stm32/gpio.h>
38 #include <libopencm3/stm32/can.h>
39 #include <libopencm3/cm3/nvic.h>
45 #define NVIC_USB_LP_CAN_RX0_IRQ_PRIO RTOS_PRIO+1
47 #define NVIC_USB_LP_CAN_RX0_IRQ_PRIO 1
48 #define NVIC_CAN1_RX_IRQ_PRIO 1
61 rcc_periph_clock_enable(RCC_AFIO);
62 rcc_periph_clock_enable(RCC_GPIOB);
63 rcc_periph_clock_enable(RCC_CAN1);
66 AFIO_MAPR |= AFIO_MAPR_CAN1_REMAP_PORTB;
69 gpio_set_mode(GPIO_BANK_CAN1_PB_RX, GPIO_MODE_INPUT,
70 GPIO_CNF_INPUT_PULL_UPDOWN, GPIO_CAN1_PB_RX);
71 gpio_set(GPIO_BANK_CAN1_PB_RX, GPIO_CAN1_PB_RX);
74 gpio_set_mode(GPIO_BANK_CAN1_PB_TX, GPIO_MODE_OUTPUT_50_MHZ,
75 GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_CAN1_PB_TX);
78 nvic_enable_irq(NVIC_USB_LP_CAN_RX0_IRQ);
84 rcc_periph_clock_enable(RCC_GPIOB);
85 rcc_periph_clock_enable(RCC_CAN1);
92 nvic_enable_irq(NVIC_CAN1_RX0_IRQ);
155 can_filter_id_mask_32bit_init(
CAN1,
163 can_enable_irq(
CAN1, CAN_IER_FMPIE0);
185 return can_transmit(
CAN1,
187 #ifdef USE_CAN_EXT_ID
197 void usb_lp_can_rx0_isr(
void)
215 can_fifo_release(
CAN1, 0);
218 void can1_rx0_isr(
void){
235 can_fifo_release(
CAN1, 0);
Handling of CAN hardware for STM32.
void _can_run_rx_callback(uint32_t id, uint8_t *buf, uint8_t len)
#define NVIC_USB_LP_CAN_RX0_IRQ_PRIO
int can_hw_transmit(uint32_t id, const uint8_t *buf, uint8_t len)
arch independent LED (Light Emitting Diodes) API
static void gpio_set(ioportid_t port, uint16_t pin)
Set a gpio output to high level.
#define NVIC_CAN1_RX_IRQ_PRIO