Skip to content
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

Merged
merged 14 commits into from Mar 18, 2023
Merged

Conversation

bavison
Copy link

@bavison bavison commented Sep 12, 2022

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).

Ben Avison added 3 commits September 12, 2022 18:46
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`.
@HiFiPhile HiFiPhile self-assigned this Sep 13, 2022
Ben Avison added 8 commits September 13, 2022 18:00
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'.
@HiFiPhile
Copy link
Collaborator

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. I feel like most IAR users use traditional MCUs

@pigrew Could you take a look at changes in USBTMC class ?

Copy link
Owner

@hathach hathach left a 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.

@hathach hathach merged commit f1a859d into hathach:master Mar 18, 2023
68 checks passed
@kilograham
Copy link
Collaborator

actually this code

#define usb_hw_set ((usb_hw_t *) hw_set_alias(usb_hw))

is wrong (and likely won't actually compile on IAR)

It should read

#define usb_hw_set    ((usb_hw_t *) hw_set_alias_untyped(usb_hw))
#define usb_hw_clear  ((usb_hw_t *) hw_clear_alias_untyped(usb_hw))

(Note the hw_xxx_alias_untyped vs hw_xxx_alias)

@hathach
Copy link
Owner

hathach commented Mar 20, 2023

@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.

@kilograham
Copy link
Collaborator

indeed - that is no coincidence ;-) and yeah the change to this PR is a result of me making changes to what was merged there ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

5 participants