This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Keil uVision 5+nRF51822+BLES110 softdevice: best way to implement a checksum at compile/build time?

Hello, I have inherited a (good) project in which the previous designer implemented a checksum using a value calculated from this:

char* pMemory = 0; return crc16_ccitt(pMemory, NVS_TESTPAGE*((uint16_t)NRF_FICR->CODEPAGESIZE));

Her firmware compares this during startup against a value retrieved from flash memory. Then she designed an install process in which you (a) install the firmware, (b) run it and let it fail the checksum (which puts it into our FAULT state), (c) use a serial maintenance tool (which talks to our code which is enabled in FAULT) to query the above code, then (d) use the serial tool to send the proper checksum value back into the device to be written to flash, and when you cycle power it passes the checksum.

We are trying to streamline this process so that we dont need the serial tool (accessing the serial port has caused a manufacturing issue), and we can get the proper checksum value in there at build time (I presume she did the above because it you store it in source code, changing it changes the needed checksum and its a catch 22). I see enough hits for this to convince me it's possible, but can't find a solution that works for our compiler+target.

Can anyone recommend an approach or point me to some sample code?

Thanks VERY much for any help.

Parents
  • Hi Riceman,

    Please correct me if I'm wrong.

    You want to generate a check sum and write it to flash in the factory testing process before it goes to the market. So that on normal operation when booting up it can check for flash integrity ?

    I am not sure why you need to read it out via Serial at ( c)and then write it back at (d), why not checking if it's the first run (using a magic byte such as 0xBEEF) you calculate the crc, then write to flash the CRC. Of course the part of flash that you store the CRC should not be calculated for CRC.

    Alternativelly, if you don't want to use the code to store the crc on flash, you can use the CRC calculating tool (crc.exe) to calculate the crc value and can use nrfjprog to write into flash on the nRF51.

Reply
  • Hi Riceman,

    Please correct me if I'm wrong.

    You want to generate a check sum and write it to flash in the factory testing process before it goes to the market. So that on normal operation when booting up it can check for flash integrity ?

    I am not sure why you need to read it out via Serial at ( c)and then write it back at (d), why not checking if it's the first run (using a magic byte such as 0xBEEF) you calculate the crc, then write to flash the CRC. Of course the part of flash that you store the CRC should not be calculated for CRC.

    Alternativelly, if you don't want to use the code to store the crc on flash, you can use the CRC calculating tool (crc.exe) to calculate the crc value and can use nrfjprog to write into flash on the nRF51.

Children
No Data
Related