jlaitine opened a new pull request, #18785:
URL: https://github.com/apache/nuttx/pull/18785
## Summary
DShot is a packet based serial protocol, used for controlling motor
controllers (ESCs), typically for drones.
I needed a dshot motor control for an i.MX93 based custom board, and decided
to make a full "traditional"
upper/lower half nuttx driver for it, for easy integration to the actual
application.
I am open to improvement requests for the upper-half / interface; the
interface presented here, however, works well for me for flying drone
integration.
This PR adds:
- a new generic drivers/timers/dshot.c upper-half driver
- an imx93 dshot lower half driver using imx9 flexio module
- initialization+registering of the dshot imx93-evk:nsh board as /dev/dshot0
The generic upper-half driver supports registering and configuring DShot, as
well as common protocol specific fuctionality to build the the 16-bit TX
packets and interpret the 20-bit RX packets (in bidirectional mode). The raw
packet sending and receiving is left for the lower-half.
For i.MX9, eight channels of DShot per flexio block are supported in:
- Normal mode in all DShot speeds, with telemetry request (uart response
needs to be handled outside of this driver)
- Bidirectional mode in all DShot speeds, with telemetry request & response
- Configurable to use either independent TX timers for each channel, or to
use a common TX timer for all channels to synchronize the output
- For bidirectional RX, each channel always uses an own RX timer.
In normal mode, the driver operates without any interrupts.
In bidirectional mode, the driver reconfigures the FlexIO timers (as needed)
and shifters from TX to RX in the interrupt handler, and reads out the raw
response packet.
## Impact
No impact to existing boards, new feature. First board supporting DShot
directly in NuttX level is the i.MX93
## Testing
The driver has been tested in both lab environment by scoping the lines and
communicating with ESCs, as well as running motors of a quadcopter and a
1-motor fixed wing flying devices.
1. Attaching 2 scope pictures:
First, the "1_ch_bidir_w_debug.png" shows a single channel "bidirectional
dshot" capture from a hexacopter + 2 debug lines. "Channel 0" is the line in
digital form. "Channel 1" is a debug channel showing RX clock timing for
bidirectional response reading. "Channel 2" is a gpio used to measure
initialization and interrupt times taken for the 6 channels per frame. The
"Channel 3" is just the line in analog form to monitor any clitches.
Second, the "4_ch_non_bidir.png" shows 4-channel output for a
"non-bidirectional dshot", running 4 motors at different speeds.
<img width="1348" height="568" alt="4_ch_non_bidir"
src="https://github.com/user-attachments/assets/f5322691-5087-4388-972a-d3204aca403c"
/>
<img width="934" height="298" alt="1_ch_bidir_w_debug"
src="https://github.com/user-attachments/assets/71785394-6163-40a4-b4bd-05e875c52957"
/>
2. Tested with flying devices:
There is no "pure nuttx" test bench for the driver, insted, the driver was
integrated into a PX4 system via wrappers used by existing code. A few places
how it was done:
https://github.com/tiiuae/px4-firmware/blob/bc0d500b0d6c8aa7550c4679c36b6f1a8497f5cb/platforms/nuttx/src/px4/nxp/imx9/dshot/dshot.c#L91
https://github.com/tiiuae/px4-firmware/blob/bc0d500b0d6c8aa7550c4679c36b6f1a8497f5cb/platforms/nuttx/src/px4/nxp/imx9/dshot/dshot.c#L148
Note for px4 people if someone is reading this, the PX4 baseline in question
is not the latest upstream one, so there are minor differencies in the wrappers.
The integrated driver was tested in flying the devices, and also checking
the telemetry data in px4 debug terminal (example below, the escs in question
only provide RPM output).
The actual ESC HW used for testing are older BLheli32 type ESCs and T-motor
F55A 4-in-1 ESCs (AM32 firmware).
```
nsh> listener esc_status
TOPIC: esc_status
esc_status
timestamp: 6067858470 (0.000719 seconds ago)
counter: 2074
esc_count: 4
esc_connectiontype: 5
esc_online_flags: 15 (0b1111)
esc_armed_flags: 15 (0b1111)
esc[0] (esc_report):
timestamp: 6067857069 (0.003602 seconds ago)
esc_errorcount: 0
esc_rpm: 128
esc_voltage: 0.00000
esc_current: 0.00000
esc_temperature: 0.00000
failures: 0
esc_address: 0
esc_cmdcount: 0
esc_state: 0
actuator_function: 101
esc_power: 0
esc[1] (esc_report):
timestamp: 6067857069 (0.028694 seconds ago)
esc_errorcount: 0
esc_rpm: 128
esc_voltage: 0.00000
esc_current: 0.00000
esc_temperature: 0.00000
failures: 0
esc_address: 0
esc_cmdcount: 0
esc_state: 0
actuator_function: 102
esc_power: 0
esc[2] (esc_report):
timestamp: 6067857069 (0.056597 seconds ago)
esc_errorcount: 0
esc_rpm: 128
esc_voltage: 0.00000
esc_current: 0.00000
esc_temperature: 0.00000
failures: 0
esc_address: 0
esc_cmdcount: 0
esc_state: 0
actuator_function: 103
esc_power: 0
esc[3] (esc_report):
timestamp: 6067857069 (0.084419 seconds ago)
esc_errorcount: 0
esc_rpm: 128
esc_voltage: 0.00000
esc_current: 0.00000
esc_temperature: 0.00000
failures: 0
esc_address: 0
esc_cmdcount: 0
esc_state: 0
actuator_function: 104
esc_power: 0
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]