Hi Team,
There's an issue from the customer need your help:
On the MSPM0L1306, I want to implement a GPIO interrupt to trigger a flash write operation.
When the interrupt is triggered, a char array writeStr (which is a global variable) with a length of 16 is stored in the flash address 0x00008000. But what is very strange is that after my code runs DL_FlashCTL_unprotectSector(FLASHCTL, MAIN_BASE_ADDRESS, DL_FLASHCTL_REGION_SELECT_MAIN);, the value of the writeStr array is modified.
I tried a few things and some of them did work. for example:
1. Place the flash operation in the main function instead of the interrupt;
2. Change the global variables in other .c files to local variables to change the address of writeStr;
3. Fill in valid data when declaring writeStr, so that the address of writeStr can also be changed.
Although the above method can help me solve the problem, I am still curious about what causes the value of global variables to be overwritten and modified when flash is operated.
I single-stepped the code in keil software and added writeStr to Watch. I can see that the address is 0x200000D4.
Check the data stored at the address 0x200000D4 in Memory. You can see that there are three bytes of data. This is the value I entered through the keyboard peripheral.
When the program enters GROUP1_IRQHandler, after running DL_FlashCTL_unprotectSector(FLASHCTL, MAIN_BASE_ADDRESS, DL_FLASHCTL_REGION_SELECT_MAIN);
You will find that the data stored at 0x200000D4 in Memory has been modified.
When the breakpoint is triggered when the writeStr value is modified, you can see that the above Disassembly window code stops in the picture below. At this time, you can observe that the corresponding value has also changed in Memory.
The above is the phenomenon I found during debugging. I hope someone can give me some advice.
Best Regards,
Ben