2 Replies Latest reply on Oct 7, 2020 1:53 AM by user_3671066

    psoc 63 ble - clear memory for writeReqParameter->handleValPair.value.val


      Can i clear the memory when i am done writing to it ?


      I am trying to transmit data over several characteristics using the cy smart app and writing ascii values as strings(chars )..

      All of my characteristics have the same length (32 bytes).


      Problem is, when I copy the data from the memory writeReqParameter->handleValPair.value.val to a char array, i dont know how to clear the memory and therefor I will copy both old and new data to my char array, if my new trasmitted data is of shorter length.



      How can i avoid this?


      I have tried using a simple memset, but this makes the program crash.

        • 1. Re: psoc 63 ble - clear memory for writeReqParameter->handleValPair.value.val



          I guess you are using custom characteristics and/or services. The implementation of custom characteristics in PSoC BLE is such that when you overwrite new characteristic values of small length on older characteristic values of larger length, the remaining values will not be erased. So you have to manually erase the data.


          One simple method you can do is to create a buffer of 32 bytes and initialize the values to '0'.


          uint8 clear_memory[32] = {0};


          You can use the API CyBLE_GattSWriteAttributeLocal() and write the clear_memory[32] to the characteristic whenever you want to. This will clear the entire characteristic of 32 bytes.


          Please try once and let us know if there is any problem for you with this method.




          • 2. Re: psoc 63 ble - clear memory for writeReqParameter->handleValPair.value.val

            It doesn't work. - and maybe it really doesn't have to, i don't know.


            My problem is when i read from the psoc, the data i read is both old and new -  even though I thought that i could restrict it to the length of data chosen by me, the data i read is longer.


            when writing from the app to the psoc my code is this:

                            memset(arr1, 0, sizeof(arr1));





            when reading on the app (receiving from psoc) my code is:

                             cy_stc_ble_gatt_handle_value_pair_t serviceHandle;

                            cy_stc_ble_gatt_value_t serviceData;


                            serviceData.val = (uint8*)arr1;

                            serviceData.len = strlen(arr1);

                            serviceData.actualLen = strlen(arr1);

                            serviceHandle.attrHandle = CY_BLE_SERVICE_CHARAC_HANDLE;

                            serviceHandle.value = serviceData;





            the global array arr1 is of type: char[32]


            if i'm typing "helloworld" the first time, and "test" the second time, what im receiving is "testoworld"