-
Notifications
You must be signed in to change notification settings - Fork 13.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
X7Pro adds CAN driver #15348
X7Pro adds CAN driver #15348
Conversation
src/drivers/uavcan/CMakeLists.txt
Outdated
@@ -46,6 +46,11 @@ if(CONFIG_ARCH_CHIP) | |||
elseif(${CONFIG_ARCH_CHIP} MATCHES "stm32h7") | |||
set(UAVCAN_DRIVER "stm32h7") | |||
set(UAVCAN_TIMER 5) # The default timer is TIM5 | |||
if(CONFIG_CDCACM_VENDORSTR) | |||
if(${CONFIG_CDCACM_VENDORSTR} MATCHES "CUAV") | |||
set(UAVCAN_TIMER 2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good other than this part. The goal is to not have any vendor specific code outside of the board directory. We should add something to the board (boards/cuav/x7pro/default.cmake) that sets this.
Alternatively we could take a quick look at the other H7 boards to see if we can get away with changing the default timer on stm32h7.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes that works for now.
Later it might make sense to move this and UAVCAN_INTERFACES to board_config.h
and out of cmake entirely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do I need to do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dagar Hello, how is the progress?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dagar Do I need to modify it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a per board mechanism to set the UAVCAN timer or see if we can change the stm32h7 default.
Hi @CUAVcaijie , |
@ghulands |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As written this would break all the configurations. The approach should be to allow an override. If not all the cmake.xxxx files will have to set the UAVCAN_TIMER.
The other approach is to set UAVCAN_TIMER in the cmake.default, and to a test and set it if not not set in the 3 places you deleted it.
I like the approach with the override as the name says what it is dong.
boards/cuav/x7pro/src/board_config.h
Outdated
@@ -153,8 +153,11 @@ | |||
/* 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 STM32_RCC_APB1ENR STM32_RCC_APB1LENR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These 5 lines do not belong in board_config.h They belongs in the timer driver (preferred) or the micro_hal
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your reply,but could you tell me the exact file i need to add these 5 lines? I think mocro_hal is a common file ,should i change it ? Look forward to your reply.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about the H7 micro_hal? platforms/nuttx/src/px4/stm/stm32h7/include/px4_arch/micro_hal.h
Then build all the H7 targets and fix them as well.
cmake/px4_add_board.cmake
Outdated
@@ -221,6 +222,10 @@ function(px4_add_board) | |||
set(config_uavcan_num_ifaces ${UAVCAN_INTERFACES} CACHE INTERNAL "UAVCAN interfaces" FORCE) | |||
endif() | |||
|
|||
if(UAVCAN_TIMER) | |||
set(config_uavcan_timer_num_ifaces ${UAVCAN_TIMER} CACHE INTERNAL "UAVCAN TIMER" FORCE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
set(config_uavcan_timer_num_ifaces ${UAVCAN_TIMER} CACHE INTERNAL "UAVCAN TIMER" FORCE) | |
set(config_uavcan_timer_override ${UAVCAN_TIMER_OVERRIDE} CACHE INTERNAL "UAVCAN TIMER OVERRIDE FORCE) |
src/drivers/uavcan/CMakeLists.txt
Outdated
@@ -65,7 +62,7 @@ string(TOUPPER "${UAVCAN_DRIVER}" UAVCAN_DRIVER_UPPER) | |||
add_definitions( | |||
-DUAVCAN_${UAVCAN_DRIVER_UPPER}_${OS_UPPER}=1 | |||
-DUAVCAN_${UAVCAN_DRIVER_UPPER}_NUM_IFACES=${config_uavcan_num_ifaces} | |||
-DUAVCAN_${UAVCAN_DRIVER_UPPER}_TIMER_NUMBER=${UAVCAN_TIMER} | |||
-DUAVCAN_${UAVCAN_DRIVER_UPPER}_TIMER_NUMBER=${config_uavcan_timer_num_ifaces} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-DUAVCAN_${UAVCAN_DRIVER_UPPER}_TIMER_NUMBER=${config_uavcan_timer_num_ifaces} | |
-DUAVCAN_${UAVCAN_DRIVER_UPPER}_TIMER_NUMBER=${UAVCAN_TIMER} |
src/drivers/uavcan/CMakeLists.txt
Outdated
elseif(${CONFIG_ARCH_CHIP} MATCHES "stm32") | ||
set(UAVCAN_DRIVER "stm32") | ||
set(UAVCAN_TIMER 5) # The default timer is TIM5 | ||
endif() | ||
endif() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be
if (DEFINED config_uavcan_timer_override)
set (UAVCAN_TIMER ${config_uavcan_timer_override})
endif()
src/drivers/uavcan/CMakeLists.txt
Outdated
@@ -42,13 +42,10 @@ set(UAVCAN_PLATFORM "generic") | |||
if(CONFIG_ARCH_CHIP) | |||
if(${CONFIG_ARCH_CHIP} MATCHES "kinetis") | |||
set(UAVCAN_DRIVER "kinetis") | |||
set(UAVCAN_TIMER 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will break all the drivers. All of this needs to stay./
cmake/px4_add_board.cmake
Outdated
@@ -142,6 +142,7 @@ function(px4_add_board) | |||
IO | |||
BOOTLOADER | |||
UAVCAN_INTERFACES | |||
UAVCAN_TIMER |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UAVCAN_TIMER | |
UAVCAN_TIMER_OVERRIDE |
cmake/px4_add_board.cmake
Outdated
@@ -221,6 +222,10 @@ function(px4_add_board) | |||
set(config_uavcan_num_ifaces ${UAVCAN_INTERFACES} CACHE INTERNAL "UAVCAN interfaces" FORCE) | |||
endif() | |||
|
|||
if(UAVCAN_TIMER) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if(UAVCAN_TIMER) | |
if(UAVCAN_TIMER_OVERRIDE) |
@@ -45,7 +45,9 @@ if(CONFIG_ARCH_CHIP) | |||
set(UAVCAN_TIMER 1) | |||
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (DEFINED config_uavcan_timer_override) | |
set(UAVCAN_TIMER 5) # The default timer is TIM5 | |
if (DEFINED config_uavcan_timer_override) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To check your changes. Please build all the H7 targets.
use find boards/ -name defconfig | xargs grep CONFIG_ARCH_CHIP_STM32H7=y
to gee the list of what you have to build test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had changed it agian base on your suggestions ,could you please review it again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see why the build fails. Run 'make cubepilot_cubeorange_default' and fix the issues.
boards/cuav/x7pro/src/board_config.h
Outdated
@@ -153,8 +153,11 @@ | |||
/* 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 STM32_RCC_APB1ENR STM32_RCC_APB1LENR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about the H7 micro_hal? platforms/nuttx/src/px4/stm/stm32h7/include/px4_arch/micro_hal.h
Then build all the H7 targets and fix them as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comments.
src/drivers/uavcan/CMakeLists.txt
Outdated
@@ -45,6 +45,7 @@ if(CONFIG_ARCH_CHIP) | |||
set(UAVCAN_TIMER 1) | |||
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}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please indent this line. Also do you know How to squash the commits? Please squash the commits to the same files to one commit PER FILE. changed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh you also need to rebase this on master |
@davids5 I had change it and fix the issue of "Run 'make cubepilot_cubeorange_default'".Could you please review it again? Thanks! |
@gitfishup the rebase looks incorrect. Please check out master and cherry-pick, in order just your commits, If your remote for px4 is not called
Then open a new PR with the Same title add |
@davids5 How about this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gitfishup - Looking good - there are a few cosmetic changes.
@dagar any comments?
platforms/nuttx/src/px4/stm/stm32h7/include/px4_arch/micro_hal.h
Outdated
Show resolved
Hide resolved
platforms/nuttx/src/px4/stm/stm32h7/include/px4_arch/micro_hal.h
Outdated
Show resolved
Hide resolved
platforms/nuttx/src/px4/stm/stm32h7/include/px4_arch/micro_hal.h
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@CUAVcaijie @gitfishup - Thank you! This looks good. @dagar Please have a look and merge, when satisfied
There is one change requested by @dagar . Maybe he is waiting until this one is marked as solved? Because on the first look it seems that the work is not finished here 🤷♂️ |
Thanks everyone. |
* 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 <honglang@cuav.net>
Because TIM5 of X7 is used for PWM, CAN uses TIM2