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/TMS320F280049C: Inefficient program memory use in Driverlibs?

Part Number: TMS320F280049C


Tool/software: Code Composer Studio

Hi,

I ran out of RAM (had to change the linker file to assign more) so I checked the memory usage an found that the eCAP initialization took up 648 words...that's a lot for a couple lines of code. I started to wonder if this might be caused by the use of driver lib and replaced a driverlib command with a bitfield command:

ECAP_disableInterrupt(ECAP1_BASE,
     (ECAP_ISR_SOURCE_CAPTURE_EVENT_1 |
     ECAP_ISR_SOURCE_CAPTURE_EVENT_2 |
     ECAP_ISR_SOURCE_CAPTURE_EVENT_3 |
     ECAP_ISR_SOURCE_CAPTURE_EVENT_4 |
     ECAP_ISR_SOURCE_COUNTER_OVERFLOW |
     ECAP_ISR_SOURCE_COUNTER_PERIOD |
     ECAP_ISR_SOURCE_COUNTER_COMPARE));
ECAP_clearInterrupt(ECAP1_BASE,
     (ECAP_ISR_SOURCE_CAPTURE_EVENT_1 |
     ECAP_ISR_SOURCE_CAPTURE_EVENT_2 |
     ECAP_ISR_SOURCE_CAPTURE_EVENT_3 |
     ECAP_ISR_SOURCE_CAPTURE_EVENT_4 |
     ECAP_ISR_SOURCE_COUNTER_OVERFLOW |
     ECAP_ISR_SOURCE_COUNTER_PERIOD |
     ECAP_ISR_SOURCE_COUNTER_COMPARE));

became:

EALLOW;
     ECap1Regs.ECEINT.all = 0;
     ECap1Regs.ECCLR.all = 1;
EDIS;

And the memory usage went from 648 words to 645 words. The EALLOW and EDIS instructions take up 2 words but I could bundle them together with all EALLOW protected instructions to trim that down and not repeat them for every instruction set. If this holds true for the rest of the instructions I could reduce codesize by 30-40% just by replacing instructions. 

Is this an issue of my compiler settings or are the driverlib instructions just that inefficient with memory? Because at the rate I am going, I am going to run out of RAM at 25% of the planned program and will have to move this thing to flash and I really do not want to keep writing into flash every time I want to check the effects of an instruction change.

Thanks in advance

Peter

  • Hi Peter,

    The compiler cancels out an EDIS instruction immediately followed by an EALLOW instruction. Since these functions are inline, the last EDIS instruction in the disable function and the first EALLOW instruction in clear function will be cancelled out.

    Regards,

    Veena

  • Hi Peter,

    The reason why you see a difference is, the driverlib functions does a read-modify-write to the ECAP registers. Whereas in case of the bitfield code you mentioned above, does direct writes to the registers. Additional cycles is spent during the reading of registers in case of driverlib.

    Regards,

    Veena

  • So, just to make sure I got this right:

    It's not a compiler setting and it's not my code. The driverlib instructions require more memory by default because they take more steps for the same task. Correct?

  • Hi Peter,

    In this case, the driverlib and the bitfield code is not doing the same task. One does read-modify-write and the other does just write.

    The driverlib function does a read modify write to the ECAP registers-> reg &= value. 

    The bitfield code is directly writing to the register without reading the current value -> reg = value.

    The 1st code will consume more cycles, no matter you use driverlib or bit field code. In this case since your are disabling all the interrupts, you can directly write to the registers without reading it. The equivalent driverlib code would be  HWREGH(ECAP1_BASE + ECAP_O_ECEINT) = 0;. This should take the same code size as the bit field code ECap1Regs.ECEINT.all = 0;

    Regards,

    Veena