Writing to flash after every connect?

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Hi,

   

 

   

I have a question regarding CyBle_GapGenerateLocalP256Keys() funciton in Cypress BLE 3.30 module. If I never call this function my BLE device will use default P-256 Debug keys (can be seen from btmon in Linux when I connect that keys are of type "debug", this causes pairing/connect to take longer than with "real" P-256 keys). If I however generate local keys right after my stack has been initialized my BLE device will use "real" P-256 keys when I initiate a pairing (and not the debug keys). But every time my BLE device wakes up from Hibernate (=boots and generates keys again) and gets connected (not even creating new pairing, just re-connects to old pairing) it will now write data to Flash. When I do not generate the keys at all (and use default debug keys) the device only writes to flash ONCE, right after I create a new pairing, never at subsequent re-connects, just as one would expect. Why does GapGenerateLocalP256Keys() cause a new write to flash every time I connect back to my already existing pairing? Nothing in the pairing has changed, I can see from btmon in Linux that the same old keys are still used even if my BLE stack generates new keys every time it boots (as I understand these newly generated P-256 keys will only be used for new pairings, they do not affect old pairings already stored in flash, as seems to actually be the case)

   

Clearly the generated P-256 keys themselves are not stored in flash, as I already tried writing a flag to user space flash memory after successfully calling GapGenerateLocalP256Keys() and at next boot read this flag and never again generate any new keys if flag was set (indicating local keys was once generated). All this ended up doing was that it defaulted back to the default P-256 debug-keys at subsequent boots, indicating my previously generated keys were not loaded into the BLE stack at boot and neither can I find any API documentation about how to specifically load stored keys from flash into the stack. (Here I am assuming it is the newly generated P-256 keys that gets written to flash at every connect, but it is of course unclear exactly what is being written into flash, but they keys are the only thing that have changed at every boot, since I am not making new pairing, just re-connecting to same old pairing)

   

 

   

I.e. what is the reason the BLE stack wants to write to flash at every connect done after the GapGenerateLocalP256Keys() function has been called?

0 Likes
2 Replies
Anonymous
Not applicable

You could try checking the cyBle_pendingFlashWrite variable's bits to see what is causing the flash write on each disconnect;

0 Likes
Anonymous
Not applicable

Hi Magnus,

   

Would it be possible for you to share the code so that we could have a look at it? 

   

When you say "writes to flash", do you mean to say that the cyBle_pendingFlashWrite flag is set and as a consequence the CyBle_StoreBondingData() is executed?

0 Likes