Skip to content

Commit 4bd2c04

Browse files
kywwilson11xiaoxiang781216
authored andcommitted
Preliminary add of fdcan source files.
Adding source files to the fdcan branch based on identical register set. These files should mostly just work. Removed references to FDCAN3. H5 only has 2 FDCAN interfaces. Add basic FDCAN Kconfig FDCAN Kconfig options Added various options for FDCAN mode, FDCAN bitrate, clock selection and division, and timing. Added bit timing config options (nominal and data). Added stm32h56xxx pin mappings. Fixed Data Bit Timing. Pulled in STM32H5_FDCAN_PDIV_VALUE. Added stm32_fdcan.c to Make.defs. Added DBITRATE to Kconfig Clock source changes to FDCAN Moved the setting of the clock source to the stm32h5xx_rcc.c file. Added notes to stm32_fdcan.c that STM32_FDCAN_FREQUENCY and STM32_FDCAN_PDIV should be set in board.h Change STM32H5_FDCAN_PDIV to STM32_FDCAN_PDIV Updated Kconfig to match G4 implementation. Removed stm32_fdcan_sock for now. Removed FDCAN3 from stm32_fdcan.h incomplete changes for bit timning Set NBRP and DBRP registers based on STM32H7 FDCAN socket algorithm. Added board file for initializing 1 can device. Will update later to initialize second device. Fixed ifdefs. Changed STM32 to STM32H5. Add some can testing changes. Added option to configure bit timing, with automatic bit timing set as default. Style fixes Fixed FDCAN2 and memory access issues FDCAN2 msgram offset was wrong by 1 word (4 bytes). I removed the + 4 at the end of the definition. This fixed the issues with fdcan2. Also changed ifdefs when setting ESI, FDF, and BRS bits. When CAN FD was used, this resulted in the first command after the endif (the setting of dest at line 2325) being skipped because it was included in the else block when it shouldn't have. This resulted in exceptions. Adjust ifdefs fixes this problem. Other minor fixes. Restoring board files to upstream versions. These files will be pulled in later in a separate pull request. stm32h5_fdcan_test branch created for this. Fixed Queue Mode Transmit The can driver checks the TFFL bits in the TXFQS register. In Queue mode, this always returns 0. As a result, fdcan_txempty was always returning false, which resulted in no transmissions. This code fixes that. Add stm32h5 fdcan chardriver to Make.defs
1 parent 6eabe35 commit 4bd2c04

File tree

5 files changed

+4035
-0
lines changed

5 files changed

+4035
-0
lines changed

arch/arm/src/stm32h5/Kconfig

Lines changed: 296 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ config STM32H5_STM32H5XXXX
3535
config STM32H5_STM32H56XXX
3636
bool
3737
default n
38+
select STM32H5_HAVE_FDCAN1
39+
select STM32H5_HAVE_FDCAN2
3840
select STM32H5_HAVE_LPUART1
3941
select STM32H5_HAVE_USART1
4042
select STM32H5_HAVE_USART2
@@ -210,6 +212,14 @@ config STM32H5_HAVE_PHY_POLLED
210212
bool
211213
default n
212214

215+
config STM32H5_HAVE_FDCAN1
216+
bool
217+
default n
218+
219+
config STM32H5_HAVE_FDCAN2
220+
bool
221+
default n
222+
213223
config STM32H5_HAVE_LPUART1
214224
bool
215225
default n
@@ -1322,6 +1332,292 @@ config STM32H5_NO_PHY
13221332

13231333
endmenu # Ethernet MAC Configuration
13241334

