cancel
Showing results for 
Search instead for 
Did you mean: 

How to verify memory checksum in STM8S103F2 controller

HTiwa.11
Associate II

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.

4 REPLIES 4

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.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

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

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

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++;

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Special thanks for all of your inputs