WriteNVRAM fail

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

cross mob
Anonymous
Not applicable

Hi guys,

Short version : WriteNVRAM gives me 0x00 for one call, on a line of my software, all other call works. The page ID is 0x12, I try to change it no improvment.

I delayed the write process by 7s (I was wondering is another process could interfer with the EEPROM, no improvement)

Ok, I have a program running on the BLE 20737S, everything works properly beside write/read EEPROM of one function. I'll explain.

My software used 3 page of EEPROM. Each Page is computed regarding of data from BLE.

T = 0s - "BLE transfer" (different UUID ....)

T = 0s - Write to page 0x13, length 50,  OK

T = 0,1 (right after the Write, I read the same ID); OK

T = 3s - Write to page 0x11, length 0xFF, OK

T = 5s - Write to page 0x12, length 200, fail (return 0x00 instead of 0xC8 wanted)

I did try lost of possibility

PageID and Length are #define

In Page 0x13 and 0x11, buffer are local memory,

Page 0x12 is a array inside a struct, (I try to use a local buffer, no changes...)

I try to chang the ID 0x12 by 0x13, no changes

I try to reduce the length, no changes

Ready for any comment.

I'm pretty sure it's nothing, but I can't figure it out.

Thanks

0 Likes
13 Replies
Anonymous
Not applicable

Hello Y F,

Can you send us a code snippet?

Thanks

JT

0 Likes
Anonymous
Not applicable

xx.h

#define BASE_ADDRESS                0x11

#define DESC_ADDRESS                0x13

typedef PACKED struct{

    ....

    UINT8    category[16];

    UINT8    name[16];

    UINT8    description[DESCRIPTION_LENGTH];

    ....

    UINT16 nvram_write_base_wait_count;

    UINT16 nvram_write_base_wait_timer;

    UINT16 nvram_write_desc_wait_count;

    UINT16 nvram_write_desc_wait_timer;

    ....

}config;

xx.c

config device;

void save_text(void)

{

    UINT8 buffer[CONFIG_BASE_LENGTH];

    UINT16 crc, i;

    UINT8 ret=0;

    BLEPROFILE_DB_PDU db_pduCategory;

    BLEPROFILE_DB_PDU db_pduName;

    /*if(fn_verbose)*/ble_trace0("void save_text(void)");

    bleprofile_ReadHandle(HANDLE_CONFIG_CAT_VALUE, &db_pduCategory);

    bleprofile_ReadHandle(HANDLE_CONFIG_NAME_VALUE, &db_pduName);

    for(i=0; i< 15 ; i++){

        buffer[BASE_CATEGORY_ADDRESS+i] = device.category;

        buffer[BASE_NAME_ADDRESS+i] = device.name;

    }

    check_crc(buffer,BASE_LENGTH-2), 1);

    ret = bleprofile_WriteNVRAM(BASE_ADDRESS, BASE_LENGTH, buffer);

    ble_trace1("return :  0x%x", ret);

    /*if(fn_verbose)*/ble_trace0("void save_text(void) - end");

}

void save_description(void)

{

    UINT16 i, crc;

    UINT8 ret=0;

    UINT8 buffer[BASE_LENGTH];

    /*if(fn_verbose)*/ble_trace0("void save_description(void)");

    check_crc(device.description,(CONFIG_DESCRIPTION_LENGTH-2), 1);

    crc = device.description[CONFIG_DESCRIPTION_LENGTH-2] | (device.description[CONFIG_DESCRIPTION_LENGTH-1]<<8);

    ble_trace2("crc :  0x%x%x", device.description[DESCRIPTION_LENGTH-1], device.description[DESCRIPTION_LENGTH-2]);

    ble_trace1("crc :  0x%x", crc);

    ble_trace1("length :  0x%x", DESCRIPTION_LENGTH);

    ret = bleprofile_WriteNVRAM(CONFIG_DESC_ADDRESS, CONFIG_DESCRIPTION_LENGTH, device.description);

    ble_trace1("return :  0x%x", ret);

    /*if(fn_verbose)*/ble_trace0("void save_description(void) - end");

}

void process_1sec()

{

    if(fn_verbose)ble_trace0("void process_1sec()");

    ...

        if(device.nvram_write_base_wait_count){

            if(device.nvram_write_base_wait_count == device.nvram_write_base_wait_timer){    //where = device.nvram_write_base_wait_timer = 3

                save_text();

                device.nvram_write_base_wait_count = 0;

            }

            else{

                device.nvram_write_base_wait_count++;

            }

        }

        if(device.nvram_write_desc_wait_count){

            if(device.nvram_write_desc_wait_count == device.nvram_write_desc_wait_timer){  //where = device.nvram_write_desc_wait_timer = 7

                save_description();

                device.nvram_write_desc_wait_count = 0;

            }

            else{

                device.nvram_write_desc_wait_count++;

            }

        }

    ....

}

