- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I recently encountered what looks like either a bug in the compiler or the generated code from PSoC Creator 4.0 (on a CY8C4124PVI-432).
As far as I know, I'm using the latest version of all the tools.
The bug is this:
I've defined a pin as a GPIO Input.
If I call CyPins_ReadPin(alias) then the generated code executes an extra "ldr r3,[r3]" - which usually causes an exception.
If I call alias_Read(), it works as expected.
I've attached an Archive of a sample project that demonstrates the problem.
If you look at the main.lst file, you'll see the following generated code:
29:main.c **** dummy = CyPins_ReadPin(Pin_1);
61 .loc 1 29 0
62 0024 0B4B ldr r3, .L3+4
63 0026 1B68 ldr r3, [r3]
64 0028 1B68 ldr r3, [r3] <--- extra instruction!
Meanwhile, the good code looks like this:
138:Generated_Source\PSoC4/Pin_1.c **** return (uint8)((Pin_1_PS & Pin_1_MASK) >> Pin_1_SHIFT);
142 .loc 1 138 0
143 0004 044B ldr r3, .L9
144 0006 1B68 ldr r3, [r3] <--- only one "ldr" here
Is this a known problem?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In your first post you have mentioned:
"If I call CyPins_ReadPin(alias) then the generated code executes an extra "ldr r3,[r3]" - which usually causes an exception.
If I call alias_Read(), it works as expected."
The alias that you are mentioning in CyPins_ReadPin(alias) is not same as used in alias_Read().
What I mean is CyPins_ReadPin(alias_0) and alias_Read() are equivalent.
It's a workaround only.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
So here's the code for each (based on your post and digging into CY_SYS_PIN_READ_PIN
Alias_Read() (uint8)((Pin_1_PS & Pin_1_MASK) >> Pin_1_SHIFT)
CyPins_Read() *(reg32 *)(Pin_1_PS) |= (0x01u << (Pin_1_SHIFT))
You're right in that it looks like there is something wrong here.
Please file a case with the support team.
As a work around, you could try the following:
#define MyCyPins_ReadPin(name) (name ## _Read())
Then call MyCyPins_ReadPin(Alias) instead. When this is fixed, you simply redefine your macro to be: (Granted the return value is a little different, make sure you check against 0 for false, not 0 for true.)
#define MyCyPins_ReadPin(name) (CyPins_ReadPin(name))
As you've seen in the assembly, there's no overhead in calling the function instead.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks. Where can I file a case with support? When I looked for that earlier, all I found was this community.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks. I'd found that page before - but under the Technical Support section, it says: "We've evolved from one-to-one technical support to a community model. Find answers verified by Cypress experts and interact with your peers to solve problems."
There is, however, an email address for "other questions" - so I'll try that...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sorry, I didn't realize that had changed.
I've talked with my contacts, this is a known issue. While easy to fix, and workaround, it is a lower priority at this point.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Can you please attach this header file "mcu_v897.h".I can't find this header file in the archive attached and it is giving build error in Creator4.2 because it is included in main.c.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Just comment out that #include. Any code that may have referenced that has been removed.
Weird that it compiled OK on my system, though...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Please use "dummy = CyPins_ReadPin(Pin_1_0);" instead of "dummy = CyPins_ReadPin(Pin_1);"
"Pin_1_0" is defined in Pin_1_aliases.h file.
This is not causing any exception, I checked in Creator4.2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks. That's what I said in my first post.
I wasn't looking for a fix. I was just making sure people (and Cypress) were aware of this bug.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In your first post you have mentioned:
"If I call CyPins_ReadPin(alias) then the generated code executes an extra "ldr r3,[r3]" - which usually causes an exception.
If I call alias_Read(), it works as expected."
The alias that you are mentioning in CyPins_ReadPin(alias) is not same as used in alias_Read().
What I mean is CyPins_ReadPin(alias_0) and alias_Read() are equivalent.
It's a workaround only.