Speaking of alignment, many students who study C language naturally think of alignment of members in the data structure. For example, they often ask questions during interviews:
Struct {
Char;
Short B;
Int C;
};
How many bytes does it take? This inappropriate example is indeed related to alignment. But how many people are in trouble with alignment?
Yesterday, we found a strange phenomenon: the lighting test code is normal, and it is not normal to add a function block. The code block is as follows:
Uint8_t pid = 0;
Uint8_t tid = 0;
Void foo1 (void)
{
Xxx;
}
Void foo2 (void)
{
YYY;
}
If you try to comment out foo1 (), it will be normal, and vice versa. I don't know why!
In desperation, I picked up openocd + JTAG and found that there was a hard fault exception in the CPU because unaligned occurred. The final reason was: When the startup code was copying data segment data, the Command finds that the data is not aligned, and the CPU exception occurs. The commented-out code just causes the data segment data to be aligned, so there is such a strange phenomenon.
As you will know later, when you need to comment out the code by block, the data should also be commented out because it may also cause errors.
This is a piece of cortex-m3 board, the next contact with the new CPU is best to make it and other CPU differences, and then start.
This should be the last interesting bug in my company. I hope my bug will continue to be wonderful.