Skip to main content
Visitor II
October 30, 2006
Question

Flash problem

  • October 30, 2006
  • 9 replies
  • 1423 views
Posted on October 30, 2006 at 13:52

Flash problem

    This topic has been closed for replies.

    9 replies

    yvonperrAuthor
    Visitor II
    October 30, 2006
    Posted on October 30, 2006 at 10:30

    Hi

    I am running the IAR IDE and I am trying to program 3 Words to flash B0F7. I am running from lower banks of B0. At address 0x030000 I have defined a table where 3 words must be written over at a latter time. However the rest of the table must remain intact so I cannot erase the sector. The 3 words are set to 0xFF when the program is written to Flash. I do disable the write protection of B0F7 prior to the writes. The peculiar thing is that if I step through the code the 3 words are programmed fine, but if I am running nothing gets programmed.

    Help !

    Visitor II
    October 30, 2006
    Posted on October 30, 2006 at 11:29

    Can you post your code here? One thing that can be happening is that you are not waiting for the program operation to finish.

    Regards,

    - mike

    yvonperrAuthor
    Visitor II
    October 30, 2006
    Posted on October 30, 2006 at 11:33

    Hi Mike

    Here is an extract of my code:

    I have tried WordWrite located both in RAM and Flash.

    __ramfunc void FLASH_MYWordWrite(u32 XtargetAdd, u32 Xdata)

    {

    // FLASH_WaitForLastTask();

    // set the Word Programming bit 'WPG' in the CR0 Reg

    FLASHR->CR0 |= FLASH_WPG_Mask;

    // Load the destination address in AR

    FLASHR->AR = XtargetAdd;

    // Load DATA to be programmed in DR0

    FLASHR->DR0 = Xdata;

    // Set the Write Mode Start bit 'WMS' in the CR0 Reg to Start Write Operation

    FLASHR->CR0 |= FLASH_WMS_Mask;

    // Wait until the write operation is completed

    // FLASH_WaitForLastTask();

    }

    unsigned char USB_Set_SerialNo( char *buf )

    {

    unsigned char success = 0;

    long address = 0x0030064;

    char tmp[20];

    int i, j, pos;

    long data1;

    if ( (strncmp( ''Set_SerialNo'', buf, 12)) == 0 )

    {

    success = 1;

    if ( strlen( buf ) != 20 )

    return( 2 );

    /* Disable the FLASH protection on Bank 0 sector 7 */

    FLASH_WritePrConfig (FLASH_B0F7,DISABLE);

    pos = 13;

    for ( j=0; j

    {

    i=0;

    tmp[i++] = buf[pos++];

    tmp[i++] = 0;

    tmp[i++] = buf[pos++];

    tmp[i++] = 0;

    memcpy( &data1, tmp, 4 );

    FLASH_WaitForLastTask();

    FLASH_MYWordWrite (address, data1) ;

    FLASH_WaitForLastTask();

    address +=4 ;

    }

    FLASH_WritePrConfig (FLASH_B0F7,ENABLE) ;

    }

    return( success );

    }

    Visitor II
    October 30, 2006
    Posted on October 30, 2006 at 12:03

    The code looks right. Just one question: is FLASH_WaitForLastTask() declared as __ramfunc?

    - mike

    yvonperrAuthor
    Visitor II
    October 30, 2006
    Posted on October 30, 2006 at 12:07

    Hi Mike

    No the FLASH_WaitForLastTask() is not define in RAM. However I will try it right now.

    Yvon

    yvonperrAuthor
    Visitor II
    October 30, 2006
    Posted on October 30, 2006 at 12:24

    Hi Mike

    Locating FLASH_WaitForLastTask() in Ram made no difference.

    Yvon

    yvonperrAuthor
    Visitor II
    October 30, 2006
    Posted on October 30, 2006 at 12:41

    Hi Mike

    By Locating both FLASH_WaitForLastTask() and FLASH_WordWrite() in RAM and using Bank 1 Sector 1 everything works properly. It still does not explain why I can't use Bank 0 Sector 7. And yes I am using an STR711FR2.

    Thanks

    Yvon

    Visitor II
    October 30, 2006
    Posted on October 30, 2006 at 13:31

    You should call FLASH_WaitForLastTask() from within FLASH_MYWordWrite(), otherwise the CPU steps out of the RAM function into a ROM function, the code of which is invalid during flash programming. Just uncomment FLASH_WaitForLastTask() at the last line of FLASH_MYWordWrite().

    - mike

    yvonperrAuthor
    Visitor II
    October 30, 2006
    Posted on October 30, 2006 at 13:52

    Hi Mike

    I did that and it now appear to work also in Bank0 Sector7.

    Thanks

    Yvon