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.

CCS/MSP430F6736: Programming Example for "FlashCtl" API in driverlib

Part Number: MSP430F6736

Tool/software: Code Composer Studio

I just started to work on the flash functionallity of the MSP430F6736. I planned on using the API functions of the driverlib and stumbled upon the missing or more like incorrect programming example on site 193 of "MSP430F5xx_6xx_DriverLib_Users_Guide-2_91_11_01.pdf".

20.3 Programming Example
The following example shows some flash operations using the APIs
do{
   FlashCtl_eraseSegment(FlashCtl_BASE,   (unsigned char *)INFOD_START);

   status = FlashCtl_performEraseCheck(FlashCtl_BASE,   (unsigned char *)INFOD_START,   128);
}while(status == STATUS_FAIL);

//Flash write
FlashCtl_write32(FlashCtl_BASE,calibration_data,(unsigned long *)(INFOD_START),1);


The first function is in both the seperate API examples before and the actual driverlib include file given as:


void FlashCtl_eraseSegment (uint8_t  flash_ptr );


It seems that the code example is wrong. If so, could you correct this fault please? Thank you in advance.

  • Hello,

    Thank you for your post. I'm a little confused about your question. Looking at page 193 in the MSP430 DriverLib for MSP430F5xx_6xx Devices user's guide and at the four "flashctl" DriverLib code examples, I'm not seeing an issue. The memory is erased before the write.

    GEDprogrammed said:
    The first function is in both the seperate API examples before and the actual driverlib include file given as:

    I'm not sure what this means. Are you saying that the code for the "FlashCtl_eraseSegment" function is missing in the 'flashctl.h' file? Did you see the "FlashCtl_eraseSegment" code in the 'flashctl.c' file?

    <snippet from 'flashctl.c'>

    void FlashCtl_eraseSegment ( uint8_t *flash_ptr){
        //Clear Lock bit
        HWREG16(FLASH_BASE + OFS_FCTL3) = FWKEY;
    
        //Set Erase bit
        HWREG16(FLASH_BASE + OFS_FCTL1) = FWKEY + ERASE;
    
        //Dummy write to erase Flash seg
        *flash_ptr = 0;
    
        //test busy
        while (HWREG8(FLASH_BASE + OFS_FCTL3) & BUSY) ;
    
        //Clear ERASE bit
        HWREG16(FLASH_BASE + OFS_FCTL1) = FWKEY;
    
        //Set LOCK bit
        HWREG16(FLASH_BASE + OFS_FCTL3) = FWKEY + LOCK;
    }

    Regards,

    James

  • Hello James,

    I am sorry about the confusing phrasing.

    What I meant is, the code example in the driverlib API guide seems to be wrong ie. FlashCtl_eraseSegment does not expect two parameters therefore the IDE calls an error. The same goes for FlashCtl_performEraseCheck and FlashCtl_write32.

    Besides the base address for the flash is labeled wrong. The correct one should be FLASH_BASE which is not needed in these function calls.

    I changed the example so that the IDE does not call any error. Can you please tell me if it could work like this?

        do
        {
            FlashCtl_eraseSegment((uint8_t *) INFOD_START);
            status = FlashCtl_performEraseCheck((uint8_t *) INFOD_START, 128);
        }
        while (status == STATUS_FAIL);
        //Flash write
        FlashCtl_write32((uint32_t *)calibration_data, (uint32_t *)INFOD_START, 1);
    }

    Regards,

    Christian

  • Hi Christian,

    GEDprogrammed said:

    I am sorry about the confusing phrasing.

    What I meant is, the code example in the driverlib API guide seems to be wrong ie. FlashCtl_eraseSegment does not expect two parameters therefore the IDE calls an error. The same goes for FlashCtl_performEraseCheck and FlashCtl_write32.

    That makes sense. You're right. The actual DriverLib functions were probably updated while those in the User's Guide were not. I'll let our software team know about this proposed improvement.

    GEDprogrammed said:
    Besides the base address for the flash is labeled wrong. The correct one should be FLASH_BASE which is not needed in these function calls.

    I'm assuming this was just a minor definition change from FlashCtl_BASE to FLASH_BASE. I would assume the base address to be the same.

    GEDprogrammed said:
    I changed the example so that the IDE does not call any error. Can you please tell me if it could work like this?

    It looks fine. The count is 1, so this should write 4 bytes of data to INFOD.

    Regards,

    James