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.

CC2652P: Does osal_snv_write disable interrupts ?

Part Number: CC2652P

Hello,

I have an application on CC2652 that runs a main loop code in a function called as interrupt by Sensor Controller (scTaskAlertCallback) every 1ms. This ISR works along the BLE framework derived from ProjectZero. The main loop code should write few bytes to the SNV memory using osal_snv_write. I'm testing my code toggling a pin every 1ms to check the main loop timing and execution, triggering the snv write every 1000ms. I noticed that from time to time the 1ms pulse train generated by main code execution (usually perfectly stable) has a stop about 20ms long (test pin pulses disappear then restart).

I also wrote a wrapper around osal_snv_write that handles several SNV block IDs in the allowed range 0x80-0x8F, to manage a larger data block as a whole, so actually the code writes every time 255 bytes. The call to osal_snv_write is from a task (the main loop enqueues the write request on a RTOS queue, the main BLE task dequeues and calls the osal write).

My questions are:

  • does osal_snv_write disable interrupts during its execution so that scTaskAlertCallback is not called ?
  • why such temporary disable occurs only from time to time, not every call of osal_snv_write ? has it to do with flash compaction ? how can I avoid stopping my main loop execution ?

Thanks

Fabio

  • Hi,

    I asked an expert to look into this. Meanwhile please check Flash — SimpleLinkTm CC13x2 / CC26x2 SDK BLE5-Stack User's Guide 2.01.02.00 documentation for SNV usage guidance.

  • Hi Fabio,

    I have a few initial questions that will help us assist you in a more efficient manner. Can you provide us with the SDK version you are using? Can you provide more details as to when you are calling the osal_snv_write() function? Is the function being called from a stack context or from a hwi/swi context? The function is intended to be called from a task context and may cause issues if called from a hwi/swi context which is why I ask. If the value of the compact threshold is modified, does the frequency of the behavior change as well? I recommend looking over the Limitations and Intended Use section of the Flash Memory chapter.  Can you also verify that the process detailed in the OSAL SNV Example section of the User's guide matches the general process you are using in your software to write and read?

    Best Regards,

    Jan

  • Hi Jan,

    sorry I forgot to mention the SDK, I'm using simplelink_cc13x2_26x2_sdk_5_20_00_52.

    osal_snv_write() is called from a task, the main task of BLE application in the app events queue. A 1ms interrupt from Sensor Controller triggers the scTaskAlertCallback, the code of such ISR periodically (seconds or more) enqueues an event that is dequeued from BLE task and calls osal_snv_write(). Another possibility is the UART callback ISR that does the same when a specific command is sent over UART, anyway the osal_snv_write() is always called from the BLE task.

    About intended use and limitations, I read the chapter and all requirements should be met, though I'm not sure about the point related with "Some care must be taken to not be close to 80% (or other compaction threshold) utilization of a sector". I would like to use the whole 4K space split into 255 bytes sectors, with a wrapper that allows me to use the NV space as a whole. I write a RAM buffer and when it is "dirty" I write all the new data to SNV whit a loop of osal_snv_write() calls (with the queue-task mechanism said above). Right now I'm not even using the whole 4K (it is a nice-to-have not mandatory relaxing some design constraints). So, how is defined the compaction threshold ? As asked in my first post, I'm afraid that the missing execution of main loop ISR is due to compaction.

    I also checked the example, but it is extremely simple so not very helpful when things get a bit more complicated.

    Hope I answered all your questions.

    Best regards

    Fabio

  • Hi, I have a new problem now, different but related with flash.

    At startup I read the SNV memory with a loop of osal_snv_read through 3 blocks (param ID = 0x80 0x81 0x82), the first read returns 2, the next calls return 10 (0xA NV_OPER_FAILED). 

    2 is INVALIDPARAMETER but I really don't understand what parameter is invalid (besides that it is not mentioned in documentation as possible return value), and the same code worked well yesterday (I didn't touch anything). I even suspect my flash is damaged for some reason.

    BR

    Fabio

  • hello, I gave a better look to the example and I don't understande something:

    static void SimplePeripheral_taskFxn(UArg a0, UArg a1)
    {
      // Initialize application
      SimpleBLEPeripheral_init();
      uint8 status = SUCCESS;
    
      status = osal_snv_read(SNV_ID_APP, BUF_LEN, (uint8 *)buf);
      if(status != SUCCESS)
      {
        Display_printf(dispHandle, 0, SP_NVS_DEBUG, "SNV READ FAIL: %d", status);
        //Write first time to initialize SNV ID
        osal_snv_write(SNV_ID_APP, BUF_LEN, (uint8 *)buf);
      }

    What is the meaning of the write after receiving status != SUCCESS ? I tried in my code and actually now all subsequent read/write operations work.

    Thanks
    Fabio
  • Hi Fabio,

    The NV ID must be initialized prior to using that ID. After the ID has been initialized, the library and backend should be able to handle reads and writes as expected. The relevant sample code can be found here: https://dev.ti.com/tirex/content/simplelink_cc13xx_cc26xx_sdk_5_40_00_40/docs/ble5stack/ble_user_guide/html/ble-stack-common/flash_memory-cc13xx_cc26xx.html#osal-snv-example

    Best Regards,

    Jan

  • hi,

    ok thanks, just few questions to clear all details.

    1) to initialize the NV ID is it enough to write a single byte in such ID block ? or the whole memory I want to use inside the block must be written ? any written value is fine ?

    2) shall this initialization be done every time the system is started ? or only if the first read returns !=SUCCESS ?

    I had seem the example but such initialization procedure should be clearly explained in the documentation, I struggled several hours before finding out a code that seems working now.

    Also a "normal" logic would suggest that I run an init procedure before reading, I don't expect a write is needed if I just want to read my data, so the documentation should be very clear about that.

    BR

    Fabio

  • Hi Fabio,

    Thank you for your feedback on our documentation. I agree it can be confusing. It appears that the whole memory inside the block should be initialized. The initialization should only be done if the initial read does not return success. 

    Best Regards,

    Jan