CyPins_ReadPin Bug Report (?)

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
jise_1327756
Level 1
Level 1

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?

0 Likes
1 Solution

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.

View solution in original post

0 Likes
10 Replies
ScottA_91
Employee
Employee
10 solutions authored 100 replies posted 50 replies posted

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.

0 Likes

Thanks.  Where can I file a case with support?  When I looked for that earlier, all I found was this community.

0 Likes

I think this is what you're looking for:

https://www.cypress.com/mycases

0 Likes

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

0 Likes

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.

0 Likes
AnkitaS_51
Employee
Employee
100 likes received 50 likes received 25 likes received

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.

0 Likes

Just comment out that #include.  Any code that may have referenced that has been removed.

Weird that it compiled OK on my system, though...

0 Likes

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

0 Likes

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.

0 Likes

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.

0 Likes