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.

cc1310如何把一个字节数据写入指定的flash地址中

Other Parts Discussed in Thread: CC1310

大家好,

    请问在CC1310中如何实现把一个字节数据写入到指定的flash地址中呢?

    类似msp430功能实现:

    unsigned long * Flash_ptrC;               // Initialize Flash pointer Seg D
    unsigned long tmp;  
    tmp = value; 
    Flash_ptrC = (unsigned long *) 0x1880;    // Initialize Flash pointer
    FCTL3 = FWKEY;                            // Clear Lock bit
    FCTL1 = FWKEY+ERASE;                      // Set Erase bit
    *Flash_ptrC = 0;                          // Dummy write to erase Flash seg
    while(FCTL3&BUSY);
    FCTL1 = FWKEY+BLKWRT;                     // Enable long-word write
    *Flash_ptrC = tmp;                     	  // Write to Flash
    while(FCTL3&BUSY);
    FCTL1 = FWKEY;                            // Clear WRT bit
    FCTL3 = FWKEY+LOCK; 

    希望能尽快得到帮助!

谢谢!

  • 可以通过NVS driver,推荐个例程: dev.ti.com/.../
  • 谢谢Viki Shi,

       我是应用IAR7.80进行搭建的环境,TI协议为tirtos_cc13xx_cc26xx_2_20_01_08,配置NVS MAPPING

    /*!
    
    *  @def    CC1310_LAUNCHXL_NVSName
    
    *  @brief  Enum of NVS names
    
    */
    
    typedef enum CC1310_LAUNCHXL_NVSName {
    
       CC1310_LAUNCHXL_NVSCC26XX0 = 0,
    
       CC1310_LAUNCHXL_NVSSPI25X0,
    
       CC1310_LAUNCHXL_NVSCOUNT
    
    } CC1310_LAUNCHXL_NVSName;
    
    /*
    
    *  =============================== NVS ===============================
    
    */
    
    #include <ti/drivers/NVS.h>
    
    #include <ti/drivers/nvs/NVSCC26XX.h>
    
    #define NVS_REGIONS_BASE 0x1A000
    
    #define SECTORSIZE       0x1000
    
    #define REGIONSIZE       (SECTORSIZE * 4)
    
    #define SPIREGIONSIZE    (SECTORSIZE * 32)
    
    #define VERIFYBUFSIZE    64
    
    static uint8_t verifyBuf[VERIFYBUFSIZE];
    
    /*
    
    * Reserve flash sectors for NVS driver use by placing an uninitialized byte
    
    * array at the desired flash address.
    
    */
    
    #if defined(__TI_COMPILER_VERSION__)
    
    /*
    
    * Place uninitialized array at NVS_REGIONS_BASE
    
    */
    
    #pragma LOCATION(flashBuf, NVS_REGIONS_BASE);
    
    #pragma NOINIT(flashBuf);
    
    static char flashBuf[REGIONSIZE];
    
    #elif defined(__IAR_SYSTEMS_ICC__)
    
    /*
    
    * Place uninitialized array at NVS_REGIONS_BASE
    
    */
    
    static __no_init char flashBuf[REGIONSIZE] @ NVS_REGIONS_BASE;
    
    #elif defined(__GNUC__)
    
    __attribute__ ((section (".nvs")))
    
    static char flashBuf[REGIONSIZE];
    
    #endif
    
    /* Allocate objects for NVS and NVS SPI */
    
    NVSCC26XX_Object nvsCC26xxObjects[1];
    
    /* Hardware attributes for NVS */
    
    const NVSCC26XX_HWAttrs nvsCC26xxHWAttrs[1] = {
    
       {
    
           .regionBase = (void *)flashBuf,
    
           .regionSize = REGIONSIZE,
    
       },
    
    };
    
    /* NVS Region index 0 and 1 refer to NVS and NVS SPI respectively */
    
    const NVS_Config NVS_config[CC1310_LAUNCHXL_NVSCOUNT] = {
    
       {
    
           .fxnTablePtr = &NVSCC26XX_fxnTable,
    
           .object = &nvsCC26xxObjects[0],
    
           .hwAttrs = &nvsCC26xxHWAttrs[0],
    
       },
    
       {NULL, NULL, NULL},
    
    };

    NVS程序

     

      NVS_Handle rHandle;
    
       NVS_Attrs regionAttrs;
    
       NVS_Params nvsParams;
    
       uint_fast16_t status;
    
       char buf[32];
    
       // Initialize the NVS driver
    
       NVS_init();
    
       NVS_Params_init(&nvsParams);
    
       rHandle = NVS_open(CC1310_LAUNCHXL_NVSCC26XX0, &nvsParams);
    
       // confirm that the NVS region opened properly
    
       if (rHandle == NULL) {
    
           // Error opening NVS driver
    
           while (1);
    
       }
    
       // fetch the generic NVS region attributes
    
       NVS_getAttrs(rHandle, &regionAttrs);

    在运行到NVS_OPEN();后返回NULL,这个是什么问题。

    通过CCS编译正常。

    谢谢!

  • CCS正常,IAR出错,按描述应该是编译环境问题,IAR版本是否符合release note的要求?

  • tirtos_cc13xx_cc26xx_2_20_01_08的release note是支持IAR7.80的,但是建立工程后的CC1310_LAUNCHXL.c中没有NVS配置信息,我是从simplelink_cc13x0_sdk_2_10_00_36中借鉴过来的,simplelink是需要IAR: 8.20.2.58 。如果真是版本问题就麻烦了,我之前的工程都是在IAR7.80上建立的。如果我还是用IAR7.80,NVS配置上需要怎么修改呢?
    谢谢!
  • 建议换到新版本,然后根据SDK中的migration guide来移植