=> Save Text works

=> Save description doesn't works and return of Write gives me back 0x00

0 Likes
Anonymous
Not applicable

Hello.

The code that you've posted seems like there's nothing wrong with it assuming:

#define CONFIG_DESC_ADDRESS 0x12

#define CONFIG_DESCRIPTION_LENGTH 0xc8

I would be happy to look at the code if you give me the source file.

(simplified, compilable code would be nicer?!:))

If you don't want to post your files on the forum, you can email it to communities-list@broadcom.com (website Admin will make sure it gets to me)

Thank you.

James

0 Likes
Anonymous
Not applicable

Hello Y F,

In your function save_description we don't see anything wrong.

Can you send us what you see on the I2C lines and post what you see on the bus?

Thanks,

JT

0 Likes
Anonymous
Not applicable

EEPROM fail.PNG

I dont know what do you want to see excatly... this is a part of when I get an error.

0 Likes
Anonymous
Not applicable

Here is what I would suggest you try::

Put your writeNVRAM calls in a loop of say 100 times.

Inside the loop check the return code.  When you see the return code you want, break out of the loop.

Another way is to follow the single writeNVRAM with a loop of readNVRAM function calls.  Break out of the read loop when the return code is good, then compare what you wrote to want was read.  If it matches all is well.

It sounds like you have experimented with timing, but from your code snippet above, it is not clear that you have a sufficient delay between the save text write and the save description write.

What often happens with EEPROM devices is when you "Write" you get a return code that says "Success" immediately.  This success only means that the device "acknowledged" receiving the write instruction.  It does not mean the device has completed the write.   After the ACK, the device begins its internal write cycling, during which time further input is disabled.  This could explain why your save description function fails.. because the device is still processing the save text and is not ready for the next write when you called.  You can either put a delay in your code, or process in a loop as described above. (or both).

Hope this helps.

Eric

0 Likes
Anonymous
Not applicable

Ok, I did try to write 20 times without brake and get the return code and compare it with the length I should get in return.

I always get a "0"

I did try a loop of 20 try, 100 try, 100 try with 1 sec wait between 100 tries, 10 try with space of 1 sec, 10 try each 5 sec

Always a 0.

0 Likes
Anonymous
Not applicable

Sorry to hear that.  I wonder. do you know the part number of the memory device?  Sometimes EEPROM has some 'write protect' by page.. do you think there some write protected area you are writing to?  Is this on a TAG board, or with one of the BCM modules?  Maybe try a different data address?  I suppose there is a small chance that the memory is damaged somehow.. if you have a second board you can try...?

0 Likes
Anonymous
Not applicable

Hello.

I don't think it is timing issue.

I was able to avoid the bug by changing THERATY_CONFIG_BASE_LENGTH to 0xFC.

Writing text:

pastedImage_0.png

Writing description:

pastedImage_1.png

For some reason writing 0xFF length gave me errors after writing something to NVRAM prior to writing 0xFF.

I'll go ahead and ask the developers why this happens.

Please let me know if you can avoid your problems by changing the base_length to 0xFC.

Thanks.

James

0 Likes
Anonymous
Not applicable

Hey guys,

Largest item size is 255 bytes (max UINT8), and all items have a 3 byte header. So largest user item is 252 bytes.

Hop this helps

Thanks

JT

0 Likes
Anonymous
Not applicable

Hi,

I just changed the length to 0xFC, no changes.

I did try to invert the sequence.

First I try to save the text and the the description(4 sec later). Where Text works and Descirption doesn't

I just try to invert, Saving Desc and then Text, Where Description works, and Text doesnt.

All tries with length = 0xF0.

Anonymous
Not applicable

Hi.

I was able to write to both text and description with the code that you sent me with just changing THERATY_CONFIG_BASE_LENGTH to 0xFC.

Perhaps I am doing something different from you.

Can you tell me the exact process that you are doing to produce your error?

This is what I did:

     1. Connect

     2. Write to characteristic that ends in 2023

pastedImage_0.png

     3. Write to characteristic that ends in 2024

pastedImage_1.png

James

0 Likes
Anonymous
Not applicable

Hello. Is this problem fixed for you?

James

0 Likes