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
uavcan: prevent system crash on stm32h7 when restarting uavcan node #23007
base: main
Are you sure you want to change the base?
Conversation
Previously, the can driver would be initialized again during the second init, causing system crash on STM32.
Oh sorry to hear this my PR caused this bug But actually there's a good reason to init the CAN driver Wouldn't it better to actually de-initialize the CAN driver in, avoiding the crash?
Because technically after |
@PetervdPerk-NXP Thanks for the quick response! Yeah, sorry, I was a bit quick and didn't look close enough at the entire commit history and PR to see that I just moved the initialization back to where it was, and that there was a good reason for the change in the first place 😅 According to the comment in the source code, there is no way to deinit the driver on STM32. We could maybe add a static flag that skips re-initialization on stm32? |
Or I guess the best would be to actually include a deinit method in the |
@PetervdPerk-NXP PX4-Autopilot/src/drivers/uavcan/uavcan_drivers/stm32h7/driver/src/uc_stm32h7_can.cpp Line 691 in 926e787
Edit: It seems like just letting |
86844f3
to
a5f6f71
Compare
It is because |
@davids5 any idea about this? |
Solved Problem
When restarting uavcan on STM32, for example by running
uavcan stop
uavcan start
, the system crashes.The issue was introduced with #20746, and affects 1.14 stable release and current main.
The issue occurs because the can driver is re-initialized when the node is restarted. The previous author noted in a comment that it shouldn't be re-initialized, but accidentally put the init call in the node initialization section of
UavcanNode::Run
. This made it run once per node restart instead of once per system boot.Solution
Move driver initialization to
UavcanNode::start
, where theCanInitHelper
is initialized, and where there is already a check if the can driver has been previously initialized.Now we can also avoid fetching the bitrate parameter twice.
Changelog Entry
For release notes:
Test coverage
Context
Crash dump from 1.14 when stopping and starting uavcan:
fault_2000_01_01_00_02_28.log