{ "ticketNumber" : "892440", "reporterName" : "Maulin Lodhia", "rankPoints" : "380", "resolutionStatus" : "TI Thinks Resolved", "ticketName" : "BQ35100: Flash stream file parsing fails on a comapare, resulting in bricked bq35100 chip", "rankName" : "Intellectual", "replies" : " 6", "views" : " 55", "queryText" : "Part Number: BQ35100 Hello, We have implemented flash stream parser based on the code described in slua801. we tested the parser and it parses the flash stream file as per specifications (flash stream specification file attached1856.Flash Stream File Format.pdf). During our tests with the bq35100 device we found that firmware revision that was read and compared against a known value was failing. When using bqstudio reading of ID and version was working correctly. In order to do the same with flash streamer file to read id and fimware version, we had to add 100ms delay after i2cwrite command (see below routine). char *BQ35100_execute_fs(char *pFS)\n{\n\tint nLength = strlen(pFS);\n\tint nDataLength;\n\tchar pBuf[16];\n\tchar pData[32];\n\tint n, m;\n\tchar *pEnd = NULL;\n\tchar *pErr;\n\tbool bWriteCmd = false;\n\tbool bReadCmd = false;\n\tbool bCompareCmd = false;\n\tunsigned char nRegister;\n\n\tm = 0;\n\tfor (n = 0; n < nLength; n++)\n\t\tif (pFS[n] != ' ') pFS[m++] = pFS[n];\n\tpEnd = pFS + m;\n\tpEnd[0] = 0;\n\n\tdo\n\t{\n\t\tswitch (*pFS)\n\t\t{\n\t\t\tcase ';':\n\t\t\t\tbreak;\n\t\t\tcase 'W':\n\t\t\tcase 'C':\n\t\t\tcase 'R':\n\t\t\t\tbWriteCmd = *pFS == 'W';\n\t\t\t\tbReadCmd = *pFS == 'R';\n\t\t\t\tbCompareCmd = *pFS == 'C';\n\t\t\t\tpFS++;\n\t\t\t\tif ((*pFS) != ':') goto exit_parse;\n\t\t\t\tpFS++;\n\t\t\t\tn = 0;\n\t\t\t\twhile ((pEnd - pFS > 2) && (n < sizeof(pData) + 2) &&(*pFS != '\\n'))\n\t\t\t\t{\n\t\t\t\t\tpBuf[0] = *(pFS++);\n\t\t\t\t\tpBuf[1] = *(pFS++);\n\t\t\t\t\tpBuf[2] = 0;\n\t\t\t\t\tm = strtoul(pBuf, &pErr, 16);\n\t\t\t\t\tif (*pErr) return (pFS - 2);\n\t\t\t\t\tif (n == 0) deviceAddress = m;\n\t\t\t\t\tif (n == 1) nRegister = m;\n\t\t\t\t\tif (n > 1) pData[n - 2] = m;\n\t\t\t\t\tn++;\n\t\t\t\t}\n\t\t\t\tif (n < 3) goto exit_parse;\n\t\t\t\tnDataLength = n - 2;\n\t\t\t\tif (bWriteCmd)\n\t\t\t\t{\n\t\t\t\t\tBQ35100_dump_data(\"Write\", nRegister, pData, nDataLength);\n\t\t\t\t\ti2cWriteBytes(nRegister, (uint8_t *)pData, nDataLength);\n\t\t\t\t\t/* Adding a delay giving bq35100 device sometime to put register value on I2C bus before we read it. */\n\t\t\t\t\tDelayMs(100);\n\t\t\t\t}\n\n\t\t\t\tif (bCompareCmd || bReadCmd)\n\t\t\t\t{\n\t\t\t\t\tchar pDataFromGauge[nDataLength];\n\t\t\t\t\ti2cReadBytes(nRegister, (uint8_t *)pDataFromGauge, nDataLength);\n\t\t\t\t\tif (bCompareCmd)\n\t\t\t\t\t{\n\t\t\t\t\t\tBQ35100_dump_data(\"Read\", nRegister, pDataFromGauge, nDataLength);\n\t\t\t\t\t\tBQ35100_dump_data(\"Compare\", nRegister, pData, nDataLength);\n\t\t\t\t\t\tif (memcmp(pData, pDataFromGauge, nDataLength))\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tDEBUG_PRINTF(\"%s: Memory comparison action failed, exiting...\\r\\n\", __func__);\n\t\t\t\t\t\t\tgoto exit_parse;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t\tBQ35100_dump_data(\"Read\", nRegister, pDataFromGauge, nDataLength);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase 'X':\n\t\t\t\tpFS++;\n\t\t\t\tif ((*pFS) != ':') goto exit_parse;\n\t\t\t\tpFS++;\n\t\t\t\tn = 0;\n\t\t\t\twhile ((pFS != pEnd) && (*pFS != '\\n') &&(n