2023-08-11 10:16 AM
I am trying to initialize a section of EEPROM address from 0x40A0 to 0x40B8 in STM8AF5288 MCU. Between I am not able to complete this initialization process & end up getting MCU Reset. Attaching the assembly code that does this action
i hope the procedure is correct, please advice if something is wrong in this code. This is done before invoking main function.
Couldn't follow the FLASH_IAPSR changes in this windows as well. It shows "intrusive read"
Thanks
Solved! Go to Solution.
2023-08-12 06:00 AM
After the changes the bit DUL (FLASH_IAPSR bit 3), means EEPROM write is unlocked is always '0'.
If you terminate with 'BRES _FLASH_IAPSR,#3 ;', bit is 0
On the last byte, address 0x47FF, after writing 0xAA you are not waiting for EOP.
A simple program is:
1. Enable write access to EEPROM
2. Test DUL bit
3. Write one byte to EEPROM
4. Wait EOP
5. Disable write access to EEPROM
6. Read EEPROM to confirm if write ok
2023-08-11 11:39 AM
The source of MCU reset can be detected by reading register RST_SR.
The bit DUL (FLASH_IAPSR bit 3), means EEPROM write is unlocked when bit is 1. And for you EEPROM write is unlocked when bit is 0. This is wrong.
See RM0016 page 45:
Before starting programming, the application must verify that the DATA area is not write protected by checking that the DUL bit is effectively set. The application can choose, at any time, to disable again write access to the DATA area by clearing the DUL bit.
After you write the unlocked keys, you MUST wait bit DUL is 1. Any you continue without any test.
This is also wrong, 'BSET _FLASH_IAPSR,#3' should be 'BRES _FLASH_IAPSR,#3
Also read PM0051.
And we must start with a simple program.
2023-08-12 03:30 AM
2023-08-12 06:00 AM
After the changes the bit DUL (FLASH_IAPSR bit 3), means EEPROM write is unlocked is always '0'.
If you terminate with 'BRES _FLASH_IAPSR,#3 ;', bit is 0
On the last byte, address 0x47FF, after writing 0xAA you are not waiting for EOP.
A simple program is:
1. Enable write access to EEPROM
2. Test DUL bit
3. Write one byte to EEPROM
4. Wait EOP
5. Disable write access to EEPROM
6. Read EEPROM to confirm if write ok
2023-08-12 01:32 PM - edited 2023-08-12 01:34 PM
Thanks for your clarification once again. I did try to run the above assembly program without single step / debug mode and then noticed the changes to the EEPROM write is working as expected.
The DUL bit is checked before writing to EEPROM and EOP is checked after a write operation to ensure programming is successful.
Cheers