Skip to main content
Explorer
November 15, 2024
Solved

MotionMC_SaveCalInNVM write byte ?

  • November 15, 2024
  • 1 reply
  • 643 views

mc.jpg

    This topic has been closed for replies.
    Best answer by Martin B

    Hello,

    The MotionMC_SaveCalInNVM() function is intended to store internal calibration data structure and is called from inside of algorithm.

    This function is exposed due to HW dependent load/store mechanism and must be implemented (customized) specificaly for each HW.

    The simplfied example code of its implementation and usage is:

    /* ... */
    
    uint8_t *calibration = NULL;
    
    /* ... */
    
    char MotionMC_SaveCalInNVM(unsigned short int datasize, unsigned int *data)
    {
     if (calibration == NULL) {
     calibration = (uint8_t *)malloc(datasize);
     }
    
     memcpy(calibration, (uint8_t *)data, datasize);
     return 0;
    }
    
    /* ... */

     

    where datasize is size of internal calibration data structure. For this specific library it is 184 bytes, e.g.:

    sizeof(calibration_data) == 184

    However this size might change in future in case of library update. Therefore it is recommended to use dynamic memory allocation using datasize as required memory size or in case of static allocation it is necessary to check
    the datasize value in advance.

    All bytes (size == datasize) are written, but some of bytes might be uninitialized and thus might apear as not written at all. Some of bytes might be uninitialized permanently (e.g.: padding bytes used for memory alignment inside of structure) or might be initialized later by algorithm internal decision.

    1 reply

    Martin BAnswer
    ST Employee
    November 15, 2024

    Hello,

    The MotionMC_SaveCalInNVM() function is intended to store internal calibration data structure and is called from inside of algorithm.

    This function is exposed due to HW dependent load/store mechanism and must be implemented (customized) specificaly for each HW.

    The simplfied example code of its implementation and usage is:

    /* ... */
    
    uint8_t *calibration = NULL;
    
    /* ... */
    
    char MotionMC_SaveCalInNVM(unsigned short int datasize, unsigned int *data)
    {
     if (calibration == NULL) {
     calibration = (uint8_t *)malloc(datasize);
     }
    
     memcpy(calibration, (uint8_t *)data, datasize);
     return 0;
    }
    
    /* ... */

     

    where datasize is size of internal calibration data structure. For this specific library it is 184 bytes, e.g.:

    sizeof(calibration_data) == 184

    However this size might change in future in case of library update. Therefore it is recommended to use dynamic memory allocation using datasize as required memory size or in case of static allocation it is necessary to check
    the datasize value in advance.

    All bytes (size == datasize) are written, but some of bytes might be uninitialized and thus might apear as not written at all. Some of bytes might be uninitialized permanently (e.g.: padding bytes used for memory alignment inside of structure) or might be initialized later by algorithm internal decision.