6 Replies Latest reply on Jan 13, 2016 8:30 PM by user_352784942

    Moving to PSoC 5 from PSoC 3




      Very recently I ported and existing application from the PSoC 3 to the 5.  I must say it was amazingly easy to do.  Creator even properly assigned all the pins!  I have not had the chance to actually test the code as the PSoC 5 development board has not arrived.


      However I do have one question.  The Keil compiler had no hard burn with the following code:


      void set_params(float wpm,uint8 paddle,uint8 mode,uint8 spacing,float weight, uint8 lag,uint8 memory,


      uint8 l_sound,uint8 l_cw_mode,uint8 l_iambic_mode,float l_iambic_tuning,uint8 l_semi_breakin,uint8 l_tx_hold,uint8 l_semi_control)




      uint8 error;


      //uint8 is_written = 1;


      uint8 iambic_section;




      iambic_section = CyEnterCriticalSection();


      // This writes variable data to EEPROM




      error = EEPROM_ByteWrite(paddle,1u,EE_PADDLE_REGISTER);


      error = EEPROM_ByteWrite(mode,1u,EE_MODE_REGISTER);


      error = EEPROM_ByteWrite(spacing,1u,EE_SPACING_REGISTER);


      error = EEPROM_ByteWrite(lag,1u,EE_LAG_REGISTER);


      error = EEPROM_ByteWrite(memory,1u,EE_MEMORY_REGISTER);


      error = EEPROM_ByteWrite(l_sound,1u,EE_EXTERNAL_SOUND_REGISTER);


      error = EEPROM_ByteWrite(l_cw_mode,1u,EE_CW_MODE_REGISTER);


      error = EEPROM_ByteWrite(l_iambic_mode,1u,EE_IAMBIC_MODE_REGISTER);


      error = EEPROM_ByteWrite(l_semi_breakin,1u,EE_SEMI_BREAKIN);


      error = EEPROM_ByteWrite(l_semi_control,1u,EE_SEMI_CONTROL);


      error = EEPROM_ByteWrite(l_tx_hold,1u,EE_TX_HOLD);


      error = EEPROM_ByteWrite(((uint8) (weight * 100)),1u,EE_WEIGHT);


      error = EEPROM_ByteWrite(((uint8)(wpm)),1u,EE_WPM);


      error = EEPROM_ByteWrite(((uint8) (l_iambic_tuning / RATIO_FACTOR)),1u,EE_IAMBIC_TUNING);




      error = 0;






      The GCC compiler produces a warning that "error" has not been used:  "variable 'error' set but not used [-Wunused-but-set-variable]".  I'm confused as it does appear that error is used in the procedure.  What am I missing.





        • 1. Re: Moving to PSoC 5 from PSoC 3

          You assign a value to the variable error and in the next line you overwrite ist value without "using" the old one. This is what GCC sees and warns you for.


          You may suppress that warning by adding -Wunused-but-set-variable to the compiler flags in the build settings dialog.


          "The"  difference between PSoC3 and 5 is the CPU core and the lack of a real stack in the 8051





          • 2. Re: Moving to PSoC 5 from PSoC 3

            Hi Bob,


            Its been a while.  I appreciate the help.  Sorry, but I don't quite follow what you are saying.  Can you provide a code snippet that would not produce the warning?  I have this same warning in three other places in my code.





            • 3. Re: Moving to PSoC 5 from PSoC 3

              Hi Bob,


              OK, I get it.  Added this to the code as a test.


              test = error;


              Now the warning does not report for "error" but does report for test since it has been "set" but not "used.  Got it.  I will add -Wunused-but-set-variable to the build.  Honestly, I have never seen that warning before, with any of my Linux based code. 





              • 4. Re: Moving to PSoC 5 from PSoC 3



                error |= expression


                except for the first assignment. Has two advantages:

                • No warning
                • A collected error-value that might be tested and reacted on at the end of the function.




                • 5. Re: Moving to PSoC 5 from PSoC 3

                  The compiler is correct in warning you. All of the write calls assign the return value to 'error', but there is never a check what this return value actually is. Thats what compiler tells you - the variable is not used for anything meaningful.


                  Either you can skip the assignment (and remove the 'error' variable alltogether) or you do an actual check (e.g. by doing an error+=WRITE() call, and the check at the end if error is still 0).

                  • 6. Re: Moving to PSoC 5 from PSoC 3



                    Thanks for the help on this issue.  I have found this in the Cypress generated code:


                    /* To remove the compiler warning if errorCode not used. */


                    errorCode = errorCode;


                    I find that somewhat amusing for some reason :)