-
-
Couldn't load subscription status.
- Fork 117
fix compile warnings - HelioSpring, Strix, Mode2Flux packed alignment of 4 same as uint32 #986
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
fix compile warnings - HelioSpring, Strix, Mode2Flux packed alignment of 4 same as uint32 #986
Conversation
… of 4 same as uint32
867d491 to
71cbe24
Compare
|
Claude Sonnet 4.5 AI analysis: Analysis: IMU-F9001 Compile Warning Fix (PR #986)✅ Recommendation: SAFE TO MERGE - FIX IS ADVISABLESummaryThis PR fixes legitimate compiler warnings by adding The Change// Before:
} __attribute__ ((__packed__)) imufCommand_t;
// After:
} __attribute__ ((__packed__, aligned(4))) imufCommand_t;File: What Was FixedThe ProblemThe code was casting a packed struct (alignment=1) to imufCommand_t command; // alignment = 1 byte
command.crc = getCrcImuf9001((uint32_t *)&command, 11); // expects 4-byte alignmentThe Risks (Before Fix)
The Fix (After)
Impact Analysis
Addressing ConcernsQ: Does this change IMU-F communication bandwidth?A: NO. Still 52 bytes per transaction. The alignment only affects where the struct sits in local memory, not what bytes are transmitted over SPI. Q: What about the mismatch with IMU-F firmware?A: No problem.
Q: Could this break compatibility?A: NO. Verified:
Q: Why did it work before?A: Lucky! The compiler/OS likely allocated the struct on 4-byte boundaries anyway, but it wasn't guaranteed. This fix makes it guaranteed, preventing potential crashes. Technical DetailsMemory Layout (UNCHANGED)Key Point: Internal layout is IDENTICAL. Only the starting address requirement changed:
SPI Communication (UNCHANGED)The wire format is just bytes. Alignment is a memory placement property, not a wire protocol property. CRC CalculationThe CRC is calculated over 11 uint32_t words (44 bytes), excluding the FAST_CODE uint32_t getCrcImuf9001(uint32_t* data, uint32_t size) {
#ifdef USE_HAL_F7_CRC
return HAL_CRC_Calculate(&CrcHandle, data, size); // Requires aligned input
#else
CRC_ResetDR();
for(uint32_t x = 0; x < size; x++) {
CRC_CalcCRC(data[x]); // Reads uint32_t values
}
return CRC_GetCRC();
#endif
}STM32 CRC hardware requires 32-bit word aligned input ( Test VerificationCompile-Time TestsRuntime Test✅ PR author: "flashed unsoldered FC, still works"
Why This MattersSTM32 CRC Peripheral
ARM Cortex-M4/M7
Code Quality
ConclusionThe fix:
Your concerns are valid to raise, but analysis shows:
This PR should be approved and merged. 👍 Optional Follow-upConsider submitting a similar fix to the IMU-F repository for consistency: // In emuflight/imu-f/src/board_comm/board_comm.h
} __attribute__ ((packed, aligned(4))) imufCommand_t;This would improve consistency and fix the same potential issue on the IMU-F side (though not strictly necessary for compatibility). |
|
flew 2 good packs emuflight commit |
|
Question: What happens if we apply the aligned(4) fix to EmuFlight but NOT to IMU-F? Answer: ✅ COMPLETELY SAFE - No negative ramifications Key Findings Why This Works |
|
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. 📝 WalkthroughWalkthroughAdded a 4-byte alignment attribute to the Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
🔇 Additional comments (1)
Comment |
fixes:
BUT, maybe we do NOT want this: https://cs50.stackexchange.com/questions/1337/what-does-attribute-packed-do 🤷♂️
What are the ramifications of not doing it on both sides? https://github.com/emuflight/imu-f/blob/master/src/board_comm/board_comm.h#L41-L55
Summary by CodeRabbit