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.

MSP430F5529: Internal info flash write failed when using USB example

Part Number: MSP430F5529

Hi,

I'm trying to read/write from/to Info D internal Flash area on the MSP430F5529.

When using the MSP430F55xx_flashwrite_02.c example, it works great but when I use the USB example (C1_LedOnOff) it seems not to work.

I'm using the C1_LedOnOff example as is with the below additional code at the beginning (for debug purpose):

void main (void)
{
    WDT_A_hold(WDT_A_BASE); // Stop watchdog timer

    unsigned long * Flash_ptrD;               // Initialize Flash pointer Seg D
    unsigned long FlashTmp;

    Flash_ptrD = (unsigned long *) 0x1800;    // Initialize Flash pointer
    FlashTmp = *Flash_ptrD;                       // Initialize Value
    FlashTmp++;
    FCTL3 = FWKEY;                            // Clear Lock bit
    FCTL1 = FWKEY+ERASE;                      // Set Erase bit
    *Flash_ptrD = 0;                          // Dummy write to erase Flash seg
    FCTL1 = FWKEY+BLKWRT;                     // Enable long-word write
    *Flash_ptrD = FlashTmp;                      // Write to Flash
    FCTL1 = FWKEY;                            // Clear WRT bit
    FCTL3 = FWKEY+LOCK;                       // Set LOCK bit
    while(1);                                 // Loop forever, SET BREAKPOINT HERE

    // Minumum Vcore setting required for the USB API is PMM_CORE_LEVEL_2 .
    PMM_setVCore(PMM_CORE_LEVEL_2);
    USBHAL_initPorts();           // Config GPIOS for low-power (output low)
    USBHAL_initClocks(8000000);   // Config clocks. MCLK=SMCLK=FLL=8MHz; ACLK=REFO=32kHz
    initTimer();           // Prepare timer for LED toggling
    USB_setup(TRUE, TRUE); // Init USB & events; if a host is present, connect

    __enable_interrupt();  // Enable interrupts globally
    
    while (1)
    {
        ...

Is there something that locks the FLASH Info area when using the USB example?

Thanks,

Itay

  • Hello Itay,

    The program looks just fine to me.  Segment A has a separate Lock A bit, but this doesn't exist for Segment D.  I don't see any mechanisms where the USB software could/should lock the Flash when using the USB example.  

    What did you do exactly? You imported a USB example, and basically copied over the Flashwrite_02.c example and it's not working the same?  

    Thanks,

    JD

  • Hi,

    Correct. This is exactly what I did.

    I think that it relates to the USB interrupts mechanism but when I try to write to the flash event before activating the USB, the write operation is failed (simply no write operation is done).

    Thanks,

    Itay

  • Hi JD,

    Do you think that you can try to reproduce the situation and assist to solve it?

    Many thanks,

    Itay

  • Managed to solve that issue.

    Just had to add (unsigned int *) to the Dummy write to erase Flash segment:

    void main (void)
    {
        WDT_A_hold(WDT_A_BASE); // Stop watchdog timer
    
        unsigned long * Flash_ptrD;               // Initialize Flash pointer Seg D
        unsigned long FlashTmp;
    
        Flash_ptrD = (unsigned long *) 0x1800;    // Initialize Flash pointer
        FlashTmp = *Flash_ptrD;                       // Initialize Value
        FlashTmp++;
        FCTL3 = FWKEY;                            // Clear Lock bit
        FCTL1 = FWKEY+ERASE;                      // Set Erase bit
        *(unsigned int *)Flash_ptrD = 0;                          // Dummy write to erase Flash seg
        FCTL1 = FWKEY+BLKWRT;                     // Enable long-word write
        *Flash_ptrD = FlashTmp;                      // Write to Flash
        FCTL1 = FWKEY;                            // Clear WRT bit
        FCTL3 = FWKEY+LOCK;                       // Set LOCK bit
        while(1);                                 // Loop forever, SET BREAKPOINT HERE
    
        // Minumum Vcore setting required for the USB API is PMM_CORE_LEVEL_2 .
        PMM_setVCore(PMM_CORE_LEVEL_2);
        USBHAL_initPorts();           // Config GPIOS for low-power (output low)
        USBHAL_initClocks(8000000);   // Config clocks. MCLK=SMCLK=FLL=8MHz; ACLK=REFO=32kHz
        initTimer();           // Prepare timer for LED toggling
        USB_setup(TRUE, TRUE); // Init USB & events; if a host is present, connect
    
        __enable_interrupt();  // Enable interrupts globally
        
        while (1)
        {
            ...
    

**Attention** This is a public forum