This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/MSP-EXP432P4111: #2623-D (ULP 5.4) Detected an assignment to a type with size less than int. To avoid unnecessary sign extension, use int-sized types for local varaibles and convert to smaller types for static storage.

Part Number: MSP-EXP432P4111

Tool/software: Code Composer Studio

on Linux 16.04 and CCS Version: 8.0.0.00016, MSP-EXP432P4111

The following code give a ULP 5.4 warning where count is incremented:

#include "msp.h"

uint16_t testResult = 0;
void main(void)
{
    uint8_t count = 0;
    WDT_A->CTL = WDT_A_CTL_PW | WDT_A_CTL_HOLD;        // stop watchdog timer

    while (1)
    {
        count++;
        if (count == 3)
        {
            testResult = 1;
        }
    }
}

What does this mean ? How could I improve the code to honour the advice ?

Is this the same issue as this ?

Regards

Peter

  • Yes, it's pretty much the same as in the other article. You can:
    1) Change "count" to be a "uint32_t" (since the Cortex-M4 is 32-bit) or
    2) Disable ULP 5.4 ("Show Build settings/ULP").
  • I have compared the dissambly.

    This is the result when the warning is shown (uint8):

    And this is with a unit32_t type that suppresses the warning:

    Basically, the opcodes

    ldr and str ( unit32_t) are replaced with ldrb and strb. In either case, 2 cycles are required, with possible optimization to one cycle.

    So does the warning make sense in this case ?

    Regards

    Peter

  • That would be a question for the ULP Advisor designers.
  • Peter Vittali said:
    The following code give a ULP 5.4 warning where count is incremented:

    To understand why this happens, consider that the expression count++, when fully expanded to show all the implicit type conversions, is ...

    count = (uint8_t)((int)count + 1);

    The addition operation is only defined for int, so count is converted to int.  Next, the addition occurs.  Next, the result is converted to uint8_t.  Finally, the result is assigned to count.  It is the conversion from int to uint8_t which triggers the ULP 5.4 diagnostic.

    There are a few ways to fix this.  I recommend changing the type of count from uint8_t to uint_fast8_t.  This is another type defined in stdint.h.  It is the fastest type which has at least 8 bits.  For ARM, this is a 32-bit unsigned int.  32-bits because that is the size of a register.  This change avoids the implicit conversions, and the ULP diagnostic.

    Thanks and regards,

    -George

  • Very good, thank you !

    Regards Peter

**Attention** This is a public forum