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

cross mob
pblemel
Level 4
Level 4
25 replies posted 25 sign-ins First like received

Hello, world!

I am seeing inconsistent behavior between two identical statements while debugging an application using PSoC Creator 4.4 on the M4 (Pioneer kit CYC6347BZI-BLD53).  In a nutshell, when I set a breakpoint and inspect a variable in the debugger after a mathematical operation, I do not see the correct result.  

 

 

int adxl_read_reg_multiple(adxl_spi_handle *spi, unsigned char reg,
                                  unsigned short count, unsigned char *val)
{
    reg = (reg << 1) | ADXL_SPI_RNW;  // ADXL_SPI_RNW = 1

    unsigned char r1 = 0;   
    r1 = (r1 << 1) | ADXL_SPI_RNW;
    
    return spi_write_then_read(spi, &reg, 1, val, count);
}

 

 

This function is called with the reg argument = 0.  Setting a breakpoint at the first statement, the debugger shows reg = 0 (as expected). Step over the statement, and the debugger still shows reg = 0  -- when the new value clearly should be 1!  Step over the same statement for r1, and the debugger shows r1 = 1 -- but reg = 0 for the same operation.  They should both be 1.

Somewhere in the chain between the compiler, M4, and debugger something is not right. I looked in startup_psoc6_01_cm4.S and the default stack size is 4K., so I don't think I'm running out of stack for a shallow call chain.

This call sequence is taken from the ADXL372 code from Analog Devices. The wrong register value ends up being sent to the chip as a result of this problem (a 0 instead of a 1). If I can figure out what's happening in this test case, hopefully the driver will work. I've removed the actual peripheral code, which isn't necessary to reproduce the issue. 

If anyone has any idea what's going on, I'd like to hear it. 

Respectfully,
Peter

  

 

0 Likes
1 Solution
ncbs
Moderator
Moderator
Moderator
500 replies posted 50 likes received 250 sign-ins

Hey @pblemel ,

Line 107 seems to be optimized out, and hence the desired operation wasn't being performed. I went ahead and set the compiler optimization to None and this worked for me. Now, I see both reg and r1 behave in the same way.

Steps: Right click on the project and click on "Build Settings". Set the compiler optimization to "None"

ncbs_3-1670229648614.png

Regards,
Nikhil

 

 

 

View solution in original post

0 Likes
1 Reply
ncbs
Moderator
Moderator
Moderator
500 replies posted 50 likes received 250 sign-ins

Hey @pblemel ,

Line 107 seems to be optimized out, and hence the desired operation wasn't being performed. I went ahead and set the compiler optimization to None and this worked for me. Now, I see both reg and r1 behave in the same way.

Steps: Right click on the project and click on "Build Settings". Set the compiler optimization to "None"

ncbs_3-1670229648614.png

Regards,
Nikhil

 

 

 

0 Likes