Skip to main content
Visitor II
February 24, 2020
Question

How to verify memory checksum in STM8S103F2 controller

  • February 24, 2020
  • 1 reply
  • 1473 views

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.

    This topic has been closed for replies.

    1 reply

    Graduate II
    February 24, 2020

    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.

    Graduate II
    February 24, 2020

    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