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
Fixes for building with IAR toolchain #1639
Conversation
strings.h is not an ISO header file, so IAR generates fatal error Pe1696 'cannot open source file "strings.h"'. Even though strncasecmp isn't an ISO C library function, IAR's runtime library defines it, though it declares it in string.h instead.
IAR generates error Pe118 'a void function may not return a value'.
Some compilers don't support the GNU extension `typeof` so their definitions of `hw_set_alias` can't inherit their type from their argument, and the best we can do is have `hw_set_alias` act the same as `hw_set_alias_untyped`. This requires an explicit cast when the macro is used instead, otherwise IAR generates error Pe132 'expression must have pointer-to-struct-or-union type but it has type "void *"'. The same goes for `hw_clear_alias`.
This is a GCC extension, illegal in ISO C. IAR generates errors Pa152 'these operand types cannot be used here' and Pe852 'expression must be a pointer to a complete object type'. Replace with uint8_t*.
IAR generates warning Pe111 'statement is unreachable'. In a couple of cases, replace return statements with TU_ATTR_FALLTHROUGH; because some compilers apparently can't figure out that the return statements are unreachable but do whinge about an imagined fall-through without them!
IAR generates warning Pe188 'enumerated type mixed with another type'.
IAR generates warning Pa089 'enumerated type mixed with another enumerated type'.
This affects struct rspMsg in usbtmc_app.c (unconditionally) and uint8_t termChar in usbtmc_device.c (when NDEBUG is defined). IAR generates warning Pe550 'variable was set but never used'.
IAR generates warning Pe546 'transfer of control bypasses initialization of variable "invInvTag"'.
IAR generates warning Pa167 'the "fallthrough" attribute is not supported'. It doesn't generate warnings when one switch case falls through to another, so simply make TU_ATTR_FALLTHROUGH expand to an empty string. Also replace one instance of __attribute__ with the macro.
IAR generates warning Pe161 'unrecognized #pragma'.
fa95362
to
73f22e3
Compare
Thanks for your PR, most changes are good for me, especially explicit enum type conversion. I don't use RP2040 so I can't test these changes. @pigrew Could you take a look at changes in USBTMC class ? |
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.
Superb! thank you very much for the PR, since then I have made some changes to also fix IAR build for some stm32 but haven't try to compile with rp2040. The changes look great, I have synced with master and updated, will merge when ci passed.
actually this code
is wrong (and likely won't actually compile on IAR) It should read
(Note the |
@kilograham ah thanks, I haven't tried IAR with rp2040, will make PR per your suggestion. I saw rpi team is also doing IAR support within pico-sdk as well, nice timing. |
indeed - that is no coincidence ;-) and yeah the change to this PR is a result of me making changes to what was merged there ;-) |
I'm aiming to get TinyUSB to build with the IAR Embedded Workbench toolchain (I'm testing against Arm version 9.20.4) and specifically, I'm trying to build it as part of the Raspberry Pi Pico SDK. In doing so, I've identified a number of issues. Some of these are in rp2040-specific source files, but many others are in platform-neutral ones.
I've grouped the changes into a series of commits based upon the diagnostic generated by IAR. The first four are errors, and prevent the build from proceeding. The remainder are fixes for warnings (I'm more generally aiming to get the entire Pico SDK to build without warnings).