2019-01-15 05:13 AM
Good afternoon,
I would like to share an issue I’m facing with a stm8s105c4.
A feature of our main application is to calculate a CRC of the entire program in the flash. Unfortunately, when I read flash data from addresses close to the instruction in execution, the data read it isn’t always correct.
I’ve been able to reproduce the issue in this small program:
main()
{
unsigned char* p_address;
unsigned char dataRead;
volatile dbg;
/* Loop and read the registers*/
for (p_address = (unsigned char*)0x80ce; ((unsigned int)p_address) < 0x80FF; p_address++)
{
dataRead = *p_address;
dbg++;
}
dataRead++;
}
In this case, when p_address points to 0x80dc, this is what we can observe in the dissasembly and the core registers:
1) This set the address we want to read in X
0x80d7 <main+9> 0x1E04 LDW X,(0x04,SP)
2) This reads the value in the address point by X :
0x80d9 <main+11> 0xF6 LD A,(X)
But the data stored in the accumulator (0x8b) is wrong according to the memory view:
Or the Srecord:
On the main application, all the data that was read incorrectly was where a LD or LDW instruction was placed. Also in this example, as 0x80dc has this disassembly:
0x80dc <main+14> 0x1E01 LDW X,(0x01,SP)
Cosmic and ST Visual Develop was used for this example. I’ve also reproduced this in a stm8s105C6 using a Discovery board. A zip with the project is provided.
Any help will be appreciated. Kind regards,
David
Solved! Go to Solution.
2019-01-15 06:55 AM
Have you tried to make the flash reading instruction reside in RAM and called from the flash program to see if there is a difference?
2019-01-15 06:55 AM
Have you tried to make the flash reading instruction reside in RAM and called from the flash program to see if there is a difference?
2019-01-16 03:07 AM
I haven't tried, I had a bit of pressure to find a solution so I decided to forget about the algorithm we were using and switch to the _checksum16 routines provided by Cosmic.
Then I found out the same issue was happening:
https://community.st.com/s/question/0D50X00009XkhppSAB/cosmic-checksum16-problems
The answer to my problem is there: a software breakpoint. I wasn't familiarized with software breakpoints implementations so I didn't figured out before.
Thanks for the help.
David