From 65b6a6b194909b07f0165bff14510e3f9af0c9d3 Mon Sep 17 00:00:00 2001 From: Jorge Guzman Date: Sun, 7 Apr 2024 10:28:30 -0300 Subject: [PATCH] stm32h7/linum-stm32h753bi: fix fdcan configuration Signed-off-by: Jorge Guzman --- .../boards/linum-stm32h753bi/index.rst | 20 +++++++++++++++++++ .../configs/socketcan/defconfig | 4 ++++ .../stm32h7/linum-stm32h753bi/include/board.h | 16 +++++++++------ .../linum-stm32h753bi/src/stm32_bringup.c | 10 ++++++++++ 4 files changed, 44 insertions(+), 6 deletions(-) diff --git a/Documentation/platforms/arm/stm32h7/boards/linum-stm32h753bi/index.rst b/Documentation/platforms/arm/stm32h7/boards/linum-stm32h753bi/index.rst index ff5e7dd75f130..bcf7064e6a014 100644 --- a/Documentation/platforms/arm/stm32h7/boards/linum-stm32h753bi/index.rst +++ b/Documentation/platforms/arm/stm32h7/boards/linum-stm32h753bi/index.rst @@ -873,3 +873,23 @@ tone This example demonstrates how to use PWM4 and Timer17 to play music using the Tone library and the board's buzzer. +socketcan +--------- + +This example demonstrates how to use the CAN-FD peripherals can0 and can1 with the SocketCAN protocol.:: + + # Configure the can0 and can1 to send messages + nsh> ifup can0 + ifup can0...OK + nsh> ifup can1 + ifup can1 ...OK + nsh> cansend can0 123#DEADBEEF + nsh> cansend can1 5A1#11.2233.44556677.88 + + # Reset the board and configure the can0 peripheral to receive messages + nsh> ifup can0 + ifup can0...OK + nsh> candump can0 + can0 051 [8] 00 11 22 33 44 55 66 77 + can0 051 [16] 00 11 22 33 44 55 66 77 88 99 AA BB CC DD EE FF + diff --git a/boards/arm/stm32h7/linum-stm32h753bi/configs/socketcan/defconfig b/boards/arm/stm32h7/linum-stm32h753bi/configs/socketcan/defconfig index 88c8bac48fb9e..d198a21f9ce94 100644 --- a/boards/arm/stm32h7/linum-stm32h753bi/configs/socketcan/defconfig +++ b/boards/arm/stm32h7/linum-stm32h753bi/configs/socketcan/defconfig @@ -35,6 +35,10 @@ CONFIG_DEBUG_NET_ERROR=y CONFIG_DEBUG_NET_INFO=y CONFIG_DEBUG_NET_WARN=y CONFIG_DEBUG_SYMBOLS=y +CONFIG_FDCAN1_ARBI_BITRATE=125000 +CONFIG_FDCAN1_DATA_BITRATE=1000000 +CONFIG_FDCAN2_ARBI_BITRATE=125000 +CONFIG_FDCAN2_DATA_BITRATE=1000000 CONFIG_FS_PROCFS=y CONFIG_INIT_ENTRYPOINT="nsh_main" CONFIG_INTELHEX_BINARY=y diff --git a/boards/arm/stm32h7/linum-stm32h753bi/include/board.h b/boards/arm/stm32h7/linum-stm32h753bi/include/board.h index 3d67f5c792165..b68233c9a9a74 100644 --- a/boards/arm/stm32h7/linum-stm32h753bi/include/board.h +++ b/boards/arm/stm32h7/linum-stm32h753bi/include/board.h @@ -366,8 +366,8 @@ /* RS485 DIR pin: PA15 */ -# define GPIO_UART4_RS485_DIR (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_100MHz|\ - GPIO_OUTPUT_CLEAR|GPIO_PORTA|GPIO_PIN15) +# define GPIO_UART4_RS485_DIR (GPIO_OUTPUT | GPIO_PUSHPULL | GPIO_SPEED_100MHz |\ + GPIO_OUTPUT_CLEAR | GPIO_PORTA | GPIO_PIN15) #endif @@ -422,13 +422,17 @@ /* FDCAN1 */ -#define GPIO_CAN1_RX (GPIO_CAN1_RX_3|GPIO_SPEED_50MHz) /* PD0 */ -#define GPIO_CAN1_TX (GPIO_CAN1_TX_3|GPIO_SPEED_50MHz) /* PD1 */ +#define GPIO_CAN1_RX (GPIO_CAN1_RX_4|GPIO_SPEED_50MHz) /* PH14 */ +#define GPIO_CAN1_TX (GPIO_CAN1_TX_4|GPIO_SPEED_50MHz) /* PH13 */ +#define GPIO_CAN1_STD (GPIO_OUTPUT | GPIO_PUSHPULL | GPIO_SPEED_100MHz |\ + GPIO_OUTPUT_CLEAR | GPIO_PORTI | GPIO_PIN2) /* PI2 */ /* FDCAN2 */ -#define GPIO_CAN2_RX (GPIO_CAN2_RX_2|GPIO_SPEED_50MHz) /* PB5 - D11 */ -#define GPIO_CAN2_TX (GPIO_CAN2_TX_2|GPIO_SPEED_50MHz) /* PB6 - D1 */ +#define GPIO_CAN2_RX (GPIO_CAN2_RX_1|GPIO_SPEED_50MHz) /* PB12 */ +#define GPIO_CAN2_TX (GPIO_CAN2_TX_1|GPIO_SPEED_50MHz) /* PB13 */ +#define GPIO_CAN2_STD (GPIO_OUTPUT | GPIO_PUSHPULL | GPIO_SPEED_100MHz |\ + GPIO_OUTPUT_CLEAR | GPIO_PORTE | GPIO_PIN3) /* PE3 */ /* QSPI Mapping */ diff --git a/boards/arm/stm32h7/linum-stm32h753bi/src/stm32_bringup.c b/boards/arm/stm32h7/linum-stm32h753bi/src/stm32_bringup.c index 0866d2312fdec..366acba1823d8 100644 --- a/boards/arm/stm32h7/linum-stm32h753bi/src/stm32_bringup.c +++ b/boards/arm/stm32h7/linum-stm32h753bi/src/stm32_bringup.c @@ -294,10 +294,20 @@ int stm32_bringup(void) #ifdef CONFIG_NETDEV_LATEINIT # ifdef CONFIG_STM32H7_FDCAN1 + + /* Enable and configure CAN1 */ + + stm32_configgpio(GPIO_CAN1_STD); + stm32_gpiowrite(GPIO_CAN1_STD, false); stm32_fdcansockinitialize(0); # endif # ifdef CONFIG_STM32H7_FDCAN2 + + /* Enable and configure CAN2 */ + + stm32_configgpio(GPIO_CAN2_STD); + stm32_gpiowrite(GPIO_CAN2_STD, false); stm32_fdcansockinitialize(1); # endif