36 #include <libopencm3/stm32/rcc.h>
37 #include <libopencm3/stm32/gpio.h>
38 #include <libopencm3/stm32/can.h>
39 #include <libopencm3/cm3/nvic.h>
44 #error "CAN is currently only implemented for STM32F1"
48 #define NVIC_USB_LP_CAN_RX0_IRQ_PRIO RTOS_PRIO+1
50 #define NVIC_USB_LP_CAN_RX0_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);
134 can_filter_id_mask_32bit_init(
CAN1,
142 can_enable_irq(
CAN1, CAN_IER_FMPIE0);
164 return can_transmit(
CAN1,
166 #ifdef USE_CAN_EXT_ID
194 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
void gpio_set(uint32_t port, uint16_t pin)
Set a gpio output to high level.
void usb_lp_can_rx0_isr(void)
int can_hw_transmit(uint32_t id, const uint8_t *buf, uint8_t len)
arch independent LED (Light Emitting Diodes) API