Loading...
Searching...
No Matches
candev_stm32.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2016 OTA keys S.A.
3 *
4 * This file is subject to the terms and conditions of the GNU Lesser General
5 * Public License v2.1. See the file LICENSE in the top level directory for more
6 * details.
7 */
8
9#pragma once
10
32
33#ifdef __cplusplus
34extern "C" {
35#endif
36
37#include "can/candev.h"
38
40#if defined(CAN3)
41#define CANDEV_STM32_CHAN_NUMOF 3
42#elif defined(CAN2)
43#define CANDEV_STM32_CHAN_NUMOF 2
44#elif defined(CAN1) || defined(CAN) || DOXYGEN
45#define CANDEV_STM32_CHAN_NUMOF 1
46#else
47#error "CAN STM32: CPU not supported"
48#endif
49
54#if defined(CPU_FAM_STM32F1)
55#define ISR_CAN1_TX isr_usb_hp_can1_tx
56#define ISR_CAN1_RX0 isr_usb_lp_can1_rx0
57#define ISR_CAN1_RX1 isr_can1_rx1
58#define ISR_CAN1_SCE isr_can1_sce
59#else
60#define ISR_CAN1_TX isr_can1_tx
61#define ISR_CAN1_RX0 isr_can1_rx0
62#define ISR_CAN1_RX1 isr_can1_rx1
63#define ISR_CAN1_SCE isr_can1_sce
64#define ISR_CAN2_TX isr_can2_tx
65#define ISR_CAN2_RX0 isr_can2_rx0
66#define ISR_CAN2_RX1 isr_can2_rx1
67#define ISR_CAN2_SCE isr_can2_sce
68#define ISR_CAN3_TX isr_can3_tx
69#define ISR_CAN3_RX0 isr_can3_rx0
70#define ISR_CAN3_RX1 isr_can3_rx1
71#define ISR_CAN3_SCE isr_can3_sce
72#endif
74
75#if CANDEV_STM32_CHAN_NUMOF > 1 || DOXYGEN
77#define CAN_STM32_NB_FILTER 28
78#else
79#define CAN_STM32_NB_FILTER 14
80#endif
81
82#ifndef CANDEV_STM32_DEFAULT_BITRATE
84#define CANDEV_STM32_DEFAULT_BITRATE 500000U
85#endif
86
87#ifndef CANDEV_STM32_DEFAULT_SPT
89#define CANDEV_STM32_DEFAULT_SPT 875
90#endif
91
93typedef struct {
94 CAN_TypeDef *can;
95 uint32_t rcc_mask;
96 gpio_t rx_pin;
97 gpio_t tx_pin;
98#ifndef CPU_FAM_STM32F1
100#endif
102#if CANDEV_STM32_CHAN_NUMOF > 1 || defined(DOXYGEN)
103 CAN_TypeDef *can_master;
111 uint8_t nb_filters;
112#endif
113#if defined(CPU_FAM_STM32F0)
114 uint8_t irqn;
115#else
116 uint8_t tx_irqn;
117 uint8_t rx0_irqn;
118 uint8_t rx1_irqn;
119 uint8_t sce_irqn;
120#endif
121 uint8_t ttcm : 1;
122 uint8_t abom : 1;
123 uint8_t awum : 1;
124 uint8_t nart : 1;
125 uint8_t rflm : 1;
126 uint8_t txfp : 1;
127 uint8_t lbkm : 1;
128 uint8_t silm : 1;
129} can_conf_t;
131#define HAVE_CAN_CONF_T
132
134#define CAN_STM32_TX_MAILBOXES 3
136#define CAN_STM32_RX_MAILBOXES 2
137
138#ifndef CAN_STM32_RX_MAIL_FIFO
140#define CAN_STM32_RX_MAIL_FIFO 12
141#endif
142
144typedef struct can can_t;
146#define HAVE_CAN_T
147
155
157typedef struct candev_stm32_isr {
158 int isr_tx : 3;
159 int isr_rx : 2;
160 int isr_wkup : 1;
162
164struct can {
167 gpio_t rx_pin;
168 gpio_t tx_pin;
174};
175
176#ifndef CPU_FAM_STM32F1
185void candev_stm32_set_pins(can_t *dev, gpio_t tx_pin, gpio_t rx_pin,
186 gpio_af_t af);
187#else
195void candev_stm32_set_pins(can_t *dev, gpio_t tx_pin, gpio_t rx_pin);
196#endif
197
198#ifdef __cplusplus
199}
200#endif
Definitions for low-level CAN driver interface.
#define CAN_STM32_TX_MAILBOXES
The number of transmit mailboxes.
#define CAN_STM32_RX_MAIL_FIFO
This is the maximum number of frame the driver can receive simultaneously.
void candev_stm32_set_pins(can_t *dev, gpio_t tx_pin, gpio_t rx_pin, gpio_af_t af)
Set the pins of an stm32 CAN device.
struct candev_stm32_rx_fifo candev_stm32_rx_fifo_t
This structure holds anything related to the receive part.
struct candev_stm32_isr candev_stm32_isr_t
Internal interrupt flags.
struct candev_stm32_isr candev_stm32_isr_t
Internal interrupt flags.
gpio_af_t
Override alternative GPIO mode options.
Definition periph_cpu.h:165
struct can can_t
Low level device structure for ESP32 CAN (extension of candev_t)
struct candev candev_t
Forward declaration for candev struct.
Definition candev.h:59
ESP CAN device configuration.
Definition can_esp.h:87
CAN_TypeDef * can
CAN device.
uint8_t nb_filters
Number of filters to use.
uint8_t nart
No automatic retransmission.
uint8_t first_filter
First filter in the bank.
uint8_t sce_irqn
SCE IRQ channel.
gpio_t tx_pin
CAN transceiver TX pin.
Definition can_esp.h:89
uint8_t txfp
Transmit FIFO priority.
uint8_t rx0_irqn
RX0 IRQ channel.
uint32_t rcc_mask
RCC mask to enable clock.
uint8_t rx1_irqn
RX1 IRQ channel.
uint8_t abom
Automatic bus-off management.
uint8_t tx_irqn
TX IRQ channel.
gpio_t rx_pin
CAN transceiver RX pin.
Definition can_esp.h:90
uint8_t awum
Automatic wakeup mode.
CAN_TypeDef * can_master
Master CAN device.
gpio_af_t af
Alternate pin function to use.
bool en_deep_sleep_wake_up
Enable deep-sleep wake-up interrupt.
uint32_t master_rcc_mask
Master device RCC mask.
uint8_t silm
Silent mode.
uint8_t rflm
Receive FIFO locked mode.
uint8_t ttcm
Time triggered communication mode.
uint8_t lbkm
Loopback mode.
Controller Area Network frame.
Definition can.h:100
Low level device structure for ESP32 CAN (extension of candev_t)
Definition can_esp.h:63
const struct can_frame * tx_mailbox[CAN_STM32_TX_MAILBOXES]
Tx mailboxes.
candev_stm32_rx_fifo_t rx_fifo
Rx FIFOs.
candev_stm32_isr_t isr_flags
ISR flags.
gpio_t rx_pin
RX pin.
candev_t candev
candev base structure
Definition can_esp.h:64
gpio_t tx_pin
TX pin.
const can_conf_t * conf
Configuration.
gpio_af_t af
Alternate pin function to use.
Internal interrupt flags.
int isr_rx
Rx FIFO interrupt.
int isr_tx
Tx mailboxes interrupt.
int isr_wkup
Wake up interrupt.
This structure holds anything related to the receive part.
int write_idx
Write index in the receive FIFO.
int read_idx
Read index in the receive FIFO.
struct can_frame frame[CAN_STM32_RX_MAIL_FIFO]
Receive FIFO.
int is_full
Flag set when the FIFO is full.