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.

请问F28027如何读写内部的Flash?

Other Parts Discussed in Thread: C2000WARE, MOTORWARE

看了C2000ware  的flash_programming例程,然后移植到motorware的lab05工程,发现程序卡在了写flash里面。。。。

请问内部的flash要如何读写?有其他例程吗?

  • 对flash进行读写的话都需要用到FLASH API函数进行操作,你可以参考一下例程:
    C:\ti\c2000\C2000Ware_3_03_00_00\device_support\f2802x\examples\structs\f28027_flash_kernel
  • 参考了flash_kernel教程,但程序卡在了擦除函数Flash_Erase里面,下面是我的程序,麻烦看看是否有问题?万分感谢!

    #define  WORDS_IN_FLASH_BUFFER 0x100               // Programming data buffer, Words
    Uint16  Buffer[WORDS_IN_FLASH_BUFFER];
    typedef struct {
         Uint16 *StartAddr;
         Uint16 *EndAddr;
    } SECTOR;
    /*--- Global variables used to interface to the flash routines */
    FLASH_ST FlashStatus;
    #define FLASH_END_ADDR    0x3F7FFF
    #define FLASH_START_ADDR  0x3D8000
    SECTOR Sector[8]= {
             (Uint16 *) 0x3D8000,(Uint16 *) 0x3DBFFF,
             (Uint16 *) 0x3DC000,(Uint16 *) 0x3DFFFF,
             (Uint16 *) 0x3E0000,(Uint16 *) 0x3E3FFF,
             (Uint16 *) 0x3E4000,(Uint16 *) 0x3E7FFF,
             (Uint16 *) 0x3E8000,(Uint16 *) 0x3EBFFF,
             (Uint16 *) 0x3EC000,(Uint16 *) 0x3EFFFF,
             (Uint16 *) 0x3F0000,(Uint16 *) 0x3F3FFF,
             (Uint16 *) 0x3F4000,(Uint16 *) 0x3F7FFF,
    };
    //----------------------------------------
    #ifdef __cplusplus
    #pragma DATA_SECTION("CsmPwlFile")
    #else
    #pragma DATA_SECTION(CsmPwl,"CsmPwlFile");
    #endif
    volatile struct CSM_PWL CsmPwl;
    //----------------------------------------
    #ifdef __cplusplus
    #pragma DATA_SECTION("CsmRegsFile")
    #else
    #pragma DATA_SECTION(CsmRegs,"CsmRegsFile");
    #endif
    volatile struct CSM_REGS CsmRegs;
    #ifdef __cplusplus
    #pragma DATA_SECTION("FlashScalingVar");
    #else
    #pragma DATA_SECTION(Flash_CPUScaleFactor, "FlashScalingVar");
    #endif
    Uint32  Flash_CPUScaleFactor;
    #ifdef __cplusplus
    #pragma DATA_SECTION("FlashCallbackVar");
    #else
    #pragma DATA_SECTION(Flash_CallbackPtr, "FlashCallbackVar");
    #endif
    void (*Flash_CallbackPtr) (void);
    #ifdef FLASH
    #pragma CODE_SECTION(Example_CallFlashAPI,"ramfuncs");
    #endif
    void Example_CallFlashAPI(void)
    {
       Uint16  i;
       Uint16  Status;
       Uint16  *Flash_ptr;     // Pointer to a location in flash
       Uint32  Length;         // Number of 16-bit values to be programmed
       CsmUnlock();
       EALLOW;
       Flash_CPUScaleFactor = SCALE_FACTOR;
       Flash_CallbackPtr = NULL;
       EDIS;
       Status = Flash_Erase(SECTORH,&FlashStatus);
       if(Status != STATUS_SUCCESS)
       {
           return ;
       }
        for(i=0;i<WORDS_IN_FLASH_BUFFER;i++)
        {
            Buffer[i] = 0x100+i;
        }
        Flash_ptr = Sector[7].StartAddr;
        Length = 0x100;
        Status = Flash_Program(Flash_ptr,Buffer,Length,&FlashStatus);
        if(Status != STATUS_SUCCESS)
        {
            return ;
        }
    // --------------
    }
    //
    // CsmUnlock - This function unlocks the CSM. User must replace 0xFFFF's with
    // current password for the DSP. Returns 1 if unlock is successful.
    //
    Uint16
    CsmUnlock()
    {
        volatile Uint16 temp;
        //
        // Load the key registers with the current password. The 0xFFFF's are dummy
        // passwords.  User should replace them with the correct password for the
        // DSP.
        //
        EALLOW;
        CsmRegs.KEY0 = 0xFFFF;
        CsmRegs.KEY1 = 0xFFFF;
        CsmRegs.KEY2 = 0xFFFF;
        CsmRegs.KEY3 = 0xFFFF;
        CsmRegs.KEY4 = 0xFFFF;
        CsmRegs.KEY5 = 0xFFFF;
        CsmRegs.KEY6 = 0xFFFF;
        CsmRegs.KEY7 = 0xFFFF;
        EDIS;
        //
        // Perform a dummy read of the password locations if they match the key
        // values, the CSM will unlock
        //
        temp = CsmPwl.PSWD0;
        temp = CsmPwl.PSWD1;
        temp = CsmPwl.PSWD2;
        temp = CsmPwl.PSWD3;
        temp = CsmPwl.PSWD4;
        temp = CsmPwl.PSWD5;
        temp = CsmPwl.PSWD6;
        temp = CsmPwl.PSWD7;
        //
        // If the CSM unlocked, return succes, otherwise return
        // failure.
        //
        if (CsmRegs.CSMSCR.bit.SECURE == 0)
        {
            return 1;
        }
        else
        {
            return 0;
        }
    }
  • 我用的是Launchpad_F28069M的评估板
  • 你好,参考一下这个帖子中的方法试一下:e2echina.ti.com/.../118420