1335+
menu "FDCAN driver configuration"
1336+
depends on STM32H5_FDCAN
1337+
1338+
choice
1339+
prompt "FDCAN character driver or SocketCAN support"
1340+
default STM32H5_FDCAN_CHARDRIVER
1341+
1342+
config STM32H5_FDCAN_CHARDRIVER
1343+
bool "STM32 FDCAN character driver support"
1344+
select ARCH_HAVE_CAN_ERRORS
1345+
select CAN
1346+
1347+
config STM32H5_FDCAN_SOCKET
1348+
bool "STM32 FDCAN SocketCAN support"
1349+
select NET_CAN_HAVE_ERRORS
1350+
select NET_CAN_HAVE_CANFD
1351+
1352+
endchoice # FDCAN character driver or SocketCAN support
1353+
1354+
config STM32H5_FDCAN_REGDEBUG
1355+
bool "CAN Register level debug"
1356+
depends on DEBUG_CAN_INFO
1357+
default n
1358+
---help---
1359+
Output detailed register-level CAN device debug information.
1360+
Requires also CONFIG_DEBUG_CAN_INFO.
1361+
1362+
config STM32H5_FDCAN_QUEUE_MODE
1363+
bool "FDCAN QUEUE mode (vs FIFO mode)"
1364+
default n
1365+
1366+
menu "FDCAN1 device driver options"
1367+
depends on STM32H5_FDCAN1
1368+
1369+
choice
1370+
prompt "FDCAN1 frame format"
1371+
default STM32H5_FDCAN1_ISO11898_1
1372+
1373+
config STM32H5_FDCAN1_ISO11898_1
1374+
bool "ISO11898-1"
1375+
---help---
1376+
Enable ISO11898-1 frame format
1377+
1378+
config STM32H5_FDCAN1_NONISO_FORMAT
1379+
bool "Non ISO"
1380+
---help---
1381+
Enable Non ISO, Bosch CAN FD Specification V1.0
1382+
1383+
endchoice # FDCAN1 frame format
1384+
1385+
choice
1386+
prompt "FDCAN1 mode"
1387+
default STM32H5_FDCAN1_CLASSIC
1388+
1389+
config STM32H5_FDCAN1_CLASSIC
1390+
bool "Classic CAN"
1391+
---help---
1392+
Enable Clasic CAN mode
1393+
1394+
config STM32H5_FDCAN1_FD
1395+
bool "CAN FD"
1396+
depends on CAN_FD || NET_CAN_CANFD
1397+
---help---
1398+
Enable CAN FD mode
1399+
1400+
config STM32H5_FDCAN1_FD_BRS
1401+
bool "CAN FD with fast bit rate switching"
1402+
depends on CAN_FD || NET_CAN_CANFD
1403+
---help---
1404+
Enable CAN FD mode with fast bit rate switching mode.
1405+
1406+
endchoice # FDCAN1 mode
1407+
1408+
menu "FDCAN1 Bit Timing"
1409+
1410+
config STM32H5_FDCAN1_AUTO_BIT_TIMING
1411+
bool "FDCAN1 Automatic Bit Timing"
1412+
default y
1413+
---help---
1414+
Automatically determine FDCAN1 bit timing (nominal and data) based on bitrate.
1415+
1416+
comment "Nominal Bit Timing"
1417+
1418+
config STM32H5_FDCAN1_BITRATE
1419+
int "FDCAN bitrate"
1420+
default 500000
1421+
range 0 1000000
1422+
---help---
1423+
FDCAN1 bitrate in bits per second. Required if STM32H5_FDCAN1 is defined.
1424+
1425+
config STM32H5_FDCAN1_NTSEG1
1426+
int "FDCAN1 NTSEG1 (PropSeg + PhaseSeg1)"
1427+
default 6
1428+
range 1 256
1429+
depends on !STM32H5_FDCAN1_AUTO_BIT_TIMING
1430+
---help---
1431+
The length of the bit time is Tquanta * (SyncSeg + PropSeg + PhaseSeg1 + PhaseSeg2).
1432+
1433+
config STM32H5_FDCAN1_NTSEG2
1434+
int "FDCAN1 NTSEG2 (PhaseSeg2)"
1435+
default 7
1436+
range 1 128
1437+
depends on !STM32H5_FDCAN1_AUTO_BIT_TIMING
1438+
---help---
1439+
The length of the bit time is Tquanta * (SyncSeg + PropSeg + PhaseSeg1 + PhaseSeg2).
1440+
1441+
config STM32H5_FDCAN1_NSJW
1442+
int "FDCAN1 synchronization jump width"
1443+
default 1
1444+
range 1 128
1445+
depends on !STM32H5_FDCAN1_AUTO_BIT_TIMING
1446+
---help---
1447+
The length of the bit time is Tquanta * (SyncSeg + PropSeg + PhaseSeg1 + PhaseSeg2).
1448+
1449+
comment "Data Bit Timing"
1450+
depends on CAN_FD && STM32H5_FDCAN1_FD_BRS
1451+
1452+
config STM32H5_FDCAN1_DBITRATE
1453+
int "FDCAN1 data bitrate"
1454+
default 2000000
1455+
depends on CAN_FD && STM32H5_FDCAN1_FD_BRS
1456+
---help---
1457+
FDCAN1 bitrate in bits per second. Required if operating in FD mode with bit rate switching (BRS).
1458+
1459+
config STM32H5_FDCAN1_DTSEG1
1460+
int "FDCAN1 DTSEG1 (PropSeg + PhaseSeg1 of data phase)"
1461+
default 4
1462+
range 1 31
1463+
depends on CAN_FD && STM32H5_FDCAN1_FD_BRS && !STM32H5_FDCAN1_AUTO_BIT_TIMING
1464+
---help---
1465+
The length of the bit time is Tquanta * (SyncSeg + PropSeg + PhaseSeg1 + PhaseSeg2).
1466+
1467+
config STM32H5_FDCAN1_DTSEG2
1468+
int "FDCAN1 DTSEG2 (PhaseSeg2 of data phase)"
1469+
default 4
1470+
range 1 15
1471+
depends on CAN_FD && STM32H5_FDCAN1_FD_BRS && !STM32H5_FDCAN1_AUTO_BIT_TIMING
1472+
---help---
1473+
The length of the bit time is Tquanta * (SyncSeg + PropSeg + PhaseSeg1 + PhaseSeg2).
1474+
1475+
config STM32H5_FDCAN1_DSJW
1476+
int "FDCAN1 fast synchronization jump width"
1477+
default 2
1478+
range 1 15
1479+
depends on CAN_FD && STM32H5_FDCAN1_FD_BRS && !STM32H5_FDCAN1_AUTO_BIT_TIMING
1480+
---help---
1481+
The duration of a synchronization jump is Tcan_clk x DSJW.
1482+
1483+
endmenu # FDCAN1 Bit Timing
1484+
1485+
config STM32H5_FDCAN1_LOOPBACK
1486+
bool "Enable FDCAN1 loopback mode"
1487+
default n
1488+
---help---
1489+
Enable the FDCAN1 local loopback mode for testing purposes.
1490+
1491+
endmenu # FDCAN1 device driver options
1492+
1493+
menu "FDCAN2 device driver options"
1494+
depends on STM32H5_FDCAN2
1495+
1496+
choice
1497+
prompt "FDCAN2 frame format"
1498+
default STM32H5_FDCAN2_ISO11898_1
1499+
1500+
config STM32H5_FDCAN2_ISO11898_1
1501+
bool "ISO11898-1"
1502+
---help---
1503+
Enable ISO11898-1 frame format
1504+
1505+
config STM32H5_FDCAN2_NONISO_FORMAT
1506+
bool "Non ISO"
1507+
---help---
1508+
Enable Non ISO, Bosch CAN FD Specification V1.0
1509+
1510+
endchoice # FDCAN2 frame format
1511+
1512+
choice
1513+
prompt "FDCAN2 mode"
1514+
default STM32H5_FDCAN2_CLASSIC
1515+
1516+
config STM32H5_FDCAN2_CLASSIC
1517+
bool "Classic CAN"
1518+
---help---
1519+
Enable Clasic CAN mode
1520+
1521+
config STM32H5_FDCAN2_FD
1522+
bool "CAN FD"
1523+
depends on CAN_FD || NET_CAN_CANFD
1524+
---help---
1525+
Enable CAN FD mode
1526+
1527+
config STM32H5_FDCAN2_FD_BRS
1528+
bool "CAN FD with fast bit rate switching"
1529+
depends on CAN_FD || NET_CAN_CANFD
1530+
---help---
1531+
Enable CAN FD mode with fast bit rate switching mode.
1532+
1533+
endchoice # FDCAN2 mode
1534+
1535+
menu "FDCAN2 Bit Timing"
1536+
1537+
config STM32H5_FDCAN2_AUTO_BIT_TIMING
1538+
bool "FDCAN2 Automatic Bit Timing"
1539+
default y
1540+
---help---
1541+
Automatically determine FDCAN2 bit timing (nominal and data) based on bitrate.
1542+
1543+
comment "Nominal Bit Timing"
1544+
1545+
config STM32H5_FDCAN2_BITRATE
1546+
int "FDCAN bitrate"
1547+
default 500000
1548+
range 0 1000000
1549+
---help---
1550+
FDCAN2 bitrate in bits per second. Required if STM32H5_FDCAN2 is defined.
1551+
1552+
config STM32H5_FDCAN2_NTSEG1
1553+
int "FDCAN2 NTSEG1 (PropSeg + PhaseSeg1)"
1554+
default 6
1555+
range 1 256
1556+
depends on !STM32H5_FDCAN2_AUTO_BIT_TIMING
1557+
---help---
1558+
The length of the bit time is Tquanta * (SyncSeg + PropSeg + PhaseSeg1 + PhaseSeg2).
1559+
1560+
config STM32H5_FDCAN2_NTSEG2
1561+
int "FDCAN2 NTSEG2 (PhaseSeg2)"
1562+
default 7
1563+
range 1 128
1564+
depends on !STM32H5_FDCAN2_AUTO_BIT_TIMING
1565+
---help---
1566+
The length of the bit time is Tquanta * (SyncSeg + PropSeg + PhaseSeg1 + PhaseSeg2).
1567+
1568+
config STM32H5_FDCAN2_NSJW
1569+
int "FDCAN2 synchronization jump width"
1570+
default 1
1571+
range 1 128
1572+
depends on !STM32H5_FDCAN2_AUTO_BIT_TIMING
1573+
---help---
1574+
The length of the bit time is Tquanta * (SyncSeg + PropSeg + PhaseSeg1 + PhaseSeg2).
1575+
1576+
comment "Data Bit Timing"
1577+
depends on CAN_FD && STM32H5_FDCAN2_FD_BRS
1578+
1579+
config STM32H5_FDCAN2_DBITRATE
1580+
int "FDCAN2 data bitrate"
1581+
default 2000000
1582+
depends on CAN_FD && STM32H5_FDCAN2_FD_BRS
1583+
---help---
1584+
FDCAN2 bitrate in bits per second. Required if operating in FD mode with bit rate switching (BRS).
1585+
1586+
config STM32H5_FDCAN2_DTSEG1
1587+
int "FDCAN2 DTSEG1 (PropSeg + PhaseSeg1 of data phase)"
1588+
default 4
1589+
range 1 31
1590+
depends on CAN_FD && STM32H5_FDCAN2_FD_BRS && !STM32H5_FDCAN2_AUTO_BIT_TIMING
1591+
---help---
1592+
The length of the bit time is Tquanta * (SyncSeg + PropSeg + PhaseSeg1 + PhaseSeg2).
1593+
1594+
config STM32H5_FDCAN2_DTSEG2
1595+
int "FDCAN2 DTSEG2 (PhaseSeg2 of data phase)"
1596+
default 4
1597+
range 1 15
1598+
depends on CAN_FD && STM32H5_FDCAN2_FD_BRS && !STM32H5_FDCAN2_AUTO_BIT_TIMING
1599+
---help---
1600+
The length of the bit time is Tquanta * (SyncSeg + PropSeg + PhaseSeg1 + PhaseSeg2).
1601+
1602+
config STM32H5_FDCAN2_DSJW
1603+
int "FDCAN2 fast synchronization jump width"
1604+
default 2
1605+
range 1 15
1606+
depends on CAN_FD && STM32H5_FDCAN2_FD_BRS && !STM32H5_FDCAN2_AUTO_BIT_TIMING
1607+
---help---
1608+
The duration of a synchronization jump is Tcan_clk x DSJW.
1609+
1610+
endmenu # FDCAN2 Bit Timing
1611+
1612+
config STM32H5_FDCAN2_LOOPBACK
1613+
bool "Enable FDCAN2 loopback mode"
1614+
default n
1615+
---help---
1616+
Enable the FDCAN2 local loopback mode for testing purposes.
1617+
1618+
endmenu # FDCAN2 device driver options
1619+
1620+
endmenu # "FDCAN driver configuration"
13251621

