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(0,
162 can_enable_irq(CAN1, CAN_IER_FMPIE0);
184 return can_transmit(CAN1,
186 #ifdef USE_CAN_EXT_ID
196 void usb_lp_can_rx0_isr(
void)
217 can_fifo_release(CAN1, 0);
220 void can1_rx0_isr(
void){
240 can_fifo_release(CAN1, 0);
void _can_run_rx_callback(uint32_t id, uint8_t *buf, uint8_t len)
#define NVIC_CAN1_RX_IRQ_PRIO
#define NVIC_USB_LP_CAN_RX0_IRQ_PRIO
int can_hw_transmit(uint32_t id, const uint8_t *buf, uint8_t len)
Handling of CAN hardware for STM32.
static void gpio_set(ioportid_t port, uint16_t pin)
Set a gpio output to high level.
arch independent LED (Light Emitting Diodes) API
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.