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.

Compiler/TMS320F280049: ADC result access issue with the opt_for_speed

Part Number: TMS320F280049

Tool/software: TI C/C++ Compiler

My customer reported an issue with F280049 regarding the optimization for opt_for_speed. They found the ADC result was not available in the watching window with the emulation mode, using the --opt_for_speed=0. When changing --opt_for_speed to 2, it worked. The --opt_level is OFF in the project. 

And it showed that PREAD instruction was created with -opt_for_speed =0, to replace two MOV instructions that use the AL register. That makes us confused. 

The compiler team has proposed a workaround to solve the issue, that removing the option -mt(--unified_memory), and the PREAD instructions are not generated. Could you please help further check why PREAD caused the issue? Thank you.

  • Aki,

    Aki Li said:
    They found the ADC result was not available in the watching window with the emulation mode

    Aki Li said:
    And it showed that PREAD instruction was created with -opt_for_speed =0, to replace two MOV instructions that use the AL register. That makes us confused. 

    The PREAD/PWRITE instruction uses the program bus to access one of the operands using the XAR7 register. The peripheral registers are not accessible via the program bus, thus if XAR7 is used, the access will return 0. (Note: I see that this information is not in the data sheet. It should be, and I will file a literature bug.)

    Something to check is that the variable used indicate the ADC result register is defined as volatile.  If they are not volatile, then change them to be volatile.

    There are two reasons for this:

    1. The hardware can change the value of the register and the C environment needs to know this.
    2. Volatile will tell the compiler to not use the program bus to access the registers. Thus PREAD/PWRITE instructions will be avoided. This is mentioned in the compiler guide briefly in the description of the --unified_memory switch.

    Please confirm if this matches the customer case. 

    best regards,

    Lori

  • Lori,

    Thank you for the detailed answers. So, the variable used to indicate the ADC result register will be 0, right? We thought it might only affect the watching window before, if it is the case, that will bring issues for their system.

    I will further whether they are using volatile.

    Besides, we do need to understand whether there are any other similar issues caused by option -mt. Are all the peripheral registers not accessible with PREAD instruction? Is option -mt necessary to be enabled for F280049?

  • Aki Li said:
    So, the variable used to indicate the ADC result register will be 0, right? We thought it might only affect the watching window before, if it is the case, that will bring issues for their system.

    Yes, it would cause issues with the system if PREAD/PWRITE is used to access any peripheral register.  There are two operands for these instructions.  The one that uses the program buss is the operand tied to the XAR7 pointer.  If XAR7 points to any peripheral register for these instructions, then it will read zero.  Volatile should prevent the compiler from doing this. 

    Aki Li said:
    Besides, we do need to understand whether there are any other similar issues caused by option -mt. Are all the peripheral registers not accessible with PREAD instruction? Is option -mt necessary to be enabled for F280049?

    -mt will help in any case where two operands are in RAM.  XAR7 addressing is used for things like a MAC instruction, as an example.  In this case it works perfectly because both operands are in RAM. 

    I think the CAN data ram may only be accessible by the data bus.  I will need to check on this. 

    Regards

    Lori

  • Lori,

    Thank you for the comments. Could you please help further check what kinds of  peripherals are allocated only in data memory? Then we will make sure customers use the volatile format for the related variables.  I think we do need to highlight this as a part of the optimization guide. 

  • Aki,

    Yes.  I am checking with owners of the datasheet to sort this out and will also file a request to add this to the optimization guide. 

    Best Regards

    Lori

  • Aki,

    I forgot to ask if the customer has checked to see if volatile was used for access of the result registers?

    Also, the optimization guide already mentions that volatile should be used when accessing peripheral registers since the hardware can change their value.  It doesn't mention the data-space issue which I will file a request to add. 

    http://software-dl.ti.com/C2000/docs/optimization_guide/phase1/volatile.html?highlight=volatile

    Regards

    Lori

  • Lori,

    Customer did not use volatile before, and will further check whether it will help. 

    We need your help to check what else registers will to be taken care. They mentioned EPWM registers also showed the same issue before.

  • Aki,

    All peripheral registers should be volatile. 

    Best Regards

    Lori