Skip to content
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

Merged
merged 4 commits into from
Aug 28, 2020
Merged

X7Pro adds CAN driver #15348

merged 4 commits into from
Aug 28, 2020

Conversation

CUAVcaijie
Copy link
Contributor

Because TIM5 of X7 is used for PWM, CAN uses TIM2

@@ -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)
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
Can it be added like this?

Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Contributor Author

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?

Copy link
Contributor Author

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?

Copy link
Member

@dagar dagar left a 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.

@ghulands
Copy link
Contributor

Hi @CUAVcaijie ,
I pulled in these changes and tested locally on the x7. I wasn't able to get it to connect to the Neo v2 Pro. Is this expected?

@CUAVcaijie
Copy link
Contributor Author

CUAVcaijie commented Aug 10, 2020

Hi @CUAVcaijie ,
I pulled in these changes and tested locally on the x7. I wasn't able to get it to connect to the Neo v2 Pro. Is this expected?

@ghulands
Because Neo V2 Pro needs to assign node ID automatically, Px4 does not support it

@CUAVcaijie
Copy link
Contributor Author

@dagar @davids5 Can you review it again?

Copy link
Member

@davids5 davids5 left a 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.

@@ -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
Copy link
Member

@davids5 davids5 Aug 13, 2020

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

Copy link
Contributor

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.

Copy link
Member

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.

@@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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)

@@ -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}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
-DUAVCAN_${UAVCAN_DRIVER_UPPER}_TIMER_NUMBER=${config_uavcan_timer_num_ifaces}
-DUAVCAN_${UAVCAN_DRIVER_UPPER}_TIMER_NUMBER=${UAVCAN_TIMER}

elseif(${CONFIG_ARCH_CHIP} MATCHES "stm32")
set(UAVCAN_DRIVER "stm32")
set(UAVCAN_TIMER 5) # The default timer is TIM5
endif()
endif()

Copy link
Member

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()

@@ -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)
Copy link
Member

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./

@@ -142,6 +142,7 @@ function(px4_add_board)
IO
BOOTLOADER
UAVCAN_INTERFACES
UAVCAN_TIMER
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
UAVCAN_TIMER
UAVCAN_TIMER_OVERRIDE

@@ -221,6 +222,10 @@ function(px4_add_board)
set(config_uavcan_num_ifaces ${UAVCAN_INTERFACES} CACHE INTERNAL "UAVCAN interfaces" FORCE)
endif()

if(UAVCAN_TIMER)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (DEFINED config_uavcan_timer_override)
set(UAVCAN_TIMER 5) # The default timer is TIM5
if (DEFINED config_uavcan_timer_override)

Copy link
Member

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.

Copy link
Contributor

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.

Copy link
Member

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.

@@ -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
Copy link
Member

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.

Copy link
Member

@davids5 davids5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments.

@@ -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})
Copy link
Member

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davids5
Copy link
Member

davids5 commented Aug 20, 2020

Ahh you also need to rebase this on master

@gitfishup
Copy link
Contributor

@davids5 I had change it and fix the issue of "Run 'make cubepilot_cubeorange_default'".Could you please review it again? Thanks!

@davids5
Copy link
Member

davids5 commented Aug 21, 2020

@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 origin use that name instead.

git fetch origin
git checkout master
git checkout -b pr-can_x7pro-remix
git reset --hard origin/master
git cherry-pick e9d408b
git cherry-pick 5f85e5b
git cherry-pick 2413316
git cherry-pick d76167b

Then open a new PR with the Same title add Remix. In the description put X7Pro adds CAN driver #15348 continued here
then close this pr with a comment "Closed see <url of new PR>

@gitfishup
Copy link
Contributor

@davids5 How about this?

Copy link
Member

@davids5 davids5 left a 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?

Copy link
Member

@davids5 davids5 left a 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

@thopiekar
Copy link

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 🤷‍♂️
Hope it gets merged soon 😄

@dagar
Copy link
Member

dagar commented Aug 28, 2020

Thanks everyone.

@dagar dagar merged commit 536877c into PX4:master Aug 28, 2020
dagar pushed a commit that referenced this pull request Aug 28, 2020
* 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>
@CUAVcaijie CUAVcaijie deleted the can_x7pro branch January 21, 2021 08:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants