-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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(RA Host Portable): git rid of the IAR warnings for packed #2077
Conversation
The root problem is not packed support, you can read more in #431 In this case since USB registers are 16bit aligned, there is no need to put |
@HiFiPhile The workaround is suppressing the warnings, but sometimes you can not use it, for example: |
I'm agreed IAR has some problem handling packed struct, behavior of
Could you try to change packed keyword into bitfields level, such as:
|
@HiFiPhile Could you try to change packed keyword into bitfields level? I did, the warning is still there, but when I use __packed it is suppressing the warnings for sure. I have tested it. The commit in this PR is getting rid of the warnings for sure. The only I am thinking of, if there is a neater way to put it in |
behavior of attribute ((packed)) and __packed should be the same. I agree with you on this, but the compiler doesn't see it this way from my side. The compiler is not doing anything with this attribute ((packed)), maybe in the newer IAR compiler it is not supported or ignored, I don't know Edit: @HiFiPhile Alright, I figured it out, It was still showing me the warning because I left TU_ATTR_PACKED also on the higher level struct. Now it looks like it passing the warnings. |
In my test there is no more warning moving TU_ATTR_PACKED to the bitfield struct level. But since @hathach what's your opinion? |
Okay, I think I figured it out. It is a little bit strange but __packed on the higher struct level suppresses the warnings, but attribute ((packed)) only works on the bit field level, however it needs also to be removed from the higher level struct. To maintain the TU_ATTR_PACKED, I agree with Hathach that maybe it is better to put it on the bit field level and solve the problem. I will rework this PR. |
look good, though can we still keep the TU_ATTR_PACKED of the overal srtuct ? this is just to prevent any padding between sub-struct member ? |
For some reason, the compiler will keep the warnings, if I do that. This is why I have removed them |
I see, what I interperte is the bit-field struct is packed -> size = 2, however, since the global struct is not packed, it is techically valid if compiler inserted padding between 2 struct/union e.g to have each 4-byte aligned. Since the global packed throw warnings, would you mind adding the TU_VERIFY_STATIC() on the total struct size just in case future compiler cause issue with this. It is nice to have anyway, I could add those veriy myself if it is not convenient for you atm since the PR is good to merge already. |
Done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perfect, thank you
This is a daughter PR from PR#2063
I am using the -e flag, for IAR workbench users it is under :
Options/ C_C++ compiler/ Language 1 / Language conformance / Standard with IAR extensions
TU_ATTR_PACKED is not solving the compiler warnings, I thought it should be enough. However, I am using IAR compiler 9.1, which seems insufficient for these structs. When I use the __packed I am getting rid of the warnings
Here is an example given by IAR, which somehow makes it seems that only __packed is supported.
https://www.iar.com/contentassets/e20cfa542d1a4734aa6b234bea42f11a/example-5.pdf
Another link that led me to use __packed on these structs:
https://www.iar.com/knowledge/support/technical-notes/compiler/accessing-unaligned-data/