From 536877cf0a6a5e5ea2852fbc67eaee23f2651076 Mon Sep 17 00:00:00 2001 From: CUAVcaijie Date: Sat, 29 Aug 2020 00:16:48 +0800 Subject: [PATCH] boards: add UAVCAN timer override mechanism and CUAV X7 add CAN (#15348) * X7Pro adds CAN driver * UAVCAN timer selection moved to default.cmake * Modify some details about @CUAVcaijie UAVCAN timer selection moved to default.cmake * Put some timer parameters to micro_hal.h from board_config.h. Fix all h7 boards Co-authored-by: honglang --- boards/cuav/nora/src/board_config.h | 3 +-- boards/cuav/x7pro/default.cmake | 5 +++-- boards/cuav/x7pro/nuttx-config/include/board.h | 3 +++ boards/cuav/x7pro/src/board_config.h | 3 +-- boards/cubepilot/cubeorange/src/board_config.h | 5 ----- boards/spracing/h7extreme/src/board_config.h | 3 +-- cmake/px4_add_board.cmake | 5 +++++ .../px4/stm/stm32h7/include/px4_arch/micro_hal.h | 13 +++++++++++++ src/drivers/uavcan/CMakeLists.txt | 3 +++ 9 files changed, 30 insertions(+), 13 deletions(-) diff --git a/boards/cuav/nora/src/board_config.h b/boards/cuav/nora/src/board_config.h index 2cb4f5f1a0..95145de892 100644 --- a/boards/cuav/nora/src/board_config.h +++ b/boards/cuav/nora/src/board_config.h @@ -153,8 +153,7 @@ /* High-resolution timer */ #define HRT_TIMER 3 /* use timer3 for the HRT */ #define HRT_TIMER_CHANNEL 3 /* use capture/compare channel 3 */ -#define STM32_RCC_APB1ENR STM32_RCC_APB1LENR -#define RCC_APB1ENR_TIM3EN RCC_APB1LENR_TIM3EN + #define HRT_PPM_CHANNEL /* T3C1 */ 1 /* use capture/compare channel 1 */ #define GPIO_PPM_IN /* PB4 T3C1 */ GPIO_TIM3_CH1IN_2 diff --git a/boards/cuav/x7pro/default.cmake b/boards/cuav/x7pro/default.cmake index 6893481234..23510712bc 100644 --- a/boards/cuav/x7pro/default.cmake +++ b/boards/cuav/x7pro/default.cmake @@ -9,7 +9,8 @@ px4_add_board( ROMFSROOT px4fmu_common BUILD_BOOTLOADER TESTING -# UAVCAN_INTERFACES 2 - No H7 or FD can support in UAVCAN + UAVCAN_INTERFACES 2 + UAVCAN_TIMER_OVERRIDE 2 SERIAL_PORTS GPS1:/dev/ttyS0 TEL1:/dev/ttyS1 @@ -56,7 +57,7 @@ px4_add_board( telemetry # all available telemetry drivers test_ppm tone_alarm -# uavcan - No H7 or FD can support in UAVCAN yet + uavcan MODULES airspeed_selector attitude_estimator_q diff --git a/boards/cuav/x7pro/nuttx-config/include/board.h b/boards/cuav/x7pro/nuttx-config/include/board.h index ce7e1b06c4..3c1208f617 100644 --- a/boards/cuav/x7pro/nuttx-config/include/board.h +++ b/boards/cuav/x7pro/nuttx-config/include/board.h @@ -193,6 +193,9 @@ #define STM32_RCC_D3CCIPR_SPI6SRC RCC_D3CCIPR_SPI6SEL_PLL2 /* SPI6 clock source */ #define STM32_RCC_D2CCIP2R_USBSRC RCC_D2CCIP2R_USBSEL_PLL3 /* USB 1 and 2 clock source */ #define STM32_RCC_D3CCIPR_ADCSEL RCC_D3CCIPR_ADCSEL_PLL2 /* ADC 1 2 3 clock source */ +#define STM32_RCC_D2CCIP1R_FDCANSEL RCC_D2CCIP1R_FDCANSEL_HSE /* FDCAN 1 2 clock source */ + +#define STM32_FDCANCLK STM32_HSE_FREQUENCY /* FLASH wait states */ #define BOARD_FLASH_WAITSTATES 2 diff --git a/boards/cuav/x7pro/src/board_config.h b/boards/cuav/x7pro/src/board_config.h index 6eac2cded9..5d068979e8 100644 --- a/boards/cuav/x7pro/src/board_config.h +++ b/boards/cuav/x7pro/src/board_config.h @@ -153,8 +153,7 @@ /* High-resolution timer */ #define HRT_TIMER 3 /* use timer3 for the HRT */ #define HRT_TIMER_CHANNEL 3 /* use capture/compare channel 3 */ -#define STM32_RCC_APB1ENR STM32_RCC_APB1LENR -#define RCC_APB1ENR_TIM3EN RCC_APB1LENR_TIM3EN + #define HRT_PPM_CHANNEL /* T3C1 */ 1 /* use capture/compare channel 1 */ #define GPIO_PPM_IN /* PB4 T3C1 */ GPIO_TIM3_CH1IN_2 diff --git a/boards/cubepilot/cubeorange/src/board_config.h b/boards/cubepilot/cubeorange/src/board_config.h index ded1c3597a..f0eaff6392 100644 --- a/boards/cubepilot/cubeorange/src/board_config.h +++ b/boards/cubepilot/cubeorange/src/board_config.h @@ -107,11 +107,6 @@ #define GPIO_nVDD_5V_HIPOWER_OC /* PE10 */ (GPIO_INPUT|GPIO_PULLUP|GPIO_PORTE|GPIO_PIN10) // VDD_5V_HIPOWER_OC /* Tone alarm output */ -#define STM32_RCC_APB1ENR STM32_RCC_APB1LENR /* This is stupid and only applies for H7 */ -#define STM32_RCC_APB1RSTR STM32_RCC_APB1LRSTR /* This is stupid and only applies for H7 */ -#define RCC_APB1ENR_TIM2EN RCC_APB1LENR_TIM2EN /* This is stupid and only applies for H7 */ -#define RCC_APB1ENR_TIM5EN RCC_APB1LENR_TIM5EN /* This is stupid and only applies for H7 */ -#define RCC_APB1RSTR_TIM5RST RCC_APB1LRSTR_TIM5RST /* This is stupid and only applies for H7 */ #define TONE_ALARM_TIMER 2 /* timer 2 */ #define TONE_ALARM_CHANNEL 1 /* PA15 TIM2_CH1 */ diff --git a/boards/spracing/h7extreme/src/board_config.h b/boards/spracing/h7extreme/src/board_config.h index d4bcea2a7e..1fd2a0c2b6 100644 --- a/boards/spracing/h7extreme/src/board_config.h +++ b/boards/spracing/h7extreme/src/board_config.h @@ -111,8 +111,7 @@ /* High-resolution timer */ #define HRT_TIMER 2 /* use timer2 for the HRT */ #define HRT_TIMER_CHANNEL 3 /* use capture/compare channel 3 */ -#define STM32_RCC_APB1ENR STM32_RCC_APB1LENR -#define RCC_APB1ENR_TIM2EN RCC_APB1LENR_TIM2EN /* This is stupid and only applies for H7 */ + /* RC Serial port */ diff --git a/cmake/px4_add_board.cmake b/cmake/px4_add_board.cmake index d385ca8903..cd3aa7d5b9 100644 --- a/cmake/px4_add_board.cmake +++ b/cmake/px4_add_board.cmake @@ -142,6 +142,7 @@ function(px4_add_board) IO BOOTLOADER UAVCAN_INTERFACES + UAVCAN_TIMER_OVERRIDE LINKER_PREFIX MULTI_VALUE DRIVERS @@ -221,6 +222,10 @@ function(px4_add_board) set(config_uavcan_num_ifaces ${UAVCAN_INTERFACES} CACHE INTERNAL "UAVCAN interfaces" FORCE) endif() + if(UAVCAN_TIMER_OVERRIDE) + set(config_uavcan_timer_override ${UAVCAN_TIMER_OVERRIDE} CACHE INTERNAL "UAVCAN TIMER OVERRIDE" FORCE) + endif() + # OPTIONS if(CONSTRAINED_FLASH) diff --git a/platforms/nuttx/src/px4/stm/stm32h7/include/px4_arch/micro_hal.h b/platforms/nuttx/src/px4/stm/stm32h7/include/px4_arch/micro_hal.h index 6beb18012c..515a3c47e3 100644 --- a/platforms/nuttx/src/px4/stm/stm32h7/include/px4_arch/micro_hal.h +++ b/platforms/nuttx/src/px4/stm/stm32h7/include/px4_arch/micro_hal.h @@ -38,6 +38,19 @@ __BEGIN_DECLS #define PX4_SOC_ARCH_ID PX4_SOC_ARCH_ID_STM32H7 + + +#define STM32_RCC_APB1ENR STM32_RCC_APB1LENR +#define STM32_RCC_APB1RSTR STM32_RCC_APB1LRSTR +#define RCC_APB1ENR_TIM2EN RCC_APB1LENR_TIM2EN +#define RCC_APB1ENR_TIM3EN RCC_APB1LENR_TIM3EN +#define RCC_APB1ENR_TIM5EN RCC_APB1LENR_TIM5EN +#define RCC_APB1ENR_TIM14EN RCC_APB1LENR_TIM14EN +#define RCC_APB1RSTR_TIM2RST RCC_APB1LRSTR_TIM2RST +#define RCC_APB1RSTR_TIM5RST RCC_APB1LRSTR_TIM5RST + + + #include #include #include //include up_systemreset() which is included on stm32.h diff --git a/src/drivers/uavcan/CMakeLists.txt b/src/drivers/uavcan/CMakeLists.txt index 8ecc63fdf8..1ee3ed8ba7 100644 --- a/src/drivers/uavcan/CMakeLists.txt +++ b/src/drivers/uavcan/CMakeLists.txt @@ -46,6 +46,9 @@ if(CONFIG_ARCH_CHIP) elseif(${CONFIG_ARCH_CHIP} MATCHES "stm32h7") set(UAVCAN_DRIVER "stm32h7") set(UAVCAN_TIMER 5) # The default timer is TIM5 + if (DEFINED config_uavcan_timer_override) + set (UAVCAN_TIMER ${config_uavcan_timer_override}) + endif() elseif(${CONFIG_ARCH_CHIP} MATCHES "stm32") set(UAVCAN_DRIVER "stm32") set(UAVCAN_TIMER 5) # The default timer is TIM5