libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
h7/fdcan.h
Go to the documentation of this file.
1/** @defgroup fdcan_defines FDCAN Defines
2
3@ingroup STM32H7xx_defines
4
5
6@author @htmlonly &copy @endhtmlonly 2021 Eduard Drusa <ventyl86 at netkosice dot sk>
7
8LGPL License Terms @ref lgpl_license
9*/
10/*
11 * This file is part of the libopencm3 project.
12 *
13 * Copyright (C) 2021 Eduard Drusa <ventyl86 at netkosice dot sk>
14 *
15 * This library is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License as published by
17 * the Free Software Foundation, either version 3 of the License, or
18 * (at your option) any later version.
19 *
20 * This library is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU Lesser General Public License for more details.
24 *
25 * You should have received a copy of the GNU Lesser General Public License
26 * along with this library. If not, see <http://www.gnu.org/licenses/>.
27 */
28
29#pragma once
30
31/** @{ */
32
33/* FDCAN block base addresses. Used in functions to identify FDCAN block being manipulated. */
34
35/** @defgroup fdcan_block FDCAN block base addresses
36 * @{
37 */
38#define CAN1 FDCAN1_BASE
39#define CAN2 FDCAN2_BASE
40/**@}*/
41
42/* Size of FDCAN peripheral message RAM in bytes */
43#define CAN_MSG_SIZE 0x2800
44
45#define FDCAN_GFC(can_base) MMIO32(can_base + 0x0080)
46
47#define FDCAN_SIDFC(can_base) MMIO32(can_base + 0x0084)
48#define FDCAN_XIDFC(can_base) MMIO32(can_base + 0x0088)
49#define FDCAN_XIDAM(can_base) MMIO32(can_base + 0x0090)
50
51#define FDCAN_HPMS(can_base) MMIO32(can_base + 0x0094)
52#define FDCAN_NDAT1(can_base) MMIO32(can_base + 0x0098)
53#define FDCAN_HDAT2(can_base) MMIO32(can_base + 0x009C)
54
55#define FDCAN_RXFIC_BASE 0x00A0
56#define FDCAN_RXFI_OFFSET 0x0010
57
58#define FDCAN_RXFIC(can_base, fifo_id) \
59 MMIO32((can_base) + FDCAN_RXFIC_BASE + (FDCAN_RXFI_OFFSET * (fifo_id)))
60
61#define FDCAN_RXF0C(can_base) FDCAN_RXFIC(can_base, 0)
62#define FDCAN_RXF1C(can_base) FDCAN_RXFIC(can_base, 1)
63
64#define FDCAN_RXFIS_BASE 0x00A4
65#define FDCAN_RXFIA_BASE 0x00A8
66
67#define FDCAN_RXBC(can_base) MMIO32(can_base + 0x00AC)
68
69#define FDCAN_RXESC(can_base) MMIO32(can_base + 0x00BC)
70#define FDCAN_TXESC(can_base) MMIO32(can_base + 0x00C8)
71#define FDCAN_TXBRP(can_base) MMIO32(can_base + 0x00CC)
72#define FDCAN_TXBAR(can_base) MMIO32(can_base + 0x00D0)
73#define FDCAN_TXBCR(can_base) MMIO32(can_base + 0x00D4)
74#define FDCAN_TXBTO(can_base) MMIO32(can_base + 0x00D8)
75#define FDCAN_TXBCF(can_base) MMIO32(can_base + 0x00DC)
76#define FDCAN_TXBTIE(can_base) MMIO32(can_base + 0x00E0)
77#define FDCAN_TXBCIE(can_base) MMIO32(can_base + 0x00E4)
78#define FDCAN_TXEFC(can_base) MMIO32(can_base + 0x00F0)
79#define FDCAN_TXEFS(can_base) MMIO32(can_base + 0x00F4)
80#define FDCAN_TXEFA(can_base) MMIO32(can_base + 0x00F8)
81
82#define FDCAN_TTTMC(can_base) MMIO32(can_base + 0x0100)
83#define FDCAN_TTRMC(can_base) MMIO32(can_base + 0x0104)
84#define FDCAN_TTOCF(can_base) MMIO32(can_base + 0x0108)
85#define FDCAN_TTMLM(can_base) MMIO32(can_base + 0x010C)
86#define FDCAN_TURCF(can_base) MMIO32(can_base + 0x0110)
87#define FDCAN_TTOCN(can_base) MMIO32(can_base + 0x0114)
88#define FDCAN_TTGTP(can_base) MMIO32(can_base + 0x0118)
89#define FDCAN_TTTMK(can_base) MMIO32(can_base + 0x011C)
90#define FDCAN_TTTIR(can_base) MMIO32(can_base + 0x0120)
91#define FDCAN_TTIE(can_base) MMIO32(can_base + 0x0124)
92#define FDCAN_TTILS(can_base) MMIO32(can_base + 0x0128)
93#define FDCAN_TTOST(can_base) MMIO32(can_base + 0x012C)
94#define FDCAN_TURNA(can_base) MMIO32(can_base + 0x0130)
95#define FDCAN_TTLGT(can_base) MMIO32(can_base + 0x0134)
96#define FDCAN_TTCTC(can_base) MMIO32(can_base + 0x0138)
97#define FDCAN_TTCPT(can_base) MMIO32(can_base + 0x013C)
98#define FDCAN_TTCSM(can_base) MMIO32(can_base + 0x0140)
99#define FDCAN_TTTS(can_base) MMIO32(can_base + 0x0300)
100
101#define FDCAN_CCU_CCFG MMIO32(CAN_CCU_BASE + 0x0004)
102#define FDCAN_CCU_CREL MMIO32(CAN_CCU_BASE + 0x0000)
103
104#define FDCAN_GFC_RRFE (1 << 0)
105#define FDCAN_GFC_RRFS (1 << 1)
106
107/** ANFE[1:0]: Accept non-matching frames w/ extended ID */
108#define FDCAN_GFC_ANFE_SHIFT 2
109#define FDCAN_GFC_ANFE_MASK 0x3
110
111/** ANFS[1:0]: Accept non-matching frames w/ standard ID */
112#define FDCAN_GFC_ANFS_SHIFT 4
113#define FDCAN_GFC_ANFS_MASK 0x3
114
115#define FDCAN_FXS_MASK 0xFF
116#define FDCAN_FXS_SHIFT 16
117
118/** Position of start address of relocatable object within register */
119#define FDCAN_FXSA_MASK 0x3FFF
120#define FDCAN_FXSA_SHIFT 2
121
122/** LSS[7:0]: List size of standard ID filters */
123#define FDCAN_SIDFC_LSS_MASK FDCAN_FXS_MASK
124#define FDCAN_SIDFC_LSS_SHIFT FDCAN_FXS_SHIFT
125
126/** LFSSA[13:0]: Filter List standard start address */
127#define FDCAN_SIDFC_FLSSA_MASK FDCAN_FXSA_MASK
128#define FDCAN_SIDFC_FLSSA_SHIFT FDCAN_FXSA_SHIFT
129
130/** LSE[7:0]: List size of extended ID filters */
131#define FDCAN_XIDFC_LSE_MASK FDCAN_FXS_MASK
132#define FDCAN_XIDFC_LSE_SHIFT FDCAN_FXS_SHIFT
133
134/** LFSSA[7:0]: Filter List extended start address */
135#define FDCAN_XIDFC_FLESA_MASK FDCAN_FXSA_MASK
136#define FDCAN_XIDFC_FLESA_SHIFT FDCAN_FXSA_SHIFT
137
138/** TFQS[5:0]: Tx FIFO/Queue size */
139#define FDCAN_TXBC_TFQS_MASK 0x3F
140#define FDCAN_TXBC_TFQS_SHIFT 24
141
142/** TBSA[7:0]: Transmit buffer start address */
143#define FDCAN_TXBC_TBSA_MASK FDCAN_FXSA_MASK
144#define FDCAN_TXBC_TBSA_SHIFT FDCAN_FXSA_SHIFT
145
146#define FDCAN_TXEFC_EFS_MASK 0x3F
147#define FDCAN_TXEFC_EFS_SHIFT 16
148
149/** EFSA[7:0]: (Transmit) event FIFO start address */
150#define FDCAN_TXEFC_EFSA_MASK FDCAN_FXSA_MASK
151#define FDCAN_TXEFC_EFSA_SHIFT FDCAN_FXSA_SHIFT
152
153#define FDCAN_RXFIC_FIOM (1 << 31)
154
155#define FDCAN_RXFIC_FIWM_MASK 0x7F
156#define FDCAN_RXFIC_FIWM_SHIFT 24
157
158#define FDCAN_RXFIC_FIS_MASK 0x7F
159#define FDCAN_RXFIC_FIS_SHIFT 16
160
161
162#define FDCAN_RXFIC_FISA_MASK FDCAN_FXSA_MASK
163#define FDCAN_RXFIC_FISA_SHIFT FDCAN_FXSA_SHIFT
164
165#define FDCAN_RXF0C_F0OM FDCAN_RXFIC_FIOM
166
167/** F0WM[6:0]: FIFO0 watermark mode */
168#define FDCAN_RXF0C_F0WM_MASK FDCAN_RXFIC_FIWM_MASK
169#define FDCAN_RXF0C_F0WM_SHIFT FDCAN_RXFIC_FIWM_SHIFT
170
171/** F0S[6:0]: FIFO0 size */
172#define FDCAN_RXF0C_F0S_MASK FDCAN_RXFIC_FIS_MASK
173#define FDCAN_RXF0C_F0S_SHIFT FDCAN_RXFIC_FIS_SHIFT
174
175/** F0SA[13:0]: FIFO0 start address */
176#define FDCAN_RXF0C_F0SA_MASK FDCAN_RXFIC_FISA_MASK
177#define FDCAN_RXF0C_F0SA_SHIFT FDCAN_RXFIC_FISA_SHIFT
178
179#define FDCAN_RXF1C_F1OM FDCAN_RXFIC_FIOM
180
181/** F1WM[6:0]: FIFO1 watermark mode */
182#define FDCAN_RXF1C_F1WM_MASK FDCAN_RXFIC_FIWM_MASK
183#define FDCAN_RXF1C_F1WM_SHIFT FDCAN_RXFIC_FIWM_SHIFT
184
185/** F1S[6:0]: FIFO1 size */
186#define FDCAN_RXF1C_F1S_MASK FDCAN_RXFIC_FIS_MASK
187#define FDCAN_RXF1C_F1S_SHIFT FDCAN_RXFIC_FIS_SHIFT
188
189/** F1SA[13:0]: FIFO1 start address */
190#define FDCAN_RXF1C_F1SA_MASK FDCAN_RXFIC_FISA_MASK
191#define FDCAN_RXF1C_F1SA_SHIFT FDCAN_RXFIC_FISA_SHIFT
192
193/** RBDS[3:0]: RX buffer data field size */
194#define FDCAN_RXESC_RBDS_MASK 0x7
195#define FDCAN_RXESC_RBDS_SHIFT 8
196
197/** F0DS[3:0]: FIFO0 data field size */
198#define FDCAN_RXESC_F0DS_MASK 0x7
199#define FDCAN_RXESC_F0DS_SHIFT 0
200
201/** F1DS[3:0]: FIFO1 data field size */
202#define FDCAN_RXESC_F1DS_MASK 0x7
203#define FDCAN_RXESC_F1DS_SHIFT 4
204
205/** TBDS[3:0]: TX buffer data field size */
206#define FDCAN_TXESC_TBDS_MASK 0x7
207#define FDCAN_TXESC_TBDS_SHIFT 0
208
209#define FDCAN_RXFIFO_FL_MASK 0x7F
210#define FDCAN_RXFIFO_GI_MASK 0x3F
211#define FDCAN_RXFIFO_PI_MASK 0x3F
212
213#define FDCAN_RXFIFO_AI_MASK 0x3F
214
215#define FDCAN_TXFQS_TFFL_MASK 0x3F
216#define FDCAN_TXFQS_TFGI_MASK 0x1F
217#define FDCAN_TXFQS_TFQPI_MASK 0x1F
218
219#define FDCAN_TXEFS_EFFL_MASK 0x3F
220#define FDCAN_TXEFS_EFGI_MASK 0x1F
221#define FDCAN_TXEFS_EFPI_MASK 0x1F
222
223/** CDIV[3:0]: Input clock divider */
224#define FDCAN_CCU_CCFG_CDIV_SHIFT 16
225#define FDCAN_CCU_CCFG_CDIV_MASK 0xF
226
227
228
229#define FDCAN_LFSSA_OFFSET(can_base) \
230 (FDCAN_SIDFC(can_base) & (FDCAN_SIDFC_FLSSA_MASK << FDCAN_SIDFC_FLSSA_SHIFT))
231
232#define FDCAN_LFESA_OFFSET(can_base) \
233 (FDCAN_XIDFC(can_base) & (FDCAN_XIDFC_FLESA_MASK << FDCAN_XIDFC_FLESA_SHIFT))
234
235#define FDCAN_RXFIFO_OFFSET(can_base, fifo_id) \
236 (FDCAN_RXFIC(can_base, fifo_id) & (FDCAN_FXSA_MASK << FDCAN_FXSA_SHIFT))
237
238#define FDCAN_TXBUF_OFFSET(can_base) \
239 (FDCAN_TXBC(can_base) & (FDCAN_TXBC_TBSA_MASK << FDCAN_TXBC_TBSA_SHIFT))
240
241#define FDCAN_TXEVT_OFFSET(can_base) \
242 (FDCAN_TXEFC(can_base) & (FDCAN_TXEFC_EFSA_MASK << FDCAN_TXEFC_EFSA_SHIFT))
243
245
246void fdcan_init_std_filter_ram(uint32_t canport, uint32_t flssa, uint8_t lss);
247void fdcan_init_ext_filter_ram(uint32_t canport, uint32_t flesa, uint8_t lse);
248void fdcan_init_fifo_ram(uint32_t canport, unsigned fifo_id, uint32_t fxsa, uint8_t fxs);
249void fdcan_init_tx_event_ram(uint32_t canport, uint32_t tesa, uint8_t tes);
250void fdcan_init_tx_buffer_ram(uint32_t canport, uint32_t tbsa, uint8_t tbs);
251int fdcan_set_rx_element_size(uint32_t canport, uint8_t rxbuf, uint8_t rxfifo0, uint8_t rxfifo1);
252int fdcan_set_tx_element_size(uint32_t canport, uint8_t txbuf);
253
255
256/**@}*/
#define END_DECLS
Definition: common.h:34
#define BEGIN_DECLS
Definition: common.h:33
void fdcan_init_tx_event_ram(uint32_t canport, uint32_t tesa, uint8_t tes)
Initialize allocation of transmit event block in CAN message RAM.
Definition: fdcan.c:163
int fdcan_set_rx_element_size(uint32_t canport, uint8_t rxbuf, uint8_t rxfifo0, uint8_t rxfifo1)
Initialize size of data fields in reception buffers.
Definition: fdcan.c:209
void fdcan_init_fifo_ram(uint32_t canport, unsigned fifo_id, uint32_t fxsa, uint8_t fxs)
Initialize allocation of FIFO block in CAN message RAM.
Definition: fdcan.c:143
void fdcan_init_std_filter_ram(uint32_t canport, uint32_t flssa, uint8_t lss)
Initialize allocation of standard filter block in CAN message RAM.
Definition: fdcan.c:111
void fdcan_init_tx_buffer_ram(uint32_t canport, uint32_t tbsa, uint8_t tbs)
Initialize allocation of transmit queue block in CAN message RAM.
Definition: fdcan.c:183
int fdcan_set_tx_element_size(uint32_t canport, uint8_t txbuf)
Initialize size of data fields in transmit buffers.
Definition: fdcan.c:261
void fdcan_init_ext_filter_ram(uint32_t canport, uint32_t flesa, uint8_t lse)
Initialize allocation of extended filter block in CAN message RAM.
Definition: fdcan.c:127