Part Number:MSP430FR5994
Tool/software: Code Composer Studio
Hi, I am using some example code and functions from the MSP430 fram examples
one of the functions from the package allows me to save and load from fram safely (i.e double buffering etc)
It was fine with single variables but when i try to use arrays it seems to clear the memory location every time i do a reset or a power lost
I have tested the storing (commit) and reading (restore) functions seperately and they seem to work with arrays
i think the problem is with the initialization function nvs_data_init
here is the code for nvs_data_init
nvs_data_handle nvs_data_init(uint8_t *storage, uint16_t size) { uint8_t *data1; uint8_t *data2; uint16_t crc; uint16_t init_crc1; uint16_t init_crc2; nvs_data_status init_status; nvs_data_header *header; // Initialize local variables init_status = NVS_DATA_INIT; init_crc1 = 0; init_crc2 = 0; // Calculate pointer to header and data storage inside the NVS container header = (nvs_data_header *)storage; data1 = (uint8_t *)header + sizeof(nvs_data_header); data2 = data1 + size; // check status of current container if ((header->token == NVS_DATA_TOKEN) && (header->size == size)) { switch (header->status) { // Storage 1 contains latest data case NVS_DATA_1: // Get CRC of storage 1 and check if it matches crc = nvs_crc(data1, header->size); if (crc == header->crc1) { // Matching checksum, return NVS data handle return (nvs_data_handle)header; } else { // Get CRC of storage 2 and check if it matches crc = nvs_crc(data2, header->size); if (crc == header->crc2) { init_status = NVS_DATA_2; init_crc2 = crc; } } break; // Storage 2 contains latest data case NVS_DATA_2: // Get CRC of storage 1 and check if it matches crc = nvs_crc(data2, header->size); if (crc == header->crc2) { // Matching checksum, return NVS data handle return (nvs_data_handle)header; } else { // Get CRC of storage 1 and check if it matches crc = nvs_crc(data1, header->size); if (crc == header->crc1) { init_status = NVS_DATA_1; init_crc1 = crc; } } break; default: // Try to recover status based on valid CRC signature // since last status is not known, recovering any valid // CRC is better than losing all information crc = nvs_crc(data1, header->size); if (crc == header->crc1) { init_status = NVS_DATA_1; init_crc1 = crc; } crc = nvs_crc (data2, header->size); if (crc == header->crc2) { init_status = NVS_DATA_2; init_crc2 = crc; } break; } } // Unlock FRAM uint16_t framState = nvs_unlockFRAM(); // Initialize NVS data header header->token = NVS_DATA_TOKEN; header->status = init_status; header->size = size; header->crc1 = init_crc1; header->crc2 = init_crc2; // Lock FRAM nvs_lockFRAM(framState); // Return NVS data handle return (nvs_data_handle)header; }