Repository navigation
Conversation
On most boards the processor can also connect a UART's TX or RX to one of the motor or servo pads. A port can now be moved there, from the Ports tab or with the new CLI command serialpad <port> <tx pad> <rx pad>, which gives a port to a board whose UART pads are taken, or puts a single-wire device (SmartAudio, Tramp, a Smart ESC) on the servo connector it is already plugged into. Each driver has a table of the pins every UART reaches (from Betaflight's, which follow the datasheets); the F4 and F7 drivers keep one alternate function per UART, so their tables only offer pins with that function. The choice is stored as the pin in a new parameter group, and applied before any port opens, only while the port has a function. A moved pad keeps its output number, so no other motor or servo moves. If the mixer drives a motor or servo on it, arming is blocked with a new PWM init error instead of that output silently going dead; the LED strip, beeper and PINIO just lose the pad. On by default where the flash is larger than 512 KB (F405, F745, F765, H7, AT32): about 2.5 to 3.4 KB of flash and 24 to 96 bytes of RAM.
These helicopter boards have few connectors, and the one labelled ESC is a pad UART1's TX can reach (PA9 on the NEXUS X and Vantac RF007, PB6 on the NEXUS). With USE_SERIAL_PADS and the Smart ESC driver turned on for them, a Smart ESC plugged into that connector works with UART1 assigned to it and `serialpad 0 5 0`. Both are off on F722 by default for flash; these three have room for them (94.4 to 97.0 % after, about 7 KB each).
|
ⓘ Qodo reviews are paused because the subscription is no longer active. Ask your workspace admin to reactivate the subscription to resume reviews. Manage billing |
|
You were right about #12087, the restrictions didn't make much sense. I reworked it: now any UART's TX or RX can go on any output pad the MCU can route it to. It's on for boards with more than 512 KB of flash (about 3 KB), plus the NEXUS boards. Is this closer to what you had in mind, @sensei-hacker? |
PR Summary by QodoRoute UART TX and RX through motor and servo output pads
AI Description
Diagram
High-Level Assessment
Files changed (28)
|
Code Review by Qodo
1.
|
|
RAM / Flash usage vs. base commit
See RAM/flash optimization guide for techniques to reduce usage. |
|
Test firmware build ready — commit Download firmware for PR #12143 251 targets built. Find your board's
|
`serialpad` alone now adds a line for each stored pad the UART is not using: the port has no function, the pad is not an output on this board, soft serial, an ADC input or another port uses that pin, or the change is waiting for a save. Serial.md lists those reasons; the firmware only marks the line, which costs about 200 bytes instead of 500 with the reasons in it. Only ports the board has accept a pad, own pin included.
A UART's TX or RX can now move to a motor or servo pad that the processor also connects to that UART, for any function, on any board with the flash for it. This replaces #12087, which did it for one UART on three boards, and only for a Smart ESC.
Some uses: a port on a board whose UART pads are all taken, or a single-wire device (SmartAudio, Tramp, a Smart ESC, SmartPort) on the servo connector it's already plugged into, with no soldering.
How it works
uartHardwaretables, which follow the datasheets' alternate function tables. F4 and F7 keep one alternate function per UART, so there a pin is offered only when it uses the UART's own function (the F765's extra AF1/AF4/AF6/AF12 pins only when the target already sets that function).serialpad <port> <tx pad> <rx pad>, one word likeserialpassthrough(the CLI would readserial_padasserial). Pads are numbered as in the Outputs tab, and 0 keeps the UART's own pin. It's included indiffanddump, and on its own it marks any stored pad the UART isn't using (Serial.md lists why that can happen).MSP2_INAV_SERIAL_PADS(0x2236) lists the pads each UART can reach and what each pad drives now.MSP2_INAV_SET_SERIAL_PAD(0x2237) sets one. The Configurator side is Ports: an output pad for a UART's TX or RX inav-configurator#2833: a Pins column in the Ports tab.PG_SERIAL_PAD_CONFIG, 1050). Its default is zero, the UART's own pins, so nothing changes for anyone who doesn't use it. The pin moves before any port opens, and only while the port has a function. A pin that another active port holds is refused.checkPwmTimerConflicts()already keeps them off the outputs.Where it's on
USE_SERIAL_PADSis on by default where the flash is larger than 512 KB: F405, F745, F765, H7 and AT32. That's 209 targets, and on 166 of them at least one UART can reach a pad. I counted with a script that crosses each target'stimerHardware[]with the tables.Nothing new runs from the scheduler. The ITCM on KAKUTEF7 and KAKUTEF7HDV can still move by up to 40 B from one build to the next (+40 B on KAKUTEF7 and 0 on KAKUTEF7HDV in this one): when code elsewhere changes, LTO sometimes stops inlining
gyroKalmanUpdate()intogyroFilter().F722 and F411 targets can opt in with a define in target.h. The second commit does that for the three boards #12087 was written for. On the NEXUS, NEXUS X and Vantac RF007 the connector labelled ESC is a pad UART1's TX reaches (PB6, PA9, PA9). The commit also turns on the Smart ESC driver there, so a Smart ESC on that connector works with UART1 assigned to it and
serialpad 0 5 0, as asked in #11184. Together that's about 7 KB of flash and 0.9 KB of RAM:Testing
Unit tests cover the pad numbering, the routing rules (soft-serial pins included), the CLI and MSP checks and the MSP list (all 629 pass).
Bench, TBS Lucid H7 Wing, with no wiring. A bench-only command (not in this PR) counted the edges on a pin while the UART sent four 0x55 bytes, and bit-banged "OK" on a pin with its internal pull resistors for the UART to read back:
serialpad 3 ...3 43 00 40 0Half duplex (
SERIAL_BIDIR, as SmartAudio and the Smart ESC use it) with TX on S3: 40 edges on PA0, and "OK" read back on the same pad; nothing on PB9. The list the board sends over MSP was UART2 on S5/S6, UART4 on S3/S4 and UART7 on S13/S14, with S3 to S6 reported as servos 1 to 4.Not tested, testing wanted
serialpad 0 5 0, and the ESC plugged into the ESC connector. The receiver has to be on another UART, since UART1 carries the ESC.Overlaps with open PRs
I test-merged this with every open PR from #12000 up that touches the same files. These conflict, all of them additions next to each other where both sides stay:
fc_init.c, whereserialPadsInit()moves withserialInit().pwm_mapping.c.#12090 is a draft test build that carries a copy of #12087.
PG id 1050 and MSP 0x2236/0x2237 skip numbers that open PRs already use (1048, 1049 and 0x2235).