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

AP_HAL: clean up UART driver storage/access and legacy ordering #25589

Merged
merged 28 commits into from
Dec 18, 2023

Conversation

tpwrules
Copy link
Contributor

@tpwrules tpwrules commented Nov 21, 2023

Eliminates UB and saves 108 bytes on CubeOrangePlus. See commits for details.

No functional change. I did test this on a real board and confirm using a GPS that the port ordering is the same.

Remaining shadows of the legacy ordering:

  • TCP port numbers on SITL (changing will break users)
  • ESP32 UART indices (can't test, don't want to fiddle with)
  • SITL and Linux command line arguments (removing will break users, deprecated with warning)

Copy link
Contributor

@peterbarker peterbarker left a comment

Choose a reason for hiding this comment

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

LGTM.

It's progress (removing uartX as members is good), but there's obviously still more to do here.

Next step would probably be to push that mapping back down into each of the HALs, so the HALs can push the devices into here in a 1-1 order.

libraries/AP_HAL/HAL.h Outdated Show resolved Hide resolved
Copy link
Contributor

@tridge tridge left a comment

Choose a reason for hiding this comment

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

I want to get rid of the old mapping completely, just needs some work in HAL_SITL, HAL_Linux etc

@tpwrules tpwrules force-pushed the ap-hal-uart-cleanup branch 2 times, most recently from 4f3ef57 to cac5009 Compare November 21, 2023 16:46
@tpwrules
Copy link
Contributor Author

I want to get rid of the old mapping completely, just needs some work in HAL_SITL, HAL_Linux etc

I looked into this but the old mapping still is user-visible as command line options with those. Is it finally time for those options to be removed? That could break people's scripts.

@rmackay9
Copy link
Contributor

@tridge how do you feel about merging this now and then do the AP_HAL changes in a follow-up PR? Just thinking of scope creep and helping devs cut their teeth on this smaller change.

@tpwrules tpwrules force-pushed the ap-hal-uart-cleanup branch 3 times, most recently from 8948024 to c82077e Compare December 11, 2023 20:20
@tpwrules tpwrules changed the title AP_HAL: clean up UART driver storage/access AP_HAL: clean up UART driver storage/access and legacy ordering Dec 11, 2023
@tpwrules
Copy link
Contributor Author

tpwrules commented Dec 11, 2023

I spent some cathartic time with Ctrl+F and I think I've managed to eliminate virtually every trace of the old mapping. A couple things remain which might break users if removed. It shouldn't be much effort to remove them for good if desired.

@tridge
Copy link
Contributor

tridge commented Dec 11, 2023

@tpwrules wow, this is great! I've been putting this off for ages, and you did it exactly the way I wanted it done. I think you deserve for medal for taking this on.
We just need some testing of this on ChibiOS and SITL at least before merging. I can't spot any errors, but it is such a tricky conversion I think we need to do some careful testing

@tpwrules
Copy link
Contributor Author

Thank you very much for the kind words. Glad to be able to help.

I did test one serial port with a serial GPS on my own CubeOrange to make sure that ordering did not change. SITL should be covered by the CI. I did also launch and fly around a bit a SITL system on my computer using MAVProxy and sim_vehicle.py but was not particularly exhaustive.

@tpwrules
Copy link
Contributor Author

tpwrules commented Dec 12, 2023

Warnings have been added as discussed on the devcall. Should be ready to merge once you are happy with ChibiOS testing.

@@ -669,7 +669,6 @@ def start_antenna_tracker(opts):
def start_CAN_Periph(opts, frame_info):
"""Compile and run the sitl_periph"""

global can_uarta
Copy link
Contributor

Choose a reason for hiding this comment

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

Missed one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's the only place that name is referenced in the whole source code. I figured it was unused, so I just removed it.

SERIAL_ORDER has been around for a few years now and UART_ORDER is
rejected by the hwdef script, so support for UART_ORDER and associated
processing in the hwdef script is removed, along with the order
conversion script.
Fourth serial port (SERIAL2) added purely for consistency.
Leave the legacy command line arguments to avoid breaking users.
Legacy command line arguments are kept to avoid breaking users.

The vestigial `_tcp_client_addr` variable is removed.

Serial port status messages are updated to a slightly different format
to clarify the numbering scheme being used and prompt any external
consumers to update.
Also delete some unused variables and update the completions.
@tpwrules
Copy link
Contributor Author

Final rebase, mostly to clean up some super minor things and make CI green.

@tpwrules tpwrules requested a review from tridge December 13, 2023 17:27
@tridge
Copy link
Contributor

tridge commented Dec 18, 2023

@tpwrules I tested all uarts on cubeorange with no issues

@tridge tridge merged commit e460a19 into ArduPilot:master Dec 18, 2023
88 checks passed
@tpwrules tpwrules deleted the ap-hal-uart-cleanup branch December 18, 2023 22:08
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.

7 participants