13261622
menu "I2C Configuration"
13271623
depends on STM32H5_I2C

arch/arm/src/stm32h5/Make.defs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ ifeq ($(CONFIG_ADC),y)
5454
CHIP_CSRCS += stm32_adc.c
5555
endif
5656

57+
ifeq ($(STM32H5_FDCAN_CHARDRIVER),y)
58+
CHIP_CSRCS += stm32_fdcan.c
59+
endif
60+
5761
ifeq ($(CONFIG_STM32H5_SPI),y)
5862
CHIP_CSRCS += stm32_spi.c
5963
endif

arch/arm/src/stm32h5/hardware/stm32h56xxx_pinmap.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,32 @@
9898
#define GPIO_ETH_RMII_TXD1_2 (GPIO_ALT|GPIO_AF11|GPIO_PUSHPULL|GPIO_PORTG|GPIO_PIN12)
9999
#define GPIO_ETH_RMII_TXD1_3 (GPIO_ALT|GPIO_AF11|GPIO_PUSHPULL|GPIO_PORTG|GPIO_PIN14)
100100

101+
/* FDCAN */
102+
103+
#define GPIO_FDCAN1_RX_1 (GPIO_ALT | GPIO_AF9 | GPIO_PUSHPULL | GPIO_PORTA | GPIO_PIN11)
104+
#define GPIO_FDCAN1_RX_2 (GPIO_ALT | GPIO_AF9 | GPIO_PUSHPULL | GPIO_PORTB | GPIO_PIN8)
105+
#define GPIO_FDCAN1_RX_3 (GPIO_ALT | GPIO_AF9 | GPIO_PUSHPULL | GPIO_PORTD | GPIO_PIN0)
106+
#define GPIO_FDCAN1_RX_4 (GPIO_ALT | GPIO_AF9 | GPIO_PUSHPULL | GPIO_PORTE | GPIO_PIN0)
107+
#define GPIO_FDCAN1_RX_5 (GPIO_ALT | GPIO_AF9 | GPIO_PUSHPULL | GPIO_PORTH | GPIO_PIN14)
108+
#define GPIO_FDCAN1_RX_6 (GPIO_ALT | GPIO_AF9 | GPIO_PUSHPULL | GPIO_PORTI | GPIO_PIN9)
109+
#define GPIO_FDCAN1_RX_7 (GPIO_ALT | GPIO_AF9 | GPIO_PUSHPULL | GPIO_PORTI | GPIO_PIN10)
110+
111+
#define GPIO_FDCAN1_TX_1 (GPIO_ALT | GPIO_AF9 | GPIO_PUSHPULL | GPIO_PORTA | GPIO_PIN12)
112+
#define GPIO_FDCAN1_TX_2 (GPIO_ALT | GPIO_AF9 | GPIO_PUSHPULL | GPIO_PORTB | GPIO_PIN9)
113+
#define GPIO_FDCAN1_TX_3 (GPIO_ALT | GPIO_AF9 | GPIO_PUSHPULL | GPIO_PORTB | GPIO_PIN7)
114+
#define GPIO_FDCAN1_TX_4 (GPIO_ALT | GPIO_AF9 | GPIO_PUSHPULL | GPIO_PORTD | GPIO_PIN1)
115+
#define GPIO_FDCAN1_TX_5 (GPIO_ALT | GPIO_AF9 | GPIO_PUSHPULL | GPIO_PORTD | GPIO_PIN5)
116+
#define GPIO_FDCAN1_TX_6 (GPIO_ALT | GPIO_AF9 | GPIO_PUSHPULL | GPIO_PORTE | GPIO_PIN1)
117+
#define GPIO_FDCAN1_TX_7 (GPIO_ALT | GPIO_AF9 | GPIO_PUSHPULL | GPIO_PORTH | GPIO_PIN13)
118+
119+
#define GPIO_FDCAN2_RX_1 (GPIO_ALT | GPIO_AF9 | GPIO_PUSHPULL | GPIO_PORTB | GPIO_PIN5)
120+
#define GPIO_FDCAN2_RX_2 (GPIO_ALT | GPIO_AF9 | GPIO_PUSHPULL | GPIO_PORTB | GPIO_PIN12)
121+
#define GPIO_FDCAN2_RX_3 (GPIO_ALT | GPIO_AF9 | GPIO_PUSHPULL | GPIO_PORTD | GPIO_PIN9)
122+
123+
#define GPIO_FDCAN2_TX_1 (GPIO_ALT | GPIO_AF9 | GPIO_PUSHPULL | GPIO_PORTB | GPIO_PIN6)
124+
#define GPIO_FDCAN2_TX_2 (GPIO_ALT | GPIO_AF9 | GPIO_PUSHPULL | GPIO_PORTB | GPIO_PIN13)
125+
#define GPIO_FDCAN2_TX_3 (GPIO_ALT | GPIO_AF9 | GPIO_PUSHPULL | GPIO_PORTA | GPIO_PIN10)
126+
101127
/* Clocks outputs */
102128

103129
#define GPIO_MCO_0 (GPIO_ALT|GPIO_AF0|GPIO_PORTA|GPIO_PIN8)

0 commit comments

Comments
 (0)