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.

[Bug Report] CCE v3 Compiler : Flash Write



Hello All.

I have some strange behaviour when trying to write byte in Flash Memory.

FlashWriteByte: copy (DataLen) Byte from DataPtr (RAM Memory) to Flashptr (Flash Memory)

Here is the code

--------------------------------------------------------------------------------------------------------------------------------

void FlashWriteByte(unsigned char *FlashPtr, unsigned int DataLen, unsigned char *DataPtr)
{
  unsigned int ByteQty;
  WDTCTL = WDTPW + WDTHOLD;  
  _DINT();
  FCTL3=FWKEY; //Lock=0
  FCTL1=FWKEY+WRT; //WRT=1
  for(ByteQty=0; ByteQty<DataLen; ByteQty++)
  {
  while((FCTL3&0x0008)==0) ; // flash memory write is busy  
  *FlashPtr++=*DataPtr++; // Program flash byte
  }  
  FCTL1=FWKEY; //WRT=0
  FCTL3=FWKEY+LOCK; //Lock=1
  _EINT();
}

--------------------------------------------------------------------------------------------------------------------------------

The problem lies here : *Flashptr++=*Dataptr++ 

By replacing this line with the 3 lines below:

*Flashptr=*Dataptr;

Flashptr++;

Dataptr++;

It works. I have no problem with IAR compiler.

  • Here is the assembly code for the loop

    *FlashPtr++=*DataPtr++; // Program flash byte

    ---------------------------------------------------------------

    0xcf0a: 411F 0004 MOV.W 0x0004(SP),R15
    0xcf0e: 4F7D MOV.B @R15+,R13
    0xcf10: 4F81 0004 MOV.W R15,0x0004(SP)
    0xcf14: 412E MOV.W @SP,R14
    0xcf16: 4E0F MOV.W R14,R15
    0xcf18: 531F INC.W R15
    0xcf1a: 4F81 0000 MOV.W R15,0x0000(SP)
    0xcf1e: 4DCE 0000 MOV.B R13,0x0000(R14)
    0xcf22: 5391 0006 INC.W 0x0006(SP)

    0xcf26: 9191 0002 0006 CMP.W 0x0002(SP),0x0006(SP)
    0xcf2c: 2BEB JLO (C$L1)

    ---------------------------------------------------------------

     

    Here is the assembly code for

    *Flashptr=*Dataptr;

    *Flashptr++;

    *Dataptr++

    ---------------------------------------------------------------

     0xcf0a: 411F 0004 MOV.W 0x0004(SP),R15
    0xcf0e: 412E MOV.W @SP,R14
    0xcf10: 4FEE 0000 MOV.B @R15,0x0000(R14)
    0xcf14: 5391 0000 INC.W 0x0000(SP)
    0xcf18: 5391 0004 INC.W 0x0004(SP)
    0xcf1c: 5391 0006 INC.W 0x0006(SP)

    0xcf20: 9191 0002 0006 CMP.W 0x0002(SP),0x0006(SP)
    0xcf26: 2BEE JLO (C$L1)

    ---------------------------------------------------------------

     

     

     

  • What version of the Code Generation Tools are you using?   You can find the number on the TI Build Settings under the Project Properties.

  • Code Generation tools version 3.0.1

     

  • I asked the dev. team about this and they said the following:

    CCE developer said:

    Well, I don't really understand everything going on here.  It seems that you (or the customer) think that for an expression "*p1++ = *p2++;" those post-increments of the pointer should happen in some order.  The IAR compiler does that way, why not the TI compiler.  Well, actually, those post-increments can be done in any order.  Here is more about that:   http://c-faq.com/expr/ieqiplusplus.html

     

     

  • Thanks for having asked to dev.Team .

    Obviously they are right and I was wrong.

    And I learned ..

     

     

     

**Attention** This is a public forum