Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Variable "sec_mode" is used uninitialized at this location in the sourcecode

With IAR (EWARM) 8.50.9 the UART project in the SDK compiles fine.

After upgrading to IAR (EWARM) 9.10.1 or 9.10.2 I get compiler error:

 Error[Go029]: Variable "sec_mode" is used uninitialized at this location in the sourcecode. D:\2\IAR\nRF5_SDK_17.0.2_d674dde\examples\ble_peripheral\ble_app_uart\main.c 156 

Any help on what the problem is?

  • Hello,

    Error[Go029]: Variable "sec_mode" is used uninitialized at this location in the sourcecode.

    This is a common compiler error, and it says that you are using the sec_mode variable, without having initialized it - so it may be any random value at the time of use.
    Please look at the mentioned line 156 of your main.c. Make sure that the sec_mode variable is initialized before it is passed to a function.
    Please see this stack overflow ticket for more information about why you almost always should initialize your variables.

    If this is not the solution to your problem, please share the entire function which encompasses line 156 of your main.c file. Please use the Insert -> Code option when sharing code here on DevZone.

    Best regards,
    Karl

  • Karl,

    Thanks for the reply, but this sounds like a bug in the UART example code?

    I do not understand why earlier versions of IAR compiled OK, and past 9.xx shows the error, but it sounds a fix in the code is needed?

    Regards

  • Renix said:
    Thanks for the reply

    No problem at all, I am happy to help!

    Renix said:
    I do not understand why earlier versions of IAR compiled OK, and past 9.xx shows the error, but it sounds a fix in the code is needed?

    Could it be that the newer version is compiling with a different optimization level, for example?
    Or could it be that the newer IAR version uses a different compiler, or different compiler version than the previous version? This should all be specified in the changelog for the newer version, if it is the case.

    Do I also understand you correctly that you have made no changes to the BLE UART example prior to running it with the newer IAR version, and suddenly getting this error?

    Best regards,
    Karl

  • Karl,

    Correct, No changes. I use the example directly from the nRF5 SDK.

    I tried to compile with Optimization set to High, and then None, with the same result.

    The IAR error is a compiler issue, but the uninitialized Variable "sec_mode" could be fixed on the code side, (Nordic side)

    Regards 

  • Renix said:
    Correct, No changes. I use the example directly from the nRF5 SDK.

    Thank you for clarifying.

    Renix said:
    The IAR error is a compiler issue, but the uninitialized Variable "sec_mode" could be fixed on the code side, (Nordic side)

    Which compiler and compiler version if this IAR version using, and what did it use before?
    The sec_mode variable is actually populated by  the BLE_GAP_CONN_SEC_MODE_SET_OPEN macro, so I do not know why the IAR compiler suddenly complains about this. Does the changelog between the two versions mention any changes to the compiler, if so, which?

    Best regards,
    Karl

Related