PX4 / PX4-Autopilot

PX4 Autopilot Software
https://px4.io
BSD 3-Clause "New" or "Revised" License
8.32k stars 13.44k forks source link

[Bug] RC driver DSM / CRSF allocates ~ 1KB on heap #22085

Open PetervdPerk-NXP opened 1 year ago

PetervdPerk-NXP commented 1 year ago

Describe the bug

The CRSF and DSM RC driver pre-allocates ~ 1KB of RAM on the heap, which means that if DSM/CRSF is not in use this memory can't reclaimed. Please move this to the local stack so it's only allocated when either DSM or CRSF is used.

Furthermore I think Nuttx or PX4 already provide a CRC8 implementation, please re-use that instead of making custom one with it's own pre-allocated lut table.

To Reproduce

Build px4_fmu-v5 using make px4_fmu-v5 bloaty_ram

You'll get the following output.

     1.0%     462    /home/peter/src/FirmwareZenoh/src/lib/rc/dsm.cpp
     0.7%     300    /home/peter/src/FirmwareZenoh/src/drivers/rc/crsf_rc/CrsfParser.cpp
     0.6%     260    /home/peter/src/FirmwareZenoh/src/drivers/rc/crsf_rc/Crc8.cpp

Expected behavior

Memory isn't pre-allocated

Screenshot / Media

No response

Flight Log

N/A

Software Version

PX4 Main

Flight controller

px4_fmu-v5

Vehicle type

None

How are the different components wired up (including port information)

No response

Additional context

No response

dagar commented 1 year ago

I was planning to split the drivers into separate modules, then after that take another pass eliminating all the static data in lib/rc. https://github.com/PX4/PX4-Autopilot/pull/20829