1 Reply Latest reply on Sep 19, 2017 11:50 AM by e.pratt_1639216

    change device name and const problem




      I want to change the device name dynamically, it's working correctly when the device is powered.


      But after the reset, the content of data in flash is the inizialisation value of the constant & with the value stored in flash


      I declare a constant with initialisation value  (is it not supposed to be initialised only once ?)



      const char8 deviceNameInFlash[20] = {'D','e','f','a','u','l','t')};




      In the stack :


         case CYBLE_EVT_STACK_ON: /* This event is received when component is Started */








        if(CYBLE_SHUTBASSCV_DEVICENAME_CHAR_HANDLE == wrReqParam->handleValPair.attrHandle)



                  {/*Client has to write the ASCI values of the characters that are in the name*/




                  StoreInFlash(tempName, wrReqParam->handleValPair.value.len); 



                      communHandle.attrHandle = CYBLE_SHUTBASSCV_DEVICENAME_CHAR_HANDLE;

                      communHandle.value.val = (uint8*) tempName;

                      communHandle.value.len = wrReqParam->handleValPair.value.len;





      void StoreInFlash( char8 *newData, uint8 length)


          CYBLE_API_RESULT_T result;




              result = CyBle_StoreAppData((uint8*)newData, (uint8*)&deviceNameInFlash,length,0);



          while (result!=CYBLE_ERROR_OK);

          CyBle_GapSetLocalName((const char *)newData);   






      If the user replace the name by "test" , when disconnect/reconnect we have 'test'


      But after device reset we have : "testult"






      So the data in flash is reseted, and i don't understand why, "const " is not supposed to mean initialized once ?


      Thanks for your answers.

        • 1. Re: change device name and const problem

          Strings are stored as nonzero characters followed by a null character which is equal to 00. If you are not writing the 00 to flash, then the code will read the string from memory and will keep reading characters until it hits the null character from the initialization value of "default"0x00

          Things to try:

          Make sure to write the null character of the string to flash as well.

          Try checking if there is already a value in memory before reading/writing/using the value, otherwise you might be overwriting it without checking if it is no longer the default value.

          1 of 1 people found this helpful