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.

CCE v3.1 Linker bug?

Code Composer's linker is unexpectedly adding a "RRCM.A #1, PC" assembly instruction into the compiled code when optimizing with --opt_level=0. This causes the program to execute an invalid flash location, crashing the program. The problem does not seem to occur (or I have not found it yet) with --opt_level=2. I have not tested it at other optimization levels.

The relevant C code I used was:

#define CMD0	(0x40+0)	/* GO_IDLE_STATE */
unsigned char send_cmd ( unsigned char, unsigned long );

unsigned char disk_initialize( unsigned char drv )
{
unsigned char ty;
... [some code here]
ty = 0;
if (send_cmd(CMD0, 0) == 1) {
... [some code here]
}

This is what the assembly looks like:

$C$DW$L$disk_initialize$6$E:
;* --------------------------------------------------------------------------*
$C$L22:    
	.dwpsn	file "../FatFs/mmc.c",line 279,column 2,is_stmt
;----------------------------------------------------------------------
; 279 | ty = 0;                                                                
;----------------------------------------------------------------------
        MOV.B     #0,r9                 ; [] |279| 
	.dwpsn	file "../FatFs/mmc.c",line 280,column 2,is_stmt
;----------------------------------------------------------------------
; 280 | if (send_cmd(CMD0, 0) == 1) {                   /* Enter Idle state */ 
;----------------------------------------------------------------------
        MOV.B     #64,r12               ; [] |280| 
        MOV.W     #0,r13                ; [] |280| 
        MOV.W     #0,r14                ; [] |280| 
$C$DW$90	.dwtag  DW_TAG_TI_branch
	.dwattr $C$DW$90, DW_AT_low_pc(0x00)
	.dwattr $C$DW$90, DW_AT_name("send_cmd")
	.dwattr $C$DW$90, DW_AT_TI_call
        CALL      #send_cmd             ; [] |280| 
                                          ; [] |280| 
        CMP.B     #1,r12                ; [] |280| 
        JNE       $C$L35                ; [] |280| 
                                          ; [] |280| 

However, the code that is linked and downloaded to my target looks like this:

         C$L22, C$DW$L$disk_initialize$6$E:
0x076a2:   4349                      CLR.B   R9
0x076a4:   407C       0040           MOV.B   #0x0040,R12
0x076a6:   0040                      RRCM.A  #1,PC
0x076a8:   430D                      CLR.W   R13
0x076aa:   430E                      CLR.W   R14
0x076ac:   12B0       8C44           CALL    #send_cmd
0x076b0:   935C                      CMP.B   #1,R12
0x076b2:   2073                      JNE     (C$L35)

That RRCM.A #1,PC was not in the compiler listing, it appears as though the linker added it unexpectedly.

Dan.

**Attention** This is a public forum