2020-02-23 10:16 PM
Hi All,
I want to verify memory checksum of my source code. I want to know, which register i can use to verify my memory checksum. Memory checksum i can see in "STVP" during programming, but that checksum i want to verify inside code. Advance thanks for the help.
2020-02-24 08:48 AM
Not an STM8 user, but for the most part "checksums" provided by programming tools, ie PROM Programmers, STM32 Cube Programmer, are a simple summation of the data bytes in the firmware image.
If a 16-bit sum, you'd presumably use a byte pointer, and sum the bytes the MCU can read from the FLASH memory space.
ie
uint8_t *flash = (uint8_t *)firmwareaddr; // on ARM "firmwareaddr" would be 0x08000000 for example, see .LD or .MAP file
uint16_t sum = 0;
for(i=0; i<firmwaresize; i++) sum += flash[i];
Different tools might use 32-bit sums, or 16/32-bit CRC depending on how effective/exotic one needed them to be.
2020-02-24 09:34 AM
Cross-posted here https://stackoverflow.com/questions/60374031/how-to-verify-memory-checksum-of-the-code-in-stm8s-controller
Base for STM8 is 0x8000, STVP outputs something that is probably a 32-bit sum, one could perhaps load the image and check. Not seeing any doc explicitly describe the algorithm.
Checksumming is touted in the safety library
https://www.st.com/en/embedded-software/stm8-safeclassb.html
2020-02-24 11:28 AM
STVP seems to be a simple 32-bit summation
uint8_t *flash = (uint8_t *)0x8000;
uint32_t sum = 0;
int firmwaresize = 8 * 1024;
while(firmwaresize--) sum += *flash++;
2020-02-25 06:45 AM
Special thanks for all of your inputs