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.

HALCoGen bug report (het.c module for RM42)

Other Parts Discussed in Thread: HALCOGEN

Hi,

I think I've spotted a possible use of an uninitialized variable in pwmSetSignal from the HALCoGen-generated code for the HET peripheral (het.c line 1924+1925 on my system, YMMV). The code below checks if parameter 1 is hetRAM1 and sets pwmPeriod accordingly. The last two lines of the function use the variable regardless. 

In het_reg.h both hetRAM1 and hetRAM2 are defined, so this looks to me like a regular bug.


#define hetRAM1 ((hetRAMBASE_t *)0xFF460000U)

#define hetRAM2 ((hetRAMBASE_t *)0xFF440000U)


The code in question is pasted here: http://pastie.org/8249533

Suspected bug is on lines 30-31 and can be triggered if pwmSetSignal is called with hetRAM2 as parameter 1.

I'm using HALCoGen 03.05.00 and generating code for the RM42L432PZ.

EDIT: HALCoGen 03.06.00 seems to contain the same use-before-initialization bug.

  • Hi Mikkel,

    Sorry for the delay.  I've referred your HalCoGen issue to our subject matter expert who will get back to you soon.

    Paul B.

  • Hi Mikkel,

    Sorry, for some reason I cannot access the link.

    Could you please attach the HALCoGen project file, ( .hcg + .dil).

  • 4885.het_test - 19-08-2013.zip

    I've zipped the .hcg and the .dil files and attached to this post.

    I've seen the suspected bug in all the code I've been generating for my RM42L43, so I think you should be able to see it in whatever code you might try to generate yourself :)

    As of now (3:24PM GMT+1) the link is working here at least, so you should be able to see the code generated. I've attached the generated code below so you can copy/paste and auto-indent it if all else fails :)


    void pwmSetSignal(hetRAMBASE_t * hetRAM, uint32 pwm, hetSIGNAL_t signal)
    {
        uint32 action;
        uint32 pwmPeriod;
        uint32 pwmPolarity;
        
        if(hetRAM == hetRAM1)
        {
    	    pwmPeriod = (uint32)((signal.period * 1000.0) / 640.000) << 7U;
            pwmPolarity = s_het1pwmPolarity[pwm];
        }
        else
        {
        }
        if (signal.duty == 0U)
        {
            action = (pwmPolarity == 3U) ? 0U : 2U;
        }
        else if (signal.duty >= 100U)
        {
            action = (pwmPolarity == 3U) ? 2U : 0U;
        }
        else
        {
            action = pwmPolarity;
        }
    
        hetRAM->Instruction[(pwm << 1U) + 41U].Control = ((hetRAM->Instruction[(pwm << 1U) + 41U].Control) & (~(0x00000018U))) | (action << 3U);
    	/*SAFETYMCUSW 96 S MR:6.1 <REVIEWED> "Calculations including int and float cannot be avoided" */
        hetRAM->Instruction[(pwm << 1U) + 41U].Data = (uint32)((pwmPeriod * signal.duty) / 100.0) + 128U;
        hetRAM->Instruction[(pwm << 1U) + 42U].Data = pwmPeriod - 128U;
    }
  • Hi Mikkel,

    Device RM42Lxx there is no HET2, you should not pass the parameter hetRAM2. The driver was written in generic to support all device varients hence you see code structed like this.
    I will definetly give this feedback to HALCogen team, to make sure no HET2 references are in the RM42Lxx varient

  • Thanks for clearing that up :) It was flagged by my static analysis tool, and I just wanted to let you know :)