Hi, I am trying to program nvm using SLG46824.The NVM programming code was ported from AN-CM-255 SLG46824_6 MTP Arduino Programming Example (MTP_Programmer).We are trying to develop a code so SLG46824 can be programmed via any host device. By using basic i2c smbus api's we are trying to program nvm. So in our code before writing, the device gets erased properly and even after soft reset,it shows erased data. When we try to program new nvm data, starting from sending control byte, it always returns -1.Are we missing any configuration or any write sequence is mismatched ?? Kindly help to understand the issue.
Thanks
Note that you need to call (per page) i2c_smbus_write_block_data() passing 16 bytes rather than calling i2c_smbus_write_byte() or i2c_smbus_write_byte_data() 16 times.
I guess we need to see more of your code.
After following all instructions, for write operation I performed below steps -
(slave address =0 ==> so control code =0, word_address = 2, write bit- 0 - so control_byte turns out to be 0x04 )
nvmString contains each row data as below-
__u8 nvmString0[16] = {0x8C, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00};
int ret = 0;int control_byte = 0x04;int SlaveAddr = 0x00;
int addressForAckPolling = 0;sleep(2);
for (int i = 0; i < 12; i ++) { ret = i2c_smbus_write_byte(file, control_byte); if (ret < 0) { printf("Failed to write control code %d\n", ret); return ret; } ret = i2c_smbus_write_i2c_block_data(file, i << 4, 16, nvmString[i]); if (ret < 0) { printf("Write byte Data failed %d\n", i); return ret; }
if (ackPolling(addressForAckPolling) == -1) { return -1; } else { usleep(20); } }
Can you help with below queries -
1. Not able to write after page 11, block data write return value is -1(that's why iterating loop till 12). According to data sheet i2c addressing mapping - page 12 , 13 are reserved so it cannot be programmed ? but if that is the case page 4,5 is also reserved so write block data should fail at that particular page also, but it doesn't. Please correct if my understanding is wrong and let me understand why I am not able to program from page 12.
2. In write function - Before resetting, read 12 pages which was written from above logic- gives the new nvm written data properly.
3. After reset, it always shows erased data - not persisting new nvm data.So concluding write failed.
Please help me to understand, if missing any write sequence or how to trace the issue.
There are multiple issues with that code:- nvmString0 has only 16 bytes, but you write 12*16 bytes- nvmString0[i] is an __u8, not a pointer to 16 __u8 values- use nvmString0 + i*16 instead (after enlarging nvmString0)- do not write the control_byte with i2c_smbus_write_byte(), it's the I²C address and passed in struct i2c_client- control_byte is wrong, it writes to volatile memory. Use (addr<<3)|2 instead.
Hi,
I have mentioned only page 0 data above using nvmString0 just for refernece. Similarly I do have other 16 pages data and those are stored in diff array as nvmString1,nvmString2 etc..
__u8 nvmString1[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
.....
Data is passed using below pointer -
__u8 *nvmString[] = { nvmString0,nvmString1,nvmString2,nvmString3,nvmString4,nvmString5,nvmString6,nvmString7,nvmString8,nvmString9,nvmString10,nvmString11,nvmString12,nvmString13,nvmString14,nvmString15};
ret = i2c_smbus_write_i2c_block_data(file, i << 4, 16, nvmString[i]);
In for loop I'm using *nvmString containing address of the particular page array.
Hope It's clear now.
2. do not write the control_byte with i2c_smbus_write_byte() -- > How should I pass this address then.Can you explain this Use (addr<<3)|2 instead.
That's in the code you haven't shown us. Probably you need to do this where ADDR is the current address of the SLG46824:
file->addr = (ADDR << 3) | 2; // NVM
control_code = (ADDR << 3) | 2; // NVM
Rather than sending control_byte via i2c_smbus_write_byte used write(file,control_code, 1) instead. Still new NVM data doesn't persist after reset. Before reset I can see the new nvm data in i2cdump.
For NVM write from QC , I send control_code = slave_address << 3 | (NVM_CONFIG).NVM_CONFIG is 0x02.
In word address - A3 to A0 is set to 0 A4 to A7 set according to page and data is sent page wise.
Page data is written successfully, read to verify the data written. But after reset, data doesn't persist. Is it possible data is not written to NVM rather to RAM due to which it is not persisting after reboot ? Is above mentioned way is appropriate to select NVM space or something is missing.
Also Is it possible to have a call/debug session to expedite the process and understand the issue?
The problem is in your code, not in a Silego/Dialog/Renesas product. Please show your code. You depend on the kindness of strangers. Also double check that your GreenPAK device really is a MTP device (such as the SLG35824) rather than an OTP device.
I agree the problem was in our code, I just wanted to understand it was the chip level addressing which we were sending was the issue or the API's used . Though I resolved the issue last week. Thank you for all the help.